8. Mutation Testing
codeknife mutate makes small, deliberate changes (“mutants”) to your source code, such as flipping >= to > or deleting an early-return guard. It runs your test command against each mutant. If the tests still pass, the mutant “survived”: no test notices that behaviour change. Use it on the functions you changed or on your riskiest functions to find tests that execute code without checking its results.
Mutants are applied only to copies of your repository. Your working tree is never edited. By default CodeKnife mutates only the 10 functions with the highest CRAP score, not the whole repository.
Quick example
Section titled “Quick example”The demo crate has three functions and one test each. The tests never check the boundary values.
pub fn is_adult(age: u32) -> bool { age >= 18}
pub fn shipping(total: u32, member: bool) -> u32 { if member { return 0; } if total > 100 && total < 1000 { 5 } else { 10 }}
pub fn add(a: i64, b: i64) -> i64 { a + b}
#[cfg(test)]mod tests { use super::*;
#[test] fn adult_checks() { assert!(is_adult(30)); assert!(!is_adult(5)); }
#[test] fn shipping_checks() { assert_eq!(shipping(50, true), 0); assert_eq!(shipping(500, false), 5); }
#[test] fn add_checks() { assert_eq!(add(2, 3), 5); }}List the mutants first
Section titled “List the mutants first”--scan lists the mutation sites without running anything:
codeknife mutate --scan --format agentCODEKNIFE mutate status=pass files=1 errors=0 warnings=0 infos=7 elapsed_ms=2[1] INFO CK_MUTATE_SITE src/lib.rs:2-2 sym=mutdemo::is_adult impact=10 | candidate mutant: flip operator `>=` -> `>` | fix: Run `codeknife mutate` without `--scan` to test whether tests kill this mutant.[2] INFO CK_MUTATE_SITE src/lib.rs:6-6 sym=mutdemo::shipping impact=10 | candidate mutant: delete early-return guard clause | fix: Run `codeknife mutate` without `--scan` to test whether tests kill this mutant.[3] INFO CK_MUTATE_SITE src/lib.rs:7-7 sym=mutdemo::shipping impact=10 | candidate mutant: replace return value with default/empty value | fix: Run `codeknife mutate` without `--scan` to test whether tests kill this mutant.[4] INFO CK_MUTATE_SITE src/lib.rs:9-9 sym=mutdemo::shipping impact=10 | candidate mutant: flip operator `&&` -> `||` | fix: Run `codeknife mutate` without `--scan` to test whether tests kill this mutant.[5] INFO CK_MUTATE_SITE src/lib.rs:9-9 sym=mutdemo::shipping impact=10 | candidate mutant: flip operator `<` -> `<=` | fix: Run `codeknife mutate` without `--scan` to test whether tests kill this mutant.[6] INFO CK_MUTATE_SITE src/lib.rs:9-9 sym=mutdemo::shipping impact=10 | candidate mutant: flip operator `>` -> `>=` | fix: Run `codeknife mutate` without `--scan` to test whether tests kill this mutant.[7] INFO CK_MUTATE_SITE src/lib.rs:17-17 sym=mutdemo::add impact=10 | candidate mutant: flip operator `+` -> `-` | fix: Run `codeknife mutate` without `--scan` to test whether tests kill this mutant.NOTE scan: 7 covered candidate mutation sites (0 uncovered skipped)All CK_MUTATE_SITE findings are info, so --scan exits with 0. It does not need a test command. The note says “covered” even when no coverage report is loaded. In that case every site counts as covered.
Run the campaign
Section titled “Run the campaign”codeknife mutate --format humanerror[CK_MUTATE_SURVIVOR]: mutant survived in `mutdemo::shipping`: replace return value with default/empty value --> src/lib.rs:7 (mutdemo::shipping) = fix: Add a test verifying behavior around `return 0` -> `return Default::default();` so this mutant fails tests.
error[CK_MUTATE_SURVIVOR]: mutant survived in `mutdemo::is_adult`: flip operator `>=` -> `>` --> src/lib.rs:2 (mutdemo::is_adult) = fix: Add a test verifying behavior around `>=` -> `>` so this mutant fails tests.
error[CK_MUTATE_SURVIVOR]: mutant survived in `mutdemo::shipping`: flip operator `&&` -> `||` --> src/lib.rs:9 (mutdemo::shipping) = fix: Add a test verifying behavior around `&&` -> `||` so this mutant fails tests.
error[CK_MUTATE_SURVIVOR]: mutant survived in `mutdemo::shipping`: flip operator `>` -> `>=` --> src/lib.rs:9 (mutdemo::shipping) = fix: Add a test verifying behavior around `>` -> `>=` so this mutant fails tests.
error[CK_MUTATE_SURVIVOR]: mutant survived in `mutdemo::shipping`: flip operator `<` -> `<=` --> src/lib.rs:9 (mutdemo::shipping) = fix: Add a test verifying behavior around `<` -> `<=` so this mutant fails tests.
note: mutation score: 28.6% (2 killed, 0 cached, 5 survived, 0 unviable, 0 uncovered skipped); schemata: 5 mutant(s) compiled once; blast-filtered tests: 7/7codeknife mutate: FAIL (1 files, 5 errors, 0 warnings, 0 info, 821ms)The exit code is 1. Two mutants were killed: add(2, 3) no longer returns 5 when + becomes -, and shipping(50, true) no longer returns 0 without its guard. The five survivors point at the missing tests: nobody calls is_adult(18), shipping(100, false) or shipping(1000, false), and Default::default() for u32 is 0, so that mutant behaves exactly like the original.
Run it again and the two killed mutants come from the cache:
NOTE mutation score: 28.6% (0 killed, 2 cached, 5 survived, 0 unviable, 0 uncovered skipped); schemata: 4 mutant(s) compiled once; blast-filtered tests: 5/5Choosing which functions to mutate
Section titled “Choosing which functions to mutate”CodeKnife first ranks every function and method that is not a test and not in a test file by CRAP: CC² × (1 − coverage)³ + CC. Coverage comes from the coverage report (see below). Without a report every function has 0% coverage, so the ranking is by complexity alone. Then it picks targets:
| You pass | Functions mutated |
|---|---|
neither --changed nor --top |
the top [mutate] top_crap functions by CRAP (default 10) across the repository |
--top N |
the top N functions by CRAP across the repository |
--changed |
every function in the changed files, with no limit |
--changed --top N |
the top N functions by CRAP among the functions in changed files |
--changed selects whole files from the git diff, not just the edited functions. In this run only half was edited, but both functions in src/extra.rs were selected:
codeknife mutate --scan --changed --no-cache --format agentCODEKNIFE mutate status=pass files=2 errors=0 warnings=0 infos=6 elapsed_ms=4[1] INFO CK_MUTATE_SITE src/extra.rs:2-2 sym=mutdemo::extra::clamp_pct impact=10 | candidate mutant: delete early-return guard clause | fix: Run `codeknife mutate` without `--scan` to test whether tests kill this mutant....[5] INFO CK_MUTATE_SITE src/extra.rs:9-9 sym=mutdemo::extra::half impact=10 | candidate mutant: flip operator `+` -> `-` | fix: Run `codeknife mutate` without `--scan` to test whether tests kill this mutant.[6] INFO CK_MUTATE_SITE src/extra.rs:9-9 sym=mutdemo::extra::half impact=10 | candidate mutant: flip operator `/` -> `*` | fix: Run `codeknife mutate` without `--scan` to test whether tests kill this mutant.NOTE scan: 6 covered candidate mutation sites (0 uncovered skipped)Adding --top 1 keeps only clamp_pct, the changed function with the higher CRAP score:
CODEKNIFE mutate status=pass files=2 errors=0 warnings=0 infos=4 elapsed_ms=3...NOTE scan: 4 covered candidate mutation sites (0 uncovered skipped)With --changed and a clean working tree there is nothing to mutate. --since <ref> sets the diff base for --changed and does nothing on its own. See Paths, Excludes & Changed Scope for how the changed-file set is built.
Files excluded by your exclude patterns are not in the code model and are never mutated.
Coverage gating
Section titled “Coverage gating”If a coverage report is available, CodeKnife skips mutation sites on lines the report marks as not executed. Those mutants cannot be killed, so running them would only waste time. They are counted as “uncovered skipped”.
The report is found the same way as for codeknife tests: --coverage <path> if given, otherwise the first existing file from [coverage] paths and the standard locations such as lcov.info. The formats are listed on Coverage Reports.
cargo llvm-cov --lcov --output-path ../covdemo/mutdemo.lcovcodeknife mutate --scan --no-cache --format agent | tail -2codeknife mutate --scan --no-cache --coverage ../covdemo/mutdemo.lcov --format agent | tail -2NOTE scan: 15 covered candidate mutation sites (0 uncovered skipped)
NOTE scan: 12 covered candidate mutation sites (3 uncovered skipped)The three skipped sites are the operators in in_band, a function no test calls.
The rules for a site:
- If the report has no entry for the site’s file, the site is kept.
- If the report has an entry for the file, the site is kept only when the report shows a hit count above zero for the site’s line. A line the report does not list counts as not covered.
Coverage also changes the CRAP ranking, so --top can pick different functions with and without a report.
Mutation operators
Section titled “Mutation operators”Every language uses the same extractor, but each grammar names its syntax nodes differently, so the operators that apply differ.
| Operator | What changes | Rust | TS / JS | Python | Go |
|---|---|---|---|---|---|
| Boundary flip | < to <=, <= to <, > to >=, >= to > |
yes | yes | yes | yes |
| Equality flip | == to != and back; === to !== and back |
yes | yes | yes (==, !=) |
yes |
| Logic flip | && to || and back; and to or and back |
yes | yes | yes (and, or) |
yes |
| Arithmetic flip | + to -, - to +, * to /, / to * |
yes | yes | no | yes |
| Bool literal flip | true and false swapped; True and False in Python |
yes | yes | yes | yes |
| Return default | replace a return statement with a default value |
yes | yes | yes | no |
| Delete guard | remove a short if that returns early |
yes | yes | yes | yes |
Details and limits:
- Binary operators are taken from
binary_expressionnodes (Rust, TypeScript, JavaScript, Go) andcomparison_operatorandboolean_operatornodes (Python). Python arithmetic uses a different node type, soa * bin Python is never mutated. A+whose expression text contains",'or`is skipped, to avoid mutating string concatenation. - Return default replaces the whole
returnstatement. Implicit Rust tail expressions (a function ending inage >= 18with noreturn) are not mutated by this operator. Returns that are already trivial (return,return;,return (),return None,return false,return False, or anything containingDefault::default()) are skipped. The replacement is:
| Language | Return contains true, false, True or False |
Otherwise |
|---|---|---|
| Rust | return false; |
return Default::default(); |
| TypeScript | return false; |
return null as any; |
| JavaScript | return false; |
return null; |
| Python | return False |
return None |
| Go | not mutated | not mutated |
- Delete guard applies to an
ifstatement of at most 4 lines whose text containsreturnorreturn;and does not containelseanywhere. Python replaces it withpass; other languages replace it with/* mutant: guard removed */ {}. - Only code inside non-test functions and methods is mutated.
The per-language metric definitions, including cyclomatic complexity, are on How Metrics Are Computed.
Execution strategies
Section titled “Execution strategies”Every mutant runs in one of two ways. Both work on copies, never on your files.
Compile-once schemata
Section titled “Compile-once schemata”A schema puts several mutants into one copy of the code at once, each guarded by an environment variable. For example, a Rust site becomes:
(if ::std::env::var("CK_MUT").as_deref() == Ok("M3") { age > 18 } else { age >= 18 })TypeScript and JavaScript check process.env.CK_MUT, and Python checks os.environ through __import__("os"). The copy is built once and the test command runs once per mutant with CK_MUT set to that mutant’s ID.
A mutant can join a schema only when:
- it is a binary operator or bool literal mutant (return and guard mutants never are),
- the file is not Go,
- the brackets in the wrapped expression are balanced.
CodeKnife groups these mutants into waves. Mutants whose expressions overlap (for example total > 100 inside total > 100 && total < 1000) go into different waves. For each wave with at least two mutants, CodeKnife:
- Makes one worker copy of the repository and writes all of the wave’s wrapped expressions into it.
- Runs the test command once with
CK_MUT=0. If this baseline does not pass, for example because the wrapper does not compile inside a Rustconst fn, the whole wave falls back to isolated workers. - Runs the test command once per mutant with
CK_MUT=<id>. For commands whose program iscargo,CARGO_TARGET_DIRpoints at atargetdirectory inside the copy, so the code compiles once per wave. That directory starts empty and is deleted with the copy.
Mutants in a wave run one after another if any of their commands starts with cargo , or if --jobs is 1. Otherwise up to --jobs of them run in parallel in the same copy.
Waves with a single mutant use isolated workers instead. The note’s “schemata: N mutant(s) compiled once” counts mutants in waves whose baseline passed.
Isolated copy-on-write workers
Section titled “Isolated copy-on-write workers”Every other mutant, and every mutant when you pass --no-schemata, gets its own worker:
- CodeKnife creates a directory and copies each top-level entry of the repository into it, except
.git,.codeknife,target,dist,build,.next,__pycache__,.pytest_cacheand.mypy_cache. On Linux it usescp -R --reflink=auto; on macOS it usescp -cR. Ifcpfails it copies the files itself.node_modules,.venvandvenvare symlinked instead of copied on Unix. - It applies the single mutation to the copy.
- It runs the test command in the copy. For commands whose program is
cargo,CARGO_TARGET_DIRis set: to your repository’s owntarget/when only one worker runs, otherwise to.codeknife/workers/cargo_target_<n>. - It deletes the copy.
Up to --jobs isolated workers run in parallel. On the demo crate the outcomes were the same with and without schemata:
codeknife mutate --no-schemata --mutate-all --format agent | tail -2NOTE mutation score: 28.6% (2 killed, 0 cached, 5 survived, 0 unviable, 0 uncovered skipped); schemata: 0 mutant(s) compiled once; blast-filtered tests: 7/7Because target, dist and build are never copied, a project whose source or test inputs live in one of those top-level directories will not find them in the worker copy.
The test command
Section titled “The test command”Which command runs
Section titled “Which command runs”CodeKnife picks the command in this order:
--test-command.- With
--changed(and a non-empty diff), the command from Smart Test Selection, if its plan for the changed files has exactly one command. [mutate] test_commandfromcodeknife.toml.- A default for the language with the most files in the repository (ties go to the later language in the order Rust, TypeScript, JavaScript, Python, Go):
| Language | Default command |
|---|---|
| Rust | cargo test |
| TypeScript, JavaScript | npx vitest run if package.json at the root mentions vitest, else npx jest if it mentions jest, else npm test. With no root package.json there is no default. |
| Python | pytest -q |
| Go | go test ./... |
If no command is found, the run fails with this error:
codeknife error: no test command discovered; pass `--test-command` or configure `[mutate]` in codeknife.tomlcodeknife check --tier full never passes a command, so it uses step 3 or step 4.
How the command is run
Section titled “How the command is run”The command is not run through a shell. CodeKnife splits it on whitespace, honours single and double quotes (and removes them), and treats leading NAME=value words as environment variables. &&, pipes, redirects and globs are passed to the program as plain arguments. --test-command "cargo test && echo hi" failed its baseline for that reason. Wrap complex commands in a script.
Up to 64 KiB of the command’s standard output and of its standard error is read. CodeKnife closes the pipe after that.
Per-mutant test scoping
Section titled “Per-mutant test scoping”Before running, CodeKnife narrows the command for each mutant to the tests that can reach the mutated function. It asks the Blast Radius engine for the tests in the function’s caller cone. If there are none, it falls back to the tests in the mutated file and the tests in test files that import the function’s module. It then rewrites the command:
| Base command | Narrowing (skipped if the condition fails) |
|---|---|
starts with cargo test and has no -- |
adds -p <package> when all covering tests are in one Cargo package and the command has no -p ; appends -- <names> when there are 1 to 12 test names |
starts with pytest and has no .py argument |
appends the covering test files |
python -m unittest or python3 -m unittest with no target |
appends the covering test modules as dotted names |
starts with go test and has no -run |
with 1 to 12 test names starting with Test: replaces ./... with the test directories (or appends them) and adds -run '^(TestA|TestB)$' |
contains vitest or jest and has no .ts or .js argument |
appends the covering test files |
anything else, including npm test |
unchanged |
If no covering test is found, the base command runs unchanged. The note’s “blast-filtered tests: X/Y” counts the executed mutants whose command was narrowed.
Timeouts
Section titled “Timeouts”Before mutating, CodeKnife runs the chosen command once in your repository root as a baseline. The baseline must exit 0 within 120 seconds, or the run stops with exit code 2:
codeknife error: baseline tests failed (`false`); fix baseline tests before running `codeknife mutate`A test suite that takes longer than 120 seconds cannot be mutation-tested.
Each mutant’s timeout is the baseline time in whole seconds (rounded down) times [mutate] timeout_multiplier, but at least [mutate] min_timeout_secs. With the defaults (3 and 5), any baseline under 2 seconds gives a 5-second timeout. A mutant that runs past its timeout is killed and recorded as timeout.
Parallelism
Section titled “Parallelism”--jobs sets the maximum number of parallel workers. It defaults to [mutate] max_jobs, which defaults to 4. The thread pool is never larger than the number of mutants. Cargo-based schema waves always run one mutant at a time.
Outcomes and score
Section titled “Outcomes and score”| Outcome | When | In the score |
|---|---|---|
killed |
The test command exits non-zero and its output has no compile-error marker. | killed |
timeout |
The command runs past the timeout and is killed. | counted as killed |
unviable |
The command exits non-zero and its output contains error[E, could not compile, error TS, SyntaxError, IndentationError, [build failed], cannot use or undefined: . |
left out |
survived |
The command exits 0. |
survived |
The score is:
score = (killed + cached) / (killed + cached + survived) × 100killed includes timeouts. cached is the number of mutants skipped because the cache recorded them as killed. Unviable mutants and uncovered sites are not counted. With nothing in the denominator the score is 100%. In this Python run the > to >= mutant turned while x > 0 into an endless loop, hit the 5-second timeout, and counted as killed:
CODEKNIFE mutate status=pass files=2 errors=0 warnings=0 infos=0 elapsed_ms=5084NOTE mutation score: 100.0% (2 killed, 0 cached, 0 survived, 0 unviable, 0 uncovered skipped); schemata: 0 mutant(s) compiled once; blast-filtered tests: 2/2The score is a note only. There is no threshold on it; the run fails because of CK_MUTATE_SURVIVOR errors.
| Rule ID | Severity | Triggers when | Threshold or key | --strict |
Fixer |
|---|---|---|---|---|---|
CK_MUTATE_SITE |
info | --scan: one finding per candidate mutant that would run. Impact 10. |
none | unchanged | none |
CK_MUTATE_SURVIVOR |
error | A mutant’s test run exits 0 (or cannot be run, see above). Impact 85. |
none | unchanged | none |
Each survivor’s fix hint names the original and replacement text, for example Add a test verifying behavior around `>=` -> `>` so this mutant fails tests. No rule here has an automatic fixer; see the Autofix Engine. The full rule list is in the Rule Catalogue. Survivors are filtered by the baseline like any other finding.
In JSON output a survivor looks like this:
{ "id": "ba694cd659dcb3ea", "rule": "CK_MUTATE_SURVIVOR", "blade": "mutate", "severity": "error", "location": { "file": "pricing.py", "start_line": 6, "end_line": 6, "symbol": "pricing.discount" }, "message": "mutant survived in `pricing.discount`: delete early-return guard clause", "fix_hint": "Add a test verifying behavior around `if total <= 0:\n return 0` -> `pass` so this mutant fails tests.", "impact_score": 85.0}The mutation cache
Section titled “The mutation cache”Results are stored in .codeknife/mutate-cache.json. Each mutant’s key is a hash of its file, function, line, original text and replacement. Each entry stores the function name, a SHA-256 hash of the function body and the outcome.
On the next run, a mutant is skipped and counted as cached only if its cached outcome is killed and the function body hash is unchanged. Survivors, timeouts and unviable mutants always run again. Editing a function re-runs all of its mutants.
| Flag | Cache behaviour |
|---|---|
| default | load the cache, skip cached kills, save all new results |
--mutate-all |
load the cache but skip nothing; save all new results |
--no-cache |
neither load nor save the cache; put workers in the system temp directory |
Entries are added or overwritten, never removed. An unreadable or corrupt cache file is treated as empty.
Configuration
Section titled “Configuration”All keys live under [mutate] in codeknife.toml:
| Key | Default | Effect |
|---|---|---|
test_command |
none | Test command, used when --test-command is not given (see the caution about --changed above). |
timeout_multiplier |
3 |
Mutant timeout is baseline seconds times this. |
min_timeout_secs |
5 |
Lower bound for the mutant timeout, in seconds. |
max_jobs |
4 |
Default for --jobs. |
top_crap |
10 |
Number of top-CRAP functions mutated when --top is not given. Also used by check --tier full. |
[mutate]test_command = "python3 -m unittest -q"max_jobs = 2Coverage paths come from [coverage] paths; see Coverage Reports. There is no [blades] toggle for mutation. It runs only when you call codeknife mutate or codeknife check --tier full.
| Flag | Default | Effect |
|---|---|---|
--scan |
off | List candidate sites as CK_MUTATE_SITE and stop. No tests run. |
--top <N> |
[mutate] top_crap |
Mutate the N highest-CRAP functions (among changed files when --changed is set). |
--test-command <cmd> |
inferred | Test command for the baseline and every mutant. |
--coverage <path> |
auto-discovered | Coverage report used for gating and CRAP ranking. Relative to the current directory. |
--jobs <N> |
[mutate] max_jobs |
Maximum parallel workers. |
--mutate-all |
off | Re-run mutants the cache records as killed. |
--no-schemata |
off | Use isolated workers for every mutant. |
--changed, --since <ref> |
off | Mutate functions in changed files. |
--no-cache |
off | Skip the mutation cache and the other .codeknife/ files; workers go to the temp directory. |
--strict |
off | Has no effect on this blade’s rules. |
--path, --format, --max-items |
Global flags. See the CLI Reference. |
What it writes to disk
Section titled “What it writes to disk”| Path | When | Removed afterwards |
|---|---|---|
Worker copies in .codeknife/workers/w_<n>_<pid>/ |
each isolated mutant and each schema wave | yes, when the mutant or wave finishes |
.codeknife/workers/cargo_target_<n>/ |
Cargo commands with more than one isolated worker | no; kept for the next run |
Your repository’s target/ |
Cargo commands with one isolated worker, and the baseline run | no |
.codeknife/mutate-cache.json |
end of every run without --no-cache |
no |
.codeknife/parse-cache.json |
every run without --no-cache (code model cache) |
no |
<temp dir>/codeknife-mutate-workers-<pid>/ |
instead of .codeknife/workers/ with --no-cache |
worker copies yes; cargo_target_<n> directories no |
The baseline runs in your repository root, so anything your test command writes there (build output, __pycache__) appears as usual. See The .codeknife Directory for the other cache files.
Interruption
Section titled “Interruption”Mutations are written only into worker copies, so your source files stay unchanged even if the run is killed. CodeKnife installs no signal handler, though. After sending SIGTERM to a run in progress, git status was clean, but the four in-flight worker copies stayed in .codeknife/workers/ with their mutated sources, and mutate-cache.json was not written, so results from that run were lost. Delete .codeknife/workers/ after an interrupted run.
check --tier full
Section titled “check --tier full”codeknife check --tier full runs a mutation campaign after the static checks and adds its survivors and score note to the check report. It uses [mutate] top_crap as the limit, even together with --changed, so it mutates at most that many functions. It always uses schemata, the configured job count, the cache (unless --no-cache) and the configured or inferred test command. --coverage on check is passed through for gating. If the baseline fails, the whole check fails with exit code 2. See The Check Gate.
codeknife check --tier full --no-cache --format agentCODEKNIFE check status=fail files=2 errors=11 warnings=0 infos=0 elapsed_ms=3435[1] ERROR CK_MUTATE_SURVIVOR src/extra.rs:2-2 sym=mutdemo::extra::clamp_pct impact=85 | mutant survived in `mutdemo::extra::clamp_pct`: flip operator `<` -> `<=` | fix: Add a test verifying behavior around `<` -> `<=` so this mutant fails tests....NOTE no coverage file found (running complexity-only mode); generate one with: cargo llvm-cov --lcov --output-path lcov.infoNOTE analyzed 3 commit(s) over the last 90 day(s)NOTE mutation score: 26.7% (4 killed, 0 cached, 11 survived, 0 unviable, 0 uncovered skipped); schemata: 11 mutant(s) compiled once; blast-filtered tests: 15/15NOTE --no-cache skipped default .codeknife/map.html writeOther ecosystems
Section titled “Other ecosystems”Python
Section titled “Python”Python is mutated with schemata too. This repository has no pytest installed, so the default pytest -q fails and the command must be given:
codeknife mutate --no-cache --format agentcodeknife error: spawning test command `pytest -q`: No such file or directory (os error 2)codeknife mutate --no-cache --test-command "python3 -m unittest -q" --format agentCODEKNIFE mutate status=fail files=2 errors=6 warnings=0 infos=0 elapsed_ms=318[1] ERROR CK_MUTATE_SURVIVOR pricing.py:2-2 sym=pricing.is_adult impact=85 | mutant survived in `pricing.is_adult`: flip operator `>=` -> `>` | fix: Add a test verifying behavior around `>=` -> `>` so this mutant fails tests.[2] ERROR CK_MUTATE_SURVIVOR pricing.py:6-6 sym=pricing.discount impact=85 | mutant survived in `pricing.discount`: delete early-return guard clause | fix: Add a test verifying behavior around `if total <= 0: return 0` -> `pass` so this mutant fails tests....NOTE mutation score: 40.0% (4 killed, 0 cached, 6 survived, 0 unviable, 0 uncovered skipped); schemata: 3 mutant(s) compiled once; blast-filtered tests: 10/10JavaScript
Section titled “JavaScript”With a root package.json whose test script is node --test, CodeKnife falls back to npm test. npm test cannot be narrowed, so no test runs were blast-filtered:
codeknife mutate --no-cache --format agentCODEKNIFE mutate status=fail files=2 errors=2 warnings=0 infos=0 elapsed_ms=4434[1] ERROR CK_MUTATE_SURVIVOR calc.js:2-2 sym=calc/isAdult impact=85 | mutant survived in `calc/isAdult`: flip operator `>=` -> `>` | fix: Add a test verifying behavior around `>=` -> `>` so this mutant fails tests.[2] ERROR CK_MUTATE_SURVIVOR calc.js:9-9 sym=calc/fee impact=85 | mutant survived in `calc/fee`: flip operator `>` -> `>=` | fix: Add a test verifying behavior around `>` -> `>=` so this mutant fails tests.NOTE mutation score: 71.4% (5 killed, 0 cached, 2 survived, 0 unviable, 0 uncovered skipped); schemata: 3 mutant(s) compiled once; blast-filtered tests: 0/7Go mutants always use isolated workers, and Go never gets return-default mutants. A full Go campaign was not run for this page.
Errors and exit codes
Section titled “Errors and exit codes”| Exit code | When |
|---|---|
0 |
No survivors (including every --scan run). |
1 |
At least one CK_MUTATE_SURVIVOR that the baseline does not suppress. |
2 |
The run could not start: the baseline failed, the test command is empty or cannot be started, no test command was found, or the --coverage file cannot be read. The messages are shown below. |
codeknife mutate --no-cache --test-command false --format agentcodeknife mutate --no-cache --test-command "" --format agentcodeknife mutate --no-cache --path nopkg --format agentcodeknife error: baseline tests failed (`false`); fix baseline tests before running `codeknife mutate`codeknife error: empty test commandcodeknife error: no test command discovered; pass `--test-command` or configure `[mutate]` in codeknife.tomlThe last command ran on a directory with one TypeScript file and no package.json.
Also available via
Section titled “Also available via”codeknife check --tier full(see above).- There is no MCP tool for mutation testing. See MCP Tools.