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

This commit is contained in:
2026-12-03 18:56:28 +01:00
parent 20c83f861f
commit 1ca2c8efe0
142 changed files with 1095 additions and 933 deletions
+2 -2
View File
@@ -22,9 +22,9 @@ NAMES = "the command names {}, a file of credentials that must stay out of the t
SEARCHES = "the command searches a folder holding {}, a file of credentials that must stay out of the transcript; search a folder without it"
def env_file_breaches(call: Call, home: str) -> list[Breach]:
def env_file_breaches(call: Call, home: str, env: typing.Mapping[str, str]) -> list[Breach]:
guarded: dict[str, pathlib.Path] = {}
for path in (pathlib.Path(home, CLAUDE_HOME, ".env"), *env_files(pathlib.Path(home))):
for path in (pathlib.Path(home, CLAUDE_HOME, ".env"), *env_files(pathlib.Path(home), env)):
if path.is_file():
# Several configs may name one file: it is checked, and reported, once.
guarded.setdefault(os.path.realpath(path), path)
+9 -9
View File
@@ -99,18 +99,18 @@ def breaches_of(call: Call, home: str, environ: typing.Mapping[str, str]) -> tup
return text(call.given, "args"), text(call.given, "skill"), skill_breaches(call, environ, home)
if call.tool in COMMAND_TOOLS:
command = text(call.given, "command")
return command, command.split("\n", 1)[0], bash_breaches(command, call.cwd, home, call.tool == "Monitor") + read_breaches(call, home) + env_file_breaches(call, home)
return command, command.split("\n", 1)[0], bash_breaches(command, call.cwd, home, environ, call.tool == "Monitor") + read_breaches(call, home) + env_file_breaches(call, home, environ)
if call.tool == "Read":
return "", text(call.given, "file_path"), read_breaches(call, home) + env_file_breaches(call, home) + transcript_breaches(call, home)
return "", text(call.given, "file_path"), read_breaches(call, home) + env_file_breaches(call, home, environ) + transcript_breaches(call, home)
if call.tool == "Grep":
# Only env-file-read checks a Grep, and it takes no override, so no marker or log line concerns the call.
return "", "", env_file_breaches(call, home)
return "", "", env_file_breaches(call, home, environ)
path = text(call.given, "file_path")
if call.tool not in FILE_TOOLS or not path:
return None
before = read(path)
added, after = applied(call, before)
return added, path, report_breaches(call, path, home) + file_breaches(path, before, added, after)
return added, path, report_breaches(call, path, home, environ) + file_breaches(path, before, added, after)
def answer(checked: Checked, what: str, now: float) -> int:
@@ -130,25 +130,25 @@ def answer(checked: Checked, what: str, now: float) -> int:
return 2 if unloggable else 0
def bash_breaches(command: str, cwd: str, home: str, monitor: bool = False) -> list[Breach]:
def bash_breaches(command: str, cwd: str, home: str, env: typing.Mapping[str, str], monitor: bool = False) -> list[Breach]:
"""The breaches of the command's own words, then of each commit it makes, then of the files those commits may take."""
simples = simple_commands(command, cwd, home)
found = commits(simples, home)
in_commits = [breach for commit in found for breach in commit_breaches(commit, pathlib.Path(home))]
in_commits = [breach for commit in found for breach in commit_breaches(commit, pathlib.Path(home), env)]
in_files = [breach for directory in dict.fromkeys(commit.directory for commit in found) for breach in committed_file_breaches(directory)]
return command_breaches(command, simples, monitor) + in_commits + in_files
def commit_breaches(commit: CommitCall, home: pathlib.Path) -> list[Breach]:
def commit_breaches(commit: CommitCall, home: pathlib.Path, env: typing.Mapping[str, str]) -> list[Breach]:
"""The breaches of one commit: its title's and its round's, read through the title templates of the project's config, and its plan's. A config that cannot be read is a breach itself, since no title can then be checked."""
config = located(commit.directory, home, functools.partial(git, guarded=True))
config = located(commit.directory, home, env, functools.partial(git, guarded=True))
unread = []
if isinstance(config, Failure) and not isinstance(config, Unnamed):
unread = [Breach("commit-title", f"the project's config cannot be read, so the title is not checked against its template: {config.reason}", commit.directory)]
titles = config.titles if isinstance(config, ProjectConfig) else templates.BARE
# A checkout no config names has no branch template, so no title of its must fit one.
branch = checkout_branch(commit.directory) if isinstance(config, ProjectConfig) else None
return unread + title_breaches(commit, titles, config.branch if isinstance(config, ProjectConfig) else templates.BRANCH, branch) + round_cap_breaches(commit, titles) + round_report_breaches(commit, titles, home) + todo_breaches(commit.directory, home)
return unread + title_breaches(commit, titles, config.branch if isinstance(config, ProjectConfig) else templates.BRANCH, branch) + round_cap_breaches(commit, titles) + round_report_breaches(commit, titles, home, env) + todo_breaches(commit.directory, home, env)
def checkout_branch(directory: str) -> str | None:
+6 -4
View File
@@ -1,21 +1,23 @@
"""Refuse a reviewer's file call other than a Write of its report into the reports folder: skills/larv-review/review-findings.md → "Report"."""
from collections.abc import Mapping
import os
import pathlib
from rule_hook.rules import Breach
from rule_hook.call import Call
from loop_state.paths import RELEASE_ROOT
from review_rules.review_folder import REPORTS
from review_rules.review_folder import reports_folder
# Each agent under agents/, read from the folder, so an agent the routing tables miss is still confined.
AGENT_FILES = frozenset(path.stem for path in (RELEASE_ROOT / "agents").glob("*.md"))
def report_breaches(call: Call, path: str, home: str) -> list[Breach]:
"""The breach of a file call from a reviewer that is not a Write under REPORTS in home; none from any other agent."""
def report_breaches(call: Call, path: str, home: str, env: Mapping[str, str]) -> list[Breach]:
"""The breach of a file call from a reviewer that is not a Write under the reports folder; none from any other agent."""
if call.agent not in AGENT_FILES:
return []
written = os.path.realpath(os.path.join(call.cwd, path))
reports = os.path.realpath(os.path.join(home, REPORTS))
reports = os.path.realpath(reports_folder(pathlib.Path(home), env))
if call.tool == "Write" and written.startswith(reports + "/"):
return []
return [Breach("reviewer-report", f"{call.agent} would {call.tool.lower()} {written}; write your report with Write to the path your prompt names, under {reports}/", call.cwd)]
+2 -2
View File
@@ -30,7 +30,7 @@ def reviewer_breaches(call: Call, environ: typing.Mapping[str, str], home: str)
kind = review_kind(call.given)
if kind is None or not hands_rungs(environ):
return []
ladder = project_ladder(call.cwd, pathlib.Path(home))
ladder = project_ladder(call.cwd, pathlib.Path(home), environ)
if isinstance(ladder, Failure):
return [unread(ladder, call.cwd)]
project, worker, escape_and_impact = handed(environ, ladder)
@@ -56,7 +56,7 @@ def skill_breaches(call: Call, environ: typing.Mapping[str, str], home: str) ->
skill = text(call.given, "skill").lstrip("/").rsplit(":", 1)[-1]
if skill not in SECURITY_SKILLS or not hands_rungs(environ) or opening_prompt(call.transcript).startswith(SECURITY_OPENER):
return []
ladder = project_ladder(call.cwd, pathlib.Path(home))
ladder = project_ladder(call.cwd, pathlib.Path(home), environ)
if isinstance(ladder, Failure):
return [unread(ladder, call.cwd)]
project, worker, _ = handed(environ, ladder)
+3 -2
View File
@@ -1,4 +1,5 @@
"""rule-hook's check of a round commit's counts against the round's report in the chunk's review folder."""
from collections.abc import Mapping
import pathlib
from rule_hook.rules import Breach
@@ -10,7 +11,7 @@ from review_rules.round_titles import ROUND, round_prefix, title_counts
from project_config.templates import Titles
def round_report_breaches(commit: CommitCall, titles: Titles, home: pathlib.Path) -> list[Breach]:
def round_report_breaches(commit: CommitCall, titles: Titles, home: pathlib.Path, env: Mapping[str, str]) -> list[Breach]:
"""A breach for each round title whose counts differ from those its round's report gives. The round title is the commit title's summary, as `titles` cuts it. A title without all three counts is title_breaches' to refuse. A round whose report is missing or unreadable, or says BLOCK without a finding heading, goes through, as does every round where git cannot name the commit's checkout within 5 seconds."""
summaries = [titles.summary(message.strip()) for message in commit.messages]
rounds = [(named, counts) for summary in summaries if (named := ROUND.match(summary)) and (counts := title_counts(summary)) and counts.misread is not None]
@@ -19,7 +20,7 @@ def round_report_breaches(commit: CommitCall, titles: Titles, home: pathlib.Path
worktree = git("rev-parse", "--show-toplevel", cwd=commit.directory, timeout=5, guarded=True)
if isinstance(worktree, Failure):
return []
folder = pathlib.Path(review_folder(str(home), worktree.strip()))
folder = pathlib.Path(review_folder(str(home), env, worktree.strip()))
breaches = []
for named, counts in rounds:
pass_, round_ = named.group(1).lower(), int(named.group(2))
+3 -4
View File
@@ -9,7 +9,6 @@ from rule_hook.endless_wait import endless_waits
from run_heavy.capped_docker import finds_this_docker
from rule_hook.heavy_command import heavy
from command_lines.shell_command import launched, LAUNCHERS, Simple
from review_rules.review_folder import REPORTS
from project_config import templates
from command_lines.docker_command import unlimited
@@ -48,7 +47,7 @@ RULES: dict[RuleName, Rule] = {
# A marker would let the credentials into the transcript all the same, so no marker waives it.
"env-file-read": Rule(
"an agent never reads ~/.claude/.env or a project's env-file, the file of credentials the project's config names, since a value the agent reads lands in its transcript, which build-release archives and the backups copy; it leaves a tool that needs a credential to read the file itself, gets the file's path from `project-config env-file`, and spells the path another way, such as \"the .env in ~/.claude\", in a command that must mention it without reading it, such as a commit's title, and searches only a folder without it",
"against ~/.claude/.env and the env-file of every config under ~/.claude-projects: a Read of one; a Grep of one, or of a folder holding one, unless a checkout ignores the file and the Grep's glob cannot match it; and a Bash command that spells one's path, or names it in a word or a redirect's target from the directory `cd` left the command in, whether or not the command reads it; and a Bash command that runs `ag`, `grep -r` or `rg` over a folder holding one, or over the directory `cd` left the command in where it names no folder, unless the tool skips the file: `ag` and `rg` skip a hidden file, one below a hidden folder of the search and one a checkout ignores, and `rg` one that none of its globs matches",
"against ~/.claude/.env and the env-file of every config under ~/.config/build-release: a Read of one; a Grep of one, or of a folder holding one, unless a checkout ignores the file and the Grep's glob cannot match it; and a Bash command that spells one's path, or names it in a word or a redirect's target from the directory `cd` left the command in, whether or not the command reads it; and a Bash command that runs `ag`, `grep -r` or `rg` over a folder holding one, or over the directory `cd` left the command in where it names no folder, unless the tool skips the file: `ag` and `rg` skip a hidden file, one below a hidden folder of the search and one a checkout ignores, and `rg` one that none of its globs matches",
overridable=False,
),
"ignorefile-sorted": Rule(
@@ -71,7 +70,7 @@ RULES: dict[RuleName, Rule] = {
),
# A reviewer only reports, so no marker waives it.
"reviewer-report": Rule(
f"a reviewer writes only its report, with Write, into a file under ~/{REPORTS}/",
"a reviewer writes only its report, with Write, into a file under the review reports folder, ~/.local/state/build-release/larv-review/ unless `XDG_STATE_HOME` is set",
"a Write, Edit or MultiEdit call from inside an agent under agents/",
overridable=False,
),
@@ -97,7 +96,7 @@ RULES: dict[RuleName, Rule] = {
),
"todo-rank-check": Rule(
"while todo.md has changes, staged or not, a git commit waits until rank_todo.py --check passes on it: the checkout's own bin/rank_todo.py where the checkout is of this setup's repo, else the release's",
"a git commit in a checkout whose todo.md has changes, and every git commit where the project's config puts todo.md outside the checkout, where the checkout's commits don't say whether it changed; and a git commit in the config's folder, `~/.claude-projects/<key>/`, whose todo.md has changes",
"a git commit in a checkout whose todo.md has changes, and every git commit where the project's config puts todo.md outside the checkout, where the checkout's commits don't say whether it changed; and a git commit in the config's folder, `~/.config/build-release/<key>/`, whose todo.md has changes",
),
# A Read carries no text for a marker, so no marker waives it.
"transcript-read": Rule(
+46 -26
View File
@@ -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}), [])
+4 -3
View File
@@ -1,5 +1,6 @@
import functools
import hashlib
from collections.abc import Mapping
import pathlib
import subprocess
import sys
@@ -20,15 +21,15 @@ OWN = RELEASE_ROOT
OWN_CHECK_SECONDS = 20
def todo_breaches(directory: str, home: pathlib.Path, own: pathlib.Path = OWN, seconds: float = OWN_CHECK_SECONDS) -> list[Breach]:
def todo_breaches(directory: str, home: pathlib.Path, env: Mapping[str, str], own: pathlib.Path = OWN, seconds: float = OWN_CHECK_SECONDS) -> list[Breach]:
"""Why the plan of directory's project is not ranked, where the plan has changed; the plan is the todo.md its config names. directory may also be in a config's folder, a git repo of its own."""
top = guarded_git(directory, "rev-parse", "--show-toplevel")
if isinstance(top, Failure):
return []
held_here = held(pathlib.Path(top), home)
held_here = held(pathlib.Path(top), home, env)
if held_here is not None:
return folder_breaches(top, held_here, own, seconds)
config = located(top, home, functools.partial(git, guarded=True))
config = located(top, home, env, functools.partial(git, guarded=True))
if isinstance(config, Failure):
# A checkout whose todo.md changes with no config is one whose config is still to write. An unchanged todo.md may be a third party's, whose clone needs no config.
unconfigured = pathlib.Path(top) / "todo.md"