āœ… test(sarathi): cli.ts passes its mutation lane, and the version moves to version.ts

Merged
AT
6d ago
+259-49

Brings sarathi's src/cli.ts to zero blocking mutants and moves the version out of it, so sarathi can release again.

Why

veda's mutation gate judges a changed file whole, and every sarathi release changed VERSION in src/cli.ts. The 0.8.6 release for https://github.com/veda-hq/veda/issues/428 is the first since the gate came in, and its push was refused: 403 mutants, 96 blocking (65 survived, 31 with no coverage), none on a line it changed.

What changes

  • src/version.ts holds VERSION, with its own suite (version.test.ts) holding it equal to package.json. A release edits that file and package.json, never cli.ts. cli.ts still re-exports VERSION, because the package has no exports map and dist/cli.js can be imported.
  • cli.test.ts drives main through a fake Io for:
    • every routed command: worktree hook, pick (--shell, a bad word, the stdin fallback and a given ask), cleanup, the lifecycle, services and autofix add/list (with the row's time);
    • a --config other than the project's list, and $CLAUDE_PROJECT_DIR set, empty and unset;
    • each forbidEnv answer in full, and the exact usage errors;
    • settings matchers that are empty, *, leave out more than one tool, or end in |.
  • settingsHooks is exported and tested on its own.

Behaviour changes, so a reviewer can check them

  • hook always calls io.out and io.err, with an empty string when there is nothing to say. The bin writes that empty string to stdout and stderr, which prints nothing. The dropped early return (entries.length === 0 && forbidden === undefined) merged to the same answer: merge(event, []) is { code: 0, stdout: '', stderr: '' }.
  • check's catch prints the error's .message. Everything in that try throws only ConfigError (loadConfig, parseConfig) or SettingsError (parseSettings). The old String(error) branch could not be reached.
  • parseOptions reads an option's value off one iterator, and returns config and settings as they are, undefined included. projectRoot is $CLAUDE_PROJECT_DIR || cwd, the same as undefined or '' falling back to cwd before.
  • settingsHooks skips an event or group whose value is not a list before looping, where it used to loop over an empty array. The result is the same, and the new test pins it.
  • The hook command's JSON catch has a plain comment, not // fail-open:. It is one of the five swallowed catches eslint-suppressions.json already allows in cli.ts. Marking it fail-open: would leave the suppression count stale, and pruning it means editing that code-owned file. Alok can prune it to 4 in a later change if he wants.

The lane

Before, on main's cli.ts (pre-push): sarathi: 307 killed of 403 in 1 file(s) (31 NoCoverage, 304 Killed, 3 Timeout, 65 Survived; 3 timeout(s) retried) - 96 blocking.

After, run by hand as pnpm exec agnipariksha --lane sarathi --files packages/sarathi/src/cli.ts,packages/sarathi/src/version.ts --no-reuse:

sarathi: 357 killed of 357 in 2 file(s) (357 Killed; 0 timeout(s) retried) - pass
agnipariksha total: 357 killed of 357 in 1 lane(s), 0 blocking, 0 refused - exit 0

pnpm --dir packages/sarathi check (1052 tests) and pnpm lint are green. No gate setting, hook or code-owned file changes.

Next

The fix branch for #428 is rebased on this one, moves version.ts to 0.8.6 and releases it. That push passing the gate is the rest of this slice's done-when, so this PR does not close it.

Slice: #431

šŸ¤– Generated with Claude Code


Summary by cubic

Fixes sarathi releases being refused by veda's mutation gate, which judges every changed file whole: a release edited VERSION in cli.ts, where 96 mutants blocked. This moves VERSION to src/version.ts and fully tests cli.ts, so its lane passes with 357 killed of 357.

  • Releases now edit version.ts and package.json; cli.ts re-exports VERSION for code importing dist/cli.js.
  • cli.test.ts drives main through a fake Io covering every routed command, --config overrides, $CLAUDE_PROJECT_DIR set/empty/unset, all forbidEnv answers, and settings matcher edge cases.
  • settingsHooks is exported and tested on its own.

Behavior changes

  • hook now always writes stdout and stderr, even empty strings; callers print nothing.
  • check's catch reports error.message; only ConfigError or SettingsError can reach it, so the old String(error) branch was unreachable.