Pin evidence on every verdict, a named non-object trust entry, one spelling of the human being needed, and a claude the judge or interrupt cannot start

This commit is contained in:
2026-09-28 16:37:55 +02:00
parent 8b5569519c
commit a1c5e8a16b
2 changed files with 83 additions and 58 deletions
+46 -46
View File
@@ -15,7 +15,7 @@ import uuid
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parent))
from loop_claude import checkout, cycle, main, premises, reload, session, transcript, worker
from loop_claude import checkout, cycle, interrupt, judge, main, models, premises, reload, session, transcript, trust, worker
from loop_claude.outcome import Continue, Failure, Retry, Stop
from loop_claude.paths import paths_from
@@ -24,6 +24,7 @@ LAUNCHER = pathlib.Path(__file__).resolve().with_name("loop-claude")
PATHS = paths_from(pathlib.Path("/h"), {})
SESSION_ID = str(getattr(uuid, "uuid7", uuid.uuid4)())
SESSION = session.Session(uuid.UUID(SESSION_ID), "A name", PATHS.projects)
OPUS = models.Models("claude-opus-5-5", "claude-opus-5-5")
def assistant(*parts):
@@ -146,10 +147,6 @@ class WorkerArgs(unittest.TestCase):
self.assertNotIn("--name", args)
self.assertNotIn("paint the fence", args[1])
def test_the_project_model_runs_unless_the_environment_names_one(self):
self.assertEqual(cycle.model_for({}, "LOOP_CLAUDE_WORKER_MODEL", "claude-opus-5-5"), "claude-opus-5-5")
self.assertEqual(cycle.model_for({"LOOP_CLAUDE_WORKER_MODEL": "claude-fable-5-1"}, "LOOP_CLAUDE_WORKER_MODEL", "claude-opus-5-5"), "claude-fable-5-1")
class ProjectModel(unittest.TestCase):
def test_asks_once_per_project_from_the_newest_catalog_and_saves_the_answer(self):
@@ -161,19 +158,19 @@ class ProjectModel(unittest.TestCase):
for name, fetched, ids in (("old.json", 1, ["claude-opus-5"]), ("new.json", 2, ["claude-opus-5-5", "claude-sonnet-5"])):
catalog.joinpath(name).write_text(json.dumps({"fetchedAt": fetched, "catalog": {"config": {"models": [{"id": id, "name": id.upper()} for id in ids]}}}))
with unittest.mock.patch("sys.stdin.isatty", return_value=False):
stop = cycle.project_model("/srv/a", paths, {})
stop = models.project_models("/srv/a", paths, {})
self.assertEqual(stop.code, 2)
self.assertIn(f'merge {{"srv/a": "<model>"}} into {saved}', stop.reason)
self.assertFalse(saved.exists())
with unittest.mock.patch("sys.stdin.isatty", return_value=False):
self.assertEqual(cycle.project_model("/srv/a", paths, {"LOOP_CLAUDE_JUDGE_MODEL": "j", "LOOP_CLAUDE_WORKER_MODEL": "w"}), "")
self.assertEqual(cycle.project_model("/srv/a", paths, {"LOOP_CLAUDE_JUDGE_MODEL": "j"}).code, 2)
self.assertEqual(models.project_models("/srv/a", paths, {"LOOP_CLAUDE_JUDGE_MODEL": "j", "LOOP_CLAUDE_WORKER_MODEL": "w"}), models.Models("j", "w"))
self.assertEqual(models.project_models("/srv/a", paths, {"LOOP_CLAUDE_JUDGE_MODEL": "j"}).code, 2)
with (
unittest.mock.patch("sys.stdin.isatty", return_value=True),
unittest.mock.patch("sys.stdout.isatty", return_value=True),
unittest.mock.patch("builtins.input", side_effect=["", "3", "2"]) as typed,
):
self.assertEqual(cycle.project_model("/srv/a", paths, {}), "claude-sonnet-5")
self.assertEqual(models.project_models("/srv/a", paths, {}), models.Models("claude-sonnet-5", "claude-sonnet-5"))
self.assertEqual(typed.call_count, 3)
self.assertIn("2. CLAUDE-SONNET-5 (claude-sonnet-5)", sys.stderr.getvalue())
self.assertIn("pick 1 to 2", sys.stderr.getvalue())
@@ -185,33 +182,34 @@ class ProjectModel(unittest.TestCase):
saved.write_text(json.dumps({**json.loads(saved.read_text()), "srv/d": "haiku"}))
return "opus[1m]"
typed.side_effect = saved_elsewhere_while_asking
self.assertEqual(cycle.project_model("/srv/b", paths, {}), "opus[1m]")
self.assertEqual(cycle.project_model("/srv/a", paths, {}), "claude-sonnet-5")
self.assertEqual(models.project_models("/srv/b", paths, {}), models.Models("opus[1m]", "opus[1m]"))
self.assertEqual(models.project_models("/srv/a", paths, {}), models.Models("claude-sonnet-5", "claude-sonnet-5"))
self.assertEqual(models.project_models("/srv/a", paths, {"LOOP_CLAUDE_WORKER_MODEL": "w"}), models.Models("claude-sonnet-5", "w"))
self.assertEqual(typed.call_count, 4)
typed.side_effect = EOFError
self.assertEqual(cycle.project_model("/srv/c", paths, {}), Stop(2, "no model picked"))
self.assertEqual(models.project_models("/srv/c", paths, {}), Stop(2, "the human is needed to pick srv/c's model, but the input ended"))
typed.side_effect = ["sonnet"]
with unittest.mock.patch("os.replace", side_effect=OSError(errno.EACCES, "Permission denied")):
self.assertEqual(cycle.project_model("/srv/c", paths, {}), Stop(1, f"could not save the model in {saved}: Permission denied"))
self.assertEqual(models.project_models("/srv/c", paths, {}), Stop(1, f"could not save the model in {saved}: Permission denied"))
self.assertEqual(json.loads(saved.read_text()), {"srv/a": "claude-sonnet-5", "srv/b": "opus[1m]", "srv/d": "haiku"})
self.assertEqual(stat.S_IMODE(saved.stat().st_mode), 0o640)
self.assertEqual(sorted(os.listdir(saved.parent)), ["cache", "loop-claude-models.json"])
for shape in ({"fetchedAt": 3, "catalog": {"config": {"models": []}}}, {"fetchedAt": 3, "catalog": None}, {"fetchedAt": 3, "catalog": {"config": []}}, {"fetchedAt": 3, "catalog": {"config": {"models": "x"}}}):
catalog.joinpath("new.json").write_text(json.dumps(shape))
with self.subTest(shape=shape):
self.assertEqual(cycle.catalog(catalog), [])
self.assertEqual(models.catalog(catalog), [])
with (
unittest.mock.patch("sys.stdin.isatty", return_value=True),
unittest.mock.patch("sys.stdout.isatty", return_value=True),
unittest.mock.patch("builtins.input", side_effect=["1"]) as typed,
):
self.assertEqual(cycle.project_model("/srv/e", paths, {}), "1")
self.assertEqual(models.project_models("/srv/e", paths, {}), models.Models("1", "1"))
self.assertEqual(typed.call_args.args[0], "A name claude --model takes: ")
self.assertIn("no model catalog cached", sys.stderr.getvalue())
for broken in ("{", "[]", '{"srv/a": 1}'):
saved.write_text(broken)
with self.subTest(broken=broken):
stop = cycle.project_model("/srv/a", paths, {})
stop = models.project_models("/srv/a", paths, {})
self.assertEqual(stop.code, 1)
self.assertTrue(stop.reason.startswith(f"could not read {saved}: "))
self.assertEqual(saved.read_text(), broken)
@@ -219,10 +217,10 @@ class ProjectModel(unittest.TestCase):
class JudgePrompt(unittest.TestCase):
def test_hands_the_judge_the_tail_of_a_long_transcript(self):
prompt = cycle.judge_prompt("task", "## Goals\n1. g", "early " * 20000 + "LATE")
prompt = judge.judge_prompt("task", "## Goals\n1. g", "early " * 20000 + "LATE")
self.assertIn("LATE", prompt)
self.assertLess(prompt.count("early"), 20000)
self.assertTrue(prompt.endswith(cycle.JUDGE_RULES))
self.assertTrue(prompt.endswith(judge.JUDGE_RULES))
class Archive(unittest.TestCase):
@@ -273,14 +271,14 @@ class Interrupt(unittest.TestCase):
transcript = os.path.join(root, "session.jsonl")
pathlib.Path(transcript).write_text("{}\n")
with unittest.mock.patch("sys.stdin.isatty", return_value=False):
self.assertEqual(cycle.interrupt(root, SESSION_ID, "m", transcript, "q?", paths_from(pathlib.Path(root), {}), {}), Stop(2, "stdin or stdout is not a terminal"))
self.assertEqual(interrupt.interrupt(root, SESSION_ID, "m", transcript, "q?", paths_from(pathlib.Path(root), {})), Stop(2, "the human is needed to answer the question above, but stdin or stdout is not a terminal"))
with (
unittest.mock.patch("sys.stdin.isatty", return_value=True),
unittest.mock.patch("sys.stdout.isatty", return_value=True),
unittest.mock.patch.multiple(cycle, checkouts=unittest.mock.DEFAULT, trust=unittest.mock.DEFAULT) as mocks,
unittest.mock.patch.multiple(interrupt, checkouts=unittest.mock.DEFAULT, trust=unittest.mock.DEFAULT) as mocks,
unittest.mock.patch("subprocess.run") as run,
):
self.assertEqual(cycle.interrupt(root, SESSION_ID, "m", transcript, "q?", paths_from(pathlib.Path(root), {}), {}), Stop(2, "the interrupt ended without the human typing anything"))
self.assertEqual(interrupt.interrupt(root, SESSION_ID, "m", transcript, "q?", paths_from(pathlib.Path(root), {})), Stop(2, "the human is needed to answer the question above, but the interrupt ended without you typing anything"))
mocks["checkouts"].assert_called_with(root)
self.assertEqual(run.call_args.kwargs["cwd"], root)
self.assertEqual(run.call_args.args[0][run.call_args.args[0].index("--model") + 1], "m")
@@ -289,7 +287,7 @@ class Interrupt(unittest.TestCase):
handle.write(json.dumps(human("typed")) + "\n")
run.side_effect = type_a_turn
self.assertIsNone(cycle.interrupt(root, SESSION_ID, "m", transcript, "q?", paths_from(pathlib.Path(root), {}), {}))
self.assertIsNone(interrupt.interrupt(root, SESSION_ID, "m", transcript, "q?", paths_from(pathlib.Path(root), {})))
class Trust(unittest.TestCase):
@@ -297,27 +295,27 @@ class Trust(unittest.TestCase):
with tempfile.TemporaryDirectory() as home, umask(0o022):
config = pathlib.Path(home, ".claude.json")
with contextlib.redirect_stderr(io.StringIO()) as err:
cycle.trust(config, ["/a"])
trust.trust(config, ["/a"])
self.assertEqual(err.getvalue(), f"could not read {config}: No such file or directory\n")
config.write_text("{")
with contextlib.redirect_stderr(io.StringIO()) as err:
cycle.trust(config, ["/a"])
trust.trust(config, ["/a"])
self.assertIn(f"could not read {config}: ", err.getvalue())
for shape in ([], {"projects": []}, {"projects": {"/a": 1}}):
for shape, said in (([], 'not an object whose "projects" is an object'), ({"projects": []}, 'not an object whose "projects" is an object'), ({"projects": {"/a": 1}}, 'projects["/a"] is not an object')):
config.write_text(json.dumps(shape))
with contextlib.redirect_stderr(io.StringIO()) as err:
cycle.trust(config, ["/a"])
self.assertEqual(err.getvalue(), f"could not read {config}: not an object whose \"projects\" maps paths to objects\n")
trust.trust(config, ["/a"])
self.assertEqual(err.getvalue(), f"could not read {config}: {said}\n")
self.assertEqual(json.loads(config.read_text()), shape)
data = {"other": 1, "projects": {"/a": {"hasTrustDialogAccepted": True, "kept": 2}}}
config.write_text(json.dumps(data))
config.chmod(0o600)
with contextlib.redirect_stderr(io.StringIO()) as err:
cycle.trust(config, ["/a"])
trust.trust(config, ["/a"])
self.assertEqual(err.getvalue(), "")
self.assertEqual(json.loads(config.read_text()), data)
with contextlib.redirect_stderr(io.StringIO()) as err:
cycle.trust(config, ["/a", "/b"])
trust.trust(config, ["/a", "/b"])
self.assertEqual(err.getvalue(), "trusted for the interrupt: /b\n")
data["projects"]["/b"] = {"hasTrustDialogAccepted": True}
self.assertEqual(json.loads(config.read_text()), data)
@@ -325,7 +323,7 @@ class Trust(unittest.TestCase):
contextlib.redirect_stderr(io.StringIO()) as err,
unittest.mock.patch("os.replace", side_effect=OSError(errno.EACCES, "Permission denied")),
):
cycle.trust(config, ["/c"])
trust.trust(config, ["/c"])
self.assertEqual(err.getvalue(), f"could not write {config}: Permission denied\n")
self.assertEqual(json.loads(config.read_text()), data)
self.assertEqual(stat.S_IMODE(config.stat().st_mode), 0o600)
@@ -340,19 +338,21 @@ class Parse(unittest.TestCase):
class Grounded(unittest.TestCase):
def test_an_interrupt_must_quote_the_transcript(self):
self.assertTrue(cycle.grounded({"interrupt": False, "evidence": ""}, "anything"))
self.assertTrue(cycle.grounded({"interrupt": True, "evidence": "Needs you: x"}, "so.\n\nNeeds you: x\n"))
self.assertFalse(cycle.grounded({"interrupt": True, "evidence": "invented"}, "the transcript"))
self.assertFalse(cycle.grounded({"interrupt": True, "evidence": ""}, "the transcript"))
self.assertFalse(cycle.grounded({"interrupt": True, "evidence": " "}, "the transcript"))
def test_every_verdict_must_quote_the_transcript(self):
for interrupting in (False, True):
self.assertTrue(judge.grounded({"interrupt": interrupting, "evidence": "Needs you: x"}, "so.\n\nNeeds you: x\n"))
self.assertFalse(judge.grounded({"interrupt": interrupting, "evidence": "invented"}, "the transcript"))
self.assertFalse(judge.grounded({"interrupt": interrupting, "evidence": ""}, "the transcript"))
self.assertFalse(judge.grounded({"interrupt": interrupting, "evidence": " "}, "the transcript"))
class Verdict(unittest.TestCase):
def test_needs_every_field_the_schema_requires(self):
self.assertTrue(cycle.complete({"interrupt": False, "evidence": "", "finished": True, "question": ""}))
self.assertFalse(cycle.complete({"interrupt": False}))
self.assertFalse(cycle.complete(None))
self.assertTrue(judge.complete({"interrupt": False, "evidence": "", "finished": True, "question": ""}))
self.assertFalse(judge.complete({"interrupt": "no", "evidence": "", "finished": True, "question": ""}))
self.assertFalse(judge.complete({"interrupt": False, "evidence": None, "finished": True, "question": ""}))
self.assertFalse(judge.complete({"interrupt": False}))
self.assertFalse(judge.complete(None))
STUB_CLAUDE = """#!/usr/bin/env python3
@@ -366,7 +366,7 @@ if "--json-schema" in args:
if plan[0] == "fail":
sys.exit(1)
interrupt = plan[0] in ("interrupt", "unquoted")
print(json.dumps({"structured_output": {"interrupt": interrupt, "evidence": {"interrupt": "worked", "unquoted": "invented"}.get(plan[0], ""), "finished": plan[0] == "finished", "question": "q?" if interrupt else ""}}))
print(json.dumps({"structured_output": {"interrupt": interrupt, "evidence": {"interrupt": "worked", "unquoted": "invented"}.get(plan[0], "worked"), "finished": plan[0] == "finished", "question": "q?" if interrupt else ""}}))
else:
flag = "--session-id" if "--session-id" in args else "--resume"
folder = os.path.expanduser("~/.claude/projects/p")
@@ -407,19 +407,19 @@ class RunCycle(unittest.TestCase):
environment = {"HOME": home, "PATH": f"{home}:{os.environ['PATH']}", "STUB_CALLS": calls, "STUB_VERDICTS": verdicts}
with unittest.mock.patch.dict(os.environ, environment), unittest.mock.patch("time.sleep") as sleep, unittest.mock.patch("sys.stdin.isatty", return_value=False):
for _ in range(3):
self.assertEqual(cycle.run_cycle(home, "task", "premises", "claude-opus-5-5", paths, {}), Continue())
self.assertEqual(cycle.run_cycle(home, "task", "premises", OPUS, paths), Continue())
pathlib.Path(verdicts).write_text("interrupt")
with unittest.mock.patch("sys.stderr") as stderr:
self.assertEqual(cycle.run_cycle(home, "task", "premises", "claude-opus-5-5", paths, {}), Stop(2, "stdin or stdout is not a terminal"))
self.assertEqual(cycle.run_cycle(home, "task", "premises", OPUS, paths), Stop(2, "the human is needed to answer the question above, but stdin or stdout is not a terminal"))
self.assertIn(f"transcript: {paths.archive}", "".join(str(call.args[0]) for call in stderr.write.call_args_list))
pathlib.Path(verdicts).write_text("interrupt fail fail fail")
with unittest.mock.patch("sys.stderr"), unittest.mock.patch.object(cycle, "interrupt", return_value=None):
self.assertEqual(cycle.run_cycle(home, "task", "premises", "claude-opus-5-5", paths, {}).code, 1)
self.assertEqual(cycle.run_cycle(home, "task", "premises", OPUS, paths).code, 1)
with unittest.mock.patch.object(cycle, "transcript_file", return_value=""):
self.assertEqual(cycle.run_cycle(home, "task", "premises", "claude-opus-5-5", paths, {}), Stop(1, f"claude left no transcript for session {session_id}"))
self.assertEqual(cycle.run_cycle(home, "task", "premises", OPUS, paths), Stop(1, f"claude left no transcript for session {session_id}"))
for plan in ("fail fail fail", "unquoted unquoted unquoted"):
pathlib.Path(verdicts).write_text(plan)
stop = cycle.run_cycle(home, "task", "premises", "claude-opus-5-5", paths, {})
stop = cycle.run_cycle(home, "task", "premises", OPUS, paths)
self.assertEqual(stop.code, 1)
self.assertTrue(stop.reason.startswith("the judge "))
if plan.startswith("unquoted"):
@@ -468,7 +468,7 @@ class RunLoop(unittest.TestCase):
self.assertEqual(main.loop_state([main.RELOAD_FLAG, *handed], CWD), Stop(1, f"the reload cannot read the loop's state from {handed}; rerun loop-claude <task>"))
def test_resumes_the_root_and_counters_a_reload_handed_over(self):
patches = [unittest.mock.patch.object(main, name) for name in ("checkout_root", "read_premises", "reload_if_edited", "run_cycle", "project_model")]
patches = [unittest.mock.patch.object(main, name) for name in ("checkout_root", "read_premises", "reload_if_edited", "run_cycle", "project_models")]
stopped = Stop(1, "stopped")
with contextlib.ExitStack() as stack:
mocks = [stack.enter_context(patch) for patch in patches]
+37 -12
View File
@@ -81,6 +81,8 @@ elif "type" in step:
append({{"type": "user", "message": {{"content": step["type"]}}}})
if step.get("unreadable"):
transcript().chmod(0)
if step.get("vanish"):
os.remove(__file__)
sys.exit(step.get("exit", 0))
"""
@@ -103,7 +105,7 @@ def worker(**step):
return {"role": "worker", **step}
def judge(interrupt=False, finished=False, evidence="", question="", **step):
def judge(interrupt=False, finished=False, evidence="working", question="", **step):
verdict = {"evidence": evidence, "finished": finished, "interrupt": interrupt, "question": question}
return {"role": "judge", "verdict": verdict, **step}
@@ -271,8 +273,8 @@ class Cycles(unittest.TestCase):
def test_resumes_the_session_while_unfinished_and_starts_it_fresh_after_finishing(self):
checkout = Checkout(self)
run = checkout.run([
worker(say="started"), judge(),
worker(say="landed-it"), judge(finished=True),
worker(say="started"), judge(evidence="started"),
worker(say="landed-it"), judge(finished=True, evidence="landed-it"),
worker(say="next chunk"),
])
self.assertEqual(run.code, 130)
@@ -314,17 +316,32 @@ class Cycles(unittest.TestCase):
self.assertIn("retrying the judge in a minute: judge down", run.stderr)
self.assertEqual(run.stderr.strip().splitlines()[-1], "the judge failed three times running: the judge returned no verdict")
def test_retries_the_judge_alone_when_its_interrupt_quotes_nothing_in_the_transcript(self):
def test_retries_the_judge_alone_when_its_verdict_quotes_nothing_in_the_transcript(self):
checkout = Checkout(self)
run = checkout.run([worker(say="Shall I use A or B?"), judge(interrupt=True, evidence="never said", question="A or B?"), judge()])
run = checkout.run([
worker(say="Shall I use A or B?"),
judge(interrupt=True, evidence="never said", question="A or B?"),
judge(finished=True, evidence=""),
judge(evidence="A or B"),
worker(),
])
self.assertEqual(run.code, 130)
self.assertEqual(run.roles(), ["worker", "judge", "judge", "worker"])
self.assertEqual(run.roles(), ["worker", "judge", "judge", "judge", "worker", "judge"])
self.assertEqual(run.sleeps, [60, 60])
self.assertIn("the judge quoted 'never said', nothing in the transcript, for the question: A or B?", run.stderr)
self.assertIn("retrying the judge in a minute: the judge quoted '', nothing in the transcript\n", run.stderr)
def test_retries_a_judge_claude_cannot_start(self):
checkout = Checkout(self)
run = checkout.run([worker(vanish=True)])
self.assertEqual((run.code, run.roles()), (1, ["worker"]))
self.assertEqual(run.sleeps, [60, 60])
self.assertEqual(run.stderr.strip().splitlines()[-1], "the judge failed three times running: could not start claude: No such file or directory")
def test_skips_a_malformed_transcript_or_stream_line(self):
checkout = Checkout(self)
raw = "\xff not UTF-8\nnot JSON\n[1]\n" + json.dumps({"type": "assistant", "message": "not an object"}) + "\n" + json.dumps({"type": "user", "message": None}) + "\n"
run = checkout.run([worker(raw=raw, say="past the noise", stream="\xff not UTF-8\n"), judge()])
run = checkout.run([worker(raw=raw, say="past the noise", stream="\xff not UTF-8\n"), judge(evidence="past the noise")])
self.assertEqual((run.code, run.roles()), (130, ["worker", "judge", "worker"]))
self.assertIn("past the noise", run.stdout)
self.assertIn("past the noise", run.calls[1]["stdin"])
@@ -360,13 +377,13 @@ class Interrupt(unittest.TestCase):
steps = [worker(say="Shall I use A or B?"), judge(interrupt=True, evidence="Shall I use A or B?", question="A or B?")]
run = checkout.run(steps)
self.assertEqual((run.code, run.roles()), (2, ["worker", "judge"]))
self.assertEqual(run.stderr.strip().splitlines()[-2:], ["A or B?", "stdin or stdout is not a terminal"])
self.assertEqual(run.stderr.strip().splitlines()[-2:], ["A or B?", "the human is needed to answer the question above, but stdin or stdout is not a terminal"])
self.assertTrue(checkout.archived())
session = argument(run.calls[0], "--session-id")
run = checkout.run(steps, terminal_input="", stdout_on_terminal=False)
self.assertEqual((run.code, run.roles()), (2, ["worker", "judge"]))
self.assertEqual(argument(run.calls[0], "--resume"), session)
self.assertEqual(run.stderr.strip().splitlines()[-1], "stdin or stdout is not a terminal")
self.assertEqual(run.stderr.strip().splitlines()[-1], "the human is needed to answer the question above, but stdin or stdout is not a terminal")
def test_hands_the_terminal_over_and_exits_2_when_nothing_is_typed(self):
checkout = Checkout(self)
@@ -375,7 +392,7 @@ class Interrupt(unittest.TestCase):
checkout.claude_json().write_text(json.dumps({"other": 1, "projects": {str(checkout.root): {"kept": True}}}))
checkout.claude_json().chmod(0o644)
asked = [worker(say="Shall I use A or B?"), judge(interrupt=True, evidence="Shall I use A or B?", question="A or B?")]
run = checkout.run([*asked, interrupt(type="B"), judge(), worker()], terminal_input="")
run = checkout.run([*asked, interrupt(type="B"), judge(evidence="B"), worker()], terminal_input="")
self.assertEqual(run.code, 130)
self.assertEqual(run.roles(), ["worker", "judge", "interrupt", "judge", "worker", "judge"])
handed = run.calls[2]["argv"]
@@ -393,7 +410,11 @@ class Interrupt(unittest.TestCase):
transcript.unlink()
run = checkout.run([*asked, interrupt()], terminal_input="")
self.assertEqual((run.code, run.roles()), (2, ["worker", "judge", "interrupt"]))
self.assertEqual(run.stderr.strip().splitlines()[-1], "the interrupt ended without the human typing anything")
self.assertEqual(run.stderr.strip().splitlines()[-1], "the human is needed to answer the question above, but the interrupt ended without you typing anything")
run = checkout.run([worker(say="A or B?"), judge(interrupt=True, evidence="A or B?", question="A or B?", vanish=True)], terminal_input="")
self.assertEqual((run.code, run.roles()), (1, ["worker", "judge"]))
self.assertEqual(run.stderr.strip().splitlines()[-1], "could not start claude: No such file or directory")
@unittest.skipIf(os.geteuid() == 0, "root reads an unreadable file")
def test_exits_1_when_the_transcript_cannot_be_read_after_the_interrupt(self):
@@ -416,7 +437,11 @@ class Models(unittest.TestCase):
self.catalog(checkout)
run = checkout.run([worker()])
self.assertEqual((run.code, run.calls), (2, []))
self.assertIn(f"proj has no model in {checkout.models_file()}", run.stderr)
self.assertEqual(run.stderr.strip(), f'the human is needed to pick proj\'s model, or merge {{"proj": "<model>"}} into {checkout.models_file()}, but stdin or stdout is not a terminal')
run = checkout.run([worker()], terminal_input="\x04")
self.assertEqual((run.code, run.calls), (2, []))
self.assertEqual(run.stderr.strip().splitlines()[-1], "the human is needed to pick proj's model, but the input ended")
run = checkout.run([worker(), judge()], terminal_input="9\n2\n")
self.assertEqual(run.code, 130)