✅ test(pariksha): cli.ts passes the mutation gate with its own suite
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
| Run | Mutants | Survived | NoCoverage | Blocking | Killed | Timeout | RuntimeError |
|---|---|---|---|---|---|---|---|
| Before, CI run 44507830088 (#238) | 1,686 | 215 | 858 | 1,073 | |||
Before, local full run on main | 1,686 | 6 | 1,017 | 1,023 | 137 | 502 | 24 |
| After, local full run on this branch | 1,537 | 0 | 0 | 0 | 1,512 | 1 | 24 |
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
COMMANDSentries mutated to{}. Each fails the import, sinceCONFIGURABLEreads every entry'sallowedat 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
beforeEachthat yields one turn of the event loop. node's TAP reporter writes asynchronously, so a file of synchronous tests printed nothing until it ended andforceBailnever 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)andconsoleIoare exported and the module ends withprocess.exitCode = await main(process.argv), so the entry point runs in-process. -
--rootreads go through onerootOf(f)(resolve(... ?? '.')made'.'→''unkillable at 20 sites). -
The
.pariksha.jsonmarkers moved from'\0…'keys in the flags map to two WeakMaps (projectFile,inlineText): no user can type a key, so blanking one changed nothing. -
runfinds its command withObject.entries(COMMANDS).find, andflags,CONFIGURABLE,applyProjectlose TypeScript-only guards. -
configTextandrequired-settingsread with.toString(): a Buffer parses as JSON the same, so'utf8'was unobservable. -
One
NONElist serves both eslint-by-workspace's no arguments and repo-rules' no removed paths, so a filled list shows as ESLint arguments. -
removedPathslists--diff-filter=Dwith renames unpaired (PLAIN_DIFF): the same old paths as before, without the rename parsing no test could tell apart.deleted-path-still-pinnedmay 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' oneTREEname,fileSize's catch, a fault group'skind. -
mainsetsprocess.exitCodeonly when it ran, so importingdist/cli.js(a public export) leaves the importer's exit code alone.
repo-rules.ts, which the gate will judge too.
sideGrepnow testskind === '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' }→{}incli.tscould 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:parseGrepstrips a commit's prefix only when it is given one, and drops a redundantfilter. Its anchors stay:.stops at\r, so a CRLF grep line is no hit, as onmain, and two cases now pin them. Whether such lines should count is a question for later.sideGrepreturns no hits for a grep that found none.lineAtanddiskRepo'sisFiledrop a bound and areturnno test could see.- The suite gains the cases that see the rest.
- Stryker on
repo-rules.tswithrepo-rules.test.ts: 297 mutants, 295 Killed, 2 Timeout (both endless loops stopped by the hit limit), 0 blocking. - The full
cli.tscount above was taken one commit before the head. That last commit touches onlyrepo-rules.tsand its suite, and nocli.test.tsfixture 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-catchhits, soeslint-suppressions.jsonis 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)andconsoleIoare exported; importing the module no longer touches the importer's exit code.- The
'\0-keyed config markers move to WeakMaps,--rootreads go through onerootOf, and unobservable TypeScript-only guards are dropped. repo-rules.tsalso passes the gate (297 mutants, 0 blocking);sideGrepchecks the tree kind first,parseGrepstrips a commit prefix only when given one.removedPathslists 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.