diff --git a/scripts/check_architecture_docs.py b/scripts/check_architecture_docs.py index a9a17768..c7147cb0 100644 --- a/scripts/check_architecture_docs.py +++ b/scripts/check_architecture_docs.py @@ -1,6 +1,7 @@ """Offline architecture links and public-interface review gate; see docs/ARCHITECTURE.md.""" import argparse import ast +import os import re import subprocess import sys @@ -21,9 +22,9 @@ } -def git(root, *args): +def git(root, *args, text=True): return subprocess.run(["git", *args], cwd=root, check=True, - capture_output=True, text=True).stdout + capture_output=True, text=text).stdout def interface(text, names): @@ -75,8 +76,10 @@ def link_errors(root): def check(root, base): git(root, "rev-parse", "--verify", f"{base}^{{commit}}") - changed = set(git(root, "diff", "--name-only", "-z", base).split("\0")) - changed.update(git(root, "ls-files", "--others", "--exclude-standard", "-z").split("\0")) + tracked = git(root, "diff", "--name-only", "-z", base, text=False) + untracked = git(root, "ls-files", "--others", "--exclude-standard", "-z", text=False) + changed = set(os.fsdecode(tracked).split("\0")) + changed.update(os.fsdecode(untracked).split("\0")) watched = changed.intersection(WATCHED) watched.update(p for p in changed if p.startswith(".github/workflows/")) for name, names in INTERFACES.items(): diff --git a/src/loopzero/cli.py b/src/loopzero/cli.py index 20b73319..a18c4994 100644 --- a/src/loopzero/cli.py +++ b/src/loopzero/cli.py @@ -220,7 +220,7 @@ def _pr_markers(reviews: list[dict], head: str, if not eligibility.review_projection(review, head, repo, number)[0] and any( runners.codex_fatal_startup(item) for item in eligibility.review_envelopes(body)[1]): continue - match = REVIEW_MARKER_RE.search(body) + match = eligibility.leading_marker(body) if not match or review.get("commit_id") != match.group(1): continue if not trusted: @@ -894,8 +894,9 @@ def _confirm_review(wt: Path, config: Config, pr: github.PR, result: ReviewResul publisher: str, reviews: list[dict]) -> bool: """Confirm an exact live publication; absence authorizes no automatic write.""" trusted = config.review_publishers or (publisher,) - evidence = [r for r in reviews if "loopzero:review" in (r.get("body") or "") and (r.get("commit_id") == result.head or any( - m.group(1) == result.head for m in REVIEW_MARKER_RE.finditer(r["body"])))] + evidence = [r for r in reviews if "loopzero:review" in (r.get("body") or "") and ( + r.get("commit_id") == result.head + or ((marker := eligibility.leading_marker(r["body"])) and marker.group(1) == result.head))] fresh = github.pr_view(config.repo, pr.number) if fresh.head_sha != result.head or fresh.state != "OPEN" or fresh.base_ref != pr.base_ref: raise CliError("PR changed during publication recovery") diff --git a/src/loopzero/eligibility.py b/src/loopzero/eligibility.py index 981c0bed..4de8fb3d 100644 --- a/src/loopzero/eligibility.py +++ b/src/loopzero/eligibility.py @@ -18,6 +18,14 @@ CONTEXT = "Loop-zero Eligibility" +def leading_marker(body: str) -> re.Match[str] | None: + """The review marker opening the publisher's leading machine block; prose never counts.""" + block, span = runners.leading_review_block(body if isinstance(body, str) else "") + if not block or len(REVIEW_MARKER_RE.findall(span)) != 1: + return None + return REVIEW_MARKER_RE.fullmatch(block[0]) + + def review_envelopes(body: str) -> tuple[str, list[dict]]: """Decode only the publisher's raw-output block, not quoted findings/prose.""" if not isinstance(body, str): @@ -40,7 +48,7 @@ def review_projection(review: dict, head: str, repo: str, number: int): block, span = runners.leading_review_block(body) positions = [i for i, line in enumerate(block) if line.lstrip().startswith("