Answer principles round 1: 1 🔴, 7 🟡 (0 misread); every effect is handed in as an argument, no test patches a global, and the traces principle scopes tools that run on their user's machine
CI / tests (pull_request) Successful in 3m43s

This commit is contained in:
2026-11-19 12:42:03 +01:00
parent 8ca612b7a4
commit cb3135bc8c
124 changed files with 1437 additions and 793 deletions
@@ -10,11 +10,12 @@ import unittest
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
from transcript_archive.project_key import checkout_of, project_key
from text_files import compressed
from text_files.doubles import compress
from failure import Failure
from transcript_archive.judge_run import JudgeRun
from transcript_archive import outcomes, read, write
from transcript_archive.location import project_archive
from text_files.file_writes import replace_file
from text_files.utc_stamp import utc
NOW = 1790000000
@@ -27,10 +28,10 @@ class Archive(unittest.TestCase):
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.unfinished("m", "working", "j", ""), NOW))
self.assertIsNone(write.archive(kept, str(transcript), "Do it.", outcomes.unfinished("m", "working", "j", ""), NOW, replace=replace_file))
(kept_outcomes,) = kept.glob("*/*.outcomes.md")
kept_outcomes.unlink()
self.assertIsNone(write.archive(kept, str(transcript), "Do it.", outcomes.stopped("m", "Ctrl-C"), NOW))
self.assertIsNone(write.archive(kept, str(transcript), "Do it.", outcomes.stopped("m", "Ctrl-C"), NOW, replace=replace_file))
self.assertEqual(kept_outcomes.read_text(), "Task: Do it.\n\n2026-09-21T14:13:20Z Stopped: Ctrl-C\n\nWorker: m\n")
@@ -45,7 +46,7 @@ class JudgeRuns(unittest.TestCase):
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))
self.assertIsNone(write.archive(kept, str(transcript), "Do it.", outcome, NOW + offset, judge_run=self.judged, replace=replace_file))
(folder,) = kept.glob("*/")
(file,) = folder.glob("judge/*")
self.assertEqual(file, folder / self.judged.file)
@@ -91,7 +92,7 @@ class JudgeRuns(unittest.TestCase):
def test_names_the_folder_it_cannot_make_in_the_failure_to_keep_a_run(self):
with tempfile.TemporaryDirectory() as root:
(pathlib.Path(root) / "judge").write_text("a file where the folder should be")
failure = write.keep_judge_run(pathlib.Path(root), self.judged)
failure = write.keep_judge_run(pathlib.Path(root), self.judged, replace_file)
self.assertRegex(failure.reason, f"^could not archive the transcript: {root}/judge: ")
self.assertNotIn("None", failure.reason)
@@ -101,10 +102,10 @@ class JudgeRuns(unittest.TestCase):
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))
self.assertIsNone(write.archive(kept, str(transcript), "Do it.", outcomes.stopped("w", "x"), NOW, replace=replace_file))
(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)
failure = write.archive(kept, str(transcript), "Do it.", outcomes.finished("w", "e", "j", judge_run=self.judged), NOW + 1, judge_run=self.judged, replace=replace_file)
self.assertIsInstance(failure, Failure)
self.assertNotIn("Verdict: finished", next(folder.glob("*.outcomes.md")).read_text())
@@ -124,7 +125,7 @@ class CopyFor(unittest.TestCase):
with tempfile.TemporaryDirectory() as temp:
copy = pathlib.Path(temp, "agent-a.jsonl")
copy.write_bytes(b"first\n")
self.assertIsNone(compressed.compress(copy))
self.assertIsNone(compress(copy))
self.assertIsNone(write.copy_for(copy, b"first\n"))
self.assertEqual(write.copy_for(copy, b"first\nsecond\n"), copy)
self.assertEqual(write.copy_for(copy, b"other\n"), copy.with_name(f"agent-a.jsonl.{hashlib.sha256(b'other' + bytes([10])).hexdigest()}"))
@@ -141,9 +142,9 @@ class Compressed(unittest.TestCase):
subagent.parent.mkdir(parents=True)
subagent.write_text('{"sub": 1}\n')
with contextlib.redirect_stderr(io.StringIO()):
self.assertIsNone(write.archive(kept, str(transcript), "Do it.", outcomes.finished("w", "merged", "j"), NOW))
self.assertIsNone(write.archive(kept, str(transcript), "Do it.", outcomes.finished("w", "merged", "j"), NOW, replace=replace_file))
for copy in kept.rglob("*.jsonl"):
self.assertIsNone(compressed.compress(copy))
self.assertIsNone(compress(copy))
return transcript
def test_a_compressed_copy_takes_the_next_outcome_and_is_not_copied_again(self):
@@ -151,7 +152,7 @@ class Compressed(unittest.TestCase):
transcript = self.archived(root)
kept = pathlib.Path(root, "archive")
with contextlib.redirect_stderr(io.StringIO()):
self.assertIsNone(write.archive(kept, str(transcript), "Do it.", outcomes.stopped("w", "Ctrl-C"), NOW + 1))
self.assertIsNone(write.archive(kept, str(transcript), "Do it.", outcomes.stopped("w", "Ctrl-C"), NOW + 1, replace=replace_file))
self.assertEqual([path.name.endswith(".gz") for path in kept.rglob("*.jsonl*")], [True, True])
self.assertIn("Stopped: Ctrl-C", next(kept.glob("*/*.outcomes.md")).read_text())
@@ -208,7 +209,7 @@ class Outcomes(unittest.TestCase):
transcript.write_text('{"timestamp": "2026-10-03T00:00:00Z"}\n')
with contextlib.redirect_stderr(io.StringIO()):
for worker in ("z-first", "a-last"):
self.assertIsNone(write.archive(kept, str(transcript), "Do it.", outcomes.unfinished(worker, "working", "j", ""), NOW))
self.assertIsNone(write.archive(kept, str(transcript), "Do it.", outcomes.unfinished(worker, "working", "j", ""), NOW, replace=replace_file))
self.assertEqual(read.latest_worker(kept, str(transcript)), "a-last")
def test_names_the_worker_the_latest_outcome_of_the_transcripts_chunk_records(self):
@@ -218,9 +219,9 @@ class Outcomes(unittest.TestCase):
transcript.write_text('{"timestamp": "2026-10-03T00:00:00Z"}\n')
self.assertIsNone(read.latest_worker(kept, str(transcript)))
with contextlib.redirect_stderr(io.StringIO()):
self.assertIsNone(write.archive(kept, str(transcript), "Do it.", outcomes.unfinished("w1", "working", "j", ""), NOW))
self.assertIsNone(write.archive(kept, str(transcript), "Do it.", outcomes.unfinished("w1", "working", "j", ""), NOW, replace=replace_file))
transcript.write_text('{"timestamp": "2026-10-03T00:00:00Z"}\n{"more": 1}\n')
self.assertIsNone(write.archive(kept, str(transcript), "Do it.", outcomes.stopped("w2", "Ctrl-C"), NOW + 1))
self.assertIsNone(write.archive(kept, str(transcript), "Do it.", outcomes.stopped("w2", "Ctrl-C"), NOW + 1, replace=replace_file))
self.assertEqual(read.latest_worker(kept, str(transcript)), "w2")
self.assertIsInstance(read.latest_worker(kept, str(pathlib.Path(root, "gone.jsonl"))), Failure)
@@ -247,8 +248,8 @@ class Outcomes(unittest.TestCase):
transcript.write_text('{"timestamp": "2026-10-03T00:00:00Z"}\n')
self.assertEqual(read.last_spent(kept, str(transcript)), "")
with contextlib.redirect_stderr(io.StringIO()):
self.assertIsNone(write.archive(kept, str(transcript), "Do it.", outcomes.unfinished("w", "e", "j", "", annotation=outcomes.Annotation("c", "Spent since the chunk began, in tokens of x:\n- worker, m: 1")), NOW))
self.assertIsNone(write.archive(kept, str(transcript), "Do it.", outcomes.stopped("w", "Ctrl-C"), NOW + 1))
self.assertIsNone(write.archive(kept, str(transcript), "Do it.", outcomes.unfinished("w", "e", "j", "", annotation=outcomes.Annotation("c", "Spent since the chunk began, in tokens of x:\n- worker, m: 1")), NOW, replace=replace_file))
self.assertIsNone(write.archive(kept, str(transcript), "Do it.", outcomes.stopped("w", "Ctrl-C"), NOW + 1, replace=replace_file))
self.assertEqual(read.last_spent(kept, str(transcript)), utc(NOW))
gone = read.last_spent(kept, str(pathlib.Path(root, "gone.jsonl")))
self.assertIsInstance(gone, Failure)