Answer stability round 1: 0 🔴, 7 🟡; quote a judge's stdout that is no json, name each left-out round and why, test the string prompt, the miss sum, the args sent to claude and the skip paths, settle the judge's hard place in item 122
This commit is contained in:
@@ -9,7 +9,8 @@ reviewed: in a throwaway clone of the project's checkout, at the newest commit o
|
||||
authored by the time the round began, on the branch the reviewer started on. The clone's default
|
||||
branch stands at the newest commit authored before the round's chunk began, so a diff against it
|
||||
shows the chunk's change. The prompt names the clone in place of the worktree it named, which the
|
||||
chunk has since removed. A round whose code it cannot find in this way is not replayed.
|
||||
chunk has since removed. A round whose code it cannot find in this way is not replayed; stderr
|
||||
names it and why.
|
||||
|
||||
It first replays every round on the reference reviewer, the project's rung, which the reviewer
|
||||
runs on while the worker runs below it. Findings it does not find may rest on code or rules that
|
||||
@@ -67,9 +68,12 @@ def main(argv: list[str], env: typing.Mapping[str, str], home: pathlib.Path, eff
|
||||
rounds = archived_rounds(anchor.model, archive_root(home, env), home)
|
||||
if isinstance(rounds, Failure):
|
||||
return failed(TOOL, rounds.reason)
|
||||
codes = {found: code for found in rounds if not isinstance(code := code_of(found, effects), Failure)}
|
||||
if len(codes) < len(rounds):
|
||||
print(f"{len(rounds) - len(codes)} of {len(rounds)} rounds holding a 🔴 or 🟡 are left out: their code cannot be found", file=sys.stderr, flush=True)
|
||||
codes = {}
|
||||
for found in rounds:
|
||||
if isinstance(code := code_of(found, effects), Failure):
|
||||
print(f"{found.root} {found.at} is left out: {code.reason}", file=sys.stderr, flush=True)
|
||||
else:
|
||||
codes[found] = code
|
||||
if not codes:
|
||||
return failed(TOOL, f"no archived stability round of projects on {anchor.model} in {archive_root(home, env)} holds a 🔴 or 🟡 on code it can find")
|
||||
chosen = sample(list(codes), LATEST)
|
||||
@@ -116,6 +120,8 @@ def code_of(found: Round, effects: Effects) -> Code | Failure:
|
||||
|
||||
Recording the reviewed commit at review time would need no such reading, but then no round archived before that change could be replayed. A wrong guess costs no rung: the reference reviewer, replayed on that code, finds fewer findings on record, and no rung is held to those.
|
||||
"""
|
||||
if not os.path.isdir(found.root):
|
||||
return Failure("the project has no checkout")
|
||||
path = reviewed_path(found.prompt, found.root, os.path.exists)
|
||||
if path is None:
|
||||
return Failure("the prompt names no one worktree")
|
||||
|
||||
@@ -2,6 +2,7 @@ import contextlib
|
||||
import dataclasses
|
||||
import io
|
||||
import json
|
||||
import os
|
||||
import pathlib
|
||||
import re
|
||||
import shutil
|
||||
@@ -52,6 +53,10 @@ class RoundFrom(unittest.TestCase):
|
||||
self.assertEqual(round_from("/code/p", 5.0, entries), Round("/code/p", "x", "2026-10-14T10:00:00.500Z", 5.0, "Review branch x in /code/p-x.", ("🔴 a.py:1 breaks",)))
|
||||
self.assertEqual(round_from("/code/p", 5.0, entries).seconds, 1791972000.5)
|
||||
|
||||
def test_reads_a_prompt_given_as_a_string(self):
|
||||
start = {"type": "user", "message": {"content": "Review branch x in /code/p-x."}, "timestamp": "2026-10-14T10:00:00Z", "gitBranch": "x"}
|
||||
self.assertEqual(round_from("/code/p", 5.0, [start, entry("assistant", "🔴 a")]).prompt, "Review branch x in /code/p-x.")
|
||||
|
||||
def test_skips_a_round_with_no_red_or_yellow_finding_or_no_report(self):
|
||||
start = entry("user", "Review.", timestamp="2026-10-14T10:00:00Z", cwd="/code/p", gitBranch="x")
|
||||
self.assertIsNone(round_from("/code/p", 5.0, [start, entry("assistant", "APPROVE\n\n🟢 nit")]))
|
||||
@@ -105,8 +110,22 @@ class Report(unittest.TestCase):
|
||||
|
||||
class Match(unittest.TestCase):
|
||||
def run_match(self, stdout):
|
||||
effects = dataclasses.replace(system_effects(), claude=lambda args, cwd, prompt: subprocess.CompletedProcess(args, 0, stdout, ""))
|
||||
return main.match(("🔴 a", "🟡 b"), "the other report", "/code/p", REFERENCE, effects)
|
||||
self.asked = []
|
||||
|
||||
def claude(args, cwd, prompt):
|
||||
self.asked.append((args, cwd, prompt))
|
||||
return subprocess.CompletedProcess(args, 0, stdout, "")
|
||||
|
||||
return main.match(("🔴 a", "🟡 b"), "the other report", "/code/p", REFERENCE, dataclasses.replace(system_effects(), claude=claude))
|
||||
|
||||
def test_asks_for_the_numbered_findings_the_other_report_raises_as_json_with_no_tools(self):
|
||||
self.run_match("{}")
|
||||
[(args, cwd, prompt)] = self.asked
|
||||
self.assertEqual(cwd, "/code/p")
|
||||
self.assertIn("1. 🔴 a\n\n2. 🟡 b\n\nThe other report:\nthe other report", prompt)
|
||||
self.assertEqual(json.loads(args[args.index("--json-schema") + 1]), main.MATCH_SCHEMA)
|
||||
self.assertEqual(args[args.index("--tools") + 1], "")
|
||||
self.assertEqual(args[args.index("--model"):args.index("--model") + 4], REFERENCE.flags())
|
||||
|
||||
def test_takes_the_numbers_in_range_and_fails_on_a_reply_of_another_shape(self):
|
||||
self.assertEqual(self.run_match(json.dumps({"type": "result", "structured_output": {"found": [2, 0, 3, 1]}})), {0, 1})
|
||||
@@ -128,15 +147,18 @@ def unused(*_):
|
||||
raise AssertionError("not called")
|
||||
|
||||
|
||||
def run_git(cwd, *args):
|
||||
subprocess.run(["git", "-c", "user.name=t", "-c", "user.email=t@t", *args], cwd=cwd, check=True, capture_output=True)
|
||||
def run_git(cwd, *args, at=None):
|
||||
"""at, when given, is the commit's author and committer time, so git log lists the commits in a fixed order."""
|
||||
env = {**os.environ, "GIT_AUTHOR_DATE": at, "GIT_COMMITTER_DATE": at} if at else None
|
||||
subprocess.run(["git", "-c", "user.name=t", "-c", "user.email=t@t", *args], cwd=cwd, check=True, capture_output=True, env=env)
|
||||
|
||||
|
||||
class Main(unittest.TestCase):
|
||||
"""The tool on a temporary home: a chunk that began after the checkout's first commit, and whose stability reviewer reviewed branch x at its second, from a worktree since removed."""
|
||||
"""The tool on a temporary home: a chunk that began after the checkout's first commit, and whose stability reviewer reviewed branch x at its second, from a worktree since removed; a prose reviewer's files sort before the stability reviewer's."""
|
||||
|
||||
def setUp(self):
|
||||
self.home = pathlib.Path(self.enterContext(tempfile.TemporaryDirectory()))
|
||||
self.archive = self.home / ".claude" / "loop-claude-transcripts"
|
||||
(self.home / ".claude").mkdir()
|
||||
(self.home / ".claude" / "loop-claude-models.json").write_text(json.dumps({"proj": "claude-opus-5-5", "other": "claude-sonnet-5-5"}))
|
||||
origin, self.checkout = self.home / "origin.git", self.home / "code" / "proj"
|
||||
@@ -145,23 +167,27 @@ class Main(unittest.TestCase):
|
||||
for n, stamp in enumerate(("2026-10-14T09:00:00Z", "2026-10-14T09:30:00Z", "2026-10-14T11:00:00Z")):
|
||||
(self.checkout / "a.txt").write_text(f"{n}\n")
|
||||
run_git(self.checkout, "add", "a.txt")
|
||||
run_git(self.checkout, "commit", "-qm", f"c{n}", f"--date={stamp}")
|
||||
run_git(self.checkout, "commit", "-qm", f"c{n}", at=stamp)
|
||||
run_git(self.checkout, "push", "-q", "origin", "main")
|
||||
run_git(self.checkout, "remote", "set-head", "origin", "main")
|
||||
gone = self.home / "code" / "proj-x"
|
||||
for key, cwd in (("proj", gone), ("other", self.home / "code" / "other")):
|
||||
subagents = self.home / ".claude" / "loop-claude-transcripts" / key / "c1" / "session" / "s" / "subagents"
|
||||
subagents.mkdir(parents=True)
|
||||
(subagents.parents[2] / "t0.jsonl").write_text(json.dumps({"type": "summary"}) + "\n" + json.dumps(entry("user", "Do the next chunk.", timestamp="2026-10-14T09:15:00Z")) + "\n")
|
||||
(subagents / "agent-a.meta.json").write_text(json.dumps({"agentType": "stability-reviewer"}))
|
||||
(subagents / "agent-b.meta.json").write_text(json.dumps({"agentType": "prose-reviewer"}))
|
||||
lines = [entry("user", f"Review branch x in {gone}.", timestamp="2026-10-14T10:00:00Z", cwd=str(cwd), gitBranch="x"), entry("assistant", "BLOCK\n\n🔴 a.txt:1 wrong\n\n🟡 slow")]
|
||||
for name in ("agent-a.jsonl", "agent-b.jsonl"):
|
||||
(subagents / name).write_text("".join(json.dumps(line) + "\n" for line in lines))
|
||||
for key in ("proj", "other"):
|
||||
self.write_chunk(key, "c1", "2026-10-14T10:00:00Z")
|
||||
self.reviews = []
|
||||
|
||||
def write_chunk(self, key, chunk, at, began="2026-10-14T09:15:00Z"):
|
||||
"""A chunk that began at began, whose stability round began at at."""
|
||||
subagents = self.archive / key / chunk / "session" / "s" / "subagents"
|
||||
subagents.mkdir(parents=True, exist_ok=True)
|
||||
(subagents.parents[2] / "t0.jsonl").write_text(json.dumps({"type": "summary"}) + "\n" + json.dumps(entry("user", "Do the next chunk.", timestamp=began)) + "\n")
|
||||
(subagents / "agent-a.meta.json").write_text(json.dumps({"agentType": "prose-reviewer"}))
|
||||
(subagents / "agent-b.meta.json").write_text(json.dumps({"agentType": "stability-reviewer"}))
|
||||
gone = self.home / "code" / "proj-x"
|
||||
lines = [entry("user", f"Review branch x in {gone}.", timestamp=at, cwd=str(gone), gitBranch="x"), entry("assistant", "BLOCK\n\n🔴 a.txt:1 wrong\n\n🟡 slow")]
|
||||
for name in ("agent-a.jsonl", "agent-b.jsonl"):
|
||||
(subagents / name).write_text("".join(json.dumps(line) + "\n" for line in lines))
|
||||
|
||||
def rewrite_round(self, change):
|
||||
path = self.home / ".claude" / "loop-claude-transcripts" / "proj" / "c1" / "session" / "s" / "subagents" / "agent-a.jsonl"
|
||||
path = self.archive / "proj" / "c1" / "session" / "s" / "subagents" / "agent-b.jsonl"
|
||||
lines = [json.loads(line) for line in path.read_text().splitlines()]
|
||||
change(lines[0])
|
||||
path.write_text("".join(json.dumps(line) + "\n" for line in lines))
|
||||
@@ -172,15 +198,15 @@ class Main(unittest.TestCase):
|
||||
def set_prompt(self, prompt):
|
||||
self.rewrite_round(lambda first: first["message"]["content"][0].update(text=prompt))
|
||||
|
||||
def run_main(self, argv, found):
|
||||
"""found(rung) is the indexes of the recorded findings the reviewer on rung finds."""
|
||||
def run_main(self, argv, found, review=lambda rung: {"type": "result", "result": f"review on {rung.model} {rung.effort}"}):
|
||||
"""found(rung) is the indexes of the recorded findings the reviewer on rung finds; review(rung), that reviewer's reply."""
|
||||
|
||||
def claude(args, cwd, prompt):
|
||||
rung = Rung(args[args.index("--model") + 1], args[args.index("--effort") + 1])
|
||||
if "--agent" in args:
|
||||
shown = [subprocess.run(["git", *command], cwd=cwd, capture_output=True, text=True).stdout for command in (["show", "HEAD:a.txt"], ["branch", "--show-current"], ["show", "origin/main:a.txt"])]
|
||||
self.reviews.append((rung, *shown, prompt, cwd))
|
||||
result = {"type": "result", "result": f"review on {rung.model} {rung.effort}"}
|
||||
result = review(rung)
|
||||
else:
|
||||
reviewed = Rung(*re.search(r"review on (\S+) (\S+)", prompt).groups())
|
||||
result = found(reviewed)
|
||||
@@ -206,27 +232,70 @@ class Main(unittest.TestCase):
|
||||
self.assertIn(f" {self.checkout} 2026-10-14T10:00:00Z: 🟡 slow", out)
|
||||
self.assertTrue(out.endswith("finds: claude-sonnet-5-5 at high effort\n"))
|
||||
|
||||
def test_replays_the_rounds_of_every_chunk(self):
|
||||
self.write_chunk("proj", "c2", "2026-10-14T10:30:00Z")
|
||||
code, out, err = self.run_main(["claude-opus-5-5"], lambda rung: {"found": [0, 1]})
|
||||
self.assertEqual(code, 0, err)
|
||||
self.assertTrue(out.startswith("Replayed 2 stability rounds"), out)
|
||||
|
||||
def test_checks_out_the_commit_detached_when_the_reviewer_started_on_the_default_branch(self):
|
||||
self.set_branch("main")
|
||||
self.assertEqual(self.run_main(["claude-opus-5-5"], lambda rung: {"found": [0]})[0], 0)
|
||||
self.assertEqual(self.reviews[0][1:3], ("1\n", ""))
|
||||
|
||||
def assert_left_out(self):
|
||||
def test_sets_the_default_branch_to_its_own_line_and_not_to_a_branch_merged_after_the_chunk_began(self):
|
||||
# Branch side's commit was authored before the chunk began, but the default branch held it only once merged, after.
|
||||
run_git(self.checkout, "reset", "-q", "--hard", "HEAD~2")
|
||||
run_git(self.checkout, "checkout", "-qb", "side")
|
||||
(self.checkout / "a.txt").write_text("s\n")
|
||||
run_git(self.checkout, "commit", "-qam", "s", at="2026-10-14T09:10:00Z")
|
||||
run_git(self.checkout, "checkout", "-q", "main")
|
||||
run_git(self.checkout, "merge", "-q", "--no-ff", "-m", "m", "side", at="2026-10-14T09:40:00Z")
|
||||
run_git(self.checkout, "push", "-qf", "origin", "main")
|
||||
self.assertEqual(self.run_main(["claude-opus-5-5"], lambda rung: {"found": [0]})[0], 0)
|
||||
self.assertEqual(self.reviews[0][1:4], ("s\n", "x\n", "0\n"))
|
||||
|
||||
def test_finds_nothing_in_a_round_whose_review_has_no_report(self):
|
||||
code, out, err = self.run_main(["claude-opus-5-5"], unused, review=lambda rung: {"type": "result"})
|
||||
self.assertEqual(code, 0, err)
|
||||
self.assertEqual([rung for rung, *_ in self.reviews], [REFERENCE] * 3)
|
||||
self.assertIn(f" {self.checkout} 2026-10-14T10:00:00Z on {REFERENCE} found nothing: the reviewer replied with no report", err)
|
||||
self.assertTrue(out.endswith("No rung tried: the reference reviewer found no finding to hold one to.\n"))
|
||||
|
||||
def assert_no_round(self):
|
||||
code, _, err = self.run_main(["claude-opus-5-5"], unused)
|
||||
self.assertEqual(code, 1)
|
||||
self.assertIn("1 of 1 rounds holding a 🔴 or 🟡 are left out", err)
|
||||
self.assertEqual(err.splitlines(), [f"stability-replay: no archived stability round of projects on claude-opus-5-5 in {self.archive} holds a 🔴 or 🟡 on code it can find"])
|
||||
|
||||
def test_skips_a_chunk_with_no_transcript_copy(self):
|
||||
(self.archive / "proj" / "c1" / "t0.jsonl").unlink()
|
||||
self.assert_no_round()
|
||||
|
||||
def test_skips_a_chunk_whose_transcript_copy_has_no_timestamp(self):
|
||||
(self.archive / "proj" / "c1" / "t0.jsonl").write_text(json.dumps({"type": "summary"}) + "\n")
|
||||
self.assert_no_round()
|
||||
|
||||
def assert_left_out(self, reason, root=None):
|
||||
code, _, err = self.run_main(["claude-opus-5-5"], unused)
|
||||
self.assertEqual(code, 1)
|
||||
self.assertIn(f"{root or self.checkout} 2026-10-14T10:00:00Z is left out: {reason}", err)
|
||||
|
||||
def test_leaves_out_a_round_whose_prompt_names_no_worktree(self):
|
||||
self.set_prompt("Review the branch.")
|
||||
self.assert_left_out()
|
||||
self.assert_left_out("the prompt names no one worktree")
|
||||
|
||||
def test_leaves_out_a_round_whose_checkout_names_no_default_branch(self):
|
||||
run_git(self.checkout, "remote", "set-head", "origin", "-d")
|
||||
self.assert_left_out()
|
||||
self.assert_left_out("git symbolic-ref --short refs/remotes/origin/HEAD: ")
|
||||
|
||||
def test_leaves_out_a_round_whose_checkout_is_gone(self):
|
||||
shutil.rmtree(self.checkout)
|
||||
self.assert_left_out()
|
||||
# With no folder under ~/code, the key names /proj.
|
||||
self.assert_left_out("the project has no checkout", "/proj")
|
||||
|
||||
def test_leaves_out_a_round_whose_chunk_began_before_the_checkouts_first_commit(self):
|
||||
self.write_chunk("proj", "c1", "2026-10-14T10:00:00Z", began="2026-10-14T08:00:00Z")
|
||||
self.assert_left_out("no commit was authored by then")
|
||||
|
||||
def test_exits_1_on_a_usage_limit_bad_arguments_or_no_round_to_replay(self):
|
||||
code, _, err = self.run_main(["claude-opus-5-5"], lambda rung: {"type": "result", "api_error_status": 429, "result": "You've hit your limit"})
|
||||
|
||||
Reference in New Issue
Block a user