Skip to content

Commit 3263b69

Browse files
committed
tooling(scripts): assertion floors for three more counter-sink self-tests
Same repair as the previous commit: the THUNK route PR #15198 measured, because every sink write in these three is failure-only, plus PR #15217's single hoisted battery with the roster size pinned at 1. Floors, each measured by pinning the roster to an unreachable value and reading the breach line -- never transcribed: check-console-intercept-disarm 11 (its printed 10 cases + the real-tree floor) check-examples-live-imports 36 (agrees with its printed `cases.length`) check-optional-error-sink-contract 66 (its printed 19 + 9x4 spellings + the reject side + 9 derivation + the `run` reference pin) check-examples-live-imports' one sink site is an if/ELSE, so it is wrapped by hand rather than by a brace matcher that would stop at the `if` block's own closing brace; the branches are reindented, not rewritten. ⛔ check-optional-error-sink-contract's two assertions over `baseline.entries` are deliberately left UNREGISTERED and say so in place: they run one-per-row of a shrink-only ledger, and a floor moving with that list would red every legitimate removal (#13797's ruling, carried forward by PR #15217's check-whole-set-label-write). `LOG_CHANNELS` is not that -- it is the contract's own vocabulary, not a list meant to shrink -- so its loops do register. `--self-test` stdout and stderr byte-identical to the base tree's on all three, exit 0 both sides; normal mode byte-identical where the gate has one. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012zGPuVVX3deAx9LdjK8jCk
1 parent b790f7b commit 3263b69

3 files changed

Lines changed: 377 additions & 41 deletions

File tree

scripts/check-console-intercept-disarm.mjs

Lines changed: 119 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,64 @@ export default defineConfig({ test: { disableConsoleIntercept: true } });
367367
// as one that passed (#13798).
368368
const SELF_TEST_VERDICT = 'check-console-intercept-disarm self-test reached its verdict';
369369

