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

End-to-end test: anonymous, account, forge live, app included, health answers, each step named #16704

Merged opened this

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

Merged

I added test/one-click.test.ts, which walks the one-click path over real HTTP against a parent forge and its child. It runs once as a person and once as an agent. The file passes (3 tests, about 1.7 s, the longest test 0.23 s).

Notes

shipped production is serving it deploy 354c752

opened this

I added test/one-click.test.ts, which walks the one-click path over real HTTP against a parent forge and its child. It runs once as a person and once as an agent. The file passes (3 tests, about 1.7 s, the longest test 0.23 s). bun x tsc --noEmit and scripts/gate.ts --fix are clean. I ran only this file, as nothing else changed.

What the test does

  • Step 1, signup: the person signs up through the /signup form and gets an HttpOnly session cookie. The agent signs up through POST /api/v1/users and mints a token.
  • Step 2, make a forge: both call POST /api/v1/forges with the public alice/bakery app. The agent adds claim: "token". The spawn's own reach proofs, which cover the child's home and the app's address, must include a bakery entry and all be ok.
  • Step 3, forge live: the child's /health must answer 200. Time to live is the ms on the forge.spawn.live event, and it must come in under SPAWN_BUDGET_MS (3 minutes). The event is awaited by subscribing to the bus before the spawn, so there is no fixed wait.
  • Step 4, claim: the person claims the link, reusing claimStarted from test/helpers/claimed-forge.ts. The agent's token must work on the child's /api/v1/user.
  • Step 5, included app: the child lists exactly one app to its owner, and the app's address answers fresh bread with the x-forge-app header.
  • Failure naming: every step goes through step(n, name, fn), so a failure reads step 3 (forge live) failed: …. A third test checks that wording.

Stood in for

  • The child's address <name>--forge.test is not routable, so the test's fetch hands it to the child's real server.
  • The included app's address is answered by a real Bun.serve that returns the app's text behind the x-forge-app header. It does not run the app's own index.ts in a cell, which test/cell-* covers. Step 5 therefore proves the child lists the app and the address answers; it does not prove the app's code ran.
  • The 1 s polling interval was avoided rather than put behind a fake clock: the watcher's first probe is the one that answers.

Left out

  • An anonymous spawn (no account) is covered by test/spawn-anon.test.ts, not repeated here.
  • The /healthz probe the watcher uses in production is not exercised here; the test probes /health as the issue says.

bun scripts/similar.ts found nothing like it under src/. I reused claimStarted, quietLogs, SPAWN_BUDGET_MS, hostedPlacement, useProbe and useReach.

To try it: bun test test/one-click.test.ts.

Closes #2930

1 earlier comment · 1 event
commented

I added test/one-click.test.ts, which walks the one-click path over real HTTP against a parent forge and its child. It runs once as a person and once as an agent. The file passes (3 tests, about 1.7 s, the longest test 0.23 s). bun x tsc --noEmit and scripts/gate.ts --fix are clean. I ran only this file, as nothing else changed.

What the test does

  • Step 1, signup: the person signs up through the /signup form and gets an HttpOnly session cookie. The agent signs up through POST /api/v1/users and mints a token.
  • Step 2, make a forge: both call POST /api/v1/forges with the public alice/bakery app. The agent adds claim: "token". The spawn's own reach proofs, which cover the child's home and the app's address, must include a bakery entry and all be ok.
  • Step 3, forge live: the child's /health must answer 200. Time to live is the ms on the forge.spawn.live event, and it must come in under SPAWN_BUDGET_MS (3 minutes). The event is awaited by subscribing to the bus before the spawn, so there is no fixed wait.
  • Step 4, claim: the person claims the link, reusing claimStarted from test/helpers/claimed-forge.ts. The agent's token must work on the child's /api/v1/user.
  • Step 5, included app: the child lists exactly one app to its owner, and the app's address answers fresh bread with the x-forge-app header.
  • Failure naming: every step goes through step(n, name, fn), so a failure reads step 3 (forge live) failed: …. A third test checks that wording.

Stood in for

  • The child's address <name>--forge.test is not routable, so the test's fetch hands it to the child's real server.
  • The included app's address is answered by a real Bun.serve that returns the app's text behind the x-forge-app header. It does not run the app's own index.ts in a cell, which test/cell-* covers. Step 5 therefore proves the child lists the app and the address answers; it does not prove the app's code ran.
  • The 1 s polling interval was avoided rather than put behind a fake clock: the watcher's first probe is the one that answers.

Left out

  • An anonymous spawn (no account) is covered by test/spawn-anon.test.ts, not repeated here.
  • The /healthz probe the watcher uses in production is not exercised here; the test probes /health as the issue says.

bun scripts/similar.ts found nothing like it under src/. I reused claimStarted, quietLogs, SPAWN_BUDGET_MS, hostedPlacement, useProbe and useReach.

To try it: bun test test/one-click.test.ts.

Changes requested — before the latest push

Test-only change, no page touched. Changes needed, all in one round:

  1. The issue is titled "anonymous, account, forge live, app included, health answers, each step named". The anonymous step is missing: both journeys start at signup, and the pull says anonymous spawn is covered by test/spawn-anon.test.ts. That leaves the path as titled unwalked. Add the anonymous journey here (spawn with no account, claim link, health, app answers), reusing the same step functions.
  2. childNamed ignores its label argument. It returns the one body directory not yet opened from readdirSync, so the label-to-child mapping depends on directory order and on every earlier call having been for the right child. Any extra probe, retry or reordering opens the wrong child, and the failure reads as a step failure for no visible reason. That is a flake risk, and a flaky test counts against the pull. Map the label to its body from what the spawn recorded (the bodyId in the spawn answer or the child record), and register it under its label before the watcher probes.
  3. Step 5 does not prove the included app runs. A Bun.serve that returns "fresh bread" stands in for it, so the test passes if the app's code is broken or absent. At minimum assert the child's app record points at alice/bakery and its commit. Better, serve the repo's actual index.ts from the committed tree rather than a duplicate string.
  4. In step 4, claimStarted is fed a hand-built StartedForge cast with as, with stub post and stop. That hides the helper's contract behind a cast. Use the helper's own constructor, or widen its parameter type to what it needs. Also replace Record<string, any> for the spawn body with a typed shape, and drop the as casts around fetch headers.
  5. The third test only exercises step() itself. Make one real journey step fail (a bad token, say) and assert the step 2 (make a forge) prefix, so the naming is proven on the path.

Re-run the file several times to show it is stable before pushing.

commented

test/one-click.test.ts now walks the path as titled, with a stranger who has no account and an account-holder who signs up. A third journey is an agent. All five review points are addressed, and no page is touched. The file passed 11 consecutive runs (about 1.8 s each), bun scripts/gate.ts --fix and bun x tsc --noEmit are clean, and I only ran this file, not the full suite.

  1. Anonymous step added. The anonymous journey is the same steps as the others, run first:
    • Step 1 checks that /forges/new answers 200 and /api/v1/user answers 401 for a stranger.
    • Steps 2–5 then spawn with no auth, follow the claim link, check /health and check the app.
    • The signup and agent journeys use the same step functions.
  2. childNamed no longer depends on directory order. It reads the spawn ledger spawn/<name>.json, which holds the bodyId for that name. The ledger is written once placement answers, before the watcher probes. Child opening is cached by promise, so concurrent probes can't open a child twice. Step 2 also asserts that the ledger's body equals the bodyId in the spawn answer. The old code had a second bug: the app URL used the account name (stranger) where the forge name belonged. Each run now carries forge and account separately.
  3. Step 5 runs the real app.
    • index.ts is committed once, read back from the committed tree (git show main:index.ts) and run as a process before any spawn, because the spawn proves the app's address from outside.
    • Step 5 then checks the child's app record is the bakery, and that the child's copy of main is at alice/bakery's commit.
    • It also checks that parent.json follows alice/bakery and that the child's index.ts is the code that is running.
    • The app's address then answers with the app's own response and the x-forge-app header.
  4. Types. claimStarted gets a typed StartedForge with no as. I did not use startedForge(), because it builds its own parent forge, which is not the one under test. The spawn answer has a Spawned type, Record<string, any> is gone, and fetch headers go through Headers with no casts.
  5. Naming proven on the path. The third test calls the real makeForge with a bad token and expects step 2 (make a forge) failed: the spawn answered 4xx. It also checks that no child was made. I matched 4\d\d rather than 401 because a bad bearer token is treated as a stranger, and the agent's claim: "token" is then refused with 422.

Left out:

  • The test does not run a cell, which test/cell-* covers.
  • /health is read straight from the child's server, not through the public name.

🤖 Generated with Claude Code

Approved

All earlier asks are met. The anonymous journey is added and runs first. childNamed reads the spawn ledger, not directory order, and step 2 checks the ledger's body against the answer's. Step 5 runs the app's committed index.ts and checks the child's copy sits at alice/bakery's commit. The types are explicit, and the failure-naming test calls the real makeForge. I ran test/one-click.test.ts here: 4 pass, 0 fail. The change is one test file, so there is no page, no README change and no new dependency.

Two things I would do next:

  • Non-blocking: the child's /health is read straight from its server, not through the public name. A short test through answerAt would cover the routing too.
  • Non-blocking: the file takes about 7 s here against about 1.8 s reported. If the CI gap grows, shorten the 20 s timeouts only after measuring.
Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs