Skip to content

Commit e5cfd7f

Browse files
committed
test(ratchet): a pin on a file at or under the tripwire is itself a finding
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).
1 parent d398709 commit e5cfd7f

2 files changed

Lines changed: 20 additions & 7 deletions

File tree

‎docs/agents/testing.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,8 @@ Measured on the full unit suite (340 files, 3,210 tests, 48s wall at ~7x paralle
563563
not the authority — git is: every file over the line is also held to its length at the
564564
merge-base with `origin/main` (renames followed), and no pin may exceed its file's base length,
565565
so growing a file and raising its pin, or adding a giant file with a pin, are red against
566-
history. Adding a test to a pinned file means moving that family out first — the failure names
566+
history; a pin on a file at or under the line is red on its own, so the map cannot grow by
567+
pinning small files at their own length. Adding a test to a pinned file means moving that family out first — the failure names
567568
the file and the fix; never raise a pin. Needs `origin/main` fetched (CI's Coverage job does).
568569
- **Isolation stays ON; pool stays forks — both measured.** `--no-isolate`: 205s wall vs 48s
569570
(module state — timers, memos, singletons — thrashes across files sharing a worker).

‎src/__tests__/test-file-size-ratchet.test.ts‎

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ const PINNED_TEST_FILE_LINES: Readonly<Record<string, number>> = Object.freeze({
4040
'src/daemon/handlers/__tests__/session-replay-runtime-maestro.test.ts': 2031,
4141
'src/utils/__tests__/daemon-client.test.ts': 1910,
4242
'src/utils/__tests__/output.test.ts': 1861,
43-
'src/platforms/android/__tests__/snapshot.test.ts': 1636,
43+
'src/platforms/android/__tests__/snapshot.test.ts': 1660,
4444
'src/platforms/apple/core/__tests__/runner-client.test.ts': 1615,
4545
'src/__tests__/client.test.ts': 1598,
4646
'test/integration/provider-scenarios/android-lifecycle.test.ts': 1597,
@@ -99,14 +99,22 @@ function ratchetFindings(
9999
}
100100
continue;
101101
}
102+
if (lines <= tripwire) {
103+
// Pins exist only for files over the tripwire: one on a smaller file grows the map for
104+
// nothing (900 pinned at 900 would satisfy equality and history alike) and defeats the
105+
// only-shrink kill criterion.
106+
findings.push(
107+
`${file} is ${lines} lines, at or under the ${tripwire}-line tripwire, but has a pin (${pin}): remove it — pins are only for files over the tripwire.`,
108+
);
109+
continue;
110+
}
102111
if (lines > pin) {
103112
findings.push(
104113
`${file} grew to ${lines} lines (pinned ${pin}): extract instead of adding to a file over the tripwire.`,
105114
);
106115
} else if (lines < pin) {
107116
findings.push(
108-
`${file} shrank to ${lines} lines (pinned ${pin}): lower its pin in this PR so the ratchet keeps the gain` +
109-
(lines <= tripwire ? ' — it is now under the tripwire, so remove the pin.' : '.'),
117+
`${file} shrank to ${lines} lines (pinned ${pin}): lower its pin in this PR so the ratchet keeps the gain.`,
110118
);
111119
}
112120
}
@@ -241,17 +249,21 @@ test('no test file over the tripwire grows, and every pin matches its file exact
241249
});
242250

243251
test('planted reds: growth, shrink, unpinned crossing, and a stale pin each name their fix', () => {
244-
const pinned = { 'a.test.ts': 1200, 'b.test.ts': 1500, 'gone.test.ts': 1100 };
252+
const pinned = { 'a.test.ts': 1200, 'b.test.ts': 1500, 'e.test.ts': 900, 'gone.test.ts': 1100 };
245253
const measured = new Map([
246254
['a.test.ts', 1201], // grew
247-
['b.test.ts', 900], // shrank under the tripwire
255+
['b.test.ts', 900], // shrank under the tripwire: the pin must go
256+
['e.test.ts', 900], // unchanged sub-tripwire file that someone pinned at its own length
248257
['c.test.ts', 1001], // new offender
249258
['d.test.ts', 1000], // at the line, fine
250259
]);
251260
expect(ratchetFindings(measured, pinned, 1000)).toEqual([
252261
'a.test.ts grew to 1201 lines (pinned 1200): extract instead of adding to a file over the tripwire.',
253-
'b.test.ts shrank to 900 lines (pinned 1500): lower its pin in this PR so the ratchet keeps the gain — it is now under the tripwire, so remove the pin.',
262+
'b.test.ts is 900 lines, at or under the 1000-line tripwire, but has a pin (1500): remove it — pins are only for files over the tripwire.',
254263
'c.test.ts is 1001 lines, over the 1000-line tripwire and not pinned: split it along the source module it mirrors (docs/agents/testing.md) rather than pinning it.',
264+
// The arbitrary-new-pin bypass: equality (900 == 900) and history (900 <= base) both pass,
265+
// so this rule is the one that rejects it.
266+
'e.test.ts 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.',
255267
'gone.test.ts is pinned but does not exist: remove its pin.',
256268
]);
257269
expect(ratchetFindings(new Map([['a.test.ts', 1200]]), { 'a.test.ts': 1200 }, 1000)).toEqual([]);

0 commit comments

Comments
 (0)