370+
// ── The self-test's own battery roster and floor (#13489) ──────────────────
371+
//
372+
// `failures` used to be this self-test's ONLY success condition, so "every case
373+
// held" and "the cases never ran" printed the same line. Closed the way
374+
// PR #13487 validated on check-doc-authoring: what is pinned is the registered
375+
// NAMES, not a number. The floor requires the OPENED set to equal the DECLARED
376+
// set with each battery at or above its own count.
377+
//
378+
// This file declares ONE battery, opened at the top of the self-test body. Its
379+
// blocks are headed by unmarked prose comments, so it carries fewer than the two
380+
// named section banners the sectioning criterion needs, and ⛔ a comment is NOT
381+
// promoted to a section head — that is a judgement per comment this transplant
382+
// does not make. The hoisted single battery is the shape PR #14896, PR #15003
383+
// and PR #15217 landed for exactly this case.
384+
//
385+
// ⛔ A pinned TOTAL is not the repair: a battery dropping from 9 cases to 3
386+
// keeps a total "right" the moment a sibling grows.
387+
//
388+
// The count is a FLOOR, not an equality — adding cases is ordinary work and must
389+
// not red. A battery BELOW its floor means cases stopped running; the remedy is
390+
// to find what stopped registering.
391+
const SELF_TEST_BATTERIES = Object.freeze({
392+
'check-console-intercept-disarm self-test': 11,
393+
});
394+
395+
// DELETING an entry silences that battery's floor exactly as effectively as
396+
// zeroing it, so the roster's own size is pinned too.
397+
const SELF_TEST_BATTERY_FLOOR = 1;
398+
399+
// The key an assertion is filed under when no battery is open. It is not a
400+
// declared battery, so it reds by the same set difference rather than silently
401+
// inflating whichever battery happened to run last.
402+
const UNATTRIBUTED_BATTERY = '(no battery open)';
403+
370404
function selfTest() {
405+
// The battery ledger this self-test's floor is evaluated against (#13489).
406+
// `battery()` opens a battery; every assertion below is attributed to the one
407+
// most recently opened, so a section that stops running stops registering and
408+
// names ITSELF at the floor rather than going quiet.
409+
const batterySeen = new Map();
410+
let openBattery = null;
411+
const battery = (name) => {
412+
openBattery = name;
413+
};
414+
const registerCase = () => {
415+
const b = openBattery ?? UNATTRIBUTED_BATTERY;
416+
batterySeen.set(b, (batterySeen.get(b) ?? 0) + 1);
417+
};
418+
battery('check-console-intercept-disarm self-test');
419+
// The thunk PR #15198 measured: it registers the case and then runs the
420+
// existing site VERBATIM, so no assertion condition is inverted or rewritten
421+
// and the sink keeps its own semantics. Registration happens whether or not
422+
// the site fires, which is what makes the count a floor on cases RUN rather
423+
// than a count of failures.
424+
const check = (fn) => {
425+
registerCase();
426+
fn();
427+
};
371428
const cases = [
372429
{
373430
name: 'disarmed package passes',
@@ -499,24 +556,75 @@ function selfTest() {
499556
) {
500557
problems.push(`expected ${testCase.expectVitestPackages} vitest package(s), got ${vitestPackages}`);
501558
}
502-
if (problems.length > 0) {
503-
failures += 1;
504-
console.error(`self-test FAIL: ${testCase.name}\n ${problems.join('\n ')}`);
505-
for (const f of findings) console.error(` finding: ${f.split('\n')[0]}`);
506-
}
559+
check(() => {
560+
if (problems.length > 0) {
561+
failures += 1;
562+
console.error(`self-test FAIL: ${testCase.name}\n ${problems.join('\n ')}`);
563+
for (const f of findings) console.error(` finding: ${f.split('\n')[0]}`);
564+
}
565+
});
507566
} finally {
508567
rmSync(caseDir, { recursive: true, force: true });
509568
}
510569
}
511570

512571
// Anti-vacuity over the REAL tree: the scan must see the real population.
513572
const real = scan(REPO_ROOT);
514-
if (real.vitestPackages < 60) {
515-
failures += 1;
516-
console.error(
517-
`self-test FAIL: real-tree scan sees only ${real.vitestPackages} vitest-running ` +
518-
`package(s); the population this gate was written against had 72. The ` +
519-
`workspace expansion has gone blind, which would pass every future arrival.`,
573+
check(() => {
574+
if (real.vitestPackages < 60) {
575+
failures += 1;
576+
console.error(
577+
`self-test FAIL: real-tree scan sees only ${real.vitestPackages} vitest-running ` +
578+
`package(s); the population this gate was written against had 72. The ` +
579+
`workspace expansion has gone blind, which would pass every future arrival.`,
580+
);
581+
}
582+
});
583+
584+
// ── The floor: every declared battery RAN, and ran its cases (#13489) ────
585+
//
586+
// Evaluated after every battery has had its chance and BEFORE the verdict, so
587+
// the success line below can only be printed by a run in which the set of
588+
// batteries that registered assertions EQUALS the set declared. A set
589+
// difference names WHICH battery stopped; a count says only that something did.
590+
// This file's sink is the `failures` counter, so the floor speaks its idiom: a
591+
// breach prints like any other case failure and reds through the existing
592+
// verdict below.
593+
const floorFailure = (message) => { console.error(message); failures += 1; };
594+
const declaredBatteries = Object.keys(SELF_TEST_BATTERIES);
595+
let floorBreached = false;
596+
if (declaredBatteries.length < SELF_TEST_BATTERY_FLOOR) {
597+
floorBreached = true;
598+
floorFailure(
599+
`SELF_TEST_BATTERIES declares ${declaredBatteries.length} batteries, below the pinned `
600+
+ `${SELF_TEST_BATTERY_FLOOR} — a battery deleted from the roster takes its own floor with it.`,
601+
);
602+
}
603+
for (const [name, count] of batterySeen) {
604+
if (declaredBatteries.includes(name)) continue;
605+
floorBreached = true;
606+
floorFailure(
607+
`self-test battery "${name}" registered ${count} case(s) but is not declared in `
608+
+ 'SELF_TEST_BATTERIES — an assertion attributed to no declared battery is one nothing floors.',
609+
);
610+
}
611+
for (const name of declaredBatteries) {
612+
const count = batterySeen.get(name) ?? 0;
613+
if (count >= SELF_TEST_BATTERIES[name]) continue;
614+
floorBreached = true;
615+
floorFailure(
616+
count === 0
617+
? `self-test battery "${name}" DID NOT RUN — 0 cases registered, ${SELF_TEST_BATTERIES[name]} pinned. `
618+
+ 'The verdict below would have claimed those cases hold.'
619+
: `self-test battery "${name}" registered ${count} case(s), below its pinned floor of `
620+
+ `${SELF_TEST_BATTERIES[name]} — cases that used to run no longer do.`,
621+
);
622+
}
623+
if (floorBreached) {
624+
floorFailure(
625+
'A battery at or below its floor means cases STOPPED RUNNING — the battery is the bug, not the '
626+
+ 'number. Find what stopped registering (an early return, a deleted block, a guard that now '
627+
+ 'skips) and restore it.',
520628
);
521629
}
522630

scripts/check-examples-live-imports.mjs

Lines changed: 113 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,64 @@ function verify() {
757757
// as one that passed (#13798).
758758
const SELF_TEST_VERDICT = 'check-examples-live-imports self-test reached its verdict';
759759

760+
// ── The self-test's own battery roster and floor (#13489) ──────────────────
761+
//
762+
// `failed` used to be this self-test's ONLY success condition, so "every case
763+
// held" and "the cases never ran" printed the same line. Closed the way
764+
// PR #13487 validated on check-doc-authoring: what is pinned is the registered
765+
// NAMES, not a number. The floor requires the OPENED set to equal the DECLARED
766+
// set with each battery at or above its own count.
767+
//
768+
// This file declares ONE battery, opened at the top of the self-test body. Its
769+
// blocks are headed by unmarked prose comments, so it carries fewer than the two
770+
// named section banners the sectioning criterion needs, and ⛔ a comment is NOT
771+
// promoted to a section head — that is a judgement per comment this transplant
772+
// does not make. The hoisted single battery is the shape PR #14896, PR #15003
773+
// and PR #15217 landed for exactly this case.
774+
//
775+
// ⛔ A pinned TOTAL is not the repair: a battery dropping from 9 cases to 3
776+
// keeps a total "right" the moment a sibling grows.
777+
//
778+
// The count is a FLOOR, not an equality — adding cases is ordinary work and must
779+
// not red. A battery BELOW its floor means cases stopped running; the remedy is
780+
// to find what stopped registering.
781+
const SELF_TEST_BATTERIES = Object.freeze({
782+
'check-examples-live-imports self-test': 36,
783+
});
784+
785+
// DELETING an entry silences that battery's floor exactly as effectively as
786+
// zeroing it, so the roster's own size is pinned too.
787+
const SELF_TEST_BATTERY_FLOOR = 1;
788+
789+
// The key an assertion is filed under when no battery is open. It is not a
790+
// declared battery, so it reds by the same set difference rather than silently
791+
// inflating whichever battery happened to run last.
792+
const UNATTRIBUTED_BATTERY = '(no battery open)';
793+
760794
function selfTest() {
795+
// The battery ledger this self-test's floor is evaluated against (#13489).
796+
// `battery()` opens a battery; every assertion below is attributed to the one
797+
// most recently opened, so a section that stops running stops registering and
798+
// names ITSELF at the floor rather than going quiet.
799+
const batterySeen = new Map();
800+
let openBattery = null;
801+
const battery = (name) => {
802+
openBattery = name;
803+
};
804+
const registerCase = () => {
805+
const b = openBattery ?? UNATTRIBUTED_BATTERY;
806+
batterySeen.set(b, (batterySeen.get(b) ?? 0) + 1);
807+
};
808+
battery('check-examples-live-imports self-test');
809+
// The thunk PR #15198 measured: it registers the case and then runs the
810+
// existing site VERBATIM, so no assertion condition is inverted or rewritten
811+
// and the sink keeps its own semantics. Registration happens whether or not
812+
// the site fires, which is what makes the count a floor on cases RUN rather
813+
// than a count of failures.
814+
const check = (fn) => {
815+
registerCase();
816+
fn();
817+
};
761818
const apps = [
762819
{ dir: 'examples/app-showcase', name: '@objectstack/example-showcase' },
763820
{ dir: 'examples/app-crm', name: '@objectstack/example-crm' },
@@ -902,13 +959,63 @@ function selfTest() {
902959

903960
let failed = 0;
904961
for (const [name, ok] of cases) {
905-
if (!ok) {
906-
failed++;
907-
console.error(` FAIL ${name}`);
908-
} else {
909-
console.log(` ok ${name}`);
910-
}
962+
check(() => {
963+
if (!ok) {
964+
failed++;
965+
console.error(` FAIL ${name}`);
966+
} else {
967+
console.log(` ok ${name}`);
968+
}
969+
});
970+
}
971+
// ── The floor: every declared battery RAN, and ran its cases (#13489) ────
972+
//
973+
// Evaluated after every battery has had its chance and BEFORE the verdict, so
974+
// the success line below can only be printed by a run in which the set of
975+
// batteries that registered assertions EQUALS the set declared. A set
976+
// difference names WHICH battery stopped; a count says only that something did.
977+
// This file's sink is the `failed` counter, so the floor speaks its idiom: a
978+
// breach prints like any other case failure and reds through the existing
979+
// verdict below. It is evaluated AFTER the verdict loop, because that loop is
980+
// where the cases register.
981+
const floorFailure = (message) => { console.error(` FAIL ${message}`); failed++; };
982+
const declaredBatteries = Object.keys(SELF_TEST_BATTERIES);
983+
let floorBreached = false;
984+
if (declaredBatteries.length < SELF_TEST_BATTERY_FLOOR) {
985+
floorBreached = true;
986+
floorFailure(
987+
`SELF_TEST_BATTERIES declares ${declaredBatteries.length} batteries, below the pinned `
988+
+ `${SELF_TEST_BATTERY_FLOOR} — a battery deleted from the roster takes its own floor with it.`,
989+
);
990+
}
991+
for (const [name, count] of batterySeen) {
992+
if (declaredBatteries.includes(name)) continue;
993+
floorBreached = true;
994+
floorFailure(
995+
`self-test battery "${name}" registered ${count} case(s) but is not declared in `
996+
+ 'SELF_TEST_BATTERIES — an assertion attributed to no declared battery is one nothing floors.',
997+
);
911998
}
999+
for (const name of declaredBatteries) {
1000+
const count = batterySeen.get(name) ?? 0;
1001+
if (count >= SELF_TEST_BATTERIES[name]) continue;
1002+
floorBreached = true;
1003+
floorFailure(
1004+
count === 0
1005+
? `self-test battery "${name}" DID NOT RUN — 0 cases registered, ${SELF_TEST_BATTERIES[name]} pinned. `
1006+
+ 'The verdict below would have claimed those cases hold.'
1007+
: `self-test battery "${name}" registered ${count} case(s), below its pinned floor of `
1008+
+ `${SELF_TEST_BATTERIES[name]} — cases that used to run no longer do.`,
1009+
);
1010+
}
1011+
if (floorBreached) {
1012+
floorFailure(
1013+
'A battery at or below its floor means cases STOPPED RUNNING — the battery is the bug, not the '
1014+
+ 'number. Find what stopped registering (an early return, a deleted block, a guard that now '
1015+
+ 'skips) and restore it.',
1016+
);
1017+
}
1018+
9121019
if (failed) {
9131020
console.error(`\n${failed}/${cases.length} self-test case(s) failed.`);
9141021
process.exit(1);

0 commit comments

Comments
 (0)