Close stdin on the worker, pipe the judge its prompt, ground empty evidence, and skip meta turns in the handoff count

This commit is contained in:
2026-09-24 20:38:42 +02:00
parent b5a7a116c2
commit 15bbae8a4e
4 changed files with 55 additions and 31 deletions
+20 -5
View File
@@ -6,6 +6,9 @@ import pathlib
import stat
import tempfile
import unittest
import uuid
SESSION_ID = str(getattr(uuid, "uuid7", uuid.uuid4)())
LOADER = importlib.machinery.SourceFileLoader("loop_claude", str(pathlib.Path(__file__).with_name("loop-claude")))
SPEC = importlib.util.spec_from_loader("loop_claude", LOADER)
@@ -43,20 +46,22 @@ class HumanTurns(unittest.TestCase):
human("typed"),
human([{"type": "text", "text": "typed as a block"}]),
human([{"type": "tool_result", "content": "not typed"}]),
human("<command-name>/model</command-name>"),
{**human("peer message"), "isMeta": True},
assistant({"type": "text", "text": "said"}),
]), 2)
class WorkerArgs(unittest.TestCase):
def test_a_fresh_round_names_the_session_and_asks_to_continue_open_work(self):
args = loop.worker_args("the task", "A name", "slot-id", resuming=False)
args = loop.worker_args("the task", "A name", SESSION_ID, resuming=False)
self.assertIn("--session-id", args)
self.assertEqual(args[args.index("--name") + 1], "A name")
self.assertTrue(args[1].startswith("the task\n\nContinue any open draft PR"))
def test_a_resumed_round_reuses_the_session(self):
args = loop.worker_args("paint the fence", "A name", "slot-id", resuming=True)
self.assertEqual(args[args.index("--resume") + 1], "slot-id")
args = loop.worker_args("paint the fence", "A name", SESSION_ID, resuming=True)
self.assertEqual(args[args.index("--resume") + 1], SESSION_ID)
self.assertNotIn("--name", args)
self.assertNotIn("paint the fence", args[1])
@@ -93,18 +98,28 @@ class Said(unittest.TestCase):
class EndSession(unittest.TestCase):
def test_removes_the_transcript_and_its_sibling_folder(self):
with tempfile.TemporaryDirectory() as root:
transcript = os.path.join(root, "abc.jsonl")
transcript = os.path.join(root, f"{SESSION_ID}.jsonl")
open(transcript, "w").write("{}\n")
os.makedirs(os.path.join(root, "abc", "subagents"))
os.makedirs(os.path.join(root, SESSION_ID, "subagents"))
os.makedirs(os.path.join(root, f"{SESSION_ID}.superseded-1", "tool-results"))
open(os.path.join(root, f"{SESSION_ID}.orphaned-1-ab.jsonl"), "w").write("{}\n")
loop.end_session(transcript)
self.assertEqual(os.listdir(root), [])
class Parse(unittest.TestCase):
def test_yields_only_json_objects(self):
self.assertEqual(loop.parse('{"type": "user"}'), {"type": "user"})
self.assertIsNone(loop.parse("not json"))
self.assertIsNone(loop.parse("[1, 2]"))
class Grounded(unittest.TestCase):
def test_an_interrupt_must_quote_the_transcript(self):
self.assertTrue(loop.grounded({"ask": False, "evidence": ""}, "anything"))
self.assertTrue(loop.grounded({"ask": True, "evidence": "Needs you: x"}, "so.\n\nNeeds you: x\n"))
self.assertFalse(loop.grounded({"ask": True, "evidence": "invented"}, "the transcript"))
self.assertFalse(loop.grounded({"ask": True, "evidence": ""}, "the transcript"))
if __name__ == "__main__":