Files
PaperClipAI/tests/e2e
DottaandClaude Opus 5.5 eca1472bae test(e2e): stop Cloud auth health stub from reading a disposed response (#21150)
## 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>
2026-11-12 12:17:57 -06:00
..