From 93970f361b831f17d48ff2a345fc78488ac71fba Mon Sep 17 00:00:00 2001 From: Joel Klinghed Date: Mon, 23 Nov 2026 00:51:32 +0100 Subject: Phase 7: hardening and shipping (M7) E2E (Playwright, e2e/): - table fixture: one real compiled server per test (temp saves dir, free port, workers: 1); a Tab helper drives the real UI (menus, rows, initiative, draw, seats) over one WS per fresh browser context - full round: onboarding, secret initiative masked to ?? per connection, draw revealing on every screen, turns, next round, round-2 secrecy - seats: claim/re-claim on owner-leave, reload keeps the session and re-claims, two sessions can't own one character - resilience: a dropped tab resyncs on reconnect (no drift); a SIGKILL'd server restarts with state + seats surviving (incl. the owner's secret initiative and the enabled draw); a throttled tab converges on the same state as the fast tabs; a double-tapped draw runs once, error sent to the sender only - figure edit: set a character level + rename from the status menu Cross-check vs the reference (feature parity): - status menu: level pills (setCharacterLevel) + a name field (changeName), mirroring SetCharacterLevelMenu - ability-card removal: draw-pile-only "send to bottom" (reorderAbilityList -> index 0) + "shuffle undrawn cards" (shuffleDrawnAbilityCard), mirroring RemoveCardMenu - Add Character: already-added classes disabled (Objective/Escort may be added repeatedly), matching _characterAlreadyAdded - every remaining registry command verified reachable from the UI Session persistence (found by the restart test): - the client never learned its session id before the first welcome, so a reconnect minted a new id and orphaned the restored seat; fixed with establishSessionCookie() (a GET /session before the WS upgrade, plus a vite /session proxy) so the x-haven-session cookie survives restarts - the initiative input now prefills from re-synced state (CharacterRow effect, guarded against clobbering a live edit) so a reload/reconnect doesn't blank an entry Performance + deployment: - immutable asset caching (Cache-Control: 1yr, immutable) for the game data / images / in-game translations; no-cache for the SPA index.html so rebuilt apps reach open tabs - server tool/perf_measure.dart: the performance probe (state payload size at full-table scale, WS fan-out bytes per action, traffic per connection) - Dockerfile (server + built web); docs/DEPLOYMENT.md (Docker, persistence, reverse proxy, measured performance, smoke-test list) - README quickstart + production/Docker/testing sections Server: - --saves-dir and --data-dir CLI options (Docker / multi-game hosts), threaded through the stores and data loading Misc: - app.css: height 100% on .row so the turn-done tap zone resolves to a clickable height; fake-socket.ts readyState constants corrected to the real WebSocket values (0 CONNECTING, 1 OPEN) - scripts/ci.sh: the Playwright E2E gate (runs when PLAYWRIGHT is set) - PLAN.md: Phase 7 boxes checked, M7 progress-log entry Verification: svelte-check 0 errors; web 196/196 tests; vite build OK; dart analyze 0 errors / 0 warnings; dart test 604/604; Playwright 9/9; scripts/ci.sh green end-to-end. --- docs/DEPLOYMENT.md | 127 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 docs/DEPLOYMENT.md (limited to 'docs') diff --git a/docs/DEPLOYMENT.md b/docs/DEPLOYMENT.md new file mode 100644 index 0000000..e27891b --- /dev/null +++ b/docs/DEPLOYMENT.md @@ -0,0 +1,127 @@ +# Deployment notes + +How to run X-Haven (web) in production. Two supported shapes: a single +container (Docker) or the two source trees directly (Dart + Node). The game +is a **single server process** — there is nothing to scale out per player; +more players just mean more WebSocket connections on the same server. + +## Running with Docker + +```bash +docker build -t xhaven . +docker run --rm -p 4567:4567 -v xhaven-saves:/app/saves xhaven +``` + +- Port: published `4567` → container `4567` (override with `-p 8080:4567` and + `--env PORT=8080`). +- State: everything the server persists lives under `/app/saves` + (`game.json` the live snapshot, `seats.json` seat ownership, + `settings.json` server-side settings, plus named saves). Mount a volume + there and redeploys keep the game. +- Health: `GET /healthz` answers 200; the image ships a `HEALTHCHECK` + (TCP probe, dependency-free). + +## Running from source + +```bash +cd web && npm ci && npm run build # → web/dist +cd ../server +dart pub get +dart run bin/main.dart \ + --port 4567 \ + --static-dir ../web/dist \ + --saves-dir /var/lib/xhaven/saves +``` + +Flags (all optional, see `server/bin/main.dart`): + +| flag | default | meaning | +|----------------|------------------|--------------------------------------------------| +| `--port` | `4567` (or `$PORT`) | HTTP + WebSocket port | +| `--static-dir` | `../web/dist` | the built web app (SPA fallback included) | +| `--saves-dir` | `saves` | game state, seats, settings, named saves | +| `--data-dir` | `assets/data/` | campaign/monster/scenario JSON (served at `/data/`) | + +Game artwork (`assets/images/`, ~66 MB) and in-game translations +(`assets/i18n/`) are served from the paths relative to the working +directory; keep the server's `assets/` tree next to `bin/`. + +## Reverse proxy / TLS + +The app is a plain-HTTP + WebSocket server; put it behind any TLS-terminating +proxy (Caddy, nginx, …). The only non-HTTP route is the WebSocket upgrade at +`/ws` — forward it with the usual `Upgrade`/`Connection` headers. All other +routes are ordinary GETs, and the client derives the WS URL from the page +origin (`wss://` under TLS), so no client configuration is needed. + +Long idle connections are kept alive by the client's 25 s keepalive `ping`; +proxy idle timeouts above ~30 s are fine. + +## Persistence & restarts + +- The server saves on **every action** (synchronous write-through), so a + crash loses at most the in-flight frame. +- On boot it restores `game.json` + `seats.json`: characters, the scenario, + round state, initiative entries, and seat ownership all survive a restart. + Reconnected browsers (same session cookie) resume with their seats; the + first `welcome` after reconnect carries the full state. +- Undo history is **not** persisted: after a restart the command index + restarts at 0 and the undo/redo buttons stay disabled until new actions + are taken. State itself is fully restored. +- Named saves (the Load/Save State menu) live under the saves dir and + survive indefinitely. + +## Performance (measured, Phase 7) + +Protocol cost under a full table, measured with +`server/tool/perf_measure.dart` (6 connected clients — 4 players + 2 +spectators — playing 3 full rounds of "#1 Roadside Ambush" with 4 characters +and 10 monsters; localhost): + +| metric | value | +|-----------------------------------------|---------| +| state JSON, full-table scale | **11.2 kB** | +| largest `update` frame (envelope+state) | 11.4 kB | +| fan-out per executed action (6 clients) | 68.5 kB | +| traffic per connection over 49 actions | ~460 kB | +| server-side action latency (localhost) | ~10 ms | + +The protocol is a full snapshot per action (bandwidth for simplicity): cost +scales linearly with state size × connections. At this scale that is trivial +for LAN or even WAN; the state grows slowly (characters, monsters, note rows, +decks) — a heavy multi-scenario game would be tens of kB, still fine. + +Static assets: + +- `index.html` and SPA routes: `cache-control: no-cache` (deploys reach open + tabs on refresh). +- Content-hashed build assets, `/data/` JSON, `/i18n/`, and the 66 MB + `/images/` set: `public, max-age=31536000, immutable` — the browser fetches + each image once and then from cache; the 66 MB art set is a one-time + download per device. +- Class artwork is `loading="lazy"` in the list. + +## Smoke-test list + +After deploying, verify in two browser tabs (and a third as spectator) — +these are exactly what the E2E suite (`e2e/`) automates: + +1. **Connect** — the "Connecting…" banner disappears on every tab; each tab + shows the table. +2. **Onboard** — in tab A open *Add Character* and add *Hatchet*; the row + appears on all tabs and tab A's Draw button enables (tab A is now a + player). +3. **Scenario** — tab A: *Set Scenario* → *#1 Roadside Ambush*. +4. **Second player** — tab B adds *Voidwarden*; all tabs show both rows. +5. **Spectator** — tab C shows both rows **read-only**: no initiative input, + no *Claim* chip, Draw disabled. +6. **Secret initiative** — tab A enters `4` in Hatchet's initiative slot. + Tab A sees the value; tabs B and C show `??`. +7. **Draw** — tab B enters `2`, then tab A taps *Draw*. All three tabs + switch to *Next Round* at once and show initiatives `4` / `2`. +8. **Turns** — tap the turn-done zone for each character; the round + completes. +9. **Next round** — tap *Next Round*; every tab shows *Round 2/* and the + initiative slots are secret again (only owners' inputs enabled). +10. **Reconnect** — reload tab C, then kill and restart the server; all + tabs show "Reconnecting…" and resync with the full state (seats kept). -- cgit v1.3.1