From 365b0f82a665738294db6d83e3025be06425ee3c Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Wed, 28 Oct 2026 18:10:57 +0100 Subject: [PATCH] =?UTF-8?q?Answer=20stability=20round=201:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=203=20=F0=9F=9F=A1=20(0=20misread);=20pin=20the?= =?UTF-8?q?=20guarded=20default-branch=20reads=20and=20which=20commit=20an?= =?UTF-8?q?=20amend=20drops,=20and=20name=20the=20pass=20and=20its=20count?= =?UTF-8?q?ed=20commits=20in=20the=20refusal?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/git_repo.py | 2 +- bin/rule_hook/round_cap.py | 15 ++++++++++----- bin/rule_hook/test_rule_hook.py | 17 +++++++++++++++-- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/bin/git_repo.py b/bin/git_repo.py index 882aef17..7d667967 100644 --- a/bin/git_repo.py +++ b/bin/git_repo.py @@ -71,7 +71,7 @@ def default_ref(cwd: str | None = None, timeout: float | None = None, guarded: b recorded = git("symbolic-ref", "--short", "refs/remotes/origin/HEAD", cwd=cwd, guarded=guarded) if not isinstance(recorded, Failure): return recorded.strip() - return Failure("origin records no default branch; set it with `git remote set-head origin --auto`") if guarded else origin_head(cwd, timeout) + return Failure("origin records no default branch") if guarded else origin_head(cwd, timeout) for branch in ("main", "master"): if not isinstance(git("rev-parse", "--quiet", "--verify", f"refs/heads/{branch}", cwd=cwd, guarded=guarded), Failure): return branch diff --git a/bin/rule_hook/round_cap.py b/bin/rule_hook/round_cap.py index 7c5b55f4..ad6f1c36 100644 --- a/bin/rule_hook/round_cap.py +++ b/bin/rule_hook/round_cap.py @@ -1,5 +1,5 @@ from rule_hook.rules import Breach -from round_titles import CAP, past_cap, ROUND +from round_titles import CAP, past_cap, ROUND, round_counts from git_command import Commit from failure import Failure import git_repo @@ -10,13 +10,18 @@ def round_cap_breaches(commit: Commit) -> list[Breach]: if not any(ROUND.match(message) for message in commit.messages): return [] earlier = earlier_titles(commit.directory, commit.amends) - if not any(past_cap(message, earlier) for message in commit.messages): - return [] - return [Breach("round-cap", f"the pass has had its {CAP} rounds; merge once the gate passes, with no round after them", commit.directory)] + return [Breach("round-cap", refusal(named.group(1).lower(), message, earlier), commit.directory) for message in commit.messages if (named := ROUND.match(message)) and past_cap(message, earlier)] + + +def refusal(name: str, title: str, earlier: list[str]) -> str: + """Why title, a round title of the pass name, is refused, listing the pass's round commits counted, and how to commit the fixes in hand.""" + counted = [earlier_title for earlier_title in earlier if (named := ROUND.match(earlier_title)) and named.group(1).lower() == name] + listed = ", ".join(f"`{counted_title}`" for counted_title in counted) or "none" + return f"this would be {name}'s round {round_counts([*counted, title])[name]}, past its {CAP}; {name}'s round commits on this branch: {listed}. Fold the fixes into its last round commit with `git commit --amend`, or commit them under a title that doesn't open `Answer round`; they merge once the gate passes" def earlier_titles(directory: str, amends: bool) -> list[str]: - """The branch's titles, less the one an --amend replaces; none where git cannot tell in time, so the title's own number still counts. + """The branch's titles, less the one an --amend replaces; none where git cannot list them within 5 seconds or the checkout records no default branch for origin, so the title's own number still counts. Run guarded, as the hook runs git, which neither fetches nor asks origin: the default branch is as last fetched.""" default = git_repo.default_ref(directory, guarded=True) diff --git a/bin/rule_hook/test_rule_hook.py b/bin/rule_hook/test_rule_hook.py index f8bf6a73..03678826 100644 --- a/bin/rule_hook/test_rule_hook.py +++ b/bin/rule_hook/test_rule_hook.py @@ -662,16 +662,29 @@ class Hook(unittest.TestCase): 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) - self.assertIn("Blocked by rule round-cap", ran.stderr) + self.assertIn("Blocked by rule round-cap: this would be stability's round 3, past its 2", ran.stderr) self.assertNotIn("rule-override", ran.stderr) self.assertEqual(self.round_commit("Answer stability round 2: 0 🔴, 1 🟡 (0 misread); fix").returncode, 0) def test_a_third_round_commit_of_a_pass_on_the_branch_is_refused_whatever_its_number(self): for title in ["Answer stability round 1: 1 🔴, 0 🟡 (0 misread); a", "Answer prose round 1: 0 🔴, 1 🟡 (0 misread); b", "Answer stability round 2: 0 🔴, 1 🟡 (0 misread); c"]: git(self.repo, "commit", "-q", "--allow-empty", "-m", title) - self.assertEqual(self.round_commit("Answer stability round 2: 0 🔴, 0 🟡 (0 misread); d").returncode, 2) + ran = self.round_commit("Answer stability round 2: 0 🔴, 0 🟡 (0 misread); d") + self.assertEqual(ran.returncode, 2) + self.assertIn("stability's round commits on this branch: `Answer stability round 2: 0 🔴, 1 🟡 (0 misread); c`, `Answer stability round 1: 1 🔴, 0 🟡 (0 misread); a`", ran.stderr) + self.assertIn("`git commit --amend`", ran.stderr) self.assertEqual(self.round_commit("Answer prose round 2: 0 🔴, 0 🟡 (0 misread); d").returncode, 0) self.assertEqual(self.round_commit("Answer stability round 2: 0 🔴, 1 🟡 (0 misread); c, reworded", "--amend --allow-empty ").returncode, 0, "an amend replaces the commit it counts") + git(self.repo, "commit", "-q", "--allow-empty", "-m", "fix a typo") + self.assertEqual(self.round_commit("Answer stability round 2: 0 🔴, 1 🟡 (0 misread); e", "--amend --allow-empty ").returncode, 2, "an amend replaces the newest commit, not the oldest") + + def test_a_stalled_origin_holds_up_neither_a_round_commit_nor_the_overrides_listing(self): + git(self.repo, "config", "protocol.ext.allow", "always") + git(self.repo, "remote", "add", "origin", "ext::sleep 30") + self.assertEqual(self.round_commit("Answer stability round 1: 0 🔴, 1 🟡 (0 misread); a").returncode, 0) + hook({"cwd": self.repo, "tool_input": {"command": "git commit -m a -m b # rule-override commit-one-line: a body is needed"}, "tool_name": "Bash"}, self.repo) + listed = subprocess.run([str(HOOK), "overrides"], capture_output=True, check=True, cwd=self.repo, env=isolated_env(), text=True, timeout=10).stdout + self.assertIn("\tcommit-one-line\ta body is needed\t", listed) def test_round_commits_merged_in_from_the_default_branch_do_not_count(self): git(self.repo, "checkout", "-q", "main")