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

Merged opened this

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

Merged

`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

opened this

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:

fileslowest test
before21.35 s9.42 s (unassigned pull), 5.55 s (steer), 5.06 s (brief)
after2.27 s / 2.29 s / 2.39 s0.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, as landing, crew-pause, crew-continues and 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; at src/crew/dispatch.ts:699): the steer test, the unassigned-pull test and the brief test fail.
  • Readers emptied (readers: readersAmong(...) in src/crew/runner.ts:1149 replaced with an empty set): the brief test fails.
  • Outsiders switch ignored (repo.crewOutsiders && canRead(...) in src/crew/direct.ts replaced with false): 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

Closes #10212

commented

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:

fileslowest test
before21.35 s9.42 s (unassigned pull), 5.55 s (steer), 5.06 s (brief)
after2.27 s / 2.29 s / 2.39 s0.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, as landing, crew-pause, crew-continues and 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; at src/crew/dispatch.ts:699): the steer test, the unassigned-pull test and the brief test fail.
  • Readers emptied (readers: readersAmong(...) in src/crew/runner.ts:1149 replaced with an empty set): the brief test fails.
  • Outsiders switch ignored (repo.crewOutsiders && canRead(...) in src/crew/direct.ts replaced with false): 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

Approved

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.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs