Skip to content

Commit 4bafdde

Browse files
claude[bot]claude
andauthored
fix(scripts): burn 25 of the 35 KNOWN_IMPORT_UNSAFE entry-guard debts down (#10704)
* fix(scripts): guard check-skill-id-lint against running on import * fix(scripts): guard check-skill-line-ratchet against running on import * fix(scripts): guard check-label-desc-cap against running on import * fix(scripts): guard ablation-dist-preflight against running on import * fix(scripts): guard check-driver-memory-census against running on import * fix(scripts): guard check-examples-live-imports against running on import * fix(scripts): guard check-nul-bytes against running on import * fix(scripts): guard check-ratchet-remedy-authority against running on import * fix(scripts): guard check-required-contexts against running on import * fix(scripts): guard check-route-envelope against running on import * fix(scripts): guard check-runtime-services-index against running on import * fix(scripts): guard check-shard-attestation against running on import * fix(scripts): guard check-spec-parsed-alias against running on import * fix(scripts): guard check-startup-registry-verdict against running on import * fix(scripts): guard check-workflow-status-functions against running on import * fix(scripts): guard check-error-code-casing against running on import * fix(scripts): guard check-dispatcher-error-vocabulary against running on import * fix(scripts): guard check-engine-split-ratio against running on import * fix(scripts): guard check-filter-alias-parity against running on import * fix(scripts): guard check-org-identifier against running on import * fix(scripts): guard check-quick-reference-counts against running on import * fix(scripts): guard check-test-completeness against running on import * fix(scripts): guard measure-test-shard-timings against running on import * fix(scripts): guard check-tenant-chokepoint against running on import * fix(scripts): guard check-audit-scope against running on import --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent b2a7447 commit 4bafdde

26 files changed

Lines changed: 167 additions & 60 deletions

scripts/ablation-dist-preflight.mjs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ import { join, relative, resolve, extname } from 'node:path';
144144
import { tmpdir } from 'node:os';
145145
import { fileURLToPath } from 'node:url';
146146
import process from 'node:process';
147+
import { isEntrypoint } from './invoked-as.mjs';
147148

148149
const REPO_ROOT = resolve(fileURLToPath(import.meta.url), '..', '..');
149150

@@ -394,5 +395,10 @@ function selfTest() {
394395
}
395396

396397
const argv = process.argv.slice(2);
397-
if (argv.includes('--self-test')) selfTest();
398+
// Exports bindings, so an import for those exports alone must run nothing (#10667).
399+
const invokedDirectly = isEntrypoint(import.meta.url);
400+
401+
if (!invokedDirectly) {
402+
// imported as a module — expose the exports and do nothing else
403+
} else if (argv.includes('--self-test')) selfTest();
398404
else run(argv);

scripts/check-dispatcher-error-vocabulary.mjs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@
152152
import { readFileSync, readdirSync, statSync, existsSync } from 'node:fs';
153153
import { maskComments } from './js-comment-mask.mjs';
154154
import { join, relative, dirname, resolve } from 'node:path';
155+
import { isEntrypoint } from './invoked-as.mjs';
155156

156157
const ROOT = resolve(new URL('..', import.meta.url).pathname);
157158
const SCAN_ROOT = 'packages';
@@ -1826,4 +1827,7 @@ function main() {
18261827
console.log(bounds);
18271828
}
18281829

1829-
main();
1830+
// Exports bindings, so an import for those exports alone must run nothing (#10667).
1831+
if (isEntrypoint(import.meta.url)) {
1832+
main();
1833+
}

scripts/check-driver-memory-census.mjs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ import { fileURLToPath } from 'node:url';
109109
import { execFileSync } from 'node:child_process';
110110
import ts from 'typescript';
111111
import { parseSourceFile } from './ts-parse.mjs';
112+
import { isEntrypoint } from './invoked-as.mjs';
112113

113114
const ROOT = join(dirname(fileURLToPath(import.meta.url)), '..');
114115
const LEDGER_PATH = join(ROOT, 'scripts', 'driver-memory-census.ledger.json');
@@ -683,5 +684,10 @@ function selfTest() {
683684
}
684685

685686
const argv = process.argv.slice(2);
686-
if (argv.includes('--self-test')) selfTest();
687+
// Exports bindings, so an import for those exports alone must run nothing (#10667).
688+
const invokedDirectly = isEntrypoint(import.meta.url);
689+
690+
if (!invokedDirectly) {
691+
// imported as a module — expose the exports and do nothing else
692+
} else if (argv.includes('--self-test')) selfTest();
687693
else report({ list: argv.includes('--list') });

scripts/check-engine-split-ratio.mjs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ import { dirname, join, resolve } from 'node:path';
7474
import { fileURLToPath } from 'node:url';
7575

7676
import { historyHorizon } from './pm/git-history.mjs';
77+
import { isEntrypoint } from './invoked-as.mjs';
7778

7879
const __dirname = dirname(fileURLToPath(import.meta.url));
7980

@@ -334,4 +335,7 @@ function selfTest() {
334335
return failures === 0 ? 0 : 1;
335336
}
336337

337-
process.exit(process.argv.includes('--self-test') ? selfTest() : main(process.argv.slice(2)));
338+
// Exports bindings, so an import for those exports alone must run nothing (#10667).
339+
if (isEntrypoint(import.meta.url)) {
340+
process.exit(process.argv.includes('--self-test') ? selfTest() : main(process.argv.slice(2)));
341+
}

scripts/check-entry-guard.mjs

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -435,39 +435,14 @@ export function importUnsafeStatements(source) {
435435
* names itself, which is what stops this from rotting into an allowlist.
436436
*/
437437
const KNOWN_IMPORT_UNSAFE = new Set([
438-
'scripts/ablation-dist-preflight.mjs',
439438
'scripts/check-changeset-no-major.mjs',
440-
'scripts/check-dispatcher-error-vocabulary.mjs',
441-
'scripts/check-driver-memory-census.mjs',
442439
'scripts/check-empty-changeset.mjs',
443-
'scripts/check-engine-split-ratio.mjs',
444-
'scripts/check-error-code-casing.mjs',
445440
'scripts/check-error-status-conformance.mjs',
446-
'scripts/check-examples-live-imports.mjs',
447-
'scripts/check-filter-alias-parity.mjs',
448-
'scripts/check-nul-bytes.mjs',
449-
'scripts/check-org-identifier.mjs',
450441
'scripts/check-query-options-erasure-ratchet.mjs',
451-
'scripts/check-quick-reference-counts.mjs',
452-
'scripts/check-ratchet-remedy-authority.mjs',
453442
'scripts/check-release-page-status.mjs',
454-
'scripts/check-required-contexts.mjs',
455-
'scripts/check-route-envelope.mjs',
456-
'scripts/check-runtime-services-index.mjs',
457-
'scripts/check-shard-attestation.mjs',
458-
'scripts/check-spec-parsed-alias.mjs',
459-
'scripts/check-startup-registry-verdict.mjs',
460-
'scripts/check-tenant-chokepoint.mjs',
461-
'scripts/check-test-completeness.mjs',
462-
'scripts/check-workflow-status-functions.mjs',
463443
'scripts/checklist-select.mjs',
464-
'scripts/docs-audit/check-audit-scope.mjs',
465-
'scripts/measure-test-shard-timings.mjs',
466444
'scripts/objectui-range.mjs',
467445
'scripts/pm/check-governed-prose.mjs',
468-
'scripts/pm/check-label-desc-cap.mjs',
469-
'scripts/pm/check-skill-id-lint.mjs',
470-
'scripts/pm/check-skill-line-ratchet.mjs',
471446
'scripts/qa/qa-rollup.mjs',
472447
'scripts/ts-parse.mjs',
473448
]);

scripts/check-error-code-casing.mjs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
import { readFileSync, readdirSync, statSync } from 'node:fs';
5454
import { maskComments } from './js-comment-mask.mjs';
5555
import { join, relative, sep } from 'node:path';
56+
import { isEntrypoint } from './invoked-as.mjs';
5657

5758
const ROOT = new URL('..', import.meta.url).pathname.replace(/\/$/, '');
5859
const SCAN_ROOTS = ['packages'];
@@ -241,4 +242,7 @@ If this literal is NOT an error.code — a field/param-addressed validator code
241242
process.exit(1);
242243
}
243244

244-
main();
245+
// Exports bindings, so an import for those exports alone must run nothing (#10667).
246+
if (isEntrypoint(import.meta.url)) {
247+
main();
248+
}

scripts/check-examples-live-imports.mjs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ import { globToRegExp } from './check-cross-package-test-inputs.mjs';
122122
import { join, resolve, relative, dirname, sep, posix } from 'node:path';
123123
import { fileURLToPath } from 'node:url';
124124
import process from 'node:process';
125+
import { isEntrypoint } from './invoked-as.mjs';
125126

126127
const HERE = dirname(fileURLToPath(import.meta.url));
127128
const REPO_ROOT = resolve(HERE, '..');
@@ -759,7 +760,12 @@ function selfTest() {
759760
}
760761

761762
const argv = process.argv.slice(2);
762-
if (argv.includes('--self-test')) selfTest();
763+
// Exports bindings, so an import for those exports alone must run nothing (#10667).
764+
const invokedDirectly = isEntrypoint(import.meta.url);
765+
766+
if (!invokedDirectly) {
767+
// imported as a module — expose the exports and do nothing else
768+
} else if (argv.includes('--self-test')) selfTest();
763769
else if (argv.includes('--list')) list();
764770
else if (argv.includes('--json')) {
765771
const { rows, unresolved } = collect();

scripts/check-filter-alias-parity.mjs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ import { join } from 'node:path';
8888
import { fileURLToPath } from 'node:url';
8989
import ts from 'typescript';
9090
import { parseSourceFile } from './ts-parse.mjs';
91+
import { isEntrypoint } from './invoked-as.mjs';
9192

9293
const ROOT = join(fileURLToPath(new URL('.', import.meta.url)), '..');
9394

@@ -648,4 +649,7 @@ function main() {
648649
process.exit(1);
649650
}
650651

651-
main();
652+
// Exports bindings, so an import for those exports alone must run nothing (#10667).
653+
if (isEntrypoint(import.meta.url)) {
654+
main();
655+
}

scripts/check-nul-bytes.mjs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ import { lstatSync, mkdirSync, mkdtempSync, readFileSync, rmSync, symlinkSync, w
269269
import { tmpdir } from 'node:os';
270270
import { dirname, join } from 'node:path';
271271
import { fileURLToPath } from 'node:url';
272+
import { isEntrypoint } from './invoked-as.mjs';
272273

273274
/**
274275
* The scanned set as a 256-entry lookup: every ASCII control character except
@@ -1155,7 +1156,12 @@ function selfTest() {
11551156
console.log(`✓ check-nul-bytes --self-test: ${checked} assertions over a temp git repo (real scan() path)`);
11561157
}
11571158

1158-
if (process.argv.includes('--self-test')) {
1159+
// Exports bindings, so an import for those exports alone must run nothing (#10667).
1160+
const invokedDirectly = isEntrypoint(import.meta.url);
1161+
1162+
if (!invokedDirectly) {
1163+
// imported as a module — expose the exports and do nothing else
1164+
} else if (process.argv.includes('--self-test')) {
11591165
selfTest();
11601166
} else if (process.argv.includes('--list')) {
11611167
const result = scan(repoRoot());

scripts/check-org-identifier.mjs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ import { join } from 'node:path';
271271
import ts from 'typescript';
272272
import { parseSourceFile } from './ts-parse.mjs';
273273
import { maskComments } from './js-comment-mask.mjs';
274+
import { isEntrypoint } from './invoked-as.mjs';
274275

275276
const ROOTS = ['examples', 'apps', 'packages'];
276277
const EXTENSIONS = ['.ts', '.tsx', '.js', '.jsx', '.mjs', '.cjs', '.cts', '.mts'];
@@ -785,4 +786,7 @@ cheapest way to silence it while leaving the dead read in place.`);
785786
process.exit(1);
786787
}
787788

788-
main();
789+
// Exports bindings, so an import for those exports alone must run nothing (#10667).
790+
if (isEntrypoint(import.meta.url)) {
791+
main();
792+
}

0 commit comments

Comments
 (0)