Files
xenia-pos-local/tests/e2e
bonaminandClaude Opus 5.5 9f5498332a feat(waiter): the waiter app on the shared foundations (api client, access, i18n), lint clean, starts offline
Plan step 4.1. No visible change to layout or flows.
- api/client.js on @xenia/api createApiClient (CS-8 baseURL, 401 → sign out, no answer →
  backend-offline, err.xenia, the manager-approval retry); the PIN login handles its own 401
  (before, a wrong PIN reloaded the page).
- <AccessProvider> at the root with an i18n instance: modules, permission keys, venue,
  language from bootstrap; who is signed in comes with it (no more /api/auth/me polling).
  packages/access: AccessProvider gains `cache` (the last bootstrap per session; used when
  the server can't be reached, `offline` in the context, keeps retrying) and `failed` (the
  app's own screen when there's nothing cached). The waiter caches per venue, shows its
  offline page (server search) on a first start without a server, retries every 5 s;
  ServerRediscovery and BundleSync run outside the bootstrap.
- Role names → keys: the shift gate and the user menu use core.dashboard.access.
- One shared, offline-cached read of the venue settings (api/venueSettings.js) instead of
  seven GET /api/settings/ calls; apiError() shows backend error codes in the user's
  language (17 places).
- Lint: 78 errors → 0 (unused code, empty catches, two duplicate style keys, a component
  created during render, refs read during render → state, hooks after an early return);
  set-state-in-effect is a warning like the manager/terminal; lint in run-all.
- Tests: tests/bootstrapCache.test.mjs; e2e browser: an offline restart stays signed in.
  Android rediscovery waits for what the screen shows instead of fixed sleeps: 10/10 three
  runs in a row (KI-009). Terminal 3.4 waits for both displays before the sale.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 11:37:47 +02:00
..

client-services tests

Automated checks for everything built in the native-app / LAN plan (docs/plans/native-waiter-app.md in the parent repo) and for offline licensing (KI-006). Run them before a release and after changing anything they cover.

Quick: unit tests (seconds, no servers)

cd client-services/local_backend
pip install -r requirements-dev.txt      # once
python -m pytest tests -q                # everything: unit tests + DB tests (~4 s)
python -m pytest tests -q -m "not db"    # quick set only: license rules, LAN IP, TLS identity, logging
python -m pytest tests -q -m db          # DB tests only: real app + temp SQLite database

cd ../waiter_pwa
npm test                                 # server rediscovery scan

cd ..
npm test -w @xenia/ui                    # PIN rules + WCAG contrast of every token pair (light/dark × venue themes)
npm test -w @xenia/i18n                  # venue-time formatting (DST), money/numbers, comma-or-dot parsing, language order, check-i18n guard, error texts vs core/errors.py
npm test -w @xenia/api                   # live client = the waiter's old WebSocket behaviour (backoff, cursor, online); HTTP client vs a fake backend (headers, codes, 401, offline, approval retry)
npm test -w @xenia/access                # can(): one key, any/all
npm test -w manager-dashboard            # platform pages' logic: module states, what stops with a module, device status/usage/limits
npm run lint -w manager-dashboard        # ESLint (waiter rules) on the manager's v2 code; the file list is the `lint` script
npm test -w terminal                     # terminal: which apps a screen can run, token store, which screen shows when, live events/refusals, idle sign-out, pairing polls
npm run lint -w terminal                 # ESLint on all of terminal/src (same rules)

DB tests (local_backend/tests/conftest.py) run the real FastAPI app against a throwaway SQLite database in a temp folder (never your dev or venue DB). Fixtures: db (session, rolled back after each test even if the code commits), client (TestClient with get_db overridden, license check open, no lifespan), make_user(role=..., perms=...) (password password, PIN 1234), login(user) (auth headers). A test that uses any of them is marked db automatically.

Full: end-to-end suites

cd client-services/tests/e2e
npm install                              # once (Playwright, fflate)
node run-all.mjs                         # everything, fastest first, with a summary
node run-all.mjs --no-android            # everything except the emulator

Or run one suite at a time:

