Files
xenia-pos-local/tools/smoke_routes.py
T
bonaminandClaude Opus 5.5 7cbd0325a4 refactor(backend): remove the v1 auth and permission leftovers no frontend uses
Platform-v2 step 2.99a. After 2.6 no frontend calls these any more:
- POST /api/auth/login needs `client` (manager/waiter/terminal); the no-`client`
  path with v1 rules and the `legacy_manager` single-session exception are gone.
- GET /api/setup/security-config (bootstrap's `login` replaced it in 2.6b).
- POST /api/recovery/use (a recovery code works in the normal login's
  password field).
- PUT /api/waiters/{id}/permission and /reset-permissions (the permission editor
  saves keys with PUT /{id}/permissions); staff create/update ignore perm_* fields.
- The v1 perm_* projection: core/access/legacy.py deleted, UserOut carries only
  `permissions` (no app reads the 13 booleans, waiter included).
e2e manager login sends client "manager"; smoke_routes too. Backend 281 passed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-14 12:08:01 +02:00

64 lines
3.0 KiB
Python

"""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={"client": "manager", "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")