Skip to content

Commit a35dd34

Browse files
claude[bot]claude
andauthored
test(scripts): batch 8b — assertion floors for two b4-thunk and two recipe-A self-tests (#15307)
* test(scripts): floor measure-test-shard-timings' self-test on a registered battery The 22 bare `if (...) throw ...` assertions in `selfTest()` are each wrapped verbatim in the `check(() => { ... })` thunk PR #15198 landed: the condition is carried in untouched, so no `!` can be dropped while the case still registers and still passes. Zero named section banners, so one hoisted battery (the PR #14896 / #15003 / #15217 shape), floored at the measured 22 with the roster's own size pinned at 1. The floor throws, matching this file's own sink, and is evaluated before the verdict so the success line can only be printed by a run that actually ran its cases. Part of #13799 Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012zGPuVVX3deAx9LdjK8jCk * test(scripts): floor measure-position-name-fold-census' self-test on a registered battery The 13 `if (...) problems.push(...)` assertion sites in `selfTest()` are each wrapped verbatim in the `check(() => { ... })` thunk PR #15198 landed. The sink here is FAILURE-ONLY, so routing `problems.push` itself through `registerCase()` would have inverted the floor rather than installing it: a green run would register nothing and the battery would read DID NOT RUN. Zero named banners, so one hoisted battery, floored at the 24 registrations measured on a run (four of the thirteen sites sit inside loops: 9 + 4 + 4 + 2 + 5). The floor lives inside the `!quiet` branch. `main()` gates the PRODUCTION census on `selfTest({ quiet: true })`, which prints no verdict and so makes no claim for a floor to guard; evaluating it there would let a roster edit change what a census run outputs. Both production modes are byte-identical to the base tree. One site stays outside the roster and says so in place: the `catch` arm of the AUDIT_CONTROLS loop ends in `continue`, illegal inside the thunk's arrow function, and rewriting that control flow is exactly what the verbatim rule forbids. Its sibling in the same loop body is floored, so a loop that stops running still reds. Part of #13799 Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012zGPuVVX3deAx9LdjK8jCk * test(scripts): floor check-override-consistency's self-test on its table rows Recipe A as the pilot PR #15271 settled it: each of the 17 row labels of the literal `cases` table is a declared battery with a floor of 1, `registerCase(name)` is the first statement of the driving loop body, and the roster is a LITERAL the table is cross-checked against so a deleted or renamed row names ITSELF rather than deleting its own floor. Roster size pinned at 17; duplicate labels are refused from both sides. The three `// --- ... ---` comments inside the array are grouping rules, not section heads. The boolean `passed` becomes a `failures` counter so the red line can carry the recipe's wording, `N failure(s) (cases and floor)`; no assertion condition is touched and the green line is byte-identical to the base tree's. Part of #13799 Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012zGPuVVX3deAx9LdjK8jCk * test(scripts): floor check-skill-line-ratchet's self-test on all 155 table rows Recipe A per the pilot PR #15271: every row label is a declared battery with a floor of 1, `registerCase(name)` is the first statement of the driving loop, the roster is a LITERAL cross-checked against the table, size pinned at 155. The only deleted line is the red-run verdict, reworded to the recipe's `N failure(s) (cases and floor)`; the green line stays byte-identical. The batch-8 census flagged this table's four `...(() => { ... })()` spreads as an IIFE-produced block whose rows could not take a literal roster key. Measured, that premise does not hold here: each IIFE is a SCOPING device that declares local fixture consts and then returns an array of LITERAL [label, actual, expected] rows. No label is a template string or computed, and no row comes from a map/push/loop. Three independent readings agree on 155 -- labels extracted from source, literal row starts, and the `cases.length` the green line prints on a run -- so ALL 155 rows are floored with no residue, rather than the partition the row anticipated. Part of #13799 Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012zGPuVVX3deAx9LdjK8jCk --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 88a35c2 commit a35dd34

4 files changed

Lines changed: 775 additions & 95 deletions

File tree

scripts/check-override-consistency.mjs

Lines changed: 124 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,63 @@ const FIXTURE_LOCKFILE = [
429429
'',
430430
].join('\n');
431431

432+
// -- The self-test's own battery roster and floor (#13489) ------------------
433+
//
434+
// `--self-test` reaching its verdict used to be this self-test's ONLY success
435+
// condition, so "every case held" and "the cases never ran" printed the same
436+
// line. Closed the PR #13487 way: what is pinned is the registered NAMES, not a
437+
// number.
438+
//
439+
// This self-test is TABLE-DRIVEN -- one literal `cases` table, one loop over it,
440+
// and a sink that writes only when a case FAILS. Routing THAT sink through
441+
// `registerCase()` would register a case only when it fails: a fully green run
442+
// would register 0 and every battery would read DID NOT RUN, the floor inverted
443+
// rather than installed. So the roster is the table's own rows. Each row LABEL
444+
// is a declared battery, verbatim, with a floor of 1, and `registerCase(name)`
445+
// is the first statement of the driving loop body -- so the case is attributed
446+
// to the row actually being run, whatever that row asserts afterwards. There is
447+
// no `battery()` opener: for a table-driven self-test the ROW is the battery.
448+
//
449+
// The three `// --- ... ---` comments inside the table are grouping rules, not
450+
// section heads, and a comment is NOT promoted to one -- the rows are the
451+
// batteries either way.
452+
//
453+
// A pinned TOTAL is not the repair, and neither is a roster DERIVED from the
454+
// table: `cases.length` moves with the table, so a deleted row would delete its
455+
// own floor. The roster below is a LITERAL the table is checked against, which
456+
// is what lets a deleted or renamed row name ITSELF in the refusal.
457+
//
458+
// The counts are a FLOOR, not an equality -- a row that grows into several
459+
// registrations must not red. 1 is the honest floor for a table row: the loop
460+
// reaches it exactly once per run.
461+
const SELF_TEST_BATTERIES = Object.freeze({
462+
'lockfile parses into a consumer index': 1,
463+
'unparseable lockfile -> census skipped, never a crash': 1,
464+
'lockfile that is not a mapping -> census skipped': 1,
465+
'transitive consumer present (snapshot pulls undici) -> NOT reported': 1,
466+
'workspace importer counts as a consumer (semver) -> NOT reported': 1,
467+
'zero consumers (nothing pulls form-data) -> REPORTED': 1,
468+
'census reports only the idle one out of a mixed set': 1,
469+
'bound equal to the target floor (the #5032 undici shape) -> REPORTED': 1,
470+
'bound below the target floor (uncovered gap) -> REPORTED': 1,
471+
'bound above the target version line (the durable shape) -> NOT reported': 1,
472+
'selector with no upper bound -> NOT reported': 1,
473+
'inclusive upper bound covers the target -> NOT reported': 1,
474+
'declared range that reaches the target -> no violation': 1,
475+
'declared range that cannot reach the target -> violation': 1,
476+
'no implicit prereleases: ^1.7.0 does not reach 1.7.0-rc.2': 1,
477+
'declaration outside the selector scope -> override does not apply': 1,
478+
'declaration inside the selector scope -> override applies': 1,
479+
});
480+
481+
// DELETING an entry silences that battery's floor exactly as effectively as
482+
// zeroing it, so the roster's own size is pinned too. This pin is also half of
483+
// the duplicate-label refusal: two rows sharing a label collapse to ONE key in
484+
// the literal above, so the roster falls below this number; the table
485+
// cross-check in the floor block is the other half, and names WHICH label
486+
// collided.
487+
const SELF_TEST_BATTERY_FLOOR = 17;
488+
432489
// Returned by `selfTest()` only after its verdict is printed. The dispatch
433490
// refuses anything else: a `return` that leaves the function above that line
434491
// prints nothing and still exits 0 — a self-test that never finished, reported
@@ -542,25 +599,88 @@ function selfTest() {
542599
},
543600
];
544601

