Answer architecture round 3: 0 🔴, 1 🟡 (0 misread); every suite sits beside the module it tests, and test_loop_claude.py holds only loop-claude's own
CI / tests (pull_request) Successful in 5m17s

This commit is contained in:
2026-11-19 11:43:38 +01:00
parent df210aaeca
commit 9bc2887ee8
17 changed files with 503 additions and 380 deletions
+16
View File
@@ -0,0 +1,16 @@
"""Test doubles for the suites that drive a chunk: the loop of an entry point that exists only in tests."""
import pathlib
import typing
from loop_effects.effects import Effects
from chunk_driver.this_loop import Loop
from loop_state import paths
from claude_code import session
from agent_cycle.doubles import WINDOW
def a_loop(effects: Effects, **fields: typing.Any) -> Loop:
"""A loop in /r on effects, with fields in place of its defaults."""
home = pathlib.Path("/h")
defaults = {"root": "/r", "session": session.session_named("A proj a-driver", home / ".claude" / "projects"), "paths": paths.paths_from(home), "env": {}, "launcher": pathlib.Path("/b/a-driver"), "window": WINDOW}
return Loop(**{**defaults, **fields}, effects=effects)
+6
View File
@@ -8,6 +8,7 @@ sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[2]))
from project_config.test_project_config import configured
from failure import Failure
from agent_cycle import judge
from chunk_driver.project import records
@@ -86,5 +87,10 @@ class Records(unittest.TestCase):
self.assertEqual(records.read_records(root, claude_md.parents[1], claude_md.parent), Failure(f"todo-items.md in {rules} is not UTF-8 on line 1 - the judge cannot read the records."))
class JudgeRules(unittest.TestCase):
def test_the_judge_prompt_names_every_rule_the_judge_reads_from_the_human(self):
self.assertEqual([name for name in records.HUMAN_RULE_NAMES if name not in judge.judge_rules("the ledger", "a-driver")], [])
if __name__ == "__main__":
unittest.main()
+2 -10
View File
@@ -9,28 +9,20 @@ import unittest
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
from chunk_driver import chunk_run, cycle_start, this_loop
from chunk_driver.doubles import a_loop
from chunk_driver import chunk_run, cycle_start
from loop_effects.doubles import FakeEffects, NOW
from agent_cycle.verdicts import Finished, TakenIn, Unfinished
from transcript_archive import outcomes, write
from loop_state import paths
from model_routing.ladder import ProjectRung, Rung
from model_routing.ladder_file import read_ladder, SHIPPED
from model_routing.route import Route
from agent_cycle import run
from claude_code import session
from agent_cycle.test_tmux import WINDOW
OPUS_PROJECT = ProjectRung(read_ladder(SHIPPED), Rung("claude-opus-5-5", "medium"))
def a_loop(effects, **fields):
"""A loop in /r on effects, with fields in place of its defaults."""
home = pathlib.Path("/h")
defaults = {"root": "/r", "session": session.session_named("A proj a-driver", home / ".claude" / "projects"), "paths": paths.paths_from(home), "env": {}, "launcher": pathlib.Path("/b/a-driver"), "window": WINDOW}
return this_loop.Loop(**{**defaults, **fields}, effects=effects)
class Steps(unittest.TestCase):
OPUS = Rung("claude-opus-5-5", "medium")
# The rungs an L 3 and an L 4 pick from OPUS.
+62
View File
@@ -1,15 +1,28 @@
import contextlib
import io
import json
import os
import pathlib
import sys
import tempfile
import types
import unittest
import unittest.mock
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
from chunk_driver.doubles import a_loop
from chunk_driver import cycle_start
from failure import Failure
from loop_effects.doubles import FakeEffects, NOW, STAMP
from git_cli.git_repo import git
from transcript_archive import outcomes, write
from model_routing.ladder import ProjectRung, Rung
from model_routing.ladder_file import read_ladder, SHIPPED
from model_routing.route import Route, WorkerLine
from claude_code import session
OPUS_PROJECT = ProjectRung(read_ladder(SHIPPED), Rung("claude-opus-5-5", "medium"))
class SetupVersion(unittest.TestCase):
@@ -36,5 +49,54 @@ class SetupVersion(unittest.TestCase):
self.assertEqual(cycle_start.setup_version(pathlib.Path("/r"), fake_git), "unknown: fatal: bad HEAD hint: repair it")
class Routes(unittest.TestCase):
OPUS = Rung("claude-opus-5-5", "medium")
SONNET = Rung("claude-sonnet-5-5", "high")
def test_keeps_a_chunks_route_or_its_archived_one_at_or_above_the_rung_its_item_picks_and_else_routes_afresh(self):
item = types.SimpleNamespace(id=3, likelihood=4, escape_and_impact=5)
archived = Route(Rung("claude-opus-5-5", "xhigh"), 3, 4, 5)
def never():
raise AssertionError("not asked")
self.assertEqual(cycle_start.routed(archived, None, "worker-model", never, never), Route(Rung("worker-model")))
self.assertEqual(cycle_start.routed(archived, OPUS_PROJECT, "claude-opus-5-5", never, never), archived)
self.assertEqual(cycle_start.routed(None, OPUS_PROJECT, "claude-opus-5-5", lambda: archived, never), archived)
self.assertEqual(cycle_start.routed(None, OPUS_PROJECT, "claude-opus-5-5", lambda: None, lambda: item), Route(Rung("claude-fable-5-2", "medium"), 3, 4, 5))
self.assertEqual(cycle_start.routed(Route(self.SONNET), OPUS_PROJECT, "claude-opus-5-5", never, lambda: None), Route(self.OPUS))
cheap = Route(self.SONNET, 4, 2, 3)
self.assertEqual(cycle_start.routed(cheap, OPUS_PROJECT, "claude-opus-5-5", never, never), cheap)
self.assertEqual(cycle_start.routed(Route(Rung("claude-haiku-5-5", "max"), 4, 2, 3), OPUS_PROJECT, "claude-opus-5-5", never, lambda: None), Route(self.OPUS))
def test_resumes_on_the_archived_route_and_says_why_it_routes_afresh(self):
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")
route = Route(Rung("claude-fable-5-2", "low"), 3, 4, 5)
with contextlib.redirect_stderr(io.StringIO()) as stderr:
self.assertIsNone(cycle_start.archived_route(archive, a_loop(FakeEffects().effects(), session=opened)))
transcript.parent.mkdir(parents=True)
transcript.write_text(json.dumps({"type": "queue-operation", "timestamp": "1"}) + "\n")
self.assertIsNone(cycle_start.archived_route(archive, a_loop(FakeEffects().effects(), session=opened)))
with contextlib.redirect_stderr(io.StringIO()):
self.assertIsNone(write.archive(archive, str(transcript), "Do it.", outcomes.unfinished(route.worker_line(), "working", "j", ""), NOW))
with contextlib.redirect_stderr(stderr):
self.assertEqual(cycle_start.archived_route(archive, a_loop(FakeEffects().effects(), session=opened)), route)
self.assertEqual(stderr.getvalue(), "")
with contextlib.redirect_stderr(io.StringIO()):
self.assertIsNone(write.archive(archive, str(transcript), "Do it.", outcomes.stepped_up(WorkerLine('{"model": "claude-opus-5-5", "rung": 3}')), NOW + 1))
with contextlib.redirect_stderr(io.StringIO()) as stderr:
self.assertIsNone(cycle_start.archived_route(archive, a_loop(FakeEffects().effects(), session=opened)))
self.assertEqual(stderr.getvalue(), f'{STAMP} routing the chunk afresh: the archive\'s latest Worker: line names no route that can be read: {{"model": "claude-opus-5-5", "rung": 3}}\n')
(chunk,) = archive.iterdir()
chunk.chmod(0)
try:
with contextlib.redirect_stderr(io.StringIO()) as stderr:
self.assertIsNone(cycle_start.archived_route(archive, a_loop(FakeEffects().effects(), session=opened)))
finally:
chunk.chmod(0o700)
self.assertTrue(stderr.getvalue().startswith(f"{STAMP} routing the chunk afresh: could not read the archive"), stderr.getvalue())
if __name__ == "__main__":
unittest.main()
+120
View File
@@ -0,0 +1,120 @@
import pathlib
import sys
import unittest
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
from model_routing.ladder import ProjectRung, Rung
from chunk_driver import prompts
from model_routing.ladder_file import read_ladder, SHIPPED
from model_routing.route import Route
LADDER = read_ladder(SHIPPED)
# The ladder's rungs around the project's: the one below it, its own, and those one to three steps up.
SONNET = Rung("claude-sonnet-5-5", "high")
OPUS = Rung("claude-opus-5-5", "medium")
FABLE_LOW = Rung("claude-fable-5-2", "low")
FABLE_MEDIUM = Rung("claude-fable-5-2", "medium")
OPUS_XHIGH = Rung("claude-opus-5-5", "xhigh")
OPUS_PROJECT = ProjectRung(LADDER, OPUS)
# The sentence with which an entry point that exists only here asks its worker to name the chunk's items.
NAMING = "Name the items."
SCAN = " Run a full scan only from such a subagent, since the scan's agents run on the model that starts them."
SEATS = " Launch each comprehension seat and the security pass's subagent with the Agent tool set to model opus, effort medium, the project's rung."
MARKDOWN = " Where your branch changes only Markdown, none of it `CLAUDE.md`, `AGENTS.md`, `workflow-bench/*-prompt.md` or under `agents/`, `principles/`, `rules/` or `skills/`, launch each reviewer on the project's rung instead, with the Agent tool set to model opus, effort medium."
def held(route, project=OPUS_PROJECT):
"""The rung sentences a-driver's worker reads on route, each after a space."""
return prompts.rungs_held("a-driver", route, project)
def resumed(route, project=OPUS_PROJECT):
"""The prompt that resumes a-driver's worker on route, with no evidence of work remaining."""
return prompts.resumed("a-driver", NAMING, "", route, project)
class Resumed(unittest.TestCase):
def test_resumes_the_worker_saying_when_the_chunk_is_finished(self):
self.assertTrue(resumed(Route(Rung("m")), None).startswith("Continue the task; the previous run ended before the chunk was finished. The chunk is finished once"))
class ReviewLaunches(unittest.TestCase):
def test_keeps_every_review_on_the_projects_rung_while_the_worker_runs_below_it(self):
below = held(Route(SONNET, 3, 2, 4))
self.assertTrue(below.startswith(f" Launch each reviewer, each comprehension seat and the security pass's subagent with the Agent tool set to model opus, effort medium, the project's rung.{SCAN} Your rung is below the project's: launch each subagent that files or scores plan items on the rung `~/.claude/bin/subagent-rung --plan claude-opus-5-5 <L>` prints. Where an item you take into the chunk has an E + I of 5 or more, launch each reviewer with the Agent tool set to `model fable, effort low` from 5, `model fable, effort medium` from 6, `model opus, effort xhigh` from 7 and `model fable, effort high` from 8. When an escalation trigger"), below)
self.assertNotIn("Launch each", held(Route(OPUS, 3, 2, 4)))
def test_launches_reviewers_on_the_rung_the_items_e_plus_i_picks_above_the_workers(self):
level = held(Route(OPUS, 3, 2, 6))
self.assertTrue(level.startswith(f" Launch each reviewer with the Agent tool set to model fable, effort medium, the rung item 3's E + I of 6 picks. Where an item you take into the chunk has an E + I of 7 or more, launch each reviewer with the Agent tool set to `model opus, effort xhigh` from 7 and `model fable, effort high` from 8.{MARKDOWN} When an escalation trigger"), level)
below = held(Route(SONNET, 3, 2, 5))
self.assertTrue(below.startswith(f" Launch each reviewer with the Agent tool set to model fable, effort low, the rung item 3's E + I of 5 picks.{SEATS}{SCAN} Your rung is below the project's:"), below)
self.assertNotIn("Launch each reviewer", held(Route(FABLE_MEDIUM, 3, 4, 6)))
def test_names_the_reviewers_rung_each_higher_e_plus_i_an_item_taken_in_picks(self):
taking_in = " Where an item you take into the chunk has an E + I of 5 or more, launch each reviewer with the Agent tool set to `model fable, effort low` from 5, `model fable, effort medium` from 6, `model opus, effort xhigh` from 7 and `model fable, effort high` from 8."
self.assertTrue(held(Route(OPUS, 3, 2, 4)).startswith(f"{taking_in} When an escalation trigger"))
self.assertIn(" Where an item you take into the chunk has an E + I of 7 or more, launch each reviewer with the Agent tool set to `model opus, effort xhigh` from 7 and `model fable, effort high` from 8.", held(Route(OPUS, 3, 2, 6)))
self.assertIn(" Where an item you take into the chunk has an E + I of 7 or more, launch each reviewer with the Agent tool set to `model opus, effort xhigh` from 7 and `model fable, effort high` from 8.", held(Route(FABLE_MEDIUM, 3, 4, 4)))
self.assertNotIn("Where an item you take into", held(Route(OPUS, 3, 2, 8)))
self.assertNotIn("Where an item you take into", held(Route(Rung("m")), None))
def test_launches_reviewers_on_the_rung_the_highest_e_plus_i_taken_in_picks(self):
self.assertIn(f"a-driver runs you on claude-opus-5-5 at medium effort. Launch each reviewer with the Agent tool set to model opus, effort xhigh, the rung picked by an item of E + I 7 taken into the chunk. Where an item you take into the chunk has an E + I of 8 or more, launch each reviewer with the Agent tool set to `model fable, effort high` from 8.{MARKDOWN} When an escalation trigger", resumed(Route(OPUS, 3, 2, 5, escape_and_impact_taken_in=7)))
self.assertIn(" Launch each reviewer with the Agent tool set to model fable, effort low, the rung picked by an item of E + I 5 taken into the chunk.", held(Route(OPUS, escape_and_impact_taken_in=5)))
def test_keeps_seats_and_the_security_pass_on_the_projects_rung_while_the_worker_runs_above_it(self):
above = Route(FABLE_LOW, 3, 3, 4)
sentences = f"{SEATS}{SCAN} Where an item you take into the chunk has an E + I of 6 or more, launch each reviewer with the Agent tool set to `model fable, effort medium` from 6, `model opus, effort xhigh` from 7 and `model fable, effort high` from 8.{MARKDOWN} When an escalation trigger"
self.assertIn(f"{prompts.ANSWERS_RECORDED}. {NAMING} a-driver runs you on claude-fable-5-2 at low effort.{sentences}", resumed(above))
self.assertNotIn("the project's", resumed(Route(OPUS, 3, 2, 4)))
self.assertNotIn("runs you on", resumed(Route(Rung("m")), None))
self.assertTrue(held(above).startswith(sentences), held(above))
def test_lets_a_markdown_only_branch_review_on_the_projects_rung_where_the_reviewers_run_above_it(self):
self.assertIn(MARKDOWN, held(Route(OPUS, 3, 2, 7)))
self.assertIn(MARKDOWN, held(Route(FABLE_LOW, 3, 3, 4)))
self.assertNotIn("only Markdown", held(Route(OPUS, 3, 2, 4)))
class Escalation(unittest.TestCase):
def test_names_the_rungs_an_escalation_trigger_lets_the_worker_hand_a_task_to_at_most_two_above_its_items(self):
routed = held(Route(OPUS, 3, 2, 4))
self.assertTrue(routed.startswith(" Where an item you take into the chunk has an E + I of 5 or more, launch each reviewer with the Agent tool set to `model fable, effort low` from 5, `model fable, effort medium` from 6, `model opus, effort xhigh` from 7 and `model fable, effort high` from 8. When an escalation trigger in `~/.claude/CLAUDE.md` fires, hand the hard part of the task to a subagent with the Agent tool set to `model fable, effort low`, one rung above yours; above that, ask the human first. Open the subagent's prompt with `Escalation trigger <n>:`, n the trigger's number."), routed)
self.assertIn(" When an escalation trigger in `~/.claude/CLAUDE.md` fires, hand the hard part of the task to a subagent with the Agent tool set to `model fable, effort medium`, one rung above yours, and on each further trigger one rung higher, up to `model opus, effort xhigh`; above that, ask the human first. Open the subagent's prompt with `Escalation trigger <n>:`, n the trigger's number.", held(Route(FABLE_LOW, 3, 3, 4)))
self.assertIn(" When an escalation trigger in `~/.claude/CLAUDE.md` fires, hand the hard part of the task to a subagent with the Agent tool set to `model opus, effort xhigh`, one rung above yours; above that, ask the human first. Open the subagent's prompt with `Escalation trigger <n>:`, n the trigger's number.", held(Route(FABLE_MEDIUM, 3, 3, 4)))
self.assertNotIn("escalation", held(Route(Rung("claude-fable-5-2", "max"), 3, 4, 8)))
self.assertIn(" An escalation trigger in `~/.claude/CLAUDE.md` lets you hand the hard part of a task to a subagent with the Agent tool set to `model fable, effort high`, one rung above yours, only once the human agrees; a-driver will not resume you higher for a trigger either, so ask the human for that yes.", held(Route(OPUS_XHIGH, 3, 3, 4)))
self.assertIn("set to `model fable, effort max`, one rung above yours, only once the human agrees;", held(Route(Rung("claude-fable-5-2", "high"), 3, 4, 5)), "one rung below the top still names the rung above")
self.assertNotIn("rerun", held(Route(Rung("claude-opus-5-5", "low"), 3, 3, 4)), "a worker off the ladder is told no rerun rung")
self.assertIn("hand the hard part of the task to a subagent with the Agent tool set to `model fable, effort high`, one rung above yours;", held(Route(OPUS_XHIGH, 3, 4, 5)))
self.assertNotIn("escalation", held(Route(Rung("m")), None))
self.assertNotIn("escalation", held(Route(Rung("claude-opus-5-5", "low"), 3, 3, 4)))
unrouted = held(Route(OPUS))
self.assertTrue(unrouted.startswith(" Where an item you take into the chunk has an E + I of 5 or more, launch each reviewer with the Agent tool set to `model fable, effort low` from 5, `model fable, effort medium` from 6, `model opus, effort xhigh` from 7 and `model fable, effort high` from 8. When an escalation trigger in `~/.claude/CLAUDE.md` fires, hand the hard part of the task to a subagent with the Agent tool set to `model fable, effort low`, one rung above yours, and on each further trigger one rung higher, up to `model fable, effort medium`; above that, ask the human first. Open the subagent's prompt with `Escalation trigger <n>:`, n the trigger's number. Where the hard part is the rest of the chunk, end your run instead, asking a-driver for a higher rung and naming a trigger that fired since your last step-up, if any: once the judge finds it in your transcript, the next cycle resumes you one rung up, up to `model fable, effort medium`. A reviewer"), unrouted)
def test_offers_the_worker_a_higher_rung_for_the_rest_of_the_chunk_up_to_the_escalation_cap(self):
offer = lambda cap: f" Where the hard part is the rest of the chunk, end your run instead, asking a-driver for a higher rung and naming a trigger that fired since your last step-up, if any: once the judge finds it in your transcript, the next cycle resumes you one rung up, up to `{cap}`."
self.assertIn(f"`Escalation trigger <n>:`, n the trigger's number.{offer('model fable, effort low')}", held(Route(OPUS, 3, 2, 4)))
self.assertIn(f"`Escalation trigger <n>:`, n the trigger's number.{offer('model opus, effort xhigh')}", held(Route(FABLE_LOW, 3, 3, 4)))
self.assertNotIn("Where the hard part", held(Route(OPUS_XHIGH, 3, 3, 4)))
class Reruns(unittest.TestCase):
def test_names_the_rung_a_reviewer_or_seat_reruns_on_one_above_its_own(self):
both = " A reviewer or comprehension seat that asks for a rerun one rung up reruns with the Agent tool set to `model fable, effort low`."
self.assertTrue(resumed(Route(OPUS, 3, 2, 4)).endswith(both))
self.assertTrue(resumed(Route(SONNET, 3, 2, 4)).endswith(both))
self.assertTrue(held(Route(OPUS)).endswith(both))
self.assertTrue(resumed(Route(FABLE_LOW, 3, 3, 4)).endswith(" A reviewer that asks for a rerun one rung up reruns with the Agent tool set to `model fable, effort medium`, and a comprehension seat with `model fable, effort low`."))
self.assertTrue(resumed(Route(OPUS, 3, 2, 7)).endswith(" A reviewer that asks for a rerun one rung up reruns with the Agent tool set to `model fable, effort high`, and a comprehension seat with `model fable, effort low`."))
self.assertTrue(resumed(Route(Rung("claude-fable-5-2", "max"), 3, 4, 8)).endswith(" A comprehension seat that asks for a rerun one rung up reruns with the Agent tool set to `model fable, effort low`."))
self.assertNotIn("rerun", resumed(Route(Rung("m")), None))
self.assertNotIn("rerun", held(Route(Rung("m", "high"), 3, 4, 5), None))
fable = Rung("claude-fable-5-2", "max")
self.assertNotIn("rerun", resumed(Route(fable), ProjectRung(LADDER, fable)))
if __name__ == "__main__":
unittest.main()