✅ test(pariksha): cli.ts passes the mutation gate with its own suite

Merged
AT
11d ago
+2378-161

Slice: #269

packages/pariksha/src/cli.ts now passes the mutation gate with cli.test.ts alone: Stryker 10.1.1, tap runner, tap.testFiles: ["src/cli.test.ts"], mutate: ["src/cli.ts"].

Counts

RunMutantsSurvivedNoCoverageBlockingKilledTimeoutRuntimeError
Before, CI run 44507830088 (#238)1,6862158581,073
Before, local full run on main1,68661,0171,02313750224
After, local full run on this branch1,5370001,512124

On a Mac shared with other sessions, the last two "after" runs took 10 min 38 s and 21 min 12 s at --concurrency 10; the "before" one took 20 min 40 s at 17. Both used the tap config of .github/stryker-timing/pariksha-169.json, narrowed to cli.ts, with incremental mode off. The 502 "before" Timeouts are load: that suite never let a bail land (below), so every covered mutant ran the whole 17-46 s file.

  • Timeout after: one, splitFiles' i += 1 → i -= 1, a loop that never ends; Stryker's hit limit stops it fast, and the gate counts a Timeout as caught. Under heavy load, earlier runs also timed out mutants that the last tests kill; each was Killed when re-run alone.
  • RuntimeError: the 24 COMMANDS entries mutated to {}. Each fails the import, since CONFIGURABLE reads every entry's allowed at load, and the gate counts that as caught.
  • Time on CI: those runs come to 106 to 212 process-minutes. On a 4-CPU runner, expect this lane to take between half an hour and an hour. #238's run took 25 minutes, but 858 of its mutants never ran.
  • The mutant count fell from 1,686 because code no test could observe is gone (below).

How

Tests in cli.test.ts, in-process and fast. Every command's own code now runs through run(args, io), with external tools injected through Io (lychee, shellcheck, Vitest, Python, ESLint and its runner, TypeScript, the clock, stdin, cwd) and one lazily built fixture per command. The sibling cli.*.test.ts suites are untouched and still test the checks end to end. About 185 tests; the file runs in about 15-23 s, cheap tests first and git histories last.

Two things the tap runner needs, both in the suite's header:

  • A beforeEach that yields one turn of the event loop. node's TAP reporter writes asynchronously, so a file of synchronous tests printed nothing until it ended and forceBail never fired: a mutant killed 2 s in still cost the whole file. With the yield, a 108-mutant range averaged about 8 s a mutant against a 24 s file.
  • Descriptor 0 closed at load and a small file opened on it. tap's child has a stdin pipe that never closes, so a mutant that read readFileSync(0) hung until the timeout. Now such a read returns at once, and the default --files-from - reader is tested in-process.

cli.ts changes, behaviour kept. Each one removes code no test could observe, as docs/lessons/stryker.md says:

  • main(argv, io) and consoleIo are exported and the module ends with process.exitCode = await main(process.argv), so the entry point runs in-process.

  • --root reads go through one rootOf(f) (resolve(... ?? '.') made '.' → '' unkillable at 20 sites).

  • The .pariksha.json markers moved from '\0…' keys in the flags map to two WeakMaps (projectFile, inlineText): no user can type a key, so blanking one changed nothing.

  • run finds its command with Object.entries(COMMANDS).find, and flags, CONFIGURABLE, applyProject lose TypeScript-only guards.

  • configText and required-settings read with .toString(): a Buffer parses as JSON the same, so 'utf8' was unobservable.

  • One NONE list serves both eslint-by-workspace's no arguments and repo-rules' no removed paths, so a filled list shows as ESLint arguments.

  • removedPaths lists --diff-filter=D with renames unpaired (PLAIN_DIFF): the same old paths as before, without the rename parsing no test could tell apart. deleted-path-still-pinned may now name the other path when one test line quotes two.

  • Smaller ones: docReferences' baseline switch, maskedExitCodes' empty-files guard, pythonFloor's options from a flag table, schemaRoots' list, env-gate-switches' one TREE name, fileSize's catch, a fault group's kind.

  • main sets process.exitCode only when it ran, so importing dist/cli.js (a public export) leaves the importer's exit code alone.

repo-rules.ts, which the gate will judge too.

  • sideGrep now tests kind === 'tree' first and treats anything else as an index or a commit. Before, a side that named no kind was read as the tree, so { kind: 'tree' } → {} in cli.ts could not be seen. The test that now sees it is a whole-tree repo-rules run whose workers rule greps the working tree.
  • Changing the file brings it whole under the gate, against repo-rules.test.ts. It had 14 survivors there, and all are gone:
    • parseGrep strips a commit's prefix only when it is given one, and drops a redundant filter. Its anchors stay: . stops at \r, so a CRLF grep line is no hit, as on main, and two cases now pin them. Whether such lines should count is a question for later.
    • sideGrep returns no hits for a grep that found none.
    • lineAt and diskRepo's isFile drop a bound and a return no test could see.
    • The suite gains the cases that see the rest.
  • Stryker on repo-rules.ts with repo-rules.test.ts: 297 mutants, 295 Killed, 2 Timeout (both endless loops stopped by the hit limit), 0 blocking.
  • The full cli.ts count above was taken one commit before the head. That last commit touches only repo-rules.ts and its suite, and no cli.test.ts fixture holds a \r.

Checks

  • pnpm --filter @veda-hq/pariksha check: green (typecheck, test with coverage, build, smoke).
  • ESLint on the changed files: cli.ts keeps its 22 suppressed no-swallowed-catch hits, so eslint-suppressions.json is unchanged; nothing else.
  • pariksha's version is not bumped.

🤖 Generated with Claude Code


Summary by cubic

packages/pariksha/src/cli.ts now passes the mutation gate with cli.test.ts alone — 0 surviving mutants out of 1,537, down from 6 survivors with 1,073 blocking on main. The suite adds ~185 fast in-process tests, with external tools injected through Io and one lazily built fixture per command.

Refactors

  • main(argv, io) and consoleIo are exported; importing the module no longer touches the importer's exit code.
  • The '\0-keyed config markers move to WeakMaps, --root reads go through one rootOf, and unobservable TypeScript-only guards are dropped.
  • repo-rules.ts also passes the gate (297 mutants, 0 blocking); sideGrep checks the tree kind first, parseGrep strips a commit prefix only when given one.
  • removedPaths lists renames as plain deletions, so a combined rename line may now name the other path.

The tap runner needs two suite-setup details: a beforeEach that yields one event loop turn so a killed mutant bails at its first failing test, and stdin closed at load so a mutant reading it returns instead of hanging.