fix(521): catalog _anchor collapses punctuation runs; single trailing newline

_anchor() mapped each space/hyphen to its own '-' without collapsing runs,
so the standard heading separator " — " (space, em-dash, space) produced a
double hyphen in every generated anchor. Since nearly every real decision
record heading uses that separator, this made the catalog emit a dead link
for essentially every row. Fix: after building the char list, collapse
consecutive '-' into one and strip leading/trailing '-' via re.sub, matching
how Goldmark/GitHub/Gitea sluggers behave.

Also fixed main() writing an extra trailing newline (want already ends in
"\n", then "+ \n" appended a second one) so docs/decisions/README.md now
ends with exactly one trailing newline; --check still compares via .strip().

Added test_anchor_collapses_em_dash_and_keeps_underscore to pin the anchor
behavior against the reported iptv.base_url case.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-07-21 02:58:58 +02:00
co-authored by Claude Opus 4.8
parent 67619b2bf6
commit 458ab2111f
3 changed files with 14 additions and 6 deletions
-1
View File
@@ -8,4 +8,3 @@ the link for rationale. Superseded/retired history lives in `archive/`. Regenera
| Key | Current rule | Since | Record |
| --- | --- | --- | --- |
+7 -5
View File
@@ -7,6 +7,7 @@ CI job checks it is in sync.
from __future__ import annotations
import re
import sys
from pathlib import Path
@@ -27,16 +28,17 @@ def _rel(rec) -> str:
def _anchor(heading: str) -> str:
# Gitea/GitHub slugger: lowercase, keep alphanumerics + underscore, spaces/hyphens → '-',
# drop other punctuation. Keeping '_' matters — headings like "…(`iptv.base_url`)…" anchor to
# …iptvbase_url…. VERIFY against Gitea's actual output on 2-3 real headings before trusting links
# (the catalog is the startup surface; a dead link there is expensive).
# drop other punctuation, then collapse runs of '-' into one and trim leading/trailing '-'.
# Keeping '_' matters — headings like "…(`iptv.base_url`)…" anchor to …iptvbase_url….
# VERIFY against Gitea's actual output on 2-3 real headings before trusting links (the catalog
# is the startup surface; a dead link there is expensive).
out = []
for ch in heading.lower():
if ch.isalnum() or ch == "_":
out.append(ch)
elif ch in " -":
out.append("-")
return "".join(out)
return re.sub(r"-+", "-", "".join(out)).strip("-")
def render_catalog(records) -> str:
@@ -76,7 +78,7 @@ def main(argv=None) -> int:
return 1
print("build_decisions_catalog: catalog up to date")
return 0
OUTPUT.write_text(want + "\n", encoding="utf-8")
OUTPUT.write_text(want.rstrip("\n") + "\n", encoding="utf-8")
print(f"build_decisions_catalog: wrote {OUTPUT}")
return 0
+7
View File
@@ -37,3 +37,10 @@ def test_catalog_lists_only_active_sorted_by_key():
assert "Alpha rule" in out and "Zeta rule" in out
assert "old" not in out # superseded excluded
assert "GENERATED" in out # do-not-edit banner
def test_anchor_collapses_em_dash_and_keeps_underscore():
a = bc._anchor("2026-07-16 — Optional advertised IPTV base URL (`iptv.base_url`)…")
assert "--" not in a
assert a == "2026-07-16-optional-advertised-iptv-base-url-iptvbase_url"
assert not a.startswith("-") and not a.endswith("-")