Answer principles round 1: 0 🔴, 4 🟡 (0 misread); stage types for the cut and shipped chunks, one text_at, the path rule in the core, a parse that fails as a value

This commit is contained in:
2026-10-28 21:51:59 +01:00
parent f7532827db
commit d967219f7e
10 changed files with 280 additions and 146 deletions
+29 -24
View File
@@ -90,37 +90,42 @@ def measure_archive(root: pathlib.Path, home: str, since: str, git: Git) -> Meas
listed = archived_outcomes(root)
if isinstance(listed, Failure):
return listed
projects = sorted({root / key for key, _ in listed})
projects = [measure_project(root, project, home, since, git) for project in sorted({root / key for key, _ in listed})]
return Measured(
[chunk for project in projects for chunk in project.chunks],
tuple(skipped for project in projects for skipped in project.skipped),
tuple(unread for project in projects for unread in project.unread),
)
def measure_project(root: pathlib.Path, project: pathlib.Path, home: str, since: str, git: Git) -> Measured:
"""The figures of each of one project's chunks that finished after since, as measure_archive measures them."""
key = str(project.relative_to(root))
listed = finished_chunks(project)
if isinstance(listed, Failure):
return Measured([], (key,))
chunks = [chunk for chunk in listed if chunk.finished > since]
if not chunks:
return Measured([], ())
history = branch_history(checkout_of(key, pathlib.Path(home)), git)
found = []
skipped = []
unread = []
for project in projects:
key = str(project.relative_to(root))
chunks = finished_chunks(project)
if isinstance(chunks, Failure):
skipped.append(key)
for chunk in chunks:
folder = project / chunk.folder
try:
kept = [path.read_text(encoding="utf-8") for path in chunk_outcomes(folder)]
subagents = [subagent(path) for path in chunk.subagents]
worker = entries(chunk.transcript)
except (OSError, UnicodeDecodeError):
skipped.append(str(folder.relative_to(root)))
continue
chunks = [chunk for chunk in chunks if chunk.finished > since]
history = branch_history(checkout_of(key, pathlib.Path(home)), git) if chunks else None
if isinstance(history, Failure):
unread.append(f"{key}: {history.reason}")
history = None
for chunk in chunks:
folder = project / chunk.folder
try:
kept = [path.read_text(encoding="utf-8") for path in chunk_outcomes(folder)]
subagents = [subagent(path) for path in chunk.subagents]
worker = entries(chunk.transcript)
except (OSError, UnicodeDecodeError):
skipped.append(str(folder.relative_to(root)))
continue
found.append(measured(Chunk(key, kept, worker, subagents), home, history))
return Measured(found, tuple(skipped), tuple(unread))
found.append(measured(Chunk(key, kept, worker, subagents), home, None if isinstance(history, Failure) else history))
return Measured(found, tuple(skipped), (f"{key}: {history.reason}",) if isinstance(history, Failure) else ())
def branch_history(checkout: str, git: Git) -> list[BranchChunk] | Failure:
"""The chunks on the checkout's default branch as last fetched, read guarded, since the checkout's config may name a program."""
ref = default_ref(checkout, GIT_TIMEOUT, guarded=True, git=git)
ref = default_ref(checkout, GIT_TIMEOUT, guarded=True, run=git)
return ref if isinstance(ref, Failure) else branch_chunks(ref, functools.partial(git, cwd=checkout, timeout=GIT_TIMEOUT, guarded=True))
+12 -1
View File
@@ -247,7 +247,18 @@ def totals(chunks: list[ChunkFigures], skipped: tuple[str, ...] = (), unread: tu
routed.setdefault(chunk.start, []).append(chunk)
for kind, found in chunk.reports.items():
reports[kind] = reports.get(kind, Reports(0, 0, 0)) + found
return Figures(len(chunks), dollars, routed, reports, summed(chunks, lambda chunk: chunk.escalated), skipped, sum(chunk.unattributed for chunk in chunks), sum(chunk.lacking for chunk in chunks), sum(chunk.start is not None and chunk.fixed_later is None for chunk in chunks), unread)
return Figures(
chunks=len(chunks),
dollars=dollars,
routed=routed,
reports=reports,
escalated=summed(chunks, lambda chunk: chunk.escalated),
skipped=skipped,
unattributed=sum(chunk.unattributed for chunk in chunks),
lacking=sum(chunk.lacking for chunk in chunks),
unmatched=sum(chunk.start is not None and chunk.fixed_later is None for chunk in chunks),
unread=unread,
)
def calls(figures: Figures) -> list[str]:
+48 -24
View File
@@ -10,6 +10,7 @@ import subprocess
import sys
import tempfile
import unittest
import unittest.mock
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
@@ -63,6 +64,10 @@ def no_checkout(*args, **options):
return Failure("no checkout")
# Two routed chunks whose later fixes are known: 0 and 3.
MATCHED = [dataclasses.replace(figures(), fixed_later=fixed) for fixed in (0, 3)]
class Measured(unittest.TestCase):
def test_prices_each_message_once_by_project_type_rung_and_the_tool_it_followed(self):
worker = [
@@ -106,15 +111,25 @@ class Measured(unittest.TestCase):
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 fixed_later(self, history, route=LOW_ROUTE):
"""The later fixes measured counts for a chunk that route started, which LOW_ROUTE does by item 7, on a project whose default branch holds history, None where it could not be read."""
return measured(Chunk("log", [stamped("2026-10-14T10:00:00Z", outcomes.finished(route, "m", "j"))], [], []), "/h", history).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",))))
self.assertEqual(self.fixed_later([shipping(6, fixed_by=("c", "d", "e")), shipping(5, 7, fixed_by=("c", "d"))]), 2)
def test_counts_no_later_fix_where_no_later_chunk_fixed_the_chunk_that_shipped_the_item(self):
self.assertEqual(self.fixed_later([shipping(7)]), 0)
def test_leaves_the_later_fixes_unknown_where_no_chunk_shipped_the_item(self):
self.assertIsNone(self.fixed_later([shipping(8, fixed_by=("c",))]))
self.assertIsNone(self.fixed_later([]))
def test_leaves_the_later_fixes_unknown_where_the_history_could_not_be_read(self):
self.assertIsNone(self.fixed_later(None))
def test_leaves_the_later_fixes_unknown_where_the_route_names_no_item(self):
self.assertIsNone(self.fixed_later([shipping(7, fixed_by=("c",))], Route(LOW).worker_line()))
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"
@@ -256,15 +271,18 @@ class Calls(unittest.TestCase):
self.assertIn("## Calls for a routing change\n\nNone.\n", render(totals([]), [], "2026-10-15T00:00:00Z", 20, ""))
self.assertIn("from 0 finished chunks that finished after the reset of 2026-10-14T00:00:00Z.", render(totals([]), [], "2026-10-15T00:00:00Z", 20, "2026-10-14T00:00:00Z"))
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(), figures(start=None)], unread=("log: no main branch",)), [], "2026-10-15T00:00:00Z", 40, "")
def test_renders_the_median_later_fixes_of_the_matched_chunks(self):
text = render(totals([*MATCHED, figures()]), [], "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 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, ""))
def test_counts_the_routed_chunks_whose_later_fixes_are_unknown(self):
self.assertIn("The later fixes of 1 of the routed chunks are unknown", render(totals([*MATCHED, figures(), figures(start=None)]), [], "2026-10-15T00:00:00Z", 40, ""))
self.assertNotIn("are unknown", render(totals(MATCHED), [], "2026-10-15T00:00:00Z", 40, ""))
def test_names_each_project_history_unread(self):
self.assertIn("## Project histories unread\n\n- log: no main branch\n", render(totals(MATCHED, unread=("log: no main branch",)), [], "2026-10-15T00:00:00Z", 40, ""))
self.assertNotIn("histories unread", render(totals(MATCHED), [], "2026-10-15T00:00:00Z", 40, ""))
def test_measures_once_the_count_runs_20_past_the_last_measurement(self):
self.assertEqual([due(cycle, 20) for cycle in (39, 40, 41)], [False, True, True])
@@ -300,11 +318,23 @@ class Archive(unittest.TestCase):
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", no_checkout), archive.Measured([], ()))
def test_counts_each_chunks_later_fixes_from_its_projects_checkout_and_names_each_history_it_cannot_read(self):
def test_counts_each_chunks_later_fixes_from_its_projects_checkout(self):
home = self.root / "home"
checkout = home / "code" / "log"
checkout.mkdir(parents=True)
env = {**isolated_env(), "GIT_CONFIG_GLOBAL": os.devnull, "HOME": str(home)}
self.ship_then_fix(home / "code" / "log", env)
self.chunk("log", "c1", stamped("2026-10-14T10:00:00Z", outcomes.finished(LOW_ROUTE, "m", "j")), [message("m1", "2026-10-14T09:00:00Z")])
with unittest.mock.patch.dict(os.environ, env, clear=True):
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], [({"log": 0}.keys(), 1)])
def test_names_each_project_whose_history_it_cannot_read(self):
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, "/h", "", no_checkout)
self.assertEqual(([chunk.fixed_later for chunk in found.chunks], found.unread), ([None], ("gone: no checkout",)))
def ship_then_fix(self, checkout, env):
"""Makes a checkout whose main branch merges the chunk that ships item 7 of LOW_ROUTE, then one that ships a defect item and rewrites a line item 7 shipped."""
checkout.mkdir(parents=True)
git = lambda *args: subprocess.run(["git", "-c", "user.name=t", "-c", "user.email=t@t", *args], cwd=checkout, check=True, env=env, capture_output=True)
plan = lambda rows: "# todo\n\n## Items\n\n| ID | Release | Blocked by | Exempt | Item | L | E | I | R | S | Moves | Score |\n|---|---|---|---|---|---|---|---|---|---|---|---|\n" + rows
@@ -324,12 +354,6 @@ class Archive(unittest.TestCase):
git("commit", "-q", "-m", "Start")
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")), [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)
def test_reads_each_cycles_route_from_its_own_outcomes_file(self):
transcript = self.root / "t.jsonl"