links: rename repoints inbound backlinks (fix orphaning)
CI & Build / Python lint (push) Successful in 2s
CI & Build / TypeScript typecheck (push) Successful in 5s
CI & Build / Python tests (push) Successful in 7s
CI & Build / Build & push image (push) Successful in 29s

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:
2026-07-20 11:26:49 -04:00
co-authored by Claude Opus 4.8
parent 9be8920362
commit f3145a5e3f
2 changed files with 57 additions and 1 deletions
+12 -1
View File
@@ -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")