✅ test(sarathi): format-before-write.ts, merge.ts and 4 more have no surviving mutant (#491)

Merged
AT
3d ago
+752-111

Slice: #491

pnpm exec agnipariksha --lane sarathi --files <the six files> --no-reuse is the slice's bar: no Survived and no NoCoverage mutant. The six files change 1854 lines, over the pre-push gate's 1000-line cut-off for the lane, so CI's required Mutation check judges this pull request.

Before. The six files and their suites are unchanged from 9b535c2 to today's main. The inventory left 186 there.

Tests. Each file's owning suite gains cases for the rules it reads:

  • format-before-write.test.ts: the session root, finding prettier, the minimal edit, the Write and Edit paths, and the script in-process.
  • merge.test.ts: how answers merge and what a blocker's stderr carries.
  • page/guard.test.ts: the transcript, the stdin read and the script entry.
  • page/page.test.ts: the action box, list links, the read and record parsers, the stream, outcomes, the guard file, and backup numbering.
  • page/usage-limit.test.ts: nested fields and non-object lines.
  • run.test.ts: an empty entry, a handler that ignores SIGTERM, and a handler that cannot start.

They assert literal values, and each builds its fixture inside its own it.

Rewrites. Each one keeps today's behaviour:

FileChangeWhy it is the same
format-before-write.tssessionRoot: stdio: 'pipe', and no top !== '' checkgit prints a toplevel or fails; it never succeeds with an empty one. Piping stdin too changes nothing, since git reads none.
format-before-write.tsloadPrettier loops over [root, CLAUDE_PROJECT_DIR] as given, with join(base ?? '', 'package.json')createRequire refuses a relative path, so an unset or empty base finds nothing, as the filter did.
format-before-write.tsuniqueIndex: one testWhen at is -1, the search from at + 1 finds the needle at 0 when there is one (answer -1) and nothing when there is none (answer at, also -1).
format-before-write.tsminimalEdit: the start scan compares charCodeAt; no old !== '' check; from = lineStart + 1charCodeAt past either end is NaN, which equals nothing. An empty old_string occurs everywhere, so uniqueIndex never finds it unique. lastIndexOf's -1 gives 0. A probe compared the old and new functions on all 10.7M pairs of strings up to 7 characters: identical.
format-before-write.tsreturn edit && {...}minimalEdit gives an edit or null, and null is the answer for no edit.
format-before-write.tsupdatedInput: no filePath === '' checkAn empty path has no extension, so inScope refuses it before prettier is asked.
merge.tsparseJson: no startsWith('{'); the catch holds a comment, then the function returns undefinedJSON.parse refuses what the prefix check refused, or yields a non-record that isRecord refuses. The catch stays un-annotated, so eslint-suppressions.json's count holds.
merge.tsmergeSpecific and mergeJson assign permissionDecisionReason, stopReason, reason, systemMessage and hookSpecificOutput directlyThe merged answer's only consumer is JSON.stringify, which drops a field left undefined.
merge.tsothersTexts(outcomes) for the non-blockersothersTexts reads only exit-0 answers, and no blocker exits 0.
page/guard.tstranscriptEvents: no blank-line skip; the catch holds only its fail-open noteJSON.parse refuses a blank line, and the catch skips it.
page/guard.tsreadInput keeps bytes and decodes once at the endThe same UTF-8 text, now with a character split across chunks decoded whole.
page/guard.tsisEntry: no script !== ''; an exported start(script, moduleUrl, stdin, run), called once at module levelAn empty path resolves to the working folder, never a module. start reads stdin only when this module is the script, as the if did.
page/page.tsopensList: String(kind), no kind === undefined line"undefined" is in neither list set.
page/page.tsa self-closing or void box returns partsIn([])It is the same { link: false, silent: false, lists: [] }.
page/page.tsstagedFile reads textFile off any other jobOnly a reply carries one.
page/page.tsrun(..., guardScript = GUARD), threaded through runJob and sessionThe default is the same guard file. A test names a missing one to show the job is refused before any session.
page/usage-limit.tsa field(value, key) reader with optional chaining, in place of isObjectA primitive or null has none of the keys read (type, api_error, message, content, result), and an unparsed line leaves event undefined.
run.tsno settled flagfinish resolves a promise, which keeps its first answer, and clears the timer each time it runs.
run.tsno stdio optionspawn pipes all three streams by default.
run.tsprocess.kill(-Number(child.pid), 'SIGKILL'), no pid checkA handler that could not start has already finished and cleared the timer, so the kill never runs without a pid.

After review. Cubic found two rewrites that changed behaviour, and both are back as main has them (5db2d0e). parseStream reads line by line, so an error result throws before a later broken line is parsed. respond returns before updatedInput when no prettier is found, so the file an Edit names is never opened; a named-pipe test shows it. CI's first Mutation run left two survivors, run.ts's clearTimeout and page.ts's guard settings, and tests now kill both (1083f37). The second run left two more (4497b65). A test with a stand-in prettier now pins respond printing nothing for an event prettier would not change. parseStream builds its events with one map over the lines, still in order and still throwing an error result before a later line, so it has no array literal whose mutant nobody can see.

The two start() entries differ in one way: a bad argv[1] is now a throw inside start (an unhandled rejection for the async one) rather than at import. The process fails either way.

Equivalent mutants. None listed: each one found was removed by a rewrite above.

Released nothing and bumped no version.

🤖 Generated with Claude Code