ā test(kavach): rule-checks' TypeScript has no surviving mutant
Brings kavach's TypeScript rule checks (packages/kavach/src/rule-checks/: args.ts, cli-entry.ts, cli.ts, fire-log.ts, latency.ts, live-runs.ts, registry.ts, runtime.ts, shell-comments.ts, shell-words.ts) to zero blocking mutants, for slice 4 of the mutation sweep (#466).
Measured first
None of these files or their suites changed on main since 9b535c2, so the issue's list of 81 is the baseline (the lock was held by other sessions' runs for hours, and a local baseline never got it). Every listed survivor has a test here, or a rewrite that removes it. The command, in its comma form (the issue's space-separated form is refused):
pnpm exec agnipariksha --lane kavach --files packages/kavach/src/rule-checks/args.ts,packages/kavach/src/rule-checks/cli-entry.ts,packages/kavach/src/rule-checks/cli.ts,packages/kavach/src/rule-checks/fire-log.ts,packages/kavach/src/rule-checks/latency.ts,packages/kavach/src/rule-checks/live-runs.ts,packages/kavach/src/rule-checks/registry.ts,packages/kavach/src/rule-checks/runtime.ts,packages/kavach/src/rule-checks/shell-comments.ts,packages/kavach/src/rule-checks/shell-words.ts --no-reuse
Tests
New tests in each owning suite, literal expected values, fixtures inside each test:
args.ts: an option's one value, the word after it read as an argument, and no flag known unless given.cli-entry.ts: the fast path answers true for the module's own path even when the file is gone.cli.ts: checks whoseeventsortoolshold a non-text item; a list or a function carrying every field;entry(another file, this module, the hook's stdin), an importer's exit code kept (a child sets 7 and imports the CLI),readStdin, andLIVE_IO's writes.fire-log.ts: the log's descriptor is closed after a whole and after a short write.latency.ts: a hung hook that ignores TERM is still killed (the signal is KILL); a hook writing more than a pipe holds still exits, since its output is dropped.live-runs.ts:ps'sstdiofor both calls, a padded zombie state, and a thrownnull.registry.ts: an enforcer file ending in.., a PR given as text, the empty-variable message whole.runtime.ts: a pass after a run of blanks, a reason running past a carriage return, fields that are not text, and the registry's owner reached through the lazily loaded registry.shell-comments.tsandshell-words.ts: a comment that starts the command; an escaped character and a backslash-newline; a here-string; a heredoc word that cannot be settled before a later one;<<-ends only after leading tabs;${and backquotes;&>|; an escaped blank in$'ā¦'; a digit word before a heredoc and before a redirection; a heredoc ending at the end of the text with one or two bodies open; arithmetic through a newline or a backquote;cdoptions taken only whole; a~inside a word.
Rewrites that keep behaviour
Where no test could tell a mutant from the code, the code changed. Each keeps today's outputs, errors and side effects:
cli.ts's entry: the import-time block is an exportedentry(argv, moduleUrl, io, stdin, env); the module endsprocess.exitCode = (await entry(process.argv, import.meta.url, LIVE_IO, readStdin, process.env)) ?? process.exitCode;.LIVE_IOandreadStdinare the same streams the block built inline. Thebinpath,dist/rule-checks/cli.js, is unchanged.latency.ts: thesettledflag goes (a promise settles once andclearTimeoutis idempotent, so a laterexitorerrorchanged nothing); the kill isprocess.kill(-Number(child.pid), 'SIGKILL'), where a child with no pid gives-NaN, which throws into the same catch thepid !== undefinedcheck led to.live-runs.ts:parseRunandgitDirread inside onetry, so their catches are the only fallbacks:JSON nullfails the destructuring there, andtypeof pid !== 'number'goes sinceNumber.isSafeIntegeris false for any non-number.liveRunreads and parses in onetry. Thegitdir:regex loses a$its.+already implied.- For a reviewer:
sweepMarkersnow has two narrowtrys, around the read and the remove, instead of one around read,isGoneand remove.isGonenever throws (the probe catches its own failures), so nothing that was swallowed before escapes now. main'sdir === undefined || dir === ''is!dir.
registry.ts: the PR check dropstypeof pr !== 'number'(Number.isSafeIntegercovers it).runtime.ts:statedPassesreads the match's groups withString()(both always take part);registryRuleswithout a path returns{ find: () => undefined, owner: DEFAULT_OWNER }instead of building an empty registry.shell-comments.ts: the last-read character becomes abreaksflag and the skipped characters a count, with a separateescapedflag for a backslash, which keeps a backslash-newline's join exactly as before; the newline drops out ofWORD_BREAK(a line's start sets the flag); the heredoc word isString(single ?? double ?? bare).shell-words.ts:HEREDOCloses|$(a word that ends the text stops the reader either way);ANSI_ESCAPEloses^(it is read at a backslash, where[\s\S]always matches when anything follows); the redirection tail is atailLength()helper over/^[<>&|]+/;bodiesis assigned when body mode starts and read only in it (a definite-assignmentlet bodies!:), so the body check and the end-of-text check testmodealone;DOUBLE_ESCAPES.includes(String(next))and/^\d+$/.test(String(word))replace checks forundefinedandnullthatString()already answers;roughCommandssplits on each blank, whose empty words were already dropped.
No equivalent mutant is left. No // Stryker disable, no change to agnipariksha.json, stryker/, eslint-suppressions.json or kavach's Python, and no version bump: kavach guards sessions from the main checkout's pinned install, so none of this reaches a session until a release.
Where each file is judged
- The seven changed sources hold more lines than the kavach lane's cut-off (1,500), so pre-push leaves them to CI: the required
Mutationcheck on this pull request runs the slice's command over them. args.ts,cli-entry.tsandfire-log.tschanged only in their suites, so neither pre-push nor CI judges them; a hand run ofpnpm exec agnipariksha --lane kavach --files packages/kavach/src/rule-checks/args.ts,packages/kavach/src/rule-checks/cli-entry.ts,packages/kavach/src/rule-checks/fire-log.ts --no-reuseis posted below.- Expect up to two Timeouts on
entry's guard: forced true, an import runs the CLI and reads stdin, which never closes under the tap runner. The gate counts a twice-timed-out mutant as caught.
Checked
pnpm --filter @veda-hq/kavach test: 806 of 806 pass, coverage thresholds included.typecheckandeslint packages/kavach/src/rule-checksare clean.- Each doubtful kill was checked by applying the mutant by hand and seeing its test fail.
Slice: #470
š¤ Generated with Claude Code
Summary by cubic
Brings kavach's TypeScript rule checks to zero surviving mutants for slice 4 of the mutation sweep (#466).
New tests in each file's own suite cover most survivors with literal expected values and inline fixtures. Where a test couldn't tell a mutant from the code, small rewrites keep today's outputs, errors, and side effects. Review and CI findings added more tests and fixed two regressions those rewrites had introduced.
Refactors
cli.ts's import-time block is now an exportedentry(), keeping thebinpath unchanged.latency.tsdrops thesettledflag; a child with no pid throws into the existing catch, and the hang timer never fires after a hook exits.live-runs.tsnarrows itstryblocks;sweepMarkerstakes a run apart before its catch so a failing probe leaves the marker instead of stopping the sweep.shell-words.tskeeps the end-of-text check's guard for an empty heredoc body queue: a substitution's own heredoc can empty it without crashing the reader.runtime.ts'sregistryRulesreturns an emptyRuleswhen no path is given.registry.ts'scountresolvescwditself when no--rootis given.shell-comments.tsandshell-words.tstrack breaks, escapes, tail counts, and body mode explicitly.
No // Stryker disable, config change, or version bump; all 806 tests pass.