Skip to content

check-cross-package-test-inputs.mjs runs verify() as an import side effect — importing it for its exported helpers runs the whole gate and can process.exit(1) #10610

Description

@claude

Filed unassigned from the #10452 dev seat (session session_01DdCnBGcHeufjrq7drTD3wt, PR #10607). Observed while probing the collector, not a card I acted on. No live consumer is broken today.

The shape

scripts/check-cross-package-test-inputs.mjs ends with a bare top-level dispatch:

constargv=process.argv.slice(2);if(argv.includes('--self-test'))selfTest();elseif(argv.includes('--list-escapes')){ ... }elseif(argv.includes('--union-into')){ ... }elseverify();

There is no isEntrypoint() guard, so the else verify() branch fires on import, not only on invocation. The file also exports real helpers (escapingBindings, importSpecifiers, coversDirectory, matchesAny, repoRelativeLiterals, findEscapingPackages, serializePackageList, unionInto).

Measured on 505e9dd905:

$ node --input-type=module -e "await import('./scripts/check-cross-package-test-inputs.mjs')"
OK: 13 package(s) read outside themselves, all declared, and turbo.json hashes every declared glob.

That line is printed by the import alone. On a tree where the gate is unhappy the same import calls process.exit(1) instead, so any consumer of the exports inherits the gate's verdict as its own exit status, plus its stdout.

Why it is a finding rather than a bug report

Nothing imports the module today — the nine files that mention it, mention it in prose. So there is no present breakage, and this is about the absence of a guard rather than a live defect.

Two things make it worth recording anyway:

  • The repo has the idiom and uses it widely.scripts/invoked-as.mjs exports isEntrypoint, and 35 scripts under scripts/ already call it. This file is one of the ones that does not.
  • The cost may already have been paid once.scripts/check-examples-live-imports.mjs:315 documents that its globToRegExp is "Mirrored from globToRegExp in check-cross-package-test-inputs.mjs rather than" imported. A hand-mirrored copy of a helper is exactly the sort of duplication an unguarded entry point encourages, and duplicated glob semantics between two gates that must agree is its own hazard.

Not claimed

  • I have not checked whether the mirroring in check-examples-live-imports.mjs was actually motivated by this; the comment gives a reason that is truncated in my quote above and should be read in full before that link is asserted.
  • I have not swept the other scripts/** gates for the same missing guard. If several are unguarded the shape of the fix changes.

Likely fix

Wrap the dispatch in the existing predicate, matching the 35 files that already do:

if(isEntrypoint(import.meta.url)){/* existing dispatch */}

The self-test would want a case pinning that importing the module produces no output and no exit, or the guard can be removed again as quietly as it was never added.


Generated by Claude Code

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions