links: rename repoints inbound backlinks (fix orphaning)
Renaming a note now rewrites [[Old Title]] references (and their note_links rows) in every note that links to it, so backlinks survive the rename instead of silently orphaning. Pure/case-only renames are skipped since they still resolve. New pure helper rewrite_link_title() (DB-free unit tests) does the token rewrite; _rename_inbound_links() applies it across owner-scoped, non-trashed sources. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FRgehjoz7Yv8LkUfADxACm
This commit is contained in:
+12
-1
@@ -2,7 +2,7 @@ import pytest
|
||||
|
||||
from thoughtsync.app import create_app
|
||||
from thoughtsync.models.note import NOTE_COLORS, Note
|
||||
from thoughtsync.notes import is_empty_note, normalize_color, parse_link_titles
|
||||
from thoughtsync.notes import is_empty_note, normalize_color, parse_link_titles, rewrite_link_title
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@@ -86,6 +86,17 @@ def test_parse_link_titles_empty():
|
||||
assert parse_link_titles("no links here") == []
|
||||
|
||||
|
||||
def test_rewrite_link_title():
|
||||
body = "see [[Alpha]] and [[ alpha ]] and [[Beta]]"
|
||||
assert rewrite_link_title(body, "alpha", "Gamma") == "see [[Gamma]] and [[Gamma]] and [[Beta]]"
|
||||
|
||||
|
||||
def test_rewrite_link_title_noop():
|
||||
assert rewrite_link_title("", "alpha", "Gamma") == ""
|
||||
assert rewrite_link_title(None, "alpha", "Gamma") == ""
|
||||
assert rewrite_link_title("no links here", "alpha", "Gamma") == "no links here"
|
||||
|
||||
|
||||
async def test_titles_requires_auth(app):
|
||||
client = app.test_client()
|
||||
resp = await client.get("/api/notes/titles")
|
||||
|
||||
Reference in New Issue
Block a user