feat: phase r1+r2 recovery + r3-0 swiftly api ingestion

R1 stabilization: pytest harness with transactional db fixture, smoke
+ alembic + auth + scrape + approval + swiftly tests, github actions
ci yaml. Bearer-token admin auth + signed-cookie session for family
ui mutations. Async POST /api/admin/scrape (BackgroundTasks, returns
202). Path canonicalization (no /list, /planned suffixes). DATABASE_URL
fail-fast on empty.

R2 deferred-risk spikes: live lucky california fetch (R2-A), full
email+per-voter approval click round trip with single-use enforcement
(R2-B, console email backend, sendgrid stub).

R3-0 phase 3 redesign: replaced playwright html scraper with requests
based swiftly json api client. 17 categories, ~10k products per scrape,
upsert by (source, external_id). 401 surfaces actionable token-refresh
message via ScrapeLog.error_message.

Pre-existing defects fixed: shopping_list.py syntax error blocking app
import, MealPlan.votes orphan relationship, JSONB(astext=True) invalid
kwarg, missing requests dep, calorie_target schema drift, every SQLEnum
needed values_callable, 0001 had empty downgrade(), seed had duplicate
ingredient rows.

Migrations added: 0003 grocery_item.description, 0004 family_profile.
calorie_target, 0005 grocery_item.external_id + source + composite index.

Verified: 31/31 pytest green, alembic upgrade->downgrade->upgrade clean,
frontend npm run build clean, live scrape 9,960 grocery_item rows in 36s.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-05 14:08:19 -07:00
co-authored by Claude Opus 4.7
parent b9434967ed
commit 8e89f793d5
58 changed files with 3594 additions and 348 deletions
+63
View File
@@ -0,0 +1,63 @@
"""
Smoke tests: app boots, routers wire up, no import-time crashes.
The router-list test asserts each endpoint returns 200 or 401 (auth gate not
yet implemented in R1-A's scope) but explicitly NOT 5xx — the goal is to catch
import errors and crashing handlers, not to validate business logic.
"""
from __future__ import annotations
import os
import pytest
def test_app_imports():
from app.main import app
assert app.title == "MealPlanner"
@pytest.mark.requires_postgres
def test_health(client):
r = client.get("/health")
assert r.status_code == 200
assert r.json() == {"status": "ok"}
@pytest.mark.requires_postgres
def test_health_db(client):
r = client.get("/health/db")
assert r.status_code == 200
body = r.json()
assert body.get("database") == "connected"
ROUTER_GET_PATHS = [
"/api/profile",
"/api/profile/members",
"/api/recipes",
"/api/recipes/ingredients",
"/api/meals",
"/api/pantry",
"/api/shopping-list",
"/api/admin/logs",
]
@pytest.mark.requires_postgres
@pytest.mark.parametrize("path", ROUTER_GET_PATHS)
def test_router_list_endpoints(client, path):
"""
Each canonical GET must respond. 200 (handled), 401 (admin-gated),
404 (handler ran but no row found) — all OK. 5xx means import/runtime
crash; 307 (trailing-slash redirect) means a handler is still mounted
on the wrong path.
"""
r = client.get(path, follow_redirects=False)
assert r.status_code < 500, (
f"{path} returned {r.status_code}: {r.text[:300]}"
)
# 307 is a regression — canonical paths must be the route definitions.
assert r.status_code in (200, 401, 404, 422), (
f"{path} returned unexpected {r.status_code}"
)