Answer architecture round 1: 2 🔴, 4 🟡 (0 misread); one branch_chunks reader with a pure fix rule, routed chunks matched by item
This commit is contained in:
@@ -14,18 +14,19 @@ import unittest
|
||||
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
||||
|
||||
from routing_figures import archive
|
||||
from branch_chunks.cut import BranchChunk
|
||||
from routing_figures.measure import calls, Chunk, ChunkFigures, due, measured, render, Reports, Subagent, totals
|
||||
from failure import Failure
|
||||
import git_repo
|
||||
from test_env import isolated_env
|
||||
from todo_table import Item
|
||||
from model_routing.ladder import LADDER, Rung
|
||||
from score_outcomes.later_fixes import Landed
|
||||
from transcript_archive import outcomes, write
|
||||
from model_routing.route import Route
|
||||
|
||||
LOW = Rung("claude-opus-5-5", "medium")
|
||||
HIGH = Rung("claude-opus-5-5", "high")
|
||||
LOW_ROUTE = Route(LOW, 7, 3, 4).worker_line()
|
||||
ROUND = "Answer stability round 1: 0 🔴, 0 🟡"
|
||||
|
||||
|
||||
def message(id_, at, *parts, model="claude-opus-5-5", usage=None):
|
||||
@@ -45,10 +46,6 @@ def result(id_, text):
|
||||
return {"type": "user", "message": {"content": [{"type": "tool_result", "tool_use_id": id_, "content": [{"type": "text", "text": text}]}]}}
|
||||
|
||||
|
||||
def commit(id_, title):
|
||||
return message(id_, "2026-10-14T10:00:00Z", call("Bash", command=f"git commit -m '{title}'"))
|
||||
|
||||
|
||||
def stamped(at, outcome):
|
||||
return f"{at} {outcome}\n"
|
||||
|
||||
@@ -57,6 +54,15 @@ def figures(start=LOW, rounds=0, unfinished=0, reports=None, escalated=None):
|
||||
return ChunkFigures({}, start, rounds, unfinished, collections.Counter(), reports or {}, collections.Counter(escalated or {}), 0.0)
|
||||
|
||||
|
||||
def shipping(*items, fixed_by=()):
|
||||
"""A chunk on a default branch that shipped the items with these IDs."""
|
||||
return BranchChunk("before", "tip", "abc1234", "merge", "2026-10-14T11:00:00Z", (), tuple(Item(id_, (0, 1, 0), "", f"**Item {id_}.**", {}, (), ()) for id_ in items), fixed_by)
|
||||
|
||||
|
||||
def no_checkout(*args, **options):
|
||||
return Failure("no checkout")
|
||||
|
||||
|
||||
class Measured(unittest.TestCase):
|
||||
def test_prices_each_message_once_by_project_type_rung_and_the_tool_it_followed(self):
|
||||
worker = [
|
||||
@@ -96,18 +102,19 @@ class Measured(unittest.TestCase):
|
||||
self.assertEqual(measured(Chunk("log", [], worker, []), "/h").escalated, {2: 2, 3: 1})
|
||||
|
||||
def test_counts_review_rounds_past_each_passs_first_once_per_title(self):
|
||||
commit = lambda id_, title: message(id_, "2026-10-14T10:00:00Z", call("Bash", command=f"git commit -m '{title}'"))
|
||||
worker = [commit("m1", "Answer stability round 1: 1 🔴, 0 🟡"), commit("m2", "Answer stability round 2: 0 🔴, 0 🟡"), commit("m3", "Answer stability round 2: 0 🔴, 0 🟡"), commit("m4", "Answer prose round 1: 0 🔴, 1 🟡")]
|
||||
self.assertEqual(measured(Chunk("log", [], worker, []), "/h").rounds_past_first, 1)
|
||||
|
||||
def test_counts_the_later_fixes_of_the_landed_chunks_holding_a_title_of_the_workers_commits_no_other_holds(self):
|
||||
worker = [commit("m1", "Ship it"), commit("m2", ROUND)]
|
||||
fixed_later = lambda *history: measured(Chunk("log", [], worker, []), "/h", list(history)).fixed_later
|
||||
self.assertEqual(fixed_later(Landed("b", "2026-10-14T11:00:00Z", frozenset({ROUND}), ("c", "d", "e")), Landed("a", "2026-10-14T10:30:00Z", frozenset({"Ship it", ROUND}), ("c", "d"))), 2)
|
||||
self.assertEqual(fixed_later(Landed("a", "2026-10-14T10:30:00Z", frozenset({"Ship it"}), ())), 0)
|
||||
self.assertEqual(fixed_later(Landed("a", "2026-10-14T10:30:00Z", frozenset({"Ship it"}), ("c", "d")), Landed("b", "2026-10-14T10:20:00Z", frozenset({ROUND}), ("d", "a"))), 2)
|
||||
self.assertIsNone(fixed_later(Landed("b", "2026-10-14T11:00:00Z", frozenset({"Ship it"}), ("c",)), Landed("a", "2026-10-14T10:30:00Z", frozenset({"Ship it"}), ())))
|
||||
self.assertIsNone(fixed_later(Landed("a", "2026-10-14T10:30:00Z", frozenset({"Other"}), ())))
|
||||
self.assertIsNone(measured(Chunk("log", [], worker, []), "/h").fixed_later)
|
||||
def test_counts_the_later_fixes_of_the_chunk_that_shipped_the_item_its_route_names(self):
|
||||
routed = [stamped("2026-10-14T10:00:00Z", outcomes.finished(LOW_ROUTE, "m", "j"))]
|
||||
fixed_later = lambda kept, *history: measured(Chunk("log", kept, [], []), "/h", list(history)).fixed_later
|
||||
self.assertEqual(fixed_later(routed, shipping(6, fixed_by=("c", "d", "e")), shipping(5, 7, fixed_by=("c", "d"))), 2)
|
||||
self.assertEqual(fixed_later(routed, shipping(7)), 0)
|
||||
self.assertIsNone(fixed_later(routed, shipping(8, fixed_by=("c",))))
|
||||
self.assertIsNone(fixed_later(routed))
|
||||
self.assertIsNone(measured(Chunk("log", routed, [], []), "/h").fixed_later)
|
||||
self.assertIsNone(fixed_later([stamped("2026-10-14T10:00:00Z", outcomes.finished(Route(LOW).worker_line(), "m", "j"))], shipping(7, fixed_by=("c",))))
|
||||
|
||||
def test_reads_the_route_of_a_line_loop_claude_wrote_before_it_archived_json(self):
|
||||
older = f"{LOW}, routed by item 7's L of 3 and E + I of 4"
|
||||
@@ -251,10 +258,10 @@ class Calls(unittest.TestCase):
|
||||
|
||||
def test_renders_the_median_later_fixes_of_the_matched_chunks_and_names_each_history_unread(self):
|
||||
matched = [dataclasses.replace(figures(), fixed_later=fixed) for fixed in (0, 3)]
|
||||
text = render(totals([*matched, figures()], unread=("log: no main branch",)), [], "2026-10-15T00:00:00Z", 40, "")
|
||||
text = render(totals([*matched, figures(), figures(start=None)], unread=("log: no main branch",)), [], "2026-10-15T00:00:00Z", 40, "")
|
||||
self.assertIn(f"| {LOW} | 3 | 0.0 | 0.0 | 1.5 | | |", text)
|
||||
self.assertIn("as `score-outcomes` counts them", text)
|
||||
self.assertIn("The later fixes of 1 of the chunks are unknown", text)
|
||||
self.assertIn("The later fixes of 1 of the routed chunks are unknown", text)
|
||||
self.assertIn("## Project histories unread\n\n- log: no main branch\n", text)
|
||||
self.assertNotIn("are unknown", render(totals(matched), [], "2026-10-15T00:00:00Z", 40, ""))
|
||||
self.assertNotIn("histories unread", render(totals(matched), [], "2026-10-15T00:00:00Z", 40, ""))
|
||||
@@ -288,10 +295,10 @@ class Archive(unittest.TestCase):
|
||||
def test_measures_each_finished_chunk_keyed_by_its_project(self):
|
||||
self.chunk("home/x", "c1", stamped("2026-10-14T10:00:00Z", outcomes.finished(LOW_ROUTE, "m", "j")), [message("m1", "2026-10-14T09:00:00Z", call("Agent", "a1", subagent_type="Explore"))], ({"agentType": "Explore", "toolUseId": "a1"}, [message("s1", "2026-10-14T09:00:01Z")]))
|
||||
self.chunk("log", "c2", stamped("2026-10-14T10:00:00Z", outcomes.unfinished(LOW_ROUTE, "e", "j", "")), [message("m1", "2026-10-14T09:00:00Z")])
|
||||
found = archive.measure_archive(self.root, "/h", "")
|
||||
found = archive.measure_archive(self.root, "/h", "", no_checkout)
|
||||
self.assertEqual([chunk.dollars["project"] for chunk in found.chunks], [{"home/x": 4.0}])
|
||||
self.assertEqual(found.chunks[0].dollars["subagent type"], {"worker": 2.0, "Explore": 2.0})
|
||||
self.assertEqual(archive.measure_archive(self.root, "/h", "2026-10-14T10:00:00Z"), archive.Measured([], ()))
|
||||
self.assertEqual(archive.measure_archive(self.root, "/h", "2026-10-14T10:00:00Z", no_checkout), archive.Measured([], ()))
|
||||
|
||||
def test_counts_each_chunks_later_fixes_from_its_projects_checkout_and_names_each_history_it_cannot_read(self):
|
||||
home = self.root / "home"
|
||||
@@ -309,16 +316,17 @@ class Archive(unittest.TestCase):
|
||||
git("commit", "-q", "-m", title)
|
||||
git("switch", "-q", "main")
|
||||
git("merge", "-q", "--no-ff", "-m", f"Merge {branch}", branch)
|
||||
fix = "| 6 | 0.1.0 | | defect | **Fix six.** | 1 | 1 | 1 | 1 | 2 | 1.1 by 3 | 1.0 |\n"
|
||||
git("init", "-q", "-b", "main")
|
||||
(checkout / "todo.md").write_text(plan("| 6 | 0.1.0 | | defect | **Fix six.** | 1 | 1 | 1 | 1 | 2 | 1.1 by 3 | 1.0 |\n"))
|
||||
(checkout / "todo.md").write_text(plan("| 7 | 0.1.0 | | | **Ship seven.** | 1 | 1 | 1 | 1 | 2 | 1.1 by 3 | 1.0 |\n" + fix))
|
||||
(checkout / "a.py").write_text("1\n")
|
||||
git("add", "todo.md", "a.py")
|
||||
git("commit", "-q", "-m", "Start")
|
||||
merge("ship", "Ship it", {"a.py": "1\nx\n"})
|
||||
merge("ship", "Ship seven", {"a.py": "1\nx\n", "todo.md": plan(fix)})
|
||||
merge("fix", "Fix six", {"a.py": "1\ny\n", "todo.md": plan("")})
|
||||
self.chunk("log", "c1", stamped("2026-10-14T10:00:00Z", outcomes.finished(LOW_ROUTE, "m", "j")), [commit("m1", "Ship it")])
|
||||
self.chunk("gone", "c1", stamped("2026-10-14T10:00:00Z", outcomes.finished(LOW_ROUTE, "m", "j")), [commit("m1", "Ship it")])
|
||||
found = archive.measure_archive(self.root, str(home), "")
|
||||
self.chunk("log", "c1", stamped("2026-10-14T10:00:00Z", outcomes.finished(LOW_ROUTE, "m", "j")), [message("m1", "2026-10-14T09:00:00Z")])
|
||||
self.chunk("gone", "c1", stamped("2026-10-14T10:00:00Z", outcomes.finished(LOW_ROUTE, "m", "j")), [message("m1", "2026-10-14T09:00:00Z")])
|
||||
found = archive.measure_archive(self.root, str(home), "", git_repo.git)
|
||||
self.assertEqual([(chunk.dollars["project"].keys(), chunk.fixed_later) for chunk in found.chunks], [({"gone": 0}.keys(), None), ({"log": 0}.keys(), 1)])
|
||||
(unread,) = found.unread
|
||||
self.assertTrue(unread.startswith("gone: "), unread)
|
||||
@@ -332,7 +340,7 @@ class Archive(unittest.TestCase):
|
||||
self.assertIsNone(write.archive(kept / "log", str(transcript), "t", outcomes.unfinished(LOW_ROUTE, "e", "j", ""), 1790000000))
|
||||
transcript.write_text(json.dumps(first) + "\n" + json.dumps(message("m2", "2099-01-01T00:00:00Z")) + "\n")
|
||||
self.assertIsNone(write.archive(kept / "log", str(transcript), "t", outcomes.finished(Route(HIGH).worker_line(), "m", "j"), 4070908800))
|
||||
(found,) = archive.measure_archive(kept, "/h", "").chunks
|
||||
(found,) = archive.measure_archive(kept, "/h", "", no_checkout).chunks
|
||||
self.assertEqual((found.start, found.unfinished), (LOW, 1))
|
||||
self.assertEqual(found.dollars["rung"], {str(LOW): 2.0, str(HIGH): 2.0})
|
||||
|
||||
@@ -342,7 +350,7 @@ class Archive(unittest.TestCase):
|
||||
self.chunk("other", "c2", stamped("2026-10-14T10:00:00Z", outcomes.finished(LOW_ROUTE, "m", "j")), [message("m1", "2026-10-14T09:00:00Z")])
|
||||
self.chunk("broken", "c3", "", [])
|
||||
(self.root / "broken" / "c3" / "copy.outcomes.md").write_bytes(b"\xff")
|
||||
found = archive.measure_archive(self.root, "/h", "")
|
||||
found = archive.measure_archive(self.root, "/h", "", no_checkout)
|
||||
self.assertEqual((len(found.chunks), found.skipped), (1, ("broken", "log/c1")))
|
||||
self.assertIn("## Chunks skipped, unreadable\n\n- log/c1\n", render(totals([], ("log/c1",)), [], "2026-10-15T00:00:00Z", 20, ""))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user