Give "record", "outcome" and "places" one meaning each across bin/, and rename larv_review/git.py by what it holds

This commit is contained in:
2026-10-23 10:42:06 +02:00
parent 9df08bd41e
commit 8d2a1cf9fd
16 changed files with 152 additions and 135 deletions
+2 -2
View File
@@ -37,7 +37,7 @@ import time
import typing
from rule_hook.call import applied, Call, FILE_TOOLS, parsed_call, text
from rule_hook.rules import Breach, command_breaches, file_breaches, Outcome, rules_help, verdict
from rule_hook.rules import Breach, Checked, command_breaches, file_breaches, rules_help, verdict
from git_command import commits
from failure import Failure
from rule_hook.override_log import Log, log_path, logged, print_overrides, write_override
@@ -85,7 +85,7 @@ def breaches_of(call: Call, home: str, environ: typing.Mapping[str, str]) -> tup
return added, path, report_breaches(call, path, home) + file_breaches(path, before, added, after)
def answer(judged: Outcome, what: str, now: float) -> int:
def answer(judged: Checked, what: str, now: float) -> int:
for message in judged.messages:
print(message, file=sys.stderr)
if judged.blocked:
+4 -3
View File
@@ -88,7 +88,8 @@ class Breach:
@dataclasses.dataclass(frozen=True)
class Outcome:
class Checked:
"""What rule-hook found in one tool call: the messages to show, whether it blocks the call, and the overrides to log."""
messages: list[str]
blocked: bool
# Each breach an override let through, with its reason; logged only when the call goes through.
@@ -102,7 +103,7 @@ def overrides(written: str) -> tuple[dict[str, str], list[str]]:
return granted, [f"rule-override {rule}: {reason}" for rule, reason in given if rule not in RULES or not reason]
def verdict(breaches: list[Breach], written: str, markdown: bool, bash: bool) -> Outcome:
def verdict(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]
messages = [f"`{marker}` names no rule below, or gives no reason." for marker in malformed] if blocking else []
@@ -114,7 +115,7 @@ def verdict(breaches: list[Breach], written: str, markdown: bool, bash: bool) ->
continue
marker = f"<!-- rule-override {rule}: <reason> -->" if markdown else f"# rule-override {rule}: <reason>"
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 Outcome(messages, bool(blocking), [(breach, granted[breach.rule]) for breach in breaches if breach.rule in granted])
return Checked(messages, bool(blocking), [(breach, granted[breach.rule]) for breach in breaches if breach.rule in granted])
def command_breaches(command: str, simples: list[Simple], home: str) -> list[Breach]: