Skip to content

Commit efe6a7a

Browse files
committed
fix(scripts): make the last two self-tests prove they reached their verdict
`check-type-check-coverage.mjs` and `bare-root-worklist.mjs` were the last two gates in `scripts/**` that the census reads as DEFEATED: an early `return` anywhere above the verdict line printed NOTHING and still exited 0, so a self-test that never finished reported as one that passed. Both dispatches DISCARD the self-test's return value (`selfTest(); process.exit(0);` and `if (--self-test) selfTest(); else report()`), so the sentinel spelling landed in PRs #14479 / #14853 is the fitting form for each: `SELF_TEST_VERDICT` returned only after the success line, compared at the dispatch, which refuses anything else with exit 1. Nothing inside either self-test body changes. Part of #13798 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012zGPuVVX3deAx9LdjK8jCk
1 parent 97a2263 commit efe6a7a

2 files changed

Lines changed: 34 additions & 3 deletions

File tree

scripts/check-type-check-coverage.mjs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3794,6 +3794,12 @@ function observed() {
37943794
};
37953795
}
37963796

3797+
// Returned by `selfTest()` only after its verdict is printed. The dispatch
3798+
// refuses anything else: a `return` that leaves the function above that line
3799+
// prints nothing and still exits 0 — a self-test that never finished, reported
3800+
// as one that passed (#13798).
3801+
const SELF_TEST_VERDICT = 'check-type-check-coverage self-test reached its verdict';
3802+
37973803
/**
37983804
* The ledger semantics are the one part of this gate that can be wrong while
37993805
* every package is right -- an evaluate() that under-reports waves the next
@@ -5657,10 +5663,19 @@ function selfTest() {
56575663
`${planCases.length + rewriteCases.length + roundTripCases.length} auto-lowering case(s) + ` +
56585664
`${REFUSING.length * 2 + 1 + exitCodeCases.length + textCases.length} exit-code case(s) hold.`,
56595665
);
5666+
5667+
return SELF_TEST_VERDICT;
56605668
}
56615669

56625670
if (process.argv.includes('--self-test')) {
5663-
selfTest();
5671+
if (selfTest() !== SELF_TEST_VERDICT) {
5672+
console.error(
5673+
'\n✗ check:type-check-coverage self-test: selfTest() returned without reaching its verdict,\n'
5674+
+ 'so no success line was printed. Exiting 0 here would report a self-test\n'
5675+
+ 'that never finished as a self-test that passed.\n',
5676+
);
5677+
process.exit(1);
5678+
}
56645679
process.exit(0);
56655680
}
56665681

scripts/pm/bare-root-worklist.mjs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,6 +1352,12 @@ function report({ wide = false } = {}) {
13521352
}
13531353
}
13541354

1355+
// Returned by `selfTest()` only after its verdict is printed. The dispatch
1356+
// refuses anything else: a `return` that leaves the function above that line
1357+
// prints nothing and still exits 0 — a self-test that never finished, reported
1358+
// as one that passed (#13798).
1359+
const SELF_TEST_VERDICT = 'bare-root-worklist self-test reached its verdict';
1360+
13551361
function selfTest() {
13561362
const failures = [];
13571363
const t = (label, ok) => { if (!ok) failures.push(label); };
@@ -1654,9 +1660,19 @@ function selfTest() {
16541660
+ '(#14695) are well-formed, disjoint from TRIAGE, contribute no hint of their own, and share '
16551661
+ 'one base commit.',
16561662
);
1663+
1664+
return SELF_TEST_VERDICT;
16571665
}
16581666

16591667
if (isEntrypoint(import.meta.url)) {
1660-
if (process.argv.includes('--self-test')) selfTest();
1661-
else report({ wide: process.argv.includes('--wide') });
1668+
if (process.argv.includes('--self-test')) {
1669+
if (selfTest() !== SELF_TEST_VERDICT) {
1670+
console.error(
1671+
'\n✗ bare-root-worklist self-test: selfTest() returned without reaching its verdict,\n'
1672+
+ 'so no success line was printed. Exiting 0 here would report a self-test\n'
1673+
+ 'that never finished as a self-test that passed.\n',
1674+
);
1675+
process.exit(1);
1676+
}
1677+
} else report({ wide: process.argv.includes('--wide') });
16621678
}

0 commit comments

Comments
 (0)