Answer stability round 1: 1 🔴, 6 🟡 (0 misread); read every title through both templates, hold a title to its template only on an item's branch, and fail on a config fault

This commit is contained in:
2026-11-14 01:47:41 +01:00
parent 1692679985
commit f98e8a84dd
42 changed files with 537 additions and 256 deletions
+54 -4
View File
@@ -14,7 +14,8 @@ import unittest.mock
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
from rule_hook.repeat_read import Asked, modified, read_breaches, result_lines
from rule_hook.rules import blocks, Breach, check, command_breaches, file_breaches, overrides, RuleName, RULES
from project_config.templates import BARE, Titles
from rule_hook.rules import blocks, Breach, check, command_breaches, file_breaches, overrides, RuleName, RULES, title_breaches
from rule_hook.main import breaches_of
from rule_hook.call import Call, parsed_call
from git_cli.git_command import commit_message, CommitCall, commits
@@ -40,8 +41,14 @@ def committed(command: str, cwd: str = "/r") -> list[CommitCall]:
return commits(simple_commands(command, cwd, "/h"), "/h")
def breaches(command: str, titles: Titles = BARE, held: bool = False) -> list[Breach]:
"""The command's breaches and those of each commit's title, read through titles; held is whether the title must fit the commit template."""
simples = simple_commands(command, "/r", "/h")
return command_breaches(command, simples) + [breach for commit in commits(simples, "/h") for breach in title_breaches(commit, titles, held)]
def checked(command: str) -> list[str]:
return rules(command_breaches(command, simple_commands(command, "/r", "/h"), "/h"))
return rules(breaches(command))
def hook(call: dict, cwd: str, env: dict[str, str] | None = None) -> subprocess.CompletedProcess:
@@ -112,7 +119,7 @@ class CommandBreaches(unittest.TestCase):
self.assertEqual(checked("git commit -m 'Answer stability round 1: fix the parser'"), ["round-title-counts"])
self.assertEqual(checked("git commit -m 'Answer stability round 1: 1 🔴, 2 🟡; fix the parser'"), ["round-title-counts"])
command = "git commit -m 'Answer stability round 1: fix the parser'"
self.assertEqual(command_breaches(command, simple_commands(command, "/r", "/h"), "/h"), [Breach("round-title-counts", "open the summary after the round's colon with `<k> 🔴, <m> 🟡 (<j> misread);`, where <j> is at most <k> + <m>", "/r")])
self.assertEqual(breaches(command), [Breach("round-title-counts", "open the summary after the round's colon with `<k> 🔴, <m> 🟡 (<j> misread);`, where <j> is at most <k> + <m>", "/r")])
self.assertEqual(checked("git commit --allow-empty -m 'Answer prose round 2: 0 🔴, 0 🟡 (0 misread)'"), [])
self.assertEqual(checked("git commit -m 'Answer stability round 1: 1 🔴, 2 🟡 (1 misread); fix the parser'"), [])
self.assertEqual(checked("git commit -m 'Answer the question in the README'"), [])
@@ -143,7 +150,20 @@ class CommandBreaches(unittest.TestCase):
self.assertEqual(checked(f"grep -rn '{TRAILER}' ."), [])
def test_a_commit_breach_names_the_commit_s_checkout(self):
self.assertEqual(command_breaches("cd w && git commit -m a -m b", simple_commands("cd w && git commit -m a -m b", "/r", "/h"), "/h")[0].directory, "/r/w")
self.assertEqual(breaches("cd w && git commit -m a -m b")[0].directory, "/r/w")
def test_a_title_must_fit_the_commit_template_only_where_the_branch_holds_it_to_it(self):
titles = Titles("PAY-{id} - {summary}", "{summary}")
self.assertEqual(breaches("git commit -m 'Release review of 0.3.0'", titles, held=True), [Breach("commit-title", "title the commit as the project's config asks, `PAY-{id} - {summary}`, where {id} is the ID of the chunk's first item; `Release review of 0.3.0` doesn't fit", "/r")])
self.assertEqual(breaches("git commit -m 'Release review of 0.3.0'", titles), [])
self.assertEqual(breaches("git commit -m 'PAY-7 - Tidy'", titles, held=True), [])
def test_a_round_title_is_read_through_either_template_for_its_counts(self):
titles = Titles("PAY-{id} - {summary}", "fix: {summary}")
for title in ("PAY-7 - Answer prose round 1: fix", "fix: Answer prose round 1: fix", "Answer prose round 1: fix"):
with self.subTest(title):
self.assertEqual(rules(breaches(f"git commit -m '{title}'", titles)), ["round-title-counts"])
self.assertEqual(breaches("git commit -m 'PAY-7 - Answer prose round 1: 0 🔴, 0 🟡 (0 misread)'", titles, held=True), [])
class FileBreaches(unittest.TestCase):
@@ -1029,6 +1049,7 @@ class Hook(unittest.TestCase):
def test_a_commit_is_titled_by_the_configs_template_and_its_round_title_read_through_it(self):
config = configured(self, pathlib.Path(self.repo)) / "config.toml"
config.write_text(config.read_text() + 'commit-title = "PAY-{id} - {summary}"\n')
git(self.repo, "checkout", "-q", "-b", "item-7")
for title in ["PAY-7 - Answer stability round 1: 1 🔴, 0 🟡 (0 misread); a", "PAY-7 - Answer stability round 2: 0 🔴, 1 🟡 (0 misread); c"]:
git(self.repo, "commit", "-q", "--allow-empty", "-m", title)
past = self.round_commit("PAY-7 - Answer stability round 2: 0 🔴, 0 🟡 (0 misread); d")
@@ -1041,6 +1062,35 @@ class Hook(unittest.TestCase):
self.assertEqual(self.round_commit("PAY-7 - Answer prose round 1: 0 🔴, 0 🟡 (0 misread); x").returncode, 0)
self.assertEqual(self.round_commit("Tidy # rule-override commit-title: the client asked for this title").returncode, 0)
def test_a_commit_on_a_branch_that_doesnt_fit_the_configs_branch_template_takes_a_bare_title(self):
config = configured(self, pathlib.Path(self.repo)) / "config.toml"
config.write_text(config.read_text() + 'commit-title = "PAY-{id} - {summary}"\nbranch = "feature/PAY-{id}"\n')
git(self.repo, "checkout", "-q", "-b", "release-review-0.3.0")
self.assertEqual(self.round_commit("Release review of 0.3.0", "--allow-empty ").returncode, 0)
self.assertIn("Blocked by rule round-title-counts", self.round_commit("PAY-7 - Answer prose round 1: fix").stderr)
git(self.repo, "checkout", "-q", "-b", "feature/PAY-7")
held = self.round_commit("Release review of 0.3.0", "--allow-empty ")
self.assertEqual(held.returncode, 2)
self.assertIn("Blocked by rule commit-title: title the commit as the project's config asks, `PAY-{id} - {summary}`", held.stderr)
self.assertEqual(self.round_commit("PAY-7 - Tidy").returncode, 0)
def test_a_commit_is_refused_naming_the_fault_while_a_config_cannot_be_read(self):
config = configured(self, pathlib.Path(self.repo)) / "config.toml"
config.write_text(config.read_text() + 'commit-title = "PAY-{id}"\n')
refused = self.round_commit("PAY-7 - Tidy")
self.assertEqual(refused.returncode, 2)
self.assertIn("Blocked by rule commit-title: the project's config cannot be read, so the title is not checked against its template: ", refused.stderr)
self.assertIn("`commit-title` is 'PAY-{id}'", refused.stderr)
config.write_text(config.read_text().replace('commit-title = "PAY-{id}"\n', ""))
other = config.parents[1] / "other" / "config.toml"
other.parent.mkdir()
other.write_text("checkout = [")
refused = self.round_commit("Tidy")
self.assertEqual(refused.returncode, 2)
self.assertIn(f"cannot read {other}", refused.stderr)
other.unlink()
self.assertEqual(self.round_commit("Tidy").returncode, 0)
def test_a_commit_while_an_unranked_todo_has_changes_is_blocked(self):
configured(self, pathlib.Path(self.repo))
pathlib.Path(self.repo, "docs").mkdir()