Mutate the Go lines a branch changes with Gremlins in mutate-changes
CI / tests (pull_request) Successful in 3m54s

This commit is contained in:
2026-11-20 23:24:21 +01:00
parent 1de88b9b20
commit a430bca9f9
6 changed files with 118 additions and 9 deletions
+12 -2
View File
@@ -16,6 +16,8 @@ or __tests__/ folder.
in its own process, so a mutant that only a child process reaches, such as a tool a test starts, shows as `no tests`. A
pyproject.toml with a [tool.mutmut] section fails the run. A crash inside mutmut, such as a KeyError in its worker pool,
becomes one line for its folder, naming the error and telling you to mutate that folder's changed lines by hand.
- .go: Gremlins, as `gremlins unleash --diff`, in the checkout's top. It skips *_test.go itself. Its git runs with diff.context=0,
set in GIT_CONFIG_* variables after any the environment holds, since Gremlins v0.6.0 mutates one run of lines per hunk.
- .rs: cargo-mutants, as `cargo mutants --in-diff`, in the checkout's top.
- .cjs, .cts, .js, .jsx, .mjs, .mts, .ts, .tsx: Stryker, as `npx --no --package=@stryker-mutator/core stryker run --mutate` on the
changed lines, in the nearest folder above the file that holds a package.json. A file with no package.json above it isn't
@@ -25,8 +27,12 @@ or __tests__/ folder.
--prefix is shell text that runs each tool: sh runs `<prefix> "$@"` in the tool's folder, which $PWD names, with the tool's command
as "$@". For example, 'uvx --from "mutmut>=3,<4"'. Without --prefix, the command runs as it is. A container must mount $PWD and
run there, as 'docker compose -f "$(git rev-parse --show-toplevel)/compose.yaml" run --rm -v "$PWD:$PWD" -w "$PWD" app' does. "$1"
is the command's first word, mutmut, cargo, npx or vendor/bin/infection, so a prefix can pick what to run per tool:
is the command's first word, mutmut, cargo, gremlins, npx or vendor/bin/infection, so a prefix can pick what to run per tool:
'case "$1" in mutmut) set -- uvx --from "mutmut>=3,<4" "$@";; esac;'.
Gremlins' git runs in the container too. In a git worktree, git keeps its data in the main checkout, outside $PWD, so the container
mounts that folder as well, and it passes on the GIT_CONFIG_* variables that set diff.context, as `-e GIT_CONFIG_COUNT -e
GIT_CONFIG_KEY_0 -e GIT_CONFIG_VALUE_0` where the environment holds no setting of its own, and one more KEY and VALUE for each it holds:
'common="$(git rev-parse --path-format=absolute --git-common-dir)"; docker run --rm -v "$PWD:$PWD" -v "$common:$common" -w "$PWD" -e GIT_CONFIG_COUNT -e GIT_CONFIG_KEY_0 -e GIT_CONFIG_VALUE_0 <image> "$@"'.
--jobs sets how many tests each tool runs at once, 4 by default: one heavy slot's CPUs. Under run-heavy, a container that sets
neither memory limit gets the slot's share, in MiB in RUN_HEAVY_MEMORY; set --jobs so that that many test runs fit in it.
@@ -34,6 +40,8 @@ neither memory limit gets the slot's share, in MiB in RUN_HEAVY_MEMORY; set --jo
It prints:
- for mutmut, per folder, a line with the mutant count, then a line per mutant on a changed line that is not killed, as
`<path>:<line>: <status>: <the line as mutated>`, or `<path>: <status>: <name>, on a line mutate-changes cannot find`;
- for Gremlins, a line with the number of mutants not killed, then a line per mutant that lived or is not covered, as
`<path>:<line>:<column>: <status>: <mutator>`;
- for cargo-mutants, a line with the mutant count, then a line per mutant it missed or that timed out, as
`<path>:<line>:<column>: <outcome>: <mutation>`;
- for Stryker and Infection, a line naming the folder the tool ran in, then the tool's own report;
@@ -57,7 +65,7 @@ from machine_load.slots import CPUS_PER_SLOT
from git_cli.git_repo import default_ref, Git, top
from failure import Failure
from git_cli import git_repo
from mutate_changes.in_diff_tools import run_cargo_mutants, run_infection, run_stryker
from mutate_changes.in_diff_tools import run_cargo_mutants, run_gremlins, run_infection, run_stryker, with_zero_diff_context
from mutate_changes.mutmut_tool import run_mutmut
from mutate_changes.tool_process import run_tool
@@ -125,6 +133,8 @@ def mutate(given: dict[str, str], env: typing.Mapping[str, str]) -> list[str] |
for tool, files in sorted(changed.items()):
if tool == "cargo-mutants":
lines = run_cargo_mutants(checkout, merge_base, sorted(files), run, git, jobs)
elif tool == "gremlins":
lines = run_gremlins(checkout, merge_base, functools.partial(run, env=with_zero_diff_context(env)), jobs)
elif tool == "infection":
lines = run_infection(checkout, merge_base, run, jobs)
elif tool == "stryker":