refactor(wikilinks): always store [[Title]] links as sentinels#1133
Merged
Conversation
[[Title]] wiki-links are now stored as wikilink:Title sentinels regardless of whether the target page already exists. Previously a single unambiguous match was stored as a resolved route path, causing inconsistencies across rename, move, and delete flows. Key changes: - helpers.go: single-match title lookups (pure and slash-fallback) now return wikilinkSentinel(target) instead of normalizeWikiPath(path) - links_store.go: GetRefactorSourcePageIDsForWikiLinkTitle finds source pages via sentinel to_path for use in rename refactoring - link_service.go: delegates new store method; HealWikiLinksForPage guards against ambiguous titles; adds HealWikiLinksForTitleIfUnambiguous - refactor.go: buildApplyPlan merges sentinel-based page IDs into affectedPageIDs on title-changing renames; getAffectedPages now also queries sentinel-based pages so the preview matches what apply does - link_effect.go: on title-changing slug updates, breaks stale wikilink:OldTitle sentinels via MarkIncomingLinksBrokenForPage then re-heals if OldTitle is still unambiguous; post-delete heal loop deduplicates by title to avoid redundant DB round-trips
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors title-based [[Title]] wiki-links to be stored uniformly as wikilink:Title sentinel to_path values (even when the target page exists), improving consistency across rename/move/delete flows and enabling reliable healing/refactoring of title-based links.
Changes:
- Store resolved
[[Title]]links aswikilink:Titlesentinels (instead of resolved route paths) during link extraction/resolution. - Extend refactor preview/apply to include pages referencing the old title via
wikilink:OldTitlesentinels so rename previews match apply behavior. - Update link indexing side effects and tests to correctly break/heal sentinel-based links during rename/delete scenarios.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| internal/wiki/pagesave/link_effect.go | Breaks/heals incoming links for rename/delete flows, including sentinel-based wikilink:* links. |
| internal/wiki/pages/refactor.go | Includes sentinel-based source pages in rename preview/apply affected sets so refactor coverage matches sentinel storage. |
| internal/wiki/pages/pages_test.go | Updates/refines refactor and delete tests to match sentinel storage and new heal/break semantics. |
| internal/links/links_store.go | Adds store query to find source pages referencing a specific wikilink:Title sentinel. |
| internal/links/link_service.go | Adds service wrapper, guards healing to only occur when a title is unambiguous, and adds “heal-if-unambiguous” helper. |
| internal/links/link_service_test.go | Adds test coverage for the new ambiguity guard behavior in HealWikiLinksForPage. |
| internal/links/helpers.go | Changes wiki-link target resolution to store wikilink:Title even for single unambiguous matches. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Cover the key behaviors of the sentinel refactoring: - Rename preview includes [[Title]] sentinel pages as affected pages with wiki-link syntax in matchedPaths (not raw route paths) - Rename apply with rewriteLinks rewrites [[Title]] to [[NewTitle]] - Rename refactor dialog shows [[Title]] page with correct matched path - Move preview shows path-hint [[folder/slug]] as affected page - Ambiguous [[Title]] shows 0 broken links in the link panel - Ambiguous [[Title]] appears as backlink for both matching pages - Delete dialog shows backlink warning for [[Title]] references
…og e2e test PageSaveEvent.Before was never set for update operations, making the title-change side effect in LinkIndexSideEffect dead code. Populate it so MarkIncomingLinksBrokenForPage and HealWikiLinksForTitleIfUnambiguous fire correctly on title-changing renames. Fix the e2e test that expected the refactor dialog to appear without triggering a manual save — auto-save skips slug changes by design, so the test must click the save button first.
Wait for the manual save button to become enabled before triggering the refactor dialog. Verify the rewritten wikilink against the stored page content instead of rendered article text so the assertion matches viewer behavior.
PageSaveEvent.Before for update events points to the live PageNode, which UpdateNode mutates in place — so Before.Title is the new title, not the old one. Remove Before from update events (satisfying the existing EventBeforeIsOmittedForLiveNodeSafety test), introduce an explicit OldTitle field that is captured before UpdateNode runs, and use After.ID (stable across renames) instead of Before.ID in the link effect. Add TestLinkIndexSideEffect_Rename_HealsPreexistingBrokenWikilinks to cover the scenario: pre-existing broken [[Alpha]] sentinels (ambiguous before the rename) are healed to the one remaining Alpha page once the renamed page exits the title.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
[[Title]] wiki-links are now stored as wikilink:Title sentinels regardless of whether the target page already exists. Previously a single unambiguous match was stored as a resolved route path, causing inconsistencies across rename, move, and delete flows.
Key changes: