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. --- e2e/tests/seats.spec.ts | 82 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 e2e/tests/seats.spec.ts (limited to 'e2e/tests/seats.spec.ts') diff --git a/e2e/tests/seats.spec.ts b/e2e/tests/seats.spec.ts new file mode 100644 index 0000000..432069a --- /dev/null +++ b/e2e/tests/seats.spec.ts @@ -0,0 +1,82 @@ +/** + * E2E: seat claiming (PLAN.md Phase 7 / section 3.3). + * + * * a disconnected owner's character becomes claimable (the Claim chip) + * * claiming grants ownership on every screen (inputs enable) + * * a page reload keeps the session (cookie) but the seat must be re-claimed + * (the server releases seats on disconnect — the Phase 2 behaviour) + */ +import { test, expect } from '../helpers/table.js'; + +test.describe('Seats: claim / re-claim / reload', () => { + test('owner leaves → seat released → another session claims', async ({ + table + }) => { + const p1 = (await table.newTab()).tab; + await p1.open(table.server.url); + await p1.addCharacter('Hatchet'); + expect(await p1.hasInitiativeInput('Hatchet')).toBe(true); + + const p2 = (await table.newTab()).tab; + await p2.open(table.server.url); + await p2.row('Hatchet').waitFor({ timeout: 15_000 }); + // While p1 is connected the seat is taken: no claim chip. + expect(await p2.claimChip('Hatchet').count()).toBe(0); + + // p1 leaves the table (tab closed → the connection drops). + await p1.closePage(); + // The seat is released and broadcast: p2 now sees the claim chip. + await p2.claimChip('Hatchet').waitFor({ timeout: 15_000 }); + + await p2.claim('Hatchet'); + // p2 is the owner now: the chip is gone, inputs enable, and the draw + // button unlocks (a claimed seat makes p2 a player). The claim is a + // server round-trip (seats broadcast → re-render), so these auto-wait. + await expect(p2.claimChip('Hatchet')).toHaveCount(0); + await expect(p2.row('Hatchet').locator('input.init__input')).toHaveCount(1); + await expect(p2.page.locator('button.drawbtn')).toBeEnabled(); + }); + + test('a page reload keeps the session, and the seat is re-claimed', async ({ + table + }) => { + const p1 = (await table.newTab()).tab; + await p1.open(table.server.url); + await p1.addCharacter('Hatchet'); + expect(await p1.hasInitiativeInput('Hatchet')).toBe(true); + + // Reload the same tab (same context → the session cookie survives). + await p1.page.reload(); + await p1.waitForConnected(); + await p1.row('Hatchet').waitFor({ timeout: 15_000 }); + + // The disconnect released the seat: the character is claimable again, + // and the (reconnected) session claims it with one tap. + await p1.claimChip('Hatchet').waitFor({ timeout: 15_000 }); + await p1.claim('Hatchet'); + // The claim round-trip (seats broadcast → re-render) is async. + await expect(p1.row('Hatchet').locator('input.init__input')).toHaveCount(1); + await expect(p1.claimChip('Hatchet')).toHaveCount(0); + }); + + test('two sessions cannot own one character at once', async ({ table }) => { + const p1 = (await table.newTab()).tab; + await p1.open(table.server.url); + await p1.addCharacter('Hatchet'); + + // p1 leaves, p2 claims, p1 comes back and tries to re-claim the same + // character — the server rejects it (it is claimed by p2). + const p2 = (await table.newTab()).tab; + await p2.open(table.server.url); + await p2.row('Hatchet').waitFor({ timeout: 15_000 }); + await p1.closePage(); + await p2.claimChip('Hatchet').waitFor({ timeout: 15_000 }); + await p2.claim('Hatchet'); + + const p1Again = (await table.newTab()).tab; + await p1Again.open(table.server.url); + await p1Again.row('Hatchet').waitFor({ timeout: 15_000 }); + // p2 holds the seat: no claim chip for p1Again. + expect(await p1Again.claimChip('Hatchet').count()).toBe(0); + }); +}); -- cgit v1.3.1