Skip to content

Commit b46773c

Browse files
Trumpclaude
andauthored
test(spec): split key-mention.test.ts's conflated shipped-ledger case (#12973)
`key-mention.baseline.json` declares itself a SHRINK-ONLY RATCHET (#11457) — a finite debt ledger that exists to be driven to zero — and its twin pinned the debt as PRESENT: `expect(doc.exemptions.length).toBeGreaterThan(0)` goes red on the commit that deletes the last exemption, i.e. exactly when the burn-down succeeds. Deleting the floor alone would not have been the repair either: the `for (const row of doc.exemptions)` one line later asserts nothing over an empty array, so it would trade a red for a silent no-op. Split into the two claims the case conflated, per the PR #12050 witness-pair idiom: * the parser + row-quality rule, carried on a SYNTHETIC witness pair (a conforming row the parser accepts and the rule holds for; a structurally valid row that only reassures, which the rule refuses) — so both halves keep discriminating once the ledger reaches zero; * the shipped ledger, held to the same rule CONDITIONALLY on rows existing, with the read asserted independently of the row count so an empty ledger cannot read as a file that was never read. Claude-Session: https://claude.ai/code/session_01LpRNHxWZgSUgVnFT9mQQo4 Co-authored-by: Claude <noreply@anthropic.com>
1 parent 2b4178a commit b46773c

1 file changed

Lines changed: 88 additions & 6 deletions

File tree

‎packages/spec/scripts/liveness/key-mention.test.ts‎

Lines changed: 88 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
parseKeyMentionBaseline,
2020
reconcileKeyMentions,
2121
} from './key-mention.mts';
22+
import type { KeyMentionExemption } from './key-mention.mts';
2223

2324
const here = dirname(fileURLToPath(import.meta.url));
2425

@@ -161,11 +162,92 @@ describe('parseKeyMentionBaseline', () => {
161162
expect(() => parseKeyMentionBaseline({})).toThrow(/exemptions/);
162163
});
163164

164-
it('parses the SHIPPED baseline, and every row explains which name the file uses', () => {
165-
const doc = parseKeyMentionBaseline(
166-
JSON.parse(readFileSync(join(here, 'key-mention.baseline.json'), 'utf8')),
167-
);
168-
expect(doc.exemptions.length).toBeGreaterThan(0);
169-
for (const row of doc.exemptions) expect(row.why.length).toBeGreaterThan(40);
165+
// ── the row-quality rule, and the pair that keeps it discriminating ──
166+
//
167+
// `key-mention.baseline.json` declares itself, in its own `_note`, a
168+
// `SHRINK-ONLY RATCHET (#11457)`: a finite, enumerated debt ledger that
169+
// exists to be driven to zero. Everything below follows from that one fact.
170+
//
171+
// What stood here was ONE case that read the shipped file and then asserted
172+
// `doc.exemptions.length > 0` before looping over the rows. It conflated two
173+
// claims, and got both of them wrong at the same moment:
174+
//
175+
// * the floor was a pin on the DEBT BEING PRESENT. It goes red on the
176+
// commit that deletes the last exemption — i.e. exactly when the
177+
// burn-down SUCCEEDS. The two reactions available to the seat that hits
178+
// it are "park a row to keep the test green" and "weaken the assertion",
179+
// and both are wrong.
180+
// * deleting the floor alone would not have been the repair either:
181+
// `for (const row of [])` asserts nothing, so it trades the red for a
182+
// silent no-op — the `[].every(...)` second-order defect the witness
183+
// pair below exists to prevent.
184+
//
185+
// So the two claims are split: a SYNTHETIC witness pair carries the rule (it
186+
// keeps discriminating at zero), and the shipped ledger is held to the rule
187+
// CONDITIONALLY on rows existing rather than being required to have them.
188+
// The rule is named once, here, so the pair and the ledger case cannot be
189+
// held to two definitions of it that drift apart.
190+
//
191+
// 40 characters is the original threshold, carried over unchanged: a `why`
192+
// shorter than that is the reassuring sentence the file's own `_exemptions`
193+
// note forbids — "a row that only asserts 'this is fine'" — rather than a
194+
// statement of WHICH name the cited file actually uses.
195+
const explainsWhichNameIsUsed = (row: KeyMentionExemption): boolean => row.why.length > 40;
196+
197+
// Both witnesses are SYNTHETIC — neither reads the shipped file — which is
198+
// the whole point: this pair goes on discriminating after the ledger burns
199+
// down to zero, where a rule carried on the live rows alone would not.
200+
// PR #12050 is the worked instance of the idiom.
201+
const WITNESS_EXPLAINED: KeyMentionExemption = {
202+
entry: 'email_template/fromOverride',
203+
path: 'email-service.ts',
204+
why: 'the file reads the compound remap `from_address`; no camelCase→snake_case fold reaches that spelling',
205+
};
206+
const WITNESS_REASSURING: KeyMentionExemption = {
207+
entry: 'email_template/fromOverride',
208+
path: 'email-service.ts',
209+
why: 'this is fine',
210+
};
211+
212+
it('accepts a conforming row, and the row-quality rule REJECTS one that only reassures', () => {
213+
// Positive half — the parser accepts a conforming row and hands it back
214+
// intact, and the rule holds for it.
215+
const parsed = parseKeyMentionBaseline({ exemptions: [WITNESS_EXPLAINED] });
216+
expect(parsed.exemptions).toEqual([WITNESS_EXPLAINED]);
217+
expect(parsed.exemptions.every(explainsWhichNameIsUsed)).toBe(true);
218+
219+
// Negative half — and the rule can FAIL. `WITNESS_REASSURING` is
220+
// STRUCTURALLY valid, so the parser accepts it: that is precisely why row
221+
// quality is a claim of its own and not one the parse already covers.
222+
expect(() => parseKeyMentionBaseline({ exemptions: [WITNESS_REASSURING] })).not.toThrow();
223+
expect(explainsWhichNameIsUsed(WITNESS_REASSURING)).toBe(false);
224+
});
225+
226+
it('reads the SHIPPED ledger, and every row that IS there explains which name the file uses', () => {
227+
const raw = JSON.parse(readFileSync(join(here, 'key-mention.baseline.json'), 'utf8')) as {
228+
_note?: unknown;
229+
};
230+
231+
// PROOF OF READ, asserted independently of how many rows come back — the
232+
// rule #11694 carries. An empty ledger is the burn-down SUCCEEDING; a file
233+
// that was never read is this case losing its subject; the two must not
234+
// look alike from here. `readFileSync` and `parseKeyMentionBaseline` throw
235+
// on the ways that can happen, and this says so out loud instead of
236+
// leaving it implicit in a loop that would be silent at zero.
237+
const note = raw._note;
238+
expect(typeof note).toBe('string');
239+
expect(String(note)).toContain('SHRINK-ONLY RATCHET');
240+
241+
const doc = parseKeyMentionBaseline(raw);
242+
243+
// ⛔ Deliberately no `toBeGreaterThan(0)`: zero rows is this ledger
244+
// reaching its goal. The check below is CONDITIONAL on rows existing and
245+
// vacuous at zero BY DESIGN — the witness pair above is what still
246+
// discriminates at that point. Reported as a list so a failure names the
247+
// offending pairs rather than a bare count.
248+
const unexplained = doc.exemptions
249+
.filter((row) => !explainsWhichNameIsUsed(row))
250+
.map((row) => `${row.entry} → ${row.path}`);
251+
expect(unexplained).toEqual([]);
170252
});
171253
});

0 commit comments

Comments
 (0)