Kill the mutants that survived on the lines the release review changed

This commit is contained in:
2026-11-19 13:44:12 +01:00
parent 2edbde8071
commit 2806a8edc9
19 changed files with 452 additions and 6 deletions
+102
View File
@@ -1,4 +1,5 @@
import contextlib
import dataclasses
import functools
import io
import json
@@ -12,16 +13,23 @@ import unittest
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
from chunk_driver.doubles import a_loop
from project_config.doubles import configured
from agent_cycle.run import Cycle
from chunk_driver import cycle_start
from failure import Failure
from loop_effects.doubles import FakeEffects, NOW, STAMP
from git_cli import git_repo
from chunk_driver.project.model_choice import Models
from transcript_archive import outcomes, write
from loop_state.paths import paths_from
from model_routing.ladder import ProjectRung, Rung
from model_routing.ladder_file import read_ladder, SHIPPED
from text_files.file_writes import replace_file
from model_routing.route import Route, WorkerLine
from claude_code import session
from agent_cycle.stop import Stop
from agent_cycle.verdicts import TakenIn
from agent_cycle.worker_prompts import WorkerPrompts
OPUS_PROJECT = ProjectRung(read_ladder(SHIPPED), Rung("claude-opus-5-5", "medium"))
@@ -49,6 +57,100 @@ class SetupVersion(unittest.TestCase):
self.assertEqual(cycle_start.setup_version(pathlib.Path("/r"), fake_git), "unknown: fatal: bad HEAD hint: repair it")
class ProjectRouting(unittest.TestCase):
def setUp(self):
temp = tempfile.TemporaryDirectory()
self.addCleanup(temp.cleanup)
self.home = pathlib.Path(temp.name)
self.paths = paths_from(self.home)
self.checkout = self.home / "code" / "acme"
self.checkout.mkdir(parents=True)
self.config = configured(self, self.checkout, home=self.home)
self.paths.models_file.parent.mkdir(exist_ok=True)
def routing(self, fake=None, env=None):
return cycle_start.project_routing(a_loop((fake or FakeEffects()).effects(), root=str(self.checkout), paths=self.paths, env=env or {}), "a-driver")
def test_routes_on_the_projects_saved_model_and_names_the_shipped_ladder_or_the_projects_own_as_its_file(self):
self.paths.models_file.write_text(json.dumps({"acme": "claude-opus-5-5"}))
shipped = read_ladder(SHIPPED)
self.assertEqual(self.routing(), cycle_start.Routing(Models("claude-opus-5-5", "claude-opus-5-5"), shipped, SHIPPED))
self.assertEqual(self.routing(env={"LOOP_CLAUDE_JUDGE_MODEL": "j"}), cycle_start.Routing(Models("j", "claude-opus-5-5"), shipped, SHIPPED))
own = self.config / "routing-ladder.json"
own.write_text('[{"model": "claude-fable-5-2", "effort": "low"}]', encoding="utf-8")
routing = self.routing()
assert isinstance(routing, cycle_start.Routing)
self.assertEqual((routing.ladder_file, [str(rung) for rung in routing.ladder.rungs]), (own, ["claude-fable-5-2 at low effort"]))
def test_stops_with_exit_1_naming_the_ladder_file_that_cannot_be_read(self):
self.paths.models_file.write_text(json.dumps({"acme": "claude-opus-5-5"}))
own = self.config / "routing-ladder.json"
own.write_text("not json", encoding="utf-8")
stop = self.routing()
assert isinstance(stop, Stop)
self.assertEqual(stop.code, 1)
self.assertIn(str(own), stop.reason)
def test_stops_with_exit_1_naming_the_config_that_cannot_be_read(self):
self.paths.models_file.write_text(json.dumps({"acme": "claude-opus-5-5"}))
(self.config / "config.toml").write_text("not toml", encoding="utf-8")
stop = self.routing()
assert isinstance(stop, Stop)
self.assertEqual(stop.code, 1)
self.assertIn(str(self.config / "config.toml"), stop.reason)
def test_asks_for_the_model_where_none_is_saved_and_off_a_terminal_stops_naming_the_driver_to_rerun(self):
stop = self.routing(FakeEffects(on_terminal=False))
assert isinstance(stop, Stop)
self.assertEqual(stop.code, 2)
self.assertIn("pick acme's model", stop.reason)
self.assertIn("rerun a-driver on a terminal", stop.reason)
with contextlib.redirect_stderr(io.StringIO()):
self.assertEqual(self.routing(FakeEffects(inputs=["claude-opus-5-5"])), cycle_start.Routing(Models("claude-opus-5-5", "claude-opus-5-5"), read_ladder(SHIPPED), SHIPPED))
class CycleStart(unittest.TestCase):
ROUTING = cycle_start.Routing(Models("judge-model", "claude-opus-5-5"), OPUS_PROJECT.ladder, SHIPPED)
def test_announces_the_route_the_chunks_run_holds_and_else_the_one_its_archive_last_names(self):
def never():
raise AssertionError("not asked")
kept = Route(Rung("claude-opus-5-5", "xhigh"), 3, 4, 5)
with tempfile.TemporaryDirectory() as home:
opened = session.session_named("A proj a-driver", pathlib.Path(home, "projects"))
loop = a_loop(FakeEffects().effects(), session=opened)
archive = pathlib.Path(home, "archive")
with contextlib.redirect_stdout(io.StringIO()) as said:
self.assertEqual(cycle_start.announced_route(4, kept, self.ROUTING, archive, never, loop), kept)
self.assertEqual(said.getvalue(), f"\n{STAMP} === cycle 4, worker on claude-opus-5-5 at xhigh effort ===\n")
transcript = pathlib.Path(home, "projects", "-fake", f"{opened.id}.jsonl")
transcript.parent.mkdir(parents=True)
transcript.write_text(json.dumps({"type": "queue-operation", "timestamp": "1"}) + "\n")
with contextlib.redirect_stderr(io.StringIO()):
self.assertIsNone(write.archive(archive, str(transcript), "Do it.", outcomes.unfinished(kept.worker_line(), "working", "j", ""), NOW, replace=replace_file))
with contextlib.redirect_stdout(io.StringIO()):
self.assertEqual(cycle_start.announced_route(1, None, self.ROUTING, archive, never, loop), kept)
def test_builds_the_cycle_from_the_loop_the_routing_and_what_the_entry_point_knows(self):
asked = []
def git(*args, cwd=None):
asked.append(cwd)
return "v0.1.0\n" if args[0] == "describe" else "abc\n"
effects = dataclasses.replace(FakeEffects().effects(), git=git)
loop, route, archive = a_loop(effects), Route(Rung("claude-opus-5-5", "xhigh"), 3, 4, 5), pathlib.Path("/t/r")
prompts = WorkerPrompts("a-driver", lambda *args: "fresh", lambda *args: "resumed", lambda *args: "", "the sources", "the destinations", "the records named")
def taken_in(entries):
return TakenIn()
cycle = cycle_start.cycle_of(loop, self.ROUTING, route, archive, task="the task", facts="the facts", premises="the premises", records="the records", unfinished_evidence="the evidence", prompts=prompts, taken_in=taken_in)
self.assertEqual(cycle, Cycle(config="v0.1.0 (abc)", effects=effects, facts="the facts", judge=Rung("judge-model"), premises="the premises", project=OPUS_PROJECT, project_archive=archive, records="the records", root="/r",
route=route, session=loop.session, task="the task", prompts=prompts, taken_in=taken_in, unfinished_evidence="the evidence", window=loop.window))
self.assertEqual(asked, ["/h/.claude", "/h/.claude"])
class Routes(unittest.TestCase):
OPUS = Rung("claude-opus-5-5", "medium")
SONNET = Rung("claude-sonnet-5-5", "high")