✅ test(kavach): bash_guard.py lines 458–669 have no cosmic-ray survivor

Merged
AT
2d ago
+321-52

Slice 42 of the mutation sweep (#466): cosmic-ray 8.9.0 leaves no survivor on bash_guard.py's lines that were 458–669 at 9b535c2, and none is listed as an equivalent.

Measured first

On main, bash_guard.py changed since 9b535c2 only by #755 (#507, which kept every line in place). Measured on #507's branch, which #755 has since merged: 492 mutants, 300 killed, 137 survived, 23 on lines no test ran (Branches.blend's variable loop, in_pipeline's pipe before the command, the depth counters' ) paths), and 32 timed out. Most timeouts were index loops that a mutant stops in place. The rest were module-level set unions, whose mutants run every test module that imports the guard.

On this branch, the same code is lines 458–666: 284 mutants, all killed. No survivor, timeout, capped run or uncovered line. Proof on Linux, with the gate's caps: draft veda-hq/veda#756 (never merges), run 46377602462.

Tests

In tests/test_bash_guard.py, the walker's helpers and Branches are called directly. Each is called in a child that loads bash_guard.py as the guard does and runs a snippet in its globals, on literal token lists.

  • command_head, at_command_start, assignment_only, is_argument (wrappers such as time, ! and builtin start no command of their own), in_pipeline (a pipe before the command, after it, and a pipe in a later command that does not count), runs_conditionally, list_end, first_or and background_end (nested and unbalanced parentheses, the end bound, a later & past a terminator), and where command_env's scan starts.
  • Branches:
    • note, restart, blend and after, each on an entry holding a directory, a stack and three variables. note and blend see an unchanged state and each kind of change: the directory, an unresolved one, a shorter and a longer stack, and variables added, changed and removed.
    • The unchanged values are equal objects built at run time, so is cannot stand in for ==.

Rewrites that keep behaviour

  • Loops. command_head, assignment_only, is_argument, in_pipeline, runs_conditionally, list_end, first_or and background_end walk with for over a range, next(...), itertools.dropwhile or itertools.takewhile, not a while with a hand-moved index. Each returns what it did, and no mutant can stall one.
  • Sets. TRACKED_ENV, COMMAND_LEADERS and LIST_ENDS are built with * unpacking instead of | of disjoint sets, where ^ gave the same set. WORD_STARTS is a comprehension over COMMAND_LEADERS, which already holds if, while and until.
  • Depth. The three depth counters read not depth for depth == 0. The depth never goes below 0 there, so <= gave the same answer.
  • command_env's start is i less the words since the last command leader, counted with takewhile. The old leaders[-1] + 1 also worked as + 0, since the leader token itself is never an assignment or env.
  • bash_guard.py imports itertools.

Lines move here: the slice's code is now lines 458–666, and what follows sits four lines earlier (9b535c2's line 671 is now 667). #509 to #512 map their ranges by the text at their ends.

Where each line is judged

The CI gate (kavach Python mutation) judges the rewritten lines.

Built on main after #755 (#507) merged.

Cubic's review allowance is used up until 9 December 2026, so its check reports neutral; Alok said to keep merging sweep pull requests without it until then.

Slice: #508

🤖 Generated with Claude Code


Summary by cubic

Rewrites the command-walker helpers and Branches in bash_guard.py so the mutation sweep finds no survivors there, and adds direct tests for them.

  • Index loops (command_head, assignment_only, is_argument, in_pipeline, runs_conditionally, list_end, first_or, background_end, command_env's start) are now for loops or iterator functions, so no mutant can stall them.
  • TRACKED_ENV, COMMAND_LEADERS, and LIST_ENDS use unpacking instead of disjoint set unions; WORD_STARTS is a comprehension over COMMAND_LEADERS.
  • New tests call each helper and Branches directly on literal token lists in a child that loads the module as the guard does.