ci(client): fail the count ratchets on an entry above the tree

lint:size, lint:layers, lint:rtl (both baselines), lint:skips and
lint:warnings only failed a count that passed its entry. A count that
fell below its entry was logged and nothing more, so a file that shrank
could grow back to its old entry unseen, and the entry of a deleted
file stayed behind for the next file at that path. lint:format and
lint:offline already fail on such a stale entry, and the docs said
these counts may only shrink.

Each of them now fails on an entry that lowerCounts would lower or
drop, naming its count or saying the file is gone, and tells to run
--update, which still only lowers. staleCounts and reportStale in
lib/ratchet.mjs hold the shared part. Every baseline matches the tree
today, so none needed lowering. The client CLAUDE.md says so, and that
CI lints through lint:warnings rather than lint:check.
This commit is contained in:
Maurice
2026-10-08 13:56:19 +02:00
parent 4344dbe923
commit bd267c67f8
18 changed files with 210 additions and 37 deletions
+32
View File
@@ -11,6 +11,8 @@ import {
RatchetError,
readBaseline,
readText,
reportStale,
staleCounts,
writeBaseline,
} from '../../../scripts/lib/ratchet.mjs';
import { ratchetTree, type RatchetTree } from '../../helpers/ratchetFixture';
@@ -79,6 +81,36 @@ describe('scripts/lib/ratchet', () => {
expect(lowerCounts({ a: 9 }, { a: 4 }, (key: string) => (key === 'a' ? 4 : 0))).toEqual({});
});
it('RATCHET-010: an entry above the count, at the floor or for a gone file is stale, one at the count is not', () => {
expect(
staleCounts({ held: 5, shrank: 5, gone: 5, floor: 5 }, { held: 5, shrank: 3, floor: 2, fresh: 9 }, 2)
).toEqual([
{ key: 'shrank', entry: 5, now: 3 },
{ key: 'gone', entry: 5, now: 0 },
{ key: 'floor', entry: 5, now: 2 },
]);
expect(staleCounts({ a: 3 }, { a: 4 })).toEqual([]);
});
it('RATCHET-011: a stale entry is reported with its count, or as gone, and how to lower it', () => {
tree = ratchetTree({ 'src/here.ts': 'x\n' });
const lines: string[] = [];
const error = (line: string) => lines.push(line);
const stale = [
{ key: 'src/here.ts', entry: 4, now: 2 },
{ key: 'src/gone.ts', entry: 3, now: 0 },
];
reportStale(stale, { file: 'b.json', command: 'lint:x', root: tree.root, error });
expect(lines).toEqual([
'FAIL src/here.ts is held at 4 in scripts/b.json, but there are 2 now.',
'FAIL src/gone.ts is held at 3 in scripts/b.json, but the file is gone.',
expect.stringMatching(/^Run npm run lint:x -- --update to lower the baseline/),
]);
lines.length = 0;
reportStale([], { file: 'b.json', command: 'lint:x', error });
expect(lines).toEqual([]);
});
it('RATCHET-008: a file list only loses the files that stopped offending', () => {
expect(lowerList(['a', 'b', 'c'], ['c', 'a', 'new'])).toEqual(['a', 'c']);
});