test: pin test files over 1,000 lines at their exact length so they can only shrink

Merged
TH
3mo ago
+347-1

Summary

Retro follow-up, item 6. AGENTS.md already says past 1,000 lines is architecture debt and tests are not exempt; nothing enforced it, and snapshot-handler.test.ts (2,652 lines) gained 55 lines in #1779 under that rule. This is the slow-test ratchet's shape applied to the other resource a giant test file consumes — a reader's context:

  • src/__tests__/test-file-size-ratchet.test.ts (unit-core) walks src, packages, test, scripts for *.test.{ts,tsx,mjs} and pins the 26 files over the 1,000-line tripwire at their exact length, R9-style (#1781 A6 equality pin): growth fails ("extract instead of adding"), shrink fails until the pin is lowered in the same PR (so the ratchet keeps the gain), a file that drops under the line leaves the list, a new file may not cross it, a stale pin is reported.
  • Lane card (in the file header, per the #1781 rule): Catches a >1,000-line test file growing or a new one appearing · Evidence 26 offenders today, the top one grew last PR · Cost one walk + line count per unit run, ~250ms · Kill criterion empty pin list → delete the file.
  • Docs: a bullet next to the slow-test ratchet in docs/agents/testing.md; the AGENTS.md tripwire line now points at the gate.

Validation

  • Green on the current tree (2 tests, 230ms).
  • Planted red on a real pinned file: appending one line to src/__tests__/cli-network.test.ts → grew to 1093 lines (pinned 1092): extract instead of adding…; deleting one line → shrank to 1091 lines (pinned 1092): lower its pin in this PR…. Restored.
  • The decision function's four outcomes (grow / shrink-under-tripwire / unpinned crossing / stale pin) are pinned in-file with their exact messages.
  • Open PRs touching a pinned file: only #1159 (remote-connection.test.ts, 2026-07 draft-era branch); anything else in flight that adds to one of the 26 will hit the message and the doc it points to — that is the gate working, not collateral.
  • lint/typecheck/fallow clean. Not this PR: check:layering R9/R10 red on origin/main itself.

3 files touched (1 test, 2 docs).