Repository navigation
fix(adr): resolve three dangling cross-ADR anchors, and teach the guard to catch them - #1460
Conversation
Contracts coverageLine coverage: 89.92% (2615/2908 lines) |
Gas snapshotNo gas changes vs base. |
ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Free Run ID: 📒 Files selected for processing (6)
WalkthroughThe PR adds Markdown anchor-target validation for ADR references, integrates it into the ADR Makefile, pre-commit hook, and CI workflow, and updates several ADR cross-references and explanations. ChangesADR anchor validation
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant CI
participant Makefile
participant AnchorValidator
participant ADRSources
CI->>Makefile: run check-anchor-targets
Makefile->>AnchorValidator: scan ADRSources
AnchorValidator->>ADRSources: index headings and fragment links
ADRSources-->>AnchorValidator: Markdown headings and links
AnchorValidator-->>CI: pass or report invalid targets
Note 🎁 Summarized by CodeRabbit FreeYour organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://app.coderabbit.ai/login. Comment |
Coverage reportTotal: 81.01% (was 81.07%, ▼ 0.06%) — 52384/64660 lines No Rust files changed in this PR. History
|
4d544b2 to
b041248
Compare
All three land on the right file in a browser — GitHub ignores a fragment it cannot resolve and renders the top of the page — so they read as working links. `check-md-anchors` verifies a cross-ADR link *carries* an anchor, never that the anchor *resolves*, so none of them were catchable. - 008-reputation.md:14 `003-payments.md#adr-003-payments` -> `#adr-003-payment-model` (H1 is "ADR 003: Payment Model") - 008-reputation.md:115 `028-slashing-appeals.md#adr-028-slashing-appeals` -> `#adr-028-slashing-appeals-and-dispute-escalation` - 011-content-takedown.md:585 `013-wire-format.md#application-error-codes` -> `013-schema-evolution.md#...`; ADR 013 was renamed and this link kept the old filename, so the *file* is gone, not just the heading. The third was not in #1455's list: the resolver used there skipped link targets that do not exist on disk, which is exactly this case. Refs #1455 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_016qu8rLCARqtS4fbwsnoTRE
…ading `check-md-anchors` requires a cross-ADR link to carry a #anchor so that a retitled ADR breaks the link visibly. It only greps for links that have *no* anchor, so any fragment passes, resolving or not — the drift the rule exists to catch is the one thing it lets through. The new sibling guard builds a heading-slug index per target file and asserts every `file.md#anchor` (and same-file `#anchor`) names one of them. Retitling ADR 003's H1 on a clean tree now lists all 21 links that named the old anchor; `check-md-anchors` still reports "all ADR cross-links carry a #anchor" on that same tree. The resolver needs a per-file heading index, so it is one awk program over the whole set rather than a per-file grep like its siblings, and lives in _build/ for the same reason the lua filters do. Still basic tools only — awk, no perl/python — per the guards' standing constraint. Slugs follow GitHub's algorithm exactly, not an approximation: lowercase, drop every character that is not a letter/digit/underscore/space/hyphen, spaces to hyphens, with `-1`/`-2` suffixes for repeated headings and inline links in a heading reduced to their rendered text. The tree already depends on the double-hyphen a stripped character leaves behind (`#tier-1--minor-no-coordination`, `#cdnprobev1--latency-probe`), so an approximation would flag correct links. Verified: all 850 headings in the ADR set slug identically to [email protected], the library GitHub uses. LC_ALL=C keeps the character class byte-oriented so multibyte punctuation is stripped the same way under every awk; mawk and gawk agree exactly. Scope: fenced code blocks are skipped on both the link and heading side, as the sibling guards do, and non-.md targets (URLs, assets) are left alone. A link naming a file that does not exist is reported too. README.md is scanned here though it is not in SRCS_REF — it links into the ADRs and out to CONTRIBUTING.md with anchors that rot identically, while not following the ADR prose conventions the other guards police. Wired into `check-refs`, so the existing CI job and pre-commit hook pick it up; both path filters extended to _build/*.awk so editing the guard re-runs it. Closes #1455 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_016qu8rLCARqtS4fbwsnoTRE
b041248 to
1df22e7
Compare
Both parts of #1455: correct the anchors, then make the class of drift catchable.
Part 1 — the broken links
Three, not two. The third was outside #1455's list because the ad-hoc resolver used there skipped link targets that do not exist on disk — which is exactly this case.
adr/008-reputation.md:14003-payments.md#adr-003-payments#adr-003-payment-modeladr/008-reputation.md:115028-slashing-appeals.md#adr-028-slashing-appeals#adr-028-slashing-appeals-and-dispute-escalationadr/011-content-takedown.md:585013-wire-format.md#application-error-codes013-schema-evolution.md#application-error-codesThe third is a renamed file, not just a retitled heading: ADR 013 became
013-schema-evolution.mdand this link kept the old name. It reads as working for the same reason as the other two — GitHub ignores a fragment it cannot resolve — with the extra wrinkle that the file is gone too, so it 404s rather than landing on the wrong page.Part 2 —
check-anchor-targetsA sibling guard rather than an extension of
check-md-anchors: the existing target's contract ("carries an anchor") is still worth stating on its own, and the CI job keeps one step per guard so a failure names the rule it broke.It builds a heading-slug index per target file and asserts every
file.md#anchor— and every same-file#anchor— names one of them. Wired intocheck-refs, so the existing CI job and pre-commit hook pick it up; both path filters extended to_build/*.awkso editing the guard re-runs it.Red/green on a clean tree. Retitling ADR 003's H1 to
# ADR 003: Payments and Settlement:That is the failure mode the anchor rule exists to prevent, before and after.
On the two constraints flagged in the issue
Basic tools only. Pure awk, no perl/python. The resolver needs a per-file heading index, so it is one awk program over the whole set rather than a per-file grep like its siblings — which is why it lives in
adr/_build/check-anchor-targets.awkrather than as ~35 continuation lines in a recipe, the same reason the lua filters live there.GitHub's slug algorithm exactly, not an approximation. Lowercase, drop every character that is not a letter/digit/underscore/space/hyphen, spaces to hyphens — plus
-1/-2suffixes for repeated heading text, and inline links in a heading reduced to their rendered text (## Relationship to [ADR 002](…)slugs fromRelationship to ADR 002, not from the URL). The double-hyphen artifact the tree already depends on falls out of this rather than being special-cased: a stripped character leaves its surrounding spaces behind, so## Tier 1 — Minor (no coordination)→#tier-1--minor-no-coordinationand### `cdn/probe/v1` — latency probe→#cdnprobev1--latency-probe.Verified rather than asserted: all 850 headings in the ADR set slug identically to
[email protected], the library GitHub itself uses. Any systematic drift in the implementation would have surfaced as false positives on the ~1750 hand-authored links that currently resolve.LC_ALL=Ckeeps the character class byte-oriented so multibyte punctuation (—,→,§) is stripped the same way under every awk. mawk 1.3.4 (CI) and gawk agree exactly; the program is POSIX awk throughout, so BSD awk on macOS is covered too.Scope
.mdtargets — 2 URLs with fragments (rfc8446#section-8, an OpenZeppelin API anchor).README.mdis scanned here though it is not inSRCS_REF— it links into the ADRs and out toCONTRIBUTING.mdwith anchors that rot identically, while not following the ADR prose conventions the other guards police. Commented at theANCHOR_SRCSdefinition.Every skip is accounted for: 1756 anchor-bearing links in the set, minus 4 in fences, minus 2 URLs = 1750 checked.
Verification
make -C adr check-refs check-book-list— all four guards + book list green[email protected]across all 850 headings — identicalmarkdownlint-cli2 --config .markdownlint.yamlon both changed ADRs — 0 issues.github/workflows/ci.ymland.pre-commit-config.yamlparse; the widened hook regex verified against the paths it must and must not matchNot run: the pandoc/typst PDF builds (unchanged recipes, and the ADR CI job does not build them), and the Rust/Solidity suites (no
crates/**orcontracts/**change).Note for reviewers
The guard is strict about anchors that already exist in the tree, so an open docs PR that removes or retitles a heading will now fail this check instead of leaving a silent dangling link. Two in flight that touch anchor-bearing headings: #1447 (ADR 013 condensation —
013-schema-evolution.md#application-error-codesis a link target as ofmain) and #1456, which independently notes this same guard gap for#minimum-reputation-rejection-floor. That is the guard working as intended, but it is a rebase cost worth knowing about.Closes #1455
🤖 Generated with Claude Code
https://claude.ai/code/session_016qu8rLCARqtS4fbwsnoTRE
Generated by Claude Code
Summary by CodeRabbit
Documentation
Quality Improvements