Pin that an edit in a folder under loop_claude reloads the loop
This commit is contained in:
@@ -67,11 +67,13 @@ if role == "worker":
|
|||||||
(transcript().parent / sibling).mkdir(parents=True, exist_ok=True)
|
(transcript().parent / sibling).mkdir(parents=True, exist_ok=True)
|
||||||
(transcript().parent / f"{{session()}}.orphaned-1-ab.jsonl").write_text("{{}}\\n")
|
(transcript().parent / f"{{session()}}.orphaned-1-ab.jsonl").write_text("{{}}\\n")
|
||||||
if "append" in step:
|
if "append" in step:
|
||||||
with open(os.environ["FAKE_CLAUDE_EDIT"], "a") as script:
|
edited = pathlib.Path(os.environ["FAKE_CLAUDE_EDIT"], step["append"][0])
|
||||||
script.write(step["append"])
|
edited.parent.mkdir(parents=True, exist_ok=True)
|
||||||
|
with open(edited, "a") as script:
|
||||||
|
script.write(step["append"][1])
|
||||||
if "replace" in step:
|
if "replace" in step:
|
||||||
script = pathlib.Path(os.environ["FAKE_CLAUDE_EDIT"])
|
script = pathlib.Path(os.environ["FAKE_CLAUDE_EDIT"], step["replace"][0])
|
||||||
script.write_text(script.read_text().replace(*step["replace"]))
|
script.write_text(script.read_text().replace(*step["replace"][1:]))
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
sys.stdout.buffer.write(step.get("stream", "").encode("latin-1"))
|
sys.stdout.buffer.write(step.get("stream", "").encode("latin-1"))
|
||||||
print(json.dumps(said))
|
print(json.dumps(said))
|
||||||
@@ -633,19 +635,19 @@ class Reload(unittest.TestCase):
|
|||||||
copy = checkout.temp / "bin"
|
copy = checkout.temp / "bin"
|
||||||
shutil.copytree(BIN, copy, ignore=shutil.ignore_patterns("__pycache__", "test_*"))
|
shutil.copytree(BIN, copy, ignore=shutil.ignore_patterns("__pycache__", "test_*"))
|
||||||
checkout.script = copy / "loop-claude"
|
checkout.script = copy / "loop-claude"
|
||||||
checkout.env["FAKE_CLAUDE_EDIT"] = str(checkout.script)
|
checkout.env["FAKE_CLAUDE_EDIT"] = str(copy)
|
||||||
run = checkout.run([
|
run = checkout.run([
|
||||||
worker(append="\ndef\n"), judge(),
|
worker(append=["loop-claude", "\ndef\n"]), judge(),
|
||||||
worker(replace=["\ndef\n", "\n# edited\n"]), judge(),
|
worker(replace=["loop-claude", "\ndef\n", "\n# edited\n"]), judge(),
|
||||||
|
worker(append=["loop_claude/nested/edited.py", "# edited\n"]), judge(),
|
||||||
worker(),
|
worker(),
|
||||||
])
|
])
|
||||||
self.assertEqual(run.code, 130)
|
self.assertEqual(run.code, 130)
|
||||||
self.assertEqual(run.roles(), ["worker", "judge"] * 3)
|
self.assertEqual(run.roles(), ["worker", "judge"] * 4)
|
||||||
self.assertIn("keeping the running script", run.stderr)
|
self.assertIn("keeping the running script", run.stderr)
|
||||||
reloads = [argv for argv in run.starts if argv[:1] == ["--reloaded"]]
|
reloads = [json.loads(argv[1]) for argv in run.starts if argv[:1] == ["--reloaded"]]
|
||||||
self.assertEqual(len(reloads), 1)
|
self.assertEqual(reloads, [{"cycle_number": cycle, "failures": 0, "root": str(checkout.root), "task": TASK} for cycle in (2, 3)])
|
||||||
self.assertEqual(json.loads(reloads[0][1]), {"cycle_number": 2, "failures": 0, "root": str(checkout.root), "task": TASK})
|
self.assertIn("=== cycle 4 ===", run.stdout)
|
||||||
self.assertIn("=== cycle 3 ===", run.stdout)
|
|
||||||
|
|
||||||
outside = checkout.temp / "outside"
|
outside = checkout.temp / "outside"
|
||||||
outside.mkdir()
|
outside.mkdir()
|
||||||
|
|||||||
Reference in New Issue
Block a user