Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
130 changes: 119 additions & 11 deletions scripts/check-console-intercept-disarm.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,64 @@ export default defineConfig({ test: { disableConsoleIntercept: true } });
// as one that passed (#13798).
const SELF_TEST_VERDICT = 'check-console-intercept-disarm self-test reached its verdict';

// ── The self-test's own battery roster and floor (#13489) ──────────────────
//
// `failures` 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, PR #15003
// and PR #15217 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-console-intercept-disarm self-test': 11,
});

// 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-console-intercept-disarm self-test');
// The thunk PR #15198 measured: it registers the case and then runs the
// existing site VERBATIM, so no assertion condition is inverted or rewritten
// and the sink keeps its own semantics. Registration happens whether or not
// the site fires, which is what makes the count a floor on cases RUN rather
// than a count of failures.
const check = (fn) => {
registerCase();
fn();
};
const cases = [
{
name: 'disarmed package passes',
Expand Down Expand Up @@ -499,24 +556,75 @@ function selfTest() {
) {
problems.push(`expected ${testCase.expectVitestPackages} vitest package(s), got ${vitestPackages}`);
}
if (problems.length > 0) {
failures += 1;
console.error(`self-test FAIL: ${testCase.name}\n ${problems.join('\n ')}`);
for (const f of findings) console.error(` finding: ${f.split('\n')[0]}`);
}
check(() => {
if (problems.length > 0) {
failures += 1;
console.error(`self-test FAIL: ${testCase.name}\n ${problems.join('\n ')}`);
for (const f of findings) console.error(` finding: ${f.split('\n')[0]}`);
}
});
} finally {
rmSync(caseDir, { recursive: true, force: true });
}
}

// Anti-vacuity over the REAL tree: the scan must see the real population.
const real = scan(REPO_ROOT);
if (real.vitestPackages < 60) {
failures += 1;
console.error(
`self-test FAIL: real-tree scan sees only ${real.vitestPackages} vitest-running ` +
`package(s); the population this gate was written against had 72. The ` +
`workspace expansion has gone blind, which would pass every future arrival.`,
check(() => {
if (real.vitestPackages < 60) {
failures += 1;
console.error(
`self-test FAIL: real-tree scan sees only ${real.vitestPackages} vitest-running ` +
`package(s); the population this gate was written against had 72. The ` +
`workspace expansion has gone blind, which would pass every future arrival.`,
);
}
});

// ── 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 the `failures` counter, so the floor speaks its idiom: a
// breach prints like any other case failure and reds through the existing
// verdict below.
const floorFailure = (message) => { console.error(message); failures += 1; };
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.',
);
}

Expand Down
103 changes: 102 additions & 1 deletion scripts/check-declaration-mirrors.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -406,9 +406,63 @@ async function main() {
// as one that passed (#13798).
const SELF_TEST_VERDICT = 'check-declaration-mirrors self-test reached its verdict';

// ── The self-test's own battery roster and floor (#13489) ──────────────────
//
// `cases.filter((c) => !c.cond)` 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, PR #15003
// and PR #15217 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-declaration-mirrors self-test': 23,
});

// 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-declaration-mirrors self-test');
const cases = [];
const ok = (label, cond) => cases.push({ label, cond });
// The concise arrow gains a BLOCK body so the case can be registered before
// it is recorded; `cases.push` is unchanged, so no assertion is rewritten.
const ok = (label, cond) => {
registerCase();
cases.push({ label, cond });
};
const dir = mkdtempSync(join(tmpdir(), 'os-decl-mirror-'));
let seq = 0;

Expand Down Expand Up @@ -549,6 +603,53 @@ async function selfTest() {
mirrorFiles().every((f) => f.endsWith('.d.mts')),
);

// ── 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 the `cases` ledger, so the floor speaks its idiom: a
// breach is recorded as a failing case and reds through the existing verdict
// below. It bypasses `ok()` deliberately — a floor message is not a case.
const floorFailure = (message) => { cases.push({ label: message, cond: false }); };
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.',
);
}

const failed = cases.filter((c) => !c.cond);
for (const c of cases) console.log(`${c.cond ? 'ok ' : 'FAIL'} ${c.label}`);
if (failed.length) {
Expand Down
104 changes: 103 additions & 1 deletion scripts/check-docs-single-h1.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -378,9 +378,64 @@ function main(argv) {
// handshake is a flag rather than a returned sentinel.
let selfTestReachedVerdict = false;

// ── The self-test's own battery roster and floor (#13489) ──────────────────
//
// `cases.filter((c) => !c.ok)` 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 exactly ONE named section banner (`The carve-out machinery, driven by
// a SYNTHETIC exclusion`), which is fewer than the two the sectioning criterion
// needs, and ⛔ a single banner is NOT split on — sectioning on it would leave
// every case above it in an unnamed remainder battery this transplant would
// have to invent a name for. The hoisted single battery is the shape PR #14896,
// PR #15003 and PR #15217 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-docs-single-h1 self-test': 20,
});

// 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-docs-single-h1 self-test');
const cases = [];
const t = (name, ok, detail) => cases.push({ name, ok: Boolean(ok), detail });
// The concise arrow gains a BLOCK body so the case can be registered before
// it is recorded; `cases.push` is unchanged, so no assertion is rewritten.
const t = (name, ok, detail) => {
registerCase();
cases.push({ name, ok: Boolean(ok), detail });
};

const dir = mkdtempSync(join(tmpdir(), 'docs-single-h1-'));
try {
Expand Down Expand Up @@ -493,6 +548,53 @@ export function selfTest() {
rmSync(dir, { recursive: true, force: true });
}

// ── 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 the `cases` ledger, so the floor speaks its idiom: a
// breach is recorded as a failing case and reds through the existing verdict
// below. It bypasses `t()` deliberately — a floor message is not a case.
const floorFailure = (message) => { cases.push({ name: message, ok: false }); };
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.',
);
}

const failed = cases.filter((c) => !c.ok);
for (const c of failed) console.error(` ✗ ${c.name}${c.detail ? ` — ${c.detail}` : ''}`);
if (failed.length) {
Expand Down
Loading
Loading