fix(521): reciprocity covers archive<->archive pairs; skip topic-file Contents heading
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -17,7 +17,7 @@ from pathlib import Path
|
||||
|
||||
import scripts.decisions_lib as dl # noqa: E402 (run with PYTHONPATH=. or as module)
|
||||
|
||||
SKIP_HEADINGS = {"Index", "Active catalog"}
|
||||
SKIP_HEADINGS = {"Index", "Active catalog", "Contents"}
|
||||
REQUIRED_META = ("key", "status", "since", "supersedes", "superseded_by")
|
||||
EDIT_TOKEN = "[decisions-edit]" # noqa: S105 (a commit-message marker, not a credential)
|
||||
|
||||
@@ -77,11 +77,14 @@ def validate(
|
||||
if r.key:
|
||||
by_key[r.key] = r
|
||||
|
||||
# reciprocal supersession (successor may live in active OR archive)
|
||||
# reciprocal supersession (successor/predecessor may live in active OR archive). Runs over the
|
||||
# union of active + archive records so a twice-reversed decision (an archived record whose
|
||||
# superseded-by points to ANOTHER archived record) is checked from both sides too.
|
||||
for r in decision_recs:
|
||||
if r.status == "active" and r.superseded_by not in (None, "", "none"):
|
||||
errs.append(f"{r.heading}: active record cannot already be superseded (superseded-by set)")
|
||||
|
||||
for r in decision_recs + list(archive_records):
|
||||
sk = _key_of(r.superseded_by)
|
||||
if sk:
|
||||
if sk not in known_keys:
|
||||
|
||||
@@ -68,6 +68,23 @@ def test_reciprocal_supersession_correct_pair_passes():
|
||||
assert errs == []
|
||||
|
||||
|
||||
def test_archive_to_archive_reciprocal_pair_passes():
|
||||
# A twice-reversed decision: both records live in the archive wing, pointing at each other.
|
||||
a = _rec(heading="A", key="a.b", status="superseded", superseded_by="a.c@2026-07-01")
|
||||
b = _rec(heading="B", key="a.c", status="retired", supersedes="a.b@2026-07-01")
|
||||
errs = _v([], archive_records=[a, b], archive_keys={"a.b", "a.c"})
|
||||
assert errs == []
|
||||
|
||||
|
||||
def test_archive_to_archive_broken_back_link_fails():
|
||||
# A.superseded-by=B but B.supersedes=none → the back-link is broken, and neither side is active
|
||||
# (so this could previously only be caught by iterating archive_records, not decision_recs).
|
||||
a = _rec(heading="A", key="a.b", status="superseded", superseded_by="a.c@2026-07-01")
|
||||
b = _rec(heading="B", key="a.c", status="retired", supersedes="none")
|
||||
errs = _v([], archive_records=[a, b], archive_keys={"a.b", "a.c"})
|
||||
assert any("does not point back" in e and "a.c" in e for e in errs)
|
||||
|
||||
|
||||
def test_active_record_with_superseded_by_fails():
|
||||
recs = [_rec(key="a.b", status="active", superseded_by="a.c@2026-07-01")]
|
||||
assert any("active record cannot already be superseded" in e for e in _v(recs, archive_keys={"a.c"}))
|
||||
@@ -120,6 +137,29 @@ def test_demoted_heading_fails():
|
||||
)
|
||||
|
||||
|
||||
def test_contents_heading_is_skipped():
|
||||
# docs/decisions/*.md topic files use "## Contents" as their index heading (the analog of
|
||||
# decisions.md's "## Index") — it carries no metadata and must not be miscounted as a
|
||||
# legacy-unmigrated record, same as "Index" already isn't.
|
||||
assert "Contents" in dv.SKIP_HEADINGS
|
||||
|
||||
rec = dl.Record(
|
||||
heading="Contents",
|
||||
source=Path("x"),
|
||||
lineno=1,
|
||||
status="legacy-unmigrated",
|
||||
since=None,
|
||||
supersedes=None,
|
||||
superseded_by=None,
|
||||
)
|
||||
# validate() itself excludes SKIP_HEADINGS from decision_recs, so a bare Contents record
|
||||
# produces no errors (it isn't checked for required metadata, bad status, etc.)
|
||||
assert _v([rec]) == []
|
||||
# mirrors main()'s legacy-unmigrated count filter
|
||||
unmigrated = [r for r in [rec] if r.status == "legacy-unmigrated" and r.heading not in dv.SKIP_HEADINGS]
|
||||
assert unmigrated == []
|
||||
|
||||
|
||||
def _git(cwd: Path, *args: str) -> None:
|
||||
subprocess.run(["git", *args], cwd=cwd, check=True, capture_output=True, text=True)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user