✅ test(sarathi): format-before-write.ts, merge.ts and 4 more have no surviving mutant (#491)
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:
| File | Change | Why it is the same |
|---|---|---|
format-before-write.ts | sessionRoot: stdio: 'pipe', and no top !== '' check | git prints a toplevel or fails; it never succeeds with an empty one. Piping stdin too changes nothing, since git reads none. |
format-before-write.ts | loadPrettier 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.ts | uniqueIndex: one test | When 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.ts | minimalEdit: the start scan compares charCodeAt; no old !== '' check; from = lineStart + 1 | charCodeAt 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.ts | return edit && {...} | minimalEdit gives an edit or null, and null is the answer for no edit. |
format-before-write.ts | updatedInput: no filePath === '' check | An empty path has no extension, so inScope refuses it before prettier is asked. |
merge.ts | parseJson: no startsWith('{'); the catch holds a comment, then the function returns undefined | JSON.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.ts | mergeSpecific and mergeJson assign permissionDecisionReason, stopReason, reason, systemMessage and hookSpecificOutput directly | The merged answer's only consumer is JSON.stringify, which drops a field left undefined. |
merge.ts | othersTexts(outcomes) for the non-blockers | othersTexts reads only exit-0 answers, and no blocker exits 0. |
page/guard.ts | transcriptEvents: no blank-line skip; the catch holds only its fail-open note | JSON.parse refuses a blank line, and the catch skips it. |
page/guard.ts | readInput keeps bytes and decodes once at the end | The same UTF-8 text, now with a character split across chunks decoded whole. |
page/guard.ts | isEntry: no script !== ''; an exported start(script, moduleUrl, stdin, run), called once at module level | An 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.ts | opensList: String(kind), no kind === undefined line | "undefined" is in neither list set. |
page/page.ts | a self-closing or void box returns partsIn([]) | It is the same { link: false, silent: false, lists: [] }. |
page/page.ts | stagedFile reads textFile off any other job | Only a reply carries one. |
page/page.ts | run(..., guardScript = GUARD), threaded through runJob and session | The default is the same guard file. A test names a missing one to show the job is refused before any session. |
page/usage-limit.ts | a field(value, key) reader with optional chaining, in place of isObject | A primitive or null has none of the keys read (type, api_error, message, content, result), and an unparsed line leaves event undefined. |
run.ts | no settled flag | finish resolves a promise, which keeps its first answer, and clears the timer each time it runs. |
run.ts | no stdio option | spawn pipes all three streams by default. |
run.ts | process.kill(-Number(child.pid), 'SIGKILL'), no pid check | A 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