"""INV-1's enforcement (SD-0001 §6.8): from an empty database, one test walks the whole surviving flow — request-code -> verify -> /me — asserting no step needed seeded state. The network-seed reset removed the create-storefront step from this flow. Migration idempotence (the second INV-1 test) lives in test_migrations.py.""" import re from fastapi.testclient import TestClient from app.main import create_app def test_inv_1_bootstrap_whole_flow_from_empty(fresh_db_url): # fresh_db_url is a brand-new empty database; create_app() self-migrates (INV-7). with TestClient(create_app(database_url=fresh_db_url)) as client: # a fresh deployment serves healthz green before any row exists assert client.get("/healthz").json()["status"] == "ok" # PUC-2: first visitor requests a code; it reaches them via the dev channel assert client.post( "/api/auth/request-code", json={"email": "first@example.com"} ).status_code == 204 code = re.search(r"\b(\d{6})\b", client.app.state.mailer.outbox[-1].body).group(1) # verify creates account #1 — the first row, through the product alone verified = client.post( "/api/auth/verify", json={"email": "first@example.com", "code": code} ) assert verified.status_code == 200 assert verified.json()["created"] is True assert verified.json()["account"] == {"email": "first@example.com"} # the admin answer — the signed-in account from /me alone (cookie set by verify) me = client.get("/api/auth/me") assert me.status_code == 200 assert me.json() == {"account": {"email": "first@example.com"}}