Command What it checks Needs Time
node install.mjs install.sh: VPN-safe HOST_IP detection (simulated WireGuard/WiFi hosts); fresh install, upgrade, re-run; proxy config identical to nginx-proxy/nginx.conf Docker ~1 min
python license_e2e.py Offline licensing with a real cloud + site process: 400 days offline, tampered file, clock set back, expiry deferred to workday close, renewal, remote lock Python deps of both backends ~2 min
node ui.mjs @xenia/ui components on the dev-only gallery (/ui-gallery, manager Vite :5185): dialog focus/Escape/backdrop, sheet, toasts, field wiring, switch, InfoTip, PinPad, themes; @xenia/i18n on /i18n-sample with the browser in New York: venue time, live language switch, el/en money and numbers, price input, translated component labels Edge ~40 s
node manager.mjs Manager on @xenia/api/@xenia/access (backend :8057 on a demo DB, manager Vite :5186): bootstrap before/after login, wrong password and wrong lock PIN stay on screen, sidebar from keys, KDS module off → "turned off" screen, session ended elsewhere → /login, a waiter's cancel approved by a manager PIN (wrong PIN first) and audited; Apps, Integrations, License, Devices (pairing played through the API, a device setting chosen when pairing and edited, the screen's live connection told of the edit and closed on app change and removal); the approvals log, "Signed in now" + end session, the staff permission editor (give, reset to role, a staff manager can't give what they lack); the notification bell (live, read, read all), sign-in/venue/print settings, log download; the owner flow (sign in → turn on KDS → pair the real terminal screen (its Vite on :5188) → give a chef the kitchen permissions → the chef picks their name and types their PIN on that screen) Edge ~2 min
node terminal.mjs The terminal app for paired screens (backend :8059, terminal Vite :5187): pairing through the screen's code, sign-in by PIN (wrong PIN first), tap and password, sign out, reload stays signed in, mode changed in the manager → the screen follows live, session ended by a manager, app off → "turned off" → on, moved to another app → signed out, a customer display without sign-in, server unreachable banner, removed → pairing again with a notice Edge ~1 min
node stack.mjs The release images + the real docker-compose.yml and proxy config on one stack (:19080/:19081/:19082): the terminal on :8082 (app, deep links, assets, /api, WebSocket through both nginx hops); :8082 and :8081 refuse a non-LAN address (a second docker network, 100.64.50.0/24) and answer a LAN one; the proxy still starts without a terminal container Docker ~3 min (first build longer)
node browser.mjs Waiter web modes (same-origin, plain HTTP by LAN IP, venue mode), install dialog + drawer entry (Android / iPhone / desktop / no APK) Docker, Edge ~2 min
node android.mjs basics Pairing, wrong address / other venue's QR, login + live WS, back button, restart, two venues, camera permission Android emulator ~5 min
node android.mjs rediscovery Server IP change (logged in / out), server down + manual search, cold start while offline Android emulator ~4 min
node android.mjs stacks TLS pinning (wrong-key QR, impostor server, HTTP→TLS upgrade, cert renewal, rediscovery over TLS) and UI bundles (apply, staged, tampered, APK too old, rollback, two venues) on two docker-compose stacks built from this repo Android emulator, Docker ~20 min

Requirements

  • Python with local_backend/requirements.txt and cloud-service/cloud_backend/requirements.txt installed.
  • Node 22+, Docker (Docker Desktop is fine).
  • Browser suite: system Edge (default). Set BROWSER_CHANNEL= (empty) to use Playwright's own Chromium after npx playwright install chromium.
  • Android suites: the Android SDK (ANDROID_HOME, or the default location) and an emulator AVD. Default name Xenia_Test_Phone (Pixel 4a, API 35), override with AVD=<name>. The suite builds the debug APK itself (SKIP_APK_BUILD=1 reuses the last one), and boots the emulator if none is attached.

Settings (environment variables)

Variable Default Meaning
LAN_IP auto (first non-VPN, non-virtual adapter) This PC's LAN address, for the "plain HTTP by LAN IP" checks
PYTHON python / python3 Python executable
BROWSER_CHANNEL msedge Playwright browser channel
AVD Xenia_Test_Phone Emulator to boot
SKIP_APK_BUILD unset Reuse the last debug APK
CLOUD_DIR ../cloud-service/cloud_backend Cloud backend for the license suite

Good to know

  • Test data: suites never touch your databases. They start from a fresh copy of a demo-seeded database (local_backend/demo_seed.py), seeded once into out/seed.db. Delete it to reseed.
  • Ports used: 8055/8056 (backends), 8101 (cloud), 5180 (Vite), 15173/15174 (nginx), 18080–18444 and 28080–28443 (compose stacks). Your own dev stack's ports (80/443/8081/8443/5173/5174) are never used. Stop anything else on those ports first.
  • Isolated stacks: the compose stacks run under their own project names (xenia-e2e-v1/v2) with their own images and data. They're removed afterwards.
  • Output: screenshots and logs go to out/, which is gitignored.
  • Licensing in tests: the license suite signs with a throwaway key, and the production signing key is never needed. The other suites run their backends without a cloud URL and with LICENSE_MODE=off (lib/proc.mjs), so every module is available. On platform v2 a backend without LICENSE_MODE=off and without a valid v2 token runs the free tier (D-5), so any new launcher must set it. license_e2e.py needs a cloud that signs v2 tokens: it's updated in plan step 1.7, and fails until then.