Answer the stability review's first round
This commit is contained in:
+18
-9
@@ -45,7 +45,7 @@ class FakeEffects:
|
|||||||
|
|
||||||
def effects(self):
|
def effects(self):
|
||||||
return Effects(
|
return Effects(
|
||||||
claude=lambda args, cwd, stdin: self.answer("claude", args),
|
claude=lambda args, cwd, stdin: self.answer("claude", (args, stdin)),
|
||||||
claude_on_terminal=lambda args, cwd: self.answer("claude_on_terminal", args),
|
claude_on_terminal=lambda args, cwd: self.answer("claude_on_terminal", args),
|
||||||
execv=self.execv,
|
execv=self.execv,
|
||||||
git=lambda args, cwd: self.answer("git", args),
|
git=lambda args, cwd: self.answer("git", args),
|
||||||
@@ -89,8 +89,8 @@ def judged(verdict, evidence="working"):
|
|||||||
class Worker:
|
class Worker:
|
||||||
"""A worker claude: writes a line to the session's transcript, then streams a result."""
|
"""A worker claude: writes a line to the session's transcript, then streams a result."""
|
||||||
|
|
||||||
def __init__(self, home, code=0):
|
def __init__(self, home):
|
||||||
self.home, self.code = home, code
|
self.home = home
|
||||||
|
|
||||||
def __call__(self, args):
|
def __call__(self, args):
|
||||||
flag = "--session-id" if "--session-id" in args else "--resume"
|
flag = "--session-id" if "--session-id" in args else "--resume"
|
||||||
@@ -98,7 +98,7 @@ class Worker:
|
|||||||
path.parent.mkdir(parents=True, exist_ok=True)
|
path.parent.mkdir(parents=True, exist_ok=True)
|
||||||
with open(path, "a") as handle:
|
with open(path, "a") as handle:
|
||||||
handle.write(json.dumps(assistant({"type": "text", "text": "working"})) + "\n")
|
handle.write(json.dumps(assistant({"type": "text", "text": "working"})) + "\n")
|
||||||
return Streamed(self.code)
|
return Streamed(0)
|
||||||
|
|
||||||
|
|
||||||
class Streamed:
|
class Streamed:
|
||||||
@@ -114,18 +114,24 @@ class Streamed:
|
|||||||
|
|
||||||
class Transitions(unittest.TestCase):
|
class Transitions(unittest.TestCase):
|
||||||
def test_each_state_moves_on_its_events_and_only_on_them(self):
|
def test_each_state_moves_on_its_events_and_only_on_them(self):
|
||||||
for state, event, after in (
|
legal = (
|
||||||
(states.Working(), states.WorkerRan("/t"), states.Judging("/t")),
|
(states.Working(), states.WorkerRan("/t"), states.Judging("/t")),
|
||||||
(states.Judging("/t"), states.Ruled(Interrupt("e", "Which one?")), states.Interrupting("/t", "Which one?")),
|
(states.Judging("/t"), states.Ruled(Interrupt("e", "Which one?")), states.Interrupting("/t", "Which one?")),
|
||||||
(states.Judging("/t"), states.Ruled(Finished("e")), states.Finishing("/t")),
|
(states.Judging("/t"), states.Ruled(Finished("e")), states.Finishing("/t")),
|
||||||
(states.Judging("/t"), states.Ruled(Unfinished("e")), states.Ended()),
|
(states.Judging("/t"), states.Ruled(Unfinished("e")), states.Ended()),
|
||||||
(states.Interrupting("/t", "q"), states.Answered(), states.Judging("/t")),
|
(states.Interrupting("/t", "q"), states.Answered(), states.Judging("/t")),
|
||||||
(states.Finishing("/t"), states.Archived(), states.Ended()),
|
(states.Finishing("/t"), states.Archived(), states.Ended()),
|
||||||
):
|
)
|
||||||
|
for state, event, after in legal:
|
||||||
with self.subTest(state=state, event=event):
|
with self.subTest(state=state, event=event):
|
||||||
self.assertEqual(states.transition(state, event), after)
|
self.assertEqual(states.transition(state, event), after)
|
||||||
with self.assertRaises(ValueError):
|
every_state = (states.Working(), states.Judging("/t"), states.Interrupting("/t", "q"), states.Finishing("/t"), states.Ended())
|
||||||
states.transition(states.Working(), states.Answered())
|
every_event = (states.WorkerRan("/t"), states.Ruled(Interrupt("e", "Which one?")), states.Ruled(Finished("e")), states.Ruled(Unfinished("e")), states.Answered(), states.Archived())
|
||||||
|
for state in every_state:
|
||||||
|
for event in every_event:
|
||||||
|
if (state, event) not in [(state, event) for state, event, _ in legal]:
|
||||||
|
with self.subTest(state=state, event=event), self.assertRaises(ValueError):
|
||||||
|
states.transition(state, event)
|
||||||
|
|
||||||
|
|
||||||
class Cycles(unittest.TestCase):
|
class Cycles(unittest.TestCase):
|
||||||
@@ -167,7 +173,10 @@ class Cycles(unittest.TestCase):
|
|||||||
self.assertIsNone(steps.run_cycle(self.cycle(fake)))
|
self.assertIsNone(steps.run_cycle(self.cycle(fake)))
|
||||||
self.assertEqual(self.archived_verdicts(), ["Task: Do it.\n\nVerdict: interrupt\n\nWhich one?\n"])
|
self.assertEqual(self.archived_verdicts(), ["Task: Do it.\n\nVerdict: interrupt\n\nWhich one?\n"])
|
||||||
self.assertIn(str(self.session.id), fake.made("claude_on_terminal")[0])
|
self.assertIn(str(self.session.id), fake.made("claude_on_terminal")[0])
|
||||||
self.assertEqual(len(fake.made("claude")), 2)
|
prompts = [stdin for args, stdin in fake.made("claude")]
|
||||||
|
self.assertEqual(len(prompts), 2)
|
||||||
|
self.assertNotIn("the second", prompts[0])
|
||||||
|
self.assertIn("[human] the second", prompts[1])
|
||||||
|
|
||||||
def test_stops_when_the_worker_leaves_no_transcript(self):
|
def test_stops_when_the_worker_leaves_no_transcript(self):
|
||||||
fake = FakeEffects(streams=[Streamed(0)])
|
fake = FakeEffects(streams=[Streamed(0)])
|
||||||
|
|||||||
Reference in New Issue
Block a user