|
|
|
@@ -15,6 +15,8 @@ from project_config.test_project_config import configured
|
|
|
|
|
from loop_effects.effects import Effects
|
|
|
|
|
from failure import Failure
|
|
|
|
|
from loop_claude.verdicts import Finished, Interrupt, QuotedAnswer, Unfinished
|
|
|
|
|
from loop_claude.cycle.judge import TRANSCRIPT_HEADING, Rejected, judge_archived
|
|
|
|
|
from claude_code.entries import AssistantTurn, HumanTurn, LoopPrompt, Text
|
|
|
|
|
from judge_replay import main
|
|
|
|
|
from rung_replay.search import Miss, Replay, Tried
|
|
|
|
|
from model_routing.ladder import Rung
|
|
|
|
@@ -177,6 +179,8 @@ class Main(unittest.TestCase):
|
|
|
|
|
self.assertIn("The reference judge, claude-opus-5-5 at xhigh effort, reproduced 2.", out)
|
|
|
|
|
# The first replay, on the finished verdict, reads the archived prompt; the second, on the interrupt, is rebuilt from the records of today.
|
|
|
|
|
self.assertEqual(self.prompts[0], prompt)
|
|
|
|
|
self.assertEqual(self.calls[0][2], self.calls[1][2])
|
|
|
|
|
self.assertTrue(self.calls[0][2].endswith("/code/proj"))
|
|
|
|
|
self.assertIn("The task the worker was given:\nDo it.", self.prompts[1])
|
|
|
|
|
self.assertIn("1. Ship.", self.prompts[1])
|
|
|
|
|
|
|
|
|
@@ -253,6 +257,55 @@ class Main(unittest.TestCase):
|
|
|
|
|
self.assertEqual(ran.returncode, 0)
|
|
|
|
|
self.assertIn("usage: judge-replay <model>", ran.stdout)
|
|
|
|
|
|
|
|
|
|
def test_exits_1_on_a_usage_limit_met_on_an_archived_prompt(self):
|
|
|
|
|
kept = self.home / ".claude" / "loop-claude-transcripts" / "proj" / "c1"
|
|
|
|
|
(kept / "judge").mkdir()
|
|
|
|
|
(kept / "judge" / "run.json").write_text(json.dumps({"prompt": "P", "reply": {}}))
|
|
|
|
|
(kept / "t0.outcomes.md").write_text("Task: Do it.\n\n2026-10-14T10:00:00Z Verdict: finished\n\nJudge: j\nJudge run: judge/run.json\nWorker: x\n")
|
|
|
|
|
code, _, err = self.run_main(["claude-opus-5-5"], lambda rung, interrupted: {"type": "result", "api_error_status": 429, "result": "You've hit your limit"})
|
|
|
|
|
self.assertEqual((code, "usage limit: You've hit your limit" in err), (1, True))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class JudgeArchivedRuns(unittest.TestCase):
|
|
|
|
|
"""judge_archived on a prompt of two parts, as the archive keeps it: HEAD, the premises, and what follows TRANSCRIPT_HEADING, the transcript the judge was shown."""
|
|
|
|
|
PROMPT = f"HEAD: Ship fast.\n\n{TRANSCRIPT_HEADING}Worker chose option B.\n[human] Use Postgres.\n"
|
|
|
|
|
ENTRIES = [AssistantTurn(parts=(Text("Worker chose option B."),)), HumanTurn(text="Use Postgres."), LoopPrompt(text="Keep going.")]
|
|
|
|
|
|
|
|
|
|
def judged(self, **fields):
|
|
|
|
|
"""What judge_archived returns where the judge's structured output is fields over an unfinished verdict, and the cwd claude ran in."""
|
|
|
|
|
output = {"answer": "", "escalation": "", "evidence": "Worker chose option B.", "finished": False, "interrupt": False, "question": "", "answered_before": "", "left_open": "", "reversed": "", "release_ready": False, **fields}
|
|
|
|
|
cwds = []
|
|
|
|
|
|
|
|
|
|
def claude(args, cwd, prompt):
|
|
|
|
|
cwds.append(cwd)
|
|
|
|
|
return subprocess.CompletedProcess(args, 0, json.dumps({"type": "result", "structured_output": output, "total_cost_usd": 0.25}), "")
|
|
|
|
|
|
|
|
|
|
effects = Effects(claude=claude, claude_on_terminal=unused, discard_typed=unused, dm=unused, execv=unused, git=unused, input=unused, local_time=unused, memory=unused, now=unused, on_terminal=unused, python=unused, sleep=unused, stream_claude=unused, tmux=unused, tmux_on_terminal=unused)
|
|
|
|
|
return judge_archived("/code/p", self.PROMPT, self.ENTRIES, REFERENCE, effects), cwds
|
|
|
|
|
|
|
|
|
|
def test_runs_in_the_projects_folder_and_stamps_the_verdict_with_the_entries_read(self):
|
|
|
|
|
verdict, cwds = self.judged()
|
|
|
|
|
self.assertEqual((cwds, verdict.entries_read), (["/code/p"], 3))
|
|
|
|
|
|
|
|
|
|
def test_checks_the_evidence_against_the_transcript_the_judge_was_shown_and_not_the_premises(self):
|
|
|
|
|
self.assertIsInstance(self.judged(evidence="Ship fast.")[0], Rejected)
|
|
|
|
|
self.assertIsInstance(self.judged(evidence="Worker chose option B.")[0], Unfinished)
|
|
|
|
|
|
|
|
|
|
def test_keeps_the_cost_and_the_run_of_a_rejected_reply(self):
|
|
|
|
|
rejected, _ = self.judged(evidence="Never said.")
|
|
|
|
|
self.assertEqual((rejected.cost, rejected.run.prompt), (0.25, self.PROMPT))
|
|
|
|
|
|
|
|
|
|
def test_checks_a_quoted_answer_against_the_premises(self):
|
|
|
|
|
self.assertIsInstance(self.judged(answer="Ship fast.", question="Which?")[0], QuotedAnswer)
|
|
|
|
|
self.assertIsInstance(self.judged(answer="Use Postgres.", question="Which?")[0], Interrupt)
|
|
|
|
|
|
|
|
|
|
def test_keeps_an_escalation_that_the_worker_wrote_after_the_start_of_the_transcript(self):
|
|
|
|
|
self.assertEqual(self.judged(escalation="Worker chose option B.")[0].escalation, "Worker chose option B.")
|
|
|
|
|
self.assertEqual(self.judged(escalation="Use Postgres.")[0].escalation, "")
|
|
|
|
|
|
|
|
|
|
def test_names_the_typed_answer_that_holds_a_reversal(self):
|
|
|
|
|
self.assertEqual(self.judged(reversed="Use Postgres.")[0].judged.reversed, "Use Postgres.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
unittest.main()
|
|
|
|
|