Files
PTSRaiAgent/tests/test_contracts.py
ElebobaandClaude Opus 5.5 4c0836a1be
CI / ruff · pytest (pull_request) Successful in 1m11s
feat(backend): monitoring service — snapshot, rules, alerts, status colour, clock persistence
- app/services/snapshot.py: PatientSnapshot from the clinical DB (field mapping, age, therapy day,
  recent C-SSRS risk, weapon access from dialog facts)
- app/services/monitoring.py: RuleMonitoring registered via register_monitoring; persists alert/crisis
  actions, crisis_acute audit, enhanced_monitoring flag, cached status_color, notifies the doctor (and
  the doctor on duty for crises) after commit; a running crisis is not restarted
- demo clock offset persisted in clock_state, restored on scheduler start
- tests: Andrey's 13 days through the service → G G G Y Y G G G G Y Y Y R

Refs #38

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-04 03:13:57 +03:00

32 lines
1.3 KiB
Python

from fastapi.testclient import TestClient
from app.db import session
from app.db.bootstrap import init_db
from app.dialog.contracts import Event, get_engine
from app.main import app
from app.services.contracts import get_monitoring
MEM = "sqlite+aiosqlite:///:memory:"
async def test_stubs_are_usable() -> None:
await session.configure(identity_url=MEM, clinical_url=MEM)
await init_db()
try:
replies = await get_engine().handle("tok", Event(type="text", text="привет"))
assert replies and replies[0].text
assert await get_monitoring().after_data_change("tok") == [] # unknown patient → no actions
assert await get_monitoring().is_in_crisis("tok") is False
finally:
await session.configure()
def test_api_fixture_routes() -> None:
with TestClient(app) as c:
patients = c.get("/api/v1/doctors/doc-smirnova/patients").json()
assert patients[0]["status_color"] == "red"
card = c.get("/api/v1/patients/tok-andrey", params={"doctor_id": "doc-smirnova"}).json()
assert card["safety_plan"] and card["series"]
assert c.post("/api/v1/dialog/tok-andrey/events", json={"type": "text", "text": "ok"}).status_code == 200
assert c.get("/api/v1/demo/clock").json()["virtual"] is True