Keep configs in ~/.config/build-release/ and tool state in ~/.local/state/build-release/, under XDG_* where set
CI / tests (pull_request) Successful in 6m34s
CI / tests (pull_request) Successful in 6m34s
This commit is contained in:
@@ -426,7 +426,7 @@ class ReviewerRung(unittest.TestCase):
|
||||
|
||||
def test_a_review_is_refused_where_the_projects_ladder_cannot_be_read_and_build_release_handed_rungs(self):
|
||||
checkout, home = self.project("[]")
|
||||
own = pathlib.Path(home, ".claude-projects", "acme", "routing-ladder.json")
|
||||
own = pathlib.Path(home, ".config/build-release", "acme", "routing-ladder.json")
|
||||
reviewer = Call("Agent", {"subagent_type": "stability-reviewer", "model": "fable", "effort": "max"}, checkout)
|
||||
for breaches in (reviewer_breaches(reviewer, self.ON_TWO_RUNGS, home), skill_breaches(Call("Skill", {"skill": "security-review"}, checkout), self.ON_TWO_RUNGS, home)):
|
||||
self.assertEqual(rules(breaches), ["reviewer-rung"])
|
||||
@@ -491,7 +491,7 @@ class EnvFileRead(unittest.TestCase):
|
||||
(self.home / ".claude").mkdir()
|
||||
(self.home / ".claude" / ".env").write_text("TOKEN=x\n")
|
||||
write_config(self.home, self.home / "code" / "acme")
|
||||
config = self.home / ".claude-projects" / "acme" / "config.toml"
|
||||
config = self.home / ".config/build-release" / "acme" / "config.toml"
|
||||
config.write_text(config.read_text() + 'env-file = "~/secrets/acme.env"\n')
|
||||
(self.home / "secrets").mkdir()
|
||||
(self.home / "secrets" / "acme.env").write_text("TOKEN=y\n")
|
||||
@@ -504,6 +504,26 @@ class EnvFileRead(unittest.TestCase):
|
||||
self.assertEqual(self.breached("Read", {"file_path": f"{self.home}/.claude/.env"}), ["env-file-read"])
|
||||
self.assertEqual(self.breached("Read", {"file_path": "acme.env"}, f"{self.home}/secrets"), ["env-file-read"])
|
||||
|
||||
def test_a_config_under_xdg_config_home_names_the_env_file_in_place_of_one_under_home(self):
|
||||
moved = self.home / "xdg" / "build-release" / "other"
|
||||
moved.mkdir(parents=True)
|
||||
(moved / "config.toml").write_text((self.home / ".config/build-release" / "acme" / "config.toml").read_text().replace("acme", "other"))
|
||||
env = {"XDG_CONFIG_HOME": str(self.home / "xdg")}
|
||||
(self.home / "secrets" / "other.env").write_text("TOKEN=z\n")
|
||||
|
||||
def refused(name: str) -> bool:
|
||||
found = breaches_of(Call("Read", {"file_path": f"{self.home}/secrets/{name}.env"}, "/r"), str(self.home), env)
|
||||
return bool(found) and "env-file-read" in rules(found[2])
|
||||
|
||||
self.assertEqual((refused("other"), refused("acme")), (True, False))
|
||||
|
||||
def test_a_config_in_the_folder_of_before_0_18_names_no_env_file(self):
|
||||
old = self.home / ".claude-projects" / "old"
|
||||
old.mkdir(parents=True)
|
||||
(old / "config.toml").write_text((self.home / ".config/build-release" / "acme" / "config.toml").read_text().replace("acme", "old"))
|
||||
(self.home / "secrets" / "old.env").write_text("TOKEN=z\n")
|
||||
self.assertEqual(self.breached("Read", {"file_path": f"{self.home}/secrets/old.env"}), [])
|
||||
|
||||
def test_a_read_spelt_from_home_is_refused_naming_the_file(self):
|
||||
found = breaches_of(Call("Read", {"file_path": "~/.claude/.env"}, "/r"), str(self.home), {})
|
||||
self.assertEqual([breach.detail for breach in found[2]], [f"the call reads {self.home}/.claude/.env, whose credentials would land in the transcript"])
|
||||
@@ -627,7 +647,7 @@ class EnvFileRead(unittest.TestCase):
|
||||
|
||||
def test_a_folder_that_starts_with_a_dash_is_searched_after_double_dash(self):
|
||||
write_config(self.home, self.home / "code" / "other")
|
||||
config = self.home / ".claude-projects" / "other" / "config.toml"
|
||||
config = self.home / ".config/build-release" / "other" / "config.toml"
|
||||
config.write_text(config.read_text() + 'env-file = "~/real/x.env"\n')
|
||||
(self.home / "real").mkdir()
|
||||
(self.home / "real" / "x.env").write_text("TOKEN=z\n")
|
||||
@@ -644,10 +664,10 @@ class EnvFileRead(unittest.TestCase):
|
||||
|
||||
def test_a_search_that_starts_in_a_hidden_folder_reaches_a_visible_file_below_it(self):
|
||||
write_config(self.home, self.home / "code" / "other")
|
||||
config = self.home / ".claude-projects" / "other" / "config.toml"
|
||||
config.write_text(config.read_text() + 'env-file = "~/.claude-projects/other.env"\n')
|
||||
(self.home / ".claude-projects" / "other.env").write_text("TOKEN=z\n")
|
||||
for command, expected in (("rg TOKEN ~/.claude-projects", ["env-file-read"]), ("ag TOKEN ~/.claude-projects", ["env-file-read"]), ("grep -r TOKEN ~/.claude-projects", ["env-file-read"])):
|
||||
config = self.home / ".config/build-release" / "other" / "config.toml"
|
||||
config.write_text(config.read_text() + 'env-file = "~/.config/build-release/other.env"\n')
|
||||
(self.home / ".config/build-release" / "other.env").write_text("TOKEN=z\n")
|
||||
for command, expected in (("rg TOKEN ~/.config/build-release", ["env-file-read"]), ("ag TOKEN ~/.config/build-release", ["env-file-read"]), ("grep -r TOKEN ~/.config/build-release", ["env-file-read"])):
|
||||
with self.subTest(command):
|
||||
self.assertEqual(self.breached("Bash", {"command": command}), expected)
|
||||
(self.home / "code").mkdir()
|
||||
@@ -655,7 +675,7 @@ class EnvFileRead(unittest.TestCase):
|
||||
|
||||
def test_rg_and_ag_skip_a_file_below_any_hidden_folder_of_the_search(self):
|
||||
write_config(self.home, self.home / "code" / "other")
|
||||
config = self.home / ".claude-projects" / "other" / "config.toml"
|
||||
config = self.home / ".config/build-release" / "other" / "config.toml"
|
||||
config.write_text(config.read_text() + 'env-file = "~/outer/deep/.h/b.env"\n')
|
||||
(self.home / "outer" / "deep" / ".h").mkdir(parents=True)
|
||||
(self.home / "outer" / "deep" / ".h" / "b.env").write_text("TOKEN=z\n")
|
||||
@@ -692,7 +712,7 @@ class EnvFileRead(unittest.TestCase):
|
||||
|
||||
def test_a_file_several_configs_name_is_reported_once(self):
|
||||
write_config(self.home, self.home / "code" / "other")
|
||||
config = self.home / ".claude-projects" / "other" / "config.toml"
|
||||
config = self.home / ".config/build-release" / "other" / "config.toml"
|
||||
config.write_text(config.read_text() + 'env-file = "~/secrets/../secrets/acme.env"\n')
|
||||
found = breaches_of(Call("Read", {"file_path": "~/secrets/acme.env"}, "/r"), str(self.home), {})
|
||||
self.assertEqual(len([breach for breach in found[2] if breach.rule == "env-file-read"]), 1)
|
||||
@@ -708,25 +728,25 @@ class ReviewerReport(unittest.TestCase):
|
||||
return rules(found[2]) if found else []
|
||||
|
||||
def test_a_reviewer_writes_its_report_into_the_reports_folder(self):
|
||||
self.assertEqual(self.breached("Write", "/h/.local/state/larv-review/.claude-item-73/prose-round-1.md"), [])
|
||||
self.assertEqual(self.breached("Write", "/h/.local/state/build-release/larv-review/.claude-item-73/prose-round-1.md"), [])
|
||||
|
||||
def test_a_relative_path_resolves_against_the_calls_cwd(self):
|
||||
self.assertEqual(self.breached("Write", "prose-round-1.md", cwd="/h/.local/state/larv-review/x"), [])
|
||||
self.assertEqual(self.breached("Write", "prose-round-1.md", cwd="/h/.local/state/build-release/larv-review/x"), [])
|
||||
|
||||
def test_a_symlink_in_the_reports_folder_is_followed_to_where_it_points(self):
|
||||
home = pathlib.Path(self.enterContext(tempfile.TemporaryDirectory()))
|
||||
(home / ".local" / "state" / "larv-review").mkdir(parents=True)
|
||||
(home / ".local" / "state" / "larv-review" / "out").symlink_to(home)
|
||||
found = breaches_of(Call("Write", {"file_path": f"{home}/.local/state/larv-review/out/a.md", "content": "x"}, "/r", "prose-reviewer"), str(home), {})
|
||||
(home / ".local" / "state" / "build-release" / "larv-review").mkdir(parents=True)
|
||||
(home / ".local" / "state" / "build-release" / "larv-review" / "out").symlink_to(home)
|
||||
found = breaches_of(Call("Write", {"file_path": f"{home}/.local/state/build-release/larv-review/out/a.md", "content": "x"}, "/r", "prose-reviewer"), str(home), {})
|
||||
self.assertEqual(rules(found[2]), ["reviewer-report"])
|
||||
|
||||
def test_a_reviewer_writing_anywhere_else_is_refused(self):
|
||||
for path in ["/r/README.md", "/h/.local/state/larv-review", "/h/.local/state/larv-review-x/a.md", "/h/.local/state/larv-review/../a.md", "/tmp/larv-review/a.md"]:
|
||||
for path in ["/r/README.md", "/h/.local/state/build-release/larv-review", "/h/.local/state/build-release/larv-review-x/a.md", "/h/.local/state/build-release/larv-review/../a.md", "/tmp/larv-review/a.md"]:
|
||||
with self.subTest(path):
|
||||
self.assertEqual(self.breached("Write", path), ["reviewer-report"])
|
||||
|
||||
def test_a_reviewer_edits_no_file_even_in_the_reports_folder(self):
|
||||
self.assertEqual(self.breached("Edit", "/h/.local/state/larv-review/x/prose-round-1.md"), ["reviewer-report"])
|
||||
self.assertEqual(self.breached("Edit", "/h/.local/state/build-release/larv-review/x/prose-round-1.md"), ["reviewer-report"])
|
||||
|
||||
def test_a_reviewers_multiedit_is_refused(self):
|
||||
self.assertEqual(self.breached("MultiEdit", "/r/a.py", "stability-reviewer"), ["reviewer-report"])
|
||||
@@ -989,7 +1009,7 @@ class Hook(unittest.TestCase):
|
||||
|
||||
def configured(self) -> pathlib.Path:
|
||||
folder = configured(self, pathlib.Path(self.repo))
|
||||
self.env = {"HOME": str(folder.parents[1])}
|
||||
self.env = {"HOME": str(folder.parents[2])}
|
||||
return folder
|
||||
|
||||
def test_runs_git_guarded(self):
|
||||
@@ -1102,7 +1122,7 @@ class Hook(unittest.TestCase):
|
||||
ran = hook(call, self.repo)
|
||||
self.assertEqual(ran.returncode, 2)
|
||||
self.assertIn("Blocked by rule reviewer-report: prose-reviewer would write ", ran.stderr)
|
||||
self.assertIn("/.local/state/larv-review/", ran.stderr)
|
||||
self.assertIn("/.local/state/build-release/larv-review/", ran.stderr)
|
||||
self.assertNotIn("rule-override", ran.stderr)
|
||||
|
||||
def test_a_commit_override_is_logged_in_the_commit_s_checkout(self):
|
||||
@@ -1123,7 +1143,7 @@ class Hook(unittest.TestCase):
|
||||
def test_a_round_commit_whose_counts_differ_from_its_report_is_refused(self):
|
||||
home = tempfile.mkdtemp()
|
||||
self.addCleanup(subprocess.run, ["rm", "-rf", home])
|
||||
folder = pathlib.Path(home, ".local", "state", "larv-review", self.repo.lstrip("/"))
|
||||
folder = pathlib.Path(home, ".local", "state", "build-release", "larv-review", self.repo.lstrip("/"))
|
||||
folder.mkdir(parents=True)
|
||||
(folder / "stability-round-1.md").write_text("BLOCK\n\n### 🔴 [misread] `a.py:1`: wrong\n\n### 🟡 `b.py:2`: worse\n")
|
||||
|
||||
@@ -1325,7 +1345,7 @@ class TodoRankCheck(unittest.TestCase):
|
||||
pathlib.Path(checkout, "bin", "rank_todo.py").write_text(stub)
|
||||
pathlib.Path(checkout, "todo.md").write_text("# todo\n")
|
||||
self.config = configured(self, pathlib.Path(checkout)) / "config.toml"
|
||||
self.home = self.config.parents[2]
|
||||
self.home = self.config.parents[3]
|
||||
return checkout
|
||||
|
||||
def test_a_changed_plan_that_cannot_be_read_is_a_breach(self):
|
||||
@@ -1335,15 +1355,15 @@ class TodoRankCheck(unittest.TestCase):
|
||||
self.assertEqual(["Permission denied" in detail for detail in self.details(checkout)], [True])
|
||||
|
||||
def details(self, checkout: str, **limit: float) -> list[str]:
|
||||
return [breach.detail for breach in todo_breaches(checkout, self.home, pathlib.Path(self.own), **limit)]
|
||||
return [breach.detail for breach in todo_breaches(checkout, self.home, {}, pathlib.Path(self.own), **limit)]
|
||||
|
||||
def test_a_checkout_of_the_hooks_repo_runs_its_own_rank_todo(self):
|
||||
checkout = self.changed_plan(f"{self.folder}/clone", self.STUB)
|
||||
self.assertEqual(self.details(checkout), [f"own script checked {checkout}/todo.md"])
|
||||
top = str(pathlib.Path(checkout).resolve())
|
||||
self.assertEqual([(breach.rule, breach.directory) for breach in todo_breaches(checkout, self.home, pathlib.Path(self.own))], [("todo-rank-check", top)])
|
||||
self.assertEqual([(breach.rule, breach.directory) for breach in todo_breaches(checkout, self.home, {}, pathlib.Path(self.own))], [("todo-rank-check", top)])
|
||||
self.config.unlink()
|
||||
self.assertEqual([(breach.rule, breach.directory) for breach in todo_breaches(checkout, self.home, pathlib.Path(self.own))], [("todo-rank-check", top)], "a todo.md with no config")
|
||||
self.assertEqual([(breach.rule, breach.directory) for breach in todo_breaches(checkout, self.home, {}, pathlib.Path(self.own))], [("todo-rank-check", top)], "a todo.md with no config")
|
||||
|
||||
def test_its_own_rank_todo_passing_passes(self):
|
||||
self.assertEqual(self.details(self.changed_plan(f"{self.folder}/clone", "")), [])
|
||||
@@ -1384,7 +1404,7 @@ class TodoRankCheck(unittest.TestCase):
|
||||
self.config.write_text(self.config.read_text().replace('"checkout:todo.md"', '"folder:todo.md"'))
|
||||
(self.config.parent / "todo.md").write_text("# todo\n")
|
||||
self.assertEqual(self.details(folder), [f"own script checked {folder}/todo.md"], "checked with the checkout's own rank_todo.py, as a commit there would be")
|
||||
self.assertEqual([(breach.rule, breach.directory) for breach in todo_breaches(folder, self.home, pathlib.Path(self.own))], [("todo-rank-check", str(pathlib.Path(folder).resolve()))])
|
||||
self.assertEqual([(breach.rule, breach.directory) for breach in todo_breaches(folder, self.home, {}, pathlib.Path(self.own))], [("todo-rank-check", str(pathlib.Path(folder).resolve()))])
|
||||
git(folder, "add", "-A")
|
||||
git(folder, "commit", "-q", "-m", "plan")
|
||||
self.assertEqual(self.details(folder), [], "committed, so unchanged")
|
||||
@@ -1420,7 +1440,7 @@ class TodoRankCheck(unittest.TestCase):
|
||||
def test_a_checkout_with_a_changed_todo_md_and_no_config_is_told_to_write_one(self):
|
||||
checkout = self.changed_plan(self.other, self.STUB)
|
||||
self.config.unlink()
|
||||
self.assertEqual(self.details(checkout), [f"no config names the checkout {checkout}: write ~/.claude-projects/<key>/config.toml, as `project-config --help` shows"])
|
||||
self.assertEqual(self.details(checkout), [f"no config names the checkout {checkout}: write {self.home}/.config/build-release/<key>/config.toml, as `project-config --help` shows"])
|
||||
git(checkout, "add", "todo.md")
|
||||
git(checkout, "commit", "-q", "-m", "plan")
|
||||
self.assertEqual(self.details(checkout), [], "a commit that leaves todo.md alone, as in a clone of someone else's project, is not held")
|
||||
@@ -1591,7 +1611,7 @@ class TranscriptRead(unittest.TestCase):
|
||||
|
||||
def test_a_jsonl_file_outside_the_projects_folder_passes(self):
|
||||
self.assertEqual(self.breached("Read", {"file_path": "/home/h/code/acme/cases.jsonl"}), [])
|
||||
self.assertEqual(self.breached("Read", {"file_path": "/home/h/.claude/loop-claude-transcripts/x.jsonl"}), [])
|
||||
self.assertEqual(self.breached("Read", {"file_path": "/home/h/.local/state/build-release/transcripts/x.jsonl"}), [])
|
||||
|
||||
def test_a_search_of_a_transcript_is_not_checked(self):
|
||||
self.assertEqual(self.breached("Grep", {"pattern": "x", "path": self.TRANSCRIPT}), [])
|
||||
|
||||
Reference in New Issue
Block a user