🧪 test(kavach): no cosmic-ray survivor left in the guards, config and refusal log
Slice #328 under #238. No cosmic-ray survivor is left in kavach's tool_guard.py, command_guard.py, config.py and refusal_log.py, except the 12 equivalents listed below.
- 49 mutants killed by new tests: the slice's 42 real survivors, the 6 in
refusal_log.log_dirthat need a mocked git, and themkdir(parents=False)the slice listed as equivalent. A log directory whose parent is missing shows that one up. - 55 annotation mutants removed: the six
X | Noneannotations becomeOptional[X], leaving cosmic-ray no|to swap. - 12 equivalents listed, down from 13 because of
mkdir.
No source line moves, so the line numbers in #328 and the proof still match.
The tests
Line numbers are on main.
| Mutants | Test |
|---|---|
isolate, tool_guard.py L26–29 and command_guard.py L73–76 (10) | test_rules.Guards: both guards run through python3 -c with modules planted in the cwd (the guard's own names and json, shlex, dataclasses, subprocess, pathlib), and through -P with the guard's names planted on PYTHONPATH. Each planted module raises as it loads. Each call must allow and print nothing. |
fired swallows a logging error, tool_guard.py L46 and command_guard.py L155 (2) | A copy whose refusal_log.label raises. A refusing rule must still print one BLOCKED line, its own. |
__name__ == "__main__" → >=, tool_guard.py L90 and command_guard.py L240 (2) | test_command_guard.Importing: importing either guard in a child with stdin closed gives (0, "", ""). |
verdict, command_guard.py L86 (0, 3) and L91 >= (2) | A check that exits 2 says nothing more. import z_absent_dependency is named as the check's own failure, whole line asserted. |
lesson_rules, command_guard.py L204 (2) | A refusing lesson rule prints exactly one BLOCKED line. |
answer, command_guard.py L217 and L219 (5) | A stub git_safety prints not json, {"other": 1} and [1, 2]. Each time the guard allows, exit 0, and passes the text through. |
cannot_name_git, command_guard.py L133 and L134 (2) | In a child process: a payload that is not JSON gives False, and ls gives True. |
run's refusal_log message, command_guard.py L234 (1) | The whole BLOCKED line is asserted. |
config.py dataclasses frozen, L33–104 (7) | Assigning a field of each raises FrozenInstanceError. |
config.py L321 and L387 (2) | refusesFrom: 5, and protectedPathsReason: 5 with no paths, are ConfigErrors, not TypeErrors. |
refusal_log.py L30 EXCERPT (2) | An excerpt and a reason are cut at exactly 200 characters. |
refusal_log.py L136 ensure_ascii (1) | A row keeps café as UTF-8, with no \u escape. |
refusal_log.py L183 and L188 guarded (4) | Exits of 0, 1, 3, None and "2", and returns of 0, 1, 3 and "2", write no row. An exit and a return of 2 each write one. |
refusal_log.py L59, L60, L65 log_dir (6) | A mocked subprocess.run: called once with timeout=5 and check=False. Return codes 1, -1 and 128 with a path on stdout give None, and so does an empty stdout. |
refusal_log.py L134 mkdir(parents=True) (1) | log_dir patched to a folder whose parent is missing: the row is still written. |
Each of the 49 was applied by hand and fails a test (the four test modules, failfast).
Equivalents for the Python gate's code-owned list
No test can tell these apart from the code. The gate's slices create the list; this pull request only names them.
| File | Line | Operator | Why no test can kill it |
|---|---|---|---|
tool_guard.py | 42 if mode == "refuse": | Eq_LtE | The only modes are "warn" and "refuse", and "warn" <= "refuse" is false. |
command_guard.py | 149 if mode == "refuse": | Eq_LtE | The same. |
tool_guard.py | 90 if __name__ == "__main__": | Eq_LtE | Imported, the name is tool_guard or kavach.tool_guard, both after "__main__". |
command_guard.py | 240 if __name__ == "__main__": | Eq_LtE | The same. |
command_guard.py | 172 verdict(...) == 2 | Eq_GtE | verdict returns only 0 or 2. |
command_guard.py | 175 verdict(...) == 2 | Eq_GtE | The same. |
command_guard.py | 187 if code == 2: | Eq_GtE | code is verdict's. |
command_guard.py | 91 getattr(error, "name", None) == module | Eq_Is | Equal only because CPython interns both names. |
command_guard.py | 91 getattr(error, "filename", None) == module | Eq_Is | The same. |
command_guard.py | 86 type(end.code) is int | Is_Eq | type(x) == int and type(x) is int agree for every x. |
refusal_log.py | 183 type(end.code) is int | Is_Eq | The same. |
refusal_log.py | 188 type(result) is int | Is_Eq | The same. |
Proof
cosmic-ray 8.9.0 on this branch's tests, every mutant of the four modules, in draft veda-hq/veda#333 (never merges): run 44788243401, all four jobs green.
| Module | Mutants | Killed | Survived, all on the list | Timed out |
|---|---|---|---|---|
tool_guard.py | 125 | 123 | 2 | 0 |
command_guard.py | 278 | 270 | 8 | 0 |
config.py | 129 | 129 | 0 | 0 |
refusal_log.py | 118 | 116 | 2 | 0 |
Each job also fails on a listed equivalent that is killed, and on a | mutant left on a rewritten annotation line; neither happened. Each mutant ran its module's main killing test files first, then the whole suite, both failfast. The first run, 44747469132, is not evidence: with every core busy the suite outran cosmic-ray's 600 s timeout, and cosmic-ray scores a timeout as a kill.
Also
Optionalgoes on each module's existingtypingimport line. kavach has no Python lint or version floor that prefersX | None.- For Alok: the first hand run of the
guardedmutants wrote a few stray rows to the main checkout's.git/kavach/refusals.jsonl. My first version of the test gaveguardedno event, so under a mutant the row went to the test process's own repository. The rows look likeBLOCKED: 0,BLOCKED: 1,BLOCKED: 3andBLOCKED: None. kavach keeps me out of that folder, so I couldn't remove them. The test now passes the fixture's event.
Slice: #328
🤖 Generated with Claude Code
Summary by cubic
Kills every surviving cosmic-ray mutant in command_guard.py, tool_guard.py, config.py, and refusal_log.py: 49 mutants now die under new tests, and 12 are confirmed equivalent with no test able to kill them.
Tests
- Both guards: planted modules in the cwd or on
PYTHONPATHcannot stand in for the guard's own modules, a raisingrefusal_log.labelleaves a refusing rule's ownBLOCKEDline, importing a guard runs nothing, and checks that exit 2 or print non-answer output pass through as written. config.py: every dataclass is frozen, and non-stringrefusesFromandprotectedPathsReasonvalues areConfigErrors, notTypeErrors.refusal_log.py: excerpts cut at 200 characters, rows keep UTF-8, the log folder is made with its parents, git is called once withtimeout=5, and only an exit or return of 2 writes a row.
Refactor
- The six
X | Noneannotations becomeOptional[X], so cosmic-ray has no|to swap. No source line moves, so the line numbers in slice #328 still match.