// Story 9 / DR 6.2 (#67): a proto mismatch completes the upgrade, sends closing{proto-mismatch} // and closes; the client must show "reload" and stop, not sign in and not retry. // // The real server's mismatch path is already proven by tools/protocol.test.mjs (it takes a build // whose proto differs). Here the browser's own WebSocket is intercepted and given exactly that // documented frame sequence, so the assertion is about the client's UI and close-code mapping. import test from 'node:test' import assert from 'node:assert/strict' import { launchBrowser, newPage, waitForText, waitForVisible, withStack } from './stack.mjs' test('protocol mismatch: the client shows reload and does not reconnect', { timeout: 120000 }, async () => { await withStack(async ({ origin }) => { const browser = await launchBrowser() try { const { page } = await newPage(browser) // The client only dials on boot when its session marker exists (M4 UX). This test is about // the upgrade outcome, so tell the page a session may exist before it loads. await page.addInitScript(() => localStorage.setItem('fff-vtt.session', '1')) let sockets = 0 await page.routeWebSocket(/\/ws\?proto=2$/, ws => { sockets += 1 // DESIGN 6.5 row 5: closing then the close frame; no hello, no state. ws.send(JSON.stringify({ t: 'closing', n: 1, reason: 'proto-mismatch', code: 4003 })) ws.close() }) await page.goto(`${origin}/`) await waitForVisible(page, '#fatal') await waitForText(page, '#fatal-text', /out of date.*reload/i) const reload = page.locator('#reload') assert.equal(await reload.isVisible(), true) assert.equal(await page.locator('#signin').isVisible(), false) assert.equal(await page.locator('#stage canvas').count(), 0) await new Promise(resolve => setTimeout(resolve, 400)) assert.equal(sockets, 1, 'a mismatch is terminal: exactly one connection attempt') } finally { await browser.close() } }) })