Run every claude the loop starts in a Claude home generated outside the clone
CI / tests (pull_request) Successful in 4m45s
CI / tests (pull_request) Successful in 4m45s
This commit is contained in:
@@ -54,6 +54,14 @@ FAKE_CLAUDE = """#!{python}
|
||||
import json, os, pathlib, signal, sys, time
|
||||
|
||||
argv = sys.argv[1:]
|
||||
# What claude_home.home asks while it builds the loop's Claude home: someone is signed in, and each plugin installs.
|
||||
if argv[:1] == ["plugin"]:
|
||||
sys.exit(0)
|
||||
if argv == ["auth", "status"]:
|
||||
print(json.dumps({{"loggedIn": os.environ.get("FAKE_CLAUDE_SIGNED_OUT") is None}}))
|
||||
if os.environ.get("FAKE_CLAUDE_VANISHES"):
|
||||
os.unlink(sys.argv[0])
|
||||
sys.exit(0)
|
||||
role = "judge" if "--json-schema" in argv else "worker" if "-p" in argv else "interrupt"
|
||||
scenario = pathlib.Path(os.environ["FAKE_CLAUDE_SCENARIO"])
|
||||
steps = json.loads(scenario.read_text())
|
||||
@@ -78,7 +86,7 @@ def session():
|
||||
|
||||
|
||||
def transcript():
|
||||
return pathlib.Path.home() / ".claude" / "projects" / "-fake" / f"{{session()}}.jsonl"
|
||||
return pathlib.Path(os.environ["CLAUDE_CONFIG_DIR"]) / "projects" / "-fake" / f"{{session()}}.jsonl"
|
||||
|
||||
|
||||
def append(*entries):
|
||||
@@ -328,7 +336,7 @@ class Checkout:
|
||||
return self.home / ".config/build-release" / "models.json"
|
||||
|
||||
def transcripts(self):
|
||||
return sorted((self.home / ".claude" / "projects").glob("*/*.jsonl"))
|
||||
return sorted((self.home / ".local/share/build-release/claude-home" / "projects").glob("*/*.jsonl"))
|
||||
|
||||
def archive(self):
|
||||
return pathlib.Path(self.env.get("BUILD_RELEASE_TRANSCRIPTS", self.home / ".local/state/build-release" / "transcripts"))
|
||||
@@ -442,8 +450,6 @@ class Cycles(unittest.TestCase):
|
||||
(checkout.root / "sub").mkdir()
|
||||
(checkout.root / "docs").mkdir()
|
||||
(checkout.root / "docs" / "decisions.md").write_text("# Decisions\n")
|
||||
(checkout.home / ".claude").mkdir()
|
||||
(checkout.home / ".claude" / "CLAUDE.md").write_text("# Global instructions\n")
|
||||
run = checkout.run([
|
||||
worker(say="started"), judge(evidence="started"),
|
||||
worker(say="landed-it", siblings=True), judge(finished=True, evidence="landed-it"),
|
||||
@@ -767,7 +773,8 @@ class Cycles(unittest.TestCase):
|
||||
|
||||
def test_retries_a_worker_claude_cannot_start(self):
|
||||
checkout = Checkout(self)
|
||||
(checkout.temp / "fake-bin" / "claude").unlink()
|
||||
# The claude that answers for the loop's Claude home is gone once the worker starts.
|
||||
checkout.env["FAKE_CLAUDE_VANISHES"] = "1"
|
||||
run = checkout.run([])
|
||||
self.assertEqual((run.code, run.calls), (1, []))
|
||||
self.assertEqual(run.sleeps, [60, 60])
|
||||
@@ -907,6 +914,21 @@ class Windows(unittest.TestCase):
|
||||
run = checkout.run([], argv=[TASK])
|
||||
self.assertEqual((run.code, run.stderr), (1, "build-release runs each chunk in a tmux window, and needs tmux 3.2 or later; it found no tmux\n"))
|
||||
|
||||
def test_builds_the_loops_claude_home_from_the_clone_then_refuses_to_start_until_someone_signs_in_there(self):
|
||||
checkout = self.checkout()
|
||||
checkout.env["FAKE_CLAUDE_SIGNED_OUT"] = "1"
|
||||
checkout.env["FAKE_TMUX_VERSION"] = "tmux 3.1c"
|
||||
home = checkout.home / ".local/share/build-release/claude-home"
|
||||
run = checkout.run([], argv=[TASK])
|
||||
self.assertEqual((run.code, run.calls), (1, []))
|
||||
self.assertEqual(run.stderr.splitlines(), [
|
||||
"build-release runs each chunk in a tmux window, and needs tmux 3.2 or later; it found tmux 3.1c",
|
||||
f"nobody is signed in to the loop's Claude home; run `CLAUDE_CONFIG_DIR={home} claude` and type /login there, once",
|
||||
])
|
||||
self.assertEqual((home / "CLAUDE.md").resolve(), BIN.parent / "CLAUDE.md")
|
||||
self.assertIn(f"{BIN}/rule-hook", (home / "settings.json").read_text())
|
||||
self.assertFalse((checkout.home / ".claude").exists())
|
||||
|
||||
def test_marks_the_window_while_an_interrupt_waits_and_rings_its_bell(self):
|
||||
checkout = self.checkout()
|
||||
run = checkout.run([worker(say="A or B?"), judge(interrupt=True, question="A or B?")], chunk="item-4")
|
||||
@@ -1016,7 +1038,7 @@ class Interrupt(unittest.TestCase):
|
||||
|
||||
class Models(unittest.TestCase):
|
||||
def catalog(self, checkout):
|
||||
folder = checkout.home / ".claude" / "cache" / "model-catalog"
|
||||
folder = checkout.home / ".local/share/build-release/claude-home" / "cache" / "model-catalog"
|
||||
folder.mkdir(parents=True)
|
||||
(folder / "old.json").write_text(json.dumps({"catalog": {"config": {"models": [{"id": "old-model"}]}}, "fetchedAt": 1}))
|
||||
(folder / "new.json").write_text(json.dumps({"catalog": {"config": {"models": [{"id": "model-a", "name": "A"}, {"id": "model-b", "name": "B"}]}}, "fetchedAt": 2}))
|
||||
@@ -1079,7 +1101,7 @@ class Models(unittest.TestCase):
|
||||
checkout = Checkout(self)
|
||||
del checkout.env["BUILD_RELEASE_JUDGE_MODEL"], checkout.env["BUILD_RELEASE_WORKER_MODEL"]
|
||||
self.catalog(checkout)
|
||||
catalog = checkout.home / ".claude" / "cache" / "model-catalog" / "new.json"
|
||||
catalog = checkout.home / ".local/share/build-release/claude-home" / "cache" / "model-catalog" / "new.json"
|
||||
for shape in ({"catalog": {"config": {"models": []}}}, {"catalog": None}, {"catalog": {"config": []}}, {"catalog": {"config": {"models": "x"}}}):
|
||||
with self.subTest(shape=shape):
|
||||
catalog.write_text(json.dumps({**shape, "fetchedAt": 3}))
|
||||
@@ -1103,8 +1125,13 @@ class Models(unittest.TestCase):
|
||||
class Reload(unittest.TestCase):
|
||||
def test_an_edit_takes_effect_at_the_next_cycle_boundary_once_it_answers_help(self):
|
||||
checkout = Checkout(self)
|
||||
copy = checkout.temp / "bin"
|
||||
# A clone of its own, since the loop's Claude home is built from the commit and the settings.json of the clone the script ships in.
|
||||
clone = checkout.temp / "clone"
|
||||
copy = clone / "bin"
|
||||
shutil.copytree(BIN, copy, ignore=shutil.ignore_patterns("__pycache__", "test_*"))
|
||||
(clone / "settings.json").write_text("{}\n")
|
||||
for command in (["init", "-q"], ["-c", "user.name=t", "-c", "user.email=t@example.com", "commit", "-q", "--allow-empty", "-m", "A release"]):
|
||||
subprocess.run(["git", *command], check=True, cwd=clone, env=checkout.env)
|
||||
checkout.script = copy / "build-release"
|
||||
checkout.env["FAKE_CLAUDE_EDIT"] = str(copy)
|
||||
run = checkout.run([
|
||||
|
||||
Reference in New Issue
Block a user