Count each finished chunk's later fixes in score-outcomes and the routing figures
This commit is contained in:
@@ -8,14 +8,19 @@ import re
|
||||
import typing
|
||||
|
||||
from transcript_archive.read import archived_outcomes, chunk_outcomes, finished_chunks
|
||||
from project_key import checkout_of
|
||||
from routing_figures.measure import Chunk, ChunkFigures, measured, MEASURED_AT, Subagent
|
||||
from git_repo import default_ref
|
||||
from failure import Failure
|
||||
from score_outcomes.later_fixes import Landed, later_fixes
|
||||
from claude_code.entries import parse_entry
|
||||
from file_writes import replace_file
|
||||
from utc_stamp import STAMPED
|
||||
from transcript_archive.outcomes import VERDICT_AT
|
||||
|
||||
FIGURES = "routing-figures.md"
|
||||
# Seconds each git call reading a project's history may take.
|
||||
GIT_TIMEOUT = 60
|
||||
LOCK = "routing-figures.lock"
|
||||
RAISED = "routing-calls-raised.md"
|
||||
RAISED_HEADING = "# Routing calls raised\n"
|
||||
@@ -72,9 +77,10 @@ def last_measured(root: pathlib.Path) -> int | Failure:
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class Measured:
|
||||
"""skipped names each chunk folder that could not be read whole, such as one another loop is writing."""
|
||||
"""skipped names each chunk folder that could not be read whole, such as one another loop is writing; unread names each project whose default branch could not be read, with why."""
|
||||
chunks: list[ChunkFigures]
|
||||
skipped: tuple[str, ...]
|
||||
unread: tuple[str, ...] = ()
|
||||
|
||||
|
||||
def measure_archive(root: pathlib.Path, home: str, since: str) -> Measured | Failure:
|
||||
@@ -85,12 +91,19 @@ def measure_archive(root: pathlib.Path, home: str, since: str) -> Measured | Fai
|
||||
projects = sorted({root / key for key, _ in listed})
|
||||
found = []
|
||||
skipped = []
|
||||
unread = []
|
||||
for project in projects:
|
||||
key = str(project.relative_to(root))
|
||||
chunks = finished_chunks(project)
|
||||
if isinstance(chunks, Failure):
|
||||
skipped.append(str(project.relative_to(root)))
|
||||
skipped.append(key)
|
||||
continue
|
||||
for chunk in (chunk for chunk in chunks if chunk.finished > since):
|
||||
chunks = [chunk for chunk in chunks if chunk.finished > since]
|
||||
history = branch_history(checkout_of(key, pathlib.Path(home))) 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)]
|
||||
@@ -99,8 +112,14 @@ def measure_archive(root: pathlib.Path, home: str, since: str) -> Measured | Fai
|
||||
except (OSError, UnicodeDecodeError):
|
||||
skipped.append(str(folder.relative_to(root)))
|
||||
continue
|
||||
found.append(measured(Chunk(str(project.relative_to(root)), kept, worker, subagents), home))
|
||||
return Measured(found, tuple(skipped))
|
||||
found.append(measured(Chunk(key, kept, worker, subagents), home, history))
|
||||
return Measured(found, tuple(skipped), tuple(unread))
|
||||
|
||||
|
||||
def branch_history(checkout: str) -> list[Landed] | 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)
|
||||
return ref if isinstance(ref, Failure) else later_fixes(ref, cwd=checkout, guarded=True, timeout=GIT_TIMEOUT)
|
||||
|
||||
|
||||
def entries(path: pathlib.Path) -> list[dict]:
|
||||
|
||||
@@ -8,6 +8,7 @@ import typing
|
||||
from claude_code.entries import assistant_parts, parts, tool_call, tool_result
|
||||
from git_command import commits
|
||||
from model_routing.route import ESCALATION_MARKER, route_from
|
||||
from score_outcomes.later_fixes import Landed
|
||||
from routing_figures.prices import listed
|
||||
from model_routing.ladder import position, Rung
|
||||
from round_titles import round_counts
|
||||
@@ -56,7 +57,7 @@ class Reports:
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class ChunkFigures:
|
||||
"""dollars maps each of DIMENSIONS to its labels' dollars; start is the rung a routed chunk started on, None where no item routed it; escalated counts the worker's escalations by trigger; unattributed is the recorded cost of a model with no priced message in the chunk; lacking counts the Agent calls, the worker's and the subagents', that have no subagent transcript in the archive."""
|
||||
"""dollars maps each of DIMENSIONS to its labels' dollars; start is the rung a routed chunk started on, None where no item routed it; escalated counts the worker's escalations by trigger; unattributed is the recorded cost of a model with no priced message in the chunk; lacking counts the Agent calls, the worker's and the subagents', that have no subagent transcript in the archive; fixed_later counts the later chunks that fixed code it shipped, None where no chunk on its project's default branch matches it."""
|
||||
dollars: Dollars
|
||||
start: Rung | None
|
||||
rounds_past_first: int
|
||||
@@ -66,11 +67,12 @@ class ChunkFigures:
|
||||
escalated: collections.Counter[int]
|
||||
unattributed: float
|
||||
lacking: int = 0
|
||||
fixed_later: int | None = None
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class Figures:
|
||||
"""escalated counts every chunk's escalations by trigger, routed or not; skipped names each chunk folder the archive could not read whole."""
|
||||
"""escalated counts every chunk's escalations by trigger, routed or not; skipped names each chunk folder the archive could not read whole; unmatched counts the chunks whose later fixes are unknown; unread names each project whose default branch could not be read, with why."""
|
||||
chunks: int
|
||||
dollars: Dollars
|
||||
routed: dict[Rung, list[ChunkFigures]]
|
||||
@@ -79,6 +81,8 @@ class Figures:
|
||||
skipped: tuple[str, ...] = ()
|
||||
unattributed: float = 0.0
|
||||
lacking: int = 0
|
||||
unmatched: int = 0
|
||||
unread: tuple[str, ...] = ()
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
@@ -97,7 +101,8 @@ class Spent(typing.NamedTuple):
|
||||
message: Message
|
||||
|
||||
|
||||
def measured(chunk: Chunk, home: str) -> ChunkFigures:
|
||||
def measured(chunk: Chunk, home: str, history: list[Landed] | None = None) -> ChunkFigures:
|
||||
"""history is the chunks on the project's default branch, None where it could not be read."""
|
||||
cycles = sorted((cycle for kept in chunk.outcomes for cycle in workers(kept)), key=lambda cycle: cycle[0])
|
||||
spent = [Spent("worker", str(rung_at(cycles, message.at)), message) for message in messages(chunk.worker)]
|
||||
launches = agent_calls(chunk.worker)
|
||||
@@ -113,19 +118,31 @@ def measured(chunk: Chunk, home: str) -> ChunkFigures:
|
||||
spent += [Spent(kind, rung, message) for message in messages(subagent.entries)]
|
||||
dollars, unattributed = costed(spent, chunk.project, recorded_costs(chunk.worker))
|
||||
start = route_from(cycles[0][1]) if cycles else None
|
||||
titles = commit_titles(chunk.worker, home)
|
||||
return ChunkFigures(
|
||||
dollars=dollars,
|
||||
start=start.rung if start and start.item else None,
|
||||
rounds_past_first=rounds_past_first(chunk.worker, home),
|
||||
rounds_past_first=sum(max(0, rounds - 1) for rounds in round_counts(titles).values()),
|
||||
unfinished=sum(len(UNFINISHED_AT.findall(kept)) for kept in chunk.outcomes),
|
||||
delegated=delegated,
|
||||
reports=reports,
|
||||
escalated=escalations(launches),
|
||||
unattributed=unattributed,
|
||||
lacking=max(0, len(launches) + sum(len(agent_calls(subagent.entries)) for subagent in chunk.subagents) - len(chunk.subagents)),
|
||||
fixed_later=later_fixes_of(titles, history or []),
|
||||
)
|
||||
|
||||
|
||||
def later_fixes_of(titles: list[str], history: list[Landed]) -> int | None:
|
||||
"""How many chunks in history fixed code that the chunks holding one of titles shipped, each counted once and none of those chunks itself; None where no chunk holds one. Only a title no other chunk holds counts, since one such as a round's with no findings recurs."""
|
||||
# A worker's commits may land as several chunks, as a rebase cut by commit time does, and every one of them is its work.
|
||||
holders = collections.Counter(title for landed in history for title in landed.titles)
|
||||
shipped = [landed for landed in history if any(holders[title] == 1 for title in landed.titles.intersection(titles))]
|
||||
if not shipped:
|
||||
return None
|
||||
return len({later for landed in shipped for later in landed.fixed_by} - {landed.label for landed in shipped})
|
||||
|
||||
|
||||
def escalations(launches: dict[str, tuple[str, dict]]) -> collections.Counter[int]:
|
||||
"""How many of the worker's Agent calls open with each escalation trigger's number."""
|
||||
opened = (ESCALATION.match(str(arguments.get("prompt") or "")) for _, arguments in launches.values())
|
||||
@@ -207,15 +224,14 @@ def results(entries: list[dict]) -> dict[str, str]:
|
||||
return {result.tool_use_id: result.text for entry in entries for part in parts(entry) if (result := tool_result(part))}
|
||||
|
||||
|
||||
def rounds_past_first(worker: list[dict], home: str) -> int:
|
||||
# A commit retried after a failed hook repeats its title, so each title counts once.
|
||||
titles = dict.fromkeys(
|
||||
def commit_titles(worker: list[dict], home: str) -> list[str]:
|
||||
"""The title of each commit the worker's Bash calls made, in order, each once: a commit retried after a failed hook repeats its title."""
|
||||
return list(dict.fromkeys(
|
||||
commit.messages[0].split("\n", 1)[0]
|
||||
for entry in worker for part in assistant_parts(entry)
|
||||
if (found := tool_call(part)) and found[0] == "Bash" and isinstance(found[1], dict)
|
||||
for commit in commits(simple_commands(str(found[1].get("command", "")), str(entry.get("cwd") or "/"), home), home) if commit.messages
|
||||
)
|
||||
return sum(max(0, rounds - 1) for rounds in round_counts(list(titles)).values())
|
||||
))
|
||||
|
||||
|
||||
def due(cycle: int, last_measured: int) -> bool:
|
||||
@@ -223,7 +239,7 @@ def due(cycle: int, last_measured: int) -> bool:
|
||||
return cycle >= last_measured + CYCLES_PER_CHECK
|
||||
|
||||
|
||||
def totals(chunks: list[ChunkFigures], skipped: tuple[str, ...] = ()) -> Figures:
|
||||
def totals(chunks: list[ChunkFigures], skipped: tuple[str, ...] = (), unread: tuple[str, ...] = ()) -> Figures:
|
||||
dollars: Dollars = {dimension: collections.defaultdict(float) for dimension in DIMENSIONS}
|
||||
for chunk in chunks:
|
||||
for dimension in DIMENSIONS:
|
||||
@@ -236,7 +252,7 @@ def totals(chunks: list[ChunkFigures], skipped: tuple[str, ...] = ()) -> Figures
|
||||
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))
|
||||
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.fixed_later is None for chunk in chunks), unread)
|
||||
|
||||
|
||||
def calls(figures: Figures) -> list[str]:
|
||||
@@ -257,12 +273,15 @@ def mean(chunks: list[ChunkFigures], of: typing.Callable[[ChunkFigures], int]) -
|
||||
|
||||
|
||||
def basis(figures: Figures) -> str:
|
||||
"""What the dollars are, what they leave out, and where the archive falls short of the recorded cost."""
|
||||
"""What the dollars and the later fixes are, what they leave out, and where the archive falls short of the recorded cost."""
|
||||
text = "Dollars are what each worker transcript's last `cost-state` entry records for each model, cache reads included. A model's dollars are split across its messages in the archive in proportion to their cost at list prices, so the cost of a compaction, or of a subagent transcript the archive lacks, lands on the archived messages of the model that ran it. A chunk without the entry, or a model it leaves out, keeps the list prices, which may be a little off. A message's dollars count towards the tools whose results it took in, split evenly; a message that took in no tool result counts towards `prompt`. The judge's runs are not archived, so their cost is not counted."
|
||||
if figures.unattributed:
|
||||
text += f" {money(figures.unattributed)} of the recorded cost is left out, since it belongs to a model with no list price or with no priced message in the archive."
|
||||
if figures.lacking:
|
||||
text += f" The archive holds no subagent transcript for {figures.lacking} of the chunks' Agent calls."
|
||||
text += " A chunk's later fixes are the chunks on its project's default branch, as last fetched, that fixed code it shipped, as `score-outcomes` counts them, so a recent chunk has had less time to gather them. What it shipped is each chunk there holding a title of the worker's commits that no other chunk there holds."
|
||||
if figures.unmatched:
|
||||
text += f" The later fixes of {figures.unmatched} of the chunks are unknown, since no chunk on the branch held such a title, or the branch could not be read."
|
||||
return text
|
||||
|
||||
|
||||
@@ -275,8 +294,8 @@ def render(figures: Figures, found: list[str], at: str, cycle: int, since: str)
|
||||
"".join(f"- {call}\n" for call in found).rstrip("\n") or "None.",
|
||||
*[part for dimension in DIMENSIONS for part in (f"## Dollars by {dimension}", table((dimension.capitalize(), "Dollars"), [(label, money(dollars)) for label, dollars in sorted(figures.dollars[dimension].items(), key=lambda spent: -spent[1])]))],
|
||||
"## Routed chunks by the rung they started on",
|
||||
table(("Rung", "Chunks", "Review rounds past each pass's first, mean", "Unfinished verdicts, mean", "Subagent rungs", "Escalations by trigger"), [
|
||||
(str(rung), str(len(chunks)), f"{mean(chunks, lambda chunk: chunk.rounds_past_first):.1f}", f"{mean(chunks, lambda chunk: chunk.unfinished):.1f}", subagent_rungs(chunks), triggers(summed(chunks, lambda chunk: chunk.escalated)))
|
||||
table(("Rung", "Chunks", "Review rounds past each pass's first, mean", "Unfinished verdicts, mean", "Later fixes, median", "Subagent rungs", "Escalations by trigger"), [
|
||||
(str(rung), str(len(chunks)), f"{mean(chunks, lambda chunk: chunk.rounds_past_first):.1f}", f"{mean(chunks, lambda chunk: chunk.unfinished):.1f}", median_fixes(chunks), subagent_rungs(chunks), triggers(summed(chunks, lambda chunk: chunk.escalated)))
|
||||
for rung, chunks in sorted(figures.routed.items(), key=lambda item: position(item[0]))
|
||||
]),
|
||||
"## Escalations by trigger across every chunk, routed or not",
|
||||
@@ -284,6 +303,7 @@ def render(figures: Figures, found: list[str], at: str, cycle: int, since: str)
|
||||
"## Subagent reports against the searches they ran, in characters",
|
||||
table(("Subagent type", "Subagents", "Reports", "Searches"), [(kind, str(found.subagents), str(found.report), str(found.searches)) for kind, found in sorted(figures.reports.items())]),
|
||||
*(["## Chunks skipped, unreadable", "".join(f"- {folder}\n" for folder in figures.skipped).rstrip("\n")] if figures.skipped else []),
|
||||
*(["## Project histories unread", "".join(f"- {project}\n" for project in figures.unread).rstrip("\n")] if figures.unread else []),
|
||||
]
|
||||
return "\n\n".join(sections) + "\n"
|
||||
|
||||
@@ -292,6 +312,12 @@ def summed(chunks: list[ChunkFigures], of: typing.Callable[[ChunkFigures], colle
|
||||
return sum(map(of, chunks), collections.Counter())
|
||||
|
||||
|
||||
def median_fixes(chunks: list[ChunkFigures]) -> str:
|
||||
"""The median later fixes of the chunks that matched one on their project's default branch, `unknown` where none did."""
|
||||
known = [chunk.fixed_later for chunk in chunks if chunk.fixed_later is not None]
|
||||
return f"{statistics.median(known):.1f}" if known else "unknown"
|
||||
|
||||
|
||||
def subagent_rungs(chunks: list[ChunkFigures]) -> str:
|
||||
"""The rungs the chunks' subagents ran on, most used first, as `claude-opus-5-5 at high effort 2, …`."""
|
||||
return ", ".join(f"{label} {times}" for label, times in summed(chunks, lambda chunk: chunk.delegated).most_common())
|
||||
|
||||
@@ -3,8 +3,10 @@ import contextlib
|
||||
import dataclasses
|
||||
import io
|
||||
import json
|
||||
import os
|
||||
import pathlib
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
@@ -14,13 +16,16 @@ sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
||||
from routing_figures import archive
|
||||
from routing_figures.measure import calls, Chunk, ChunkFigures, due, measured, render, Reports, Subagent, totals
|
||||
from failure import Failure
|
||||
from test_env import isolated_env
|
||||
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):
|
||||
@@ -40,6 +45,10 @@ 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"
|
||||
|
||||
@@ -87,10 +96,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_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"
|
||||
kept = stamped("2026-10-14T10:00:00Z", outcomes.finished(older, "m", "j"))
|
||||
@@ -220,17 +238,27 @@ class Calls(unittest.TestCase):
|
||||
self.assertNotIn("no transcript", text)
|
||||
self.assertIn("The archive holds no subagent transcript for 2 of the chunks' Agent calls.", render(totals([dataclasses.replace(chunk, lacking=1)] * 2), [], "2026-10-15T00:00:00Z", 40, ""))
|
||||
self.assertIn("$0.50 of the recorded cost is left out", render(totals([ChunkFigures({}, LOW, 0, 0, collections.Counter(), {}, collections.Counter(), 0.5), chunk]), [], "2026-10-15T00:00:00Z", 40, ""))
|
||||
self.assertIn(f"| {LOW} | 1 | 1.0 | 0.0 | {HIGH} 2 | |", text)
|
||||
self.assertIn(f"| {LOW} | 1 | 1.0 | 0.0 | unknown | {HIGH} 2 | |", text)
|
||||
two = ChunkFigures({}, HIGH, 0, 1, collections.Counter({str(HIGH): 2, str(LOW): 1}), {}, collections.Counter(), 0.0)
|
||||
self.assertIn(f"| {LOW} | 1 | 1.0 | 0.0 | {HIGH} 2 | |\n| {HIGH} | 1 | 0.0 | 1.0 | {HIGH} 2, {LOW} 1 | |", render(totals([two, chunk]), [], "2026-10-15T00:00:00Z", 40, ""))
|
||||
self.assertIn(f"| {LOW} | 1 | 1.0 | 0.0 | unknown | {HIGH} 2 | |\n| {HIGH} | 1 | 0.0 | 1.0 | unknown | {HIGH} 2, {LOW} 1 | |", render(totals([two, chunk]), [], "2026-10-15T00:00:00Z", 40, ""))
|
||||
self.assertIn("| Explore | 2 | 3 | 4 |", text)
|
||||
escalated = render(totals([figures(escalated={2: 2}), figures(escalated={2: 1, 10: 1}), figures(start=None, escalated={3: 1})]), [], "2026-10-15T00:00:00Z", 40, "")
|
||||
self.assertIn(f"| {LOW} | 2 | 0.0 | 0.0 | | trigger 2: 3, trigger 10: 1 |", escalated)
|
||||
self.assertIn(f"| {LOW} | 2 | 0.0 | 0.0 | unknown | | trigger 2: 3, trigger 10: 1 |", escalated)
|
||||
self.assertIn("## Escalations by trigger across every chunk, routed or not\n\ntrigger 2: 3, trigger 3: 1, trigger 10: 1.\n", escalated)
|
||||
self.assertIn("## Escalations by trigger across every chunk, routed or not\n\nNone.\n", text)
|
||||
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()], 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("## 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_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])
|
||||
self.assertTrue(due(20, 0))
|
||||
@@ -265,6 +293,36 @@ 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"), 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"
|
||||
checkout = home / "code" / "log"
|
||||
checkout.mkdir(parents=True)
|
||||
env = {**isolated_env(), "GIT_CONFIG_GLOBAL": os.devnull, "HOME": str(home)}
|
||||
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
|
||||
|
||||
def merge(branch, title, files):
|
||||
git("switch", "-q", "-c", branch)
|
||||
for name, text in files.items():
|
||||
(checkout / name).write_text(text)
|
||||
git("add", *files)
|
||||
git("commit", "-q", "-m", title)
|
||||
git("switch", "-q", "main")
|
||||
git("merge", "-q", "--no-ff", "-m", f"Merge {branch}", branch)
|
||||
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 / "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("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.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"
|
||||
kept = self.root / "archive"
|
||||
|
||||
Reference in New Issue
Block a user