Add task-bench, which has Haiku fix planted bugs at a base and a head and prints what each side took
CI / tests (pull_request) Failing after 4m9s
CI / tests (pull_request) Failing after 4m9s
This commit is contained in:
@@ -59,28 +59,37 @@ def run_gremlins(top: str, base: str, run: Run, jobs: int) -> list[str] | Failur
|
||||
"""A line with the number of mutants on the changed lines and how many of them Gremlins reports as lived or not covered, then a
|
||||
line per such mutant, as `<path>:<line>:<column>: <status>: <mutator>`.
|
||||
|
||||
Gremlins runs in top and mutates the Go lines the branch changes since base. It skips `*_test.go` itself. It reads the diff from
|
||||
git, so `run` must hold the environment that `with_plain_git_diff` makes. Gremlins exits nonzero on a mutation score below a
|
||||
threshold the project sets, which its exit code doesn't tell from a run that broke, so any nonzero exit fails the run."""
|
||||
Gremlins mutates the Go lines the branch changes since base. It reads the diff from git, so `run` must hold the environment that
|
||||
`with_plain_git_diff` makes."""
|
||||
mutants = gremlins_mutants(top, ["--diff", base], run, jobs)
|
||||
if isinstance(mutants, Failure):
|
||||
return mutants
|
||||
# Gremlins lists the mutants on the unchanged lines of a hunk too, as SKIPPED. It lists the files in no fixed order.
|
||||
unkilled = sorted(mutant for mutant in mutants if mutant.status in GREMLINS_UNKILLED)
|
||||
on_changed_lines = sum(mutant.status != "SKIPPED" for mutant in mutants)
|
||||
return [f"gremlins: {on_changed_lines} mutants on changed lines, {len(unkilled)} not killed.", *(f"{m.path}:{m.line}:{m.column}: {m.status}: {m.mutator}" for m in unkilled)]
|
||||
|
||||
|
||||
def gremlins_mutants(top: str, arguments: list[str], run: Run, jobs: int) -> list[Mutant] | Failure:
|
||||
"""Each mutant in the report of `gremlins unleash <arguments>`, which runs in top.
|
||||
|
||||
Gremlins skips `*_test.go` itself. It exits nonzero on a mutation score below a threshold the project sets, which its exit code
|
||||
doesn't tell from a run that broke, so any nonzero exit fails the run."""
|
||||
scratch = scratch_folder(top)
|
||||
if isinstance(scratch, Failure):
|
||||
return scratch
|
||||
try:
|
||||
report = pathlib.Path(scratch, "report.json")
|
||||
ran = run(["gremlins", "unleash", "--diff", base, "--output", os.path.join(os.path.relpath(scratch, top), report.name), "--workers", str(jobs)], top)
|
||||
ran = run(["gremlins", "unleash", *arguments, "--output", os.path.join(os.path.relpath(scratch, top), report.name), "--workers", str(jobs)], top)
|
||||
if isinstance(ran, Failure) or ran.code:
|
||||
return ran if isinstance(ran, Failure) else whole_output("Gremlins", ran)
|
||||
# Gremlins writes no report where it finds no mutant, and `null` for a list with no entry.
|
||||
files = (json.loads(report.read_text(encoding="utf-8"))["files"] or []) if report.is_file() else []
|
||||
mutants = [Mutant(file["file_name"], mutant["line"], mutant["column"], mutant["status"], mutant["type"]) for file in files for mutant in file["mutations"] or []]
|
||||
return [Mutant(file["file_name"], mutant["line"], mutant["column"], mutant["status"], mutant["type"]) for file in files for mutant in file["mutations"] or []]
|
||||
except (OSError, ValueError, KeyError, TypeError) as failure:
|
||||
return Failure(f"could not read Gremlins' report in {scratch}: {failure}")
|
||||
finally:
|
||||
remove(scratch)
|
||||
# Gremlins lists the mutants on the unchanged lines of a hunk too, as SKIPPED. It lists the files in no fixed order.
|
||||
unkilled = sorted(mutant for mutant in mutants if mutant.status in GREMLINS_UNKILLED)
|
||||
on_changed_lines = sum(mutant.status != "SKIPPED" for mutant in mutants)
|
||||
return [f"gremlins: {on_changed_lines} mutants on changed lines, {len(unkilled)} not killed.", *(f"{m.path}:{m.line}:{m.column}: {m.status}: {m.mutator}" for m in unkilled)]
|
||||
|
||||
|
||||
def with_plain_git_diff(env: typing.Mapping[str, str]) -> dict[str, str]:
|
||||
|
||||
Reference in New Issue
Block a user