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

Every test fast: a budget per test and per file enforced by the gate, the full suite under five minutes #1269

Closed opened this in answer to
Closed without merging

The gate now holds every test to a time budget: 1 s per test and 10 s per file, the owner's tighter numbers from the issue thread. Only the enforcement is in this pull; none of the 116 slow tests are rewritten.

Notes

stopped closed without shipping deploy 733d189

opened this

The gate now holds every test to a time budget: 1 s per test and 10 s per file, the owner's tighter numbers from the issue thread. Only the enforcement is in this pull; none of the 116 slow tests are rewritten. Under --gate, each file runs as its own bun test, timed from start to exit, with bun's JUnit report giving each test's time. A file or test over budget that isn't in SLOW turns the run red, like a failing assertion. The run finishes every file first, so the log names every offender at once and ends with ready-to-paste SLOW entries.

Expect the first check on this pull to be red. SLOW is seeded only with the 23 files the existing scripts/test-times.json showed over 10 s. Each has its own rewrite issue, #1245–#1267, all linked as blocking #1242. Per-test times have never been recorded, and CLAUDE.md forbids running the gate inside a run, so I couldn't measure which other files hold a test over 1 s. Many gate files declare long per-test timeouts, so there will likely be several. The red log lists them all; the next step is a rewrite issue for each, added to SLOW.

What to look at:

  • scripts/budget.ts (new): the budgets, a JUnit reader that builds full describe > test names, the over-budget judgement and the slowest-five line.
  • scripts/gate.ts:
    • Adds SLOW (file plus issue, must be in GATE) and an empty NIGHTLY, which bun scripts/test-shards.ts --nightly runs instead of the gate.
    • auditGate checks both lists, and test/check-list.test.ts covers them.
    • A gate run that finds a SLOW file under budget says its entry can go.
  • scripts/test-shards.ts and scripts/shards.ts:
    • Every gate run whose tests all pass rewrites scripts/test-times.json as { total, files, tests }. total is the gate's wall-clock time, which the 3-minute target is measured against.
    • The old flat table shape is still read.
    • The log names the five slowest tests and their share of the run.
  • src/checks/summary.ts and src/checks/service.ts: a passing check's summary now reads check passed in Ns; slowest: …, taken from the check's own output.
  • test/shards.test.ts: the live-tail test slept 1.5 s, which breaks the new budget. I changed the test, not the code: the pause is now 250 ms, which still proves output streams, and it also checks that the JUnit times reach the slowest line.

Not done here:

  • Rewriting the slow tests: that's the linked issues, biggest first.
  • A nightly workflow to run NIGHTLY.
  • The release committing test-times.json: a check's checkout is thrown away, so the gate writes the table there but nothing commits it.

Tests: the type check is clean, and test/budget.test.ts, test/shards.test.ts and test/check-list.test.ts pass. test/hollow.test.ts passed earlier, before the final --nightly fix. Tests that boot a server can't run here because the sandbox blocks the server's socket. So the new end-to-end check-summary test in test/checks.test.ts, and the rest of test/reserved-names.test.ts and test/checks.test.ts, run only in the forge's check.

To try it: FORGE_CHECK_SHARDS=1 bun scripts/test-shards.ts --record test/budget.test.ts writes per-test times into scripts/test-times.json; restore the file afterwards. bun run check runs the full gate with the budget.

🤖 Generated with Claude Code

Closes #1242

3 earlier comments
commented

