fix(7736): #N in a body links to the record it names, not to a tag
CI & Build / TypeScript typecheck (push) Successful in 35s
CI & Build / Python lint (push) Successful in 2s
CI & Build / Plugin hooks (push) Successful in 14s
CI & Build / Python tests (push) Failing after 1m37s
CI & Build / integration (push) Successful in 2m11s
CI & Build / Build & push image (push) Skipped
CI & Build / TypeScript typecheck (push) Successful in 35s
CI & Build / Python lint (push) Successful in 2s
CI & Build / Plugin hooks (push) Successful in 14s
CI & Build / Python tests (push) Failing after 1m37s
CI & Build / integration (push) Successful in 2m11s
CI & Build / Build & push image (push) Skipped
A purely numeric #N is a record reference everywhere now. The tag patterns (frontend utils/tags.ts, the editor decoration, the first-line tag strip, tag autocomplete, backend utils/tags.py) leave digits alone, so #3127 is no longer drawn as a tag chip linking to /notes?tag=3127. - utils/recordRefs.ts links #N, milestone N and rule N in rendered markdown, with the same patterns and other-numbering word list as services/record_refs.py. A drift test reads the TS source and fails when the two differ. - v-record-refs (directives/recordRefs.ts) asks POST /api/notes/resolve-refs once per body for what each id is. A link gets the route for its kind (task, lesson, snippet, note, milestone, rule) and its kind and title on hover. One the reader cannot open is drawn as a dead reference, and missing vs not shared read the same. Applied on every surface that renders markdown. - /milestones/:id finds the project and opens its board at that milestone (?milestone= expands it, scrolls to it and focuses it). - Backlinks include records that cite #N in a body or a work log, through readable_notes_clause instead of an owner-only filter, and route by kind. The graph draws #N citations as dashed reference edges. - create_note, create_task and add_task_log say which forms link. There were no numeric tags to clean up: tags are stored only from the explicit field, and none of the 200 most used is numeric. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,106 @@
|
||||
"""Real-Postgres proof that a reference resolves only to what the reader may open, and that backlinks follow `#N`.
|
||||
|
||||
What mocks cannot show: the access clause applied in SQL to a shared project,
|
||||
the LIKE prefilter not admitting `#12` as a link to 1, and a citation in a work
|
||||
log reaching the cited record's backlinks.
|
||||
"""
|
||||
import pytest
|
||||
import pytest_asyncio
|
||||
|
||||
from grimoire.models import async_session
|
||||
from grimoire.models.milestone import Milestone
|
||||
from grimoire.models.note import Note
|
||||
from grimoire.models.project import Project
|
||||
from grimoire.models.share import ProjectShare
|
||||
from grimoire.models.task_log import TaskLog
|
||||
from grimoire.services.notes import get_backlinks
|
||||
from grimoire.services.record_refs import resolve_refs
|
||||
from tests.helpers import ensure_user
|
||||
|
||||
pytestmark = [pytest.mark.integration, pytest.mark.usefixtures("_dispose_engine", "_no_embedding")]
|
||||
|
||||
|
||||
@pytest_asyncio.fixture
|
||||
async def world():
|
||||
async with async_session() as s:
|
||||
owner = await ensure_user(s, "ref_links_owner")
|
||||
reader = await ensure_user(s, "ref_links_reader")
|
||||
stranger = await ensure_user(s, "ref_links_stranger")
|
||||
shared = Project(user_id=owner.id, title="Shared project")
|
||||
private = Project(user_id=owner.id, title="Private project")
|
||||
s.add_all([shared, private])
|
||||
await s.flush()
|
||||
s.add(ProjectShare(project_id=shared.id, shared_with_user_id=reader.id,
|
||||
permission="viewer", invited_by=owner.id))
|
||||
target = Note(user_id=owner.id, project_id=shared.id, title="Target", body="")
|
||||
hidden = Note(user_id=owner.id, project_id=private.id, title="Hidden", body="")
|
||||
lesson = Note(user_id=owner.id, project_id=shared.id, title="A lesson",
|
||||
body="", note_type="lesson")
|
||||
ms_shared = Milestone(user_id=owner.id, project_id=shared.id, title="Shared plan")
|
||||
ms_private = Milestone(user_id=owner.id, project_id=private.id, title="Private plan")
|
||||
s.add_all([target, hidden, lesson, ms_shared, ms_private])
|
||||
await s.flush()
|
||||
ids = {
|
||||
"owner": owner.id, "reader": reader.id, "stranger": stranger.id,
|
||||
"shared": shared.id, "target": target.id, "hidden": hidden.id,
|
||||
"lesson": lesson.id, "ms_shared": ms_shared.id, "ms_private": ms_private.id,
|
||||
}
|
||||
await s.commit()
|
||||
return ids
|
||||
|
||||
|
||||
async def test_the_owner_resolves_every_kind_with_its_route_fields(world):
|
||||
out = await resolve_refs(
|
||||
world["owner"],
|
||||
notes=[world["target"], world["lesson"], world["hidden"]],
|
||||
milestones=[world["ms_shared"], world["ms_private"]],
|
||||
)
|
||||
assert set(out["notes"]) == {world["target"], world["lesson"], world["hidden"]}
|
||||
assert out["notes"][world["lesson"]]["note_type"] == "lesson"
|
||||
assert out["notes"][world["target"]]["is_task"] is False
|
||||
assert out["milestones"][world["ms_shared"]]["project_id"] == world["shared"]
|
||||
|
||||
|
||||
async def test_a_collaborator_resolves_the_shared_project_and_nothing_else(world):
|
||||
out = await resolve_refs(
|
||||
world["reader"],
|
||||
notes=[world["target"], world["hidden"]],
|
||||
milestones=[world["ms_shared"], world["ms_private"]],
|
||||
)
|
||||
assert set(out["notes"]) == {world["target"]}
|
||||
assert set(out["milestones"]) == {world["ms_shared"]}
|
||||
|
||||
|
||||
async def test_unreadable_and_nonexistent_ids_read_the_same(world):
|
||||
"""Absent either way, so the resolver cannot be used to probe for ids."""
|
||||
out = await resolve_refs(world["stranger"], notes=[world["target"], 2_000_000_000])
|
||||
assert out["notes"] == {}
|
||||
|
||||
|
||||
async def test_backlinks_follow_references_in_bodies_and_work_logs(world):
|
||||
t = world["target"]
|
||||
async with async_session() as s:
|
||||
citing = Note(user_id=world["owner"], project_id=world["shared"],
|
||||
title="Cites it", body=f"Builds on #{t}.")
|
||||
logged = Note(user_id=world["owner"], project_id=world["shared"],
|
||||
title="Logs it", body="", status="todo")
|
||||
other_space = Note(user_id=world["owner"], project_id=world["shared"],
|
||||
title="Other numbering", body=f"See PR #{t}.")
|
||||
longer = Note(user_id=world["owner"], project_id=world["shared"],
|
||||
title="Longer id", body=f"See #{t}0.")
|
||||
s.add_all([citing, logged, other_space, longer])
|
||||
await s.flush()
|
||||
s.add(TaskLog(task_id=logged.id, user_id=world["owner"], content=f"Fixed with #{t} in mind."))
|
||||
ids = {"citing": citing.id, "logged": logged.id}
|
||||
await s.commit()
|
||||
|
||||
rows = await get_backlinks(world["owner"], t)
|
||||
by_id = {r["id"]: r for r in rows}
|
||||
assert set(by_id) == {ids["citing"], ids["logged"]}
|
||||
assert by_id[ids["citing"]]["via"] == "reference"
|
||||
assert by_id[ids["logged"]]["is_task"] is True
|
||||
|
||||
# The collaborator sees the same backlinks, since every record is in the
|
||||
# project shared with them; a stranger cannot open the target at all.
|
||||
assert {r["id"] for r in await get_backlinks(world["reader"], t)} == set(by_id)
|
||||
assert await get_backlinks(world["stranger"], t) == []
|
||||
Reference in New Issue
Block a user