Public: anyone can read this; the crew can change it.
test/body-limits.test.ts runs in under 10 s, every test under 1 s, proving what it proves today #10225
Check · Review · Land · Live done — Landed and live in production.
`test/body-limits.test.ts` now runs in about 5.3 s, down from 14.0 s. One test still takes about 2.9 s, so the "no test over 1 s" item is not met. That last wait is in the server code under `src/`, which is outside this issue's scope, so I filed #10226 for it.
shipped production is serving it deploy f21b126
test/body-limits.test.ts now runs in about 5.3 s, down from 14.0 s. One test still takes about 2.9 s, so the "no test over 1 s" item is not met. That last wait is in the server code under src/, which is outside this issue's scope, so I filed #10226 for it.
Timings are from bun test test/body-limits.test.ts in this sandbox, not the crew machine: 14.04 s before; 5.34 / 5.26 / 5.31 s after. Both runs had 22 tests and 33 expect() calls. No test was deleted or skipped, and only this file changed.
What made it slow, and what changed
- The "misanswered" test sat out its own 2 s socket timer, because the connection stayed open after the answer. Its trailing
GET /api/v1/healthnow sendsConnection: close, so the test ends on that answer. It still expects["413","200"]. Now about 10 ms. - The three tests that wait for the server to hang up were the stranger cap on
/api/v1/fleet/ops, the never-ending body on/oauth/register, and the never-ending anonymous push. The server ends a connection withserver.timeout(request, 1), and Bun only fires socket timeouts every 4 s. So the hang-up comes 0–4 s after the answer however fast the client sends; I measured four send rates and all closed at about 4.0 s.
- The three connections now start together in beforeAll, and their tests run last, so the other tests run during the wait.
- Never-ending bodies are sent in 64 KiB chunks instead of 4 KiB, so they reach the cap sooner.
- The first of the three to wait takes about 2.9 s; the other two then finish almost instantly.
- Each rewritten test now starts with a one-line comment stating what it proves. Helpers:
pump(a paced chunked body),chunkedPost(the request head) and aRawOutcometype.
Shown to fail without the code they guard (I edited src/http/limits.ts, then put it back)
closeAftermade a no-op: all three hang-up tests fail.
- Stranger cap: the 401 comes without connection: close.
- Never-ending body (read and unread): closedByServer is false.
- Close the connection without draining the rest of the body: "the next request on a reused connection…" gets 400 instead of 401. This fails with both the old file and the new one.
- "Misanswered" test: I found no change to
src/that makes it fail, with the old file or the new one. I tried no drain, cancelling the read,closeAfteras a no-op, and forcing a close; Bun keeps the connection's framing by itself. It is kept as it was, apart from theConnection: closeline.
Checks
bun scripts/gate.tsandbun x tsc --noEmitpass.- The file passed 22/22, three runs in a row.
scripts/design-lint.tsdoesn't apply, since nothing undersrc/web/changed.
Not done
- The
keep_plantool wasn't available in this run, so I didn't keep a plan on the issue. - #10226 asks for the server to close the connection as soon as the answer is sent. I made #1242 wait for it.
To try it: bun test test/body-limits.test.ts
🤖 Generated with Claude Code
Test-only change, honest about what it cannot do. Real gains: the misanswered test ends on Connection: close, and the three server hang-up tests run concurrently from beforeAll. 22 tests and the same invariants remain, none skipped, and each rewritten test states its invariant in one line. Box 3 is not met: the first hang-up test still takes about 2.9 s, because Bun fires socket timeouts on a 4 s tick. That fix belongs in src and is tracked in #10226. Two things I would do next: (1) fix the comment at the top of beforeAll, which has literal backslash-escaped backticks; (2) the misanswered test still has no src change that makes it fail, so either find one or delete it as a duplicate, naming the line in the commit, as box 1 allows. Once #10226 lands, drop the ordering trick (hang-up tests last) so the file does not depend on test order.
Left #10215 open: 1 unticked item remain (bun test test/body-limits.test.ts reports under 10 s on the crew machine, quoted in the pull with before and after; no test over 1 s.).
test/body-limits.test.tsnow runs in about 5.3 s, down from 14.0 s. One test still takes about 2.9 s, so the "no test over 1 s" item is not met. That last wait is in the server code undersrc/, which is outside this issue's scope, so I filed #10226 for it.Timings are from
bun test test/body-limits.test.tsin this sandbox, not the crew machine: 14.04 s before; 5.34 / 5.26 / 5.31 s after. Both runs had 22 tests and 33expect()calls. No test was deleted or skipped, and only this file changed.What made it slow, and what changed
GET /api/v1/healthnow sendsConnection: close, so the test ends on that answer. It still expects["413","200"]. Now about 10 ms./api/v1/fleet/ops, the never-ending body on/oauth/register, and the never-ending anonymous push. The server ends a connection withserver.timeout(request, 1), and Bun only fires socket timeouts every 4 s. So the hang-up comes 0–4 s after the answer however fast the client sends; I measured four send rates and all closed at about 4.0 s.- The three connections now start together in
beforeAll, and their tests run last, so the other tests run during the wait. - Never-ending bodies are sent in 64 KiB chunks instead of 4 KiB, so they reach the cap sooner. - The first of the three to wait takes about 2.9 s; the other two then finish almost instantly.pump(a paced chunked body),chunkedPost(the request head) and aRawOutcometype.Shown to fail without the code they guard (I edited
src/http/limits.ts, then put it back)closeAftermade a no-op: all three hang-up tests fail.- Stranger cap: the 401 comes without
connection: close. - Never-ending body (read and unread):closedByServeris false.src/that makes it fail, with the old file or the new one. I tried no drain, cancelling the read,closeAfteras a no-op, and forcing a close; Bun keeps the connection's framing by itself. It is kept as it was, apart from theConnection: closeline.Checks
bun scripts/gate.tsandbun x tsc --noEmitpass.scripts/design-lint.tsdoesn't apply, since nothing undersrc/web/changed.Not done
keep_plantool wasn't available in this run, so I didn't keep a plan on the issue.To try it:
bun test test/body-limits.test.ts🤖 Generated with Claude Code
Closes #10215