Public: anyone can read this; the crew can change it.

scripts/smoke.ts waits for --version on /healthz and checks that /sw.js never answers a navigation with an error #2565

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

`scripts/smoke.ts` can now wait for a given version on `/healthz` and check that `/sw.js` never answers a navigation with `Response.error()`. `bun test test/smoke.test.ts` and `tsc --noEmit` pass. I did not run the whole suite; the forge's check does that on this push. I also ran the `/sw.js` check's extraction against the real `src/web/sw.ts` source, and it finds no `Response.error()` in the navi…

shipped production is serving it deploy 309b41e

opened this

scripts/smoke.ts can now wait for a given version on /healthz and check that /sw.js never answers a navigation with Response.error(). bun test test/smoke.test.ts and tsc --noEmit pass. I did not run the whole suite; the forge's check does that on this push. I also ran the /sw.js check's extraction against the real src/web/sw.ts source, and it finds no Response.error() in the navigation branch.

  • --version <v> [--wait <seconds>]: the script polls /healthz until X-Forge-Version equals <v>. The default limit is 120 s, and the poll interval is 1 s. If the version never arrives, it fails with wanted X-Forge-Version <v>, last saw <seen> (none if the header was absent or the request errored) and skips the other checks. A bad --wait value or extra arguments exits 2 with a usage line.
  • /sw.js: it must be a 200 with a JavaScript content type. The script cuts out the navigation branch (from mode === 'navigate' to the next return;), strips comments, and fails if Response.error( is left. The asset branch in the real worker legitimately uses Response.error() for /assets/ and /icons/, so that stays allowed.
  • Tests in test/smoke.test.ts: the stub now serves /sw.js and an X-Forge-Version header. New tests cover a late version, a version that never arrives (with a 100 ms limit), a bad /sw.js (an error on navigation, a non-JS type, a 404), and the CLI flags.

What I left out: the navigation-branch check is a text heuristic on the worker source, not a run of the worker. It would miss a Response.error() hidden behind a helper function. Only scripts/smoke.ts and its test changed.

To try it: bun scripts/smoke.ts https://<preview> --version <sha> --wait 60.

🤖 Generated with Claude Code

Closes #2423

commented

scripts/smoke.ts can now wait for a given version on /healthz and check that /sw.js never answers a navigation with Response.error(). bun test test/smoke.test.ts and tsc --noEmit pass. I did not run the whole suite; the forge's check does that on this push. I also ran the /sw.js check's extraction against the real src/web/sw.ts source, and it finds no Response.error() in the navigation branch.

  • --version <v> [--wait <seconds>]: the script polls /healthz until X-Forge-Version equals <v>. The default limit is 120 s, and the poll interval is 1 s. If the version never arrives, it fails with wanted X-Forge-Version <v>, last saw <seen> (none if the header was absent or the request errored) and skips the other checks. A bad --wait value or extra arguments exits 2 with a usage line.
  • /sw.js: it must be a 200 with a JavaScript content type. The script cuts out the navigation branch (from mode === 'navigate' to the next return;), strips comments, and fails if Response.error( is left. The asset branch in the real worker legitimately uses Response.error() for /assets/ and /icons/, so that stays allowed.
  • Tests in test/smoke.test.ts: the stub now serves /sw.js and an X-Forge-Version header. New tests cover a late version, a version that never arrives (with a 100 ms limit), a bad /sw.js (an error on navigation, a non-JS type, a 404), and the CLI flags.

What I left out: the navigation-branch check is a text heuristic on the worker source, not a run of the worker. It would miss a Response.error() hidden behind a helper function. Only scripts/smoke.ts and its test changed.

To try it: bun scripts/smoke.ts https://<preview> --version <sha> --wait 60.

🤖 Generated with Claude Code

Approved

Approved. I read the diff and the real src/web/sw.ts. The navigation branch runs from mode === navigate to the first return; at line 99, and it holds no Response.error(). The asset branch after it does, and is correctly left out. The new code has no input, write or secret surface, and the tests cover the late version, the missing version, the bad sw.js cases and the CLI flags. I did not run the tests or the preview. Two things I would do next: (1) wire --version $SHA into the deploy or preview check that calls smoke.ts, since nothing in the repo uses the flag yet and the wait only matters once it does; (2) make navigationBranch stricter. The //[^\n]* comment strip also cuts string literals that contain //, such as URLs. A helper that returns Response.error() would also slip past it. A small runtime test that runs swSource with a stubbed fetch and caches and asserts the navigation response is not an error would replace the regex.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs