From 5d59d54b518f3ba5118f8d233b3ffa3476736b7a Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 25 Sep 2026 18:00:51 +0200 Subject: [PATCH] Drive the retry line in the main test from zero failures --- bin/test_loop_claude.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/bin/test_loop_claude.py b/bin/test_loop_claude.py index 2a36670e..fa7cc65e 100644 --- a/bin/test_loop_claude.py +++ b/bin/test_loop_claude.py @@ -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")