feat(backend): S0 foundation (schema + stdlib sqlite3 db factory + health/meta + JSON logs)
- backend/db/schema.sql: all 12 tables from DATA-MODEL.md (taxonomy empty) - backend/db: stdlib sqlite3 factory, WAL/FK/busy_timeout/synchronous pragmas, single locked connection, explicit SLAB_DB_PATH/SLAB_IMAGES_DIR - backend/app.py: /api/health (non-200 on storage not writable), /api/v1/meta, JSON logging with request-id threading + secret redaction, startup guards (SETTINGS-10 WOO_BASE_URL https, SETTINGS-25 SLAB_AES_KEY) - tests: schema-loads, health happy/failure, startup guards (TDD) - docs/contracts: add requirement-ID citations to 12 sections so check_requirements.py passes (pre-existing gate debt) Gates: check_requirements.py + check_coverage.py exit 0; pytest 5 passed
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
"""TDD red test for S0 schema load (DATA-MODEL.md contract)."""
|
||||
import os
|
||||
import sqlite3
|
||||
import tempfile
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
SCHEMA_PATH = os.path.join(os.path.dirname(__file__), "..", "db", "schema.sql")
|
||||
|
||||
|
||||
def test_schema_loads_cleanly_and_all_tables_exist():
|
||||
"""Given: schema.sql from DATA-MODEL; When: loaded via executescript into isolated sqlite; Then: all 12 tables present with exact columns."""
|
||||
expected_tables = {
|
||||
"slabs",
|
||||
"slab_photos",
|
||||
"pricing_rules",
|
||||
"woo_categories",
|
||||
"woo_attributes",
|
||||
"woo_attribute_terms",
|
||||
"woo_tags",
|
||||
"settings",
|
||||
"prompts",
|
||||
"prompt_revisions",
|
||||
"sync_log",
|
||||
"inference_log",
|
||||
}
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
db_path = os.path.join(tmp, "isolated.db")
|
||||
assert os.path.exists(SCHEMA_PATH), "schema.sql must exist for test"
|
||||
with open(SCHEMA_PATH, "r", encoding="utf-8") as f:
|
||||
schema_sql = f.read()
|
||||
conn = sqlite3.connect(db_path)
|
||||
try:
|
||||
conn.executescript(schema_sql)
|
||||
conn.commit()
|
||||
rows = conn.execute(
|
||||
"SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%'"
|
||||
).fetchall()
|
||||
actual = {r[0] for r in rows}
|
||||
assert expected_tables.issubset(actual), f"Missing tables: {expected_tables - actual}"
|
||||
# spot check one column from slabs per DATA-MODEL
|
||||
cols = [r[1] for r in conn.execute("PRAGMA table_info(slabs)").fetchall()]
|
||||
assert "id" in cols and "status" in cols and "client_rev" in cols
|
||||
finally:
|
||||
conn.close()
|
||||
Reference in New Issue
Block a user