Answer stability round 1: 0 🔴, 5 🟡 (0 misread); run both tools in a scratch copy, read Infection's two sources, end PHPUnit's list, spell glob characters

This commit is contained in:
2026-11-26 11:42:20 +01:00
parent 76de4fa497
commit 874e417e27
8 changed files with 268 additions and 169 deletions
+11 -3
View File
@@ -2,6 +2,7 @@
import json
import os
import pathlib
import re
import typing
from mutate_changes.changed_lines import by_folder, label, runs
@@ -14,7 +15,7 @@ CARGO_FINISHED = frozenset({0, 2, 3})
CARGO_OUTCOMES = ("caught", "missed", "timeout", "unviable")
INFECTION = "vendor/bin/infection" # the project's own, as Composer installs it
# npx runs the project's own @stryker-mutator/core, else one an earlier npx run cached, and installs none.
STRYKER = ["npx", "--no", "--package=@stryker-mutator/core", "stryker", "run"]
STRYKER_RUN = ["npx", "--no", "--package=@stryker-mutator/core", "stryker", "run"]
GREMLINS_UNKILLED = frozenset({"LIVED", "NOT COVERED"})
# What Gremlins v0.6.0 needs of the diff it reads from git: one run of lines per hunk is all it mutates, so a hunk holds the changed
# lines and none around them, nor a neighbouring change; it takes each file's path after a b/; and it reads no colour codes. A user's git
@@ -117,6 +118,13 @@ def outcome_lines(path: pathlib.Path) -> list[str]:
# Stryker and Infection also exit nonzero on a mutation score below a threshold the project sets, which their exit code doesn't
# tell from a run that broke, so either fails the run.
def glob_escaped(path: str) -> str:
"""A path as a glob that matches it. Stryker 10.1.1 reads each entry of --mutate as a glob, in which `app/[slug]/page.tsx`
matches `app/s/page.tsx` and not the file of that name. It reads a backslash as a slash, so no character can be escaped: a `?`
stands for each one a glob gives a meaning, and matches it."""
return re.sub(r"[][!()*+@{}]", "?", path)
def run_stryker(top: str, changed: dict[str, frozenset[int]], run: Run, jobs: int) -> list[str] | Failure:
"""For each folder Stryker runs in, a line naming it, then Stryker's own report of the mutants on the changed lines. Last, a line
naming the files with no package.json above them, if any.
@@ -129,8 +137,8 @@ def run_stryker(top: str, changed: dict[str, frozenset[int]], run: Run, jobs: in
if not os.path.isfile(os.path.join(top, folder, "package.json")):
unplaced = sorted(files)
continue
mutate = ",".join(f"{path}:{first}-{last}" for path, lines in sorted(files.items()) for first, last in runs(lines))
ran = run([*STRYKER, "--mutate", mutate, "--concurrency", str(jobs), "--reporters", "clear-text"], os.path.join(top, folder))
mutate = ",".join(f"{glob_escaped(path)}:{first}-{last}" for path, lines in sorted(files.items()) for first, last in runs(lines))
ran = run([*STRYKER_RUN, "--mutate", mutate, "--concurrency", str(jobs), "--reporters", "clear-text"], os.path.join(top, folder))
if isinstance(ran, Failure) or ran.code:
return ran if isinstance(ran, Failure) else whole_output(f"Stryker in {label(folder)}", ran)
report.extend([f"Stryker in {label(folder)}:", *ran.output.splitlines()])
+13 -1
View File
@@ -17,12 +17,12 @@ from mutate_changes.changed_lines import added_lines, by_folder, not_mutated, ru
from mutate_changes.mutmut_tool import copy_files, Ended, Folder, mutate_folder, NO_MUTANT, reported
from mutate_changes.mutmut_mutants import crash_in_mutmut, function_keys, mutant_globs, mutated_lines, named, statuses
from failure import Failure
from mutate_changes.in_diff_tools import glob_escaped, run_stryker, with_plain_git_diff
from mutate_changes.bare_imports import imported_by_file_name
from test_env import isolated_env
from mutate_changes.mutmut_setup import left_out, mutmut_config
from mutate_changes import main
from mutate_changes.tool_process import Ran, run_tool, scratch_folder
from mutate_changes.in_diff_tools import with_plain_git_diff
SOURCE = "def double(n):\n\treturn n * 2\n\n\nclass Pt:\n\tdef moved(self, by=1):\n\t\treturn self.x + by\n"
# The shape of the file mutmut 3 writes under mutants/: the original of each function and its mutants, with the original's lines.
@@ -163,6 +163,18 @@ class InDiffTools(unittest.TestCase):
self.assertEqual((env["GIT_CONFIG_COUNT"], env["GIT_CONFIG_KEY_0"], env["GIT_CONFIG_KEY_6"], "GIT_CONFIG_KEY_7" in env), ("7", "diff.context", "diff.interHunkContext", False))
def test_a_path_goes_to_stryker_with_a_question_mark_for_each_character_a_glob_gives_a_meaning(self):
self.assertEqual(glob_escaped("app/[slug]/(shop)/{a}/b!c*d+e@f.tsx"), "app/?slug?/?shop?/?a?/b?c?d?e?f.tsx")
self.assertEqual(glob_escaped("src/pick-one_two.test.ts"), "src/pick-one_two.test.ts")
def test_stryker_is_handed_a_changed_file_whose_path_holds_a_globs_characters_as_a_glob_that_matches_it(self):
with tempfile.TemporaryDirectory() as top:
pathlib.Path(top, "package.json").write_text("{}")
ran: list[list[str]] = []
run_stryker(top, {"app/[slug]/page.tsx": frozenset({3, 4})}, lambda argv, cwd: ran.append(argv) or Ran(0, ""), 1)
self.assertEqual(ran[0][5:7], ["--mutate", "app/?slug?/page.tsx:3-4"])
class MutmutSetup(unittest.TestCase):
def test_the_config_mutates_the_sources_and_copies_each_entry_of_the_folder(self):
for existing in ("", "[mutmut]\nsource_paths = old.py\nalso_copy = old\n"):