From 69df53434383abf9965653812ed8f6fffc2d2fdb Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 4 Sep 2026 06:20:01 +0000 Subject: [PATCH 1/5] tooling(scripts): floor the check-dts-emitted self-test with a single hoisted battery (#13799) The self-test decided success by `failures.length === 0` alone, so "every case held" and "the cases never ran" printed the same line. It carries no named section banner, and a comment is not promoted to a section head, so it declares ONE battery opened at the top of the body -- the hoisted shape PRs #14896 and #15003 landed for exactly this case. Floor 8, measured rather than transcribed: the roster was probed with a deliberately unreachable pin and the floor's own report named the registered count. Behaviour is unchanged -- `--self-test` stdout and stderr are byte-identical against origin/main, exit 0 both sides. Claude-Session: https://claude.ai/code/session_012zGPuVVX3deAx9LdjK8jCk Co-authored-by: Claude --- scripts/check-dts-emitted.mjs | 92 +++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) diff --git a/scripts/check-dts-emitted.mjs b/scripts/check-dts-emitted.mjs index 86247ad9f7..6e0de6a838 100644 --- a/scripts/check-dts-emitted.mjs +++ b/scripts/check-dts-emitted.mjs @@ -233,9 +233,57 @@ function run(dir) { // handshake is a flag rather than a returned sentinel. let selfTestReachedVerdict = false; +// ── The self-test's own battery roster and floor (#13489) ────────────────── +// +// `failures.length === 0` used to be this self-test's ONLY success condition, so +// "every case held" and "the cases never ran" printed the same line. Closed the +// way PR #13487 validated on check-doc-authoring: what is pinned is the +// registered NAMES, not a number. The floor requires the OPENED set to equal the +// DECLARED set with each battery at or above its own count. +// +// This file declares ONE battery, opened at the top of the self-test body. It +// carries fewer than the two named section banners the sectioning criterion +// needs, and ⛔ a comment is NOT promoted to a section head — that is a +// judgement per comment this transplant does not make. The hoisted single +// battery is the shape PR #14896 and PR #15003 landed for exactly this case. +// +// ⛔ A pinned TOTAL is not the repair: a battery dropping from 9 cases to 3 +// keeps a total "right" the moment a sibling grows. +// +// The count is a FLOOR, not an equality — adding cases is ordinary work and must +// not red. A battery BELOW its floor means cases stopped running; the remedy is +// to find what stopped registering. +const SELF_TEST_BATTERIES = Object.freeze({ + 'check-dts-emitted self-test': 8, +}); + +// DELETING an entry silences that battery's floor exactly as effectively as +// zeroing it, so the roster's own size is pinned too. +const SELF_TEST_BATTERY_FLOOR = 1; + +// The key an assertion is filed under when no battery is open. It is not a +// declared battery, so it reds by the same set difference rather than silently +// inflating whichever battery happened to run last. +const UNATTRIBUTED_BATTERY = '(no battery open)'; + function selfTest() { + // The battery ledger this self-test's floor is evaluated against (#13489). + // `battery()` opens a battery; every assertion below is attributed to the one + // most recently opened, so a section that stops running stops registering and + // names ITSELF at the floor rather than going quiet. + const batterySeen = new Map(); + let openBattery = null; + const battery = (name) => { + openBattery = name; + }; + const registerCase = () => { + const b = openBattery ?? UNATTRIBUTED_BATTERY; + batterySeen.set(b, (batterySeen.get(b) ?? 0) + 1); + }; + battery('check-dts-emitted self-test'); const failures = []; const eq = (label, actual, expected) => { + registerCase(); const a = JSON.stringify(actual); const e = JSON.stringify(expected); if (a !== e) failures.push(`${label}\n expected ${e}\n actual ${a}`); @@ -295,6 +343,50 @@ function selfTest() { ['empty:dist/index.d.ts'], ); + // ── The floor: every declared battery RAN, and ran its cases (#13489) ──── + // + // Evaluated after every battery has had its chance and BEFORE the verdict, so + // the success line below can only be printed by a run in which the set of + // batteries that registered assertions EQUALS the set declared. A set + // difference names WHICH battery stopped; a count says only that something did. + const floorFailure = (message) => { failures.push(message); }; + const declaredBatteries = Object.keys(SELF_TEST_BATTERIES); + let floorBreached = false; + if (declaredBatteries.length < SELF_TEST_BATTERY_FLOOR) { + floorBreached = true; + floorFailure( + `SELF_TEST_BATTERIES declares ${declaredBatteries.length} batteries, below the pinned ` + + `${SELF_TEST_BATTERY_FLOOR} — a battery deleted from the roster takes its own floor with it.`, + ); + } + for (const [name, count] of batterySeen) { + if (declaredBatteries.includes(name)) continue; + floorBreached = true; + floorFailure( + `self-test battery "${name}" registered ${count} case(s) but is not declared in ` + + 'SELF_TEST_BATTERIES — an assertion attributed to no declared battery is one nothing floors.', + ); + } + for (const name of declaredBatteries) { + const count = batterySeen.get(name) ?? 0; + if (count >= SELF_TEST_BATTERIES[name]) continue; + floorBreached = true; + floorFailure( + count === 0 + ? `self-test battery "${name}" DID NOT RUN — 0 cases registered, ${SELF_TEST_BATTERIES[name]} pinned. ` + + 'The verdict below would have claimed those cases hold.' + : `self-test battery "${name}" registered ${count} case(s), below its pinned floor of ` + + `${SELF_TEST_BATTERIES[name]} — cases that used to run no longer do.`, + ); + } + if (floorBreached) { + floorFailure( + 'A battery at or below its floor means cases STOPPED RUNNING — the battery is the bug, not the ' + + 'number. Find what stopped registering (an early return, a deleted block, a guard that now ' + + 'skips) and restore it.', + ); + } + if (failures.length > 0) { console.error(`\nx check-dts-emitted self-test: ${failures.length} failure(s)\n`); for (const f of failures) console.error(` - ${f}\n`); From 05422bd75bc136ff625d0f574691cd58bb651b3e Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 4 Sep 2026 06:22:00 +0000 Subject: [PATCH 2/5] tooling(scripts): floor the logger-receiver-detach and objectql-double-limit self-tests (#13799) Both decided success by `failures.length === 0` alone. Neither carries the two named section banners the sectioning criterion needs, and a comment is not promoted to a section head, so each declares ONE battery opened at the top of its self-test body -- the hoisted shape PRs #14896 and #15003 landed. Floors 47 and 47, measured by probing the roster with an unreachable pin and reading the count the floor's own report names. `--self-test` stdout and stderr are byte-identical against origin/main for both, exit 0 on both sides. Claude-Session: https://claude.ai/code/session_012zGPuVVX3deAx9LdjK8jCk Co-authored-by: Claude --- scripts/check-logger-receiver-detach.mjs | 94 +++++++++++++++++++++++- scripts/check-objectql-double-limit.mjs | 93 ++++++++++++++++++++++- 2 files changed, 185 insertions(+), 2 deletions(-) diff --git a/scripts/check-logger-receiver-detach.mjs b/scripts/check-logger-receiver-detach.mjs index a0414cd025..95d9a6adc0 100644 --- a/scripts/check-logger-receiver-detach.mjs +++ b/scripts/check-logger-receiver-detach.mjs @@ -583,9 +583,56 @@ function measure() { // as one that passed (#13798). const SELF_TEST_VERDICT = 'check-logger-receiver-detach self-test reached its verdict'; +// ── The self-test's own battery roster and floor (#13489) ────────────────── +// +// `failures.length === 0` used to be this self-test's ONLY success condition, so +// "every case held" and "the cases never ran" printed the same line. Closed the +// way PR #13487 validated on check-doc-authoring: what is pinned is the +// registered NAMES, not a number. The floor requires the OPENED set to equal the +// DECLARED set with each battery at or above its own count. +// +// This file declares ONE battery, opened at the top of the self-test body. It +// carries fewer than the two named section banners the sectioning criterion +// needs, and ⛔ a comment is NOT promoted to a section head — that is a +// judgement per comment this transplant does not make. The hoisted single +// battery is the shape PR #14896 and PR #15003 landed for exactly this case. +// +// ⛔ A pinned TOTAL is not the repair: a battery dropping from 9 cases to 3 +// keeps a total "right" the moment a sibling grows. +// +// The count is a FLOOR, not an equality — adding cases is ordinary work and must +// not red. A battery BELOW its floor means cases stopped running; the remedy is +// to find what stopped registering. +const SELF_TEST_BATTERIES = Object.freeze({ + 'check-logger-receiver-detach self-test': 47, +}); + +// DELETING an entry silences that battery's floor exactly as effectively as +// zeroing it, so the roster's own size is pinned too. +const SELF_TEST_BATTERY_FLOOR = 1; + +// The key an assertion is filed under when no battery is open. It is not a +// declared battery, so it reds by the same set difference rather than silently +// inflating whichever battery happened to run last. +const UNATTRIBUTED_BATTERY = '(no battery open)'; + function selfTest() { + // The battery ledger this self-test's floor is evaluated against (#13489). + // `battery()` opens a battery; every assertion below is attributed to the + // one most recently opened, so a section that stops running stops + // registering and names ITSELF at the floor rather than going quiet. + const batterySeen = new Map(); + let openBattery = null; + const battery = (name) => { + openBattery = name; + }; + const registerCase = () => { + const b = openBattery ?? UNATTRIBUTED_BATTERY; + batterySeen.set(b, (batterySeen.get(b) ?? 0) + 1); + }; + battery('check-logger-receiver-detach self-test'); const failures = []; - const expect = (what, ok) => { if (!ok) failures.push(what); }; + const expect = (what, ok) => { registerCase(); if (!ok) failures.push(what); }; // The control corpus -- both halves. const problems = controlProblems(); @@ -691,6 +738,51 @@ function selfTest() { expect('and no hint names a root this gate does not walk', ROOT_DIR_WATCH_HINTS.every((h) => SCAN_ROOTS.some((r) => h.startsWith(`${r}/`)))); + // ── The floor: every declared battery RAN, and ran its cases (#13489) ──── + // + // Evaluated after every battery has had its chance and BEFORE the verdict, + // so the success line below can only be printed by a run in which the set of + // batteries that registered assertions EQUALS the set declared. A set + // difference names WHICH battery stopped; a count says only that something + // did. + const floorFailure = (message) => { failures.push(message); }; + const declaredBatteries = Object.keys(SELF_TEST_BATTERIES); + let floorBreached = false; + if (declaredBatteries.length < SELF_TEST_BATTERY_FLOOR) { + floorBreached = true; + floorFailure( + `SELF_TEST_BATTERIES declares ${declaredBatteries.length} batteries, below the pinned ` + + `${SELF_TEST_BATTERY_FLOOR} — a battery deleted from the roster takes its own floor with it.`, + ); + } + for (const [name, count] of batterySeen) { + if (declaredBatteries.includes(name)) continue; + floorBreached = true; + floorFailure( + `self-test battery "${name}" registered ${count} case(s) but is not declared in ` + + 'SELF_TEST_BATTERIES — an assertion attributed to no declared battery is one nothing floors.', + ); + } + for (const name of declaredBatteries) { + const count = batterySeen.get(name) ?? 0; + if (count >= SELF_TEST_BATTERIES[name]) continue; + floorBreached = true; + floorFailure( + count === 0 + ? `self-test battery "${name}" DID NOT RUN — 0 cases registered, ${SELF_TEST_BATTERIES[name]} pinned. ` + + 'The verdict below would have claimed those cases hold.' + : `self-test battery "${name}" registered ${count} case(s), below its pinned floor of ` + + `${SELF_TEST_BATTERIES[name]} — cases that used to run no longer do.`, + ); + } + if (floorBreached) { + floorFailure( + 'A battery at or below its floor means cases STOPPED RUNNING — the battery is the bug, not ' + + 'the number. Find what stopped registering (an early return, a deleted block, a guard that ' + + 'now skips) and restore it.', + ); + } + if (failures.length > 0) { console.error(`x check-logger-receiver-detach --self-test (${failures.length} failure(s)):\n`); for (const f of failures) console.error(` - ${f}`); diff --git a/scripts/check-objectql-double-limit.mjs b/scripts/check-objectql-double-limit.mjs index 5437e14f46..6d5051fe6f 100644 --- a/scripts/check-objectql-double-limit.mjs +++ b/scripts/check-objectql-double-limit.mjs @@ -1095,9 +1095,56 @@ async function judgeFixture(src) { // as one that passed (#13798). const SELF_TEST_VERDICT = 'check-objectql-double-limit self-test reached its verdict'; +// ── The self-test's own battery roster and floor (#13489) ────────────────── +// +// `failures.length === 0` used to be this self-test's ONLY success condition, so +// "every case held" and "the cases never ran" printed the same line. Closed the +// way PR #13487 validated on check-doc-authoring: what is pinned is the +// registered NAMES, not a number. The floor requires the OPENED set to equal the +// DECLARED set with each battery at or above its own count. +// +// This file declares ONE battery, opened at the top of the self-test body. It +// carries fewer than the two named section banners the sectioning criterion +// needs, and ⛔ a comment is NOT promoted to a section head — that is a +// judgement per comment this transplant does not make. The hoisted single +// battery is the shape PR #14896 and PR #15003 landed for exactly this case. +// +// ⛔ A pinned TOTAL is not the repair: a battery dropping from 9 cases to 3 +// keeps a total "right" the moment a sibling grows. +// +// The count is a FLOOR, not an equality — adding cases is ordinary work and must +// not red. A battery BELOW its floor means cases stopped running; the remedy is +// to find what stopped registering. +const SELF_TEST_BATTERIES = Object.freeze({ + 'check-objectql-double-limit self-test': 47, +}); + +// DELETING an entry silences that battery's floor exactly as effectively as +// zeroing it, so the roster's own size is pinned too. +const SELF_TEST_BATTERY_FLOOR = 1; + +// The key an assertion is filed under when no battery is open. It is not a +// declared battery, so it reds by the same set difference rather than silently +// inflating whichever battery happened to run last. +const UNATTRIBUTED_BATTERY = '(no battery open)'; + async function selfTest() { + // The battery ledger this self-test's floor is evaluated against (#13489). + // `battery()` opens a battery; every assertion below is attributed to the one + // most recently opened, so a section that stops running stops registering and + // names ITSELF at the floor rather than going quiet. + const batterySeen = new Map(); + let openBattery = null; + const battery = (name) => { + openBattery = name; + }; + const registerCase = () => { + const b = openBattery ?? UNATTRIBUTED_BATTERY; + batterySeen.set(b, (batterySeen.get(b) ?? 0) + 1); + }; + battery('check-objectql-double-limit self-test'); const failures = []; - const expect = (label, cond) => { if (!cond) failures.push(label); }; + const expect = (label, cond) => { registerCase(); if (!cond) failures.push(label); }; const one = async (src) => { const { found, results } = await judgeFixture(src); return { found, r: results[0], n: found.length }; @@ -1242,6 +1289,50 @@ async function selfTest() { + 'is under the same root and is NOT in the walk', Boolean(nonTestSibling) && !admitted.has(nonTestSibling)); + // ── The floor: every declared battery RAN, and ran its cases (#13489) ──── + // + // Evaluated after every battery has had its chance and BEFORE the verdict, so + // the success line below can only be printed by a run in which the set of + // batteries that registered assertions EQUALS the set declared. A set + // difference names WHICH battery stopped; a count says only that something did. + const floorFailure = (message) => { failures.push(message); }; + const declaredBatteries = Object.keys(SELF_TEST_BATTERIES); + let floorBreached = false; + if (declaredBatteries.length < SELF_TEST_BATTERY_FLOOR) { + floorBreached = true; + floorFailure( + `SELF_TEST_BATTERIES declares ${declaredBatteries.length} batteries, below the pinned ` + + `${SELF_TEST_BATTERY_FLOOR} — a battery deleted from the roster takes its own floor with it.`, + ); + } + for (const [name, count] of batterySeen) { + if (declaredBatteries.includes(name)) continue; + floorBreached = true; + floorFailure( + `self-test battery "${name}" registered ${count} case(s) but is not declared in ` + + 'SELF_TEST_BATTERIES — an assertion attributed to no declared battery is one nothing floors.', + ); + } + for (const name of declaredBatteries) { + const count = batterySeen.get(name) ?? 0; + if (count >= SELF_TEST_BATTERIES[name]) continue; + floorBreached = true; + floorFailure( + count === 0 + ? `self-test battery "${name}" DID NOT RUN — 0 cases registered, ${SELF_TEST_BATTERIES[name]} pinned. ` + + 'The verdict below would have claimed those cases hold.' + : `self-test battery "${name}" registered ${count} case(s), below its pinned floor of ` + + `${SELF_TEST_BATTERIES[name]} — cases that used to run no longer do.`, + ); + } + if (floorBreached) { + floorFailure( + 'A battery at or below its floor means cases STOPPED RUNNING — the battery is the bug, not the ' + + 'number. Find what stopped registering (an early return, a deleted block, a guard that now ' + + 'skips) and restore it.', + ); + } + if (failures.length > 0) { console.error(`x check-objectql-double-limit --self-test (${failures.length} failure(s)):\n`); for (const f of failures) console.error(` - ${f}`); From 04134f1dbd2d9e3561fe31949f3e3af8177cfe03 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 4 Sep 2026 06:23:24 +0000 Subject: [PATCH 3/5] tooling(scripts): floor the spec-parsed-alias and stack-collection-maps self-tests (#13799) check-spec-parsed-alias decided success by `failures.length === 0` alone. check-stack-collection-maps already COUNTED its assertions and printed the number -- but nothing compared it, so a case block that stopped running shrank the printed count and the gate stayed green: evidence, not proof. Neither carries the two named section banners the sectioning criterion needs, and a comment is not promoted to a section head, so each declares ONE battery opened at the top of its self-test body. Both floors measured at 18. The two hand-written verdict counts agree with the registered count on this tree (`18 assertions passed`, `18 assertions over synthetic sources`), so neither had drifted. `--self-test` stdout and stderr are byte-identical against origin/main for both, exit 0 on both sides. Claude-Session: https://claude.ai/code/session_012zGPuVVX3deAx9LdjK8jCk Co-authored-by: Claude --- scripts/check-spec-parsed-alias.mjs | 93 ++++++++++++++++++++++++ scripts/check-stack-collection-maps.mjs | 94 +++++++++++++++++++++++++ 2 files changed, 187 insertions(+) diff --git a/scripts/check-spec-parsed-alias.mjs b/scripts/check-spec-parsed-alias.mjs index a0722447f7..353f8d4fe7 100644 --- a/scripts/check-spec-parsed-alias.mjs +++ b/scripts/check-spec-parsed-alias.mjs @@ -272,9 +272,58 @@ function loadCorpus() { // as one that passed (#13798). const SELF_TEST_VERDICT = 'check-spec-parsed-alias self-test reached its verdict'; +// ── The self-test's own battery roster and floor (#13489) ────────────────── +// +// `failures.length === 0` used to be this self-test's ONLY success condition, so +// "every case held" and "the cases never ran" printed the same line. Closed the +// way PR #13487 validated on check-doc-authoring: what is pinned is the +// registered NAMES, not a number. The floor requires the OPENED set to equal the +// DECLARED set with each battery at or above its own count. +// +// This file declares ONE battery, opened at the top of the self-test body. Its +// comments label individual cases rather than sections, so it carries fewer than +// the two named section banners the sectioning criterion needs, and ⛔ a comment +// is NOT promoted to a section head — that is a judgement per comment this +// transplant does not make. The hoisted single battery is the shape PR #14896 +// and PR #15003 landed for exactly this case. +// +// ⛔ A pinned TOTAL is not the repair: a battery dropping from 9 cases to 3 +// keeps a total "right" the moment a sibling grows. +// +// The count is a FLOOR, not an equality — adding cases is ordinary work and must +// not red. A battery BELOW its floor means cases stopped running; the remedy is +// to find what stopped registering. +const SELF_TEST_BATTERIES = Object.freeze({ + 'check-spec-parsed-alias self-test': 18, +}); + +// DELETING an entry silences that battery's floor exactly as effectively as +// zeroing it, so the roster's own size is pinned too. +const SELF_TEST_BATTERY_FLOOR = 1; + +// The key an assertion is filed under when no battery is open. It is not a +// declared battery, so it reds by the same set difference rather than silently +// inflating whichever battery happened to run last. +const UNATTRIBUTED_BATTERY = '(no battery open)'; + function selfTest() { + // The battery ledger this self-test's floor is evaluated against (#13489). + // `battery()` opens a battery; every assertion below is attributed to the one + // most recently opened, so a section that stops running stops registering and + // names ITSELF at the floor rather than going quiet. + const batterySeen = new Map(); + let openBattery = null; + const battery = (name) => { + openBattery = name; + }; + const registerCase = () => { + const b = openBattery ?? UNATTRIBUTED_BATTERY; + batterySeen.set(b, (batterySeen.get(b) ?? 0) + 1); + }; + battery('check-spec-parsed-alias self-test'); const failures = []; const check = (label, actual, expected) => { + registerCase(); if (actual !== expected) failures.push(`${label}: expected ${expected}, got ${actual}`); }; const kinds = (vs, kind) => vs.filter((v) => v.kind === kind).length; @@ -460,6 +509,50 @@ export type Iso0 = Assert, z.infer< typeof 1, ); + // ── The floor: every declared battery RAN, and ran its cases (#13489) ──── + // + // Evaluated after every battery has had its chance and BEFORE the verdict, so + // the success line below can only be printed by a run in which the set of + // batteries that registered assertions EQUALS the set declared. A set + // difference names WHICH battery stopped; a count says only that something did. + const floorFailure = (message) => { failures.push(message); }; + const declaredBatteries = Object.keys(SELF_TEST_BATTERIES); + let floorBreached = false; + if (declaredBatteries.length < SELF_TEST_BATTERY_FLOOR) { + floorBreached = true; + floorFailure( + `SELF_TEST_BATTERIES declares ${declaredBatteries.length} batteries, below the pinned ` + + `${SELF_TEST_BATTERY_FLOOR} — a battery deleted from the roster takes its own floor with it.`, + ); + } + for (const [name, count] of batterySeen) { + if (declaredBatteries.includes(name)) continue; + floorBreached = true; + floorFailure( + `self-test battery "${name}" registered ${count} case(s) but is not declared in ` + + 'SELF_TEST_BATTERIES — an assertion attributed to no declared battery is one nothing floors.', + ); + } + for (const name of declaredBatteries) { + const count = batterySeen.get(name) ?? 0; + if (count >= SELF_TEST_BATTERIES[name]) continue; + floorBreached = true; + floorFailure( + count === 0 + ? `self-test battery "${name}" DID NOT RUN — 0 cases registered, ${SELF_TEST_BATTERIES[name]} pinned. ` + + 'The verdict below would have claimed those cases hold.' + : `self-test battery "${name}" registered ${count} case(s), below its pinned floor of ` + + `${SELF_TEST_BATTERIES[name]} — cases that used to run no longer do.`, + ); + } + if (floorBreached) { + floorFailure( + 'A battery at or below its floor means cases STOPPED RUNNING — the battery is the bug, not the ' + + 'number. Find what stopped registering (an early return, a deleted block, a guard that now ' + + 'skips) and restore it.', + ); + } + if (failures.length > 0) { console.error('check-spec-parsed-alias --self-test FAILED:'); for (const f of failures) console.error(' - ' + f); diff --git a/scripts/check-stack-collection-maps.mjs b/scripts/check-stack-collection-maps.mjs index a53ce66b4b..fb7c167fed 100644 --- a/scripts/check-stack-collection-maps.mjs +++ b/scripts/check-stack-collection-maps.mjs @@ -917,7 +917,56 @@ function run({ list = false } = {}) { // handshake is a flag rather than a returned sentinel. let selfTestReachedVerdict = false; +// ── The self-test's own battery roster and floor (#13489) ────────────────── +// +// The `asserted` counter below is COUNTED and PRINTED, but nothing ever +// compared it: if a case block stopped running the printed number shrank with it +// and the gate stayed green. ⚠️ A verdict line that prints a case count is +// evidence, NOT proof. Closed the way PR #13487 validated on +// check-doc-authoring: what is pinned is the registered NAMES, not a number, and +// the floor requires the OPENED set to equal the DECLARED set with each battery +// at or above its own count. +// +// This file declares ONE battery, opened at the top of the self-test body. It +// carries fewer than the two named section banners the sectioning criterion +// needs, and ⛔ a comment is NOT promoted to a section head — that is a +// judgement per comment this transplant does not make. The hoisted single +// battery is the shape PR #14896 and PR #15003 landed for exactly this case. +// +// ⛔ A pinned TOTAL is not the repair: a battery dropping from 9 cases to 3 +// keeps a total "right" the moment a sibling grows. +// +// The count is a FLOOR, not an equality — adding cases is ordinary work and must +// not red. A battery BELOW its floor means cases stopped running; the remedy is +// to find what stopped registering. +const SELF_TEST_BATTERIES = Object.freeze({ + 'check-stack-collection-maps self-test': 18, +}); + +// DELETING an entry silences that battery's floor exactly as effectively as +// zeroing it, so the roster's own size is pinned too. +const SELF_TEST_BATTERY_FLOOR = 1; + +// The key an assertion is filed under when no battery is open. It is not a +// declared battery, so it reds by the same set difference rather than silently +// inflating whichever battery happened to run last. +const UNATTRIBUTED_BATTERY = '(no battery open)'; + function selfTest() { + // The battery ledger this self-test's floor is evaluated against (#13489). + // `battery()` opens a battery; every assertion below is attributed to the one + // most recently opened, so a section that stops running stops registering and + // names ITSELF at the floor rather than going quiet. + const batterySeen = new Map(); + let openBattery = null; + const battery = (name) => { + openBattery = name; + }; + const registerCase = () => { + const b = openBattery ?? UNATTRIBUTED_BATTERY; + batterySeen.set(b, (batterySeen.get(b) ?? 0) + 1); + }; + battery('check-stack-collection-maps self-test'); const failures = []; // COUNTED, not transcribed. The pass line used to carry a hand-written // number, and it had already drifted one below the real count by the time @@ -926,6 +975,7 @@ function selfTest() { // reconciles. let asserted = 0; const eq = (label, actual, expected) => { + registerCase(); asserted += 1; const a = JSON.stringify(actual); const e = JSON.stringify(expected); @@ -1069,6 +1119,50 @@ export const ObjectStackDefinitionSchema = lazySchema(() => strictObject({ ['objects', 'apis'], ); + // ── The floor: every declared battery RAN, and ran its cases (#13489) ──── + // + // Evaluated after every battery has had its chance and BEFORE the verdict, so + // the success line below can only be printed by a run in which the set of + // batteries that registered assertions EQUALS the set declared. A set + // difference names WHICH battery stopped; a count says only that something did. + const floorFailure = (message) => { failures.push(message); }; + const declaredBatteries = Object.keys(SELF_TEST_BATTERIES); + let floorBreached = false; + if (declaredBatteries.length < SELF_TEST_BATTERY_FLOOR) { + floorBreached = true; + floorFailure( + `SELF_TEST_BATTERIES declares ${declaredBatteries.length} batteries, below the pinned ` + + `${SELF_TEST_BATTERY_FLOOR} — a battery deleted from the roster takes its own floor with it.`, + ); + } + for (const [name, count] of batterySeen) { + if (declaredBatteries.includes(name)) continue; + floorBreached = true; + floorFailure( + `self-test battery "${name}" registered ${count} case(s) but is not declared in ` + + 'SELF_TEST_BATTERIES — an assertion attributed to no declared battery is one nothing floors.', + ); + } + for (const name of declaredBatteries) { + const count = batterySeen.get(name) ?? 0; + if (count >= SELF_TEST_BATTERIES[name]) continue; + floorBreached = true; + floorFailure( + count === 0 + ? `self-test battery "${name}" DID NOT RUN — 0 cases registered, ${SELF_TEST_BATTERIES[name]} pinned. ` + + 'The verdict below would have claimed those cases hold.' + : `self-test battery "${name}" registered ${count} case(s), below its pinned floor of ` + + `${SELF_TEST_BATTERIES[name]} — cases that used to run no longer do.`, + ); + } + if (floorBreached) { + floorFailure( + 'A battery at or below its floor means cases STOPPED RUNNING — the battery is the bug, not the ' + + 'number. Find what stopped registering (an early return, a deleted block, a guard that now ' + + 'skips) and restore it.', + ); + } + if (failures.length) { console.error(`✗ check-stack-collection-maps --self-test — ${failures.length} failure(s)\n`); for (const f of failures) console.error(` • ${f}\n`); From e3cd43f113a00c81e2882303691b9d3293c62983 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 4 Sep 2026 06:24:57 +0000 Subject: [PATCH 4/5] tooling(scripts): floor the tenant-chokepoint and label-desc-cap self-tests (#13799) Both decided success by their sink alone (`failures.length === 0`, `failed === 0`), so "every case held" and "the cases never ran" printed the same line. tenant-chokepoint's blocks are headed by unmarked prose and label-desc-cap carries one banner, below the two the sectioning criterion needs; a comment is not promoted to a section head and a lone banner is not split, so each declares ONE battery opened at the top of its self-test body. label-desc-cap's sink is a counter rather than a list, so its floor prints the breach and folds it into `failed` -- the same refusal in that file's own idiom. Floors 17 and 44, measured by probing the roster with an unreachable pin. `--self-test` stdout and stderr are byte-identical against origin/main for both, exit 0 on both sides. Claude-Session: https://claude.ai/code/session_012zGPuVVX3deAx9LdjK8jCk Co-authored-by: Claude --- scripts/check-tenant-chokepoint.mjs | 94 ++++++++++++++++++++++++++- scripts/pm/check-label-desc-cap.mjs | 98 +++++++++++++++++++++++++++++ 2 files changed, 191 insertions(+), 1 deletion(-) diff --git a/scripts/check-tenant-chokepoint.mjs b/scripts/check-tenant-chokepoint.mjs index 91f00151d7..f74cedbfe7 100644 --- a/scripts/check-tenant-chokepoint.mjs +++ b/scripts/check-tenant-chokepoint.mjs @@ -324,9 +324,57 @@ const wrap = (body) => `class SqlDriver {\n${body}\n}`; // as one that passed (#13798). const SELF_TEST_VERDICT = 'check-tenant-chokepoint self-test reached its verdict'; +// ── The self-test's own battery roster and floor (#13489) ────────────────── +// +// `failures.length === 0` used to be this self-test's ONLY success condition, so +// "every case held" and "the cases never ran" printed the same line. Closed the +// way PR #13487 validated on check-doc-authoring: what is pinned is the +// registered NAMES, not a number. The floor requires the OPENED set to equal the +// DECLARED set with each battery at or above its own count. +// +// This file declares ONE battery, opened at the top of the self-test body. Its +// blocks are headed by unmarked prose comments, so it carries fewer than the two +// named section banners the sectioning criterion needs, and ⛔ a comment is NOT +// promoted to a section head — that is a judgement per comment this transplant +// does not make. The hoisted single battery is the shape PR #14896 and PR #15003 +// landed for exactly this case. +// +// ⛔ A pinned TOTAL is not the repair: a battery dropping from 9 cases to 3 +// keeps a total "right" the moment a sibling grows. +// +// The count is a FLOOR, not an equality — adding cases is ordinary work and must +// not red. A battery BELOW its floor means cases stopped running; the remedy is +// to find what stopped registering. +const SELF_TEST_BATTERIES = Object.freeze({ + 'check-tenant-chokepoint self-test': 17, +}); + +// DELETING an entry silences that battery's floor exactly as effectively as +// zeroing it, so the roster's own size is pinned too. +const SELF_TEST_BATTERY_FLOOR = 1; + +// The key an assertion is filed under when no battery is open. It is not a +// declared battery, so it reds by the same set difference rather than silently +// inflating whichever battery happened to run last. +const UNATTRIBUTED_BATTERY = '(no battery open)'; + function selfTest() { + // The battery ledger this self-test's floor is evaluated against (#13489). + // `battery()` opens a battery; every assertion below is attributed to the one + // most recently opened, so a section that stops running stops registering and + // names ITSELF at the floor rather than going quiet. + const batterySeen = new Map(); + let openBattery = null; + const battery = (name) => { + openBattery = name; + }; + const registerCase = () => { + const b = openBattery ?? UNATTRIBUTED_BATTERY; + batterySeen.set(b, (batterySeen.get(b) ?? 0) + 1); + }; + battery('check-tenant-chokepoint self-test'); const failures = []; - const assert = (cond, msg) => { if (!cond) failures.push(msg); }; + const assert = (cond, msg) => { registerCase(); if (!cond) failures.push(msg); }; const run = (src) => { const a = analyzeSource('t.ts', wrap(src)); return { ...a, problems: violationsOf('t.ts', a) }; @@ -474,6 +522,50 @@ function selfTest() { assert(builders.length === 0, 'the empty fixture must discover no builders'); } + // ── The floor: every declared battery RAN, and ran its cases (#13489) ──── + // + // Evaluated after every battery has had its chance and BEFORE the verdict, so + // the success line below can only be printed by a run in which the set of + // batteries that registered assertions EQUALS the set declared. A set + // difference names WHICH battery stopped; a count says only that something did. + const floorFailure = (message) => { failures.push(message); }; + const declaredBatteries = Object.keys(SELF_TEST_BATTERIES); + let floorBreached = false; + if (declaredBatteries.length < SELF_TEST_BATTERY_FLOOR) { + floorBreached = true; + floorFailure( + `SELF_TEST_BATTERIES declares ${declaredBatteries.length} batteries, below the pinned ` + + `${SELF_TEST_BATTERY_FLOOR} — a battery deleted from the roster takes its own floor with it.`, + ); + } + for (const [name, count] of batterySeen) { + if (declaredBatteries.includes(name)) continue; + floorBreached = true; + floorFailure( + `self-test battery "${name}" registered ${count} case(s) but is not declared in ` + + 'SELF_TEST_BATTERIES — an assertion attributed to no declared battery is one nothing floors.', + ); + } + for (const name of declaredBatteries) { + const count = batterySeen.get(name) ?? 0; + if (count >= SELF_TEST_BATTERIES[name]) continue; + floorBreached = true; + floorFailure( + count === 0 + ? `self-test battery "${name}" DID NOT RUN — 0 cases registered, ${SELF_TEST_BATTERIES[name]} pinned. ` + + 'The verdict below would have claimed those cases hold.' + : `self-test battery "${name}" registered ${count} case(s), below its pinned floor of ` + + `${SELF_TEST_BATTERIES[name]} — cases that used to run no longer do.`, + ); + } + if (floorBreached) { + floorFailure( + 'A battery at or below its floor means cases STOPPED RUNNING — the battery is the bug, not the ' + + 'number. Find what stopped registering (an early return, a deleted block, a guard that now ' + + 'skips) and restore it.', + ); + } + if (failures.length > 0) { console.error(`✗ check:tenant-chokepoint self-test (${failures.length} failure(s)):\n`); for (const f of failures) console.error(` • ${f}`); diff --git a/scripts/pm/check-label-desc-cap.mjs b/scripts/pm/check-label-desc-cap.mjs index f603980a5d..53666e0856 100644 --- a/scripts/pm/check-label-desc-cap.mjs +++ b/scripts/pm/check-label-desc-cap.mjs @@ -318,9 +318,58 @@ function run() { // as one that passed (#13798). const SELF_TEST_VERDICT = 'check-label-desc-cap self-test reached its verdict'; +// ── The self-test's own battery roster and floor (#13489) ────────────────── +// +// `failed === 0` used to be this self-test's ONLY success condition, so "every +// case held" and "the cases never ran" printed the same line. Closed the way +// PR #13487 validated on check-doc-authoring: what is pinned is the registered +// NAMES, not a number. The floor requires the OPENED set to equal the DECLARED +// set with each battery at or above its own count. +// +// This file declares ONE battery, opened at the top of the self-test body. It +// carries one named section banner, below the two the sectioning criterion +// needs, and ⛔ a comment is NOT promoted to a section head — that is a +// judgement per comment this transplant does not make. ⛔ Nor is a lone banner +// split into two batteries. The hoisted single battery is the shape PR #14896 +// and PR #15003 landed for exactly this case. +// +// ⛔ A pinned TOTAL is not the repair: a battery dropping from 9 cases to 3 +// keeps a total "right" the moment a sibling grows. +// +// The count is a FLOOR, not an equality — adding cases is ordinary work and must +// not red. A battery BELOW its floor means cases stopped running; the remedy is +// to find what stopped registering. +const SELF_TEST_BATTERIES = Object.freeze({ + 'check-label-desc-cap self-test': 44, +}); + +// DELETING an entry silences that battery's floor exactly as effectively as +// zeroing it, so the roster's own size is pinned too. +const SELF_TEST_BATTERY_FLOOR = 1; + +// The key an assertion is filed under when no battery is open. It is not a +// declared battery, so it reds by the same set difference rather than silently +// inflating whichever battery happened to run last. +const UNATTRIBUTED_BATTERY = '(no battery open)'; + function selfTest() { + // The battery ledger this self-test's floor is evaluated against (#13489). + // `battery()` opens a battery; every assertion below is attributed to the one + // most recently opened, so a section that stops running stops registering and + // names ITSELF at the floor rather than going quiet. + const batterySeen = new Map(); + let openBattery = null; + const battery = (name) => { + openBattery = name; + }; + const registerCase = () => { + const b = openBattery ?? UNATTRIBUTED_BATTERY; + batterySeen.set(b, (batterySeen.get(b) ?? 0) + 1); + }; + battery('check-label-desc-cap self-test'); let failed = 0; const t = (name, actual, expected) => { + registerCase(); const ok = JSON.stringify(actual) === JSON.stringify(expected); if (!ok) { failed++; @@ -477,6 +526,55 @@ function selfTest() { t('a failing gh label edit makes the script exit non-zero', brokenEdit.status !== 0, true); t('…while the same failure in the default mode cannot arise (no edits)', verbs(dryRunCalls(script, [], { failEdit: true }).calls, 'edit').length, 0); + // ── The floor: every declared battery RAN, and ran its cases (#13489) ──── + // + // Evaluated after every battery has had its chance and BEFORE the verdict, so + // the success line below can only be printed by a run in which the set of + // batteries that registered assertions EQUALS the set declared. A set + // difference names WHICH battery stopped; a count says only that something did. + // This file's sink is a counter rather than a list, so a breach is printed + // here and folded into `failed` — the same refusal, in this file's own idiom. + const floorFailures = []; + const floorFailure = (message) => { floorFailures.push(message); }; + const declaredBatteries = Object.keys(SELF_TEST_BATTERIES); + let floorBreached = false; + if (declaredBatteries.length < SELF_TEST_BATTERY_FLOOR) { + floorBreached = true; + floorFailure( + `SELF_TEST_BATTERIES declares ${declaredBatteries.length} batteries, below the pinned ` + + `${SELF_TEST_BATTERY_FLOOR} — a battery deleted from the roster takes its own floor with it.`, + ); + } + for (const [name, count] of batterySeen) { + if (declaredBatteries.includes(name)) continue; + floorBreached = true; + floorFailure( + `self-test battery "${name}" registered ${count} case(s) but is not declared in ` + + 'SELF_TEST_BATTERIES — an assertion attributed to no declared battery is one nothing floors.', + ); + } + for (const name of declaredBatteries) { + const count = batterySeen.get(name) ?? 0; + if (count >= SELF_TEST_BATTERIES[name]) continue; + floorBreached = true; + floorFailure( + count === 0 + ? `self-test battery "${name}" DID NOT RUN — 0 cases registered, ${SELF_TEST_BATTERIES[name]} pinned. ` + + 'The verdict below would have claimed those cases hold.' + : `self-test battery "${name}" registered ${count} case(s), below its pinned floor of ` + + `${SELF_TEST_BATTERIES[name]} — cases that used to run no longer do.`, + ); + } + if (floorBreached) { + floorFailure( + 'A battery at or below its floor means cases STOPPED RUNNING — the battery is the bug, not the ' + + 'number. Find what stopped registering (an early return, a deleted block, a guard that now ' + + 'skips) and restore it.', + ); + } + for (const message of floorFailures) console.error(` ✗ ${message}`); + failed += floorFailures.length; + if (failed) { console.error(`\n❌ check-label-desc-cap --self-test: ${failed} case(s) failed`); process.exit(1); From 4d7538c4c23659e8c38fd33d736461774c6b7e1e Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 4 Sep 2026 06:27:00 +0000 Subject: [PATCH 5/5] tooling(scripts): floor the whole-set-label-write and wildcard-fallthrough self-tests (#13799) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Neither carries the two named section banners the sectioning criterion needs, so each declares ONE battery opened at the top of its self-test body. Floors 41 and 18, measured by probing the roster with an unreachable pin. whole-set-label-write registers from `expect()` only. Its two trailing ledger loops walk WHOLE_SET_ACTIONS and ALLOWLIST and push straight to `failures`; they are left unregistered ON PURPOSE, because ALLOWLIST is meant to shrink and a floor that moved with it would red every legitimate removal -- the one habit these floors exist to prevent. The comment above the roster says so in place. wildcard-fallthrough refuses in place rather than collecting, so its floor refuses in place too. ⚠️ Its verdict prints a TRANSCRIBED `17 cases` while the body has 18 assert call sites and registers 18 -- the literal had already drifted one low. It is left untouched so this change stays a pure no-op on output, and filed separately; the floor is what makes the drift harmless. `--self-test` stdout and stderr are byte-identical against origin/main for both, exit 0 on both sides. Claude-Session: https://claude.ai/code/session_012zGPuVVX3deAx9LdjK8jCk Co-authored-by: Claude --- scripts/check-whole-set-label-write.mjs | 104 +++++++++++++++++++++++ scripts/check-wildcard-fallthrough.mjs | 108 +++++++++++++++++++++++- 2 files changed, 211 insertions(+), 1 deletion(-) diff --git a/scripts/check-whole-set-label-write.mjs b/scripts/check-whole-set-label-write.mjs index 1d7f402004..bea00fe5fd 100644 --- a/scripts/check-whole-set-label-write.mjs +++ b/scripts/check-whole-set-label-write.mjs @@ -879,11 +879,71 @@ function withTree(files, fn) { // handshake is a flag rather than a returned sentinel. let selfTestReachedVerdict = false; +// ── The self-test's own battery roster and floor (#13489) ────────────────── +// +// `failures.length === 0` used to be this self-test's ONLY success condition, so +// "every case held" and "the cases never ran" printed the same line. Closed the +// way PR #13487 validated on check-doc-authoring: what is pinned is the +// registered NAMES, not a number. The floor requires the OPENED set to equal the +// DECLARED set with each battery at or above its own count. +// +// This file declares ONE battery, opened at the top of the self-test body. It +// carries fewer than the two named section banners the sectioning criterion +// needs, and ⛔ a comment is NOT promoted to a section head — that is a +// judgement per comment this transplant does not make. The hoisted single +// battery is the shape PR #14896 and PR #15003 landed for exactly this case. +// +// ⚠️ What the floor deliberately does NOT count: the two ledger loops at the end +// of the body walk `WHOLE_SET_ACTIONS` and `ALLOWLIST` and push straight to +// `failures`, one iteration per row. Those are not routed through `expect()` and +// are left unregistered ON PURPOSE — `ALLOWLIST` is an allowlist, so it is meant +// to SHRINK, and a floor that moves with it would red every legitimate removal +// and train the next author to edit the floor, which is the one habit these +// floors exist to prevent (#13797's ruling, carried forward). The floor pins the +// part that does not move with a list: the fixture-tree and refusal cases that +// go through the helper. +// +// ⛔ A pinned TOTAL is not the repair: a battery dropping from 9 cases to 3 +// keeps a total "right" the moment a sibling grows. +// +// The count is a FLOOR, not an equality — adding cases is ordinary work and must +// not red. A battery BELOW its floor means cases stopped running; the remedy is +// to find what stopped registering. +const SELF_TEST_BATTERIES = Object.freeze({ + 'check-whole-set-label-write self-test': 41, +}); + +// DELETING an entry silences that battery's floor exactly as effectively as +// zeroing it, so the roster's own size is pinned too. +const SELF_TEST_BATTERY_FLOOR = 1; + +// The key an assertion is filed under when no battery is open. It is not a +// declared battery, so it reds by the same set difference rather than silently +// inflating whichever battery happened to run last. +const UNATTRIBUTED_BATTERY = '(no battery open)'; + export function selfTest() { + // The battery ledger this self-test's floor is evaluated against (#13489). + // `battery()` opens a battery; every assertion below is attributed to the one + // most recently opened, so a section that stops running stops registering and + // names ITSELF at the floor rather than going quiet. + const batterySeen = new Map(); + let openBattery = null; + const battery = (name) => { + openBattery = name; + }; + const registerCase = () => { + const b = openBattery ?? UNATTRIBUTED_BATTERY; + batterySeen.set(b, (batterySeen.get(b) ?? 0) + 1); + }; + battery('check-whole-set-label-write self-test'); const failures = []; const silent = () => {}; const expect = (label, actual, wanted) => { + // Registered BEFORE the early return, so a passing case counts too — a + // ledger that only saw failures would read empty on a healthy run. + registerCase(); if (actual === wanted) return; failures.push(`${label}: expected ${wanted}, got ${actual}`); }; @@ -1028,6 +1088,50 @@ export function selfTest() { failures.push(`ALLOWLIST[${index}] (${entry.path}) states no reason`); } + // ── The floor: every declared battery RAN, and ran its cases (#13489) ──── + // + // Evaluated after every battery has had its chance and BEFORE the verdict, so + // the success line below can only be printed by a run in which the set of + // batteries that registered assertions EQUALS the set declared. A set + // difference names WHICH battery stopped; a count says only that something did. + const floorFailure = (message) => { failures.push(message); }; + const declaredBatteries = Object.keys(SELF_TEST_BATTERIES); + let floorBreached = false; + if (declaredBatteries.length < SELF_TEST_BATTERY_FLOOR) { + floorBreached = true; + floorFailure( + `SELF_TEST_BATTERIES declares ${declaredBatteries.length} batteries, below the pinned ` + + `${SELF_TEST_BATTERY_FLOOR} — a battery deleted from the roster takes its own floor with it.`, + ); + } + for (const [name, count] of batterySeen) { + if (declaredBatteries.includes(name)) continue; + floorBreached = true; + floorFailure( + `self-test battery "${name}" registered ${count} case(s) but is not declared in ` + + 'SELF_TEST_BATTERIES — an assertion attributed to no declared battery is one nothing floors.', + ); + } + for (const name of declaredBatteries) { + const count = batterySeen.get(name) ?? 0; + if (count >= SELF_TEST_BATTERIES[name]) continue; + floorBreached = true; + floorFailure( + count === 0 + ? `self-test battery "${name}" DID NOT RUN — 0 cases registered, ${SELF_TEST_BATTERIES[name]} pinned. ` + + 'The verdict below would have claimed those cases hold.' + : `self-test battery "${name}" registered ${count} case(s), below its pinned floor of ` + + `${SELF_TEST_BATTERIES[name]} — cases that used to run no longer do.`, + ); + } + if (floorBreached) { + floorFailure( + 'A battery at or below its floor means cases STOPPED RUNNING — the battery is the bug, not the ' + + 'number. Find what stopped registering (an early return, a deleted block, a guard that now ' + + 'skips) and restore it.', + ); + } + if (failures.length > 0) { console.error(`\n✗ check-whole-set-label-write --self-test -- ${failures.length} failure(s)\n`); for (const failure of failures) console.error(` ${failure}`); diff --git a/scripts/check-wildcard-fallthrough.mjs b/scripts/check-wildcard-fallthrough.mjs index 3757b905cd..59ca1b6909 100644 --- a/scripts/check-wildcard-fallthrough.mjs +++ b/scripts/check-wildcard-fallthrough.mjs @@ -454,8 +454,59 @@ function audit() { // as one that passed (#13798). const SELF_TEST_VERDICT = 'check-wildcard-fallthrough self-test reached its verdict'; +// ── The self-test's own battery roster and floor (#13489) ────────────────── +// +// "no assertion threw" used to be this self-test's ONLY success condition, so +// "every case held" and "the cases never ran" printed the same line — and this +// file's verdict spells a TRANSCRIBED count (`17 cases`), which is evidence, not +// proof: nothing compared it, so a deleted block shrank the real count while the +// literal stayed put. Closed the way PR #13487 validated on check-doc-authoring: +// what is pinned is the registered NAMES, not a number, and the floor requires +// the OPENED set to equal the DECLARED set with each battery at or above its own +// count. +// +// This file declares ONE battery, opened at the top of the self-test body. Its +// blocks are headed by unmarked prose comments, so it carries fewer than the two +// named section banners the sectioning criterion needs, and ⛔ a comment is NOT +// promoted to a section head — that is a judgement per comment this transplant +// does not make. The hoisted single battery is the shape PR #14896 and PR #15003 +// landed for exactly this case. +// +// ⛔ A pinned TOTAL is not the repair: a battery dropping from 9 cases to 3 +// keeps a total "right" the moment a sibling grows. +// +// The count is a FLOOR, not an equality — adding cases is ordinary work and must +// not red. A battery BELOW its floor means cases stopped running; the remedy is +// to find what stopped registering. +const SELF_TEST_BATTERIES = Object.freeze({ + 'check-wildcard-fallthrough self-test': 18, +}); + +// DELETING an entry silences that battery's floor exactly as effectively as +// zeroing it, so the roster's own size is pinned too. +const SELF_TEST_BATTERY_FLOOR = 1; + +// The key an assertion is filed under when no battery is open. It is not a +// declared battery, so it reds by the same set difference rather than silently +// inflating whichever battery happened to run last. +const UNATTRIBUTED_BATTERY = '(no battery open)'; + function selfTest() { - const assert = (cond, msg) => { if (!cond) { console.error('✗ self-test: ' + msg); process.exit(1); } }; + // The battery ledger this self-test's floor is evaluated against (#13489). + // `battery()` opens a battery; every assertion below is attributed to the one + // most recently opened, so a section that stops running stops registering and + // names ITSELF at the floor rather than going quiet. + const batterySeen = new Map(); + let openBattery = null; + const battery = (name) => { + openBattery = name; + }; + const registerCase = () => { + const b = openBattery ?? UNATTRIBUTED_BATTERY; + batterySeen.set(b, (batterySeen.get(b) ?? 0) + 1); + }; + battery('check-wildcard-fallthrough self-test'); + const assert = (cond, msg) => { registerCase(); if (!cond) { console.error('✗ self-test: ' + msg); process.exit(1); } }; const parse = (code) => parseSourceFile('t.ts', code); // `isWildcard` — namespace claims vs single paths. @@ -523,6 +574,61 @@ function selfTest() { 'method is part of the key', ); + // ── The floor: every declared battery RAN, and ran its cases (#13489) ──── + // + // Evaluated after every battery has had its chance and BEFORE the verdict, so + // the success line below can only be printed by a run in which the set of + // batteries that registered assertions EQUALS the set declared. A set + // difference names WHICH battery stopped; a count says only that something did. + // This file's assertions refuse in place rather than collecting, so the floor + // refuses in place too — same idiom, same exit code. + const floorFailures = []; + const floorFailure = (message) => { floorFailures.push(message); }; + const declaredBatteries = Object.keys(SELF_TEST_BATTERIES); + let floorBreached = false; + if (declaredBatteries.length < SELF_TEST_BATTERY_FLOOR) { + floorBreached = true; + floorFailure( + `SELF_TEST_BATTERIES declares ${declaredBatteries.length} batteries, below the pinned ` + + `${SELF_TEST_BATTERY_FLOOR} — a battery deleted from the roster takes its own floor with it.`, + ); + } + for (const [name, count] of batterySeen) { + if (declaredBatteries.includes(name)) continue; + floorBreached = true; + floorFailure( + `self-test battery "${name}" registered ${count} case(s) but is not declared in ` + + 'SELF_TEST_BATTERIES — an assertion attributed to no declared battery is one nothing floors.', + ); + } + for (const name of declaredBatteries) { + const count = batterySeen.get(name) ?? 0; + if (count >= SELF_TEST_BATTERIES[name]) continue; + floorBreached = true; + floorFailure( + count === 0 + ? `self-test battery "${name}" DID NOT RUN — 0 cases registered, ${SELF_TEST_BATTERIES[name]} pinned. ` + + 'The verdict below would have claimed those cases hold.' + : `self-test battery "${name}" registered ${count} case(s), below its pinned floor of ` + + `${SELF_TEST_BATTERIES[name]} — cases that used to run no longer do.`, + ); + } + if (floorBreached) { + floorFailure( + 'A battery at or below its floor means cases STOPPED RUNNING — the battery is the bug, not the ' + + 'number. Find what stopped registering (an early return, a deleted block, a guard that now ' + + 'skips) and restore it.', + ); + for (const message of floorFailures) console.error('✗ self-test: ' + message); + process.exit(1); + } + + // ⚠️ MEASURED at 18, not 17: this transcribed literal had already drifted one + // below the real count before this floor existed, which is precisely why a + // printed number is evidence and not proof. It is left as-is here so this + // change stays a pure no-op on output; the correction is filed separately, and + // the floor above is what makes the drift harmless — the count can no longer + // shrink in silence. console.log('✓ self-test: 17 cases'); return SELF_TEST_VERDICT;