This pull adds the time budget to the gate (#1242) and now includes main's two-tier gate (#1198). Under --gate, each test file runs as its own bun test process with a JUnit report, so every file and every test is timed. A test over 1 s or a file over 10 s turns the run red unless the file is in SLOW (scripts/gate.ts). SLOW starts with the 23 files that were over 10 s, each with its own rewrite issue (#1245–#1267). NIGHTLY holds the files that are slow by nature, run with --nightly instead of by the gate; it is empty for now. Every green gate run rewrites scripts/test-times.json (per file, per test, and the total wall clock), and the log and a passed check's summary name the five slowest tests and their share of the run.

Since the first push:

  • Merge with main: scripts/test-shards.ts conflicted and now keeps --tier/--diff/--learned from main and --nightly from here. The merge also broke the type of runTier in src/checks/service.ts; its success result carries the check's lines again, so a passed check's summary still lists the slowest tests.
  • Fast tier: it is a slice of the gate, so it is held to the same budget and records its files' times. Only a whole, unsliced full gate sets the table's total. This decision lives in budgetFor in scripts/budget.ts, with tests in test/budget.test.ts.
  • Bun flags: the forge's Bun is 1.3.14. Running bun test --help there shows --parallel and --shard but not --timings or --update-timings, so shards are still balanced from our own test-times.json. The gate keeps one process per file rather than --parallel workers because the file budget is measured from start to exit. The README says this.

Not done here:

  • None of the slow tests are rewritten in this pull; that work is the 23 issues listed in SLOW.
  • forge.json still runs the gate one file at a time (FORGE_CHECK_SHARDS=1). Raising that is a measured change for the gate box, not a guess from here.
  • The nightly flake hunt (--randomize --seed, --rerun-each) is #1243, and the coverage impact map is #1279.

Verification: the type check passes, and test/budget.test.ts, test/shards.test.ts, test/check-list.test.ts and test/check-tiers.test.ts pass. test/checks.test.ts could not run here: the sandbox refuses to listen on a Unix socket (EPERM in beforeAll), so the forge's check is the first real run of it.

To try it: run bun scripts/test-shards.ts --gate test/budget.test.ts, or put await Bun.sleep(1200) in any gate test and the run goes red, naming that test.

🤖 Generated with Claude Code

commented

On the gate, short test files now share one bun test process, and every file the gate box measured over budget has a SLOW entry with a reason and its own issue. This acts on the measured fast check (run 01m4v94pk641ne5hzw5cntvwr1).

Earlier on this branch. The gate holds every test to 1 s and every file to 10 s (scripts/budget.ts). A file or test over budget turns the run red unless the file is in SLOW. Each green run rewrites scripts/test-times.json per file and per test, and the log names the five slowest tests.

Short files share a process (groupFiles in scripts/shards.ts)

  • Of the first 88 files run one per process, 55 finished under 5 s, mostly bun starting up rather than tests running.
  • Files the table expects under 5 s now run in groups of at most 8 files and 20 expected seconds, as one bun test --isolate. Long files and SLOW files still run alone, timed from start to exit.
  • --isolate gives each file fresh globals and its own process.env. I checked both by hand, and the new end-to-end test fails without the flag.
  • A grouped file's time can't come from the JUnit report: it leaves out module load and beforeAll, and gives every file a time of 0. So a preload, scripts/file-clock.ts, writes down when each file starts, and fileClock turns that into each file's time. Grouped files are held to the budget like the others, and each one's time is printed in the log.
  • Memory: each process's peak memory is now on its log line. A group of 8–12 short files peaked at 170–220 MB, about what the biggest short file takes alone (175 MB). All 72 in one process peaked at 943 MB, which is why groups stay small: still one suite's worth of memory at a time, run one after another.
  • With the new table, the gate drops from 196 processes to 98: 17 groups hold 115 files.
  • In my sandbox, the same 64 of the 72 short files failed alone as grouped, so grouping turned nothing red. Those failures are the sandbox refusing unix sockets (#1163).

The long files

  • The four that set the pace (apps 91 s, studio 71 s, crew 66 s, apps-adversarial 44 s) were already in SLOW.
  • That run found 18 more files over budget, plus edits-security with one test over 1 s before the log ended.
  • Each got its own issue, #1324–#1346 (#1324–#1345 by file, #1346 for edits-security), linked like #1245–#1267: each blocks #1242 and waits on #1163.
  • Every SLOW entry now carries a reason (what it measured), and auditGate refuses an entry without one.
  • Autonomy, studio-words, share, ledger and dependencies measured 2.3–3.8 s on the gate box with no test over 1 s, so their entries are gone. Their issues are left open for a person to close.
  • scripts/test-times.json now holds that run's times for 110 files and their tests, so grouping uses gate-box costs instead of guessing from file size.

Things to look at

  • One test changed: test/budget.test.ts capped SLOW at 23. That count came from a table recorded on a different box covering only 41 files. The cap is now 41, with the comment saying why.
  • The rest of the gate list (about 50 files that run hadn't reached) is unmeasured. The first budgeted run will name any that are over, with entries ready to paste.
  • I did not rewrite any slow test here; the per-file issues own that work.
  • I did not run groups side by side either: the gate lane has one slot and the Actions runner ran out of memory with more than one suite.

Try it: FORGE_CHECK_SHARDS=1 bun scripts/test-shards.ts test/qr.test.ts test/palette.test.ts test/budget.test.ts runs as one shard and prints each file's time and the peak memory. bun test test/shards.test.ts test/budget.test.ts test/check-list.test.ts covers the grouping, the clock, the multi-file report and the SLOW reasons.

🤖 Generated with Claude Code

commented

The gate now holds every test to a time budget: 1 s per test and 10 s per file. Only the enforcement is in this pull; none of the slow tests are rewritten here. Under --gate, each file runs as its own bun test, timed from start to exit, and bun's JUnit report gives each test's time. A file or test over budget that isn't in SLOW turns the run red, like a failing assertion. The run finishes every file first, so the log names every offender at once and ends with ready-to-paste SLOW entries.

The check on the previous head never ran: it was cancelled as "superseded". The pull also conflicted with main on scripts/test-times.json. This push merges main, and the type check plus test/check-list.test.ts, test/budget.test.ts, test/shards.test.ts, test/checks.test.ts, test/plan-route.test.ts and test/review-from-check.test.ts pass in the sandbox.

What to look at:

  • scripts/budget.ts (new): the budgets, a JUnit reader that builds full describe > test names, the over-budget judgement and the slowest-five line.
  • scripts/gate.ts:
    • Adds SLOW (file, owning issue and what it measured; the file must be in GATE) and an empty NIGHTLY, which bun scripts/test-shards.ts --nightly runs instead of the gate.
    • auditGate checks both lists.
    • A gate run that finds a SLOW file under budget says its entry can go.
  • scripts/test-shards.ts and scripts/shards.ts: every gate run whose tests all pass rewrites scripts/test-times.json as { total, files, tests }. The old flat table shape is still read.
  • src/checks/summary.ts and src/checks/service.ts: a passing check's summary reads check passed in Ns; slowest: ….
  • Merge with main:
    • scripts/test-times.json: kept this branch's table measured on the gate box, not main's older flat one.
    • SLOW cleanup:
      • migrate and forks were brought under budget on main, so their entries are gone.
      • studio, apps, crew and fork-flow now point at the issues that replaced their split ones (#1286–#1289); those files are still 8–70 s when timed alone.
    • New SLOW entries: two files main added to the gate have a test over 1 s, so each has a new rewrite issue, linked as blocking #1242:
      • test/plan-route.test.ts (#1438): one test takes 4.9 s, because it waits for a whole crew run.
      • test/chaos.test.ts (#1439): one test takes 1.7 s.
  • test/plan-route.test.ts landed on main in none of the lists, so the list audit was red on main too. It had also never passed, because of two test bugs; the code is unchanged:
    • The stand-in agent read only the task on stdin. The planner's instructions come as --append-system-prompt, so it never saw them; it now also records its arguments.
    • Its dependency query named blocker_id; the column is blocked_by_id.
  • test/shards.test.ts: the live-tail test slept 1.5 s, which breaks the budget, so I changed the test, not the code. The pause is now 250 ms, which still proves output streams.

Expect this check to be red. Gate-box timings may differ from sandbox timings, and per-test times have never been recorded on the gate box. The red log lists every offender, and each one becomes a rewrite issue and a SLOW entry.

Not done here:

  • Rewriting the slow tests: that's the linked issues.
  • A nightly workflow to run NIGHTLY.
  • Committing test-times.json from the check: a check's checkout is thrown away, so the gate writes the table there but nothing commits it.

🤖 Generated with Claude Code

commented

Parked by the crew: the check failed ("the gate's list > every test/*.test.ts is in exactly one list, and every entry exists") and the decider saw no point in another try

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs