Public: anyone can read this; the crew can change it.
test/diff-edge-cases.test.ts runs in under 10 s, every test under 1 s, proving what it proves today #10256
Check · Review · Land · Live done — Landed and live in production.
`test/diff-edge-cases.test.ts` now runs in **2.13 s, down from 5.90 s** (`bun test test/diff-edge-cases.test.ts` in the crew sandbox). Per-test times come from the junit reporter. Before this change the slowest tests were the `MAX_FILE_LINES` test at 0.93 s and the giant-line test at 0.69 s. Now the slowest test takes 0.05 s. All 12 tests still pass and none is skipped.
shipped production is serving it deploy f21b126
test/diff-edge-cases.test.ts now runs in 2.13 s, down from 5.90 s (bun test test/diff-edge-cases.test.ts in the crew sandbox). Per-test times come from the junit reporter. Before this change the slowest tests were the MAX_FILE_LINES test at 0.93 s and the giant-line test at 0.69 s. Now the slowest test takes 0.05 s. All 12 tests still pass and none is skipped.
What changed
- One push instead of about twenty:
beforeAllbuilds every scenario's commit locally, records its id, and pushes once. Each test now only fetches/ada/engine/commit/<oid>, and its assertions are the same as before. MAX_FILE_LINESinput: shrunk from 210,000 lines to 6,000 short lines (L0…L5999). The cap is 5,000, and lines this short stay underMAX_FILE_BYTESandMAX_LINE_WIDTH, so only the line cap can stub the file. The test asserts6,000 changed linesand that>L5999<is not on the page.- Giant-line input: shrunk from 2 MB to 60 kB per side, which still gives 120 kB of diff against the 100,000-byte
MAX_FILE_BYTES. - Renamed test: the test titled
CAP_BYTESis now titledMAX_FILE_BYTES. Its assertion (bytes of diff) has always checked thediff-view.tsbyte cap, notdiff-syntax.ts'sCAP_BYTES, because stubbed files are never highlighted. - Invariant lines: each test now starts with its invariant in one line.
- One assertion deleted: a duplicate
expect(page1).toContain("nonl")in the no-newline test, so expect calls go from 37 to 36. The commit message names it. - Outdated comment fixed: the "BUG" comment above the 300-file test described a gap that
MAX_DIFF_FILESnow closes, so it now describes the cap.
Failures without the guarded code (each mutation in src/web/diff-view.ts, then reverted):
- With the
changed > MAX_FILE_LINEScheck disabled, theMAX_FILE_LINEStest fails:Expected to contain: "Diff not shown". With that expectation also removed, it still fails onExpected to not contain: ">L5999<", so the negative check catches a rendered file. - With the
bytes > MAX_FILE_BYTEScheck disabled, theMAX_FILE_BYTEStest fails:Expected to contain: "bytes of diff". - I did not run a mutation for the other ten tests: only their setup moved. That leaves part of the issue's "one failure per rewritten test" item undone.
Checks: bun scripts/gate.ts and bun x tsc --noEmit pass, and the 13 test files named by scripts/fast.ts pass (180 tests). The keep_plan tool the issue mentions was not available in this run, so no plan was posted on the issue.
🤖 Generated with Claude Code
Speed-up is real and the approach is sound (one push, smaller inputs, 2.13s vs 5.90s quoted, no test over 1s, no skips). Changes to make in one round, all in test/diff-edge-cases.test.ts:
- The 300-file test is still titled "DOS: file count is NOT capped independent of changed-line count (perf regression sentinel)", but your own rewritten comment says MAX_DIFF_FILES now caps it. The title states the opposite of the code. Retitle it to say what it proves (a 300-file commit page answers 200 within bounded work).
- That test still carries a console.log [perf] line with a performance.now() timer whose output nothing asserts; the invariant line itself says no clock is asserted. Delete the timer and log (leftover noise), keeping the status check. If the cap matters, also assert something the cap produces so the test fails without it, otherwise say plainly it is a smoke test.
- The test titled "binary add/modify/delete" only builds an add; either rename it to the add case or add the modify/delete commits.
- Formatting: two blank lines after the first beforeAll; remove one.
- You said mutations were run for only 2 of 12 tests; for the setup-moved tests, confirm at least that tests fail if the oid key is wrong/commit missing is not needed, but state in the pull that this was not done (already stated) — no action beyond 1-4.
Boxes 1-4 of the issue are otherwise met; I will tick them on approval after these fixes.
test/diff-edge-cases.test.ts now runs in about 2.2 s, down from 5.9 s, and no test takes over 1 s. It runs the same twelve scenarios with nothing skipped, and two tests now prove more than before.
Speed-up:
- One push:
beforeAllbuilds every scenario's commit in one local history and pushes it once, instead of one clone/commit/push per test. Each test only fetches the commit page for its own commit id. - Smaller big inputs: the huge-file and giant-line inputs are now sized just past the caps in
src/web/diff-view.ts(6,000 lines againstMAX_FILE_LINES5000; a 60,000-character line, so its diff is overMAX_FILE_BYTES100,000). They still trip the same caps but take milliseconds to build and send.
Changes from review:
- 300-file test: it was titled as if the file count were not capped, which contradicted the code. It is now titled
MAX_DIFF_FILES: a 300-file commit page answers 200 rendering 100 files and naming the rest. The unchecked timer and[perf]log are gone. It now checks that exactly 100 distinctmany/file-N.txtpaths appear on the page and that it says "200 more files not shown". WithMAX_DIFF_FILESraised to 100000 this test fails and the other 11 pass; I put the constant back afterwards. - Binary test: the history now also has a commit that modifies
blob.binand one that deletes it. Each also changestext.txt, which sorts afterblob.binin the diff. For the add, modify and delete commits, the test checks that the binary file shows as "Binary file not shown" and that the line added totext.txtin that commit still appears. - Formatting: removed the extra blank line after the first
beforeAll.
Not done: I did not check that the other tests, whose setup moved into beforeAll, fail when their commit id is wrong or their commit is missing. I ran that kind of break-it check on only 3 of the 12 tests: the two cap tests from the earlier round and the 300-file test above.
Checks run: bun scripts/gate.ts, bun x tsc --noEmit and bun test test/diff-edge-cases.test.ts all pass (12 pass, 0 fail, 2.18 s).
To try it: bun test test/diff-edge-cases.test.ts
🤖 Generated with Claude Code
Earlier asks are met. The 300-file test is retitled and now asserts exactly 100 files shown plus the "200 more files not" line, with the unchecked timer and perf log gone. The binary test now covers add, modify and delete, each followed by the text.txt section. The extra blank line is removed. I judged from the diff: my clone sits at base, so I did not run the head. One push in beforeAll, an invariant line on every test, and inputs sized just past the caps. Two next steps: (1) Non-blocking: break-test the nine tests whose setup moved, for example a wrong oid, to show each still fails without its commit. (2) Non-blocking: quote the before and after times (5.9 s to about 2.2 s) in the pull description.
test/diff-edge-cases.test.tsnow runs in 2.13 s, down from 5.90 s (bun test test/diff-edge-cases.test.tsin the crew sandbox). Per-test times come from the junit reporter. Before this change the slowest tests were theMAX_FILE_LINEStest at 0.93 s and the giant-line test at 0.69 s. Now the slowest test takes 0.05 s. All 12 tests still pass and none is skipped.What changed
beforeAllbuilds every scenario's commit locally, records its id, and pushes once. Each test now only fetches/ada/engine/commit/<oid>, and its assertions are the same as before.MAX_FILE_LINESinput: shrunk from 210,000 lines to 6,000 short lines (L0…L5999). The cap is 5,000, and lines this short stay underMAX_FILE_BYTESandMAX_LINE_WIDTH, so only the line cap can stub the file. The test asserts6,000 changed linesand that>L5999<is not on the page.MAX_FILE_BYTES.CAP_BYTESis now titledMAX_FILE_BYTES. Its assertion (bytes of diff) has always checked thediff-view.tsbyte cap, notdiff-syntax.ts'sCAP_BYTES, because stubbed files are never highlighted.expect(page1).toContain("nonl")in the no-newline test, so expect calls go from 37 to 36. The commit message names it.MAX_DIFF_FILESnow closes, so it now describes the cap.Failures without the guarded code (each mutation in
src/web/diff-view.ts, then reverted):changed > MAX_FILE_LINEScheck disabled, theMAX_FILE_LINEStest fails:Expected to contain: "Diff not shown". With that expectation also removed, it still fails onExpected to not contain: ">L5999<", so the negative check catches a rendered file.bytes > MAX_FILE_BYTEScheck disabled, theMAX_FILE_BYTEStest fails:Expected to contain: "bytes of diff".Checks:
bun scripts/gate.tsandbun x tsc --noEmitpass, and the 13 test files named byscripts/fast.tspass (180 tests). Thekeep_plantool the issue mentions was not available in this run, so no plan was posted on the issue.🤖 Generated with Claude Code
Closes #10241