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:
@@ -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