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
+19 -20
View File
@@ -1,15 +1,11 @@
import dataclasses
import functools
import pathlib
import posixpath
import re
import typing
from review_rules.round_titles import CAP, COUNTS, EXAMPLE, lacks_counts, OPENING, RELEASE_REVIEW_CAP
from project_config.main import commit_title
from git_cli.git_command import commits
from git_cli.git_command import CommitCall
from run_heavy.capped_docker import finds_this_docker
from git_cli.git_repo import git
from rule_hook.heavy_command import heavy
from command_lines.shell_command import launched, Simple
from review_rules.review_folder import REPORTS
@@ -37,8 +33,8 @@ RULES: dict[RuleName, Rule] = {
"git commit takes its message as one -m with no line break; -F, a second -m and a heredoc are blocked",
),
"commit-title": Rule(
"a commit's title fits the `commit-title` template the project's config names, such as `PAY-{id} - {summary}`, so the project's log reads as its owners write it",
"the -m of a git commit in a checkout whose config sets `commit-title`; a round title's `Answer <pass> round <n>:` is the template's {summary}",
"a commit's title fits the `commit-title` template the project's config names, such as `[{id}] {summary}`, so the project's log reads as its owners write it",
"the -m of a git commit in a checkout whose config sets `commit-title`, on a branch that fits the config's `branch` template; on any other branch, as for a chunk with no plan item, the title may be the bare summary. A round title, from `Answer <pass> round <n>:` to its end, is the template's {summary}. While the config cannot be read, every commit is blocked",
),
"docker-run-memory": Rule(
"a container made with docker run or docker create has a memory limit and a swap limit, as large as its work needs, such as `--memory 4g --memory-swap 4g`, so a runaway container fails alone instead of starving the machine; a swap limit equal to the memory limit keeps it out of swap",
@@ -156,9 +152,8 @@ def check(breaches: list[Breach], written: str, markdown: bool, bash: bool) -> C
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]:
def command_breaches(command: str, simples: list[Simple]) -> list[Breach]:
breaches = []
found = commits(simples, home)
publishing = [simple for simple in simples if posixpath.basename(simple.words[0]) in ("chunk-pr", "gh", "git", "tea")]
if publishing and ATTRIBUTION.search(command):
breaches.append(Breach("no-ai-attribution", "the command carries an attribution", publishing[0].directory))
@@ -167,17 +162,21 @@ def command_breaches(command: str, simples: list[Simple], home: str) -> list[Bre
breaches.append(Breach("run-heavy", f"run `{' '.join(simple.words)[:80]}` under `~/.claude/bin/run-heavy`, in the background", simple.directory))
if unlimited_container(simple.words):
breaches.append(Breach("docker-run-memory", f"give `{' '.join(simple.words)[:80]}` a memory limit and a swap limit as large as its work needs", simple.directory))
for commit in found:
if commit.from_file:
breaches.append(Breach("commit-one-line", "pass the message as one -m '<line>', not from a file", commit.directory))
elif len(commit.messages) > 1 or any("\n" in message.strip() for message in commit.messages):
breaches.append(Breach("commit-one-line", "pass the message as one -m '<line>', with no heredoc, second -m or newline", commit.directory))
template = commit_title(commit.directory, pathlib.Path(home), functools.partial(git, guarded=True))
# A message of several lines breaks commit-one-line above, which says how to fix it.
if misfit := [message for message in commit.messages[:1] if "\n" not in message.strip() and not templates.fits(template, message.strip())]:
breaches.append(Breach("commit-title", f"title the commit as the project's config asks, `{template}`, where {{id}} is the ID of the chunk's first item; `{misfit[0].strip()[:80]}` doesn't fit", commit.directory))
if any(lacks_counts(templates.summary_of(template, message.strip())) for message in commit.messages):
breaches.append(Breach("round-title-counts", f"open the summary after the round's colon with `{COUNTS}`, where <j> is at most <k> + <m>", commit.directory))
return breaches
def title_breaches(commit: CommitCall, titles: templates.Titles, held: bool) -> list[Breach]:
"""The breaches of the commit's message, read through titles, the project's title templates. held is whether the title must fit the commit template: it must on a branch that fits the config's `branch` template."""
breaches = []
if commit.from_file:
breaches.append(Breach("commit-one-line", "pass the message as one -m '<line>', not from a file", commit.directory))
elif len(commit.messages) > 1 or any("\n" in message.strip() for message in commit.messages):
breaches.append(Breach("commit-one-line", "pass the message as one -m '<line>', with no heredoc, second -m or newline", commit.directory))
# A message of several lines breaks commit-one-line above, which says how to fix it.
if held and (misfit := [message for message in commit.messages[:1] if "\n" not in message.strip() and not templates.fits(titles.commit, message.strip())]):
breaches.append(Breach("commit-title", f"title the commit as the project's config asks, `{titles.commit}`, where {{id}} is the ID of the chunk's first item; `{misfit[0].strip()[:80]}` doesn't fit", commit.directory))
if any(lacks_counts(titles.summary(message.strip())) for message in commit.messages):
breaches.append(Breach("round-title-counts", f"open the summary after the round's colon with `{COUNTS}`, where <j> is at most <k> + <m>", commit.directory))
return breaches