Archive each judge run's prompt and json reply beside the verdict it gave, and replay from the archived prompt
CI / tests (pull_request) Failing after 2m45s
CI / tests (pull_request) Failing after 2m45s
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import contextlib
|
||||
import hashlib
|
||||
import io
|
||||
import json
|
||||
import pathlib
|
||||
import sys
|
||||
import tempfile
|
||||
@@ -11,6 +12,7 @@ sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
||||
from transcript_archive.project_key import checkout_of, project_key
|
||||
from failure import Failure
|
||||
from transcript_archive import outcomes, read, write
|
||||
from transcript_archive.judge_run import JudgeRun
|
||||
from transcript_archive.location import project_archive
|
||||
from text_files.utc_stamp import utc
|
||||
|
||||
@@ -31,6 +33,49 @@ class Archive(unittest.TestCase):
|
||||
self.assertEqual(kept_outcomes.read_text(), "Task: Do it.\n\n2026-09-21T14:13:20Z Stopped: Ctrl-C\n\nWorker: m\n")
|
||||
|
||||
|
||||
class JudgeRuns(unittest.TestCase):
|
||||
judged = JudgeRun("The prompt.", {"structured_output": {"finished": True}, "total_cost_usd": 0.5})
|
||||
|
||||
def test_a_run_is_kept_once_in_the_chunk_folder_under_the_hash_of_its_content(self):
|
||||
with tempfile.TemporaryDirectory() as root:
|
||||
kept = pathlib.Path(root, "archive")
|
||||
transcript = pathlib.Path(root, "t.jsonl")
|
||||
transcript.write_text('{"timestamp": "2026-10-03T00:00:00Z"}\n')
|
||||
with contextlib.redirect_stderr(io.StringIO()):
|
||||
for offset in (0, 1):
|
||||
outcome = outcomes.finished("w", "merged", "j", judge_run=self.judged)
|
||||
self.assertIsNone(write.archive(kept, str(transcript), "Do it.", outcome, NOW + offset, judge_run=self.judged))
|
||||
(folder,) = kept.glob("*/")
|
||||
(file,) = folder.glob("judge/*")
|
||||
self.assertEqual(file, folder / self.judged.file)
|
||||
self.assertEqual(file.name, hashlib.sha256(file.read_bytes()).hexdigest() + ".json")
|
||||
self.assertEqual(json.loads(file.read_text()), {"prompt": "The prompt.", "reply": {"structured_output": {"finished": True}, "total_cost_usd": 0.5}})
|
||||
self.assertEqual(JudgeRun.read(file), self.judged)
|
||||
|
||||
def test_names_the_run_on_the_line_after_the_judge_lines_and_reads_the_name_back(self):
|
||||
outcome = outcomes.finished("w", "e", "j", judge_cost=0.5, judge_run=self.judged)
|
||||
self.assertEqual(outcome, f"Verdict: finished\n\nEvidence:\n> e\n\nJudge: j\nJudge cost: 0.5000\nJudge run: {self.judged.file}\nWorker: w")
|
||||
self.assertEqual(outcomes.rejected("why", "{}", "j", judge_run=self.judged), f"Judge reply rejected: why\n\nReply:\n> {{}}\n\nJudge: j\nJudge run: {self.judged.file}")
|
||||
self.assertEqual(outcomes.workers(f"{utc(NOW)} {outcome}\n"), [(utc(NOW), "w")])
|
||||
self.assertEqual(outcomes.judge_costs(f"{utc(NOW)} {outcome}\n"), [("j", 0.5)])
|
||||
kept = f"Task: Do it.\n\n{utc(NOW)} {outcomes.stopped('w', 'Ctrl-C')}\n\n{utc(NOW + 1)} {outcome}\n\n{utc(NOW + 2)} {outcomes.finished('w', 'e', 'j')}\n"
|
||||
self.assertEqual(outcomes.judge_run_at(kept, utc(NOW + 1)), self.judged.file)
|
||||
self.assertIsNone(outcomes.judge_run_at(kept, utc(NOW + 2)))
|
||||
|
||||
def test_writes_no_outcome_where_the_run_cannot_be_kept(self):
|
||||
with tempfile.TemporaryDirectory() as root:
|
||||
kept = pathlib.Path(root, "archive")
|
||||
transcript = pathlib.Path(root, "t.jsonl")
|
||||
transcript.write_text('{"timestamp": "2026-10-03T00:00:00Z"}\n')
|
||||
with contextlib.redirect_stderr(io.StringIO()):
|
||||
self.assertIsNone(write.archive(kept, str(transcript), "Do it.", outcomes.stopped("w", "x"), NOW))
|
||||
(folder,) = kept.glob("*/")
|
||||
(folder / "judge").write_text("a file where the folder should be")
|
||||
failure = write.archive(kept, str(transcript), "Do it.", outcomes.finished("w", "e", "j", judge_run=self.judged), NOW + 1, judge_run=self.judged)
|
||||
self.assertIsInstance(failure, Failure)
|
||||
self.assertNotIn("Verdict: finished", next(folder.glob("*.outcomes.md")).read_text())
|
||||
|
||||
|
||||
class CopyFor(unittest.TestCase):
|
||||
def test_skips_a_version_already_kept_beside_its_copy(self):
|
||||
with tempfile.TemporaryDirectory() as temp:
|
||||
|
||||
Reference in New Issue
Block a user