Files
FabledGrimoire/tests/test_services_notes_process.py
bvandeusenandClaude Opus 5.5 0f5ef0be63
CI & Build / Python lint (push) Successful in 3s
CI & Build / Plugin hooks (push) Successful in 12s
CI & Build / TypeScript typecheck (push) Successful in 56s
CI & Build / integration (push) Successful in 1m4s
CI & Build / Python tests (push) Successful in 1m55s
CI & Build / Build & push image (push) Successful in 44s
rename(547): the server is grimoire — package, image, DB defaults, backups
Step 2 of the Scribe -> Grimoire rename.

- src/scribe -> src/grimoire, and every import, patch target, module path,
  hypercorn entry point and `python -m grimoire.restore` with it; pyproject,
  uv.lock and the frontend package are named grimoire.
- Image git.fabledsword.com/bvandeusen/fabledgrimoire; CI's Postgres service
  runs as grimoire / grimoire_test.
- Compose files default the DB user, database and (prod) volume to grimoire,
  each overridable from .env, so an install created as Scribe keeps its data
  by setting POSTGRES_USER, POSTGRES_DB and PGDATA_VOLUME.
- Backups are written as grimoire-<ts>.tar with format grimoire-backup-tar.
  Archives named scribe-* with the scribe-backup-tar manifest still restore
  and are still counted at the destination (folder and S3), with tests.
- Exports, the MCP auth realm, the ASGI scope key and the persistent logger
  carry the new name.

Kept on purpose: the secret-sealing key label stays "scribe.secrets.v1",
because every stored secret was derived under it.

Plugin identity (plugin name, hooks, env vars, .scribe marker, skills) is
step 3.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-22 10:50:45 -04:00

75 lines
2.9 KiB
Python

"""resolve_process precedence (id → exact title → substring) in services/notes.py.
Mocks async_session — no real DB, matching the other notes-service tests.
"""
from unittest.mock import AsyncMock, MagicMock, patch
import pytest
from tests.helpers import fake_note, make_mock_session
def _result(first=None, all_=None):
"""A SQLAlchemy-result mock exposing .scalars().first()/.all()."""
r = MagicMock()
r.scalars.return_value.first.return_value = first
r.scalars.return_value.all.return_value = all_ or []
return r
@pytest.mark.asyncio
async def test_resolve_process_by_numeric_id():
note = fake_note(id=5, title="Drift Audit")
session = make_mock_session()
# numeric id → first execute (id lookup) hits
session.execute = AsyncMock(side_effect=[_result(first=note)])
with patch("grimoire.services.notes.async_session") as cls:
cls.return_value = session
from grimoire.services.notes import resolve_process
found, candidates = await resolve_process(1, "5")
assert found is note
assert candidates == []
assert session.execute.await_count == 1
@pytest.mark.asyncio
async def test_resolve_process_exact_title_beats_substring():
note = fake_note(id=7, title="Drift Audit")
session = make_mock_session()
# non-digit → exact-title query (first execute) hits; substring never runs
session.execute = AsyncMock(side_effect=[_result(first=note)])
with patch("grimoire.services.notes.async_session") as cls:
cls.return_value = session
from grimoire.services.notes import resolve_process
found, candidates = await resolve_process(1, "Drift Audit")
assert found is note
assert candidates == []
assert session.execute.await_count == 1
@pytest.mark.asyncio
async def test_resolve_process_substring_returns_candidates():
n1 = fake_note(id=7, title="Drift Audit Remediation")
n2 = fake_note(id=9, title="Drift Audit Notes")
session = make_mock_session()
# exact miss, then substring returns two (most-recent first)
session.execute = AsyncMock(side_effect=[_result(first=None), _result(all_=[n1, n2])])
with patch("grimoire.services.notes.async_session") as cls:
cls.return_value = session
from grimoire.services.notes import resolve_process
found, candidates = await resolve_process(1, "drift")
assert found is n1
assert candidates == [{"id": 9, "title": "Drift Audit Notes"}]
assert session.execute.await_count == 2
@pytest.mark.asyncio
async def test_resolve_process_no_match():
session = make_mock_session()
session.execute = AsyncMock(side_effect=[_result(first=None), _result(all_=[])])
with patch("grimoire.services.notes.async_session") as cls:
cls.return_value = session
from grimoire.services.notes import resolve_process
found, candidates = await resolve_process(1, "nope")
assert found is None
assert candidates == []