diff --git a/bin/loop_claude/main.py b/bin/loop_claude/main.py index 2488ecbf..6cb7cd92 100644 --- a/bin/loop_claude/main.py +++ b/bin/loop_claude/main.py @@ -27,7 +27,7 @@ and read each cycle; a project without an entry, as on its first run, is asked f LOOP_CLAUDE_JUDGE_MODEL overrides it for the judge, LOOP_CLAUDE_WORKER_MODEL for the worker and the interrupt; with both set, nothing is asked. -A change to loop-claude's files takes effect at the next cycle boundary, once they answer --help. +A change to loop-claude's files takes effect at the next cycle boundary, once the launcher answers --help. Claude Code internals this rests on, observed on 2.1.282, the model catalog on 2.1.283: - The transcript is ~/.claude/projects/*/.jsonl, one JSON object per line. A / diff --git a/bin/test_loop_claude.py b/bin/test_loop_claude.py index 607f7499..456c31ad 100644 --- a/bin/test_loop_claude.py +++ b/bin/test_loop_claude.py @@ -4,6 +4,7 @@ import io import json import os import pathlib +import shutil import stat import subprocess import sys @@ -431,6 +432,24 @@ class RunCycle(unittest.TestCase): self.assertEqual({args[args.index("--model") + 1] for args in map(json.loads, pathlib.Path(calls).read_text().splitlines())}, {"claude-opus-5-5"}) +class Reload(unittest.TestCase): + def test_an_edited_package_file_reloads_once_the_launcher_answers_help(self): + with tempfile.TemporaryDirectory() as root: + copy = pathlib.Path(root, "bin") + shutil.copytree(LAUNCHER.parent, copy, ignore=shutil.ignore_patterns("__pycache__", "test_*")) + launcher, edited = copy / "loop-claude", copy / "loop_claude" / "cycle.py" + state = main.LoopState(1, 2, "/r", "do it") + with unittest.mock.patch.object(main, "__file__", str(copy / "loop_claude" / "main.py")), unittest.mock.patch("os.execv") as execv, contextlib.redirect_stderr(io.StringIO()) as err: + baseline = main.fingerprint(launcher) + edited.write_text(edited.read_text() + "\ndef\n") + main.reload_if_edited(launcher, baseline, state) + execv.assert_not_called() + self.assertIn("keeping the running script", err.getvalue()) + edited.write_text(edited.read_text().replace("\ndef\n", "\n# edited\n")) + main.reload_if_edited(launcher, baseline, state) + execv.assert_called_once_with(sys.executable, [sys.executable, str(launcher), main.RELOAD_FLAG, json.dumps({"cycle_number": 1, "failures": 2, "root": "/r", "task": "do it"})]) + + class Main(unittest.TestCase): def test_returns_the_exit_code_of_the_stop_the_loop_returned(self): for argv, code, stream in ((["--help"], 0, "stdout"), ([], 1, "stderr"), ([main.RELOAD_FLAG, "3"], 1, "stderr")):