Skip to content

Commit 2cc4610

Browse files
claude[bot]claude
andauthored
fix(scripts): make the last two self-tests prove they reached their verdict (#15123)
`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 Claude-Session: https://claude.ai/code/session_012zGPuVVX3deAx9LdjK8jCk Co-authored-by: Claude <noreply@anthropic.com>
1 parent f074616 commit 2cc4610

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
@@ -1396,6 +1396,12 @@ function report({ wide = false } = {}) {
13961396
}
13971397
}
13981398

1399+
// Returned by `selfTest()` only after its verdict is printed. The dispatch
1400+
// refuses anything else: a `return` that leaves the function above that line
1401+
// prints nothing and still exits 0 — a self-test that never finished, reported
1402+
// as one that passed (#13798).
1403+
const SELF_TEST_VERDICT = 'bare-root-worklist self-test reached its verdict';
1404+
13991405
function selfTest() {
14001406
const failures = [];
14011407
const t = (label, ok) => { if (!ok) failures.push(label); };
@@ -1698,9 +1704,19 @@ function selfTest() {
16981704
+ '(#14695) are well-formed, disjoint from TRIAGE, contribute no hint of their own, and share '
16991705
+ 'one base commit.',
17001706
);
1707+
1708+
return SELF_TEST_VERDICT;
17011709
}
17021710

17031711
if (isEntrypoint(import.meta.url)) {
1704-
if (process.argv.includes('--self-test')) selfTest();
1705-
else report({ wide: process.argv.includes('--wide') });
1712+
if (process.argv.includes('--self-test')) {
1713+
if (selfTest() !== SELF_TEST_VERDICT) {
1714+
console.error(
1715+
'\n✗ bare-root-worklist self-test: selfTest() returned without reaching its verdict,\n'
1716+
+ 'so no success line was printed. Exiting 0 here would report a self-test\n'
1717+
+ 'that never finished as a self-test that passed.\n',
1718+
);
1719+
process.exit(1);
1720+
}
1721+
} else report({ wide: process.argv.includes('--wide') });
17061722
}

0 commit comments

Comments
 (0)