Files
PaperClipAI/tests/e2e/onboarding-subscription-models.spec.ts
T
Devin FoleyandPaperclip 6e340a3f96 Verify onboarding models and explain provider failures (#23563)
Verify deployment-configured model preferences with the selected account.
Preserve structured provider failures and show descriptive messages for known
causes through the existing onboarding error display. Keep the existing failure
buttons, account binding, and retry/sign-in behavior.

Validation: UI typecheck, 38 focused tests, four browser journeys, all applicable
CI checks, and Greptile 5/5 with no unresolved review comments.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-12-02 16:47:58 -08:00

113 lines
6.9 KiB
TypeScript

import { randomUUID } from "node:crypto";
import { expect, test, type Page } from "@playwright/test";
type Outcome = "pass" | "fallback" | "quota_exhausted" | "auth_required" | "unknown";
const genericError = "The environment test failed. Fix the reported checks before you hire this agent.";
const messages = {
quota_exhausted: "Your account has no usage remaining. Check your plan's limits or available credits.",
auth_required: "Your sign-in could not be verified. Please sign in again.",
model_unavailable: "Your account does not have access to the selected model.",
unknown: "",
};
async function setup(page: Page, provider: "Claude" | "OpenAI", initialOutcome: Outcome) {
const response = await page.request.post("/api/companies", { data: { name: `Model verification ${randomUUID()}` } });
expect(response.ok()).toBe(true);
const company = await response.json();
const accounts = ["anthropic", "openai"].map(provider => ({
id: randomUUID(), grantId: randomUUID(), companyId: company.id, provider,
method: "subscription", name: "Personal account", ownership: "personal", ownerUserId: "local-board", status: "connected", isDefault: true,
}));
const candidates = { claude_local: ["claude-opus-5-5", "claude-sonnet-5-5"], codex_local: ["gpt-6.1-sol", "gpt-6-luna"] };
const probes: Array<{ provider: string; model: string }> = [];
const hires: Array<Record<string, any>> = [];
const newSignIns: unknown[] = [], removals: string[] = [];
let agent: Record<string, any> | undefined;
let outcome = initialOutcome;
await page.addInitScript(({ company }) => localStorage.setItem("paperclip-onboarding-state", JSON.stringify({
step: 3, companyName: company.name, createdCompanyId: company.id, createdCompanyPrefix: company.issuePrefix,
agentName: "Recovery lead", agentRole: "general",
})), { company });
await page.route("**/api/health", async route => {
const response = await route.fetch();
await route.fulfill({ response, json: { ...await response.json(), onboardingModels: candidates } });
});
await page.route("**/api/adapters**", async route => {
const response = await route.fetch();
const rows = await response.json();
await route.fulfill({ response, json: rows.map((row: any) => ({ ...row, defaultRunner: "legacy", supportedRunners: ["legacy"] })) });
});
await page.route(`**/companies/${company.id}/ai-connections`, route => route.fulfill({ json: {
currentUserId: "local-board", canManageConnections: true, connections: accounts,
} }));
await page.route(`**/companies/${company.id}/ai-connections/default`, route => route.fulfill({ json: { ok: true } }));
await page.route("**/ai-connections/local/attempts", route => {
newSignIns.push(route.request().postDataJSON());
return route.fulfill({ json: { sessionId: "unexpected-login", expiresAt: "2099-01-01T00:00:00Z" } });
});
await page.route("**/tool-connections/*", route => {
if (route.request().method() !== "DELETE") return route.continue();
removals.push(route.request().url());
return route.fulfill({ json: { removal: { providerAccess: "revoked" } } });
});
await page.route("**/api/agents/*", async route => {
if (!agent || !route.request().url().includes(agent.id)) return route.continue();
if (route.request().method() === "PATCH") agent = { ...agent, ...route.request().postDataJSON() };
await route.fulfill({ json: agent });
});
await page.route(`**/companies/${company.id}/agent-hires`, async route => {
hires.push(route.request().postDataJSON());
await route.fulfill({ json: { agent: { ...agent, ...hires.at(-1), status: "idle" }, approval: null } });
});
await page.route("**/adapters/*/test-environment", async route => {
const request = route.request().postDataJSON();
const adapter = route.request().url().includes("claude_local") ? "claude_local" : "codex_local";
const model = request.adapterConfig.model;
probes.push({ provider: adapter, model });
const reason = outcome === "fallback" ? model === candidates[adapter][0] ? "model_unavailable" : null
: outcome === "pass" ? null : outcome;
await route.fulfill({ json: { adapterType: "paperclip_runner", testedAt: "2099-01-01", status: reason ? "fail" : "pass",
checks: [{ code: reason ? `runner_hello_probe_${reason === "unknown" ? "failed" : reason}` : "runner_hello_probe_passed",
level: reason ? "error" : "info", message: reason ? messages[reason] : "Verified" }] } });
});
const created = page.waitForResponse(response => response.request().method() === "POST"
&& response.url().endsWith(`/companies/${company.id}/agents`));
await page.goto("/onboarding");
await page.locator("#onboarding-agent-name").fill("Recovery lead");
await page.getByRole("button", { name: "Next", exact: true }).click();
agent = await (await created).json();
await page.getByRole("radio", { name: new RegExp(provider) }).click();
return { candidates, probes, hires, newSignIns, removals, setOutcome: (value: Outcome) => { outcome = value; } };
}
test("onboarding saves the model that passes the selected account's check", async ({ page }) => {
const fixture = await setup(page, "Claude", "fallback");
await expect.poll(() => fixture.hires.length).toBe(1);
expect(fixture.probes).toEqual(fixture.candidates.claude_local.map(model => ({ provider: "claude_local", model })));
expect(fixture.hires[0]).toMatchObject({ name: "Recovery lead", adapterConfig: { model: "claude-sonnet-5-5" } });
});
for (const scenario of [
{ provider: "Claude", reason: "quota_exhausted", message: messages.quota_exhausted },
{ provider: "OpenAI", reason: "auth_required", message: messages.auth_required },
{ provider: "Claude", reason: "unknown", message: genericError },
] as const) {
test(`${scenario.provider} ${scenario.reason} keeps existing failure controls and displays the available error`, async ({ page }) => {
const fixture = await setup(page, scenario.provider, scenario.reason);
await expect(page.getByText(scenario.message, { exact: true }).first()).toBeVisible();
if (scenario.reason !== "unknown") await expect(page.getByText(genericError, { exact: true })).toHaveCount(0);
expect(fixture.probes).toHaveLength(1);
expect(fixture.hires).toHaveLength(0);
await expect(page.getByRole("button", { name: "Back", exact: true })).toBeVisible();
await expect(page.getByRole("button", { name: "Connect", exact: true })).toBeEnabled();
await expect(page.getByRole("button", { name: /Use another subscription|Remove this connection|Sign in to another account|Change provider/ })).toHaveCount(0);
fixture.setOutcome("pass");
await page.getByRole("button", { name: "Connect", exact: true }).click();
await expect.poll(() => fixture.hires.length).toBe(1);
expect(fixture.probes).toHaveLength(2);
expect(fixture.hires[0]).toMatchObject({ name: "Recovery lead" });
expect(fixture.newSignIns).toHaveLength(0);
expect(fixture.removals).toHaveLength(0);
});
}