Repository navigation
Description
Nothing stops a new script — or a later edit to an existing one — from shipping the raw entry-point comparison that #372 removed: path.resolve(process.argv[1]) === fileURLToPath(import.meta.url) (or any spelling of it). Node realpaths the main module and leaves process.argv[1] as typed, so through a symlinked checkout, plugin cache or npm prefix the comparison never matches, main() does not run, and the script exits 0 having checked nothing.
#372 fixed the scripts that had it and gave isMain() (scripts/lib/verify-core.mjs) and each self-guarded file a behaviour test that spawns it through a symlink. It does not stop the next one. src/ has six more cases: #381.
What was tried and why it was dropped
The #372 branch carried a test that classified every script by reading its source text. It went through five review rounds, and every round found the next spelling a text rule cannot decide:
- a
.cjsguard written with__filename(never a candidate); argv[i]whereiis 1,Array.from(process.argv)[1],parseArgs(process.argv),const [, entry] = process.argv,.at(1),.slice(1);- a
!==early return withmain()in theelse; .endsWith(process.argv[1])(still live insrc/transports/http/server.ts);- an alias next to an unrelated
realpathSync(other); - a script on the "has no guard" allowlist that later gains one.
Whether a comparison resolves the path is a question about which value reaches which operand. A regular expression over text cannot answer it, and a test that answers it wrongly gives false assurance.
Suggested approach
Use the syntax tree. npm run lint already runs ESLint over every file git lists under src/, scripts/, tests/ and dashboard/src/ (all seven extensions the config covers), so a rule there needs no second file walker:
no-restricted-syntaxselectors that forbid reading element 1 ofprocess.argv(process.argv[1],process.argv.at(1), and an array pattern taking it fromprocess.argv) everywhere exceptscripts/lib/verify-core.mjs, through per-fileoverridesineslint.config.js;- the override list is the allowlist: each entry a file that ships standalone and cannot import
scripts/lib/(scripts/hooks/*,scripts/check-plugin-hook-artifact.mjs), each with a named behaviour test that spawns it through a symlink (four exist today).
Also
node --test scripts/lib/verify-core.test.mjs — the only behaviour proof for isMain() — runs only in the sdlc-verify CI job. npm run verify and verify:release do not run it, so removing that CI step would leave twelve entry points depending on a function nobody tests. Run it from a gate that both paths share.
Activity
kevintseng commentedon Dec 2, 2026
PR #650 adds an ESLint rule covering raw entry-point guards and runs the shared helper tests from the release gate. That gate passed on Windows Node 22 and 24 and on Linux.