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

test/apps.test.ts runs in under 10 s, every test under 1 s, proving what it proves today #10260

Merged opened this

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

Merged

`bun test test/apps.test.ts` now runs in about 5.2 s in the crew sandbox, down from 11.28 s on main 495df9944 (the issue's measurement). Still 23 tests, none skipped or deleted, and the slowest is 0.80 s. Only `test/apps.test.ts` and `test/helpers/apps-forge.ts` changed.

shipped production is serving it deploy f21b126

opened this

bun test test/apps.test.ts now runs in about 5.2 s in the crew sandbox, down from 11.28 s on main 495df9944 (the issue's measurement). Still 23 tests, none skipped or deleted, and the slowest is 0.80 s. Only test/apps.test.ts and test/helpers/apps-forge.ts changed.

whole fileslowest test
main 495df9944 (issue)11.28 s—
after the first commit (cd1299058)8.54 s—
after this pull (3 runs)5.05 s, 5.17 s, 5.30 s0.80 s (retries stop after PORT_RETRIES…)

What moved

  • Faster polling (cd1299058): settled deploys are checked every 10 ms. No sleep longer than 10 ms remains.
  • Concurrent stories (c4ccefb7d): these stories don't depend on the production → preview → merge → archive chain, so they now run together in one describe.concurrent:

- #36: a preview starts again on empty data - #202: a start failure names the app's own file - #254: the terminal line between email_off markers - #255: stopping mid-install reads as cancelled - #270: crash messages - #296: production before previews at boot - port races and lap timing

Each story builds its forge once, and all the forges are built in one beforeAll at the same time. The #254 forge never starts its runtime, because only the page is under test. The two #36 apps deploy side by side.

  • Boot restart fixture: the #296 restart setup is the slowest fixture, so it now starts in the file's first beforeAll, beside the chain, and its one test reads the settled result.
  • Helper: startAppsForge takes optional { domain, concurrency, start }, and existing callers are unchanged. New helpers are appsRuntime (to build the replacement runtime after a restart) and signedInCookie, which replaces three copies of the sign-in code.
  • Invariant lines: each slow test now opens with a one-line comment stating what it proves.

Each rewritten test still fails without the code it guards. I broke the source, ran only that test, and restored:

storysource brokenresult
#36reseedEmpty(…) removed from the preview retryfails
#36the retry condition forced to true, so production retries toofails
#202stripForgeDirs returns the line unchangedfails
#254email_off markers removed in src/web/ui.tsfails
#255the this.stopped && abort.signal.aborted branch disabledfails
#296boot reconciles app by app, and the gate's first: production set to falsefails

Breaking only the #296 boot loop is not enough to fail its test, and the test on main doesn't fail either. The gate's first: production (src/apps/runtime.ts:1258) keeps production first by itself, so the ordering is guarded in two places. The test catches the order only when both are broken.

Checks run: bun scripts/gate.ts, bun x tsc --noEmit, test/apps.test.ts three times in a row, and the 12 other suites that import test/helpers/apps-forge.ts (44 pass, 0 fail). All green.

Not done: I didn't add a fake clock. The remaining time is real process starts and health checks, which is what these tests prove, and the only waits left are 10 ms polls.

To try it: bun test test/apps.test.ts, or bun test --reporter=junit --reporter-outfile=out.xml test/apps.test.ts for per-test times.

🤖 Generated with Claude Code

Closes #10244

commented

bun test test/apps.test.ts now runs in about 5.2 s in the crew sandbox, down from 11.28 s on main 495df9944 (the issue's measurement). Still 23 tests, none skipped or deleted, and the slowest is 0.80 s. Only test/apps.test.ts and test/helpers/apps-forge.ts changed.

whole fileslowest test
main 495df9944 (issue)11.28 s—
after the first commit (cd1299058)8.54 s—
after this pull (3 runs)5.05 s, 5.17 s, 5.30 s0.80 s (retries stop after PORT_RETRIES…)

What moved

  • Faster polling (cd1299058): settled deploys are checked every 10 ms. No sleep longer than 10 ms remains.
  • Concurrent stories (c4ccefb7d): these stories don't depend on the production → preview → merge → archive chain, so they now run together in one describe.concurrent:

- #36: a preview starts again on empty data - #202: a start failure names the app's own file - #254: the terminal line between email_off markers - #255: stopping mid-install reads as cancelled - #270: crash messages - #296: production before previews at boot - port races and lap timing

Each story builds its forge once, and all the forges are built in one beforeAll at the same time. The #254 forge never starts its runtime, because only the page is under test. The two #36 apps deploy side by side.

  • Boot restart fixture: the #296 restart setup is the slowest fixture, so it now starts in the file's first beforeAll, beside the chain, and its one test reads the settled result.
  • Helper: startAppsForge takes optional { domain, concurrency, start }, and existing callers are unchanged. New helpers are appsRuntime (to build the replacement runtime after a restart) and signedInCookie, which replaces three copies of the sign-in code.
  • Invariant lines: each slow test now opens with a one-line comment stating what it proves.

Each rewritten test still fails without the code it guards. I broke the source, ran only that test, and restored:

storysource brokenresult
#36reseedEmpty(…) removed from the preview retryfails
#36the retry condition forced to true, so production retries toofails
#202stripForgeDirs returns the line unchangedfails
#254email_off markers removed in src/web/ui.tsfails
#255the this.stopped && abort.signal.aborted branch disabledfails
#296boot reconciles app by app, and the gate's first: production set to falsefails

Breaking only the #296 boot loop is not enough to fail its test, and the test on main doesn't fail either. The gate's first: production (src/apps/runtime.ts:1258) keeps production first by itself, so the ordering is guarded in two places. The test catches the order only when both are broken.

Checks run: bun scripts/gate.ts, bun x tsc --noEmit, test/apps.test.ts three times in a row, and the 12 other suites that import test/helpers/apps-forge.ts (44 pass, 0 fail). All green.

Not done: I didn't add a fake clock. The remaining time is real process starts and health checks, which is what these tests prove, and the only waits left are 10 ms polls.

To try it: bun test test/apps.test.ts, or bun test --reporter=junit --reporter-outfile=out.xml test/apps.test.ts for per-test times.

🤖 Generated with Claude Code

Approved

Test-only change (apps.test.ts and its helper). 23 tests kept and none skipped. Each slow test opens with a one-line invariant. Forges are built once and the independent stories run in one describe.concurrent. The quoted time is 5.05 to 5.30 s against 11.28 s before, with the slowest test at 0.80 s. Polls are 10 ms. Mason also quoted source-break checks showing the rewritten tests still fail without the code they guard. The preview and screenshots are unaffected, since no product code changed. Two things I would do next: (1) The #296 boot test now uses one preview instead of two, and it only fails when both the boot loop and the gate first:production are broken. Add a case that guards the boot ordering by itself. (2) Watch the concurrent real-process stories for flakes on a loaded gate. If one appears, cap the concurrency rather than raise timeouts.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs