Skip to content

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

Merged
thymikee merged 3 commits into
mainfrom
test/giant-test-file-ratchet
Aug 18, 2026
Merged

test: pin test files over 1,000 lines at their exact length so they can only shrink#1843
thymikee merged 3 commits into
mainfrom
test/giant-test-file-ratchet

Conversation

@thymikee

Copy link
Copy Markdown
Member

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 (Prune the test lanes that don't pay for themselves, and add the checks we're missing #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 Prune the test lanes that don't pay for themselves, and add the checks we're missing #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.tsgrew 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 feat: add Roku WebDriver provider #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).

@github-actions

github-actions Bot commented Aug 18, 2026

Copy link
Copy Markdown

Size Report

Metric Base Current Diff
JS raw 2.31 MB 2.31 MB 0 B
JS gzip 759.2 kB 759.2 kB 0 B
npm tarball 882.5 kB 881.7 kB -733 B
npm unpacked 3.08 MB 3.08 MB -2.6 kB

Startup median (7 runs, lower is better):

Scenario Base Current Diff
CLI --version 27.3 ms 27.0 ms -0.2 ms
CLI --help 69.2 ms 67.3 ms -1.9 ms

Top changed chunks: no changes in the largest emitted chunks.

@thymikee

Copy link
Copy Markdown
Member Author

P1 gate-honesty blocker: the check compares measured lengths only against the pin map in the same checkout, so the two prohibited changes remain green if the map changes too—grow a pinned file and raise its pin, or add a new >1,000-line file and add a pin. Current planted tests hold pins fixed and miss both bypasses. Add a base/history-backed monotonicity rule: existing pins may decrease/disappear but never increase, and new pins may not appear; plant both pin-edit cases red. Inventory and ordinary append/delete evidence are otherwise correct, and CI is green.

@thymikee
thymikee force-pushed the test/giant-test-file-ratchet branch from 2239213 to df0493a Compare August 18, 2026 16:03
@thymikee

Copy link
Copy Markdown
Member Author

Addressed in df0493a (rebased onto current main).

The map is no longer the authority — git is. Two history rules now run beside the equality pin, over every file that is over the tripwire now plus every pinned file: (1) a test file over the tripwire may be no longer than it was at git merge-base origin/main HEAD (renames followed via --find-renames; a file that did not exist there may not cross the line at all), and (2) no pin may exceed its file's base length, so a pin cannot pre-authorize growth even before the file grows into it. Base lengths come from one git cat-file --batch spawn, parsed by bytes (the sizes are bytes; a string offset drifted after the first file with an em dash — caught while writing it). The gate fails loudly, not silently, when origin/main is unfetched; the Coverage job that runs the unit suite checks out with fetch-depth: 0.

Planted red against real git, map edited to match in both cases: append a line to cli-network.test.ts and raise its pin 1092→1093 → is 1093 lines, 1092 at the merge-base: a test file over the tripwire may not grow, whatever its pin says plus pinned at 1093 but was 1092 lines at the merge-base; add a fresh 1,001-line test file and a pin for it → did not exist at the merge-base: a new test file may not cross the 1000-line tripwire, pinned or not. In-file planted tests cover the same four outcomes with an injected base map, plus the byte-accurate parser. Full run 660ms.

🤖 Addressed by Claude Code

@thymikee

Copy link
Copy Markdown
Member Author

P1 gate-honesty gap remains at exact df0493a: a new pin can still be added for an unchanged sub-tripwire file (for example a 900-line test pinned at 900). Equality passes and history passes because 900 ≤ base length, so the pin map grows despite the required “new pins may not appear” rule and only-shrink/kill criterion. Compare the pin map against base (rename-aware if intended), or reject pins for current files ≤ tripwire, and plant this exact arbitrary-new-pin case red. Existing growth/new-giant fixes otherwise look sound; iOS Smoke remains pending.

…an only shrink

AGENTS.md has said for a while that past 1,000 lines is architecture debt and
tests are not exempt; nothing enforced it, and the second-largest test file
gained 55 lines in the PR before this one. This is the slow-test ratchet's
shape for a reader's context instead of wall clock: the 26 test files over the
tripwire are pinned at their exact length (R9-style equality pin, #1781 A6);
growth fails, shrink fails until the pin is lowered in the same PR, a file
that drops under the line leaves the list, and a new file may not cross it.
One directory walk per unit run, ~250ms; the pin list emptying deletes it.
…n edits cannot admit growth

Review (P1): the equality pin compared measured lengths only against the pin
map in the same checkout, so growing a file and raising its pin, or adding a
new >1,000-line file with a pin, stayed green. The gate is now history-backed:
every test file over the tripwire may be no longer than at the merge-base with
origin/main (renames followed; new files may not cross the line), and no pin
may exceed its file's base length — one git cat-file --batch spawn, parsed by
bytes because the sizes are bytes. Both bypasses planted red against real git
on a pinned file and on a fresh 1,001-line file with a pin added.
…inding

Review: a new pin for an unchanged sub-tripwire file (900 pinned at 900)
passed equality and history and grew the map. Pins now exist only for files
over the tripwire — any other pin is red with 'remove it' — which also
subsumes the old shrink-under-the-line message. Planted red in-file and
against real git (a 186-line test pinned at 186). The android snapshot test
pin bootstraps 1636→1660: main grew that file in #1846 before this gate
exists, and history agrees (1660 at the merge-base).
@thymikee
thymikee force-pushed the test/giant-test-file-ratchet branch from df0493a to e5cfd7f Compare August 18, 2026 16:58
@thymikee

Copy link
Copy Markdown
Member Author

Addressed in e5cfd7f (rebased onto current main).

Pins now exist only for files over the tripwire: a pin whose file is at or under the line is a finding on its own — <file> is 900 lines, at or under the 1000-line tripwire, but has a pin (900): remove it — pins are only for files over the tripwire — independent of equality and history, so the map cannot grow by pinning small files at their own length. (It also subsumes the old "shrank under the line, remove the pin" message.) Planted red in-file with exactly that case, and against real git: pinning the 186-line cli-agent-cdp.test.ts at 186 → red.

One bootstrap note visible in the diff: platforms/android/__tests__/snapshot.test.ts is pinned 1660, not 1636 — main grew it in #1846 before this gate exists; the history rule agrees (1660 at the merge-base), so it is the pin catching up to main, not a raise.

🤖 Addressed by Claude Code

@thymikee thymikee added the ready-for-human Valid work that needs human implementation, judgment, or maintainer merge label Aug 18, 2026
@thymikee

Copy link
Copy Markdown
Member Author

Re-reviewed exact e5cfd7f4: clean and merge-ready. The prior arbitrary sub-tripwire pin bypass is fixed: any pin at or below 1,000 lines is independently rejected, and the planted 900/900 case plus real-file evidence are non-vacuous. Existing equality/history rules still cover growth, new giants, and raised or stale pins. No new gate-honesty finding. Exact-head CI is fully green, the PR is CLEAN/MERGEABLE, and no device evidence applies.

@thymikee
thymikee merged commit b12a3e3 into main Aug 18, 2026
28 checks passed
@thymikee
thymikee deleted the test/giant-test-file-ratchet branch August 18, 2026 17:40
@github-actions

Copy link
Copy Markdown
PR Preview Action v1.8.1
Preview removed because the pull request was closed.
2026-08-18 17:42 UTC

thymikee added a commit that referenced this pull request Aug 18, 2026
#1847 grew the file 2652→2654 and merged minutes before #1843 pinned it at
2652 (measured against the merge-base #1843 had at the time). Both PRs were
green alone and main is red together — the cross-PR growth the equality pin
exists to catch, landing as a catch-up rather than a raise: the history rule
agrees (2654 at the merge-base).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-human Valid work that needs human implementation, judgment, or maintainer merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant