mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-16 03:31:44 +01:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - The e2e suite proves that a Cloud tenant returns to its task after Cloud sign-in > - `tests/e2e/cloud-auth.spec.ts` "Cloud recovery preserves the task" failed in CI e2e shards on at least 6 unrelated PR branches in 48 hours > - The error was `apiResponse.json: Response has been disposed`, which blocks unrelated PRs and hides real failures > - The `/api/health` route stub called `route.fetch()` and `response.json()` for each health request. A health request that started just before the test ended kept that handler in flight. Context teardown then disposed the fetched response, and the handler failed. > - This pull request reads the real health payload one time through the test-scoped `request` fixture and fulfills each intercepted health request from that snapshot > - The benefit is that no route handler does network work that can outlive the browser context, so the test cannot fail at teardown ## Linked Issues or Issue Description **What happened?** `Cloud recovery preserves the task (https://my.paperclip.app, task|auth)` and `(https://my-staging.paperclip.app, task)` failed intermittently in CI with `Error: apiResponse.json: Response has been disposed` at the `/api/health` route handler. **Steps to reproduce** 1. Route `/api/health` with a handler that awaits `route.fetch()` and then `response.json()`. 2. Start a `/api/health` fetch in the page just before the test ends. 3. The browser context closes while the handler is in flight. Playwright disposes the fetched response, and the handler throws. **Expected behavior** The test passes when the UI starts a health request near the end of the test. **Root cause** Playwright stores `route.fetch()` response bodies on the browser context request context. Context close clears them (`fetchResponses.clear()`), so `response.json()` (or `route.fetch()` itself, with "Test ended") fails in any handler that is still running. The UI fetches health from several components on mount and after reload, so a request is sometimes in flight at teardown. ## What Changed - `tests/e2e/cloud-auth.spec.ts`: get `/api/health` one time through the test `request` fixture, add the Cloud overrides, and fulfill intercepted health requests from that snapshot. The route handler no longer calls `route.fetch()`. - The snapshot also sets `status: "ok"`. A snapshot taken during startup recovery reports `starting`, which would keep the Cloud gate on the starting screen for the whole test. ## Verification - Before the fix: `PAPERCLIP_E2E_PORT=3293 npx playwright test --config tests/e2e/playwright.config.ts tests/e2e/cloud-auth.spec.ts -g "Cloud recovery" --repeat-each=30` gave 119 passed, 1 failed (`route.fetch: Test ended ... while running route callback` in the `/api/health` handler, the same teardown race). - Deterministic red/green probe (temporary spec, not committed): the page fires five `/api/health` fetches as the last step of the test. With the old handler: 15/15 failed with the exact CI error `apiResponse.json: Response has been disposed`. With the snapshot handler: 15/15 passed. - After the fix: `PAPERCLIP_E2E_PORT=3293 npx playwright test --config tests/e2e/playwright.config.ts tests/e2e/cloud-auth.spec.ts --repeat-each=30` gave 150 passed, 0 failed (120 Cloud recovery runs plus 30 self-hosted runs). After the `status: "ok"` follow-up: `--repeat-each=10` gave 50 passed, 0 failed. ## Risks - Low risk. Test-only change. The health payload is now a snapshot taken at the start of the test, not a live read. The test only depends on the overridden Cloud fields, and the other health fields do not change during one test. > For core feature work, check [`ROADMAP.md`](ROADMAP.md) first and discuss it in `#dev` before opening the PR. Feature PRs that overlap with planned core work may need to be redirected — check the roadmap first. See `CONTRIBUTING.md`. ## Model Used - Anthropic Claude Opus 5.5 (`claude-opus-5-5`), running in Claude Code as an agent with tool use (shell, file edit, Playwright runs). Standard context window, extended reasoning enabled. ## 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 - [ ] 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 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
69 lines
4.0 KiB
TypeScript
69 lines
4.0 KiB
TypeScript
import { randomUUID } from "node:crypto";
|
|
import { expect, test } from "@playwright/test";
|
|
|
|
test.use({ trace: "retain-on-failure" });
|
|
|
|
// The tenant UI and task database are real. Cloud is an external dependency:
|
|
// simulate its entry endpoint and independent session states at the HTTP edge.
|
|
for (const cloudOrigin of ["https://my.paperclip.app", "https://my-staging.paperclip.app"]) {
|
|
for (const entry of ["auth", "task"] as const) {
|
|
test(`Cloud recovery preserves the task (${cloudOrigin}, ${entry})`, async ({ page, request, baseURL }, testInfo) => {
|
|
const companyResponse = await request.post("/api/companies", { data: { name: `Cloud auth ${randomUUID()}` } });
|
|
expect(companyResponse.ok()).toBe(true);
|
|
const company = await companyResponse.json();
|
|
const issueResponse = await request.post(`/api/companies/${company.id}/issues`, {
|
|
data: { title: "Return here after Cloud sign-in", status: "backlog" },
|
|
});
|
|
expect(issueResponse.ok()).toBe(true);
|
|
const issue = await issueResponse.json();
|
|
const target = `/${company.issuePrefix}/issues/${issue.identifier}?view=activity#recovered`;
|
|
let authenticated = false;
|
|
let handoffs = 0;
|
|
let formWasRendered = false;
|
|
await page.exposeFunction("reportInstanceLoginForm", () => { formWasRendered = true; });
|
|
await page.addInitScript(() => {
|
|
new MutationObserver(() => {
|
|
if (document.querySelector('input[autocomplete="current-password"]')) {
|
|
void (window as unknown as { reportInstanceLoginForm: () => Promise<void> }).reportInstanceLoginForm();
|
|
}
|
|
}).observe(document, { childList: true, subtree: true });
|
|
});
|
|
const healthResponse = await request.get("/api/health");
|
|
expect(healthResponse.ok()).toBe(true);
|
|
const cloudHealth = {
|
|
...await healthResponse.json(), status: "ok", deploymentMode: "authenticated", bootstrapStatus: "ready",
|
|
cloud: { managed: true, managedBy: "paperclip-cloud", cloudBaseUrl: cloudOrigin, stackSlug: "test-workspace" },
|
|
};
|
|
await page.route("**/api/health", (route) => route.fulfill({ json: cloudHealth }));
|
|
await page.route("**/api/auth/get-session", (route) => route.fulfill(authenticated ? {
|
|
json: { session: { id: "test-session", userId: "local-board" }, user: { id: "local-board", email: "test@example.test", name: "Test user", image: null }, sentryDsn: null },
|
|
} : { status: 401, json: { error: "Board authentication required" } }));
|
|
await page.route(`${cloudOrigin}/v1/stacks/test-workspace/entry-redirect?**`, async (route) => {
|
|
handoffs++;
|
|
expect(new URL(route.request().url()).searchParams.get("returnTo")).toBe(target);
|
|
authenticated = true;
|
|
await route.fulfill({ status: 302, headers: { Location: `${baseURL}${target}` } });
|
|
});
|
|
const returnedFromCloud = page.waitForURL((url) => handoffs === 1 && url.href === `${baseURL}${target}`);
|
|
await page.goto(entry === "auth" ? `/auth?next=${encodeURIComponent(target)}` : target);
|
|
await returnedFromCloud;
|
|
await expect(page.getByRole("heading", { name: issue.title, exact: true })).toBeVisible();
|
|
expect(page.url()).toBe(`${baseURL}${target}`);
|
|
expect(handoffs).toBe(1);
|
|
expect(formWasRendered).toBe(false);
|
|
await page.screenshot({ path: testInfo.outputPath("cloud-session-recovered.png") });
|
|
await page.reload();
|
|
await expect(page.getByRole("heading", { name: issue.title, exact: true })).toBeVisible();
|
|
expect(handoffs).toBe(1);
|
|
expect(formWasRendered).toBe(false);
|
|
});
|
|
}
|
|
}
|
|
|
|
test("self-hosted auth still shows the instance sign-in form", async ({ page }) => {
|
|
await page.route("**/api/auth/get-session", (route) => route.fulfill({ status: 401, json: { error: "Board authentication required" } }));
|
|
await page.goto("/auth");
|
|
await expect(page.getByRole("heading", { name: "Sign in to Paperclip", exact: true })).toBeVisible();
|
|
await expect(page.getByLabel("Password", { exact: true })).toBeVisible();
|
|
});
|