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