Phase 03 (Story: Chat RAG Answer — happy path):
- app/rag/retriever.py: top-k cosine search + parent-doc selection with
per-doc dedupe and BOR_MAX_CONTEXT_CHARS cap ([…truncated…] marker)
- app/rag/prompts.py: locked persona + HIGH/DEFLECT prompt builders
- app/rag/llm.py: LLMError + chat_stream (turbo, temp 0.4, max 700, stream)
- app/api/chat.py: POST /api/chat SSE — delta* then done{deflected,
sources, suggestions}; query_log row + PLAN §9 per-turn log line;
structured error event on mid-stream failure, JSON 503 when DB down
- frontend: SSE reader, live bubble streaming, source chips -> /sources.html,
red role=alert banner, Send button state that always recovers
- fix(scaffold): [hidden] { display: none !important } — .kb-banner's
display:flex was overriding the hidden attribute (banner always visible)
- tests: unit (retriever/prompts/sse/llm) + integration (real Postgres RAG
turn, query_log, error + 503 paths, mid-turn failures) + Playwright story
suite (grounded answer, log row, raw SSE shape); smoke placeholder test
replaced with the real never-stale-button contract
40 lines
1.2 KiB
Python
40 lines
1.2 KiB
Python
"""Integration tests: HTTP API surface (no database required)."""
|
|
from __future__ import annotations
|
|
|
|
|
|
def test_health_reports_ok(client) -> None:
|
|
r = client.get("/api/health")
|
|
assert r.status_code == 200
|
|
body = r.json()
|
|
assert body["status"] == "ok"
|
|
assert body["db"] in {"up", "down"}
|
|
assert body["version"]
|
|
|
|
|
|
def test_suggestions_returns_list(client) -> None:
|
|
r = client.get("/api/suggestions")
|
|
assert r.status_code == 200
|
|
suggestions = r.json()["suggestions"]
|
|
assert isinstance(suggestions, list)
|
|
assert all(isinstance(s, str) and s for s in suggestions)
|
|
|
|
|
|
def test_index_html_served_locally(client) -> None:
|
|
"""No-CDN check: the page is served by FastAPI and references only
|
|
same-origin assets (no https:// script/link tags)."""
|
|
r = client.get("/")
|
|
assert r.status_code == 200
|
|
assert "Brain of Reese" in r.text
|
|
assert 'src="https://' not in r.text
|
|
assert 'href="https://' not in r.text
|
|
|
|
|
|
def test_styles_and_js_served(client) -> None:
|
|
assert client.get("/assets/styles.css").status_code == 200
|
|
assert client.get("/assets/app.js").status_code == 200
|
|
|
|
|
|
def test_chat_requires_message(client) -> None:
|
|
r = client.post("/api/chat", json={"message": ""})
|
|
assert r.status_code == 422
|