Answer stability round 1: 1 🔴, 2 🟡 (0 misread); pin the git diff settings Gremlins parses, show the mutant total, and a container prefix that runs as root
This commit is contained in:
+17
-14
@@ -1,10 +1,10 @@
|
||||
"""Mutation-test the lines a branch adds or changes, and print each mutant its tests don't kill.
|
||||
r"""Mutation-test the lines a branch adds or changes, and print each mutant its tests don't kill.
|
||||
|
||||
usage: mutate-changes [--base <ref>] [--prefix <shell text>] [--jobs <n>]
|
||||
|
||||
Run it in a checkout, under ~/.claude/bin/run-heavy. It diffs the working tree's tracked files against the merge base of HEAD and
|
||||
--base, by default the default branch: origin's as last fetched, else main or master. It picks the tool by each changed file's
|
||||
extension, and leaves out test files: test_*.py, *_test.py, conftest.py, *.test.* and *.spec.*, and any file under a tests/, test/
|
||||
extension, and leaves out test files: test_*.py, *_test.py, *_test.go, conftest.py, *.test.* and *.spec.*, and any file under a tests/, test/
|
||||
or __tests__/ folder.
|
||||
|
||||
- .py: mutmut 3, in a scratch copy of the nearest folder above the file that holds a setup.cfg or a pyproject.toml, else of the
|
||||
@@ -16,8 +16,9 @@ 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.
|
||||
- .go: Gremlins, as `gremlins unleash --diff`, in the checkout's top, where its go.mod must be. Gremlins reads the diff from git, so
|
||||
the run adds settings to the GIT_CONFIG_* variables, after any the environment holds: no context lines, since Gremlins mutates
|
||||
every line of a hunk; a/ and b/ as the file prefixes; and no colour.
|
||||
- .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
|
||||
@@ -29,10 +30,12 @@ as "$@". For example, 'uvx --from "mutmut>=3,<4"'. Without --prefix, the command
|
||||
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, 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> "$@"'.
|
||||
Gremlins' git runs in the container too, so a Go prefix mounts git's data and passes on the GIT_CONFIG_* variables, and allows git
|
||||
to read a checkout that the container's root user doesn't own. In a git worktree, git's data is in the main checkout, outside $PWD:
|
||||
|
||||
common="$(git rev-parse --path-format=absolute --git-common-dir)"
|
||||
docker run --rm -v "$PWD:$PWD" -v "$common:$common" -w "$PWD" $(printenv | sed -n 's/^\(GIT_CONFIG_[A-Z0-9_]*\)=.*/-e \1/p') \
|
||||
<image holding gremlins> sh -c 'git config --global --add safe.directory "*" && exec "$@"' sh
|
||||
|
||||
--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.
|
||||
@@ -40,7 +43,7 @@ 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
|
||||
- for Gremlins, a line with the mutant count and how many it did not kill, 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>`;
|
||||
@@ -50,9 +53,9 @@ It prints:
|
||||
- last, the wall time.
|
||||
|
||||
Exit 1, saying why, on an unknown or repeated argument, an option without its value, or a --jobs that is no whole number from 1.
|
||||
Exit 1 too when git fails, a file cannot be read or copied, a tool cannot start, or a tool fails before it reports. Stryker and
|
||||
Infection also exit nonzero on a mutation score below a threshold the project sets, which fails the run as well and prints their
|
||||
whole report.
|
||||
Exit 1 too when git fails, a file cannot be read or copied, a tool cannot start, or a tool fails before it reports. Stryker, Infection
|
||||
and Gremlins also exit nonzero on a mutation score below a threshold the project sets, which fails the run as well and prints their
|
||||
whole output.
|
||||
"""
|
||||
import functools
|
||||
import os
|
||||
@@ -65,7 +68,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_gremlins, run_infection, run_stryker, with_zero_diff_context
|
||||
from mutate_changes.in_diff_tools import run_cargo_mutants, run_gremlins, run_infection, run_stryker, with_plain_git_diff
|
||||
from mutate_changes.mutmut_tool import run_mutmut
|
||||
from mutate_changes.tool_process import run_tool
|
||||
|
||||
@@ -134,7 +137,7 @@ def mutate(given: dict[str, str], env: typing.Mapping[str, str]) -> list[str] |
|
||||
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)
|
||||
lines = run_gremlins(checkout, merge_base, functools.partial(run, env=with_plain_git_diff(env)), jobs)
|
||||
elif tool == "infection":
|
||||
lines = run_infection(checkout, merge_base, run, jobs)
|
||||
elif tool == "stryker":
|
||||
|
||||
Reference in New Issue
Block a user