Sort the imports and hand the planter its languages as an argument
CI / tests (pull_request) Successful in 3m28s

This commit is contained in:
2026-11-23 21:35:21 +01:00
parent c6cdd2f850
commit b0e50e24ae
9 changed files with 25 additions and 30 deletions
+1 -1
View File
@@ -12,7 +12,7 @@ import tomllib
import typing import typing
from mutate_changes.changed_lines import by_folder, label from mutate_changes.changed_lines import by_folder, label
from mutate_changes.mutmut_mutants import crash_in_mutmut, function_keys, Change, mutant_globs, mutated_lines, named, statuses from mutate_changes.mutmut_mutants import Change, crash_in_mutmut, function_keys, mutant_globs, mutated_lines, named, statuses
from mutate_changes.tool_process import failed, Ran, remove, Run, scratch_folder from mutate_changes.tool_process import failed, Ran, remove, Run, scratch_folder
from failure import Failure from failure import Failure
from git_cli.git_repo import Git from git_cli.git_repo import Git
+1 -1
View File
@@ -7,8 +7,8 @@ import re
from failure import Failure from failure import Failure
from mutate_changes import in_diff_tools from mutate_changes import in_diff_tools
from mutate_changes.changed_lines import is_test from mutate_changes.changed_lines import is_test
from mutate_changes.tool_process import Run
from task_bench.planted_mutant import Mutant from task_bench.planted_mutant import Mutant
from mutate_changes.tool_process import Run
# What each of Gremlins v0.6.0's mutators writes in place of a token: `tokenMutations` in its internal/engine/mappings.go, under the # What each of Gremlins v0.6.0's mutators writes in place of a token: `tokenMutations` in its internal/engine/mappings.go, under the
# names its report gives the mutators, from internal/mutator/mutator.go. # names its report gives the mutators, from internal/mutator/mutator.go.
+1 -1
View File
@@ -128,7 +128,6 @@ import typing
import uuid import uuid
from task_bench.tasks import Asked, Bench, BUG, check_made, committed, Kind, KINDS, on_disk, Planned, Task, tests_in_copy from task_bench.tasks import Asked, Bench, BUG, check_made, committed, Kind, KINDS, on_disk, Planned, Task, tests_in_copy
from task_bench.plant import drawn, killed_mutants, place_files, task_text
from task_bench.planted_mutant import bug_at_sides, Mutant from task_bench.planted_mutant import bug_at_sides, Mutant
from claude_code.reply import Claude from claude_code.reply import Claude
from task_bench.bench_folder import clear_left, held from task_bench.bench_folder import clear_left, held
@@ -137,6 +136,7 @@ from task_bench.digest import counted, digest, Run, TaskRuns
from machine_load.slots import CPUS_PER_SLOT from machine_load.slots import CPUS_PER_SLOT
from git_cli.git_repo import default_ref, Git, top from git_cli.git_repo import default_ref, Git, top
from task_bench.gather import DIGEST, gather, run_claude from task_bench.gather import DIGEST, gather, run_claude
from task_bench.plant import drawn, killed_mutants, place_files, task_text
from claude_code.entries import entry_from, json_objects from claude_code.entries import entry_from, json_objects
from mutate_changes.tool_process import failed, Ran, run_tool from mutate_changes.tool_process import failed, Ran, run_tool
from failure import Failure from failure import Failure
+9 -9
View File
@@ -6,10 +6,10 @@ import re
import typing import typing
from failure import Failure from failure import Failure
from mutate_changes.changed_lines import is_test
from mutate_changes.tool_process import Run
from task_bench import go_bugs, python_bugs from task_bench import go_bugs, python_bugs
from mutate_changes.changed_lines import is_test
from task_bench.planted_mutant import Mutant from task_bench.planted_mutant import Mutant
from mutate_changes.tool_process import Run
# A place as `larv-review places` prints it: `<path>:<line>` in backticks. # A place as `larv-review places` prints it: `<path>:<line>` in backticks.
PLACE = re.compile(r"`([^`\s:]+):\d+`") PLACE = re.compile(r"`([^`\s:]+):\d+`")
@@ -32,8 +32,8 @@ LANGUAGES = (
) )
def language_of(path: str) -> Language | None: def language_of(path: str, languages: tuple[Language, ...] = LANGUAGES) -> Language | None:
return next((language for language in LANGUAGES if path.endswith(language.suffixes)), None) return next((language for language in languages if path.endswith(language.suffixes)), None)
def place_files(places: str) -> list[str]: def place_files(places: str) -> list[str]:
@@ -42,12 +42,12 @@ def place_files(places: str) -> list[str]:
return sorted({path for path in PLACE.findall(places) if language_of(path) and not is_test(path)}) return sorted({path for path in PLACE.findall(places) if language_of(path) and not is_test(path)})
def killed_mutants(top: str, files: list[str], run: Run, jobs: int) -> list[Mutant] | Failure: def killed_mutants(top: str, files: list[str], run: Run, jobs: int, languages: tuple[Language, ...] = LANGUAGES) -> list[Mutant] | Failure:
"""The mutants in `files`, which place_files named, that the tests of the tree at top kill: each language's tool runs over """The mutants in `files`, which place_files named, that the tests of the tree at top kill: each language's tool runs over
the files in that language.""" the files in that language."""
killed: list[Mutant] = [] killed: list[Mutant] = []
for language in LANGUAGES: for language in languages:
own = [path for path in files if language_of(path) is language] own = [path for path in files if language_of(path, languages) is language]
found = language.killed(top, own, run, jobs) if own else [] found = language.killed(top, own, run, jobs) if own else []
if isinstance(found, Failure): if isinstance(found, Failure):
return found return found
@@ -60,8 +60,8 @@ def drawn(mutants: list[Mutant], seed: int) -> list[Mutant]:
return random.Random(seed).sample(sorted(set(mutants)), len(set(mutants))) return random.Random(seed).sample(sorted(set(mutants)), len(set(mutants)))
def task_text(path: str, output: str) -> str | None: def task_text(path: str, output: str, languages: tuple[Language, ...] = LANGUAGES) -> str | None:
"""What Haiku is told of a bug planted in the file at path, one place_files named: the failing test's message in output, """What Haiku is told of a bug planted in the file at path, one place_files named: the failing test's message in output,
what the test command printed, as the file's language reads it. None where the output holds no such message.""" what the test command printed, as the file's language reads it. None where the output holds no such message."""
language = language_of(path) language = language_of(path, languages)
return language.told(output) if language else None return language.told(output) if language else None
+1 -1
View File
@@ -4,8 +4,8 @@ import re
from failure import Failure from failure import Failure
from mutate_changes.mutmut_tool import killed_by_mutmut from mutate_changes.mutmut_tool import killed_by_mutmut
from mutate_changes.tool_process import Run
from task_bench.planted_mutant import Mutant from task_bench.planted_mutant import Mutant
from mutate_changes.tool_process import Run
# pytest's report of the failed tests, in its default form or with --tb=short: under this heading, a section per test. # pytest's report of the failed tests, in its default form or with --tb=short: under this heading, a section per test.
FAILURES = re.compile(r"^=+ FAILURES =+$", re.MULTILINE) FAILURES = re.compile(r"^=+ FAILURES =+$", re.MULTILINE)
+3 -3
View File
@@ -1,16 +1,16 @@
"""task-bench's Go planter: which files Gremlins mutates, how its mutants are re-applied and what go test's output tells Haiku.""" """task-bench's Go planter: which files Gremlins mutates, how its mutants are re-applied and what go test's output tells Haiku."""
import json import json
import tempfile
import pathlib import pathlib
import sys import sys
import tempfile
import unittest import unittest
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1])) sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
from task_bench.go_bugs import go_files, killed_mutants, reapplied, task_text
from task_bench.planted_mutant import Mutant
from failure import Failure from failure import Failure
from task_bench.go_bugs import go_files, killed_mutants, reapplied, task_text
from mutate_changes import in_diff_tools from mutate_changes import in_diff_tools
from task_bench.planted_mutant import Mutant
from mutate_changes.tool_process import Ran from mutate_changes.tool_process import Ran
# go test's report of an assertion that failed in a subtest, then of one whose message runs over two lines. # go test's report of an assertion that failed in a subtest, then of one whose message runs over two lines.
+7 -12
View File
@@ -2,14 +2,12 @@
import pathlib import pathlib
import sys import sys
import unittest import unittest
import unittest.mock
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1])) sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
from task_bench import plant
from task_bench.plant import drawn, killed_mutants, Language, LANGUAGES, place_files, task_text from task_bench.plant import drawn, killed_mutants, Language, LANGUAGES, place_files, task_text
from task_bench.planted_mutant import Mutant
from failure import Failure from failure import Failure
from task_bench.planted_mutant import Mutant
PLACES = """## 2026-11-19T22:33:15Z, PR #646 at a357cc7b PLACES = """## 2026-11-19T22:33:15Z, PR #646 at a357cc7b
@@ -57,10 +55,7 @@ class LanguagesTest(unittest.TestCase):
def setUp(self): def setUp(self):
self.asked: list[tuple] = [] self.asked: list[tuple] = []
self.found: dict[str, list[Mutant] | Failure] = {"Go": [mutant("b.go"), mutant("a.go")], "Python": [mutant("c.py")]} self.found: dict[str, list[Mutant] | Failure] = {"Go": [mutant("b.go"), mutant("a.go")], "Python": [mutant("c.py")]}
languages = tuple(Language(name, suffixes, self.killed(name), f"{name} read {{}}".format) for name, suffixes in (("Go", (".go",)), ("Python", (".py", ".pyi")))) self.languages = tuple(Language(name, suffixes, self.killed(name), f"{name} read {{}}".format) for name, suffixes in (("Go", (".go",)), ("Python", (".py", ".pyi"))))
patched = unittest.mock.patch.object(plant, "LANGUAGES", languages)
patched.start()
self.addCleanup(patched.stop)
def killed(self, name: str): def killed(self, name: str):
def killed(top: str, files: list[str], run, jobs: int) -> list[Mutant] | Failure: def killed(top: str, files: list[str], run, jobs: int) -> list[Mutant] | Failure:
@@ -70,20 +65,20 @@ class LanguagesTest(unittest.TestCase):
return killed return killed
def test_each_languages_tool_finds_the_mutants_of_the_files_in_that_language(self): def test_each_languages_tool_finds_the_mutants_of_the_files_in_that_language(self):
self.assertEqual(killed_mutants("/top", ["a.go", "c.py", "b.go", "d.pyi"], "run", 3), [mutant("b.go"), mutant("a.go"), mutant("c.py")]) self.assertEqual(killed_mutants("/top", ["a.go", "c.py", "b.go", "d.pyi"], "run", 3, self.languages), [mutant("b.go"), mutant("a.go"), mutant("c.py")])
self.assertEqual(self.asked, [("Go", "/top", ["a.go", "b.go"], "run", 3), ("Python", "/top", ["c.py", "d.pyi"], "run", 3)]) self.assertEqual(self.asked, [("Go", "/top", ["a.go", "b.go"], "run", 3), ("Python", "/top", ["c.py", "d.pyi"], "run", 3)])
def test_a_language_without_a_file_runs_no_tool(self): def test_a_language_without_a_file_runs_no_tool(self):
self.assertEqual(killed_mutants("/top", ["c.py"], "run", 3), [mutant("c.py")]) self.assertEqual(killed_mutants("/top", ["c.py"], "run", 3, self.languages), [mutant("c.py")])
self.assertEqual([name for name, *_ in self.asked], ["Python"]) self.assertEqual([name for name, *_ in self.asked], ["Python"])
def test_a_tool_that_fails_fails_the_whole(self): def test_a_tool_that_fails_fails_the_whole(self):
self.found["Go"] = Failure("gremlins broke") self.found["Go"] = Failure("gremlins broke")
self.assertEqual(killed_mutants("/top", ["a.go", "c.py"], "run", 3), Failure("gremlins broke")) self.assertEqual(killed_mutants("/top", ["a.go", "c.py"], "run", 3, self.languages), Failure("gremlins broke"))
def test_the_language_of_the_bugs_file_reads_the_test_commands_output(self): def test_the_language_of_the_bugs_file_reads_the_test_commands_output(self):
self.assertEqual((task_text("pkg/a.go", "output"), task_text("pkg/c.pyi", "output")), ("Go read output", "Python read output")) self.assertEqual((task_text("pkg/a.go", "output", self.languages), task_text("pkg/c.pyi", "output", self.languages)), ("Go read output", "Python read output"))
self.assertIsNone(task_text("README.md", "output")) self.assertIsNone(task_text("README.md", "output", self.languages))
class ShippedLanguagesTest(unittest.TestCase): class ShippedLanguagesTest(unittest.TestCase):
+1 -1
View File
@@ -6,9 +6,9 @@ import unittest
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1])) sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
from failure import Failure
from task_bench.python_bugs import killed_mutants, task_text from task_bench.python_bugs import killed_mutants, task_text
from task_bench.planted_mutant import Mutant from task_bench.planted_mutant import Mutant
from failure import Failure
from mutate_changes.tool_process import Ran from mutate_changes.tool_process import Ran
CALC = "def double(n):\n\treturn n * 2\n\n\ndef triple(n):\n\treturn (\n\t\tn * 3\n\t)\n" CALC = "def double(n):\n\treturn n * 2\n\n\ndef triple(n):\n\treturn (\n\t\tn * 3\n\t)\n"
+1 -1
View File
@@ -19,10 +19,10 @@ from task_bench import api_proxy, bench_folder, main, runs
from test_env import assert_not_root, isolated_env from test_env import assert_not_root, isolated_env
from task_bench.runs import checked_tree, closed, Containers, docker_cli, fix_attempted, opened, ran_tests, TimedOut from task_bench.runs import checked_tree, closed, Containers, docker_cli, fix_attempted, opened, ran_tests, TimedOut
from task_bench.plant import drawn from task_bench.plant import drawn
from task_bench.planted_mutant import Mutant
from claude_code.entries import Entry, entry_from from claude_code.entries import Entry, entry_from
from failure import Failure from failure import Failure
from task_bench.figures import Figures, Result from task_bench.figures import Figures, Result
from task_bench.planted_mutant import Mutant
from mutate_changes.tool_process import Ran from mutate_changes.tool_process import Ran
from claude_code.tokens import Tokens from claude_code.tokens import Tokens