From 3e289c95d939757f060254a3dd9553acd5e6959a Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Wed, 11 Nov 2026 14:07:34 +0100 Subject: [PATCH 1/6] Check the files a commit would commit against rule-hook's file rules, and sort .gitignore's allowlist block --- .gitignore | 4 +- CHANGELOG.md | 1 + CLAUDE.md | 2 +- bin/rule_hook/committed_files.py | 41 ++++++++++++++++++++ bin/rule_hook/file_text.py | 12 ++++++ bin/rule_hook/main.py | 22 +++++------ bin/rule_hook/rules.py | 8 +++- bin/rule_hook/test_rule_hook.py | 64 ++++++++++++++++++++++++++++++++ docs/decisions.md | 2 +- docs/reading-cost.md | 17 +++++++++ todo.md | 10 ----- 11 files changed, 154 insertions(+), 29 deletions(-) create mode 100644 bin/rule_hook/committed_files.py create mode 100644 bin/rule_hook/file_text.py diff --git a/.gitignore b/.gitignore index cc723115..e03842c6 100644 --- a/.gitignore +++ b/.gitignore @@ -25,9 +25,9 @@ !bin/branch_chunks/ !bin/branch_chunks/*.py !bin/chunk-pr +!bin/chunk-preflight !bin/chunk_pr/ !bin/chunk_pr/*.py -!bin/chunk-preflight !bin/chunk_preflight/ !bin/chunk_preflight/*.py !bin/claude_code/ @@ -50,12 +50,12 @@ !bin/larv_review/ !bin/larv_review/*.py !bin/loop-claude +!bin/loop-inbox !bin/loop_claude/ !bin/loop_claude/**/ !bin/loop_claude/**/*.py !bin/loop_effects/ !bin/loop_effects/*.py -!bin/loop-inbox !bin/loop_inbox/ !bin/loop_inbox/*.py !bin/loop_state/ diff --git a/CHANGELOG.md b/CHANGELOG.md index 0340441b..a8cd05cc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Unreleased +- `rule-hook` now holds the files a `git commit` would commit to its file rules (`action-pin`, `image-pin`, `ignorefile-sorted`, `no-ai-attribution`), so a file a Bash command wrote is checked as an Edit or Write is. A `# rule-override` line in the file or the command still overrides a breach. - `chunk-pr merge` now refuses while a scoring run the plan calls is unrecorded on the branch, and `larv-review needs-scoring-run` calls one after a release is cut with none. ## 0.7.0 diff --git a/CLAUDE.md b/CLAUDE.md index fab61046..4d5a845e 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -81,7 +81,7 @@ The rules only reviewers apply, for quality, comments, READMEs and prose, live i When one fires, hand the hard part, edits included, to a subagent on the rung loop-claude's prompt names, one above yours. Open the subagent's prompt with the marker loop-claude's prompt gives, then the trigger's evidence. Each later subagent on that task runs on that rung or higher, and each further escalation trigger moves the task one rung higher, up to the highest rung loop-claude's prompt names. Ask the human before going higher. Where loop-claude's prompt names no escalation, as on the ladder's top rung or off it, keep the task in your own thread. - Give a subagent only the access its job needs, and state the limits in its prompt. One that only reads, such as a prose review, gets no shell and no edits. A reviewer under `~/.claude/agents/` writes only its report, under `~/.local/state/larv-review/`, and rule-hook refuses it every other Write, every Edit and every MultiEdit. One that probes a build tags the image as throwaway and removes it afterwards, writes only to a folder it makes under the chunk's review folder (`~/.claude/bin/larv-review review-folder` prints it), and removes no image or file it did not create. - Check `README.md` first for build, test, install, and codegen commands, and fix one that misbehaves in the same change. Refresh `README.md` whenever you change what it describes, keeping it true, not longer. -- Where `~/.claude/bin/rule-hook` does not check it, such as an image named in test code, a Kubernetes manifest, a `docker run` line or a file a Bash command writes, pin a container image to its full patch version and a GitHub Action to a semver tag. +- Where `~/.claude/bin/rule-hook` does not check it, such as an image named in test code, a Kubernetes manifest or a `docker run` line, pin a container image to its full patch version and a GitHub Action to a semver tag. ## Naming files & folders - Name by what's inside. BANNED: `scripts`, `utils`, `helpers`, `misc`, `common`, `lib`, `stuff`. GOOD: `e2e-tests/`, `db-migrations/`, `release-tooling/`. diff --git a/bin/rule_hook/committed_files.py b/bin/rule_hook/committed_files.py new file mode 100644 index 00000000..a1c10978 --- /dev/null +++ b/bin/rule_hook/committed_files.py @@ -0,0 +1,41 @@ +import dataclasses +import posixpath + +from failure import Failure +from rule_hook.file_text import read +from rule_hook.git import guarded_git +from rule_hook.rules import Breach, file_breaches + +# settings.json gives rule-hook 30 seconds; a file past this size is no source file, and reading it would eat them. +MAX_BYTES = 1_000_000 + + +def committed_file_breaches(directory: str) -> list[Breach]: + """The breaches of file_breaches in the files a commit in directory's checkout would commit. + + A file a Bash command wrote reaches no Edit or Write check, so the commit stands in for it. The files are those that differ from HEAD in the index or the work tree, or that are untracked and not ignored: the hook runs before a `git add` earlier in the same command, so the index alone would miss them. Deleted files and files that are no UTF-8 text have no added text. A breach carries its file's text, so a marker in the file overrides it, as in an Edit.""" + top = guarded_git(directory, "rev-parse", "--show-toplevel") + if isinstance(top, Failure): + return [] + changed = guarded_git(top, "diff", "-z", "--name-only", "--no-renames", "--diff-filter=d", "HEAD") + # A checkout with no commit has no HEAD: its index is what differs. + changed = guarded_git(top, "diff", "-z", "--name-only", "--cached", "--no-renames", "--diff-filter=d") if isinstance(changed, Failure) else changed + untracked = guarded_git(top, "ls-files", "-z", "--others", "--exclude-standard") + names = sorted({name for listing in (changed, untracked) if not isinstance(listing, Failure) for name in listing.split("\0") if name}) + breaches = [] + for name in names: + path = posixpath.join(top, name) + after = read(path) if size(path) <= MAX_BYTES else "" + before = guarded_git(top, "show", f"HEAD:{name}") + before = "" if isinstance(before, Failure) else before + known = set(before.splitlines()) + added = "\n".join(line for line in after.splitlines() if line not in known) + breaches += [dataclasses.replace(breach, marked=after) for breach in file_breaches(path, before, added, after)] if added else [] + return breaches + + +def size(path: str) -> int: + try: + return posixpath.getsize(path) + except OSError: + return 0 diff --git a/bin/rule_hook/file_text.py b/bin/rule_hook/file_text.py new file mode 100644 index 00000000..17561398 --- /dev/null +++ b/bin/rule_hook/file_text.py @@ -0,0 +1,12 @@ +import os +import stat + + +def read(path: str) -> str: + """path's text, or "" for anything but a regular file: a FIFO would hang the hook and a device such as /dev/zero would flood it.""" + try: + # O_NONBLOCK opens a FIFO without waiting for a writer; fstat then judges the file opened, not one swapped in after a stat. + with open(os.open(path, os.O_RDONLY | os.O_NONBLOCK), encoding="utf-8") as opened: + return opened.read() if stat.S_ISREG(os.fstat(opened.fileno()).st_mode) else "" + except (OSError, UnicodeDecodeError): + return "" diff --git a/bin/rule_hook/main.py b/bin/rule_hook/main.py index 5d7ede86..c029fb4a 100644 --- a/bin/rule_hook/main.py +++ b/bin/rule_hook/main.py @@ -8,7 +8,10 @@ subagent. The rules: {rules} -A file a Bash command writes, such as through `cat > Dockerfile`, is not checked. +A file a Bash command writes, such as through `cat > Dockerfile`, is checked when a `git commit` would commit it, not +when written: the file rules (action-pin, image-pin, ignorefile-sorted, no-ai-attribution) hold each file that differs +from HEAD in the index or the work tree, or is untracked and not ignored, to the lines it adds. A `# rule-override` line +in that file or in the commit command overrides its breach. A call overrides a rule with `# rule-override : `: @@ -31,7 +34,6 @@ cannot read. """ import json import os -import stat import sys import time import typing @@ -39,8 +41,10 @@ import typing from rule_hook.call import applied, Call, FILE_TOOLS, parsed_call, text from rule_hook.rules import Breach, check, Checked, command_breaches, file_breaches, rules_help from git_cli.git_command import commits +from rule_hook.committed_files import committed_file_breaches from failure import Failure from rule_hook.override_log import Log, log_path, logged, print_overrides, write_override +from rule_hook.file_text import read from rule_hook.repeat_read import read_breaches from rule_hook.reviewer_report import report_breaches from rule_hook.reviewer_rung import reviewer_breaches, skill_breaches @@ -110,14 +114,6 @@ def answer(checked: Checked, what: str, now: float) -> int: def bash_breaches(command: str, cwd: str, home: str) -> list[Breach]: simples = simple_commands(command, cwd, home) - return command_breaches(command, simples, home) + [breach for commit in commits(simples, home) for breach in round_cap_breaches(commit) + todo_breaches(commit.directory)] - - -def read(path: str) -> str: - """path's text, or "" for anything but a regular file: a FIFO would hang the hook and a device such as /dev/zero would flood it.""" - try: - # O_NONBLOCK opens a FIFO without waiting for a writer; fstat then judges the file opened, not one swapped in after a stat. - with open(os.open(path, os.O_RDONLY | os.O_NONBLOCK), encoding="utf-8") as opened: - return opened.read() if stat.S_ISREG(os.fstat(opened.fileno()).st_mode) else "" - except (OSError, UnicodeDecodeError): - return "" + found = commits(simples, home) + 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, home) + [breach for commit in found for breach in round_cap_breaches(commit) + todo_breaches(commit.directory)] + in_files diff --git a/bin/rule_hook/rules.py b/bin/rule_hook/rules.py index 9d119eb0..0c68de8f 100644 --- a/bin/rule_hook/rules.py +++ b/bin/rule_hook/rules.py @@ -104,6 +104,8 @@ class Breach: detail: str # The checkout whose log records an override of this breach. directory: str + # Text beyond the call's own whose markers override this breach: the file a commit holds, as an Edit's text is for its file. + marked: str = "" @dataclasses.dataclass(frozen=True) @@ -124,7 +126,9 @@ def overrides(written: str) -> tuple[dict[str, str], list[str]]: def check(breaches: list[Breach], written: str, markdown: bool, bash: bool) -> Checked: granted, malformed = overrides(written) - blocking = [breach for breach in breaches if breach.rule not in granted] + # Each breach is overridden by the call's markers and by its own file's. + grants = [granted | overrides(breach.marked)[0] for breach in breaches] + blocking = [breach for breach, grant in zip(breaches, grants) if breach.rule not in grant] messages = [f"`{marker}` names no rule below, or gives no reason." for marker in malformed] if blocking else [] where = "the command" if bash else "the text you write, as a comment line" for rule in sorted({breach.rule for breach in blocking}): @@ -134,7 +138,7 @@ def check(breaches: list[Breach], written: str, markdown: bool, bash: bool) -> C continue marker = f"" if markdown else f"# rule-override {rule}: " messages.append(f"Blocked by rule {rule}: {details}. The rule: {RULES[rule].holds}. Where it does not fit this case, add `{marker}` to {where}; larv-review rules on the reason.") - return Checked(messages, bool(blocking), [(breach, granted[breach.rule]) for breach in breaches if breach.rule in granted]) + return Checked(messages, bool(blocking), [(breach, grant[breach.rule]) for breach, grant in zip(breaches, grants) if breach.rule in grant]) def command_breaches(command: str, simples: list[Simple], home: str) -> list[Breach]: diff --git a/bin/rule_hook/test_rule_hook.py b/bin/rule_hook/test_rule_hook.py index 6adb1e80..ff99510d 100644 --- a/bin/rule_hook/test_rule_hook.py +++ b/bin/rule_hook/test_rule_hook.py @@ -913,6 +913,70 @@ class TodoRankCheck(unittest.TestCase): self.assertNotIn("own script", " ".join(reasons)) +class CommittedFiles(unittest.TestCase): + """A git commit holds the files it would commit to the file rules, as an Edit or Write of each would be.""" + UNPINNED = "jobs:\n a:\n steps:\n - uses: actions/checkout@main\n" + + def setUp(self): + self.repo = tempfile.mkdtemp() + self.addCleanup(subprocess.run, ["rm", "-rf", self.repo]) + git(self.repo, "init", "-q", "-b", "main") + git(self.repo, "commit", "-q", "--allow-empty", "-m", "base") + + def write(self, name: str, content: str) -> None: + path = pathlib.Path(self.repo, name) + path.parent.mkdir(parents=True, exist_ok=True) + path.write_text(content) + + def commit(self, command: str = "git add -A && git commit -m x") -> subprocess.CompletedProcess: + return hook({"cwd": self.repo, "tool_input": {"command": command}, "tool_name": "Bash"}, self.repo) + + def test_a_file_a_command_wrote_is_checked_at_the_commit(self): + self.write(".github/workflows/ci.yml", self.UNPINNED) + self.write("Dockerfile", "FROM node:24\n") + self.write(".gitignore", "b\na\n") + self.write("NOTES.md", "Co-Authored-" + "By: Claude \n") + ran = self.commit() + self.assertEqual(ran.returncode, 2) + for rule in ["action-pin", "image-pin", "ignorefile-sorted", "no-ai-attribution"]: + with self.subTest(rule): + self.assertIn(f"Blocked by rule {rule}: ", ran.stderr) + + def test_a_staged_file_is_checked_and_a_clean_tree_passes(self): + self.assertEqual(self.commit().returncode, 0) + self.write(".github/workflows/ci.yml", self.UNPINNED) + git(self.repo, "add", "-A") + self.assertEqual(self.commit("git commit -m x").returncode, 2) + + def test_a_breach_the_head_already_holds_is_left_alone(self): + self.write("Dockerfile", "FROM node:24\n") + self.write(".gitignore", "b\na\n") + git(self.repo, "add", "-A") + git(self.repo, "commit", "-qm", "x", "--no-verify") + self.write("Dockerfile", "FROM node:24\nRUN true\n") + self.write(".gitignore", "b\na\n\n# more\nc\n") + self.assertEqual(self.commit().returncode, 0) + self.write("Dockerfile", "FROM node:24\nRUN true\nFROM node:25\n") + self.assertIn("image-pin: ", self.commit().stderr) + + def test_a_marker_in_the_command_or_the_file_lets_the_commit_through(self): + self.write("Dockerfile", "FROM vendor/tool:2\n") + self.assertEqual(self.commit("git add -A && git commit -m x # rule-override image-pin: the vendor tags no patch versions").returncode, 0) + self.write("Dockerfile", "# rule-override image-pin: the vendor tags no patch versions\nFROM vendor/tool:2\n") + self.assertEqual(self.commit().returncode, 0) + + def test_a_marker_in_another_file_overrides_nothing(self): + self.write("Dockerfile", "FROM vendor/tool:2\n") + self.write("NOTES.md", "# rule-override image-pin: quoted in a note\n") + self.assertIn("Blocked by rule image-pin: ", self.commit().stderr) + + def test_an_untracked_ignored_or_binary_file_breaks_nothing(self): + self.write(".gitignore", "build/\n") + self.write("build/Dockerfile", "FROM node:24\n") + pathlib.Path(self.repo, "image.png").write_bytes(b"\xff\xfe\x00FROM node:24\n") + self.assertEqual(self.commit().returncode, 0) + + class RuleNames(unittest.TestCase): def test_every_rule_name_has_a_rule_and_every_rule_a_name(self): self.assertEqual(set(RULES), set(typing.get_args(RuleName))) diff --git a/docs/decisions.md b/docs/decisions.md index d47faa23..348261d0 100644 --- a/docs/decisions.md +++ b/docs/decisions.md @@ -412,7 +412,7 @@ Valid while a model switch inside a session discards its prompt cache. ## rule-hook: a PreToolUse hook enforces each rule a program can check, a `# rule-override : ` marker overrides any rule but those `rule-hook --help` marks as taking none, and larv-review's overrides pass rules on each override before merge -2026-10-12, lilleman. Serves goals 1.2 and 1.3. Anthropic's best-practices page calls `CLAUDE.md` advisory and hooks deterministic, so a rule that must hold every time moves into `bin/rule-hook`, and `CLAUDE.md` keeps it only where the hook cannot check it. A Claude Code hook ties the check to one vendor ("Prefer the vendor-neutral option", `principles/technical-principles.md`), which is the target itself here: this repo configures Claude Code. What the tie buys: the hook blocks before a write lands, Edit and Write calls included, in every project with no per-repo install; a git `commit-msg` hook sees only commits, and CI sees them only after the push. The hook checks each write, so the agent fixes the line it just wrote; checking the staged diff at commit time would also cover files a Bash command writes, at the cost of later feedback. The marker's spelling was picked by a panel of three fresh readers, two to one. Each override is logged in the checkout's git directory, which is never pushed (goal 4). The plan had loop-claude's judge to rule on overrides inside a loop; lilleman approved larv-review's overrides pass in every run, because it rules before merge and an outrageous override still reaches the human through its ask. 2026-10-16, lilleman, answering plan item 166: no marker overrides `reviewer-rung`. 2026-11-04, lilleman: the title points at `rule-hook --help`, which lists every rule no marker overrides from the code, so the title can't drift from it; the comment above each in `bin/rule_hook/rules.py` says why. Valid while a PreToolUse hook that exits 2 blocks the call and hands its stderr to the model, and while an agent commits through Claude Code's Bash tool. +2026-10-12, lilleman. Serves goals 1.2 and 1.3. Anthropic's best-practices page calls `CLAUDE.md` advisory and hooks deterministic, so a rule that must hold every time moves into `bin/rule-hook`, and `CLAUDE.md` keeps it only where the hook cannot check it. A Claude Code hook ties the check to one vendor ("Prefer the vendor-neutral option", `principles/technical-principles.md`), which is the target itself here: this repo configures Claude Code. What the tie buys: the hook blocks before a write lands, Edit and Write calls included, in every project with no per-repo install; a git `commit-msg` hook sees only commits, and CI sees them only after the push. The hook checks each write, so the agent fixes the line it just wrote; a commit also holds the files it would commit to the file rules, since a file a Bash command writes reaches no write check; that feedback comes later, at the commit. The marker's spelling was picked by a panel of three fresh readers, two to one. Each override is logged in the checkout's git directory, which is never pushed (goal 4). The plan had loop-claude's judge to rule on overrides inside a loop; lilleman approved larv-review's overrides pass in every run, because it rules before merge and an outrageous override still reaches the human through its ask. 2026-10-16, lilleman, answering plan item 166: no marker overrides `reviewer-rung`. 2026-11-04, lilleman: the title points at `rule-hook --help`, which lists every rule no marker overrides from the code, so the title can't drift from it; the comment above each in `bin/rule_hook/rules.py` says why. Valid while a PreToolUse hook that exits 2 blocks the call and hands its stderr to the model, and while an agent commits through Claude Code's Bash tool. ## rules/: `CLAUDE.md` holds the worker's rules that no file path can scope, and each topic's rules for the worker live in a `rules/` file that Claude Code loads by its `paths:` frontmatter diff --git a/docs/reading-cost.md b/docs/reading-cost.md index f94e43cc..157e7eca 100644 --- a/docs/reading-cost.md +++ b/docs/reading-cost.md @@ -1536,3 +1536,20 @@ Read most (opens and searches): Read most (opens and searches): - `todo.md` 1 + +## Reading cost, chunk 4a0a495957fb, finished 2026-11-11T13:02:21Z + +146184 new input tokens before the first commit. + +Read most (opens and searches): + +- `bin/larv_review/main.py` 9 +- `bin/larv_review/plan.py` 5 +- `bin/larv_review/test_larv_review.py` 5 +- `bin/chunk_pr/test_chunk_pr.py` 4 +- `bin/larv_review/history_commands.py` 4 +- `bin/review_rules/comprehension_history.py` 4 +- `bin/chunk_pr/main.py` 3 +- `bin/chunk_preflight/main.py` 3 +- `bin/release_plan/release_standing.py` 3 +- `CHANGELOG.md` 2 diff --git a/todo.md b/todo.md index 3de39d8c..af7bf4d0 100644 --- a/todo.md +++ b/todo.md @@ -12,7 +12,6 @@ | ID | Release | Blocked by | Exempt | Item | L | E | I | R | S | Moves | Score | |---|---|---|---|---|---|---|---|---|---|---|---| -| 294 | 0.8.0 | | | **Check the files a commit stages against rule-hook's file rules, so a file a Bash command wrote is held to them as an Edit or Write is.** | 2 | 2 | 3 | 5 | 4 | 1.3 by 5 | 5.2 | | 297 | 0.8.0 | | | **Have loop-claude compute the judge's taken-in items, release-ready and escalation fields from `chunk-preflight`, git and the worker's structured lines, and leave the judge only the verdict kind.** | 3 | 2 | 3 | 6 | 4 | 1.4 by 2, code health by 2 | 3.7 | | 302 | 0.8.0 | | | **Call a scoring run for an item whose tagline makes the comprehension floor its target, and not for one that only names the floor, such as in a quoted decision title.** | 2 | 2 | 3 | 5 | 3 | code health by 2 | 3.6 | | 293 | 0.8.0 | | | **Run mutation tests on a chunk's changed lines in the worker's pre-review gate, through one command that picks the tool by language, and hand stability-reviewer the surviving mutants.** | 3 | 2 | 3 | 6 | 5 | 1.1 by 5, 1.4 by 4, 1.5 by 2 | 2.8 | @@ -48,7 +47,6 @@ | 187 | 0.9.0 | | | **Count the tokens a worker spends reading reviewers' reports, so goal 1.4's signal shows whether report files lowered what a review costs the worker's context.** | 2 | 2 | 1 | 3 | 3 | 1.4 by 3 | 1.2 | | 266 | 0.9.0 | | | **Move the chunks archived under the key `home/lilleman/.claude` to the key `claude-config`, so the routing figures and `score-outcomes` count this repo's chunks as one project.** | 3 | 2 | 2 | 5 | 3 | 1.4 by 3 | 1.2 | | 181 | 0.9.0 | | principle | **Have the test of a quoted answer's step-up assert the stepped rung's facts as literals, not through `prompts.rungs_held`.** | 1 | 1 | 1 | 1 | 1 | 1.1 by 2 | 1.0 | -| 192 | 0.9.0 | | principle | **Sort `.gitignore`'s allowlist block, from `!.claude/` to `!workflow-bench/test_review_git.py`, by code point, so rule-hook's `ignorefile-sorted` checks later edits to it again.** | 1 | 1 | 1 | 1 | 1 | 1.1 by 2 | 1.0 | | 193 | 0.9.0 | | | **Narrow `readme_goals`'s mark to `Mark` by a typed lookup in place of `typing.cast`, so a mark added to the regex but not the lookup fails at run time, and one added to the lookup but not `Mark` fails mypy.** | 1 | 1 | 3 | 3 | 1 | 1.1 by 2 | 1.0 | | 194 | 0.9.0 | | | **Make `test_waits_out_a_usage_limit_which_ends_a_run_of_failures` expect a usage-limit wait independent of the wall-clock time that passes during the run.** | 1 | 1 | 1 | 1 | 1 | 1.1 by 2 | 1.0 | | 202 | 0.9.0 | | | **Add `CLAUDE.md` → "Prose"'s rule "Write negations as people say them", with its examples, to `skills/larv-review/standards/prose.md`, so the prose reviewer holds prose to it.** | 1 | 2 | 2 | 3 | 1 | 1.1 by 2 | 1.0 | @@ -60,10 +58,6 @@ ## Details -### 294. Check the files a commit stages against rule-hook's file rules, so a file a Bash command wrote is held to them as an Edit or Write is. - -From 2026-11-08 to 2026-11-10, workers in other projects wrote 1,266 files through Bash (a python heredoc, `sed -i`, `cat >`) against 260 through Edit and Write, and `rule-hook --help` says it doesn't check a file a Bash command writes. So `action-pin`, `image-pin`, `ignorefile-sorted` and the attribution check miss most edits. rule-hook already checks at `git commit` for `todo-rank-check`, so checking staged files there follows a pattern the repo has. Ship item 192 in the same chunk: its unsorted `.gitignore` block is one symptom of this gap. - ### 297. Have loop-claude compute the judge's taken-in items, release-ready and escalation fields from `chunk-preflight`, git and the worker's structured lines, and leave the judge only the verdict kind. `bin/loop_claude/cycle/judge.py` already checks quotes in code (`quotes_checked`, `grounded`, `re_ask_checked`). The `Reply` fields `items_taken_in`, `release_ready` and `escalation` state facts the plan and git already hold, so code can derive them with certainty, and the judge's prompt shrinks to what needs judgement. Before switching, recompute each field for the 668 archived verdicts offline and count where code and judge disagree; read each disagreement and keep the judge for a field where code is wrong. Seats found `quotes_checked` hard to read (PR #397's scoring run: the misquote rule is split across `judge.py` and `escalation_mark.py`); make it easier to read where the change touches it. @@ -285,10 +279,6 @@ The archive holds 277 chunk folders under `home/lilleman/.claude`, from 2026-09- `bin/loop_claude/test_loop_claude.py`'s `test_a_quoted_answer_that_cites_an_escalation_trigger_steps_the_worker_up_before_it_resumes_and_archives_the_step` builds its expected prompt from `prompts.rungs_held`, the code under test, so a bug there passes it. The technical principles' test bullet bans that shape. Assert the new rung and one review launch as literals, as the typed answer's step-up test does. Raised by the principles audit of PR #308. -### 192. Sort `.gitignore`'s allowlist block, from `!.claude/` to `!workflow-bench/test_review_git.py`, by code point, so rule-hook's `ignorefile-sorted` checks later edits to it again. - -Found by review of PR #317. The block, `.gitignore:17-142` on 2026-11-10, is out of order in several places: `!bin/chunk-preflight` sits below `!bin/chunk_pr/`, and `!bin/loop-inbox` below `!bin/loop_claude/`, though `-` sorts before `_`. `LC_ALL=C sort -c` on the block names the first one. `ignore_breaches` in `bin/rule_hook/rules.py` skips a block that was already unsorted before an edit, so while this one stays unsorted no later edit to it is checked. The unsorted block breaches the technical principle "Deterministic order wherever order carries no meaning". - ### 193. Narrow `readme_goals`'s mark to `Mark` by a typed lookup in place of `typing.cast`, so a mark added to the regex but not the lookup fails at run time, and one added to the lookup but not `Mark` fails mypy. Found by review of PR #317. `bin/release_plan/ranking.py`'s `readme_goals` writes `typing.cast(Mark, mark or None)`, which asserts the type `goal_weights` branches on without checking it: a mark added to the regex reaches `goal_weights` as a value `Mark` lacks. mypy does not read the regex, so no lookup lets it catch that. Replace the cast with a lookup typed `dict[str, Mark]`, from each mark the regex captures, and `""` for none, to its `Mark` value. A mark added to the regex but not the lookup then raises `KeyError` at run time, and a value added to the lookup but not `Mark` fails mypy. -- 2.52.0 From 47c10c456548bb84fc0e56f8f79b56c83ebd3404 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Wed, 11 Nov 2026 14:19:48 +0100 Subject: [PATCH 2/6] =?UTF-8?q?Answer=20prose=20round=201:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=205=20=F0=9F=9F=A1=20(0=20misread);=20reword=20th?= =?UTF-8?q?e=20help=20paragraph,=20the=20changelog=20bullet=20and=20the=20?= =?UTF-8?q?decision,=20and=20restore=20the=20entry's=20old=20sentence?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 2 +- bin/rule_hook/main.py | 11 ++++++----- bin/rule_hook/rules.py | 4 ++-- docs/decisions.md | 2 +- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a8cd05cc..51b352a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## Unreleased -- `rule-hook` now holds the files a `git commit` would commit to its file rules (`action-pin`, `image-pin`, `ignorefile-sorted`, `no-ai-attribution`), so a file a Bash command wrote is checked as an Edit or Write is. A `# rule-override` line in the file or the command still overrides a breach. +- `rule-hook` now checks files at `git commit`: each file that differs from HEAD or is untracked and not ignored, even one the commit leaves out. It holds each to `action-pin`, `image-pin`, `ignorefile-sorted` and `no-ai-attribution`, so a file a Bash command wrote is checked as an Edit or Write is. A `# rule-override` line in the file or the command overrides a breach. - `chunk-pr merge` now refuses while a scoring run the plan calls is unrecorded on the branch, and `larv-review needs-scoring-run` calls one after a release is cut with none. ## 0.7.0 diff --git a/bin/rule_hook/main.py b/bin/rule_hook/main.py index c029fb4a..b15401e5 100644 --- a/bin/rule_hook/main.py +++ b/bin/rule_hook/main.py @@ -8,17 +8,18 @@ subagent. The rules: {rules} -A file a Bash command writes, such as through `cat > Dockerfile`, is checked when a `git commit` would commit it, not -when written: the file rules (action-pin, image-pin, ignorefile-sorted, no-ai-attribution) hold each file that differs -from HEAD in the index or the work tree, or is untracked and not ignored, to the lines it adds. A `# rule-override` line -in that file or in the commit command overrides its breach. - A call overrides a rule with `# rule-override : `: - anywhere in a Bash command, such as a trailing comment - in a file, as a comment line in the text the edit writes - in Markdown, as `` +A file a Bash command writes, such as through `cat > Dockerfile`, is checked when a `git commit` runs, not when written. +The commit checks every file that differs from HEAD, in the index or the work tree, and every untracked file that is +not ignored, even one the commit leaves out. It holds each to the rules that name a file (action-pin, image-pin, +ignorefile-sorted, no-ai-attribution), judged on the lines the file adds. A marker among those lines, or in the commit +command, overrides the file's breach. + Each override that let a call through is appended to rule-overrides.tsv in the git directory of the checkout it touched: UTC time, branch, the commit checked out, rule, reason, and the file written or the command's first line. An override outside any git checkout is not logged. diff --git a/bin/rule_hook/rules.py b/bin/rule_hook/rules.py index 0c68de8f..206b8fb1 100644 --- a/bin/rule_hook/rules.py +++ b/bin/rule_hook/rules.py @@ -104,7 +104,7 @@ class Breach: detail: str # The checkout whose log records an override of this breach. directory: str - # Text beyond the call's own whose markers override this breach: the file a commit holds, as an Edit's text is for its file. + # The lines a commit adds to the breach's file: its markers override this breach, as a Write's text overrides its own file's. marked: str = "" @@ -126,7 +126,7 @@ def overrides(written: str) -> tuple[dict[str, str], list[str]]: def check(breaches: list[Breach], written: str, markdown: bool, bash: bool) -> Checked: granted, malformed = overrides(written) - # Each breach is overridden by the call's markers and by its own file's. + # A marker overrides a breach when it is in the call's own text or in the breach's file. grants = [granted | overrides(breach.marked)[0] for breach in breaches] blocking = [breach for breach, grant in zip(breaches, grants) if breach.rule not in grant] messages = [f"`{marker}` names no rule below, or gives no reason." for marker in malformed] if blocking else [] diff --git a/docs/decisions.md b/docs/decisions.md index 348261d0..b105d0a6 100644 --- a/docs/decisions.md +++ b/docs/decisions.md @@ -412,7 +412,7 @@ Valid while a model switch inside a session discards its prompt cache. ## rule-hook: a PreToolUse hook enforces each rule a program can check, a `# rule-override : ` marker overrides any rule but those `rule-hook --help` marks as taking none, and larv-review's overrides pass rules on each override before merge -2026-10-12, lilleman. Serves goals 1.2 and 1.3. Anthropic's best-practices page calls `CLAUDE.md` advisory and hooks deterministic, so a rule that must hold every time moves into `bin/rule-hook`, and `CLAUDE.md` keeps it only where the hook cannot check it. A Claude Code hook ties the check to one vendor ("Prefer the vendor-neutral option", `principles/technical-principles.md`), which is the target itself here: this repo configures Claude Code. What the tie buys: the hook blocks before a write lands, Edit and Write calls included, in every project with no per-repo install; a git `commit-msg` hook sees only commits, and CI sees them only after the push. The hook checks each write, so the agent fixes the line it just wrote; a commit also holds the files it would commit to the file rules, since a file a Bash command writes reaches no write check; that feedback comes later, at the commit. The marker's spelling was picked by a panel of three fresh readers, two to one. Each override is logged in the checkout's git directory, which is never pushed (goal 4). The plan had loop-claude's judge to rule on overrides inside a loop; lilleman approved larv-review's overrides pass in every run, because it rules before merge and an outrageous override still reaches the human through its ask. 2026-10-16, lilleman, answering plan item 166: no marker overrides `reviewer-rung`. 2026-11-04, lilleman: the title points at `rule-hook --help`, which lists every rule no marker overrides from the code, so the title can't drift from it; the comment above each in `bin/rule_hook/rules.py` says why. Valid while a PreToolUse hook that exits 2 blocks the call and hands its stderr to the model, and while an agent commits through Claude Code's Bash tool. +2026-10-12, lilleman. Serves goals 1.2 and 1.3. Anthropic's best-practices page calls `CLAUDE.md` advisory and hooks deterministic, so a rule that must hold every time moves into `bin/rule-hook`, and `CLAUDE.md` keeps it only where the hook cannot check it. A Claude Code hook ties the check to one vendor ("Prefer the vendor-neutral option", `principles/technical-principles.md`), which is the target itself here: this repo configures Claude Code. What the tie buys: the hook blocks before a write lands, Edit and Write calls included, in every project with no per-repo install; a git `commit-msg` hook sees only commits, and CI sees them only after the push. The hook checks each write, so the agent fixes the line it just wrote; checking the staged diff at commit time would also cover files a Bash command writes, at the cost of later feedback. The marker's spelling was picked by a panel of three fresh readers, two to one. Each override is logged in the checkout's git directory, which is never pushed (goal 4). The plan had loop-claude's judge to rule on overrides inside a loop; lilleman approved larv-review's overrides pass in every run, because it rules before merge and an outrageous override still reaches the human through its ask. 2026-10-16, lilleman, answering plan item 166: no marker overrides `reviewer-rung`. 2026-11-04, lilleman: the title points at `rule-hook --help`, which lists every rule no marker overrides from the code, so the title can't drift from it; the comment above each in `bin/rule_hook/rules.py` says why. Valid while a PreToolUse hook that exits 2 blocks the call and hands its stderr to the model, and while an agent commits through Claude Code's Bash tool. 2026-11-11, lilleman: the hook also checks, at a `git commit`, each file the commit would commit against the rules that name a file, since a file a Bash command writes reaches no write check; the feedback comes at the commit, not at the write. ## rules/: `CLAUDE.md` holds the worker's rules that no file path can scope, and each topic's rules for the worker live in a `rules/` file that Claude Code loads by its `paths:` frontmatter -- 2.52.0 From 21bd753c5b927e0cc249e80a2f93b9475c48bd8c Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Wed, 11 Nov 2026 14:19:48 +0100 Subject: [PATCH 3/6] =?UTF-8?q?Answer=20stability=20round=201:=203=20?= =?UTF-8?q?=F0=9F=94=B4,=203=20=F0=9F=9F=A1=20(0=20misread);=20list=20file?= =?UTF-8?q?s=20with=20diff-index,=20check=20the=20index=20blob,=20take=20o?= =?UTF-8?q?verride=20markers=20from=20the=20added=20lines?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/rule_hook/committed_files.py | 53 +++++++++++++++++++++----------- bin/rule_hook/test_rule_hook.py | 46 +++++++++++++++++++++++++-- 2 files changed, 79 insertions(+), 20 deletions(-) diff --git a/bin/rule_hook/committed_files.py b/bin/rule_hook/committed_files.py index a1c10978..1dd89ca6 100644 --- a/bin/rule_hook/committed_files.py +++ b/bin/rule_hook/committed_files.py @@ -1,37 +1,54 @@ import dataclasses import posixpath -from failure import Failure -from rule_hook.file_text import read -from rule_hook.git import guarded_git from rule_hook.rules import Breach, file_breaches +from failure import Failure +from git_cli import git_repo +from rule_hook.git import guarded_git +from rule_hook.file_text import read -# settings.json gives rule-hook 30 seconds; a file past this size is no source file, and reading it would eat them. +# settings.json gives rule-hook 30 seconds; a file past this size is not source code, and reading it would use them up. MAX_BYTES = 1_000_000 def committed_file_breaches(directory: str) -> list[Breach]: """The breaches of file_breaches in the files a commit in directory's checkout would commit. - A file a Bash command wrote reaches no Edit or Write check, so the commit stands in for it. The files are those that differ from HEAD in the index or the work tree, or that are untracked and not ignored: the hook runs before a `git add` earlier in the same command, so the index alone would miss them. Deleted files and files that are no UTF-8 text have no added text. A breach carries its file's text, so a marker in the file overrides it, as in an Edit.""" + A file a Bash command wrote reaches no Edit or Write check, so the commit checks the file instead. The files are those that differ from HEAD in the index or the work tree, or that are untracked and not ignored: the hook runs before a `git add` earlier in the same command, so the index alone would miss those files. A tracked file is checked as the index holds it and as the work tree does, since the commit takes the index. A deleted file, or one that is not UTF-8 text, has no added text. A breach carries the lines its file adds, so a marker among them overrides it, as in a Write; a marker the file already held doesn't.""" top = guarded_git(directory, "rev-parse", "--show-toplevel") if isinstance(top, Failure): return [] - changed = guarded_git(top, "diff", "-z", "--name-only", "--no-renames", "--diff-filter=d", "HEAD") - # A checkout with no commit has no HEAD: its index is what differs. - changed = guarded_git(top, "diff", "-z", "--name-only", "--cached", "--no-renames", "--diff-filter=d") if isinstance(changed, Failure) else changed + tracked = tracked_names(top) untracked = guarded_git(top, "ls-files", "-z", "--others", "--exclude-standard") - names = sorted({name for listing in (changed, untracked) if not isinstance(listing, Failure) for name in listing.split("\0") if name}) - breaches = [] - for name in names: + breaches: list[Breach] = [] + for name in sorted(tracked | (set() if isinstance(untracked, Failure) else names_in(untracked))): path = posixpath.join(top, name) - after = read(path) if size(path) <= MAX_BYTES else "" - before = guarded_git(top, "show", f"HEAD:{name}") - before = "" if isinstance(before, Failure) else before - known = set(before.splitlines()) - added = "\n".join(line for line in after.splitlines() if line not in known) - breaches += [dataclasses.replace(breach, marked=after) for breach in file_breaches(path, before, added, after)] if added else [] - return breaches + before = blob(top, "HEAD" if name in tracked else "", name) + for after in dict.fromkeys([read(path) if size(path) <= MAX_BYTES else "", blob(top, "", name) if name in tracked else ""]): + known = set(before.splitlines()) + added = "\n".join(line for line in after.splitlines() if line not in known) + breaches += [dataclasses.replace(breach, marked=added) for breach in file_breaches(path, before, added, after)] + return list(dict.fromkeys(breaches)) + + +def tracked_names(top: str) -> set[str]: + """The tracked files that differ from HEAD in the index or the work tree, deleted ones left out. It lists with diff-index, which neither hashes the work tree nor enters a submodule: either would run a clean filter that the checkout's config names, before the call is allowed.""" + listings = [guarded_git(top, "diff-index", "-z", "--name-only", "--no-renames", "--diff-filter=d", "--ignore-submodules", *cached, "HEAD") for cached in ([], ["--cached"])] + if any(isinstance(listing, Failure) for listing in listings): + # A checkout with no commit has no HEAD: every file in its index is new. + listing = guarded_git(top, "ls-files", "-z") + return set() if isinstance(listing, Failure) else names_in(listing) + return {name for listing in listings if not isinstance(listing, Failure) for name in names_in(listing)} + + +def names_in(listing: str) -> set[str]: + return {name for name in listing.split("\0") if name} + + +def blob(top: str, commit: str, name: str) -> str: + """name's text in the commit, or in the index where commit is empty; "" where there is none.""" + shown = git_repo.git("show", f"{commit}:{name}", cwd=top, guarded=True) + return "" if isinstance(shown, Failure) else shown def size(path: str) -> int: diff --git a/bin/rule_hook/test_rule_hook.py b/bin/rule_hook/test_rule_hook.py index ff99510d..2be74551 100644 --- a/bin/rule_hook/test_rule_hook.py +++ b/bin/rule_hook/test_rule_hook.py @@ -965,12 +965,54 @@ class CommittedFiles(unittest.TestCase): self.write("Dockerfile", "# rule-override image-pin: the vendor tags no patch versions\nFROM vendor/tool:2\n") self.assertEqual(self.commit().returncode, 0) - def test_a_marker_in_another_file_overrides_nothing(self): + def test_a_staged_breach_blocks_the_commit_after_the_work_tree_is_fixed(self): + self.write("Dockerfile", "FROM node:24\n") + git(self.repo, "add", "Dockerfile") + self.write("Dockerfile", "FROM node:24.18.1\n") + self.assertIn("image-pin: ", self.commit("git commit -m x").stderr) + + def test_a_stat_dirty_file_runs_no_clean_filter(self): + self.write("a.txt", "a\n") + self.write(".gitattributes", "a.txt filter=planted\n") + git(self.repo, "add", "-A") + git(self.repo, "commit", "-qm", "x", "--no-verify") + git(self.repo, "config", "filter.planted.clean", f"touch {self.repo}/ran; cat") + pathlib.Path(self.repo, "ran").unlink(missing_ok=True) + os.utime(pathlib.Path(self.repo, "a.txt"), (1, 1)) + self.assertEqual(self.commit("git commit -m x").returncode, 0) + self.assertFalse(pathlib.Path(self.repo, "ran").exists()) + + def test_a_checkout_with_no_commit_checks_its_index_and_untracked_files(self): + fresh = tempfile.mkdtemp() + self.addCleanup(subprocess.run, ["rm", "-rf", fresh]) + git(fresh, "init", "-q", "-b", "main") + pathlib.Path(fresh, "Dockerfile").write_text("FROM node:24\n") + git(fresh, "add", "Dockerfile") + pathlib.Path(fresh, "NOTES.md").write_text(TRAILER + "\n") + ran = hook({"cwd": fresh, "tool_input": {"command": "git commit -m x"}, "tool_name": "Bash"}, fresh) + for rule in ["image-pin", "no-ai-attribution"]: + self.assertIn(f"Blocked by rule {rule}: ", ran.stderr) + + def test_a_change_that_only_reorders_an_ignore_file_is_checked(self): + self.write(".gitignore", "a\nb\nc\n") + git(self.repo, "add", "-A") + git(self.repo, "commit", "-qm", "x", "--no-verify") + self.write(".gitignore", "c\nb\na\n") + self.assertIn("ignorefile-sorted: ", self.commit().stderr) + + def test_a_marker_the_head_already_holds_does_not_override_a_new_breach(self): + self.write("Dockerfile", "# rule-override image-pin: the vendor tags no patch versions\nFROM vendor/tool:2\n") + git(self.repo, "add", "-A") + git(self.repo, "commit", "-qm", "x", "--no-verify") + self.write("Dockerfile", "# rule-override image-pin: the vendor tags no patch versions\nFROM vendor/tool:2\nFROM node:24\n") + self.assertIn("image-pin: ", self.commit().stderr) + + def test_a_marker_in_another_file_does_not_override_a_breach(self): self.write("Dockerfile", "FROM vendor/tool:2\n") self.write("NOTES.md", "# rule-override image-pin: quoted in a note\n") self.assertIn("Blocked by rule image-pin: ", self.commit().stderr) - def test_an_untracked_ignored_or_binary_file_breaks_nothing(self): + def test_an_ignored_or_binary_file_is_left_alone(self): self.write(".gitignore", "build/\n") self.write("build/Dockerfile", "FROM node:24\n") pathlib.Path(self.repo, "image.png").write_bytes(b"\xff\xfe\x00FROM node:24\n") -- 2.52.0 From 0b5a41fbf9d25ea0b9c22e6c054790cdaf6fa1a5 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Wed, 11 Nov 2026 14:19:48 +0100 Subject: [PATCH 4/6] =?UTF-8?q?Answer=20product-owner=20round=201:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=201=20=F0=9F=9F=A1=20(0=20misread);=20markers=20c?= =?UTF-8?q?ome=20from=20the=20added=20lines,=20in=20the=20stability=20roun?= =?UTF-8?q?d's=20commit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit -- 2.52.0 From 89bd9e86cc2b4e0db4301441716cf24eb2305c64 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Wed, 11 Nov 2026 14:19:48 +0100 Subject: [PATCH 5/6] =?UTF-8?q?Answer=20security=20round=201:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=200=20=F0=9F=9F=A1=20(0=20misread);=20no=20findin?= =?UTF-8?q?gs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit -- 2.52.0 From b99e362a8c759f355678e417732d1f152455abf4 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Wed, 11 Nov 2026 14:26:49 +0100 Subject: [PATCH 6/6] =?UTF-8?q?Answer=20stability=20round=202:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=202=20=F0=9F=9F=A1=20(0=20misread);=20test=20the?= =?UTF-8?q?=20submodule=20filter,=20skip=20the=20git=20call=20for=20an=20u?= =?UTF-8?q?ntracked=20file,=20merge=20a=20repeated=20breach,=20cap=20the?= =?UTF-8?q?=20staged=20blob?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/rule_hook/committed_files.py | 8 +++++--- bin/rule_hook/test_rule_hook.py | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/bin/rule_hook/committed_files.py b/bin/rule_hook/committed_files.py index 1dd89ca6..b30ec7ef 100644 --- a/bin/rule_hook/committed_files.py +++ b/bin/rule_hook/committed_files.py @@ -23,12 +23,14 @@ def committed_file_breaches(directory: str) -> list[Breach]: breaches: list[Breach] = [] for name in sorted(tracked | (set() if isinstance(untracked, Failure) else names_in(untracked))): path = posixpath.join(top, name) - before = blob(top, "HEAD" if name in tracked else "", name) + # An untracked file has neither a version in HEAD nor one in the index. A tracked file costs two git calls, about 4 ms each: a commit of 3000 changed files uses 13 of the hook's 30 seconds. + before = blob(top, "HEAD", name) if name in tracked else "" for after in dict.fromkeys([read(path) if size(path) <= MAX_BYTES else "", blob(top, "", name) if name in tracked else ""]): known = set(before.splitlines()) added = "\n".join(line for line in after.splitlines() if line not in known) breaches += [dataclasses.replace(breach, marked=added) for breach in file_breaches(path, before, added, after)] - return list(dict.fromkeys(breaches)) + # The index copy and the work-tree copy of a file can breach the same way; the first stands. + return list({(breach.rule, breach.detail): breach for breach in reversed(breaches)}.values())[::-1] def tracked_names(top: str) -> set[str]: @@ -48,7 +50,7 @@ def names_in(listing: str) -> set[str]: def blob(top: str, commit: str, name: str) -> str: """name's text in the commit, or in the index where commit is empty; "" where there is none.""" shown = git_repo.git("show", f"{commit}:{name}", cwd=top, guarded=True) - return "" if isinstance(shown, Failure) else shown + return "" if isinstance(shown, Failure) or len(shown) > MAX_BYTES else shown def size(path: str) -> int: diff --git a/bin/rule_hook/test_rule_hook.py b/bin/rule_hook/test_rule_hook.py index 2be74551..9e3f597c 100644 --- a/bin/rule_hook/test_rule_hook.py +++ b/bin/rule_hook/test_rule_hook.py @@ -982,6 +982,21 @@ class CommittedFiles(unittest.TestCase): self.assertEqual(self.commit("git commit -m x").returncode, 0) self.assertFalse(pathlib.Path(self.repo, "ran").exists()) + def test_a_submodule_runs_no_clean_filter(self): + inner = tempfile.mkdtemp() + self.addCleanup(subprocess.run, ["rm", "-rf", inner]) + git(inner, "init", "-q", "-b", "main") + pathlib.Path(inner, "b.txt").write_text("b\n") + pathlib.Path(inner, ".gitattributes").write_text("b.txt filter=planted\n") + git(inner, "add", "-A") + git(inner, "commit", "-qm", "x", "--no-verify") + git(self.repo, "-c", "protocol.file.allow=always", "submodule", "add", "-q", inner, "sub") + git(self.repo, "commit", "-qm", "x", "--no-verify") + git(f"{self.repo}/sub", "config", "filter.planted.clean", f"touch {self.repo}/ran; cat") + os.utime(pathlib.Path(self.repo, "sub", "b.txt"), (1, 1)) + self.assertEqual(self.commit("git commit -m x").returncode, 0) + self.assertFalse(pathlib.Path(self.repo, "ran").exists()) + def test_a_checkout_with_no_commit_checks_its_index_and_untracked_files(self): fresh = tempfile.mkdtemp() self.addCleanup(subprocess.run, ["rm", "-rf", fresh]) -- 2.52.0