Files
peter 4b6bc54aa8 test(db): stand up the DB-backed pytest lane (R6 S3b)
The suite was pure-logic only (R2 S2b deferred the DB lane). Add an opt-in `db`
fixture (tests/conftest.py) that hands a test a real session against an ephemeral
Postgres; schema is built with `alembic upgrade head` (the real prod schema needs
the unaccent extension + unaccent_simple TS config that create_all can't provide,
and this also proves the migration chain applies). Each test starts from a TRUNCATEd
clean DB so tests that COMMIT — the whole point, for R6 S2's transaction work —
don't leak.

backend/docker-compose.test.yml wires an ephemeral tmpfs pg + the test image. When
no Postgres is reachable (a plain `docker run`), the DB tests SKIP and the pure-logic
lane is unchanged: 172 passed, 2 skipped. With the DB: 174 passed.

test_db_lane.py smoke-proves commit round-trip + TRUNCATE isolation. The gate wiring
(siftlode.sh) lands in the ops repo.
2026-07-26 13:47:07 +02:00

22 lines
839 B
Python

"""Smoke test proving the DB-backed lane works (R6 S3b): a real commit round-trips, and each
test starts from a clean database (TRUNCATE isolation), which is what lets the transaction-
ownership tests (R6 S2) trust what they commit."""
from sqlalchemy import func, select
from app.models import User
def test_commit_roundtrips(db):
db.add(User(email="lane@example.com", role="admin"))
db.commit()
got = db.execute(select(User).where(User.email == "lane@example.com")).scalar_one()
assert got.id is not None
assert got.role == "admin"
assert got.is_active is True # server_default applied on flush/commit
def test_isolation_starts_clean(db):
# If the previous test's committed row leaked, this count would be 1 — TRUNCATE must reset it.
assert db.scalar(select(func.count()).select_from(User)) == 0