Drive the retry line in the main test from zero failures

This commit is contained in:
2026-09-25 18:00:51 +02:00
parent 5d9cb80912
commit 5d59d54b51
+8 -4
View File
@@ -277,14 +277,14 @@ else:
class RunWorker(unittest.TestCase):
def test_says_whether_a_non_zero_exit_or_a_missing_result_event_failed_it(self):
with tempfile.TemporaryDirectory() as home:
stub = os.path.join(home, "claude")
with tempfile.TemporaryDirectory() as bin:
stub = os.path.join(bin, "claude")
scripts = {
"": 'print(json.dumps({"type": "result"}))',
"claude exited 0 without a result event": 'print(json.dumps({"type": "assistant", "message": {"content": [{"type": "text", "text": "worked"}]}}))',
"claude exited 3": "sys.exit(3)",
}
with unittest.mock.patch.dict(os.environ, {"PATH": f"{home}:{os.environ['PATH']}"}), unittest.mock.patch.object(sys, "stdout", io.StringIO()):
with unittest.mock.patch.dict(os.environ, {"PATH": f"{bin}:{os.environ['PATH']}"}), unittest.mock.patch.object(sys, "stdout", io.StringIO()):
for failure, script in scripts.items():
open(stub, "w").write(f"#!/usr/bin/env python3\nimport json\nimport sys\n{script}\n")
os.chmod(stub, 0o700)
@@ -355,9 +355,13 @@ class Main(unittest.TestCase):
mocks[2].assert_called_once_with("do it", 3, 2)
self.assertIn("=== cycle 4 ===", sys.stdout.getvalue())
mocks[3].side_effect = ["claude exited 3"] * 3
stack.enter_context(unittest.mock.patch("time.sleep"))
stack.enter_context(unittest.mock.patch.object(sys, "argv", ["loop-claude", loop.RELOAD_FLAG, "3", "0", "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:
loop.main()
self.assertIn("the worker failed: claude exited 3 - retrying in a minute", sys.stderr.getvalue())
self.assertEqual(sleep.call_count, 2)
self.assertEqual(stopped.exception.code, "the worker failed three times running: claude exited 3")