Merge remote-tracking branch 'origin/main' into item-387

This commit is contained in:
2026-11-17 08:55:05 +01:00
18 changed files with 248 additions and 37 deletions
+2 -1
View File
@@ -57,6 +57,7 @@ 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
from rule_hook.round_cap import round_cap_breaches
from rule_hook.round_report import round_report_breaches
from command_lines.shell_command import simple_commands
from project_config import templates
from rule_hook.todo_check import todo_breaches
@@ -142,7 +143,7 @@ def commit_breaches(commit: CommitCall, home: pathlib.Path) -> list[Breach]:
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) + 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) + todo_breaches(commit.directory, home)
def checkout_branch(directory: str) -> str | None:
+30
View File
@@ -0,0 +1,30 @@
"""rule-hook's check of a round commit's counts against the round's report in the chunk's review folder."""
import pathlib
from rule_hook.rules import Breach
from git_cli.git_command import CommitCall
from failure import Failure
from review_rules.review_folder import findings_in, review_folder, standing_report
from git_cli.git_repo import git
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]:
"""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]
if not rounds:
return []
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()))
breaches = []
for named, counts in rounds:
pass_, round_ = named.group(1).lower(), int(named.group(2))
report = standing_report(folder, pass_, round_)
found = findings_in(report)
if not isinstance(found, Failure) and found != counts:
breaches.append(Breach("round-title-counts", f"{report} counts `{round_prefix(pass_, round_, found)}`; open the title's summary with that, which `larv-review round-title {pass_}` prints", commit.directory))
return breaches
+1 -1
View File
@@ -84,7 +84,7 @@ RULES: dict[RuleName, Rule] = {
),
"round-title-counts": Rule(
f"a larv-review round's commit title gives the counts of 🔴 and 🟡 findings the round reported, and how many of them a reviewer marked `[misread]`, at most the two together, such as `{EXAMPLE}`, since score-outcomes counts them",
f"a git commit whose message opens `{OPENING}`",
f"a git commit whose message opens `{OPENING}`; its counts are checked against the round's report in the chunk's review folder, where that report exists",
),
"run-heavy": Rule(
"a heavy command, which loads the machine for minutes, runs under ~/.claude/bin/run-heavy, so sessions running at once cannot starve the machine",
+26
View File
@@ -1055,6 +1055,32 @@ class Hook(unittest.TestCase):
def round_commit(self, title: str, given: str = "") -> subprocess.CompletedProcess:
return hook({"cwd": self.repo, "tool_input": {"command": f"git commit {given}-m '{title}'"}, "tool_name": "Bash"}, self.repo)
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.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")
def commit(title: str) -> subprocess.CompletedProcess:
return hook({"cwd": self.repo, "tool_input": {"command": f"git commit -m '{title}'"}, "tool_name": "Bash"}, self.repo, {"HOME": home})
wrong = commit("Answer stability round 1: 1 🔴, 2 🟡 (0 misread); fix")
self.assertEqual(wrong.returncode, 2)
self.assertIn(f"Blocked by rule round-title-counts: {folder}/stability-round-1.md counts `Answer stability round 1: 1 🔴, 1 🟡 (1 misread);`", wrong.stderr)
self.assertEqual(commit("Answer stability round 1: 1 🔴, 1 🟡 (1 misread); fix").returncode, 0)
self.assertEqual(commit("Answer prose round 1: 0 🔴, 3 🟡 (0 misread); fix").returncode, 0, "a round whose report is missing goes through")
self.assertEqual(commit("Answer stability round 1: 1 🔴, 2 🟡 (0 misread); fix # rule-override round-title-counts: the reviewer wrote its findings as a list").returncode, 0)
self.assertEqual(commit("Answer Stability round 1: 1 🔴, 2 🟡 (0 misread); fix").returncode, 2, "a capitalised pass reads its report")
elsewhere = tempfile.mkdtemp()
self.addCleanup(subprocess.run, ["rm", "-rf", elsewhere])
moved = hook({"cwd": elsewhere, "tool_input": {"command": f"git -C {self.repo} commit -m 'Answer stability round 1: 1 🔴, 2 🟡 (0 misread); fix'"}, "tool_name": "Bash"}, elsewhere, {"HOME": home})
self.assertEqual(moved.returncode, 2, "the report is the commit's checkout's, not the hook's working directory's")
outside = hook({"cwd": elsewhere, "tool_input": {"command": "git commit -m 'Answer stability round 1: 1 🔴, 2 🟡 (0 misread); fix'"}, "tool_name": "Bash"}, elsewhere, {"HOME": home})
self.assertEqual((outside.returncode, outside.stderr), (0, ""), "outside a checkout no report is read")
(folder / "stability-round-1-rerun.md").write_text("BLOCK\n\n### 🔴 `a.py:1`: wrong\n\n### 🟡 `b.py:2`: worse\n\n### 🟡 `c.py:3`: worse\n")
self.assertEqual(commit("Answer stability round 1: 1 🔴, 2 🟡 (0 misread); fix").returncode, 0, "the rerun's report stands in place of the round's")
def test_a_round_commit_past_round_2_is_refused_and_offers_no_override(self):
ran = self.round_commit("Answer stability round 3: 0 🔴, 1 🟡 (0 misread); fix # rule-override round-cap: the human said yes")
self.assertEqual(ran.returncode, 2)