chore(backend): smoke_routes tool - GET every endpoint per role on a demo DB

The check used after each platform-v2 step (until now a scratch script): calls every parameterless GET endpoint as the demo manager and demo waiter, in dev mode or with licensing enforced (--free), and lists 5xx responses.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-12 20:55:10 +02:00
co-authored by Claude Opus 5.5
parent e128cc37ec
commit 1d7a521e05
+63
View File
@@ -0,0 +1,63 @@
"""Smoke check: call every parameterless GET endpoint of the local backend, by role.
Used after each platform-v2 step to catch crashes (5xx) the unit tests don't reach.
Works on a COPY of a demo database; never point it at a venue's real data.
cd client-services/local_backend
# once: a demo DB (needs PYTHONIOENCODING=utf-8 on Windows consoles)
set PYTHONIOENCODING=utf-8 & set LICENSE_MODE=off & set DATABASE_URL=sqlite:///C:/tmp/demo/pos.db
python demo_seed.py
python ../tools/smoke_routes.py C:/tmp/demo # dev mode (every module)
python ../tools/smoke_routes.py C:/tmp/demo --free # licensing enforced, no token = free tier
Prints status-code counts per caller (demo manager by password, demo waiter by PIN) and
every 5xx path. Expected on 2026-11-12: only /api/reports/orders/export fails (KI-008).
"""
import collections
import os
import sqlite3
import sys
data = sys.argv[1]
free = "--free" in sys.argv
os.environ.update(DATABASE_URL=f"sqlite:///{data}/pos.db", LOG_DIR=f"{data}/logs", TLS_DIR=f"{data}/tls",
LICENSE_MODE="enforced" if free else "off")
sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "local_backend"))
os.chdir(os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "local_backend"))
from fastapi.testclient import TestClient # noqa: E402
import main # noqa: E402
from core.schema import upgrade_to_head # noqa: E402
from services.cloud_sync import load_license_at_startup # noqa: E402
upgrade_to_head()
load_license_at_startup()
c = TestClient(main.app, raise_server_exceptions=False)
callers = {}
r = c.post("/api/auth/login", json={"username": "manager", "password": "password"})
if r.status_code == 200:
callers["manager"] = r.json()["access_token"]
row = sqlite3.connect(f"{data}/pos.db").execute("select id from users where username='demo_nikos'").fetchone()
if row:
r = c.post("/api/auth/login", json={"client": "waiter", "user_id": row[0], "pin": "2201"})
if r.status_code == 200:
callers["waiter"] = r.json()["access_token"]
print("callers:", list(callers) or "none (login failed - free tier or not a demo DB?)")
for who, tok in callers.items():
h = {"Authorization": f"Bearer {tok}"}
codes, errors = collections.Counter(), []
for route in main.app.routes:
if "GET" not in getattr(route, "methods", set()) or "{" in route.path or not route.path.startswith("/api") \
or "/sse" in route.path:
continue
for params in ({}, {"from": "2026-08-01", "to": "2026-11-12"}):
resp = c.get(route.path, headers=h, params=params)
body = resp.json() if resp.headers.get("content-type", "").startswith("application/json") else None
code = body.get("error", {}).get("code") if isinstance(body, dict) else None
codes[(resp.status_code, code)] += 1
if resp.status_code >= 500:
errors.append(route.path)
print(who, dict(sorted(codes.items(), key=lambda x: -x[1])), "\n 5xx:", sorted(set(errors)) or "none")