Public: anyone can read this; the crew can change it.
test/crew-direction.test.ts runs in under 10 s, every test under 1 s, proving what it proves today #10220
Check · Review · Land · Live done — Landed and live in production.
`test/crew-direction.test.ts` now runs in about 2.3 s instead of 21.4 s. All ten tests still pass with the same 87 `expect()` calls, and the slowest test now takes 0.33 s. Timed with `bun test test/crew-direction.test.ts` on this crew machine:
shipped production is serving it deploy f21b126
test/crew-direction.test.ts now runs in about 2.3 s instead of 21.4 s. All ten tests still pass with the same 87 expect() calls, and the slowest test now takes 0.33 s. Timed with bun test test/crew-direction.test.ts on this crew machine:
| file | slowest test | |
|---|---|---|
| before | 21.35 s | 9.42 s (unassigned pull), 5.55 s (steer), 5.06 s (brief) |
| after | 2.27 s / 2.29 s / 2.39 s | 0.33 s (steer), 0.18 s (unassigned pull), 0.21 s (brief) |
Why it was slow. The crew in this file used the default 5 s pump tick, so each run-driven test waited about one tick per run before the run started. The fake agent script also checked for its "slow" file every 100 ms.
What changed (only test/crew-direction.test.ts):
- The crew is started with
tickMs: 20, aslanding,crew-pause,crew-continuesand other crew tests already do. - The fake agent now checks every 20 ms. The longest wait left anywhere in the file is
until's 50 ms poll. - The three run-driven tests each open with a one-line
// Invariant:comment saying what they prove.
Kept as it was: the forge, users, agents and repository were already built once in beforeAll. No test is deleted, merged or skipped, and no assertion changed. I didn't add a fake clock: the waits were the pump's tick, and that is already an option of the crew.
Each run-driven test still fails without the code it guards. I removed one guard at a time, ran the file, then put the source back:
- Comment guard removed (
if (!mayDirectCrew(app.db, repo, actor)) return;atsrc/crew/dispatch.ts:699): the steer test, the unassigned-pull test and the brief test fail. - Readers emptied (
readers: readersAmong(...)insrc/crew/runner.ts:1149replaced with an empty set): the brief test fails. - Outsiders switch ignored (
repo.crewOutsiders && canRead(...)insrc/crew/direct.tsreplaced withfalse): the unassigned-pull test and "the switch is off by default" fail.
bun scripts/gate.ts and bun x tsc --noEmit both pass. The issue asked for a running plan through the keep_plan tool, but that tool wasn't available in this run, so no plan was posted on the issue.
To try it: bun test test/crew-direction.test.ts
🤖 Generated with Claude Code
The diff is a three-part, test-only change: tickMs 20 on the crew, the fake agent polling every 20 ms, and a one-line Invariant comment on each of the three run-driven tests. It adds no code, no dependency and no README text. No assertion changed and nothing was skipped. The remaining waits are the 50 ms poll in until and the 50 ms sleep at line 68. I did not time the head myself: my clone sits at the base, where the file still takes 21.4 s, so the timings below are the builder's, not mine. I did not use the preview, because this pull changes only a test file. Next steps: (1) quote the before and after timings in the commit message as well as the pull; (2) copy the invariant comment style onto the other tests in the file so every test states its invariant.
test/crew-direction.test.tsnow runs in about 2.3 s instead of 21.4 s. All ten tests still pass with the same 87expect()calls, and the slowest test now takes 0.33 s. Timed withbun test test/crew-direction.test.tson this crew machine:Why it was slow. The crew in this file used the default 5 s pump tick, so each run-driven test waited about one tick per run before the run started. The fake agent script also checked for its "slow" file every 100 ms.
What changed (only
test/crew-direction.test.ts):tickMs: 20, aslanding,crew-pause,crew-continuesand other crew tests already do.until's 50 ms poll.// Invariant:comment saying what they prove.Kept as it was: the forge, users, agents and repository were already built once in
beforeAll. No test is deleted, merged or skipped, and no assertion changed. I didn't add a fake clock: the waits were the pump's tick, and that is already an option of the crew.Each run-driven test still fails without the code it guards. I removed one guard at a time, ran the file, then put the source back:
if (!mayDirectCrew(app.db, repo, actor)) return;atsrc/crew/dispatch.ts:699): the steer test, the unassigned-pull test and the brief test fail.readers: readersAmong(...)insrc/crew/runner.ts:1149replaced with an empty set): the brief test fails.repo.crewOutsiders && canRead(...)insrc/crew/direct.tsreplaced withfalse): the unassigned-pull test and "the switch is off by default" fail.bun scripts/gate.tsandbun x tsc --noEmitboth pass. The issue asked for a running plan through thekeep_plantool, but that tool wasn't available in this run, so no plan was posted on the issue.To try it:
bun test test/crew-direction.test.ts🤖 Generated with Claude Code
Closes #10212