Keep the own home's instructions out of the loop's home

This commit is contained in:
2026-12-04 06:49:23 +01:00
parent 59b633b67d
commit 29ce6bb11a
3 changed files with 22 additions and 14 deletions
+11 -5
View File
@@ -33,6 +33,7 @@ class Home(unittest.TestCase):
self.home = self.temp / "share" / "claude-home"
self.commit: str | Failure = "1a2b3c\n"
self.reports = self.temp / "state" / "build-release" / "larv-review"
self.own = self.temp / "home" / ".claude"
self.status = SIGNED_IN
# The exit code of each `claude plugin` command, by its last argument; 0 for one not named.
self.exits: dict[str, int] = {}
@@ -45,7 +46,7 @@ class Home(unittest.TestCase):
return subprocess.CompletedProcess(args, self.exits.get(args[-1], 0), "", f"no {args[-1]}\nin the marketplace\n")
def unready(self) -> str | None:
return unready(self.home, self.clone, self.reports, self.claude, lambda *args, cwd=None: self.commit if (args, cwd) == (("rev-parse", "HEAD"), str(self.clone)) else Failure(f"unexpected git {args} in {cwd}"))
return unready(self.home, self.clone, self.reports, self.own, self.claude, lambda *args, cwd=None: self.commit if (args, cwd) == (("rev-parse", "HEAD"), str(self.clone)) else Failure(f"unexpected git {args} in {cwd}"))
def settings(self) -> dict[str, object]:
read: dict[str, object] = json.loads((self.home / "settings.json").read_text(encoding="utf-8"))
@@ -71,6 +72,11 @@ class Home(unittest.TestCase):
self.assertEqual(self.settings()["permissions"], {"additionalDirectories": [str(self.reports), "~/code"], "defaultMode": "bypassPermissions"})
def test_the_generated_settings_keep_out_the_instructions_of_the_persons_own_home(self) -> None:
self.unready()
self.assertEqual(self.settings()["claudeMdExcludes"], [f"{self.own}/**"])
def test_a_moved_reports_folder_refreshes_the_home(self) -> None:
self.unready()
self.reports = self.temp / "elsewhere" / "build-release" / "larv-review"
@@ -102,7 +108,7 @@ class Home(unittest.TestCase):
self.unready()
self.assertEqual((self.home / "settings.json").read_text(encoding="utf-8"), '{\n "env": {\n "A": "1"\n },\n "tui": "fullscreen"\n}\n')
self.assertEqual((self.home / "settings.json").read_text(encoding="utf-8"), f'{{\n "claudeMdExcludes": [\n "{self.own}/**"\n ],\n "env": {{\n "A": "1"\n }},\n "tui": "fullscreen"\n}}\n')
def test_a_home_built_from_the_clones_commit_is_left_as_it_is(self) -> None:
self.unready()
@@ -149,7 +155,7 @@ class Home(unittest.TestCase):
def claude(args: list[str]) -> subprocess.CompletedProcess[str]:
return subprocess.CompletedProcess(args, 1, stdout, stderr) if args == ["auth", "status"] else subprocess.CompletedProcess(args, 0, "", "")
reason = unready(self.home, self.clone, self.reports, claude, lambda *args, cwd=None: "1a2b3c\n")
reason = unready(self.home, self.clone, self.reports, self.own, 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}")
@@ -190,7 +196,7 @@ class Home(unittest.TestCase):
def missing(args: list[str]) -> subprocess.CompletedProcess[str]:
raise FileNotFoundError(2, "No such file or directory", "claude")
reason = unready(self.home, self.clone, self.reports, missing, lambda *args, cwd=None: "1a2b3c\n")
reason = unready(self.home, self.clone, self.reports, self.own, missing, lambda *args, cwd=None: "1a2b3c\n")
self.assertEqual(reason, f"could not build the loop's Claude home, {self.home}: [Errno 2] No such file or directory: 'claude'")
self.assertFalse(only_signed_out(reason))
@@ -199,7 +205,7 @@ class Home(unittest.TestCase):
def stalled(args: list[str]) -> subprocess.CompletedProcess[str]:
raise subprocess.TimeoutExpired(["claude", *args], 600)
reason = unready(self.home, self.clone, self.reports, stalled, lambda *args, cwd=None: "1a2b3c\n")
reason = unready(self.home, self.clone, self.reports, self.own, 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")