Files
claude-config/bin/review_replay/test_recall.py
T

90 lines
4.5 KiB
Python

from fractions import Fraction
import pathlib
import sys
import unittest
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
from review_replay.recall import candidates, Recall, recall_report, tried
from review_replay.rounds import Round
from model_routing.ladder import Rung
REFERENCE = Rung("claude-opus-5-5", "medium")
LOW = Rung("claude-opus-5-5", "low")
SONNET = Rung("claude-sonnet-5-5", "high")
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%.
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}]
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_lower_effort_of_the_ladders_lowest_rung(self):
self.assertEqual(candidates(SONNET), [Rung("claude-sonnet-5-5", "medium"), Rung("claude-sonnet-5-5", "low")])
class Tried(unittest.TestCase):
def test_qualifies_a_rung_no_more_than_the_margin_below_the_project_rungs_share_that_misses_no_red_found_both_times(self):
found = tried(LOW, ROUNDS, (FIRST, SECOND), [{0, 1, 2}, {0, 1, 2}])
self.assertEqual((found.share, found.missed_red, found.qualifies), (Fraction(3, 5), [], True))
def test_fails_a_rung_below_the_bar(self):
found = tried(LOW, ROUNDS, (FIRST, SECOND), [{0, 1}, {0, 3}])
self.assertEqual((found.share, found.missed_red, found.qualifies), (Fraction(2, 5), [], False))
def test_fails_a_rung_that_misses_a_red_found_both_times_and_only_such_a_red(self):
above_the_bar = [{1, 2, 3, 4}, {0, 1, 2, 3}]
found = tried(LOW, ROUNDS, (FIRST, SECOND), above_the_bar)
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)
def test_fails_every_rung_where_the_project_rung_found_nothing(self):
self.assertFalse(tried(LOW, ROUNDS, ([set(), set()], [set(), set()]), [{0}, {0}]).qualifies)
class RecallReport(unittest.TestCase):
# Eight rounds, enough to try a rung.
EIGHT = (ROUNDS * 4, (FIRST * 4, SECOND * 4))
def test_states_the_bar_each_rung_tried_each_red_it_missed_and_the_lowest_that_qualifies(self):
rounds, reference = self.EIGHT
low = tried(LOW, rounds, reference, [{0, 1, 2}, {0, 1, 2}] * 4)
sonnet = tried(SONNET, rounds, reference, [{1, 2, 3, 4}, {0}] * 4)
lines = recall_report("prose", REFERENCE, Recall(rounds, reference, 1, [low, sonnet], LOW)).splitlines()
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.",
"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,
"Lowest rung that qualifies: claude-opus-5-5 at low effort",
])
def test_says_why_no_rung_was_tried(self):
few = recall_report("prose", REFERENCE, Recall(ROUNDS, (FIRST, SECOND), 0, [], None)).splitlines()
self.assertEqual(few[1:], ["No rung tried: fewer than 8 rounds were replayed on the project's rung without a failure."])
rounds, _ = self.EIGHT
none_found = recall_report("prose", REFERENCE, Recall(rounds, ([set()] * 8, [set()] * 8), 0, [], None)).splitlines()
self.assertEqual(none_found[1:], ["No rung tried: the project's rung found none of them."])
def test_names_no_rung_where_none_qualifies(self):
rounds, reference = self.EIGHT
low = tried(LOW, rounds, reference, [{0}, {0}] * 4)
lines = recall_report("prose", REFERENCE, Recall(rounds, reference, 0, [low], None)).splitlines()
self.assertEqual(lines[-2:], ["claude-opus-5-5 at low effort found 20% and missed no such 🔴.", "Lowest rung that qualifies: none below the project's rung"])
if __name__ == "__main__":
unittest.main()