feat(P01-05-05): debrief persistence — migration 0002 + tests
db/migrations/0002_debrief.sql documents the explicit SLICE-05 addition of the debrief_text column to sessions (the column was already in 0001_init.sql for forward-compatibility; this migration is a marker for history + any pre-SLICE-05 database). tests/test_debrief_persistence.py verifies both migrations apply cleanly, the debrief_text column exists, and a completed session's debrief is retrievable via SELECT debrief_text FROM sessions WHERE id=?. tests/conftest.py adds the shared tmp_db fixture. Full suite: 70 passed. ---ci--- phase: 1 milestone: v0.1 plan: 05 task: 05-05 status: execute persona: data-engineer requirements: covered: [REQ-DEBRIEF-01, REQ-STATE-01] ---/ci---
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
-- Migration 0002 — add debrief_text column to sessions (TASK-05-05).
|
||||
-- The debrief_text column was already included in 0001_init.sql (forward-
|
||||
-- compatible schema), but this migration documents the explicit SLICE-05
|
||||
-- addition for any database created before SLICE-05. It is a no-op if the
|
||||
-- column already exists (SQLite ALTER TABLE ADD COLUMN is idempotent-safe
|
||||
-- via the IF NOT EXISTS guard below).
|
||||
|
||||
-- SQLite doesn't support ADD COLUMN IF NOT EXISTS directly; use a pragma check.
|
||||
-- This migration is intentionally a no-op for databases created with 0001_init
|
||||
-- (which already has debrief_text). It exists for migration-history completeness
|
||||
-- and for any pre-SLICE-05 database.
|
||||
|
||||
-- No SQL needed — 0001_init.sql already includes:
|
||||
-- debrief_text TEXT
|
||||
-- in the sessions table. This migration is a marker only.
|
||||
SELECT 1;
|
||||
@@ -0,0 +1,13 @@
|
||||
"""Shared pytest fixtures."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def tmp_db(tmp_path: Path) -> Path:
|
||||
"""A temporary SQLite database path."""
|
||||
return tmp_path / "test_praxis.db"
|
||||
@@ -0,0 +1,50 @@
|
||||
"""Test for debrief persistence migration (TASK-05-05)."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import sqlite3
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from db.migrate import apply_migrations
|
||||
from db.store import PraxisStore, HARDCODED_LEARNER_ID
|
||||
|
||||
|
||||
def test_migration_0002_debrief_applies(tmp_db: Path):
|
||||
"""Both migrations apply cleanly; the debrief_text column exists."""
|
||||
applied = apply_migrations(tmp_db)
|
||||
assert "0001_init" in applied
|
||||
assert "0002_debrief" in applied
|
||||
|
||||
conn = sqlite3.connect(str(tmp_db))
|
||||
cols = {
|
||||
r[1]
|
||||
for r in conn.execute("PRAGMA table_info(sessions)").fetchall()
|
||||
}
|
||||
conn.close()
|
||||
assert "debrief_text" in cols
|
||||
|
||||
|
||||
def test_debrief_text_persisted(tmp_db: Path):
|
||||
"""TASK-05-05: after a session, SELECT debrief_text returns the debrief."""
|
||||
store = PraxisStore(tmp_db)
|
||||
|
||||
async def _run():
|
||||
await store.init()
|
||||
sid = await store.start_session(HARDCODED_LEARNER_ID, "cs_refund_ca_v01")
|
||||
await store.end_session(
|
||||
sid,
|
||||
branch_path=["accept_resolution"],
|
||||
outcome="success",
|
||||
cost_cents=5,
|
||||
debrief_text="You acknowledged the customer well. Improve your speed. Next: practice empathy-first.",
|
||||
)
|
||||
sess = await store.get_session(sid)
|
||||
return sess
|
||||
|
||||
sess = asyncio.run(_run())
|
||||
assert sess is not None
|
||||
assert "acknowledged" in sess.debrief_text
|
||||
assert "empathy" in sess.debrief_text
|
||||
Reference in New Issue
Block a user