Answer stability round 1: 1 🔴, 6 🟡 (2 misread); read the scoring rule from the clone, hand windows XDG_DATA_HOME, retry the home check where nobody watches, tell an unreadable sign-in status and settings file apart, and bound the claude commands that build the home
CI / tests (pull_request) Successful in 4m35s

This commit is contained in:
2026-12-04 02:45:02 +01:00
parent 71865e0479
commit 3519922f01
19 changed files with 153 additions and 69 deletions
+26 -12
View File
@@ -15,7 +15,7 @@ from text_files.file_writes import replace_file
# What the home links to in the clone: the instruction files Claude Code reads from its home.
LINKED = ("CLAUDE.md", "agents", "rules", "skills")
# In a value of the clone's settings.json, the clone's folder. Every value that holds it is a shell command, such as a hook's.
# Stands for the clone's folder in the clone's settings.json. Every value that holds it is a shell command, such as a hook's.
CLONE = "{clone}"
# The file in the home that names the clone and the commit the home was built from.
BUILT_FROM = "built-from"
@@ -34,22 +34,31 @@ def unready(home: pathlib.Path, clone: pathlib.Path, claude: Claude, git: Git) -
built = refreshed(home, clone, claude, git)
if isinstance(built, Failure):
return f"could not build the loop's Claude home, {home}: {built.reason}"
status = claude(["auth", "status"]).stdout
except OSError as failure:
status = claude(["auth", "status"])
except (OSError, subprocess.TimeoutExpired) as failure:
return f"could not build the loop's Claude home, {home}: {failure}"
if signed_in(status):
signed = signed_in(status.stdout)
if signed is None:
return f"could not ask claude who is signed in to the loop's Claude home, {home}: {printed(status)}"
if signed:
return None
# /login is typed in a claude that runs in the home: lilleman chose it over a token file on 2026-12-03.
# /login is typed in a claude that runs in the home: docs/decisions.md → `Claude Code in a home of its own`.
return f"nobody is signed in to the loop's Claude home; run `CLAUDE_CONFIG_DIR={shlex.quote(str(home))} claude` and type /login there, once"
def signed_in(status: str) -> bool:
"""Whether `claude auth status` printed that someone is signed in, by a /login or by a token in the environment."""
def signed_in(status: str) -> bool | None:
"""Whether `claude auth status` printed that someone is signed in, by a /login or by a token in the environment; None where it printed no such answer."""
try:
read = json.loads(status)
except ValueError:
return False
return isinstance(read, dict) and read.get("loggedIn") is True
return None
logged_in = read.get("loggedIn") if isinstance(read, dict) else None
return logged_in if isinstance(logged_in, bool) else None
def printed(done: subprocess.CompletedProcess[str]) -> str:
"""What a claude command printed, on stderr, else on stdout, on one line."""
return " ".join((done.stderr or done.stdout).split()) or f"it printed nothing and exited {done.returncode}"
def refreshed(home: pathlib.Path, clone: pathlib.Path, claude: Claude, git: Git) -> Failure | None:
@@ -82,8 +91,14 @@ def settings_written(home: pathlib.Path, clone: pathlib.Path) -> Failure | None:
"""Writes the home's settings.json: the clone's, with the clone's folder in place of CLONE, and the model the home's file holds."""
settings = placed(json.loads((clone / "settings.json").read_text(encoding="utf-8")), shlex.quote(str(clone)))
generated = home / "settings.json"
try:
old = json.loads(generated.read_text(encoding="utf-8")) if generated.is_file() else {}
except ValueError as failure:
return Failure(f"{generated} is not a JSON object: {failure}; delete it and run again")
if not isinstance(old, dict):
return Failure(f"{generated} is not a JSON object; delete it and run again")
# Claude Code writes a /model pick into the home's file, so a refresh keeps it.
if generated.is_file() and "model" in (old := json.loads(generated.read_text(encoding="utf-8"))):
if "model" in old:
settings["model"] = old["model"]
return replace_file(generated, (json.dumps(settings, indent=2, sort_keys=True) + "\n").encode())
@@ -107,6 +122,5 @@ def plugins_installed(clone: pathlib.Path, claude: Claude) -> Failure | None:
for command in commands + [["plugin", "install", plugin] for plugin in plugins]:
done = claude(command)
if done.returncode:
said = " ".join((done.stderr or done.stdout).split())
return Failure(f"claude {' '.join(command)} failed: {said}")
return Failure(f"claude {' '.join(command)} failed: {printed(done)}")
return None
+27 -3
View File
@@ -127,10 +127,26 @@ class Home(unittest.TestCase):
self.assertEqual(self.unready(), f"nobody is signed in to the loop's Claude home; run `CLAUDE_CONFIG_DIR={self.home} claude` and type /login there, once")
def test_a_status_that_is_no_json_reads_as_signed_out(self) -> None:
self.status = "Not logged in"
def test_a_status_that_says_nobody_is_signed_in_or_out_quotes_what_claude_said(self) -> None:
for stdout, stderr, said in (("", "Error: the settings\nare broken\n", "Error: the settings are broken"), ("Not logged in\n", "", "Not logged in"), ('{"authMethod": "none"}', "", '{"authMethod": "none"}'), ("", "", "it printed nothing and exited 1")):
with self.subTest(said=said):
def claude(args: list[str]) -> subprocess.CompletedProcess[str]:
return subprocess.CompletedProcess(args, 1, stdout, stderr) if args == ["auth", "status"] else subprocess.CompletedProcess(args, 0, "", "")
self.assertIn("nobody is signed in", self.unready() or "")
reason = unready(self.home, self.clone, claude, lambda *args, cwd=None: "1a2b3c\n")
self.assertEqual(reason, f"could not ask claude who is signed in to the loop's Claude home, {self.home}: {said}")
def test_a_home_settings_file_that_is_no_json_object_stops_naming_the_file(self) -> None:
for written in ('{"model": "o', "3"):
with self.subTest(written=written):
self.home.mkdir(parents=True, exist_ok=True)
(self.home / "settings.json").write_text(written, encoding="utf-8")
reason = self.unready() or ""
self.assertTrue(reason.startswith(f"could not build the loop's Claude home, {self.home}: {self.home / 'settings.json'} is not a JSON object"), reason)
self.assertTrue(reason.endswith("; delete it and run again"), reason)
def test_a_plugin_that_does_not_install_stops_and_the_next_run_tries_again(self) -> None:
self.exits = {"lsp@other": 1}
@@ -162,6 +178,14 @@ class Home(unittest.TestCase):
self.assertEqual(reason, f"could not build the loop's Claude home, {self.home}: [Errno 2] No such file or directory: 'claude'")
def test_a_claude_that_is_stopped_after_its_time_stops(self) -> None:
def stalled(args: list[str]) -> subprocess.CompletedProcess[str]:
raise subprocess.TimeoutExpired(["claude", *args], 600)
reason = unready(self.home, self.clone, stalled, lambda *args, cwd=None: "1a2b3c\n")
self.assertEqual(reason, f"could not build the loop's Claude home, {self.home}: Command '['claude', 'plugin', 'marketplace', 'add', 'anthropics/official']' timed out after 600 seconds")
if __name__ == "__main__":
unittest.main()