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:
2026-08-21 13:42:21 -04:00
commit 022da8e2bc
63 changed files with 5225 additions and 0 deletions
+46
View File
@@ -0,0 +1,46 @@
"""Unit tests: SQLAlchemy models register the pgvector schema on the metadata.
Importing :mod:`app.models` is what Alembic's ``env.py`` and the runtime rely
on; these tests lock the table/column contract (PLAN §5) without a live DB.
"""
from __future__ import annotations
from pgvector.sqlalchemy import Vector
from sqlalchemy import UniqueConstraint
import app.models # noqa: F401 (import registers all tables on Base.metadata)
from app.db import Base
def test_all_tables_registered() -> None:
tables = Base.metadata.tables
assert "documents" in tables
assert "chunks" in tables
assert "query_log" in tables
def test_chunks_embedding_is_vector_768() -> None:
chunks = Base.metadata.tables["chunks"]
col = chunks.c["embedding"]
assert isinstance(col.type, Vector)
assert col.type.dim == 768
# Embeddings are two-phase: inserted first, embedded later.
assert col.nullable is True
def test_chunks_reference_documents_cascade() -> None:
chunks = Base.metadata.tables["chunks"]
fkc = list(chunks.foreign_key_constraints)[0]
assert fkc.elements[0].column.table.name == "documents"
assert fkc.ondelete == "CASCADE"
def test_documents_unique_source_path() -> None:
documents = Base.metadata.tables["documents"]
uq = [
c
for c in documents.constraints
if isinstance(c, UniqueConstraint)
and {col.name for col in c.columns} == {"source", "path"}
]
assert uq, "documents must be unique on (source, path) — the upsert key"