Skip to content

tests: end-to-end coverage, and the token-field bug it found - #4

Merged
blakebauman merged 1 commit into
mainfrom
e2e-tests
Aug 11, 2026
Merged

blakebauman merged 1 commit into
mainfrom
e2e-tests

Conversation

@blakebauman

Copy link
Copy Markdown
Member

Closes the largest gap in docs/design.md. 38 Playwright specs across the read
paths, the MCP session, and the invariants this page is actually held to.

They run against the built bundle through pnpm preview, not the dev
server — that server replays fold's exact response headers, so the suite
exercises the real Content-Security-Policy instead of reasoning about it.

⚠️ It found a real bug on the first run

The Bearer-token field never applied its value.

preact/compat aliases React's onChange onto the input event, so declaring
both onInput and onChange left one handler clobbering the other. Keystrokes
were swallowed, draft never advanced past empty, and a pasted token
authenticated nothing:

value after fill: ""                       # the input rejected its own keystrokes
federationAuth:   ["", "", ""]             # no Authorization header, ever

Against a gateway with auth on — the only configuration where that field is
even shown — the console was unusable. It shipped in #1 and is live in fold
main today.

Nothing caught it. Typecheck, lint and every CI grep passed, and the browser
looked correct because the local dev gateway runs with auth disabled and hides
the field. Fixed by dropping onChange and committing on blur and Enter, which
is what the hand-written console did before the rewrite.

value after fill: "tok_abc"
federationAuth:   ["", "Bearer tok_abc", "Bearer tok_abc"]

What is covered

  • The CSP is exercised. One test walks the whole app and asserts no
    securitypolicyviolation fired. CI's greps catch an inline <script> in the
    HTML and a style={{}} in the source; neither would notice a dependency
    injecting a style tag at runtime.
  • Untrusted strings, with real payloads. A federated tool named
    <img src=x onerror=...>, plus an upstream error, a label, and a tool result
    — each asserted to render as text, leaving no element and no side effect.
    This is the invariant that matters most: these pages render
    attacker-influenced strings on the gateway's own origin, next to a live
    Bearer token.
  • The token reaches no storage and no cookie, a reload signs you out, and
    the same credential goes to both /api/federation and /mcp.
  • A deep link renders on a cold load — the test for hash routing, which
    exists because fold's file server has no SPA fallback.
  • Filter and sort round-trip through the URL, including a filtered URL
    opened fresh. That property is what makes "the broken upstream" a link.
  • The MCP session survives navigation, argument skeletons come from the
    tool's inputSchema, and a method-not-found answer to prompts/list reads
    as an empty capability rather than an error.
  • 401 stops the poll loop instead of minting audit events; 403 names
    server.introspection.groups
    , not the retired server.console.groups.
  • Version skew: an old gateway warns, a current one is silent, a dev
    build is not treated as stale.
  • Every asset the page requests is same-origin.

The gateway is mocked, deliberately

It buys the states a real gateway will not produce on demand: 401, 403, skew,
an empty federation, an open breaker, a server answering method-not-found, a
hostile tool name.

It does not buy contract fidelity. tests/gateway.ts says so at the top and
names what covers that instead (src/lib/federation.ts typed against fold's
introspection.go, and fold's own suite grepping the vendored bundle) — because
a suite that mocked its way to green while the real endpoint renamed a field
would be worse than no suite.

Incidental

CardGroup and JsonPane are now named regions. That started as a way to
disambiguate test locators, but a scrollable pane of output that a screen-reader
user can identify is worth having on its own, and there are two of them on the
test console.

CI gets a separate e2e job — it needs a Chromium download the static checks
do not, and a typo should not wait on that. Runs in ~8s locally.

🤖 Generated with Claude Code

The console had no tests. The routing work made them tractable — every view has
an address now — so this adds 38 Playwright specs across the read paths, the
MCP session, and the invariants this page is actually held to.

They run against the BUILT bundle through `pnpm preview`, not the dev server.
That is the whole point: preview replays fold's exact response headers, so the
suite exercises the Content-Security-Policy a shipped binary sends rather than
reasoning about it. One test walks the app and asserts no
securitypolicyviolation fired — CI's greps catch an inline <script> in the HTML
and a `style={{}}` in the source, but neither would notice a dependency
injecting a style tag at runtime.

WHAT IT FOUND

The Bearer-token field never applied its value. preact/compat aliases React's
onChange onto the input event, so declaring both onInput and onChange left one
handler clobbering the other: keystrokes were swallowed, the draft never
advanced past empty, and a pasted token authenticated nothing. Against a
gateway with auth on — the only configuration where the field is shown — the
console was unusable.

Nothing caught it. Typecheck, lint and every CI grep passed; the browser looked
correct because the local gateway runs with auth disabled and hides the field.
Fixed by dropping onChange and committing on blur and Enter, which is also what
the hand-written console did before the rewrite.

WHAT IS COVERED

  - Overview renders from a snapshot, and omits cards for absent facts rather
    than printing a row of em dashes.
  - A deep link into an upstream detail page renders on a COLD load. That is
    the test for hash routing, which exists because fold's file server has no
    SPA fallback.
  - Filter and sort state round-trips through the URL, including a filtered URL
    opened fresh — the property that makes "the broken upstream" a link.
  - The MCP session survives navigation between routes, argument skeletons come
    from the tool's inputSchema, and a method-not-found answer to prompts/list
    reads as an empty capability rather than an error.
  - 401 stops the poll loop instead of minting audit events; 403 names
    server.introspection.groups and not the retired server.console.groups.
  - Version skew: an old gateway warns, a current one is silent, a "dev" build
    is not treated as stale.
  - Untrusted strings, with real payloads. A federated tool named
    `<img src=x onerror=...>`, an upstream error, a label, a tool result: each
    asserted to render as text, leaving no element and no side effect. These
    pages render attacker-influenced strings on the gateway's own origin next
    to a live Bearer token, so this is the invariant that matters most.
  - The token reaches no storage and no cookie, a reload signs you out, and the
    same credential goes to both /api/federation and /mcp.
  - Every asset the page requests is same-origin.

The gateway is mocked, deliberately. It buys the states a real one will not
produce on demand — 401, 403, skew, an empty federation, an open breaker, a
hostile tool name. It does not buy contract fidelity, and tests/gateway.ts says
so at the top and names what covers that instead, because a suite that mocked
its way to green while the real endpoint renamed a field would be worse than no
suite.

Two components gained accessible names along the way (CardGroup and JsonPane
are now named regions). That began as a way to disambiguate locators, but a
scrollable pane of output a screen-reader user can identify is worth having on
its own — and there are two of them on the test console.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant