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

Tab forge: a real-browser walk makes an app and edits a file without 'Failed to fetch' #18307

opened this

Merged 3h 37m ago, live in production

This adds test/tab-browser.test.ts, a real-browser walk of the tab forge, and fixes the two causes of its earlier reds. The new real-browser assertions have never run: Chromium cannot start in this crew sandbox, so they are skipped here.

Notes

opened this

This adds test/tab-browser.test.ts, a real-browser walk of the tab forge, and fixes the two causes of its earlier reds. The new real-browser assertions have never run: Chromium cannot start in this crew sandbox, so they are skipped here. The first real run is this pull's check, and "green five runs in a row" is not shown yet.

Why the walk was red (#18267's history and check log). In both cases the test was at fault, not the guard or the server.

  • walk: TypeError: Failed to fetch: the test called fetch() from a tab forge page. Those pages send CSP default-src 'none', so the browser refused the request before it left. Commit 9b9933e on #18267 moved that read into the service worker.
  • walk: SyntaxError: Invalid or unexpected token: this was the next and last red. The test pasted JSON.stringify(makeSpec(…)) into its script and then doubled the backslashes, which broke the string. The doubling is removed.

What changed

  • Test and helper: test/tab-browser.test.ts and walkWithWorker in test/helpers/chrome.ts are taken from #18267 and adapted to main's guard, fromOwnPage(origin, referrer, own).
  • Worker-side probe: it now records request.referrer, which is what the guard in src/tab/sw.ts reads. It used to read a referer header, which a service worker never sees, so its own-page check would have failed even when the guard let the post through.
  • New browser test: after the edit, the app's page shows the new entry. That is the "edits a file and sees it run" step; the tab forge's apps have entries, not files.
  • Tests that need no browser:
    • every script the walk sends to Chromium must parse;
    • the pasted spec must reach the import form exactly as makeSpec wrote it.

    These catch the SyntaxError class of red anywhere.

  • No app code changed. #18300 already let the tab's own page through the guard.

Writes the guard could refuse. The walk posts make, an entry added to the app, a new issue, import, and app removal. Tick, remove-entry and move use the same /apps/:id/:block/:op route and the same guard, but the walk does not post them. The tab forge has no commit, pull, settings or Talk writes, so there is nothing more to fix or list.

What I chose not to do: no retries and no longer waits. Every wait in the walk is bounded and fails with the step's name.

Checks run here: bun x tsc --noEmit is clean, and the gate passes. I ran 22 test files on their own: the gate's rules (unused exports, module-level state, duplicate imports, named timers and waits) and the Chromium helpers. They all pass. Across the 217 test files scripts/fast.ts named, only test/scripts-fast.test.ts failed. It hit its 5 s limit, and fails the same way with this branch's two files reverted to main, so it is not this change.

To try it: bun test test/tab-browser.test.ts on a machine where Chromium starts. The walk's log prints each post's Origin and referrer as the worker saw them.

🤖 Generated with Claude Code

Closes #18295

2 earlier comments
commented

This adds test/tab-browser.test.ts, a real-browser walk of the tab forge, and fixes the two causes of its earlier reds. The new real-browser assertions have never run: Chromium cannot start in this crew sandbox, so they are skipped here. The first real run is this pull's check, and "green five runs in a row" is not shown yet.

Why the walk was red (#18267's history and check log). In both cases the test was at fault, not the guard or the server.

  • walk: TypeError: Failed to fetch: the test called fetch() from a tab forge page. Those pages send CSP default-src 'none', so the browser refused the request before it left. Commit 9b9933e on #18267 moved that read into the service worker.
  • walk: SyntaxError: Invalid or unexpected token: this was the next and last red. The test pasted JSON.stringify(makeSpec(…)) into its script and then doubled the backslashes, which broke the string. The doubling is removed.

What changed

  • Test and helper: test/tab-browser.test.ts and walkWithWorker in test/helpers/chrome.ts are taken from #18267 and adapted to main's guard, fromOwnPage(origin, referrer, own).
  • Worker-side probe: it now records request.referrer, which is what the guard in src/tab/sw.ts reads. It used to read a referer header, which a service worker never sees, so its own-page check would have failed even when the guard let the post through.
  • New browser test: after the edit, the app's page shows the new entry. That is the "edits a file and sees it run" step; the tab forge's apps have entries, not files.
  • Tests that need no browser:
    • every script the walk sends to Chromium must parse;
    • the pasted spec must reach the import form exactly as makeSpec wrote it.

    These catch the SyntaxError class of red anywhere.

  • No app code changed. #18300 already let the tab's own page through the guard.

Writes the guard could refuse. The walk posts make, an entry added to the app, a new issue, import, and app removal. Tick, remove-entry and move use the same /apps/:id/:block/:op route and the same guard, but the walk does not post them. The tab forge has no commit, pull, settings or Talk writes, so there is nothing more to fix or list.

What I chose not to do: no retries and no longer waits. Every wait in the walk is bounded and fails with the step's name.

Checks run here: bun x tsc --noEmit is clean, and the gate passes. I ran 22 test files on their own: the gate's rules (unused exports, module-level state, duplicate imports, named timers and waits) and the Chromium helpers. They all pass. Across the 217 test files scripts/fast.ts named, only test/scripts-fast.test.ts failed. It hit its 5 s limit, and fails the same way with this branch's two files reverted to main, so it is not this change.

To try it: bun test test/tab-browser.test.ts on a machine where Chromium starts. The walk's log prints each post's Origin and referrer as the worker saw them.

🤖 Generated with Claude Code

commented

This adds test/tab-browser.test.ts, a real-browser walk of the tab forge, and fixes what made it red. No app code changes. The last fix (801ddad) has not had a browser run yet: Chromium cannot start in this crew sandbox, so this pull's check is its first run. "Green five runs in a row" is not shown yet.

Why the walk was red. Each red came from the test, not from the guard or the server.

  • walk: TypeError: Failed to fetch (#18267): the test called fetch() from a tab forge page. Those pages send CSP default-src 'none', so the browser refused the request before it left. The walk now acts as a person does, with forms and links; the one file it reads is asked of the service worker.
  • walk: SyntaxError (#18267): the test pasted an already-quoted JSON spec into its script and then doubled the backslashes, which broke the string. The doubling is removed.
  • "0 posts seen" (this pull's first check): the walk itself landed every write, but the record of what each post carried came back empty. Chrome only runs the fetch listeners a service worker adds when its script first runs, so a listener added later from DevTools never fires. The record is now taken in the page from the DevTools network events, one entry per request. The test then asserts that each of the five posts carried an Origin and Referer that fromOwnPage accepts.

What the walk proves. A fresh tab forge makes an app, adds an entry to it and shows the entry on the app's page. It also files an issue, downloads the app file, imports a spec back and removes the app. A post the guard refused would answer 403 where it was sent and never reach the page its step expects, so the walk itself checks the guard.

Writes the walk does not post. Tick, remove-entry and move use the same /apps/:id/:block/:op route and the same guard as the entry the walk adds. The tab forge has no commit, pull, settings or Talk writes, so there is nothing more to fix or list.

What I chose not to do: no retries and no longer waits. Every wait in the walk is bounded and fails with the step's name.

Tests that need no browser: every script the walk sends must parse, and the pasted spec must reach the import form exactly as makeSpec wrote it. These catch the SyntaxError kind of red anywhere.

Checks run here: the gate and bun x tsc --noEmit are clean. test/tab-browser.test.ts and the gate's rule tests pass (the browser tests skip, as above). test/scripts-fast.test.ts hits its 5 s limit here, and fails the same way with this branch's files reverted to main.

To try it: bun test test/tab-browser.test.ts where Chromium starts. The log prints each post's headers as the page sent them.

The walk and its helper walkWithWorker in test/helpers/chrome.ts come from #18267, adapted to main's guard fromOwnPage(origin, referrer, own).

🤖 Generated with Claude Code

commented

Left #18295 open: 1 unticked item remain (The test makes a new app, edits a file and sees it run; it is green five runs in a row locally.).

Sign in to join this conversation.

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs