Test the reference replays apart, a round one of them failed on and a reference that found nothing; drop share's dead guard

This commit is contained in:
2026-11-12 11:01:49 +01:00
parent d55b1e4ad5
commit 058f4ca7aa
3 changed files with 32 additions and 8 deletions
+3 -3
View File
@@ -2,8 +2,8 @@
import dataclasses
from fractions import Fraction
from review_replay.rounds import Round
from model_routing.ladder import LADDER, Rung
from review_replay.rounds import Round
# A rung qualifies with a share of the archived findings up to this far below the project's rung's. The project's rung found 69 to 73% of its own findings again, so about 3 of the 30 to 40 that 10 rounds hold go either way between two replays.
MARGIN = Fraction(1, 10)
@@ -49,8 +49,8 @@ def found_any(reference: Reference) -> bool:
def share(rounds: list[Round], found: list[set[int]]) -> Fraction:
total = sum(len(one.findings) for one in rounds)
return Fraction(sum(map(len, found)), total) if total else Fraction(0)
"""The share of rounds' findings that found holds; rounds is never empty, and each holds a finding."""
return Fraction(sum(map(len, found)), sum(len(one.findings) for one in rounds))
def bar(rounds: list[Round], reference: Reference) -> Fraction:
+9 -4
View File
@@ -18,16 +18,19 @@ def a_round(at, findings):
return Round("prose-reviewer", "/code/p", "x", f"2026-10-14T10:00:0{at}Z", 0, "Review it.", tuple(findings))
# Ten findings over two rounds; the project's rung found 7 and then 7, so its share is 70% and the bar 60%.
# Ten findings over two rounds; the project's rung found 8 and then 6, so its share is 70% and the bar 60%. Both found the first round's 🔴, and only the first found the second's.
ROUNDS = [a_round(1, ("🔴 a", "🟡 b", "🟡 c", "🟡 d", "🟡 e")), a_round(2, ("🔴 f\nmore", "🟡 g", "🟡 h", "🟡 i", "🟡 j"))]
FIRST = [{0, 1, 2, 3}, {0, 1, 2}]
SECOND = [{0, 1, 2}, {0, 1, 2, 4}]
FIRST = [{0, 1, 2, 3}, {0, 1, 2, 3}]
SECOND = [{0, 1, 2}, {1, 2, 3}]
class Candidates(unittest.TestCase):
def test_tries_the_project_models_lower_efforts_first_then_the_ladder_below_it(self):
self.assertEqual(candidates(REFERENCE), [LOW, SONNET])
def test_tries_each_ladder_rung_below_highest_first(self):
self.assertEqual(candidates(Rung("claude-fable-5-2", "low")), [REFERENCE, SONNET])
def test_tries_each_lower_effort_of_the_ladders_lowest_rung(self):
self.assertEqual(candidates(SONNET), [Rung("claude-sonnet-5-5", "medium"), Rung("claude-sonnet-5-5", "low")])
@@ -47,6 +50,8 @@ class Tried(unittest.TestCase):
self.assertEqual((found.share, found.missed_red, found.qualifies), (Fraction(4, 5), [(ROUNDS[0], 0)], False))
# The first round's 🔴 is found both times; a yellow found both times, such as its b, may be missed.
self.assertTrue(tried(LOW, ROUNDS, (FIRST, SECOND), [{0, 2, 3, 4}, {0, 2, 3, 4}]).qualifies)
# The second round's 🔴, which only the first replay found, may be missed too.
self.assertTrue(tried(LOW, ROUNDS, (FIRST, SECOND), [{0, 1, 2, 3}, {1, 2, 3}]).qualifies)
def test_fails_every_rung_where_the_project_rung_found_nothing(self):
self.assertFalse(tried(LOW, ROUNDS, ([set(), set()], [set(), set()]), [{0}, {0}]).qualifies)
@@ -64,7 +69,7 @@ class RecallReport(unittest.TestCase):
self.assertEqual(lines, [
"Replayed 8 prose rounds of claude-opus-5-5 projects, which hold 40 🔴 and 🟡 findings, twice on the project's rung, claude-opus-5-5 at medium effort.",
"Left out 1 more, which a replay on the project's rung failed on; stderr says why.",
"The project's rung found 28 and then 28 of them, 70%, so a rung qualifies at 60% or more and missing no 🔴 it found both times.",
"The project's rung found 32 and then 24 of them, 70%, so a rung qualifies at 60% or more and missing no 🔴 it found both times.",
"claude-opus-5-5 at low effort found 60% and missed no such 🔴: it qualifies.",
"claude-sonnet-5-5 at high effort found 50% and missed 4 such 🔴:",
*[" /code/p 2026-10-14T10:00:01Z: 🔴 a"] * 4,
+20 -1
View File
@@ -22,6 +22,7 @@ from review_replay import main, recall
from review_rules.reviewer_context import reviewer_context
from review_rules.review_passes import REVIEWERS
from model_routing.ladder import Rung
from rung_replay import search
TOOL = pathlib.Path(__file__).resolve().parents[1] / "review-replay"
REFERENCE = Rung("claude-opus-5-5", "medium")
@@ -325,6 +326,8 @@ class Main(unittest.TestCase):
def test_counts_a_failed_replay_on_a_lower_rung_as_finding_nothing(self):
code, out, err = self.run_main(["prose", "claude-opus-5-5"], lambda rung: {"found": [0, 1]}, review=lambda rung: {"type": "result"} if rung == LOW else {"type": "result", "result": f"review on {rung.model} {rung.effort}"})
self.assertEqual(code, 0, err)
self.assertIn(f"replaying 1 prose rounds on {REFERENCE}\n", err)
self.assertIn(f"replaying 1 prose rounds on {LOW}\n", err)
self.assertIn(f"on {LOW} failed: the reviewer replied with no report", err)
self.assertIn("claude-opus-5-5 at low effort found 0% and missed 1 such 🔴:", out)
@@ -421,6 +424,22 @@ class Main(unittest.TestCase):
self.assertEqual(code, 0, err)
self.assertTrue(out.startswith("Replayed 2 stability rounds"), out)
def test_leaves_out_a_round_that_either_replay_on_the_project_rung_failed_on(self):
self.write_chunk("proj", "c2", "2026-10-14T10:30:00Z")
self.enterContext(unittest.mock.patch.object(search, "AT_ONCE", 1))
calls = iter(range(100))
# One round at a time, the first replay's three tries on the first round reply with no report; every other review replies.
code, out, err = self.run_main(["prose", "claude-opus-5-5"], lambda rung: {"found": [0, 1]}, review=lambda rung: {"type": "result"} if next(calls) < 3 else {"type": "result", "result": f"review on {rung.model} {rung.effort}"})
self.assertEqual(code, 0, err)
self.assertTrue(out.startswith("Replayed 1 prose rounds"), out)
self.assertIn("Left out 1 more", out)
def test_tries_no_lower_rung_where_the_project_rung_found_nothing(self):
code, out, err = self.run_main(["prose", "claude-opus-5-5"], lambda rung: {"found": []})
self.assertEqual(code, 0, err)
self.assertEqual([rung for rung, *_ in self.reviews], [REFERENCE, REFERENCE])
self.assertTrue(out.endswith("No rung tried: the project's rung found none of them.\n"), 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(["stability", "claude-opus-5-5"], lambda rung: {"found": [0]})[0], 0)
@@ -485,7 +504,7 @@ class Main(unittest.TestCase):
def test_exits_1_on_a_usage_limit_bad_arguments_or_no_round_to_replay(self):
code, _, err = self.run_main(["stability", "claude-opus-5-5"], lambda rung: {"type": "result", "api_error_status": 429, "result": "You've hit your limit"})
self.assertEqual(code, 1)
self.assertIn("usage limit: You've hit your limit", err)
self.assertIn("review-replay: claude hit a usage limit: You've hit your limit", err)
for argv in ([], ["claude-opus-5-5"], ["full scan", "claude-opus-5-5"], ["stability", "off-ladder"], ["stability", "claude-opus-5-5", "x"]):
with self.subTest(argv=argv):
self.assertEqual(self.run_main(argv, unused)[0], 1)