feat: scaffold Brain of Reese — FastAPI RAG chat over Postgres 17 + pgvector
Foundation (phase 01, verified): - FastAPI app: /api/health, /api/suggestions, /api/chat (placeholder), static frontend served locally (no CDN) - Postgres 17 + pgvector via db/Containerfile + compose.yaml (podman compose up -d db), Alembic initial migration (documents, chunks with vector(768), query_log) - LLM client targeting https://aipi.reeseapps.com/v1 (turbo/embed); scripts/llm_probe.py verified models + 768-dim embeddings live - Conditional debugpy: imported only when DEBUGPY=1 (attach on demand, :5678); logging config for clean single-line logs - Frontend shell: mobile-first chat + Sources pages, tokens, a11y baselines - Tests: 24 unit+integration (99% coverage on app/), ruff + pyright clean, Playwright smoke E2E (3 tests) against a deterministic mock LLM - Planning: .agent/PLAN.md (architecture + LOCKED decisions), AGENTS.md, 6 user stories, 7 phase files (one story / one phase / one Playwright suite each)
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
"""Unit tests: engine/session helpers (no live database required).
|
||||
|
||||
Creating a SQLAlchemy engine/session is lazy — no connection opens until the
|
||||
first query — so these run anywhere.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
from sqlalchemy import Engine
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app import db as app_db
|
||||
|
||||
|
||||
def test_engine_and_session_factory_are_lazy() -> None:
|
||||
assert isinstance(app_db.engine, Engine)
|
||||
session = app_db.SessionLocal()
|
||||
try:
|
||||
assert isinstance(session, Session)
|
||||
finally:
|
||||
session.close()
|
||||
|
||||
|
||||
def test_get_db_yields_session_and_closes_generator() -> None:
|
||||
gen = app_db.get_db()
|
||||
session = next(gen)
|
||||
assert isinstance(session, Session)
|
||||
session.close()
|
||||
gen.close() # exercises the finally: db.close()
|
||||
|
||||
|
||||
def test_db_available_true_on_select_one(monkeypatch) -> None:
|
||||
class _FakeConn:
|
||||
def __enter__(self):
|
||||
return self
|
||||
|
||||
def __exit__(self, *exc: object) -> None:
|
||||
return None
|
||||
|
||||
def execute(self, _stmt: object) -> None:
|
||||
return None
|
||||
|
||||
class _FakeEngine:
|
||||
def connect(self) -> _FakeConn:
|
||||
return _FakeConn()
|
||||
|
||||
monkeypatch.setattr(app_db, "engine", _FakeEngine())
|
||||
assert app_db.db_available() is True
|
||||
|
||||
|
||||
def test_db_available_false_on_error(monkeypatch) -> None:
|
||||
class _BrokenEngine:
|
||||
def connect(self) -> object:
|
||||
raise ConnectionError("db is down")
|
||||
|
||||
monkeypatch.setattr(app_db, "engine", _BrokenEngine())
|
||||
assert app_db.db_available() is False
|
||||
Reference in New Issue
Block a user