545-
let passed = true;
602+
// The ledger this self-test's floor is evaluated against (#13489).
603+
const batterySeen = new Map();
604+
const registerCase = (name) => {
605+
batterySeen.set(name, (batterySeen.get(name) ?? 0) + 1);
606+
};
607+
608+
let failures = 0;
546609
console.log('check-override-consistency self-test (both directions):');
547610
for (const testCase of cases) {
611+
registerCase(testCase.name);
548612
let actual;
549613
try {
550614
actual = testCase.actual();
551615
} catch (error) {
552616
actual = `threw: ${error.message}`;
553617
}
554618
const ok = actual === testCase.expect;
555-
if (!ok) passed = false;
619+
if (!ok) failures++;
556620
console.log(
557621
`${ok ? ' ✓' : ' ✗'} ${testCase.name}` +
558622
(ok ? '' : `\n expected ${JSON.stringify(testCase.expect)}, got ${JSON.stringify(actual)}`),
559623
);
560624
}
561625

562-
if (!passed) {
563-
console.error('\n✗ self-test failed — this check does not do what it claims.');
626+
// -- The floor: every declared row RAN, and ran its case (#13489) --------
627+
//
628+
// Evaluated after every row has had its chance and BEFORE the verdict, so the
629+
// success line below can only be printed by a run in which the set of rows
630+
// that registered EQUALS the set declared. A set difference names WHICH row
631+
// stopped; a count says only that something did.
632+
const floorFailure = (message) => {
633+
console.error(`✗ self-test floor: ${message}`);
634+
failures++;
635+
};
636+
const declaredBatteries = Object.keys(SELF_TEST_BATTERIES);
637+
let floorBreached = false;
638+
if (declaredBatteries.length < SELF_TEST_BATTERY_FLOOR) {
639+
floorBreached = true;
640+
floorFailure(
641+
`SELF_TEST_BATTERIES declares ${declaredBatteries.length} batteries, below the pinned ` +
642+
`${SELF_TEST_BATTERY_FLOOR} — a battery deleted from the roster takes its own floor with it.`,
643+
);
644+
}
645+
const rowLabels = cases.map((c) => c.name);
646+
const duplicated = [...new Set(rowLabels.filter((name, i) => rowLabels.indexOf(name) !== i))];
647+
if (duplicated.length > 0) {
648+
floorBreached = true;
649+
floorFailure(
650+
`the cases table uses ${duplicated.map((n) => JSON.stringify(n)).join(', ')} as a row label more than once — ` +
651+
'two rows sharing a label are ONE battery, so the second can stop running while the first keeps the floor met.',
652+
);
653+
}
654+
for (const [name, count] of batterySeen) {
655+
if (declaredBatteries.includes(name)) continue;
656+
floorBreached = true;
657+
floorFailure(
658+
`self-test battery "${name}" registered ${count} case(s) but is not declared in ` +
659+
'SELF_TEST_BATTERIES — a case attributed to no declared battery is one nothing floors.',
660+
);
661+
}
662+
for (const name of declaredBatteries) {
663+
const count = batterySeen.get(name) ?? 0;
664+
if (count >= SELF_TEST_BATTERIES[name]) continue;
665+
floorBreached = true;
666+
floorFailure(
667+
count === 0
668+
? `self-test battery "${name}" DID NOT RUN — 0 cases registered, ${SELF_TEST_BATTERIES[name]} pinned. ` +
669+
'The verdict below would have claimed that case holds.'
670+
: `self-test battery "${name}" registered ${count} case(s), below its pinned floor of ` +
671+
`${SELF_TEST_BATTERIES[name]} — cases that used to run no longer do.`,
672+
);
673+
}
674+
if (floorBreached) {
675+
floorFailure(
676+
'A battery at or below its floor means cases STOPPED RUNNING — the battery is the bug, not the ' +
677+
'number. Find what stopped registering (a deleted row, a renamed label, a loop that no longer ' +
678+
'reaches it) and restore it.',
679+
);
680+
}
681+
682+
if (failures) {
683+
console.error(`\n✗ check-override-consistency self-test: ${failures} failure(s) (cases and floor).`);
564684
process.exit(1);
565685
}
566686
console.log(

0 commit comments

Comments
 (0)