✨ feat(mutation): a scripts lane judges the root's scripts/*.mjs

Merged
AT
11d ago
+1177-240

Slice: #327

The mutation gate now judges the root's own scripts/*.mjs: the lane planner, the version rule, the provenance check and the temp-folder wrapper. Its first run found survivors in all four, and each is killed. No mutant is left: 863 of 863 killed (859 Killed, 4 RuntimeError), in about 50 s on an 18-core Mac. On CI's Linux runner the lane job took 1 min 37 s.

This waits for Alok's code-owner review. It touches agnipariksha.json, stryker/ and scripts/version-rule.mjs and scripts/mutation-lanes.mjs, which .github/CODEOWNERS names. Auto-merge is on, so it merges once he approves and the checks pass.

The lane

  • The lane: agnipariksha.json gains a scripts lane:

    • it is the only lane that runs from the root (cwd: ""; judgeLane handles an empty cwd);
    • it includes ^scripts/[^/]+\.mjs$, with the extension .mjs;
    • \.test\.mjs$ is added to ignore.
  • Its Stryker config, stryker/scripts.config.mjs, is lane('') with ignorePatterns. It lives under stryker/, which CODEOWNERS already owns, so neither CODEOWNERS nor CLAUDE.md changes.

    • Run from the root, Stryker would otherwise copy the whole tree into its sandbox: packages/, .tmp/, and in the main checkout every worktree under .claude/worktrees/. The sandbox keeps only scripts/, package.json and agnipariksha.json.
    • pnpm-lock.yaml must stay out. The 4 RuntimeErrors are the mutants that force own-provenance.mjs's entry condition true, and they die on its absence before any request leaves the machine. The config says so.
  • released-pins.mjs is out, through the lane's exclude. It is a hook file agents don't change (CLAUDE.md, "Git hooks"), so a survivor there would block a push only you could make. guards.sh isn't JavaScript.

  • The pin needed no change. The root already pins agnipariksha 0.8.5 (#421), which carries #325's .test.mjs ownership. Going back to 0.8.4 would drop --pushed-refs, which the pre-push hook uses (#423).

  • CI plans the lane with no change to the planner's logic. A new case in mutation-lanes.test.mjs plans veda's real agnipariksha.json:

    • a changed scripts/x.mjs beside its suite gives the scripts lane work;
    • a changed suite alone gives it none, and neither does released-pins.mjs.

    Run by hand on this branch, scripts/mutation-lanes.mjs --base origin/main prints lanes to judge: scripts, so this PR's Mutation check runs the lane on Linux. A lane job's 90-minute timeout is far above that.

  • The lint rule that refuses // Stryker disable (MUTABLE in eslint.config.js) already covers scripts/**, so no comment can take a script's mutants out of the lane.

The sources changed too

The slice expected the survivors to die in the suites alone. They couldn't, so all four sources changed. Each change keeps the command line, output and exit codes as they were:

  • Every script, the entry. The /* node:coverage disable */ block if (process.argv[1] && import.meta.url === …) { … } was untestable in-process: Stryker sees no coverage from a spawned child. It becomes an exported entry(argv, url, io) that returns the exit code, or undefined when the module is imported. The module ends with process.exitCode = (await entry(process.argv, import.meta.url)) ?? process.exitCode;, so an import leaves the importer's exit code as it was. Each suite checks that in a child that sets the code to 7 before importing the script.
    • Its real I/O is injectable, with the real one as the default.
    • The suites test it in-process with fakes, so a forced-true mutant reaches no network, spawns nothing, and runs no git in the real repository.
  • mutation-lanes.mjs: gitIn's stdio went from ['ignore', 'pipe', 'pipe'] to 'pipe'. The array's [] mutant was equivalent. The '' mutant of 'pipe' makes execFileSync print git's stderr as well, which a spy sees.
  • version-rule.mjs:
    • gitTags, fetchJson and realIo() are exported.
    • majorApproved: (a.environments ?? []).some(…) became a.environments?.some(…) === true, with the same result.
    • Manifests are read as String(readFileSync(…)), with no encoding named.
    • check gets tag directly; it already treats an absent tag and an undefined one alike.
    • main's last branches were reordered so "nothing unreleased" comes first. check always returns a version with a bump, so result.version ?? '' in the major warning could never be reached, and it is gone.
    • defaultManifests(root, list) takes the folder listing, so the .sort() kill does not depend on the order the filesystem lists folders in: APFS sorts them, ext4 does not.
  • own-provenance.mjs:
    • main(io) writes to an injectable stdout and stderr, and returns 1 where the block called process.exit(1). Nothing runs after it.
    • fetchJson(url, { get, env }) and readText are exported.
    • bundleVerifier takes the verifier class, so a test sees its thresholds, which equal the library's defaults.
    • utf8String takes the byte length of Buffer.from(text). The bytes are the same for the ASCII it is given (a commit id, refs/heads/main).
    • Two Array.isArray(x) ? x : [] fallbacks became direct find and some calls; their ["Stryker was here"] mutants could not be told apart.
  • fresh-tmpdir.mjs:
    • run takes a spawn option, so a fake child can reach the 'error' handler and the signal forwarding.
    • A comment was wrong: Node does send 'close' (code -2) after a spawn's ENOENT 'error'. It now says so.

The suites:

  • Each suite yields once per test (beforeEach → setImmediate), so the tap runner's forceBail lands on a mutant's first failure.
  • Messages are asserted whole, as literals.
  • fresh-tmpdir's tests that run a real process have a 10 s timeout. Each such child first checks that its temp folder is the run's own scratch folder, so no mutant can aim a removal at the real tmpdir.
  • pnpm test:scripts has 100% lines and functions in all four.

Not done

docs/lessons/stryker.md still describes the lanes as one per package. That page is copied into sarathi's package at build, so the fix is left for a docs change.

🤖 Generated with Claude Code