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. --- server/bin/main.dart | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) (limited to 'server/bin') diff --git a/server/bin/main.dart b/server/bin/main.dart index 60910a9..36c64c7 100644 --- a/server/bin/main.dart +++ b/server/bin/main.dart @@ -3,6 +3,7 @@ /// Usage (from the server/ directory): /// dart run bin/main.dart /// dart run bin/main.dart --port 8080 --static-dir ../web/dist +/// dart run bin/main.dart --saves-dir /data/saves # e.g. in Docker library; import 'dart:io'; @@ -27,15 +28,20 @@ Future main(List args) async { int.tryParse(Platform.environment['PORT'] ?? '') ?? 4567; final staticDir = _parseString(args, 'static-dir') ?? '../web/dist'; + // The save directory (game state, settings, saves, seats) defaults to + // `saves/` next to the server; override for Docker / multi-game hosts. + final savesDir = _parseString(args, 'saves-dir') ?? 'saves'; + // The game data the engine loads and the client's menus read. + final dataDir = _parseString(args, 'data-dir') ?? 'assets/data/'; - // Boot the game engine (single save in saves/, game data from - // assets/data/), then attach the network layer: the WebSocket game - // server, with seat ownership persisted next to the game state. - await _bootGameCore(); + // Boot the game engine (single save in [savesDir], game data from + // [dataDir]), then attach the network layer: the WebSocket game server, + // with seat ownership persisted next to the game state. + await _bootGameCore(savesDir: savesDir, dataDir: dataDir); final gameServer = GameServer( gameState: getIt(), sessions: SessionManager(), - seatStore: FileSeatStore('saves'), + seatStore: FileSeatStore(savesDir), ); final server = await startServer( @@ -43,7 +49,7 @@ Future main(List args) async { staticDir: staticDir, gameServer: gameServer, // The client's menus and artwork read the same assets the engine loads. - dataDir: 'assets/data/', + dataDir: dataDir, imageDir: 'assets/images/', // In-game ability-text translations for the client's card renderer. i18nDir: 'assets/i18n/', @@ -61,19 +67,25 @@ Future main(List args) async { /// Registers the core singletons (file-backed save), loads the game data, /// initializes the game state, and restores the most recent save. -Future _bootGameCore({String dataDir = 'assets/data/'}) async { +Future _bootGameCore({ + required String savesDir, + required String dataDir, +}) async { setupCore( - saveStore: FileSaveStore('saves'), - settingsStore: FileSettingsStore('saves'), + saveStore: FileSaveStore(savesDir), + settingsStore: FileSettingsStore(savesDir), ); await getIt().loadData(dataDir); final gameState = getIt(); gameState.init(); - // Restore the persisted settings (saves/settings.json; no-op on first + // Restore the persisted settings (/settings.json; no-op on first // run) before the server answers the first `welcome` with them. getIt().loadFromDisk(); gameState.load(); - _log.info('game core booted (command index ${gameState.commandIndex})'); + _log.info( + 'game core booted (saves: $savesDir, ' + 'command index ${gameState.commandIndex})', + ); } int? _parseInt(List args, String name) => -- cgit v1.3.1