āœ… test(kavach): rule-checks' TypeScript has no surviving mutant

Merged
AT
4d ago
+413-102

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 whose events or tools hold 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, and LIVE_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's stdio for both calls, a padded zombie state, and a thrown null.
  • 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.ts and shell-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; cd options 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 exported entry(argv, moduleUrl, io, stdin, env); the module ends process.exitCode = (await entry(process.argv, import.meta.url, LIVE_IO, readStdin, process.env)) ?? process.exitCode;. LIVE_IO and readStdin are the same streams the block built inline. The bin path, dist/rule-checks/cli.js, is unchanged.
  • latency.ts: the settled flag goes (a promise settles once and clearTimeout is idempotent, so a later exit or error changed nothing); the kill is process.kill(-Number(child.pid), 'SIGKILL'), where a child with no pid gives -NaN, which throws into the same catch the pid !== undefined check led to.
  • live-runs.ts:
    • parseRun and gitDir read inside one try, so their catches are the only fallbacks: JSON null fails the destructuring there, and typeof pid !== 'number' goes since Number.isSafeInteger is false for any non-number. liveRun reads and parses in one try. The gitdir: regex loses a $ its .+ already implied.
    • For a reviewer: sweepMarkers now has two narrow trys, around the read and the remove, instead of one around read, isGone and remove. isGone never throws (the probe catches its own failures), so nothing that was swallowed before escapes now.
    • main's dir === undefined || dir === '' is !dir.
  • registry.ts: the PR check drops typeof pr !== 'number' (Number.isSafeInteger covers it).
  • runtime.ts: statedPasses reads the match's groups with String() (both always take part); registryRules without a path returns { find: () => undefined, owner: DEFAULT_OWNER } instead of building an empty registry.
  • shell-comments.ts: the last-read character becomes a breaks flag and the skipped characters a count, with a separate escaped flag for a backslash, which keeps a backslash-newline's join exactly as before; the newline drops out of WORD_BREAK (a line's start sets the flag); the heredoc word is String(single ?? double ?? bare).
  • shell-words.ts: HEREDOC loses |$ (a word that ends the text stops the reader either way); ANSI_ESCAPE loses ^ (it is read at a backslash, where [\s\S] always matches when anything follows); the redirection tail is a tailLength() helper over /^[<>&|]+/; bodies is assigned when body mode starts and read only in it (a definite-assignment let bodies!:), so the body check and the end-of-text check test mode alone; DOUBLE_ESCAPES.includes(String(next)) and /^\d+$/.test(String(word)) replace checks for undefined and null that String() already answers; roughCommands splits 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 Mutation check on this pull request runs the slice's command over them.
  • args.ts, cli-entry.ts and fire-log.ts changed only in their suites, so neither pre-push nor CI judges them; a hand run of 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/fire-log.ts --no-reuse is 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. typecheck and eslint packages/kavach/src/rule-checks are 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 exported entry(), keeping the bin path unchanged.
  • latency.ts drops the settled flag; a child with no pid throws into the existing catch, and the hang timer never fires after a hook exits.
  • live-runs.ts narrows its try blocks; sweepMarkers takes a run apart before its catch so a failing probe leaves the marker instead of stopping the sweep.
  • shell-words.ts keeps 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's registryRules returns an empty Rules when no path is given.
  • registry.ts's count resolves cwd itself when no --root is given.
  • shell-comments.ts and shell-words.ts track breaks, escapes, tail counts, and body mode explicitly.

No // Stryker disable, config change, or version bump; all 806 tests pass.