Carry the reload state as one JSON argument and exit naming a reload without a task
This commit is contained in:
+13
-4
@@ -337,7 +337,7 @@ class RunCycle(unittest.TestCase):
|
||||
|
||||
|
||||
class Reload(unittest.TestCase):
|
||||
def test_runs_the_edited_file_before_trusting_it_and_hands_it_the_root_and_counters_on_argv(self):
|
||||
def test_runs_the_edited_file_before_trusting_it_and_hands_it_the_state_as_one_json_argument(self):
|
||||
with tempfile.TemporaryDirectory() as root:
|
||||
script = os.path.join(root, "loop-claude")
|
||||
open(script, "w").write(loop.RELOAD_BASELINE.replace("import glob\n", "import glob\nimport no_such_module\n"))
|
||||
@@ -348,16 +348,25 @@ class Reload(unittest.TestCase):
|
||||
environment = dict(os.environ)
|
||||
with unittest.mock.patch.object(loop, "__file__", script), unittest.mock.patch("os.execv") as execv:
|
||||
loop.reload_if_edited("/r", "do it", cycle_number=1, failures=2)
|
||||
execv.assert_called_once_with(sys.executable, [sys.executable, script, loop.RELOAD_FLAG, "1", "2", "/r", "do it"])
|
||||
execv.assert_called_once_with(sys.executable, [sys.executable, script, loop.RELOAD_FLAG, STATE])
|
||||
self.assertEqual(dict(os.environ), environment)
|
||||
|
||||
|
||||
STATE = json.dumps({"cycle_number": 1, "failures": 2, "root": "/r", "task": "do it"})
|
||||
|
||||
|
||||
class Main(unittest.TestCase):
|
||||
def test_exits_naming_the_reload_when_it_hands_over_anything_but_the_state_with_a_task(self):
|
||||
for handed in (["3", "2", "/r", "do it"], ["3"], ["[1]"], [json.dumps({"cycle_number": 3, "failures": 0, "root": "/r"})], [json.dumps({"cycle_number": 3, "failures": 0, "root": "/r", "task": ""})]):
|
||||
with self.subTest(handed=handed), unittest.mock.patch.object(sys, "argv", ["loop-claude", loop.RELOAD_FLAG, *handed]), self.assertRaises(SystemExit) as stopped:
|
||||
loop.main()
|
||||
self.assertEqual(stopped.exception.code, f"the reload handed {handed}, not the loop's state with a task; rerun loop-claude <task>")
|
||||
|
||||
def test_resumes_the_root_and_counters_a_reload_handed_over(self):
|
||||
patches = [unittest.mock.patch.object(loop, name) for name in ("checkout_root", "read_premises", "reload_if_edited", "run_cycle")]
|
||||
with contextlib.ExitStack() as stack:
|
||||
mocks = [stack.enter_context(patch) for patch in patches]
|
||||
stack.enter_context(unittest.mock.patch.object(sys, "argv", ["loop-claude", loop.RELOAD_FLAG, "3", "2", "/r", "do it"]))
|
||||
stack.enter_context(unittest.mock.patch.object(sys, "argv", ["loop-claude", loop.RELOAD_FLAG, json.dumps({"cycle_number": 3, "failures": 2, "root": "/r", "task": "do it"})]))
|
||||
stack.enter_context(unittest.mock.patch.object(sys, "stdout", io.StringIO()))
|
||||
mocks[3].side_effect = SystemExit(0)
|
||||
with self.assertRaises(SystemExit):
|
||||
@@ -374,7 +383,7 @@ class Main(unittest.TestCase):
|
||||
mocks[1].assert_called_with("/s")
|
||||
self.assertIn("=== cycle 4 ===", sys.stdout.getvalue())
|
||||
mocks[3].side_effect = ["claude exited 3"] * 3
|
||||
stack.enter_context(unittest.mock.patch.object(sys, "argv", ["loop-claude", loop.RELOAD_FLAG, "3", "0", "/r", "do it"]))
|
||||
stack.enter_context(unittest.mock.patch.object(sys, "argv", ["loop-claude", loop.RELOAD_FLAG, json.dumps({"cycle_number": 3, "failures": 0, "root": "/r", "task": "do it"})]))
|
||||
stack.enter_context(unittest.mock.patch.object(sys, "stderr", io.StringIO()))
|
||||
sleep = stack.enter_context(unittest.mock.patch("time.sleep"))
|
||||
with self.assertRaises(SystemExit) as stopped:
|
||||
|
||||
Reference in New Issue
Block a user