Kill the mutants that survived on the lines the release review changed
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import contextlib
|
||||
import dataclasses
|
||||
import fcntl
|
||||
import io
|
||||
import json
|
||||
import pathlib
|
||||
import sys
|
||||
@@ -24,6 +26,52 @@ class Overridden(unittest.TestCase):
|
||||
self.assertEqual(model_choice.overridden({"LOOP_CLAUDE_JUDGE_MODEL": "j", "LOOP_CLAUDE_WORKER_MODEL": "w"}, "saved"), model_choice.Models("j", "w"))
|
||||
|
||||
|
||||
class ModelsOfARun(unittest.TestCase):
|
||||
def setUp(self):
|
||||
temp = tempfile.TemporaryDirectory()
|
||||
self.addCleanup(temp.cleanup)
|
||||
self.paths = paths_from(pathlib.Path(temp.name))
|
||||
self.paths.models_file.parent.mkdir()
|
||||
|
||||
def test_a_run_that_names_both_models_reads_no_models_file_and_asks_nothing(self):
|
||||
self.paths.models_file.write_text("not json")
|
||||
fake = FakeEffects()
|
||||
env = {"LOOP_CLAUDE_JUDGE_MODEL": "j", "LOOP_CLAUDE_WORKER_MODEL": "w"}
|
||||
self.assertEqual(model_choice.get_or_ask_models("proj", self.paths, env, LOOP_CLAUDE, fake.effects()), model_choice.Models("j", "w"))
|
||||
self.assertEqual(fake.calls, [])
|
||||
|
||||
def test_a_run_that_names_one_model_takes_the_other_from_the_models_file(self):
|
||||
self.paths.models_file.write_text(json.dumps({"proj": "saved"}))
|
||||
fake = FakeEffects()
|
||||
self.assertEqual(model_choice.get_or_ask_models("proj", self.paths, {"LOOP_CLAUDE_JUDGE_MODEL": "j"}, LOOP_CLAUDE, fake.effects()), model_choice.Models("j", "saved"))
|
||||
self.assertEqual(model_choice.get_or_ask_models("proj", self.paths, {"LOOP_CLAUDE_WORKER_MODEL": "w"}, LOOP_CLAUDE, fake.effects()), model_choice.Models("saved", "w"))
|
||||
self.assertEqual(fake.calls, [])
|
||||
|
||||
def test_a_run_that_names_one_model_asks_for_the_projects_where_none_is_saved_and_saves_the_pick(self):
|
||||
fake, said = FakeEffects(inputs=["my-model"]), io.StringIO()
|
||||
with contextlib.redirect_stderr(said):
|
||||
models = model_choice.get_or_ask_models("proj", self.paths, {"LOOP_CLAUDE_JUDGE_MODEL": "j"}, LOOP_CLAUDE, fake.effects())
|
||||
self.assertEqual(models, model_choice.Models("j", "my-model"))
|
||||
self.assertEqual(json.loads(self.paths.models_file.read_text()), {"proj": "my-model"})
|
||||
self.assertIn(" proj runs on my-model\n", said.getvalue())
|
||||
|
||||
def test_off_a_terminal_it_stops_naming_the_driver_to_rerun_and_the_file_to_merge_the_model_into(self):
|
||||
fake = FakeEffects(on_terminal=False)
|
||||
stop = model_choice.get_or_ask_models("proj", self.paths, {}, LOOP_CLAUDE, fake.effects())
|
||||
assert isinstance(stop, Stop)
|
||||
self.assertEqual(stop.code, 2)
|
||||
self.assertIn(f"pick proj's model, or merge {{\"proj\": \"<model>\"}} into {self.paths.models_file}", stop.reason)
|
||||
self.assertIn(LOOP_CLAUDE, stop.reason)
|
||||
self.assertFalse(self.paths.models_file.exists())
|
||||
|
||||
def test_stops_with_exit_1_where_the_models_file_maps_no_projects_to_model_names(self):
|
||||
for held in ("[]", '{"proj": 5}', '{"proj": ""}'):
|
||||
with self.subTest(held=held):
|
||||
self.paths.models_file.write_text(held)
|
||||
stop = model_choice.get_or_ask_models("proj", self.paths, {}, LOOP_CLAUDE, FakeEffects().effects())
|
||||
self.assertEqual(stop, Stop(1, f"could not read {self.paths.models_file}: not an object mapping projects to model names"))
|
||||
|
||||
|
||||
class SavingAModel(unittest.TestCase):
|
||||
def setUp(self):
|
||||
temp = tempfile.TemporaryDirectory()
|
||||
@@ -37,6 +85,12 @@ class SavingAModel(unittest.TestCase):
|
||||
self.assertIsNone(model_choice.save_model("proj", "model-b", self.paths, replace_file))
|
||||
self.assertEqual(json.loads(self.paths.models_file.read_text()), {"other": "model-x", "proj": "model-b"})
|
||||
|
||||
def test_writes_the_file_for_a_human_to_merge_into_a_project_per_tab_indented_line_in_the_order_of_their_keys(self):
|
||||
self.paths.models_file.parent.mkdir()
|
||||
self.paths.models_file.write_text(json.dumps({"zebra": "model-z", "other": "model-x"}))
|
||||
self.assertIsNone(model_choice.save_model("proj", "model-b", self.paths, replace_file))
|
||||
self.assertEqual(self.paths.models_file.read_text(), '{\n\t"other": "model-x",\n\t"proj": "model-b",\n\t"zebra": "model-z"\n}')
|
||||
|
||||
def lock_is_held(self) -> bool:
|
||||
with open(self.lock, "a") as other:
|
||||
try:
|
||||
@@ -91,6 +145,8 @@ class ModelPrompt(unittest.TestCase):
|
||||
|
||||
def test_reads_a_number_as_the_offered_model_and_anything_else_as_a_name(self):
|
||||
self.assertEqual(model_choice.model_picked(" 2 ", self.OFFERED), "claude-haiku-4-5")
|
||||
self.assertEqual(model_choice.model_picked("1", self.OFFERED), "claude-opus-5-5")
|
||||
self.assertEqual(model_choice.model_picked("0", self.OFFERED), Failure("pick 1 to 2"))
|
||||
self.assertEqual(model_choice.model_picked("opus", self.OFFERED), "opus")
|
||||
self.assertEqual(model_choice.model_picked("3", []), "3")
|
||||
self.assertEqual(model_choice.model_picked("3", self.OFFERED), Failure("pick 1 to 2"))
|
||||
|
||||
@@ -20,6 +20,7 @@ from text_files.file_writes import replace_file
|
||||
from model_routing.route import Route
|
||||
from agent_cycle import run
|
||||
from claude_code import session
|
||||
from agent_cycle.stop import Stop
|
||||
|
||||
OPUS_PROJECT = ProjectRung(read_ladder(SHIPPED), Rung("claude-opus-5-5", "medium"))
|
||||
|
||||
@@ -71,6 +72,33 @@ class Steps(unittest.TestCase):
|
||||
stop = chunk_run.closed_cycle(chunk_run.ChunkRun(cycle_number=1, task="Do it.", unfinished_evidence=""), OPUS_PROJECT, run.Concluded(Unfinished("working", taken_in=TakenIn(highest_likelihood=4)), before), blocked, "a-driver", a_loop(FakeEffects().effects(), session=opened))
|
||||
self.assertEqual((stop.code, stop.reason.split(":")[0]), (1, "could not archive the transcript"))
|
||||
|
||||
def outcomes_after(self, unfinished_run: int, taken_in: TakenIn) -> tuple[object, str]:
|
||||
"""What closed_cycle answers for a-driver's chunk `Do it.`, after an unfinished verdict that follows unfinished_run others, and the outcomes it archived for a transcript not archived before."""
|
||||
with tempfile.TemporaryDirectory() as home:
|
||||
opened = session.session_named("A proj a-driver", pathlib.Path(home, "projects"))
|
||||
archive = pathlib.Path(home, "archive")
|
||||
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")
|
||||
before = Route(self.FABLE_LOW, 3, 3, 4)
|
||||
with contextlib.redirect_stderr(io.StringIO()):
|
||||
closed = chunk_run.closed_cycle(chunk_run.ChunkRun(cycle_number=1, task="Do it.", unfinished_evidence="", unfinished_run=unfinished_run), OPUS_PROJECT, run.Concluded(Unfinished("working", taken_in=taken_in), before), archive, "a-driver", a_loop(FakeEffects().effects(), session=opened))
|
||||
return closed, "".join(file.read_text() for file in archive.rglob("*") if file.is_file() and file.suffix != ".jsonl")
|
||||
|
||||
def test_a_step_up_archived_first_for_its_transcript_names_the_chunks_task(self):
|
||||
closed, outcomes_kept = self.outcomes_after(0, TakenIn(highest_likelihood=4))
|
||||
self.assertEqual(closed.route.rung, self.FABLE_MEDIUM)
|
||||
self.assertIn("Do it.\n", outcomes_kept)
|
||||
|
||||
def test_the_sixth_unfinished_verdict_running_stops_for_the_human_naming_the_driver_to_rerun_and_archives_why_with_the_task(self):
|
||||
reason = "the human is needed to go on with the chunk, but the judge ruled it unfinished 6 cycles running; finish the chunk yourself, or rerun a-driver to give it 6 more cycles"
|
||||
closed, outcomes_kept = self.outcomes_after(5, TakenIn())
|
||||
self.assertEqual(closed, Stop(2, reason))
|
||||
self.assertIn("Do it.\n", outcomes_kept)
|
||||
self.assertIn(f"Stopped: {reason}\n", outcomes_kept)
|
||||
closed, outcomes_kept = self.outcomes_after(4, TakenIn())
|
||||
self.assertEqual((closed.unfinished_run, outcomes_kept), (5, ""))
|
||||
|
||||
def test_archives_a_higher_e_plus_i_taken_in_so_a_rerun_keeps_it(self):
|
||||
with tempfile.TemporaryDirectory() as home:
|
||||
opened = session.session_named("A proj a-driver", pathlib.Path(home, "projects"))
|
||||
|
||||
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user