fix(wiki): resolve links by title before an earlier page's alias#545
fix(wiki): resolve links by title before an earlier page's alias#545rsnetworkinginc wants to merge 1 commit into
Conversation
_link_index registered each page's title, id and alias in a single pass, so setdefault made link resolution depend on list_pages() order: a page holding a name only as an alias could shadow the page actually titled it when it sorted first. [[Retry Policy]] then resolved to the wrong page and its backlink landed on the alias holder in the render-wiki map-of-content, contradicting the module's promise that an alias never shadows a title. build the index in tiers instead — every title, then every id/slug, then every alias — so a real title always wins regardless of ordering. within a tier the earlier page still wins a genuine title-title collision. adds a regression test covering resolve_link and backlinks with an alias holder sorted ahead of the titled page.
WalkthroughWiki link indexing now prioritizes page titles over ids, slugs, and aliases. Tests cover resolution and backlinks when an earlier alias conflicts with a later page title, and the changelog documents the fix. ChangesWiki link title precedence
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
tests/test_wiki_render.py (1)
89-106: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winextend the regression matrix to every affected consumer.
This covers the alias/title failure through
resolve_link()andbacklinks(), but the pr also claims title precedence over ids/slugs and behavior throughrender_moc(). Add one conflicting id/slug case and arender_moc()assertion so those guarantees are protected too.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/test_wiki_render.py` around lines 89 - 106, Extend test_title_beats_an_earlier_pages_alias_regardless_of_order to cover title precedence over a conflicting page id/slug, asserting resolve_link() selects the titled page. Add a render_moc() assertion using the same conflict to verify rendered links resolve to the titled page, while preserving the existing alias and backlinks coverage.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@tests/test_wiki_render.py`:
- Around line 89-106: Extend
test_title_beats_an_earlier_pages_alias_regardless_of_order to cover title
precedence over a conflicting page id/slug, asserting resolve_link() selects the
titled page. Add a render_moc() assertion using the same conflict to verify
rendered links resolve to the titled page, while preserving the existing alias
and backlinks coverage.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 0abeda2c-3290-4b0b-a936-92d944d39c2f
📒 Files selected for processing (3)
CHANGELOG.mdsrc/vouch/wiki_render.pytests/test_wiki_render.py
fix(wiki): resolve links by title before an earlier page's alias
what
wiki_render._link_indexbuilt its name → page map in a single pass per page,registering each page's title, id and aliases together and relying on
setdefaultfor collisions. that made link resolution depend on the orderstore.list_pages()happens to return: if a page carrying a name only as analias sorted ahead of the page actually titled that name, the alias won.
concretely, with a page titled "Retry Policy" and an unrelated "Backoff Notes"
page listing "Retry Policy" as an alias,
[[Retry Policy]]resolved to"Backoff Notes", and in the
vouch render-wikimap-of-content the inboundbacklink for that reference landed on the alias holder instead of the titled
page. the module docstring already promised the opposite ("a later page's
alias never shadows an existing page's title") — the implementation just
didn't guarantee it independent of list order.
why / fix
resolution priority should be a property of the kind of handle (title beats
id/slug beats alias), not of iteration order. the index is now built in tiers:
every page's title first, then every id/slug, then every alias, each with
setdefault. a real title therefore always wins over another page's aliasregardless of ordering; within a single tier the earlier page still wins a
genuine title-title collision, preserving the existing behaviour there.
the change is confined to the pure
_link_indexhelper — a derived,regenerable view (never a gated write), so no object-model,
kb.*method,on-disk layout, bundle or audit-log surface is touched.
resolve_link,backlinksandrender_mocall pick up the corrected precedence.regression test
tests/test_wiki_render.py::test_title_beats_an_earlier_pages_alias_regardless_of_orderputs the alias holder ahead of the titled page and asserts both
resolve_linkandbacklinksfollow the title. it fails on the pre-fix code(
resolve_linkreturns the alias holder) and passes after.validation
ran the full gate against the
testbase (python 3.11,.[dev,web]):python -m pytest tests/ -q --ignore=tests/embeddings— 1662 passed, 37 skippedpython -m mypy src— success, no issues in 103 source filespython -m ruff check src tests— all checks passedassert resolved is titled; with the fix applied it passes.changelog
added under
## [Unreleased]→### Fixed.note
no filed issue tracks this — it was found by exercising the new
wiki_rendermodule directly against current
test(HEAD 285bf79). no linked issue, so noClosesline.Summary by CodeRabbit