mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-12-03 11:47:42 +01:00
## Thinking Path
> - Paperclip is the open source app people use to manage AI agents for
work
> - Hosted Paperclip Cloud tracks user onboarding conversion in PostHog
across server-side events and browser events
> - Onboarding funnel events (`onboarding_opened`,
`onboarding_step_viewed`, `onboarding_step_completed`,
`onboarding_step_failed`, `onboarding_dismissed`) currently fire only
from browser `posthog-js`
> - Browser `posthog-js` loads lazily after `whenPageSettles` (up to 15
seconds), drops events captured before `startProductAnalytics`
initializes, and can be blocked by privacy extensions, causing
artificial dropoff between server-side `workspace_entry` and
`onboarding_opened`
> - Step 1 (`name_org`) is unmapped in `WIZARD_STEPS`, and
`connect_model` lacks sub-step visibility (provider selection,
credential mode switch, OAuth progress, API key submission, Cloud trial
CTA, mobile handoff)
> - This pull request routes all onboarding funnel events through a
first-party `POST /api/onboarding/telemetry` endpoint backed by
`trackCloudPostHogEvent` (`posthog-node`), preserves every existing
event name verbatim, adds granular step and sub-step instrumentation,
and fixes the pre-start queue drop in `product-analytics.ts`
> - The benefit is adblocker-proof, race-free server-side onboarding
analytics in PostHog with complete step-by-step dropoff visibility and
zero breaking changes to existing insights
## Linked Issues or Issue Description
**What existing behavior does this improve?**
Cloud onboarding funnel analytics in
`ui/src/lib/analytics/onboarding-analytics.ts`,
`ui/src/lib/analytics/product-analytics.ts`,
`ui/src/components/OnboardingWizard.tsx`, and `server/src/telemetry.ts`.
**Subsystem affected**
Cross-cutting (multiple of the above)
**Current behavior**
Onboarding funnel events fire only from browser `posthog-js`. Events
captured before `ProductAnalyticsGate` calls `startProductAnalytics` are
silently dropped, queued events are lost if the user leaves before
`/_ph/static/array.js` loads, Step 1 (`name_org`) is unmapped, and
`connect_model` sub-steps (OAuth link open, code submit, retry, abandon,
provider tile click, Cloud trial CTA, mobile desktop handoff) are not
instrumented.
**Proposed behavior**
All onboarding funnel and interaction events are sent via
`fetch("/api/onboarding/telemetry", { method: "POST", keepalive: true
})` to a board-authenticated, strictly Zod-validated Express route that
forwards them server-side to PostHog via `trackCloudPostHogEvent`.
Existing event names are preserved verbatim and removed from
`posthog-js` to guarantee a single sender per event. Pre-start browser
events in `product-analytics.ts` are also buffered until
`startProductAnalytics` runs.
**Reason and benefit**
Adblockers and browser script lazy-load races can no longer drop
onboarding funnel events. Product analytics can now separate
`workspace_entry` -> `onboarding_workspace_loaded` ->
`onboarding_opened` and pinpoint exact dropoff points on every step and
`connect_model` sub-step.
**Breaking changes**
None. Existing PostHog event names (`onboarding_opened`,
`onboarding_step_viewed`, `onboarding_step_completed`,
`onboarding_step_failed`, `onboarding_dismissed`,
`agent_chat_message_sent`) are preserved verbatim. On self-hosted
installs, `trackCloudPostHogEvent` is a no-op and the endpoint returns
`204 No Content`.
## What Changed
- Added `packages/shared/src/onboarding-telemetry.ts` (exported from
`packages/shared/src/index.ts`) with strict Zod discriminated-union
schemas (`onboardingTelemetryEventSchema`), canonical event names
(`ONBOARDING_TELEMETRY_EVENTS`), and snake_case PostHog property mapping
(`onboardingTelemetryEventToPostHogProperties`).
- Added `server/src/routes/onboarding-telemetry.ts` (`POST
/api/onboarding/telemetry`), mounted in `server/src/app.ts`, enforcing
`assertBoard(req)`, `assertCompanyAccess(req, companyId)` when
`companyId` is present, strict schema validation, and server-side
delivery via `trackCloudPostHogEvent`.
- Updated `ui/src/lib/analytics/onboarding-analytics.ts` to send all
onboarding events to `/api/onboarding/telemetry` with `keepalive: true`
(removing duplicate browser `posthog-js` sends), mapped Step 1 to
`name_org`, fixed `1 -> 3` forward step completion ordering, and added
granular capture helpers.
- Instrumented `ui/src/hooks/useAgentlessOnboardingAutoOpen.ts`
(`onboarding_workspace_loaded`),
`ui/src/components/onboarding/MobileDesktopNudge.tsx`
(`onboarding_mobile_handoff_action`), and
`ui/src/components/OnboardingWizard.tsx` (all step submissions,
back/jump navigation, Cloud trial CTA, model source selection,
credential mode switching, OAuth progress stages, API key submission,
advanced toggle, and launch click). Note: `OnboardingWizard.tsx` is an
existing large file (>1,000 lines); all schema and transport logic lives
in `packages/shared/src/onboarding-telemetry.ts` and
`ui/src/lib/analytics/onboarding-analytics.ts`, with only call-site
wiring added to the wizard.
- Fixed `ui/src/lib/analytics/product-analytics.ts` to buffer events
captured before `startProductAnalytics` runs (still bounded to 50 events
and cleared on user change).
- Added server route tests in
`server/src/__tests__/onboarding-telemetry-routes.test.ts` and expanded
`ui/src/lib/analytics/onboarding-analytics.test.tsx`.
- Updated `tests/runner-e2e/source-sdk-public-inputs.json` for the new
`@paperclipai/shared` export.
## Verification
- `pnpm --filter @paperclipai/shared build` — passed.
- `pnpm --filter @paperclipai/ui typecheck` — passed.
- `pnpm --filter @paperclipai/server typecheck` — passed.
- `pnpm vitest run
server/src/__tests__/onboarding-telemetry-routes.test.ts
ui/src/lib/analytics/onboarding-analytics.test.tsx
ui/src/lib/analytics/product-analytics.test.ts
ui/src/lib/analytics/product-analytics-events.test.ts
ui/src/components/ProductAnalyticsGate.test.tsx
ui/src/hooks/useAgentlessOnboardingAutoOpen.test.tsx` — 6/6 test files
passed (41/41 tests).
- `pnpm verify` — exited with code 2 because
`tests/runner-e2e/source-sdk-public-inputs.json` requires broad CI
coverage; relying on required CI checks for the remaining broad suites.
## Risks
- Low risk: `POST /api/onboarding/telemetry` performs no database
writes, validates all fields against a strict allowlist (enums,
booleans, bounded integers, safe regex slugs), enforces board auth and
company access, and is a no-op returning `204` on self-hosted instances.
- Browser telemetry calls swallow network failures so analytics can
never block or break onboarding.
## Model Used
- Google Gemini (Gemini 4 Neon, Medium) via Antigravity agentic coding
environment with tool use and local command execution.
## Checklist
- [x] I have included a thinking path that traces from project context
to this change
- [x] I have specified the model used (with version and capability
details)
- [x] I have checked ROADMAP.md and confirmed this PR does not duplicate
planned core work
- [x] I have searched GitHub for duplicate or related PRs and linked
them above
- [x] I have either (a) linked existing issues with `Fixes: #` / `Closes
#` / `Refs #` OR (b) described the issue in-PR following the relevant
issue template
- [x] I have not referenced internal/instance-local Paperclip issues or
links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip`
URLs)
- [x] My branch name describes the change (e.g. `docs/...`, `fix/...`)
and contains no internal Paperclip ticket id or instance-derived details
- [x] I have run tests locally and they pass
- [x] I have added or updated tests where applicable
- [x] I have updated relevant documentation to reflect my changes
- [x] I have considered and documented any risks above
- [ ] All Paperclip CI gates are green
- [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [x] I will address all Greptile and reviewer comments before
requesting merge
415 lines
16 KiB
TypeScript
415 lines
16 KiB
TypeScript
// @vitest-environment jsdom
|
|
|
|
import { act, createElement } from "react";
|
|
import { createRoot } from "react-dom/client";
|
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
import {
|
|
ADAPTER_AUTH_MISSING_CHECK_CODE,
|
|
onboardingTelemetryEventSchema,
|
|
type BrowserAnalyticsConfig,
|
|
type OnboardingTelemetryEventInput,
|
|
} from "@paperclipai/shared";
|
|
import { blocksAgentCreate } from "@/lib/onboarding-connection-test";
|
|
import { isReportableAdapterLoginFailure } from "@/components/AgentConfigForm";
|
|
import {
|
|
captureProductAnalyticsEvent,
|
|
resetProductAnalyticsForTest,
|
|
setProductAnalyticsUser,
|
|
startProductAnalytics,
|
|
type ProductAnalyticsClient,
|
|
} from "./product-analytics";
|
|
import {
|
|
captureAgentChatMessageSent,
|
|
captureOnboardingAdvancedToggled,
|
|
captureOnboardingApiKeySubmitted,
|
|
captureOnboardingCredentialModeSwitched,
|
|
captureOnboardingLaunchClicked,
|
|
captureOnboardingMobileHandoffAction,
|
|
captureOnboardingModelSourceSelected,
|
|
captureOnboardingOAuthProgress,
|
|
captureOnboardingStepCompleted,
|
|
captureOnboardingStepFailed,
|
|
captureOnboardingStepNavigated,
|
|
captureOnboardingStepSubmitted,
|
|
captureOnboardingTrialCtaClicked,
|
|
captureOnboardingWorkspaceLoaded,
|
|
resetOnboardingTelemetryForTest,
|
|
setOnboardingTelemetrySenderForTest,
|
|
useOnboardingAnalytics,
|
|
type OnboardingAnalyticsOutcome,
|
|
} from "./onboarding-analytics";
|
|
|
|
(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
|
|
|
|
const unmounts: Array<() => void> = [];
|
|
|
|
function renderHook<R, P>(callback: (props: P) => R, options: { initialProps: P }) {
|
|
const host = document.createElement("div");
|
|
document.body.append(host);
|
|
const root = createRoot(host);
|
|
let props = options.initialProps;
|
|
const result = {} as { current: R };
|
|
function Harness() {
|
|
result.current = callback(props);
|
|
return null;
|
|
}
|
|
function rerender(next: P = props) {
|
|
props = next;
|
|
act(() => root.render(createElement(Harness)));
|
|
}
|
|
unmounts.push(() => {
|
|
act(() => root.unmount());
|
|
host.remove();
|
|
});
|
|
rerender();
|
|
return { result, rerender };
|
|
}
|
|
|
|
const config: BrowserAnalyticsConfig = {
|
|
token: "phc_test",
|
|
apiHost: "/_ph",
|
|
uiHost: "https://us.posthog.com",
|
|
environment: "staging",
|
|
stackId: "stack-1",
|
|
replayEnabled: false,
|
|
};
|
|
|
|
function mockClient() {
|
|
return {
|
|
init: vi.fn(),
|
|
register: vi.fn(),
|
|
identify: vi.fn(),
|
|
group: vi.fn(),
|
|
reset: vi.fn(),
|
|
capture: vi.fn(),
|
|
opt_out_capturing: vi.fn(),
|
|
opt_in_capturing: vi.fn(),
|
|
};
|
|
}
|
|
|
|
async function flush() {
|
|
await Promise.resolve();
|
|
await Promise.resolve();
|
|
}
|
|
|
|
let client: ReturnType<typeof mockClient>;
|
|
let scheduled: (() => void) | null;
|
|
let sentServerEvents: OnboardingTelemetryEventInput[];
|
|
const load = () => Promise.resolve(client as unknown as ProductAnalyticsClient);
|
|
const schedule = (start: () => void) => {
|
|
scheduled = start;
|
|
return () => { scheduled = null; };
|
|
};
|
|
|
|
function capturedBrowser() {
|
|
return client.capture.mock.calls.map(([event, properties]) => [event, properties]);
|
|
}
|
|
|
|
beforeEach(() => {
|
|
client = mockClient();
|
|
scheduled = null;
|
|
sentServerEvents = [];
|
|
setOnboardingTelemetrySenderForTest((payload) => {
|
|
// Every payload emitted by the UI must pass the server's strict Zod contract.
|
|
sentServerEvents.push(onboardingTelemetryEventSchema.parse(payload));
|
|
});
|
|
});
|
|
|
|
afterEach(() => {
|
|
for (const unmount of unmounts.splice(0)) unmount();
|
|
resetProductAnalyticsForTest();
|
|
resetOnboardingTelemetryForTest();
|
|
});
|
|
|
|
describe("browser product events", () => {
|
|
it("captures nothing when browser analytics is off", async () => {
|
|
captureProductAnalyticsEvent("ui_interaction", { surface: "test" });
|
|
await flush();
|
|
expect(client.capture).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("holds events captured before startProductAnalytics and flushes them once posthog-js loads", async () => {
|
|
captureProductAnalyticsEvent("early_event", { step: "create_agent" });
|
|
startProductAnalytics(config, { load, schedule });
|
|
expect(client.capture).not.toHaveBeenCalled();
|
|
scheduled!();
|
|
await flush();
|
|
expect(client.capture).toHaveBeenCalledTimes(1);
|
|
expect(client.capture).toHaveBeenCalledWith(
|
|
"early_event",
|
|
{ step: "create_agent" },
|
|
{ timestamp: expect.any(Date) },
|
|
);
|
|
});
|
|
|
|
it("holds events from before posthog-js loads and sends them with their own time", async () => {
|
|
startProductAnalytics(config, { load, schedule });
|
|
captureProductAnalyticsEvent("onboarding_opened", { step: "create_agent" });
|
|
expect(client.capture).not.toHaveBeenCalled();
|
|
scheduled!();
|
|
await flush();
|
|
expect(client.capture).toHaveBeenCalledTimes(1);
|
|
expect(client.capture).toHaveBeenCalledWith(
|
|
"onboarding_opened",
|
|
{ step: "create_agent" },
|
|
{ timestamp: expect.any(Date) },
|
|
);
|
|
});
|
|
|
|
it("bounds the pre-load queue to 50 events", async () => {
|
|
startProductAnalytics(config, { load, schedule });
|
|
for (let index = 0; index < 50; index++) {
|
|
captureProductAnalyticsEvent("onboarding_step_viewed", { step: "create_agent" });
|
|
}
|
|
captureProductAnalyticsEvent("onboarding_step_viewed", { step: "review" });
|
|
scheduled!();
|
|
await flush();
|
|
expect(client.capture).toHaveBeenCalledTimes(50);
|
|
expect(capturedBrowser()).not.toContainEqual(["onboarding_step_viewed", { step: "review" }]);
|
|
});
|
|
|
|
it("drops held events on a person change before posthog-js loads", async () => {
|
|
setProductAnalyticsUser({ id: "user-1", email: null, name: null });
|
|
startProductAnalytics(config, { load, schedule });
|
|
captureProductAnalyticsEvent("onboarding_opened", { step: "create_agent" });
|
|
setProductAnalyticsUser(null);
|
|
setProductAnalyticsUser({ id: "user-2", email: null, name: null });
|
|
captureProductAnalyticsEvent("onboarding_opened", { step: "connect_model" });
|
|
scheduled!();
|
|
await flush();
|
|
expect(capturedBrowser()).toEqual([["onboarding_opened", { step: "connect_model" }]]);
|
|
expect(client.identify).toHaveBeenCalledWith("user-2", {});
|
|
});
|
|
|
|
it("keeps held events when the same person is set again before posthog-js loads", async () => {
|
|
setProductAnalyticsUser({ id: "user-1", email: null, name: null });
|
|
startProductAnalytics(config, { load, schedule });
|
|
captureProductAnalyticsEvent("onboarding_opened", { step: "create_agent" });
|
|
setProductAnalyticsUser({ id: "user-1", email: "jane@example.com", name: null });
|
|
scheduled!();
|
|
await flush();
|
|
expect(capturedBrowser()).toEqual([["onboarding_opened", { step: "create_agent" }]]);
|
|
});
|
|
});
|
|
|
|
describe("server-side onboarding funnel events", () => {
|
|
function renderWizard(initial: { open: boolean; step: number }) {
|
|
return renderHook(
|
|
(props: { open: boolean; step: number; connectOutcome: OnboardingAnalyticsOutcome }) =>
|
|
useOnboardingAnalytics(props),
|
|
{ initialProps: { ...initial, connectOutcome: "subscription" as OnboardingAnalyticsOutcome } },
|
|
);
|
|
}
|
|
|
|
it("sends each wizard transition server-side (never via posthog-js), including Step 1 name_org -> Step 3 create_agent", () => {
|
|
const wizard = renderWizard({ open: false, step: 1 });
|
|
wizard.rerender({ open: true, step: 1, connectOutcome: "subscription" });
|
|
act(() => wizard.result.current.opened(1, 1, { source: "manual", isMobile: false }));
|
|
wizard.rerender({ open: true, step: 3, connectOutcome: "subscription" });
|
|
wizard.rerender({ open: true, step: 3, connectOutcome: "subscription" });
|
|
wizard.rerender({ open: true, step: 4, connectOutcome: "subscription" });
|
|
wizard.rerender({ open: true, step: 4, connectOutcome: "api_key" });
|
|
wizard.rerender({ open: true, step: 5, connectOutcome: "api_key" });
|
|
captureOnboardingStepCompleted("review");
|
|
captureOnboardingStepCompleted("launch", "succeeded");
|
|
act(() => wizard.result.current.finished());
|
|
wizard.rerender({ open: false, step: 1, connectOutcome: "subscription" });
|
|
|
|
expect(client.capture).not.toHaveBeenCalled();
|
|
expect(sentServerEvents).toEqual([
|
|
{ event: "onboarding_opened", step: "name_org", source: "manual", isMobile: false },
|
|
{ event: "onboarding_step_viewed", step: "name_org" },
|
|
{ event: "onboarding_step_completed", step: "name_org" },
|
|
{ event: "onboarding_step_viewed", step: "create_agent" },
|
|
{ event: "onboarding_step_completed", step: "create_agent" },
|
|
{ event: "onboarding_step_viewed", step: "connect_model" },
|
|
{ event: "onboarding_step_completed", step: "connect_model", outcome: "api_key" },
|
|
{ event: "onboarding_step_viewed", step: "review" },
|
|
{ event: "onboarding_step_completed", step: "review" },
|
|
{ event: "onboarding_step_completed", step: "launch", outcome: "succeeded" },
|
|
]);
|
|
});
|
|
|
|
it("does not count a stale step from the opening render as a view", () => {
|
|
const wizard = renderWizard({ open: true, step: 5 });
|
|
act(() => wizard.result.current.opened(3, 5));
|
|
wizard.rerender({ open: true, step: 5, connectOutcome: "subscription" });
|
|
wizard.rerender({ open: true, step: 3, connectOutcome: "subscription" });
|
|
|
|
expect(sentServerEvents).toEqual([
|
|
{ event: "onboarding_opened", step: "create_agent" },
|
|
{ event: "onboarding_step_viewed", step: "create_agent" },
|
|
]);
|
|
});
|
|
|
|
it("captures a dismissal once and a reopen as a new session", () => {
|
|
const wizard = renderWizard({ open: true, step: 4 });
|
|
act(() => wizard.result.current.opened(4, 4));
|
|
act(() => wizard.result.current.opened(4, 4));
|
|
act(() => wizard.result.current.dismissed(4));
|
|
act(() => wizard.result.current.dismissed(4));
|
|
wizard.rerender({ open: false, step: 1, connectOutcome: "subscription" });
|
|
wizard.rerender({ open: true, step: 1, connectOutcome: "subscription" });
|
|
act(() => wizard.result.current.opened(3, 1));
|
|
|
|
expect(sentServerEvents).toEqual([
|
|
{ event: "onboarding_opened", step: "connect_model" },
|
|
{ event: "onboarding_step_viewed", step: "connect_model" },
|
|
{ event: "onboarding_dismissed", step: "connect_model", method: "close_button" },
|
|
{ event: "onboarding_opened", step: "create_agent" },
|
|
{ event: "onboarding_step_viewed", step: "create_agent" },
|
|
]);
|
|
});
|
|
|
|
it("captures a dismissal when the wizard closes before launch", () => {
|
|
const wizard = renderWizard({ open: true, step: 3 });
|
|
act(() => wizard.result.current.opened(3, 3));
|
|
wizard.rerender({ open: true, step: 4, connectOutcome: "subscription" });
|
|
wizard.rerender({ open: false, step: 1, connectOutcome: "subscription" });
|
|
wizard.rerender({ open: false, step: 1, connectOutcome: "subscription" });
|
|
|
|
expect(sentServerEvents).toEqual([
|
|
{ event: "onboarding_opened", step: "create_agent" },
|
|
{ event: "onboarding_step_viewed", step: "create_agent" },
|
|
{ event: "onboarding_step_completed", step: "create_agent" },
|
|
{ event: "onboarding_step_viewed", step: "connect_model" },
|
|
{ event: "onboarding_dismissed", step: "connect_model", method: "unmount" },
|
|
]);
|
|
});
|
|
|
|
it("captures structured onboarding failures and drops unsafe provider strings", () => {
|
|
captureOnboardingStepFailed({
|
|
step: "connect_model",
|
|
reason: "api_key_save_failed",
|
|
provider: "Anthropic",
|
|
method: "api_key",
|
|
});
|
|
captureOnboardingStepFailed({
|
|
step: "connect_model",
|
|
reason: "subscription_login_failed",
|
|
provider: "secret token=sk-123",
|
|
method: "subscription",
|
|
});
|
|
captureOnboardingStepFailed({
|
|
step: "launch",
|
|
reason: "greeting_failed",
|
|
});
|
|
expect(sentServerEvents).toEqual([
|
|
{ event: "onboarding_step_failed", step: "connect_model", reason: "api_key_save_failed", provider: "anthropic", method: "api_key" },
|
|
{ event: "onboarding_step_failed", step: "connect_model", reason: "subscription_login_failed", method: "subscription" },
|
|
{ event: "onboarding_step_failed", step: "launch", reason: "greeting_failed" },
|
|
]);
|
|
});
|
|
|
|
it("captures granular onboarding interaction events matching the server schema", () => {
|
|
const companyId = "11111111-1111-4111-8111-111111111111";
|
|
captureOnboardingWorkspaceLoaded({
|
|
companyId,
|
|
hasCompany: true,
|
|
hasAgent: false,
|
|
willAutoOpen: true,
|
|
isMobile: false,
|
|
});
|
|
captureOnboardingStepSubmitted({ step: "create_agent", via: "button", companyId });
|
|
captureOnboardingStepNavigated({
|
|
fromStep: "connect_model",
|
|
toStep: "create_agent",
|
|
direction: "back",
|
|
via: "back_button",
|
|
companyId,
|
|
});
|
|
captureOnboardingMobileHandoffAction({ action: "copy_link", companyId });
|
|
captureOnboardingTrialCtaClicked({ companyId });
|
|
captureOnboardingModelSourceSelected({
|
|
adapterType: "claude_local",
|
|
provider: "anthropic",
|
|
credentialMode: "subscription",
|
|
companyId,
|
|
});
|
|
captureOnboardingCredentialModeSwitched({
|
|
fromMode: "subscription",
|
|
toMode: "api_key",
|
|
adapterType: "claude_local",
|
|
companyId,
|
|
});
|
|
captureOnboardingOAuthProgress({
|
|
stage: "auth_link_opened",
|
|
provider: "anthropic",
|
|
adapterType: "claude_local",
|
|
phase: "ready",
|
|
companyId,
|
|
});
|
|
captureOnboardingApiKeySubmitted({
|
|
provider: "anthropic",
|
|
adapterType: "claude_local",
|
|
usedSavedKey: false,
|
|
companyId,
|
|
});
|
|
captureOnboardingAdvancedToggled({ adapterType: "claude_local", open: true, companyId });
|
|
captureOnboardingLaunchClicked({
|
|
adapterType: "claude_local",
|
|
provider: "anthropic",
|
|
outcome: "subscription",
|
|
companyId,
|
|
});
|
|
captureAgentChatMessageSent("onboarding_chat", { companyId });
|
|
captureAgentChatMessageSent("agent_chat");
|
|
|
|
expect(sentServerEvents.map((e) => e.event)).toEqual([
|
|
"onboarding_workspace_loaded",
|
|
"onboarding_step_submitted",
|
|
"onboarding_step_navigated",
|
|
"onboarding_mobile_handoff_action",
|
|
"onboarding_trial_cta_clicked",
|
|
"onboarding_model_source_selected",
|
|
"onboarding_credential_mode_switched",
|
|
"onboarding_oauth_progress",
|
|
"onboarding_api_key_submitted",
|
|
"onboarding_advanced_toggled",
|
|
"onboarding_launch_clicked",
|
|
"agent_chat_message_sent",
|
|
"agent_chat_message_sent",
|
|
]);
|
|
});
|
|
|
|
it("blocksAgentCreate flags fail results and warn/pass results with missing-auth checks", () => {
|
|
const base = {
|
|
adapterType: "codex_local",
|
|
testedAt: "2026-01-01T00:00:00.000Z",
|
|
};
|
|
expect(blocksAgentCreate({ ...base, status: "fail", checks: [] })).toBe(true);
|
|
expect(
|
|
blocksAgentCreate({
|
|
...base,
|
|
status: "warn",
|
|
checks: [{ code: ADAPTER_AUTH_MISSING_CHECK_CODE, level: "warn", message: "Auth required" }],
|
|
}),
|
|
).toBe(true);
|
|
expect(
|
|
blocksAgentCreate({
|
|
...base,
|
|
status: "pass",
|
|
checks: [{ code: ADAPTER_AUTH_MISSING_CHECK_CODE, level: "warn", message: "Auth required" }],
|
|
}),
|
|
).toBe(true);
|
|
expect(
|
|
blocksAgentCreate({
|
|
...base,
|
|
status: "warn",
|
|
checks: [{ code: "other_warning", level: "warn", message: "Non-blocking warning" }],
|
|
}),
|
|
).toBe(false);
|
|
expect(blocksAgentCreate({ ...base, status: "pass", checks: [] })).toBe(false);
|
|
});
|
|
|
|
it("isReportableAdapterLoginFailure covers start/poll/timeout failures and excludes cancellation and retries", () => {
|
|
expect(isReportableAdapterLoginFailure({ active: true, retrying: false, status: "failed", hasFailure: true })).toBe(true);
|
|
expect(isReportableAdapterLoginFailure({ active: true, retrying: false, status: "timed_out", hasFailure: true })).toBe(true);
|
|
expect(isReportableAdapterLoginFailure({ active: true, retrying: false, status: undefined, hasFailure: true })).toBe(true);
|
|
expect(isReportableAdapterLoginFailure({ active: true, retrying: false, status: "cancelled", hasFailure: true })).toBe(false);
|
|
expect(isReportableAdapterLoginFailure({ active: true, retrying: true, status: "failed", hasFailure: true })).toBe(false);
|
|
expect(isReportableAdapterLoginFailure({ active: false, retrying: false, status: "failed", hasFailure: true })).toBe(false);
|
|
expect(isReportableAdapterLoginFailure({ active: true, retrying: false, status: "waiting_for_user", hasFailure: false })).toBe(false);
|
|
});
|
|
});
|