feat(7834): issues linked to the file being written arrive before anything found by meaning
CI & Build / TypeScript typecheck (push) Successful in 37s
CI & Build / Plugin hooks (push) Successful in 12s
CI & Build / Python lint (push) Successful in 2s
CI & Build / Python tests (push) Successful in 2m53s
CI & Build / integration (push) Successful in 2m7s
CI & Build / Build & push image (push) Successful in 30s
CI & Build / TypeScript typecheck (push) Successful in 37s
CI & Build / Plugin hooks (push) Successful in 12s
CI & Build / Python lint (push) Successful in 2s
CI & Build / Python tests (push) Successful in 2m53s
CI & Build / integration (push) Successful in 2m7s
CI & Build / Build & push image (push) Successful in 30s
Before a write, the write path now looks up issues by structure: - an issue whose body or a log names the file (any status: a closed one is the record of what was already tried there); - an open issue tagged to an area whose path patterns cover the file. At most two, listed first, withheld from the search by meaning, which fills only what is left and only past the gate. Measured under write_path_linked. The lookups follow the kind x moment table: no issue lookup when issues are off at work.change, no nearby-snippet lookup when snippets are. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
"""Real-Postgres tests for `record_links.issues_for_path`: an issue naming the
|
||||
file in its body or a log comes first; an open issue in the file's area comes
|
||||
next; a closed one there, another project's and a plain task are
|
||||
left out, as is everything for a reader without access; and a path is
|
||||
matched literally."""
|
||||
import pytest
|
||||
|
||||
from grimoire.models import async_session
|
||||
from grimoire.models.note import Note
|
||||
from grimoire.models.project import Project
|
||||
from grimoire.models.system import RecordSystem, System
|
||||
from grimoire.models.task_log import TaskLog
|
||||
from grimoire.services import record_links
|
||||
from tests.helpers import ensure_user
|
||||
|
||||
pytestmark = [pytest.mark.integration, pytest.mark.usefixtures("_dispose_engine")]
|
||||
|
||||
PATH = "src/app/lock_guard.py"
|
||||
|
||||
|
||||
async def _world():
|
||||
async with async_session() as s:
|
||||
owner = await ensure_user(s, "record_links_owner")
|
||||
stranger = await ensure_user(s, "record_links_stranger")
|
||||
project = Project(user_id=owner.id, title="record links project")
|
||||
other = Project(user_id=owner.id, title="record links other")
|
||||
s.add_all([project, other])
|
||||
await s.flush()
|
||||
area = System(user_id=owner.id, project_id=project.id, name="locks",
|
||||
path_patterns=["src/app/**"])
|
||||
s.add(area)
|
||||
await s.flush()
|
||||
|
||||
def issue(title, status="done", body="", pid=project.id, uid=owner.id, kind="issue"):
|
||||
return Note(user_id=uid, project_id=pid, title=title, status=status,
|
||||
task_kind=kind, body=body)
|
||||
|
||||
made = {
|
||||
"in_body": issue("names it in its body", body=f"fixed in {PATH}"),
|
||||
"in_log": issue("names it in a log"),
|
||||
"open_area": issue("open in the area", status="todo"),
|
||||
"closed_area": issue("closed in the area"),
|
||||
"other_project": issue("other project", body=f"see {PATH}", pid=other.id),
|
||||
"work_task": issue("a work task naming it", body=f"edit {PATH}", kind="work"),
|
||||
# `_` is a single-character wildcard to LIKE; matched literally it
|
||||
# must not stand in for the `_` in the path.
|
||||
"near_miss": issue("a near miss", body="src/app/lockXguard.py"),
|
||||
}
|
||||
s.add_all(made.values())
|
||||
await s.flush()
|
||||
s.add(TaskLog(task_id=made["in_log"].id, user_id=owner.id, content=f"touched {PATH}"))
|
||||
s.add_all(RecordSystem(note_id=made[k].id, system_id=area.id)
|
||||
for k in ("open_area", "closed_area"))
|
||||
await s.commit()
|
||||
ids = {k: n.id for k, n in made.items()}
|
||||
return owner.id, project.id, ids, stranger.id
|
||||
|
||||
|
||||
async def test_issues_naming_the_file_come_first_then_open_ones_in_its_area():
|
||||
uid, pid, ids, _stranger = await _world()
|
||||
found = await record_links.issues_for_path(uid, pid, PATH, limit=5)
|
||||
got = [(link, int(n.id)) for link, n in found]
|
||||
named = {i for link, i in got if link == record_links.NAMES_FILE}
|
||||
assert named == {ids["in_body"], ids["in_log"]}
|
||||
assert got[:2] == [(link, i) for link, i in got if link == record_links.NAMES_FILE]
|
||||
assert (record_links.OPEN_IN_AREA, ids["open_area"]) in got
|
||||
left_out = {"closed_area", "other_project", "work_task", "near_miss"}
|
||||
assert not {ids[k] for k in left_out} & {i for _l, i in got}
|
||||
|
||||
|
||||
async def test_the_limit_and_the_exclusions_hold():
|
||||
uid, pid, ids, stranger = await _world()
|
||||
assert len(await record_links.issues_for_path(uid, pid, PATH, limit=1)) == 1
|
||||
found = await record_links.issues_for_path(
|
||||
uid, pid, PATH, limit=5, exclude={ids["in_body"], ids["in_log"]},
|
||||
)
|
||||
assert [int(n.id) for _l, n in found] == [ids["open_area"]]
|
||||
assert await record_links.issues_for_path(uid, 0, PATH, limit=5) == []
|
||||
# A reader who cannot read the project is shown none of its issues.
|
||||
assert await record_links.issues_for_path(stranger, pid, PATH, limit=5) == []
|
||||
Reference in New Issue
Block a user