Answer the stability and product passes: print each records answer, name its question, drop a misquote to an interrupt, budget the whole prompt
This commit is contained in:
+21
-18
@@ -130,12 +130,12 @@ class Transitions(unittest.TestCase):
|
||||
answered = states.Ruled(AnsweredFromRecords("e", "Which one?", "A."))
|
||||
legal = (
|
||||
(states.Working(), states.WorkerRan("/t"), states.Judging("/t")),
|
||||
(states.Working("A.", 3), states.WorkerRan("/t"), states.Judging("/t", 3)),
|
||||
(states.Working(AnsweredFromRecords("e", "Which one?", "A."), 3), states.WorkerRan("/t"), states.Judging("/t", 3)),
|
||||
(states.Judging("/t"), states.Ruled(Interrupt("e", "Which one?")), states.Interrupting("/t", "Which one?")),
|
||||
(states.Judging("/t", 3), states.Ruled(Interrupt("e", "Which one?")), states.Interrupting("/t", "Which one?", 3)),
|
||||
(states.Judging("/t"), answered, states.Working("A.", 1)),
|
||||
(states.Judging("/t", 2), answered, states.Working("A.", 3)),
|
||||
(states.Judging("/t", 3), answered, states.Interrupting("/t", "Which one?\n\nREADME.md or the project's records say:\nA.", 3)),
|
||||
(states.Judging("/t"), answered, states.Working(AnsweredFromRecords("e", "Which one?", "A."), 1)),
|
||||
(states.Judging("/t", 2), answered, states.Working(AnsweredFromRecords("e", "Which one?", "A."), 3)),
|
||||
(states.Judging("/t", 3), answered, states.Interrupting("/t", "Which one?\n\nREADME.md or the project's records say:\nA.\n\nThe records answered 3 questions this cycle, so this one comes to you.", 3)),
|
||||
(states.Judging("/t"), states.Ruled(Finished("e")), states.Closing("/t", Finished("e"))),
|
||||
(states.Judging("/t", 3), states.Ruled(Finished("e")), states.Closing("/t", Finished("e"))),
|
||||
(states.Judging("/t"), states.Ruled(Unfinished("e")), states.Closing("/t", Unfinished("e"))),
|
||||
@@ -147,7 +147,7 @@ class Transitions(unittest.TestCase):
|
||||
for state, event, after in legal:
|
||||
with self.subTest(state=state, event=event):
|
||||
self.assertEqual(states.transition(state, event), after)
|
||||
every_state = (states.Working(), states.Working("A.", 3), states.Judging("/t"), states.Judging("/t", 3), states.Interrupting("/t", "q"), states.Interrupting("/t", "q", 3), states.Closing("/t", Finished("e")), states.Ended())
|
||||
every_state = (states.Working(), states.Working(AnsweredFromRecords("e", "Which one?", "A."), 3), states.Judging("/t"), states.Judging("/t", 3), states.Interrupting("/t", "q"), states.Interrupting("/t", "q", 3), states.Closing("/t", Finished("e")), states.Ended())
|
||||
every_event = (states.WorkerRan("/t"), states.Ruled(Interrupt("e", "Which one?")), answered, states.Ruled(Finished("e")), states.Ruled(Unfinished("e")), states.HumanAnswered(), states.Archived())
|
||||
for state in every_state:
|
||||
for event in every_event:
|
||||
@@ -247,18 +247,21 @@ class Cycles(unittest.TestCase):
|
||||
def test_a_question_the_records_answer_resumes_the_worker_with_the_answer_three_times_a_cycle(self):
|
||||
answered = judged("interrupt", answer="Use *A*.")
|
||||
fake = FakeEffects(streams=[Worker(self.paths.claude_code_transcripts.parent)] * 4, claude=[answered] * 4, on_terminal_claude=[0], git=[ran()])
|
||||
with contextlib.redirect_stderr(io.StringIO()) as said:
|
||||
with contextlib.redirect_stderr(io.StringIO()) as said, contextlib.redirect_stdout(io.StringIO()) as printed:
|
||||
self.assertEqual(run.run_cycle(self.cycle(fake, records="From AGENTS.md:\nUse A.")), Stop(2, "the human is needed to answer the question above, but the interrupt ended with nothing typed"))
|
||||
resumed = fake.made("stream_claude")[1]
|
||||
self.assertEqual(resumed[resumed.index("-p") + 1], "README.md or the project's records answer your question:\n\nUse *A*.\n\nContinue the task.")
|
||||
self.assertEqual(resumed[resumed.index("-p") + 1], "Your question: Which one?\n\nREADME.md or the project's records answer it:\n\nUse *A*.\n\nContinue the task.")
|
||||
self.assertEqual(len(fake.made("stream_claude")), 4)
|
||||
self.assertIn("Which one?\n\nREADME.md or the project's records say:\nUse *A*.", said.getvalue())
|
||||
self.assertEqual(printed.getvalue().count("=== the records answered: Which one? ===\nUse *A*."), 3)
|
||||
self.assertIn("Which one?\n\nREADME.md or the project's records say:\nUse *A*.\n\nThe records answered 3 questions this cycle", said.getvalue())
|
||||
|
||||
def test_the_judge_fails_on_an_answer_the_records_do_not_hold(self):
|
||||
invented = judged("interrupt", answer="Use B.")
|
||||
fake = FakeEffects(streams=[Worker(self.paths.claude_code_transcripts.parent)], claude=[invented] * 3)
|
||||
with contextlib.redirect_stderr(io.StringIO()):
|
||||
self.assertEqual(run.run_cycle(self.cycle(fake, records="From AGENTS.md:\nUse A.")), Stop(1, "the judge failed three times running: the judge answered 'Which one?' with 'Use B.', which README.md and the project's records do not hold"))
|
||||
def test_an_answer_the_records_do_not_hold_is_dropped_and_the_question_goes_to_the_human(self):
|
||||
fake = FakeEffects(streams=[Worker(self.paths.claude_code_transcripts.parent)], claude=[judged("interrupt", answer="Use B.")], on_terminal_claude=[0], git=[ran()])
|
||||
with contextlib.redirect_stderr(io.StringIO()) as said:
|
||||
self.assertEqual(run.run_cycle(self.cycle(fake, records="From AGENTS.md:\nUse A.")), Stop(2, "the human is needed to answer the question above, but the interrupt ended with nothing typed"))
|
||||
self.assertEqual(len(fake.made("stream_claude")), 1)
|
||||
self.assertIn("\nWhich one?\n", said.getvalue())
|
||||
self.assertNotIn("Use B.", said.getvalue())
|
||||
|
||||
@unittest.skipIf(os.geteuid() == 0, "root writes into a read-only directory")
|
||||
def test_stops_keeping_the_transcript_when_the_finished_chunks_session_cannot_be_deleted(self):
|
||||
@@ -388,7 +391,7 @@ class Records(unittest.TestCase):
|
||||
pathlib.Path(root, "docs", "decisions.md").mkdir(parents=True)
|
||||
self.assertEqual(records.read_records(root), Stop(1, f"docs/decisions.md in {root}: Is a directory - the judge cannot read the project's records."))
|
||||
pathlib.Path(root, "AGENTS.md").write_bytes(b"# Rules\n\xff\n")
|
||||
self.assertEqual(records.read_records(root), Stop(1, "AGENTS.md is not UTF-8 on line 2 - the judge cannot read the project's records."))
|
||||
self.assertEqual(records.read_records(root), Stop(1, f"AGENTS.md in {root} is not UTF-8 on line 2 - the judge cannot read the project's records."))
|
||||
|
||||
|
||||
class Sections(unittest.TestCase):
|
||||
@@ -500,7 +503,7 @@ class Verdict(unittest.TestCase):
|
||||
self.assertEqual(judge.verdict_from({"answer": "", "interrupt": False, "evidence": "e", "finished": False, "question": "ignored"}), Unfinished("e"))
|
||||
self.assertEqual(judge.verdict_from({"answer": "", "interrupt": True, "evidence": "e", "finished": True, "question": "Which one?"}), Interrupt("e", "Which one?"))
|
||||
self.assertEqual(judge.verdict_from({"answer": "A.", "interrupt": True, "evidence": "e", "finished": False, "question": "Which one?"}), AnsweredFromRecords("e", "Which one?", "A."))
|
||||
self.assertEqual(judge.verdict_from({"answer": "A.", "interrupt": False, "evidence": "e", "finished": False, "question": ""}), Failure("the judge answered without interrupting"))
|
||||
self.assertEqual(judge.verdict_from({"answer": "ignored", "interrupt": False, "evidence": "e", "finished": False, "question": ""}), Unfinished("e"))
|
||||
self.assertEqual(judge.verdict_from({"answer": "", "interrupt": "no", "evidence": "", "finished": True, "question": ""}), Failure("the judge's reply has no interrupt of type boolean"))
|
||||
self.assertEqual(judge.verdict_from({"answer": "", "interrupt": False, "evidence": None, "finished": True, "question": ""}), Failure("the judge's reply has no evidence of type string"))
|
||||
self.assertEqual(judge.verdict_from({"answer": "", "interrupt": True, "evidence": "x", "finished": False, "question": " "}), Failure("the judge interrupted without a question"))
|
||||
@@ -531,8 +534,8 @@ class LoopRuns(unittest.TestCase):
|
||||
|
||||
class HelpLimits(unittest.TestCase):
|
||||
def test_help_states_the_limits_the_code_holds(self):
|
||||
self.assertIn(f"last {judge.JUDGED_TRANSCRIPT_TAIL:,} characters", main.__doc__)
|
||||
self.assertIn(f"up to {['one', 'two', 'three', 'four'][states.RECORDS_ANSWERS_PER_CYCLE - 1]}\ntimes a cycle", main.__doc__)
|
||||
self.assertIn(f"a {judge.JUDGE_PROMPT_CHARS:,}-character prompt", main.__doc__)
|
||||
self.assertIn(f"up to {['one', 'two', 'three', 'four'][states.RECORDS_ANSWERS_PER_CYCLE - 1]} times a cycle", main.__doc__)
|
||||
|
||||
|
||||
class ExitContract(unittest.TestCase):
|
||||
@@ -558,7 +561,7 @@ class ExitContract(unittest.TestCase):
|
||||
("project/checkout.py", "checkout_root", "1", "f'could not start git:", git),
|
||||
("project/checkout.py", "checkout_root", "1", "found.stderr.strip()", git),
|
||||
("project/checkout.py", "read_checkout_file", "1", "f'{name} in {root}:", unreadable),
|
||||
("project/checkout.py", "read_checkout_file", "1", "f'{name} is not UTF-8", unreadable),
|
||||
("project/checkout.py", "read_checkout_file", "1", "f'{name} in {root} is not UTF-8", unreadable),
|
||||
("project/model_choice.py", "get_or_ask_model", "1", "f'could not save the model in", models_),
|
||||
("project/model_choice.py", "read_models_file", "1", 'f"could not read {saved}: {getattr(', models_),
|
||||
("project/model_choice.py", "read_models_file", "1", "f'could not read {saved}: not an object", models_),
|
||||
|
||||
Reference in New Issue
Block a user