fix(609): review fixes — exclude merge commits, unfold folded values, correct the fail-posture doc
Cross-family review (High + Medium + Low), all three reproduced before fixing: High -- on a pull_request event actions/checkout lands on a synthetic merge commit whose body the forge composes from the PR description, so a description ending in an example marker armed a guard no author armed. Excluded merge commits from the range; merging main into a PR branch is separately forbidden, so no author-written commit is skipped. Medium -- a folded value (`no` + continuation ` yes`) was split into independent lines and the continuation armed on its own, inverting the value the author wrote. Read with `unfold` so the value is judged whole. Low -- the module docstring promised fail-open while marker resolution deliberately fails closed. The posture is right; the docstring was wrong. Documented as the one exception. Both new negative controls verified red against the unfixed matcher. Decision record amended to state the residual honestly rather than overclaim: a quoted example that is the FINAL paragraph of an ordinary commit is a trailer by git's own grammar and does arm. What the change buys is that discussing the marker can no longer disable anything. fixes #609 Decisions-Edit: yes Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -4,8 +4,9 @@
|
||||
Replaces the line-level append-only guard (ersatztv#303 H9) with lifecycle checks that preserve its
|
||||
spirit — rationale is never silently rewritten or deleted; every history touch is deliberate and
|
||||
reviewable. A `Decisions-Edit: yes` commit trailer is kept ONLY for rationale-prose edits; routine
|
||||
lifecycle metadata writes are token-free. Fail-open on tooling trouble (missing refs, git errors,
|
||||
parse issues), matching the old guard.
|
||||
lifecycle metadata writes are marker-free. Fail-open on tooling trouble (missing refs, git errors,
|
||||
parse issues), matching the old guard — with ONE deliberate exception: resolving the edit marker
|
||||
itself fails CLOSED (`_edit_trailer_armed`), because a fail-open marker lookup is just #609 again.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -267,16 +268,27 @@ def _edit_trailer_armed(mb: str, head: str) -> bool:
|
||||
marker must be an explicit yes, so a trailer written to *record that no edit was intended* can
|
||||
never disable the guard — the ersatztv#609 failure mode, one abstraction level up.
|
||||
|
||||
Git errors return False (the guard stays ON), matching the rest of the fail-safe posture here:
|
||||
a lost marker costs a contributor one clear error message, a lost guard costs silent history
|
||||
rewrites in the one PR that most needed policing.
|
||||
This is the one git helper here that deliberately does NOT fail open (see the module docstring):
|
||||
on a git error it returns False, leaving the guard ON. A lost marker costs a contributor one
|
||||
clear error message and a re-push; a lost guard costs a silent history rewrite in the PR that
|
||||
most needed policing. Failing open here would reintroduce #609 through a different door.
|
||||
|
||||
`--no-merges` skips merge commits: on a `pull_request` event `actions/checkout` lands on a
|
||||
synthetic merge commit whose body is composed by the forge, not by the author, so a trailer
|
||||
parsed out of it was never a deliberate marker. Merging main into a PR branch is separately
|
||||
forbidden (`.husky/pre-push` → `prepush-rebase-check.sh`), so no author-written commit is lost.
|
||||
|
||||
`unfold` joins RFC-822 continuation lines before the value is compared. Without it, a folded
|
||||
`Decisions-Edit: no\\n yes` yields two lines and the continuation ` yes` arms the exemption on
|
||||
its own — the value the author actually wrote is `no`.
|
||||
"""
|
||||
out = _run(["git", "log", f"--format=%(trailers:key={EDIT_TRAILER},valueonly)", f"{mb}..{head}"])
|
||||
fmt = f"--format=%(trailers:key={EDIT_TRAILER},valueonly,unfold)"
|
||||
out = _run(["git", "log", "--no-merges", fmt, f"{mb}..{head}"])
|
||||
if out is not None and any(ln.strip().lower() in _EDIT_TRAILER_AFFIRMATIVE for ln in out.splitlines()):
|
||||
return True
|
||||
# Retired-form nudge: without it, a contributor using the pre-#609 habit gets a bare "prose
|
||||
# changed" failure and no hint that the marker's FORM (not their intent) is what changed.
|
||||
if _LEGACY_EDIT_TOKEN in (_run(["git", "log", "--format=%B", f"{mb}..{head}"]) or "").lower():
|
||||
if _LEGACY_EDIT_TOKEN in (_run(["git", "log", "--no-merges", "--format=%B", f"{mb}..{head}"]) or "").lower():
|
||||
print(
|
||||
f"::warning::decisions-validate: the commit range carries the retired "
|
||||
f"{_LEGACY_EDIT_TOKEN} marker but no '{EDIT_TRAILER}: yes' trailer — since ersatztv#609 "
|
||||
|
||||
@@ -339,6 +339,48 @@ def test_diff_engine_negative_trailer_value_does_not_arm(tmp_path, monkeypatch):
|
||||
assert _RECORD in rewritten
|
||||
|
||||
|
||||
def test_diff_engine_folded_trailer_continuation_does_not_arm(tmp_path, monkeypatch):
|
||||
"""A folded value must be judged whole: `no` + continuation ` yes` is the value "no yes".
|
||||
|
||||
Without `unfold`, git emits the continuation as its own line and ` yes`.strip() arms the
|
||||
exemption on its own — inverting the author's explicit `no`.
|
||||
"""
|
||||
_removed, rewritten = _rewrite_repo(tmp_path, monkeypatch, "rewrite rationale", "Decisions-Edit: no\n yes")
|
||||
assert _RECORD in rewritten
|
||||
|
||||
|
||||
def test_diff_engine_merge_commit_body_does_not_arm(tmp_path, monkeypatch):
|
||||
# On a pull_request event, actions/checkout lands on a synthetic merge commit whose body the
|
||||
# forge composes (quoting the PR description) — a trailer parsed out of it is not an author's
|
||||
# deliberate marker, so merge commits are excluded from the range.
|
||||
repo = tmp_path / "repo"
|
||||
(repo / "docs").mkdir(parents=True)
|
||||
_git(tmp_path, "init", str(repo))
|
||||
_git(repo, "config", "user.email", "t@example.com")
|
||||
_git(repo, "config", "user.name", "T")
|
||||
_write_decisions(repo / "docs" / "decisions.md", status="active", since="2026-01-01", rationale="Original prose.")
|
||||
_git(repo, "add", "-A")
|
||||
_git(repo, "commit", "-m", "base")
|
||||
|
||||
monkeypatch.chdir(repo)
|
||||
base = subprocess.run(
|
||||
["git", "rev-parse", "HEAD"], cwd=repo, check=True, capture_output=True, text=True
|
||||
).stdout.strip()
|
||||
|
||||
_git(repo, "checkout", "-q", "-b", "feature")
|
||||
_write_decisions(repo / "docs" / "decisions.md", status="active", since="2026-01-01", rationale="Reworded prose.")
|
||||
_git(repo, "add", "-A")
|
||||
_git(repo, "commit", "-m", "rewrite rationale") # the author never armed anything
|
||||
|
||||
# the forge's synthetic merge, whose body quotes a PR description ending in an example marker
|
||||
_git(repo, "checkout", "-q", base)
|
||||
_git(repo, "merge", "--no-ff", "-q", "feature", "-m", "Merge pull request #1", "-m", "Decisions-Edit: yes")
|
||||
|
||||
removed, rewritten, *_rest = dv._diff_findings(base, "HEAD")
|
||||
assert removed == []
|
||||
assert _RECORD in rewritten
|
||||
|
||||
|
||||
def test_diff_engine_retired_bracket_token_no_longer_arms(tmp_path, monkeypatch):
|
||||
# the pre-#609 habit (token appended to the subject) is retired, not silently honored.
|
||||
_removed, rewritten = _rewrite_repo(tmp_path, monkeypatch, "rewrite rationale [decisions-edit]")
|
||||
@@ -359,7 +401,7 @@ def test_diff_engine_detects_appended_smuggled_rationale(tmp_path, monkeypatch):
|
||||
monkeypatch.chdir(repo)
|
||||
|
||||
# append-shape exploit: original prose line is PRESERVED, a smuggled **Rule:** paragraph is
|
||||
# appended after a blank line, no [decisions-edit] token. The old buggy _rationale() strips
|
||||
# appended after a blank line, no edit marker on the commit. The old buggy _rationale() strips
|
||||
# ANY `**Rule:**`/`**Signals:**`/`**Mechanics:**`/`` `key:`` line wherever it appears, so it
|
||||
# silently strips the appended line too → base==head → bypass succeeds. The bounded strip only
|
||||
# removes the contiguous top metadata block, so the appended paragraph survives as prose →
|
||||
|
||||
Reference in New Issue
Block a user