Files
FabledGrimoire/tests/test_integration_task_kind_spike.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

101 lines
3.7 KiB
Python

"""Real-Postgres test that the CHECK actually accepts 'spike' (0091).
The value and the constraint can drift apart: the
code starts writing a new kind while the database still refuses it, and
nothing catches it until a write fails in front of someone. A mock cannot
show that — it has no CHECK — so the constraint gets its own real-DB test,
the same way migration 0090's nullability did.
The negative half matters as much as the positive one. A test that only
proves 'spike' is accepted would also pass against a table with NO
constraint at all, which is the other way this goes wrong.
"""
import pytest
import pytest_asyncio
from sqlalchemy.exc import IntegrityError
from grimoire.models import async_session
from grimoire.models.note import Note
from tests.helpers import ensure_user
pytestmark = [pytest.mark.integration, pytest.mark.usefixtures("_dispose_engine")]
@pytest_asyncio.fixture
async def owner_id():
async with async_session() as s:
owner = await ensure_user(s, "spike_owner")
uid = owner.id
await s.commit()
return uid
async def _write(uid: int, kind: str) -> int:
async with async_session() as s:
# No is_task=: it is a derived read-only property (a note IS a task
# when status is not None), so passing it raises rather than being
# ignored. status="todo" is what makes this a task.
note = Note(
user_id=uid, title=f"kind {kind}", body="",
status="todo", task_kind=kind,
)
s.add(note)
await s.commit()
return note.id
async def test_a_spike_can_be_written(owner_id):
note_id = await _write(owner_id, "spike")
async with async_session() as s:
assert (await s.get(Note, note_id)).task_kind == "spike"
async def test_the_older_kinds_still_write(owner_id):
"""0091 widens the whitelist; it must not narrow it by accident.
'plan' is retired — plans are milestones since 0066 — but historical
plan-tasks still carry it, and a row that cannot be rewritten is a row
that cannot be edited, restored, or migrated.
"""
for kind in ("work", "issue", "plan"):
note_id = await _write(owner_id, kind)
async with async_session() as s:
assert (await s.get(Note, note_id)).task_kind == kind
async def test_an_unknown_kind_is_still_refused(owner_id):
"""The half that proves a constraint is there at all.
Without this, every assertion above would pass just as happily against a
table whose CHECK had been dropped and never re-added — which is exactly
the drift this file is written against.
"""
with pytest.raises(IntegrityError):
await _write(owner_id, "investigation")
async def test_a_kind_can_be_corrected_after_the_fact(owner_id):
"""A kind is not write-once, asserted against a real column.
The read-back is the whole test. A version that only asserted the update
call succeeded would pass against a route that returns 200 while dropping
the field, which is a failure nothing else reports.
"""
from grimoire.services import notes as notes_svc
note_id = await _write(owner_id, "work")
await notes_svc.update_note(owner_id, note_id, task_kind="spike")
async with async_session() as s:
assert (await s.get(Note, note_id)).task_kind == "spike"
async def test_an_invalid_kind_is_refused_before_the_database(owner_id):
"""A readable ValueError, not a CheckViolationError surfacing as a 500."""
from grimoire.services import notes as notes_svc
note_id = await _write(owner_id, "work")
with pytest.raises(ValueError, match="Invalid kind"):
await notes_svc.update_note(owner_id, note_id, task_kind="investigation")
async with async_session() as s:
assert (await s.get(Note, note_id)).task_kind == "work"