Skip to content

Nothing stops a new script from shipping a raw entry-point guard that a symlink defeats #383

Done

Description

@kevintseng

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 .cjs guard written with __filename (never a candidate);
  • argv[i] where i is 1, Array.from(process.argv)[1], parseArgs(process.argv), const [, entry] = process.argv, .at(1), .slice(1);
  • a !== early return with main() in the else;
  • .endsWith(process.argv[1]) (still live in src/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-syntax selectors that forbid reading element 1 of process.argv (process.argv[1], process.argv.at(1), and an array pattern taking it from process.argv) everywhere except scripts/lib/verify-core.mjs, through per-file overrides in eslint.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

  1. kevintseng commented on Dec 2, 2026

    @kevintseng
    CollaboratorAuthor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions