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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user