From 3c0258ea3193068b99ec9608a112583b3d8dcdc2 Mon Sep 17 00:00:00 2001 From: Davide Cappellini Date: Fri, 20 Nov 2026 23:57:13 +0100 Subject: [PATCH] feat: client shell, sign-in and protocol client (#67) New `client/` package (Vite + TypeScript + PixiJS v8, plain DOM overlay): the pure reducer seam (no Pixi import), an append-only slice registry build-time glob, the `proto` 2 WS client with envelope/ack/closing mapping, the sign-in door (`POST /join`, one "Key not recognised." for wrong and unknown), the DOM shell/HUD and a minimal Pixi stage created only after a live `hello`. `hello` resets every slice so a reconnect cannot show stale state; `proto-mismatch` shows reload; `revoked` returns to the sign-in page and stops. The browser e2e moves into the client package (`client/e2e/`, owning playwright-core) and runs the real Vite build through the TLS/HTTP2 test nginx: join -> canvas -> hello/roster for GM and player, no data before join, identical wrong/unknown key refusal, proto mismatch, revoked. `devbox run client-test` adds the Vitest seam; `devbox run e2e` builds the client first. The #66 stub dist stays local to `tools/vhost.test.mjs`, so `devbox run test` still needs no npm install. Refs #67 --- .gitignore | 4 +- client/README.md | 74 ++ client/e2e/h2.test.mjs | 55 ++ client/e2e/mismatch.test.mjs | 38 + client/e2e/run.sh | 20 + client/e2e/shell.test.mjs | 103 ++ client/e2e/stack.mjs | 96 ++ client/index.html | 12 + client/package-lock.json | 1342 +++++++++++++++++++++++++++ client/package.json | 22 + client/run-tests.sh | 11 + client/src/main.ts | 103 ++ client/src/protocol.ts | 181 ++++ client/src/reducer.ts | 218 +++++ client/src/render/modules/README.md | 19 + client/src/render/stage.ts | 105 +++ client/src/shell.ts | 173 ++++ client/src/slices/roster.ts | 25 + client/src/store.ts | 35 + client/src/style.css | 104 +++ client/src/vite-env.d.ts | 1 + client/src/ws.ts | 143 +++ client/test/protocol.test.ts | 137 +++ client/test/reducer.test.ts | 184 ++++ client/test/ws.test.ts | 147 +++ client/tsconfig.json | 19 + client/vite.config.ts | 13 + devbox.json | 5 +- docs/DESIGN.md | 3 + docs/TESTING.md | 32 +- e2e/h2.test.mjs | 80 -- e2e/package-lock.json | 28 - e2e/package.json | 10 - e2e/run.sh | 18 - tools/distfixture.mjs | 24 - tools/tlsdev.mjs | 2 +- tools/vhost.test.mjs | 31 +- 37 files changed, 3439 insertions(+), 178 deletions(-) create mode 100644 client/README.md create mode 100644 client/e2e/h2.test.mjs create mode 100644 client/e2e/mismatch.test.mjs create mode 100755 client/e2e/run.sh create mode 100644 client/e2e/shell.test.mjs create mode 100644 client/e2e/stack.mjs create mode 100644 client/index.html create mode 100644 client/package-lock.json create mode 100644 client/package.json create mode 100755 client/run-tests.sh create mode 100644 client/src/main.ts create mode 100644 client/src/protocol.ts create mode 100644 client/src/reducer.ts create mode 100644 client/src/render/modules/README.md create mode 100644 client/src/render/stage.ts create mode 100644 client/src/shell.ts create mode 100644 client/src/slices/roster.ts create mode 100644 client/src/store.ts create mode 100644 client/src/style.css create mode 100644 client/src/vite-env.d.ts create mode 100644 client/src/ws.ts create mode 100644 client/test/protocol.test.ts create mode 100644 client/test/reducer.test.ts create mode 100644 client/test/ws.test.ts create mode 100644 client/tsconfig.json create mode 100644 client/vite.config.ts delete mode 100644 e2e/h2.test.mjs delete mode 100644 e2e/package-lock.json delete mode 100644 e2e/package.json delete mode 100755 e2e/run.sh delete mode 100644 tools/distfixture.mjs diff --git a/.gitignore b/.gitignore index 6492b13..6dbe70c 100644 --- a/.gitignore +++ b/.gitignore @@ -14,5 +14,7 @@ run/ # node-test.log carries per-run durations; regenerate it, do not commit it results/node-test.log results/e2e.log -e2e/node_modules/ +results/client-test.log +client/node_modules/ +client/dist/ .cache-nim*/ diff --git a/client/README.md b/client/README.md new file mode 100644 index 0000000..3352508 --- /dev/null +++ b/client/README.md @@ -0,0 +1,74 @@ +# FFF VTT client + +Vite + TypeScript + PixiJS v8, plain DOM overlay, `proto` 2 (DESIGN §7, ADR-0011). No framework. + +## Run and gates + +All through devbox, from the repo root: + +```sh +devbox run client-test # Vitest: pure reducer + protocol client + envelope (no DOM, no GPU) +devbox run e2e # builds client/dist, then Chromium against the real server through the + # TLS/HTTP2 test nginx (client/e2e/*.test.mjs, playwright-core) +devbox run test # the server gate; unaffected by the client +devbox run -- bash -c 'cd client && npm run dev' # local dev (Vite, no server API on :5173) +``` + +`npm run build` = `tsc --noEmit && vite build` into `client/dist`, which the test/production nginx +serves at `/` (DESIGN §11.1). `client/dist` and `client/node_modules` are not committed. + +## The one seam that matters + +`src/reducer.ts` is pure: server frames and connection events in, state out. **It must never import +Pixi, the DOM, or the socket.** Its unit tests (`test/*.test.ts`) are the contract. Everything else +is wiring: + +| File | Owns | +|---|---| +| `src/protocol.ts` | Wire types, envelope/ack/closing guards, intent encoding, `/ws?proto=2` URL. Pure. | +| `src/reducer.ts` | `RootState`, phase machine (`boot/connecting/signin/live/reload/offline`), `hello` reset, slice registry. Pure. | +| `src/slices/*.ts` | Append-only domain state (roster today; fog, tokens, walls, panels later). | +| `src/ws.ts` | Socket, `reqId` counter, pending map, close-code mapping. No DOM. | +| `src/shell.ts` | Sign-in, HUD/roster, fatal screens. Plain DOM, `textContent` only. | +| `src/render/stage.ts` | One Pixi `Application`, one world container, fixed layers. Pixi lives here and in modules only. | +| `src/render/modules/*.ts` | Append-only render modules. | +| `src/main.ts` | Wiring: store -> shell/stage, `/join`, connect. | + +## Convention for the M4 fan-out (T7, T8/T9, T10, T11/T12) + +The registry is a **build-time glob**, so parallel tickets are file-disjoint: no shared import list +to merge and no registry file to edit. + +- **State slice**: add `src/slices/.ts` exporting `export const slice: Slice` + (`name`, `init()`, `reduce(state, event, root)`). It is registered automatically. Read it with + `sliceOf(state, '')`. `hello` resets every slice for you (DESIGN §6.3): never + keep server-derived state outside a slice or the core session. +- **Render module**: add `src/render/modules/.ts` exporting + `export const renderModule: RenderModule` (`name`, `mount(context)`, optional teardown). Draw into + your layer: `tiles`, `grid`, `tokens`, `fog` (players), `gm` (GM only), `dom`. +- **Panel/DOM**: add `src/panels/.ts` and mount under the existing `#panels` host; do not + rewrite the sign-in flow. Server strings go through `textContent` (never `innerHTML`); token + labels use `BitmapText` with the pre-installed `BitmapFont` (DESIGN §7.2). +- **No per-frame full redraw**: subscribe to the store and touch only entities that changed + (DESIGN §7.2). Keep the DOM overlay work per frame minimal. +- **Protocol**: only the catalogue in DESIGN §6.1. The client ignores unknown frame types/fields + (§6.2). `closing` reasons map through `closeOutcome`: `proto-mismatch` -> reload, `revoked` -> + sign-in, `evicted`/`malformed-flood` -> offline. Do not invent wire fields; server-side additions + are separate tickets (e.g. `seen_by`, T12). + +Suggested ownership (no file overlap): T7 fog = `slices/fog.ts` + `render/modules/fog.ts`; T8/T9 +tokens/drag = `slices/tokens.ts`, `slices/move.ts`, `render/modules/tokens.ts`; T10 walls = +`slices/walls.ts` + `render/modules/walls.ts`; T11/T12 GM panels = `slices/admin.ts` + +`src/panels/*.ts`. `src/reducer.ts`, `src/main.ts` and `src/render/stage.ts` are already generic; +change them only if a slice needs a new *core* event, and say so in the PR. + +## Protocol notes already encoded + +- `/ws?proto=2`; a mismatch is `closing{reason:"proto-mismatch",code:4003}` then close. The reason + is read from the last `closing` frame because browsers report 1005 at the mummy pin (ADR-0019). +- `hello` resets all state; the resync after it rebuilds the view. Pending `reqId`s survive a + `hello` on a live connection and die with the socket (DESIGN §6.3). +- Sign-in is `POST /join` (form body, key never in the URL). A `401` for a wrong key and for an + unknown key is shown as the same "Key not recognised." (DESIGN §3.2, story 3). +- No game data (and no Pixi `Application`) exists before a live `hello`; a visitor without a session + only sees the sign-in page. diff --git a/client/e2e/h2.test.mjs b/client/e2e/h2.test.mjs new file mode 100644 index 0000000..5ead4e9 --- /dev/null +++ b/client/e2e/h2.test.mjs @@ -0,0 +1,55 @@ +// The browser half of the vhost gate (#66, TESTING 10.3): real Chromium loads the real client build +// from `/` through the TLS/HTTP2 test nginx and reports h2 for the document and its hashed assets. +// The client bundle replaces the throwaway `tools/distfixture.mjs` of #66; `client/e2e/run.sh` +// builds it before this test runs. +import test from 'node:test' +import assert from 'node:assert/strict' +import { launchBrowser, newPage, withStack } from './stack.mjs' + +test('e2e: headless chromium loads the real client build and the page reports h2', { timeout: 120000 }, async () => { + await withStack(async ({ origin }) => { + const browser = await launchBrowser() + try { + const { page } = await newPage(browser) + const loaded = [] + page.on('response', response => loaded.push({ url: response.url(), status: response.status() })) + const errors = [] + page.on('pageerror', error => errors.push(error.message)) + page.on('console', message => { + // The boot probe's refused WebSocket upgrade is the expected no-session path (the browser + // logs it); it is not a page error. Everything else must be silent. + if (message.type() === 'error' && !message.text().includes('WebSocket connection')) { + errors.push(message.text()) + } + }) + + await page.goto(`${origin}/`, { waitUntil: 'load' }) + + assert.equal(await page.title(), 'FFF VTT') + await page.locator('#app').waitFor({ state: 'attached' }) + // A visitor with no session gets the sign-in door; the canvas is created only after `hello`. + await page.locator('#signin').waitFor({ state: 'visible', timeout: 20000 }) + assert.deepEqual(errors, []) + + const assets = loaded.filter(response => new URL(response.url).pathname.startsWith('/assets/')) + assert.ok(assets.length > 0, `the page loaded hashed assets: ${JSON.stringify(loaded)}`) + assert.ok(assets.every(response => response.status === 200)) + + const proto = await page.evaluate(() => { + const navigation = performance.getEntriesByType('navigation')[0] + const resources = performance + .getEntriesByType('resource') + .map(entry => ({ name: entry.name, protocol: entry.nextHopProtocol })) + return { scheme: location.protocol, navigation: navigation.nextHopProtocol, resources } + }) + assert.equal(proto.scheme, 'https:') + assert.equal(proto.navigation, 'h2', 'the document came over HTTP/2') + assert.ok( + proto.resources.some(resource => resource.protocol === 'h2' && resource.name.endsWith('.js')), + `subresources are h2 too: ${JSON.stringify(proto.resources)}`, + ) + } finally { + await browser.close() + } + }) +}) diff --git a/client/e2e/mismatch.test.mjs b/client/e2e/mismatch.test.mjs new file mode 100644 index 0000000..bf76232 --- /dev/null +++ b/client/e2e/mismatch.test.mjs @@ -0,0 +1,38 @@ +// 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) + 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() + } + }) +}) diff --git a/client/e2e/run.sh b/client/e2e/run.sh new file mode 100755 index 0000000..8e6949f --- /dev/null +++ b/client/e2e/run.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash +# devbox run e2e: the headless-browser gate (TESTING 10.3). Builds the real client, then runs the +# browser suite against the real server through the TLS/HTTP2 test nginx. Separate from +# `devbox run test` so the fast server gate stays fast (TESTING 11.1); the client's own unit tests +# are `devbox run client-test`. +set -euo pipefail +cd "$(dirname "$0")/../.." || exit 1 +mkdir -p results +export CHROMIUM="${CHROMIUM:-$(command -v chromium || true)}" +if [ -z "$CHROMIUM" ]; then + echo "e2e: chromium not found; it is a root devbox package (devbox.json) - run inside devbox" >&2 + exit 1 +fi +# npm deps stay out of tools/ (TESTING 10.4) and out of git; install once per checkout. +( cd client && { [ -d node_modules ] || npm ci --no-audit --no-fund; } ) +( cd client && npm run build ) +node --test --test-concurrency=1 --test-reporter=spec client/e2e/*.test.mjs > results/e2e.log 2>&1 +rc=$? +cat results/e2e.log +exit $rc diff --git a/client/e2e/shell.test.mjs b/client/e2e/shell.test.mjs new file mode 100644 index 0000000..ad112e8 --- /dev/null +++ b/client/e2e/shell.test.mjs @@ -0,0 +1,103 @@ +// T4 client shell (#67, TESTING 10.3): join -> canvas -> hello/roster for the GM and a player, no +// data before join, one plain refusal for a wrong and an unknown key, and a revoked session +// returning to sign-in. The server, the nginx vhost and the client are the real ones. +import test from 'node:test' +import assert from 'node:assert/strict' +import { sleep } from '../../tools/lib.mjs' +import { openAs } from '../../tools/withserver.mjs' +import { + launchBrowser, + makePlayer, + newPage, + signIn, + waitForText, + waitForVisible, + withStack, +} from './stack.mjs' + +const KEY_REFUSED = 'Key not recognised.' + +async function canvasAndRoster(page, expectedNames) { + await waitForVisible(page, '#stage canvas') + await waitForVisible(page, '#hud') + const roster = await waitForText(page, '#roster', new RegExp(expectedNames[0])) + for (const name of expectedNames) assert.match(roster, new RegExp(name)) + return roster +} + +test('no session: only the sign-in page, and a wrong and an unknown key look identical', { timeout: 120000 }, async () => { + await withStack(async ({ origin }) => { + const browser = await launchBrowser() + try { + const { page } = await newPage(browser) + const joins = [] + page.on('response', response => { + if (new URL(response.url()).pathname === '/join') joins.push(response.status()) + }) + + await page.goto(`${origin}/`) + await waitForVisible(page, '#signin') + // Story 1: a stranger gets the door and no game data. + assert.equal(await page.locator('#stage').isVisible(), false) + assert.equal(await page.locator('#hud').isVisible(), false) + assert.equal(await page.locator('#roster li').count(), 0) + + // Story 3: the same answer for a well-formed but wrong key and for an unknown one. + await signIn(page, 'ABCD-EFGH-JKMN-PQRS') + await waitForVisible(page, '#signin-error') + const wrong = await page.textContent('#signin-error') + await signIn(page, 'not-a-key') + await waitForVisible(page, '#signin-error') + const unknown = await page.textContent('#signin-error') + assert.equal(wrong, KEY_REFUSED) + assert.equal(unknown, KEY_REFUSED) + assert.deepEqual(joins, [401, 401]) + + // No map request was made before a session existed. + assert.equal(await page.locator('#stage canvas').count(), 0) + } finally { + await browser.close() + } + }) +}) + +test('GM and player: join -> canvas -> hello and roster; revoked returns to sign-in', { timeout: 120000 }, async () => { + await withStack(async ({ origin, gmKey }) => { + const player = await makePlayer(origin, gmKey, 'Alice') + const browser = await launchBrowser() + try { + const gmView = await newPage(browser) + await gmView.page.goto(`${origin}/`) + await waitForVisible(gmView.page, '#signin') + await signIn(gmView.page, gmKey) + const gmRoster = await canvasAndRoster(gmView.page, ['GM', 'Alice']) + assert.equal(await gmView.page.textContent('#role'), 'GM') + assert.match(gmRoster, /connected/) + + const playerView = await newPage(browser) + await playerView.page.goto(`${origin}/`) + await waitForVisible(playerView.page, '#signin') + await signIn(playerView.page, player.key) + await canvasAndRoster(playerView.page, ['GM', 'Alice']) + assert.equal(await playerView.page.textContent('#role'), 'Player') + assert.equal(await playerView.page.textContent('#me'), 'Alice') + + // Story 10: the GM replaces the key, the server revokes the session, and the browser stops + // at the sign-in door instead of hammering a dead socket. + const gm = await openAs(origin, gmKey) + await gm.ws.waitText('hello') + const ack = await gm.ws.request({ t: 'key.replace', id: player.id }) + assert.equal(ack.ok, true) + gm.ws.close() + await waitForVisible(playerView.page, '#signin') + await waitForText(playerView.page, '#signin-notice', /session has ended/i) + assert.equal(await playerView.page.locator('#stage canvas').count(), 0) + assert.equal(await playerView.page.locator('#roster li').count(), 0) + // No automatic reconnection: still on the sign-in page a moment later. + await sleep(300) + assert.equal(await playerView.page.locator('#signin').isVisible(), true) + } finally { + await browser.close() + } + }) +}) diff --git a/client/e2e/stack.mjs b/client/e2e/stack.mjs new file mode 100644 index 0000000..e6824b4 --- /dev/null +++ b/client/e2e/stack.mjs @@ -0,0 +1,96 @@ +// Shared stack for the client e2e (TESTING 10.3): the real client build served by the TLS/HTTP2 +// test nginx in front of the real server binary. Never a fixture, never a mocked protocol. +import assert from 'node:assert/strict' +import fs from 'node:fs' +import path from 'node:path' +import { chromium } from 'playwright-core' +import { createPlayer, freePort, httpsBaseUrl, namePlayer, projectRoot, sleep } from '../../tools/lib.mjs' +import { gmKeyOf, makeStateDir, openAs, startServer, stopServer } from '../../tools/withserver.mjs' +import { startTestNginx, stopTestNginx } from '../../tools/nginx.mjs' + +export const CHROMIUM = process.env.CHROMIUM ?? 'chromium' +export const LAUNCH_ARGS = [ + '--no-sandbox', + '--use-angle=swiftshader', + '--enable-unsafe-swiftshader', + '--ignore-gpu-blocklist', +] + +export const CLIENT_DIST = path.join(projectRoot, 'client', 'dist') + +export function assertClientBuild() { + assert.ok( + fs.existsSync(path.join(CLIENT_DIST, 'index.html')), + `client build missing at ${CLIENT_DIST}: run \`npm run build\` in client/ (client/e2e/run.sh does)`, + ) +} + +export async function withStack(fn) { + assertClientBuild() + const stateDir = makeStateDir() + const gmKey = gmKeyOf(stateDir) + const nginxPort = await freePort() + const server = await startServer({ stateDir, publicOrigin: httpsBaseUrl(nginxPort) }) + let nginx + try { + nginx = await startTestNginx({ + backendPort: server.port, + stateDir, + port: nginxPort, + distDir: CLIENT_DIST, + }) + return await fn({ stateDir, server, nginx, origin: nginx.origin, gmKey }) + } finally { + if (nginx) await stopTestNginx(nginx) + await stopServer(server) + fs.rmSync(stateDir, { recursive: true, force: true }) + } +} + +export async function launchBrowser() { + return chromium.launch({ executablePath: CHROMIUM, args: LAUNCH_ARGS }) +} + +export async function newPage(browser) { + // The certificate is generated per run by tools/tlsdev.mjs; trusting it in the browser is the + // one concession, the rest of the page is the real https/h2 path. + const context = await browser.newContext({ ignoreHTTPSErrors: true, viewport: { width: 1000, height: 700 } }) + return { context, page: await context.newPage() } +} + +/** A named player created the way the product creates one: a GM key.create, then player.setname. */ +export async function makePlayer(origin, gmKey, name) { + const gm = await openAs(origin, gmKey) + await gm.ws.waitText('hello') + const created = await createPlayer(gm.ws) + await namePlayer(origin, created.key, name) + gm.ws.close() + await gm.ws.closed + return { id: created.id, key: created.key, name } +} + +export async function signIn(page, key) { + await page.fill('#key', key) + await page.click('#signin-submit') +} + +export async function waitForVisible(page, selector, timeout = 20000) { + await page.locator(selector).waitFor({ state: 'visible', timeout }) +} + +export async function waitForHidden(page, selector, timeout = 20000) { + await page.locator(selector).waitFor({ state: 'hidden', timeout }) +} + +export async function waitForText(page, selector, pattern, timeout = 20000) { + const deadline = Date.now() + timeout + let last = '' + while (Date.now() < deadline) { + last = (await page.locator(selector).textContent()) ?? '' + if (pattern.test(last)) return last + await sleep(50) + } + throw new Error(`${selector} never matched ${pattern}: last was ${JSON.stringify(last)}`) +} + +export { sleep } diff --git a/client/index.html b/client/index.html new file mode 100644 index 0000000..1c6de0d --- /dev/null +++ b/client/index.html @@ -0,0 +1,12 @@ + + + + + + FFF VTT + + +
+ + + diff --git a/client/package-lock.json b/client/package-lock.json new file mode 100644 index 0000000..9944cef --- /dev/null +++ b/client/package-lock.json @@ -0,0 +1,1342 @@ +{ + "name": "fff-vtt-client", + "version": "0.1.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "fff-vtt-client", + "version": "0.1.0", + "dependencies": { + "pixi.js": "8.23.0" + }, + "devDependencies": { + "playwright-core": "1.65.1", + "typescript": "5.9.3", + "vite": "8.3.8", + "vitest": "5.1.1" + } + }, + "node_modules/@emnapi/core": { + "version": "2.0.0-beta.2", + "resolved": "https://registry.npmjs.org/@emnapi/core/-/core-2.0.0-beta.2.tgz", + "integrity": "sha512-MzCVoWtcg4Pm2B3je5mMvYMvj3MmBKw+fU7vbsJc9/iT8ip6/eYIHo/Dsm/mr+wsHB6SEyJDuxB09Yy6r/8+4A==", + "dev": true, + "license": "MIT", + "optional": true, + "dependencies": { + "@emnapi/wasi-threads": "2.2.0", + "tslib": "^2.4.0" + } + }, + "node_modules/@emnapi/runtime": { + "version": "2.0.0-beta.2", + "resolved": "https://registry.npmjs.org/@emnapi/runtime/-/runtime-2.0.0-beta.2.tgz", + "integrity": "sha512-JcrSPzPvZuNZvJqPTF9Fw25LbOJ8avzFVlaf2grmH4Cku0oGP47tRgqPZadcfj3YoZMHkFVnCYFbQM8I+i5QEw==", + "dev": true, + "license": "MIT", + "optional": true, + "dependencies": { + "tslib": "^2.4.0" + } + }, + "node_modules/@emnapi/wasi-threads": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/@emnapi/wasi-threads/-/wasi-threads-2.2.0.tgz", + "integrity": "sha512-JP7OYH38Q7+pyTAe14raZHLQIK7BDKbdwji+Xi3pcd/6QkJYQH3SX4wu6EplGrGJWRepoNzedfm0G3B9Z4e9Rw==", + "dev": true, + "license": "MIT", + "optional": true, + "dependencies": { + "tslib": "^2.4.0" + } + }, + "node_modules/@jridgewell/resolve-uri": { + "version": "3.1.3", + "resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.3.tgz", + "integrity": "sha512-lhTtjtoEArWBjismtfS761S9Hlyn+nIZqOZVYoZ1Xn82PMNMVnk+jj/NhC4fAXGTs7ydONcJiR5vyQBTMDu27g==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=6.0.0" + } + }, + "node_modules/@jridgewell/sourcemap-codec": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.6.0.tgz", + "integrity": "sha512-T7jf+5zgsZHwNJ4lvQ7/aezbyk0nNX+zJVWpmHA7VYsEx7a7qr5Rg5IbtJFqkgze5Y2sruq1RUY8Q837Od7iFw==", + "dev": true, + "license": "MIT" + }, + "node_modules/@jridgewell/trace-mapping": { + "version": "0.3.31", + "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.31.tgz", + "integrity": "sha512-zzNR+SdQSDJzc8joaeP8QQoCQr8NuYx2dIIytl1QeBEZHJ9uW6hebsrYgbz8hJwUQao3TWCMtmfV8Nu1twOLAw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@jridgewell/resolve-uri": "^3.1.0", + "@jridgewell/sourcemap-codec": "^1.4.14" + } + }, + "node_modules/@napi-rs/wasm-runtime": { + "version": "1.2.6", + "resolved": "https://registry.npmjs.org/@napi-rs/wasm-runtime/-/wasm-runtime-1.2.6.tgz", + "integrity": "sha512-mRyDmEw9/fCDXCGfL1sbgIw/GUK0PVxRW4YwgPN61F3LQ+fSyoBFarJVzgGyhF6kRzEQZ0FejDqm4WLXSeqQmw==", + "dev": true, + "license": "MIT", + "optional": true, + "dependencies": { + "@tybys/wasm-util": "^0.10.3" + }, + "engines": { + "node": "^20.19.0 || ^22.13.0 || >=23.5.0" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/Brooooooklyn" + }, + "peerDependencies": { + "@emnapi/core": "^1.7.1 || 2.0.0-beta.2", + "@emnapi/runtime": "^1.7.1 || 2.0.0-beta.2" + } + }, + "node_modules/@oxc-project/types": { + "version": "0.156.0", + "resolved": "https://registry.npmjs.org/@oxc-project/types/-/types-0.156.0.tgz", + "integrity": "sha512-1Duyg48TdJNdyhEB8Xn1L36bT9Pv6GUtlKjHxOys8xkaF/rQq3XJE+bAurSK/AgIz5mGFsb77cn9Pb20+WCScw==", + "dev": true, + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/oxc-project" + } + }, + "node_modules/@rolldown/binding-android-arm-eabi": { + "version": "1.2.19", + "resolved": "https://registry.npmjs.org/@rolldown/binding-android-arm-eabi/-/binding-android-arm-eabi-1.2.19.tgz", + "integrity": "sha512-e+Ebe0WT+9tbXmNKPIiC8YrWAHYwug3m6i4p3rZGGulfZri1jtI4HslT+OZnFf/OIHowWF71DTlHwXBP2SiA7A==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-android-arm64": { + "version": "1.2.19", + "resolved": "https://registry.npmjs.org/@rolldown/binding-android-arm64/-/binding-android-arm64-1.2.19.tgz", + "integrity": "sha512-hOombrTJ+szt2ciEzS7oCA78lMPBgF5UMQWCJIyNfnrI7GLl8HYoFqCnpL2gcPOaXMqryGCU5ExdQKyDDcC+yA==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-darwin-arm64": { + "version": "1.2.19", + "resolved": "https://registry.npmjs.org/@rolldown/binding-darwin-arm64/-/binding-darwin-arm64-1.2.19.tgz", + "integrity": "sha512-XoMA2pwCKGTQzUjPgtRwkedH4WmXhdIPKT6l6oOxd1PUbNodGI6DcBekgN7EC//+x3pfBYX/qL1gNmZAqivw5g==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-darwin-x64": { + "version": "1.2.19", + "resolved": "https://registry.npmjs.org/@rolldown/binding-darwin-x64/-/binding-darwin-x64-1.2.19.tgz", + "integrity": "sha512-zo8EsSSwMZCY/e+fRnGaX02YGgvJD0yvhNi/9hpGPA2MJ9ZF8dPCw75UGfpI6OpQ/myR/dIYmogRvqiZD0TrXg==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-freebsd-x64": { + "version": "1.2.19", + "resolved": "https://registry.npmjs.org/@rolldown/binding-freebsd-x64/-/binding-freebsd-x64-1.2.19.tgz", + "integrity": "sha512-O8ISAOfI1nj7AuBPd30FSF47z7f7lzlk5poQVGgiikvQuGEBFYvW8ki+UEnT+YJPnNGjQzn304klt4O9FUE7mA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-linux-arm-gnueabihf": { + "version": "1.2.19", + "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-arm-gnueabihf/-/binding-linux-arm-gnueabihf-1.2.19.tgz", + "integrity": "sha512-/lYCba5NO0yq4S0jGMH8QTBtkvQxoXjoQWzF5BcWp9MjB9jxVRD1GQDNofkVjcOj30DWyhLIN/4Oe60JKzaONw==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-linux-arm64-gnu": { + "version": "1.2.19", + "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-arm64-gnu/-/binding-linux-arm64-gnu-1.2.19.tgz", + "integrity": "sha512-pm/apFMBnSbFb3O6nG5pHO1iqHhZrjGDFEjSm+ot9J17XXPvH9L90y5h+jgfHCE+Qdlsvy8qKEcU4VKxgjD+vA==", + "cpu": [ + "arm64" + ], + "dev": true, + "libc": [ + "glibc" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-linux-arm64-musl": { + "version": "1.2.19", + "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-arm64-musl/-/binding-linux-arm64-musl-1.2.19.tgz", + "integrity": "sha512-K1SmQp3FFichn8oqrNIwvFoZ5wcvjC7goBzpaMNvLf9FZc+QB/QvLmnpJZgAAGHiD980tP8FZZnXk2K94rvlxg==", + "cpu": [ + "arm64" + ], + "dev": true, + "libc": [ + "musl" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-linux-ppc64-gnu": { + "version": "1.2.19", + "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-ppc64-gnu/-/binding-linux-ppc64-gnu-1.2.19.tgz", + "integrity": "sha512-I0xwD57jP/3A7+5UPZin2w8Y7XHEmEM5zqpYZOcQ45MlNW6tUJUziymV3yRr7rL4vwyfEcRsRksC4a7Kc08p5Q==", + "cpu": [ + "ppc64" + ], + "dev": true, + "libc": [ + "glibc" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-linux-s390x-gnu": { + "version": "1.2.19", + "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-s390x-gnu/-/binding-linux-s390x-gnu-1.2.19.tgz", + "integrity": "sha512-BrtEHT24SNXj9HiXqy+s/kXiSiQGt6EKCPUlRirAoIioVxKGnbXBUEkbZASAei7iZJB0/Ynm+0JP00Ipx7AnSw==", + "cpu": [ + "s390x" + ], + "dev": true, + "libc": [ + "glibc" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-linux-x64-gnu": { + "version": "1.2.19", + "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-x64-gnu/-/binding-linux-x64-gnu-1.2.19.tgz", + "integrity": "sha512-rm75/9DkHKeU2WnA8w4X94WGYgLlDCFCfkQC+4bguVJmC/jvDRv2B+2wLOYhyE0fVuv7//Ckk39OoOufyCu76Q==", + "cpu": [ + "x64" + ], + "dev": true, + "libc": [ + "glibc" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-linux-x64-musl": { + "version": "1.2.19", + "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-x64-musl/-/binding-linux-x64-musl-1.2.19.tgz", + "integrity": "sha512-irh/4+iYFM4GAzpluDErgjz89bj6NDtqqMAG/6O1LG38Ed3NpyebzCpcVNkFW8uhy+/3/BocUvnXDR33CXWe9A==", + "cpu": [ + "x64" + ], + "dev": true, + "libc": [ + "musl" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-openharmony-arm64": { + "version": "1.2.19", + "resolved": "https://registry.npmjs.org/@rolldown/binding-openharmony-arm64/-/binding-openharmony-arm64-1.2.19.tgz", + "integrity": "sha512-+KWTWNoPt+CfSq94CiceWu3yPE+QzkaG+phPyz9G60tmZLwfQkcA4AeksafzvJAw4pvg1mcd5a1TkUqVv0s4JA==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openharmony" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-wasm32-wasi": { + "version": "1.2.19", + "resolved": "https://registry.npmjs.org/@rolldown/binding-wasm32-wasi/-/binding-wasm32-wasi-1.2.19.tgz", + "integrity": "sha512-7EH+skOsl5qpWnK0vzamgJFhOv1cwxQpsxm8tI883K9fur5c27p8q87fzEO6BbBPabA2/+s/zR63/pLc137iOg==", + "cpu": [ + "wasm32" + ], + "dev": true, + "license": "MIT", + "optional": true, + "dependencies": { + "@emnapi/core": "2.0.0-beta.2", + "@emnapi/runtime": "2.0.0-beta.2", + "@napi-rs/wasm-runtime": "1.2.6" + }, + "engines": { + "node": "^20.19.0 || ^22.13.0 || >=23.5.0" + } + }, + "node_modules/@rolldown/binding-win32-arm64-msvc": { + "version": "1.2.19", + "resolved": "https://registry.npmjs.org/@rolldown/binding-win32-arm64-msvc/-/binding-win32-arm64-msvc-1.2.19.tgz", + "integrity": "sha512-3Q1Yg1Q7tEvBWoZf5rFvG/GKZQPgwfru+p4wBajDfJFBs0SHCpL++dfTjW9gyAKd1T7ZpIYvdaUax7Pa/IhFVQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-win32-x64-msvc": { + "version": "1.2.19", + "resolved": "https://registry.npmjs.org/@rolldown/binding-win32-x64-msvc/-/binding-win32-x64-msvc-1.2.19.tgz", + "integrity": "sha512-y/sqRRc6d7hECzOFc5n3LSeqctmIp9mMjY1Kq4s14uLPd/LZ4z7i1zrW6fMtp2mPeuQIC4e6ULMcwQzMomqQag==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/pluginutils": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/@rolldown/pluginutils/-/pluginutils-1.1.1.tgz", + "integrity": "sha512-glFIJDvLNDtJhT9qrMFWLPbvS+skxgt4L0K8Ei2YtnhPysAJnsI7nyxSJxKj4ADeKX0OLjC4ntRkwpLOoS3rwA==", + "dev": true, + "license": "MIT" + }, + "node_modules/@tybys/wasm-util": { + "version": "0.10.5", + "resolved": "https://registry.npmjs.org/@tybys/wasm-util/-/wasm-util-0.10.5.tgz", + "integrity": "sha512-dOGOPxlaNV+G046mZzN+9C0dAcQZeSKcXiVaM0TYy/LM4ttTmgSBDxYfovcYI8Em3+eAbiAYpvWLOv8+ZVRJKA==", + "dev": true, + "license": "MIT", + "optional": true, + "dependencies": { + "tslib": "^2.4.0" + } + }, + "node_modules/@types/chai": { + "version": "5.2.3", + "resolved": "https://registry.npmjs.org/@types/chai/-/chai-5.2.3.tgz", + "integrity": "sha512-Mw558oeA9fFbv65/y4mHtXDs9bPnFMZAL/jxdPFUpOHHIXX91mcgEHbS5Lahr+pwZFR8A7GQleRWeI6cGFC2UA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/deep-eql": "*", + "assertion-error": "^2.0.1" + } + }, + "node_modules/@types/deep-eql": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/@types/deep-eql/-/deep-eql-4.0.2.tgz", + "integrity": "sha512-c9h9dVVMigMPc4bwTvC5dxqtqJZwQPePsWjPlpSOnojbor6pGqdk541lfA7AqFQr5pB1BRdq0juY9db81BwyFw==", + "dev": true, + "license": "MIT" + }, + "node_modules/@types/earcut": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/@types/earcut/-/earcut-3.0.0.tgz", + "integrity": "sha512-k/9fOUGO39yd2sCjrbAJvGDEQvRwRnQIZlBz43roGwUZo5SHAmyVvSFyaVVZkicRVCaDXPKlbxrUcBuJoSWunQ==", + "license": "MIT" + }, + "node_modules/@types/estree": { + "version": "1.0.10", + "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.10.tgz", + "integrity": "sha512-lTyOMnOcmRBzdCv6/4zUZCrEhV0xrqQiUZBZtVcbmLHBXKLnN8q89v/wKRF/Q0HbwVsqbIG3o5HDoFl9sduM+g==", + "dev": true, + "license": "MIT" + }, + "node_modules/@vitest/mocker": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/@vitest/mocker/-/mocker-5.1.1.tgz", + "integrity": "sha512-b2OgTB4+3ImWIVafXKazJXwLKwQxUNnix6b3xUvUTMh7RyXlrtzoxfZr8aEz9zkHOMAS4K5lu3TvFWoiVeVTQg==", + "dev": true, + "license": "MIT", + "dependencies": { + "@jridgewell/trace-mapping": "0.3.31", + "@vitest/spy": "5.1.1", + "estree-walker": "^3.0.3", + "magic-string": "^1.4.5" + }, + "funding": { + "url": "https://opencollective.com/vitest" + }, + "peerDependencies": { + "msw": "^2.4.9 || ^3.0.0", + "vite": "^6.0.0 || ^7.0.0 || ^8.0.0" + }, + "peerDependenciesMeta": { + "msw": { + "optional": true + }, + "vite": { + "optional": true + } + } + }, + "node_modules/@vitest/spy": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/@vitest/spy/-/spy-5.1.1.tgz", + "integrity": "sha512-6K8C6alQG1/Yc8/ZI22iJS7JEsxPdVzqtqDq+/xM4Z0mGVykemMVjLhqMy/q6/IHYG3kKD8hKSwRen/ZdyI9vQ==", + "dev": true, + "license": "MIT", + "funding": { + "url": "https://opencollective.com/vitest" + } + }, + "node_modules/@webgpu/types": { + "version": "0.1.74", + "resolved": "https://registry.npmjs.org/@webgpu/types/-/types-0.1.74.tgz", + "integrity": "sha512-lgiI4hbuLcI9unnm2cL/tvCaQU45dp0xcLWJh5uB/9MBGvIA4F8XIk7nSiBeg+K4xWGYwgZKn80LmERI5CxoTA==", + "license": "BSD-3-Clause" + }, + "node_modules/@xmldom/xmldom": { + "version": "0.8.15", + "resolved": "https://registry.npmjs.org/@xmldom/xmldom/-/xmldom-0.8.15.tgz", + "integrity": "sha512-/5NV/vDALVFDXgLmfsy9TRCBlKwO2LNBFzpzvb9iIj+jR+eSc6DLYYvVOdivT/jm7MtU6TebYuRmzEOI7w40UA==", + "license": "MIT", + "engines": { + "node": ">=10.0.0" + } + }, + "node_modules/assertion-error": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-2.0.1.tgz", + "integrity": "sha512-Izi8RQcffqCeNVgFigKli1ssklIbpHnCYc6AknXGYoB6grJqyeby7jv12JUQgmTAnIDnbck1uxksT4dzN3PWBA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12" + } + }, + "node_modules/chai": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/chai/-/chai-6.3.0.tgz", + "integrity": "sha512-XWAtwJ6OHO+tj0EKCs0Y2UamnyOxseZWltU4x2U2wh8g4AigdjwvtUjvLP2tqkA/avxHEtzxNaqGq/YGNwckKg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=18" + } + }, + "node_modules/colord": { + "version": "2.14.0", + "resolved": "https://registry.npmjs.org/colord/-/colord-2.14.0.tgz", + "integrity": "sha512-eSdMel9EBvdFxnchObp7gljRoqYQLr+zXhaxjkym7syVphw1FIhfQwgsA5Bv3jArflZPJEa1rmQtGpa7NRc7Rw==", + "license": "MIT" + }, + "node_modules/detect-libc": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.1.2.tgz", + "integrity": "sha512-Btj2BOOO83o3WyH59e8MgXsxEQVcarkUOpEYrubB0urwnN10yQ364rsiByU11nZlqWYZm05i/of7io4mzihBtQ==", + "dev": true, + "license": "Apache-2.0", + "engines": { + "node": ">=8" + } + }, + "node_modules/earcut": { + "version": "3.2.4", + "resolved": "https://registry.npmjs.org/earcut/-/earcut-3.2.4.tgz", + "integrity": "sha512-FHc6yNpnTORB0tM5kmZ03iD2mDuNakDE2lvf4Hw1XkfxtEHIGVi01B/GqUSwx+NcC1WGjidAfpTXzeALtPtfpg==", + "license": "ISC" + }, + "node_modules/es-module-lexer": { + "version": "2.3.2", + "resolved": "https://registry.npmjs.org/es-module-lexer/-/es-module-lexer-2.3.2.tgz", + "integrity": "sha512-poHGpORABojJJucnV9KbOavETW8lBVnphkW77ER5/BQ5Fz7oXSoCNek7IH3vR5nRjdsEz926ibFYX8KtLQmdyw==", + "dev": true, + "license": "MIT" + }, + "node_modules/estree-walker": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-3.0.3.tgz", + "integrity": "sha512-7RUKfXgSMMkzt6ZuXmqapOurLGPPfgj6l9uRZ7lRGolvk0y2yocc35LdcxKC5PQZdn2DMqioAQ2NoWcrTKmm6g==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/estree": "^1.0.0" + } + }, + "node_modules/eventemitter3": { + "version": "5.0.4", + "resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-5.0.4.tgz", + "integrity": "sha512-mlsTRyGaPBjPedk6Bvw+aqbsXDtoAyAzm5MO7JgU+yVRyMQ5O8bD4Kcci7BS85f93veegeCPkL8R4GLClnjLFw==", + "license": "MIT" + }, + "node_modules/expect-type": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/expect-type/-/expect-type-1.4.0.tgz", + "integrity": "sha512-KfYbmpRm0VbLjEvVa9yGwCi9GI34xvi7A/HXYWQO65CSD2u3MczUJSuwXKFIxlGsgBQizV9q5J9NHj4VG0n+pA==", + "dev": true, + "license": "Apache-2.0", + "engines": { + "node": ">=12.0.0" + } + }, + "node_modules/fdir": { + "version": "6.5.0", + "resolved": "https://registry.npmjs.org/fdir/-/fdir-6.5.0.tgz", + "integrity": "sha512-tIbYtZbucOs0BRGqPJkshJUYdL+SDH7dVM8gjy+ERp3WAUjLEFJE+02kanyHtwjWOnwrKYBiwAmM0p4kLJAnXg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12.0.0" + }, + "peerDependencies": { + "picomatch": "^3 || ^4" + }, + "peerDependenciesMeta": { + "picomatch": { + "optional": true + } + } + }, + "node_modules/fsevents": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", + "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", + "dev": true, + "hasInstallScript": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^8.16.0 || ^10.6.0 || >=11.0.0" + } + }, + "node_modules/gifuct-js": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/gifuct-js/-/gifuct-js-2.1.2.tgz", + "integrity": "sha512-rI2asw77u0mGgwhV3qA+OEgYqaDn5UNqgs+Bx0FGwSpuqfYn+Ir6RQY5ENNQ8SbIiG/m5gVa7CD5RriO4f4Lsg==", + "license": "MIT", + "dependencies": { + "js-binary-schema-parser": "^2.0.3" + } + }, + "node_modules/ismobilejs": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/ismobilejs/-/ismobilejs-1.1.1.tgz", + "integrity": "sha512-VaFW53yt8QO61k2WJui0dHf4SlL8lxBofUuUmwBo0ljPk0Drz2TiuDW4jo3wDcv41qy/SxrJ+VAzJ/qYqsmzRw==", + "license": "MIT" + }, + "node_modules/js-binary-schema-parser": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/js-binary-schema-parser/-/js-binary-schema-parser-2.0.3.tgz", + "integrity": "sha512-xezGJmOb4lk/M1ZZLTR/jaBHQ4gG/lqQnJqdIv4721DMggsa1bDVlHXNeHYogaIEHD9vCRv0fcL4hMA+Coarkg==", + "license": "MIT" + }, + "node_modules/lightningcss": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss/-/lightningcss-1.33.0.tgz", + "integrity": "sha512-WkUDrojuJs0xkgGf2udWxa3yGBRxPtxUkB79i6aCZLRgc7PM8fZe9TosfPDcvEpQZbuFASnHYmRLBLUbmLOIIA==", + "dev": true, + "license": "MPL-2.0", + "dependencies": { + "detect-libc": "^2.0.3" + }, + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + }, + "optionalDependencies": { + "lightningcss-android-arm64": "1.33.0", + "lightningcss-darwin-arm64": "1.33.0", + "lightningcss-darwin-x64": "1.33.0", + "lightningcss-freebsd-x64": "1.33.0", + "lightningcss-linux-arm-gnueabihf": "1.33.0", + "lightningcss-linux-arm64-gnu": "1.33.0", + "lightningcss-linux-arm64-musl": "1.33.0", + "lightningcss-linux-x64-gnu": "1.33.0", + "lightningcss-linux-x64-musl": "1.33.0", + "lightningcss-win32-arm64-msvc": "1.33.0", + "lightningcss-win32-x64-msvc": "1.33.0" + } + }, + "node_modules/lightningcss-android-arm64": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-android-arm64/-/lightningcss-android-arm64-1.33.0.tgz", + "integrity": "sha512-gEpRTalKdosp4Bb8qWtc2iOgE5SeIHlpS1up9bFq2wAyYhl1UdTObYiHe98zEM9SQvSoqQZ1IQD0JNpg3Ml5pg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-darwin-arm64": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-darwin-arm64/-/lightningcss-darwin-arm64-1.33.0.tgz", + "integrity": "sha512-Sciaz8eenNTKn9b3t7+xr0ipTp9YxKQY4npwQ3mrRuL0BAVHBLyZxofhaKBAVtzmtRZ/zTyo0/to4B1uWG/Djg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-darwin-x64": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-darwin-x64/-/lightningcss-darwin-x64-1.33.0.tgz", + "integrity": "sha512-Z5UPAxzrjlWNNyGy6i65cJzzvgJ5D3T6wMvs+gWpY9d7qRhANrxqAp6LhxIgZhWEw18RfJTGcRxjuLIBr+m8XQ==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-freebsd-x64": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-freebsd-x64/-/lightningcss-freebsd-x64-1.33.0.tgz", + "integrity": "sha512-QQM/Ti/hQajJwCY+RiWuCZ9sdtI/XQk7nDK5vC8kkdwixezOlDgvDx7+RT+QjK6FcFT4MpsuoBnHIo/O3StRRg==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-linux-arm-gnueabihf": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-linux-arm-gnueabihf/-/lightningcss-linux-arm-gnueabihf-1.33.0.tgz", + "integrity": "sha512-N7FVBe6iS24MlM6R/4RBTxGhQheZGs7tiQ9U32UtF75NzP5Q7xWPRqLBCKxlRQRk3rY1jCIPLzx7WzOhuUIRLQ==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-linux-arm64-gnu": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-linux-arm64-gnu/-/lightningcss-linux-arm64-gnu-1.33.0.tgz", + "integrity": "sha512-j2v/itmy4HlNxlc6voKXYgBqNi0Ng2LShg4z7GufpEgs05P+2suBVyi9I6YHq5uoVFx9ETin3eCEhLVyXGQnKg==", + "cpu": [ + "arm64" + ], + "dev": true, + "libc": [ + "glibc" + ], + "license": "MPL-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-linux-arm64-musl": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-linux-arm64-musl/-/lightningcss-linux-arm64-musl-1.33.0.tgz", + "integrity": "sha512-yiO5ROMuYQgXbC60yjZU5CYSFZGKXL0HFATXt9mHJn1+zW55oCtMI9NfcVhYLMFDL7gV7oBPon/EmMMGg2OvtQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "libc": [ + "musl" + ], + "license": "MPL-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-linux-x64-gnu": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-linux-x64-gnu/-/lightningcss-linux-x64-gnu-1.33.0.tgz", + "integrity": "sha512-ar+Ju7LmcN0Jo4FpL4hpFybwNG9/3A/Br5KW2n2jyODg3MEZXaDYADdemoNS+BDNfMgKvylJLj4S5tyRActuAg==", + "cpu": [ + "x64" + ], + "dev": true, + "libc": [ + "glibc" + ], + "license": "MPL-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-linux-x64-musl": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-linux-x64-musl/-/lightningcss-linux-x64-musl-1.33.0.tgz", + "integrity": "sha512-RYiYbkokw0trfKqqzfF55lginwEPrD3OJDfTuJzFs1MK6iFnDenaz1fqLLtX4ITG3OktJQXOeTaw1awrBAlZPw==", + "cpu": [ + "x64" + ], + "dev": true, + "libc": [ + "musl" + ], + "license": "MPL-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-win32-arm64-msvc": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-win32-arm64-msvc/-/lightningcss-win32-arm64-msvc-1.33.0.tgz", + "integrity": "sha512-1K+MPfLSFVpphzpdbfkhlWk6wBrTObBzS2T6db10PNOZgR9GoVsAWzwNyuhUYYbTp23j+4RrncfujZ4uAzXvwA==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-win32-x64-msvc": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-win32-x64-msvc/-/lightningcss-win32-x64-msvc-1.33.0.tgz", + "integrity": "sha512-OlEICDx/Xl0FqSp4bry8zFnCvGpig3Gl4gCquvYwHuqJKEC1+n9NgDniFvqHGmMv1ZkqDJrDqKKSykTDX+ehuA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/magic-string": { + "version": "1.4.5", + "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-1.4.5.tgz", + "integrity": "sha512-oLLC2+YvQUfAa+vxoufE/yc1icb87M9iXIRqAoR/2EhE/8cb3SF/+Gi0c2By1B+5Vz2e2vQtUvHiu1+63Znh+w==", + "dev": true, + "license": "MIT", + "dependencies": { + "@jridgewell/sourcemap-codec": "^1.6.0" + } + }, + "node_modules/nanoid": { + "version": "3.3.20", + "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.20.tgz", + "integrity": "sha512-uKdg2G3GNCKQn9byYOpxbGqrT2fGO5KRt5J/8b3pok8rT6qxGWF6hxMyJiEYtAf+FVyYuD9hRaDqX5uPFYJ4ZQ==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/ai" + } + ], + "license": "MIT", + "bin": { + "nanoid": "bin/nanoid.cjs" + }, + "engines": { + "node": "^10 || ^12 || ^13.7 || ^14 || >=15.0.1" + } + }, + "node_modules/obug": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/obug/-/obug-3.0.0.tgz", + "integrity": "sha512-5vvB5+W7ePv+p3uqxi+RcW1XAzLW0/hxt3/4X4Lc4qHudzOhmBiBwOY6DRob4WnanAEGvNcLjF+KNOufrUoEQw==", + "dev": true, + "funding": [ + "https://github.com/sponsors/sxzz", + "https://opencollective.com/debug" + ], + "license": "MIT", + "engines": { + "node": ">=12.20.0" + } + }, + "node_modules/parse-svg-path": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/parse-svg-path/-/parse-svg-path-0.2.0.tgz", + "integrity": "sha512-Tf7FFIrguPKQwzD4pWnYkR2VOv3raoHeKED80Bm+BYHI3KxC8KsgsGC5+fSMzAGDA6UEk4bHvmi+RsjmL3khpg==", + "license": "MIT" + }, + "node_modules/picocolors": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.1.1.tgz", + "integrity": "sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==", + "dev": true, + "license": "ISC" + }, + "node_modules/picomatch": { + "version": "4.0.7", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.7.tgz", + "integrity": "sha512-qcJu88Q2IWqJsDD529JKMdwGm/dvInW4HvQnRwiH9JtihJvzGOscDtHE3x1pBKeUOTysQ8kVmLnJ2kJu7yhcGA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/jonschlinkert" + } + }, + "node_modules/pixi.js": { + "version": "8.23.0", + "resolved": "https://registry.npmjs.org/pixi.js/-/pixi.js-8.23.0.tgz", + "integrity": "sha512-RkWSwo+mAR0d7MKnJ20IjKkWGPdFh1C0adBRYYLa+SGdxTfbrr6RnQyZZRwjBaG/bDAIQqgBcTBbiNsN6iKFVQ==", + "license": "MIT", + "workspaces": [ + "examples", + "playground" + ], + "dependencies": { + "@types/earcut": "^3.0.0", + "@webgpu/types": "^0.1.69", + "@xmldom/xmldom": "^0.8.15", + "colord": "^2.11.0", + "earcut": "^3.0.2", + "eventemitter3": "^5.0.1", + "gifuct-js": "^2.1.2", + "ismobilejs": "^1.1.1", + "parse-svg-path": "^0.2.0", + "tiny-lru": "^11.4.7" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/pixijs" + } + }, + "node_modules/playwright-core": { + "version": "1.65.1", + "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.65.1.tgz", + "integrity": "sha512-hqPpz7blSMPxWVdoeE1yiBSzXsKiVOd2k+kjCvmUywD2GPO2Dd9HfcWnq9NN0GHbNZDFgZ9JfBFr+X5/BLo0qw==", + "dev": true, + "license": "Apache-2.0", + "bin": { + "playwright-core": "cli.js" + }, + "engines": { + "node": ">=20" + } + }, + "node_modules/postcss": { + "version": "8.5.33", + "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.5.33.tgz", + "integrity": "sha512-RVHEU9/Pp1Fnjr/MpAJsZoADukCKhfIi15OunEYiGktIkYLkPVvC1sioWolGDS7XByMTx9m/IGbro0Js13zhnQ==", + "dev": true, + "funding": [ + { + "type": "opencollective", + "url": "https://opencollective.com/postcss/" + }, + { + "type": "tidelift", + "url": "https://tidelift.com/funding/github/npm/postcss" + }, + { + "type": "github", + "url": "https://github.com/sponsors/ai" + } + ], + "license": "MIT", + "dependencies": { + "nanoid": "^3.3.20", + "picocolors": "^1.1.1", + "source-map-js": "^1.2.2" + }, + "engines": { + "node": "^10 || ^12 || >=14" + } + }, + "node_modules/rolldown": { + "version": "1.2.19", + "resolved": "https://registry.npmjs.org/rolldown/-/rolldown-1.2.19.tgz", + "integrity": "sha512-QIiV1J9d0pzN4jeeTH4sjPy0AZ6cAy2cG0ExeoE1+U8Rvj+hR3gYkokx0YbeUNGlZqiQJJ2utcETe0oKXwzsuA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@oxc-project/types": "=0.156.0", + "@rolldown/pluginutils": "^1.0.0" + }, + "bin": { + "rolldown": "bin/cli.mjs" + }, + "engines": { + "node": "^20.19.0 || >=22.12.0" + }, + "optionalDependencies": { + "@rolldown/binding-android-arm-eabi": "1.2.19", + "@rolldown/binding-android-arm64": "1.2.19", + "@rolldown/binding-darwin-arm64": "1.2.19", + "@rolldown/binding-darwin-x64": "1.2.19", + "@rolldown/binding-freebsd-x64": "1.2.19", + "@rolldown/binding-linux-arm-gnueabihf": "1.2.19", + "@rolldown/binding-linux-arm64-gnu": "1.2.19", + "@rolldown/binding-linux-arm64-musl": "1.2.19", + "@rolldown/binding-linux-ppc64-gnu": "1.2.19", + "@rolldown/binding-linux-s390x-gnu": "1.2.19", + "@rolldown/binding-linux-x64-gnu": "1.2.19", + "@rolldown/binding-linux-x64-musl": "1.2.19", + "@rolldown/binding-openharmony-arm64": "1.2.19", + "@rolldown/binding-wasm32-wasi": "1.2.19", + "@rolldown/binding-win32-arm64-msvc": "1.2.19", + "@rolldown/binding-win32-x64-msvc": "1.2.19" + } + }, + "node_modules/source-map-js": { + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.2.4.tgz", + "integrity": "sha512-J7ZjMvHd9O1fcT/5V09QWaaSl2BbWx3F6O08spde82Namf9UB0GxRVIPiNbVsdKkoizHiSpTodo3vp2bAy91MA==", + "dev": true, + "license": "BSD-3-Clause", + "engines": { + "node": ">=6.0.0" + } + }, + "node_modules/std-env": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/std-env/-/std-env-4.3.0.tgz", + "integrity": "sha512-OtU/EgQ1kIm5KwqQpBC6ZEMXrZRui11w8zgfTWp8cdO9B8OaPsbA8bTHO2P+HNo1VlUTGMVBwPhydu6poeXiag==", + "dev": true, + "license": "MIT" + }, + "node_modules/tiny-lru": { + "version": "11.4.7", + "resolved": "https://registry.npmjs.org/tiny-lru/-/tiny-lru-11.4.7.tgz", + "integrity": "sha512-w/Te7uMUVeH0CR8vZIjr+XiN41V+30lkDdK+NRIDCUYKKuL9VcmaUEmaPISuwGhLlrTGh5yu18lENtR9axSxYw==", + "license": "BSD-3-Clause", + "engines": { + "node": ">=12" + } + }, + "node_modules/tinybench": { + "version": "6.2.4", + "resolved": "https://registry.npmjs.org/tinybench/-/tinybench-6.2.4.tgz", + "integrity": "sha512-SQ52jEncXxbMCzJuY2A/jGIbbAu6NYsBWW7grz2pNE+EnzQdoGaoBfpk4qC/opE7qiUcGmGgaGIz5EoHdS1O9w==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=20.0.0" + } + }, + "node_modules/tinyexec": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/tinyexec/-/tinyexec-1.3.1.tgz", + "integrity": "sha512-GCvB3aoys96IuDFBMcTB46JOR6mdMtAToqwiW8JlWhsoh1mhHi/xn9ss/Dg7N555GiJyEt2qzoG/NHCwM6h1EA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=18" + } + }, + "node_modules/tinyglobby": { + "version": "0.2.17", + "resolved": "https://registry.npmjs.org/tinyglobby/-/tinyglobby-0.2.17.tgz", + "integrity": "sha512-wXR/dYpcqKmfWpEdZjiKJOwCNFndD0DMnrW/cYjVGttEkBfVgcLFHoNrlj47mjOVic9yyNu65alsgF4NQyTa2g==", + "dev": true, + "license": "MIT", + "dependencies": { + "fdir": "^6.5.0", + "picomatch": "^4.0.4" + }, + "engines": { + "node": ">=12.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/SuperchupuDev" + } + }, + "node_modules/tslib": { + "version": "2.9.1", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.9.1.tgz", + "integrity": "sha512-a4Ux9VKuIMHsOS7ENbEq6hK2ZGYIT27Rtl0E4eD9KqwxhKiQeMZE/9xb3IdYwWaSOyIBQLExhQgXDTYoiCxnWA==", + "dev": true, + "license": "0BSD", + "optional": true + }, + "node_modules/typescript": { + "version": "5.9.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz", + "integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==", + "dev": true, + "license": "Apache-2.0", + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=14.17" + } + }, + "node_modules/vite": { + "version": "8.3.8", + "resolved": "https://registry.npmjs.org/vite/-/vite-8.3.8.tgz", + "integrity": "sha512-LzOn3h9rG/0vhLdXrV4yJ4QFA9eEoqCl+Yx+kGJd7aB9w6nfNgVHKSYwLPZUHrz4ZGa+t+kXjV9itvcHDLQouA==", + "dev": true, + "license": "MIT", + "dependencies": { + "lightningcss": "^1.33.0", + "picomatch": "^4.0.7", + "postcss": "^8.5.32", + "rolldown": "~1.2.18", + "tinyglobby": "^0.2.17" + }, + "bin": { + "vite": "bin/vite.js" + }, + "engines": { + "node": "^20.19.0 || >=22.12.0" + }, + "funding": { + "url": "https://github.com/vitejs/vite?sponsor=1" + }, + "optionalDependencies": { + "fsevents": "~2.3.3" + }, + "peerDependencies": { + "@types/node": "^20.19.0 || >=22.12.0", + "@vitejs/devtools": "^0.7.1 || ^0.8.0", + "esbuild": "^0.27.0 || ^0.28.0", + "jiti": ">=1.21.0", + "less": "^4.0.0", + "sass": "^1.70.0", + "sass-embedded": "^1.70.0", + "stylus": ">=0.54.8", + "sugarss": "^5.0.0", + "terser": "^5.16.0", + "tsx": "^4.8.1", + "yaml": "^2.4.2" + }, + "peerDependenciesMeta": { + "@types/node": { + "optional": true + }, + "@vitejs/devtools": { + "optional": true + }, + "esbuild": { + "optional": true + }, + "jiti": { + "optional": true + }, + "less": { + "optional": true + }, + "sass": { + "optional": true + }, + "sass-embedded": { + "optional": true + }, + "stylus": { + "optional": true + }, + "sugarss": { + "optional": true + }, + "terser": { + "optional": true + }, + "tsx": { + "optional": true + }, + "yaml": { + "optional": true + } + } + }, + "node_modules/vitest": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/vitest/-/vitest-5.1.1.tgz", + "integrity": "sha512-trVmzUFOSraCZcI3uZIMD5FqBh4atFkC/XuJP/IU7qtyQay0FCs3Ia+0QiQ2JJwGyWG/xrcBoJNel2+O7kEZ0g==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/chai": "^5.2.2", + "@vitest/mocker": "5.1.1", + "chai": "^6.3.0", + "es-module-lexer": "^2.3.2", + "expect-type": "^1.4.0", + "magic-string": "^1.4.5", + "obug": "^3.0.0", + "picomatch": "^4.0.7", + "std-env": "^4.3.0", + "tinybench": "^6.2.3", + "tinyexec": "^1.3.1", + "tinyglobby": "^0.2.17", + "why-is-node-running": "3.2.1" + }, + "bin": { + "vitest": "vitest.mjs" + }, + "engines": { + "node": "^22.12.0 || ^24.0.0 || >=26.0.0" + }, + "funding": { + "url": "https://opencollective.com/vitest" + }, + "peerDependencies": { + "@edge-runtime/vm": "*", + "@opentelemetry/api": "^1.9.0", + "@types/node": "^22.0.0 || >=24.0.0", + "@vitest/browser-playwright": "5.1.1", + "@vitest/browser-preview": "5.1.1", + "@vitest/browser-webdriverio": "^5.0.0-beta.5 || >=5.0.0", + "@vitest/coverage-istanbul": "5.1.1", + "@vitest/coverage-v8": "5.1.1", + "@vitest/ui": "5.1.1", + "happy-dom": "*", + "jsdom": "*", + "vite": "^6.4.0 || ^7.0.0 || ^8.0.0" + }, + "peerDependenciesMeta": { + "@edge-runtime/vm": { + "optional": true + }, + "@opentelemetry/api": { + "optional": true + }, + "@types/node": { + "optional": true + }, + "@vitest/browser-playwright": { + "optional": true + }, + "@vitest/browser-preview": { + "optional": true + }, + "@vitest/browser-webdriverio": { + "optional": true + }, + "@vitest/coverage-istanbul": { + "optional": true + }, + "@vitest/coverage-v8": { + "optional": true + }, + "@vitest/ui": { + "optional": true + }, + "happy-dom": { + "optional": true + }, + "jsdom": { + "optional": true + }, + "vite": { + "optional": false + } + } + }, + "node_modules/why-is-node-running": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/why-is-node-running/-/why-is-node-running-3.2.1.tgz", + "integrity": "sha512-Tb2FUhB4vUsGQlfSquQLYkApkuPAFQXGFzxWKHHumVz2dK+X1RUm/HnID4+TfIGYJ1kTcwOaCk/buYCEJr6YjQ==", + "dev": true, + "license": "MIT", + "bin": { + "why-is-node-running": "cli.js" + }, + "engines": { + "node": ">=20.11" + } + } + } +} diff --git a/client/package.json b/client/package.json new file mode 100644 index 0000000..42bdc02 --- /dev/null +++ b/client/package.json @@ -0,0 +1,22 @@ +{ + "name": "fff-vtt-client", + "version": "0.1.0", + "private": true, + "type": "module", + "description": "FFF VTT browser client: Vite + TypeScript + PixiJS v8, plain DOM overlay (DESIGN 7).", + "scripts": { + "dev": "vite", + "build": "tsc --noEmit && vite build", + "preview": "vite preview", + "test": "vitest run --reporter=dot" + }, + "dependencies": { + "pixi.js": "8.23.0" + }, + "devDependencies": { + "playwright-core": "1.65.1", + "typescript": "5.9.3", + "vite": "8.3.8", + "vitest": "5.1.1" + } +} diff --git a/client/run-tests.sh b/client/run-tests.sh new file mode 100755 index 0000000..c3a76f6 --- /dev/null +++ b/client/run-tests.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash +# devbox run client-test: the pure reducer/protocol-client seam (TESTING 10.3 "Client reducer", +# spec #63 decision 13). No server, no browser, no GPU: these run in a second. +set -euo pipefail +cd "$(dirname "$0")/.." || exit 1 +mkdir -p results +{ [ -d client/node_modules ] || ( cd client && npm ci --no-audit --no-fund ); } +( cd client && npm test ) > results/client-test.log 2>&1 +rc=$? +cat results/client-test.log +exit $rc diff --git a/client/src/main.ts b/client/src/main.ts new file mode 100644 index 0000000..d353f81 --- /dev/null +++ b/client/src/main.ts @@ -0,0 +1,103 @@ +// Client bootstrap: one store, one WS client, one DOM shell, one Pixi stage created only once the +// session is live. Every network/UI decision goes through the pure reducer; this file is wiring. + +import './style.css' +import { ProtocolClient } from './ws.ts' +import { Store } from './store.ts' +import { mountShell } from './shell.ts' +import type { Stage } from './render/stage.ts' +import { createStage } from './render/stage.ts' +import type { RootState } from './reducer.ts' + +const KEY_REFUSED = 'Key not recognised.' + +const host = document.querySelector('#app') +if (!host) throw new Error('#app is missing') + +const store = new Store() +let client: ProtocolClient | null = null +let stage: Stage | null = null +let startingStage: Promise | null = null + +const shell = mountShell(host, { + onSubmitKey: key => { + void signIn(key) + }, + onReload: () => location.reload(), +}) + +const stageHost = document.querySelector('#stage') +if (!stageHost) throw new Error('#stage is missing') +const stageRoot: HTMLElement = stageHost + +async function signIn(key: string): Promise { + shell.setBusy(true) + let accepted = false + try { + // DESIGN 3.2/6.6: POST /join, key in the body. `redirect: 'manual'` turns the 303 into an + // opaque redirect the client cannot mistake for a body; a 401 (wrong or unknown key alike) + // is a readable same-origin response. + const response = await fetch('/join', { + method: 'POST', + credentials: 'same-origin', + redirect: 'manual', + headers: { 'content-type': 'application/x-www-form-urlencoded' }, + body: new URLSearchParams({ key }).toString(), + }) + accepted = response.type === 'opaqueredirect' || response.status === 303 + } catch { + accepted = false + } + if (!accepted) { + // Story 3: one plain answer, whatever the reason. No key existence oracle. + store.dispatch({ type: 'signin-failed', message: KEY_REFUSED }) + return + } + client?.close() + store.dispatch({ type: 'connecting' }) + connect() +} + +function connect(): void { + client = new ProtocolClient({ + onEvent: event => { + store.dispatch(event) + }, + }) + client.connect() +} + +function syncStage(state: RootState): void { + const live = state.connection.phase === 'live' + if (!live) { + stage?.destroy() + stage = null + return + } + if (stage || startingStage) return + startingStage = createStage(stageRoot, store) + .then(created => { + if (store.state.connection.phase !== 'live') { + created.destroy() + return + } + stage = created + }) + .catch(error => { + console.error('stage init failed', error) + }) + .finally(() => { + startingStage = null + }) +} + +store.subscribe(state => { + shell.render(state) + syncStage(state) +}) + +// Boot: show the neutral connecting screen and probe for a session. A visitor without a session +// gets a refused `/ws` upgrade and lands on the sign-in page; no map data is ever created. +store.dispatch({ type: 'connecting' }) +shell.render(store.state) +connect() diff --git a/client/src/protocol.ts b/client/src/protocol.ts new file mode 100644 index 0000000..637e69c --- /dev/null +++ b/client/src/protocol.ts @@ -0,0 +1,181 @@ +// The wire contract (DESIGN 6). This module is pure: no Pixi, no DOM, no socket. The client speaks +// `proto` 2 (ADR-0011) and ignores unknown server message types and unknown fields (6.2). + +/** Compiled into the client exactly as into the server (DESIGN 6.2, ADR-0011). */ +export const PROTO = 2 + +export type Role = 'gm' | 'player' +export type Vec2 = [number, number] + +/** `hello.scene` (DESIGN 6.1; views.sceneBlock). No counts, no wall data, no owned ids. */ +export interface SceneInfo { + id: number + name: string + w: number + h: number + tile_size: number + cell: number + grid_size: number + vision_radius_default: number + token_radius_default: number + art_version: number +} + +export interface RosterEntry { + id: number + name: string | null + role: Role + colour: string + connected: boolean +} + +export interface Me { + id: number + name: string | null +} + +/** Every server frame carries the per-connection counter `n` (DESIGN 6, 6.4). */ +export interface ServerFrame { + t: string + n: number + [field: string]: unknown +} + +export interface HelloFrame extends ServerFrame { + t: 'hello' + proto: number + role: Role + me: Me + scene?: SceneInfo + extra?: unknown +} + +export interface AckFrame extends ServerFrame { + t: 'ack' + reqId: number + ok: boolean + code?: string + id?: number + key?: string + pos?: Vec2 + ts?: number +} + +export const CLOSE_REASONS = [ + 'revoked', + 'evicted', + 'proto-mismatch', + 'malformed-flood', + 'server-shutdown', +] as const + +export type CloseReason = (typeof CLOSE_REASONS)[number] + +export interface ClosingFrame extends ServerFrame { + t: 'closing' + reason: CloseReason + code: number +} + +/** What the shell does when a connection outcome arrives (DESIGN 6.5). */ +export type CloseOutcome = 'signin' | 'reload' | 'offline' + +export function closeOutcome(reason: CloseReason | null): CloseOutcome { + switch (reason) { + case 'revoked': + return 'signin' + case 'proto-mismatch': + return 'reload' + case 'evicted': + case 'malformed-flood': + case 'server-shutdown': + return 'offline' + case null: + return 'offline' + } +} + +function isRecord(value: unknown): value is Record { + return typeof value === 'object' && value !== null && !Array.isArray(value) +} + +/** + * Parse one text frame into a server envelope. Binary frames and anything that is not a JSON + * object with a string `t` and an integer `n >= 1` are not frames (DESIGN 6: a binary frame counts + * as malformed server input; the client ignores it, exactly as 6.2 says for unknown shapes). + */ +export function parseServerFrame(raw: unknown): ServerFrame | null { + if (typeof raw !== 'string') return null + let value: unknown + try { + value = JSON.parse(raw) + } catch { + return null + } + if (!isRecord(value)) return null + const t = value['t'] + const n = value['n'] + if (typeof t !== 'string' || t.length === 0) return null + if (typeof n !== 'number' || !Number.isInteger(n) || n < 1) return null + return value as ServerFrame +} + +function isRole(value: unknown): value is Role { + return value === 'gm' || value === 'player' +} + +function isMe(value: unknown): value is Me { + if (!isRecord(value)) return false + const name = value['name'] + return ( + typeof value['id'] === 'number' && + Number.isInteger(value['id']) && + (name === null || typeof name === 'string') + ) +} + +export function isHello(frame: ServerFrame): frame is HelloFrame { + if (frame.t !== 'hello') return false + if (typeof frame['proto'] !== 'number' || !Number.isInteger(frame['proto'])) return false + if (!isRole(frame['role'])) return false + if (!isMe(frame['me'])) return false + const scene = frame['scene'] + if (scene !== undefined && !isRecord(scene)) return false + return true +} + +export function isAck(frame: ServerFrame): frame is AckFrame { + return ( + frame.t === 'ack' && + typeof frame['reqId'] === 'number' && + Number.isInteger(frame['reqId']) && + typeof frame['ok'] === 'boolean' + ) +} + +function isCloseReason(value: unknown): value is CloseReason { + return typeof value === 'string' && (CLOSE_REASONS as readonly string[]).includes(value) +} + +export function isClosing(frame: ServerFrame): frame is ClosingFrame { + return ( + frame.t === 'closing' && + isCloseReason(frame['reason']) && + typeof frame['code'] === 'number' && + Number.isInteger(frame['code']) + ) +} + +/** + * Serialise one intent: envelope `t` plus its `reqId` and fields (DESIGN 6 Conventions). The server + * ignores unknown fields (6.2); the client never invents a `t` outside the catalogue. + */ +export function encodeIntent(t: string, reqId: number, fields: Record = {}): string { + return JSON.stringify({ ...fields, t, reqId }) +} + +/** The only place the client spells the `proto` parameter (6.2: absent or non-integer is 400). */ +export function wsUrl(location: Pick = window.location): string { + const scheme = location.protocol === 'https:' ? 'wss' : 'ws' + return `${scheme}://${location.host}/ws?proto=${PROTO}` +} diff --git a/client/src/reducer.ts b/client/src/reducer.ts new file mode 100644 index 0000000..428d30d --- /dev/null +++ b/client/src/reducer.ts @@ -0,0 +1,218 @@ +// The client's one pure reducer (DESIGN 7.1, spec #63 decision 11): server frames and connection +// events in, state out. No Pixi import here, ever: this module is the unit-test seam. +// +// Domain slices are *append-only*: every file in ./slices/ that exports `slice` is picked up by the +// build-time glob below and registered automatically, so a later ticket (fog, tokens, walls, GM +// panels) adds one file and touches no other slice. `hello` resets every slice (DESIGN 6.3: a +// reconnect is a full resync), which is why the registry owns the reset rather than each slice. + +import type { + CloseReason, + Me, + Role, + RosterEntry, + SceneInfo, + ServerFrame, +} from './protocol.ts' +import { closeOutcome, isClosing, isHello } from './protocol.ts' + +export type Phase = 'boot' | 'connecting' | 'signin' | 'live' | 'reload' | 'offline' + +export interface ConnectionState { + phase: Phase + /** Server frames seen on this connection (`n` is per connection, starts at 1). */ + frames: number + lastN: number + /** Human text for the shell; never game data. */ + notice: string | null + /** Sign-in failure text ("Key not recognised.") or a transport message. */ + error: string | null +} + +export interface SessionState { + role: Role | null + me: Me | null + proto: number | null + scene: SceneInfo | null +} + +export interface RootState { + connection: ConnectionState + session: SessionState + /** + * Append-only domain state, keyed by slice name. Later tickets read `slices.tokens`, `slices.fog` + * and so on; core connection/session/handshake state stays in this file. + */ + slices: Record +} + +export type ReducerEvent = + | { type: 'connecting' } + | { type: 'open' } + | { type: 'frame'; frame: ServerFrame } + | { type: 'close'; reason: CloseReason | null; code: number | null } + | { type: 'signin-failed'; message: string } + | { type: 'signed-out' } + +/** + * A domain slice. `init()` returns the empty value; `reduce` mutates the draft it is handed (the + * root reducer clones before dispatching, so the previous state is never touched). + */ +export interface Slice { + readonly name: string + init(): S + reduce(state: S, event: ReducerEvent, root: RootState): void +} + +interface SliceModule { + slice: Slice +} + +// Build-time registry: no shared import list to merge, so parallel tickets never edit one file. +const modules = import.meta.glob('./slices/*.ts', { eager: true }) + +export const SLICES: readonly Slice[] = Object.keys(modules) + .sort() + .map(path => { + const module = modules[path] + if (!module || !module.slice) throw new Error(`slice ${path} has no \`slice\` export`) + return module.slice + }) + +const sliceNames = new Set(SLICES.map(slice => slice.name)) +if (sliceNames.size !== SLICES.length) throw new Error('duplicate slice name') + +export function sliceOf(state: RootState, name: string): S { + return state.slices[name] as S +} + +function initialConnection(): ConnectionState { + return { phase: 'boot', frames: 0, lastN: 0, notice: null, error: null } +} + +function initialSession(): SessionState { + return { role: null, me: null, proto: null, scene: null } +} + +export function initialState(): RootState { + const slices: Record = {} + for (const slice of SLICES) slices[slice.name] = slice.init() + return { connection: initialConnection(), session: initialSession(), slices } +} + +/** Reset everything that came from the server; keep the connection envelope. */ +function resetDomain(state: RootState): void { + state.session = initialSession() + const slices: Record = {} + for (const slice of SLICES) slices[slice.name] = slice.init() + state.slices = slices +} + +function onFrame(state: RootState, frame: ServerFrame): void { + state.connection.frames += 1 + state.connection.lastN = frame.n + + if (isHello(frame)) { + // DESIGN 6.1/6.3: `hello` means "start clean". The resync that follows rebuilds the view; a + // client that kept the previous connection's state would show stale tokens after a reconnect. + resetDomain(state) + state.session.role = frame.role + state.session.me = frame.me + state.session.proto = frame.proto + state.session.scene = frame.scene ?? null + state.connection.phase = 'live' + state.connection.notice = null + state.connection.error = null + } else if (isClosing(frame)) { + // DESIGN 6.5: the closing frame is the reason a browser cannot read from the close code. + const outcome = closeOutcome(frame.reason) + state.connection.notice = + frame.reason === 'revoked' + ? 'Your session has ended. Sign in again.' + : frame.reason === 'proto-mismatch' + ? 'This client is out of date.' + : frame.reason === 'evicted' + ? 'This tab was replaced by a newer connection.' + : 'The connection was closed by the server.' + if (outcome === 'signin') { + resetDomain(state) + state.connection.phase = 'signin' + } else if (outcome === 'reload') { + state.connection.phase = 'reload' + } else { + state.connection.phase = 'offline' + } + } +} + +export function reduce(previous: RootState, event: ReducerEvent): RootState { + const state: RootState = { + connection: { ...previous.connection }, + session: { ...previous.session }, + slices: { ...previous.slices }, + } + + switch (event.type) { + case 'connecting': + resetDomain(state) + state.connection.phase = 'connecting' + state.connection.frames = 0 + state.connection.lastN = 0 + state.connection.notice = null + state.connection.error = null + break + case 'open': + // An open socket is not a view: stay on the boot/connecting screen until `hello` (6.3). + break + case 'frame': + onFrame(state, event.frame) + break + case 'close': { + // A `closing` frame already decided the outcome (6.5); a close without one is a transport + // failure. Before the first `hello` that means "no session" (the `/ws` upgrade was refused). + if (state.connection.phase === 'live') { + const outcome = closeOutcome(event.reason) + if (outcome === 'signin') { + resetDomain(state) + state.connection.phase = 'signin' + state.connection.notice = 'Your session has ended. Sign in again.' + } else if (outcome === 'reload') { + state.connection.phase = 'reload' + state.connection.notice = 'This client is out of date.' + } else { + state.connection.phase = 'offline' + state.connection.notice = 'Connection lost.' + } + } else if (state.connection.phase === 'connecting' || state.connection.phase === 'boot') { + resetDomain(state) + state.connection.phase = 'signin' + } + break + } + case 'signin-failed': + resetDomain(state) + state.connection.phase = 'signin' + state.connection.error = event.message + break + case 'signed-out': + resetDomain(state) + state.connection.phase = 'signin' + state.connection.notice = null + state.connection.error = null + break + } + + for (const slice of SLICES) { + slice.reduce(state.slices[slice.name], event, state) + } + return state +} + +/** `roster` lives in its own slice (append-only), read through here by the shell. */ +export interface RosterState { + players: RosterEntry[] +} + +export function rosterOf(state: RootState): RosterEntry[] { + return sliceOf(state, 'roster').players +} diff --git a/client/src/render/modules/README.md b/client/src/render/modules/README.md new file mode 100644 index 0000000..80cbb95 --- /dev/null +++ b/client/src/render/modules/README.md @@ -0,0 +1,19 @@ +# Render modules: append-only + +Every `*.ts` file here that exports `renderModule` is registered by the build-time glob in +`../stage.ts`. Add one file per feature; never edit the registry. + +```ts +import type { RenderModule } from '../stage.ts' + +export const renderModule: RenderModule = { + name: 'tiles', // unique + mount({ app, world, layers, store }) { + // create your objects in `layers.*`, subscribe to `store` for state changes, + // return a teardown only for global resources you install. + }, +} +``` + +Layers bottom to top: `tiles`, `grid`, `tokens`, `fog`, `gm`, `dom` (DESIGN 7.1). Update only the +entities that changed (DESIGN 7.2); no per-frame full redraw. diff --git a/client/src/render/stage.ts b/client/src/render/stage.ts new file mode 100644 index 0000000..200eaf1 --- /dev/null +++ b/client/src/render/stage.ts @@ -0,0 +1,105 @@ +// The Pixi stage (DESIGN 7.1): one Application, one world container under pan/zoom, fixed layers +// bottom to top. Render modules are append-only, exactly like reducer slices: every file in +// ./modules/ that exports `renderModule` is picked up by the glob, so a later ticket (tiles/grid +// T6, fog T7, tokens T8, walls T10, GM overlays) adds one file and touches no other module. +// +// Pixi is imported here (and in modules/) only. The reducer, the WS client and the DOM shell stay +// Pixi-free so their unit tests run without a GPU or a DOM. + +import { Application, Container } from 'pixi.js' +import type { Store } from '../store.ts' +import { PROTO } from '../protocol.ts' + +export interface RenderLayers { + tiles: Container + grid: Container + tokens: Container + fog: Container + gm: Container + dom: Container +} + +export interface RenderContext { + app: Application + world: Container + layers: RenderLayers + store: Store +} + +export interface RenderModule { + readonly name: string + /** Start drawing. Return a teardown for anything global the module installed. */ + mount(context: RenderContext): void | (() => void) +} + +interface ModuleExport { + renderModule: RenderModule +} + +const modules = import.meta.glob('./modules/*.ts', { eager: true }) + +const RENDER_MODULES: readonly RenderModule[] = Object.keys(modules) + .sort() + .map(path => { + const module = modules[path] + if (!module || !module.renderModule) { + throw new Error(`render module ${path} has no \`renderModule\` export`) + } + return module.renderModule + }) + +const moduleNames = new Set(RENDER_MODULES.map(module => module.name)) +if (moduleNames.size !== RENDER_MODULES.length) throw new Error('duplicate render module name') + +export interface Stage { + readonly app: Application + readonly context: RenderContext + destroy(): void +} + +/** + * Create the stage inside `host`. The caller creates it only when the session is live, so a + * visitor without a session never gets a canvas (story 1). `PROTO` is touched here so the build + * keeps the constant referenced even before an intent module exists. + */ +export async function createStage(host: HTMLElement, store: Store): Promise { + const app = new Application() + await app.init({ + resizeTo: window, + background: 0x000000, + antialias: true, + autoDensity: true, + resolution: Math.min(window.devicePixelRatio || 1, 2), + preference: 'webgl', + }) + app.canvas.id = 'stage-canvas' + app.canvas.dataset['proto'] = String(PROTO) + host.replaceChildren(app.canvas) + + const world = new Container() + const layers: RenderLayers = { + tiles: new Container(), + grid: new Container(), + tokens: new Container(), + fog: new Container(), + gm: new Container(), + dom: new Container(), + } + world.addChild(layers.tiles, layers.grid, layers.tokens, layers.fog, layers.gm, layers.dom) + app.stage.addChild(world) + + // A v1 scene is large and the camera starts at the origin until T6 adds pan/zoom; scaling the + // world down is not a map feature, so the world simply sits under the camera transform. + const context: RenderContext = { app, world, layers, store } + const teardowns = RENDER_MODULES.map(module => module.mount(context)) + + return { + app, + context, + destroy() { + for (const teardown of teardowns) teardown?.() + app.destroy(true, { children: true }) + host.replaceChildren() + }, + } +} diff --git a/client/src/shell.ts b/client/src/shell.ts new file mode 100644 index 0000000..441efc3 --- /dev/null +++ b/client/src/shell.ts @@ -0,0 +1,173 @@ +// The plain-DOM overlay (DESIGN 7.1 layer 6, spec #63 decision 15). No framework, no `innerHTML`: +// every server-supplied string goes through `textContent`, so a name can never become markup. +// +// The shell is the only module that owns page structure; later panels (roster/keys/tokens T11, +// characters/reveals T12) add their DOM under `#panels` or as their own file next to this one, +// never by rewriting the sign-in flow. + +import type { RootState } from './reducer.ts' +import { rosterOf } from './reducer.ts' +import type { RosterEntry } from './protocol.ts' + +export interface ShellHandlers { + onSubmitKey(key: string): void + onReload(): void +} + +export interface Shell { + render(state: RootState): void + setBusy(busy: boolean): void +} + +function element( + tag: K, + id: string, + text?: string, +): HTMLElementTagNameMap[K] { + const node = document.createElement(tag) + node.id = id + if (text !== undefined) node.textContent = text + return node +} + +function rosterName(entry: RosterEntry): string { + return entry.name ?? '(unnamed)' +} + +export function mountShell(root: HTMLElement, handlers: ShellHandlers): Shell { + const stage = element('div', 'stage') + stage.hidden = true + + const boot = element('section', 'boot') + const bootText = element('p', 'boot-text', 'Connecting…') + boot.append(bootText) + + const signin = element('section', 'signin') + signin.hidden = true + const title = element('h1', 'signin-title', 'FFF VTT') + const notice = element('p', 'signin-notice') + notice.hidden = true + const form = element('form', 'signin-form') + const label = element('label', 'signin-label', 'Player or GM key') + label.htmlFor = 'key' + const input = element('input', 'key') + input.name = 'key' + input.type = 'text' + input.autocomplete = 'off' + input.autocapitalize = 'characters' + input.spellcheck = false + input.required = true + const submit = element('button', 'signin-submit', 'Sign in') + submit.type = 'submit' + form.append(label, input, submit) + const error = element('p', 'signin-error') + error.hidden = true + error.setAttribute('role', 'alert') + signin.append(title, notice, form, error) + + const hud = element('header', 'hud') + hud.hidden = true + const role = element('span', 'role') + const scene = element('span', 'scene') + const me = element('span', 'me') + const roster = element('ul', 'roster') + hud.append(role, scene, me, roster) + + const fatal = element('section', 'fatal') + fatal.hidden = true + const fatalText = element('p', 'fatal-text') + const reload = element('button', 'reload', 'Reload') + reload.type = 'button' + reload.addEventListener('click', () => handlers.onReload()) + fatal.append(fatalText, reload) + + const panels = element('div', 'panels') + root.replaceChildren(stage, hud, signin, boot, fatal, panels) + + form.addEventListener('submit', event => { + event.preventDefault() + const key = input.value.trim() + if (key.length === 0) return + handlers.onSubmitKey(key) + }) + + let busy = false + + function setBusy(next: boolean): void { + busy = next + submit.disabled = next + input.disabled = next + bootText.textContent = next ? 'Signing in…' : 'Connecting…' + if (next) showOnly(boot) + } + + function showOnly(active: HTMLElement): void { + for (const node of [boot, signin, hud, fatal]) node.hidden = node !== active + } + + function renderRoster(players: RosterEntry[]): void { + roster.replaceChildren( + ...players.map(entry => { + const item = document.createElement('li') + item.dataset['player'] = String(entry.id) + const name = element('span', 'roster-name', rosterName(entry)) + const state = element('span', 'roster-state', entry.connected ? 'connected' : 'offline') + item.append(name, state) + return item + }), + ) + } + + function render(state: RootState): void { + const phase = state.connection.phase + + notice.textContent = state.connection.notice ?? '' + notice.hidden = state.connection.notice === null + error.textContent = state.connection.error ?? '' + error.hidden = state.connection.error === null + + stage.hidden = phase !== 'live' + + // Leaving the live phase clears every server-derived DOM text, so a revoked session cannot + // leave a roster (or names) behind the sign-in page. + if (phase !== 'live') { + role.textContent = '' + scene.textContent = '' + me.textContent = '' + roster.replaceChildren() + } + + switch (phase) { + case 'boot': + case 'connecting': + if (!busy) bootText.textContent = 'Connecting…' + showOnly(boot) + break + case 'signin': + busy = false + submit.disabled = false + input.disabled = false + showOnly(signin) + input.focus() + break + case 'live': + busy = false + showOnly(hud) + role.textContent = state.session.role === 'gm' ? 'GM' : 'Player' + scene.textContent = state.session.scene?.name ?? '' + me.textContent = state.session.me?.name ?? '' + renderRoster(rosterOf(state)) + break + case 'reload': + showOnly(fatal) + fatalText.textContent = 'This client is out of date. Reload the page to get the matching version.' + break + case 'offline': + showOnly(fatal) + fatalText.textContent = state.connection.notice ?? 'Connection lost. Reload to reconnect.' + break + } + } + + return { render, setBusy } +} diff --git a/client/src/slices/roster.ts b/client/src/slices/roster.ts new file mode 100644 index 0000000..0c1e9fb --- /dev/null +++ b/client/src/slices/roster.ts @@ -0,0 +1,25 @@ +// Roster slice (DESIGN 6.1 `roster`). Append-only registration: adding this file was enough; the +// reducer's glob picked it up and `hello` reset it with every other slice. + +import type { ReducerEvent, RootState, Slice } from '../reducer.ts' +import type { RosterEntry } from '../protocol.ts' + +export interface RosterState { + /** Always the full list the server sent; the client never merges (6.1). */ + players: RosterEntry[] +} + +function rosterList(value: unknown): RosterEntry[] | null { + if (!Array.isArray(value)) return null + return value as RosterEntry[] +} + +export const slice: Slice = { + name: 'roster', + init: () => ({ players: [] }), + reduce(state: RosterState, event: ReducerEvent, _root: RootState): void { + if (event.type !== 'frame' || event.frame.t !== 'roster') return + const players = rosterList(event.frame['players']) + if (players) state.players = players + }, +} diff --git a/client/src/store.ts b/client/src/store.ts new file mode 100644 index 0000000..974ec70 --- /dev/null +++ b/client/src/store.ts @@ -0,0 +1,35 @@ +// The store is the tiny bridge between the pure reducer and the renderer/DOM shell. It owns the +// current state and notifies subscribers once per dispatch; render modules update only the +// entities they saw change (DESIGN 7.2), so no module may assume a frame-by-frame redraw. + +import type { ReducerEvent, RootState } from './reducer.ts' +import { initialState, reduce } from './reducer.ts' + +export type Listener = (state: RootState, event: ReducerEvent) => void + +export class Store { + #state: RootState + #listeners = new Set() + + constructor(state: RootState = initialState()) { + this.#state = state + } + + get state(): RootState { + return this.#state + } + + dispatch(event: ReducerEvent): RootState { + const next = reduce(this.#state, event) + this.#state = next + for (const listener of this.#listeners) listener(next, event) + return next + } + + subscribe(listener: Listener): () => void { + this.#listeners.add(listener) + return () => { + this.#listeners.delete(listener) + } + } +} diff --git a/client/src/style.css b/client/src/style.css new file mode 100644 index 0000000..6515adb --- /dev/null +++ b/client/src/style.css @@ -0,0 +1,104 @@ +html, +body { + margin: 0; + height: 100%; + overflow: hidden; + background: #000; + color: #eee; + font: 14px/1.4 system-ui, sans-serif; +} + +#app { + position: fixed; + inset: 0; +} + +[hidden] { + display: none !important; +} + +#stage { + position: absolute; + inset: 0; +} + +#stage canvas { + display: block; +} + +#boot, +#signin, +#fatal { + position: absolute; + inset: 0; + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + gap: 12px; + padding: 24px; + text-align: center; +} + +#signin form { + display: flex; + flex-direction: column; + gap: 8px; + width: min(360px, 90vw); +} + +#key { + font: inherit; + padding: 10px 12px; + border-radius: 6px; + border: 1px solid #555; + background: #111; + color: inherit; + letter-spacing: 0.08em; + text-transform: uppercase; +} + +#signin button, +#fatal button { + font: inherit; + padding: 10px 12px; + border-radius: 6px; + border: 1px solid #777; + background: #222; + color: inherit; +} + +#signin-error { + color: #ff8a8a; +} + +#hud { + position: absolute; + top: 0; + left: 0; + right: 0; + display: flex; + gap: 16px; + align-items: baseline; + padding: 6px 12px; + background: rgb(0 0 0 / 65%); + pointer-events: none; + font: 12px/1.4 ui-monospace, monospace; +} + +#roster { + display: flex; + gap: 12px; + margin: 0; + padding: 0; + list-style: none; +} + +#roster li { + display: flex; + gap: 4px; +} + +#roster-state { + opacity: 0.6; +} diff --git a/client/src/vite-env.d.ts b/client/src/vite-env.d.ts new file mode 100644 index 0000000..11f02fe --- /dev/null +++ b/client/src/vite-env.d.ts @@ -0,0 +1 @@ +/// diff --git a/client/src/ws.ts b/client/src/ws.ts new file mode 100644 index 0000000..8826e4c --- /dev/null +++ b/client/src/ws.ts @@ -0,0 +1,143 @@ +// The protocol client (DESIGN 6.2, 6.3, 6.5; spec #63 decision 14). It owns the socket, the `reqId` +// counter and the pending-request map; it emits reducer events and never touches the DOM. The +// socket factory and clock-free design make it unit-testable without a browser. +// +// Close mapping (6.5, FIXED #18): a server-initiated close is `closing {reason, code}` and then a +// close frame the browser reports as 1005, so the reason always comes from the last `closing` frame. +// `revoked` and `proto-mismatch` are terminal: this client does not reconnect to them. Reconnect +// with backoff is T5 (#68); T4 only proves the outcome mapping. + +import type { AckFrame, CloseReason, ServerFrame } from './protocol.ts' +import { encodeIntent, isAck, isClosing, parseServerFrame, wsUrl } from './protocol.ts' + +export interface SocketLike { + send(data: string): void + close(code?: number, reason?: string): void + onopen: (() => void) | null + onmessage: ((event: { data: unknown }) => void) | null + onclose: ((event: { code: number; reason: string }) => void) | null + onerror: ((event: unknown) => void) | null +} + +export type ClientEvent = + | { type: 'open' } + | { type: 'frame'; frame: ServerFrame } + | { type: 'close'; reason: CloseReason | null; code: number | null } + +export interface ProtocolClientOptions { + url?: string + createSocket?: (url: string) => SocketLike + onEvent: (event: ClientEvent) => void +} + +type Pending = { + resolve: (ack: AckFrame) => void + reject: (error: Error) => void +} + +function defaultSocket(url: string): SocketLike { + return new WebSocket(url) as unknown as SocketLike +} + +export class ProtocolClient { + #url: string + #createSocket: (url: string) => SocketLike + #onEvent: (event: ClientEvent) => void + #socket: SocketLike | null = null + #nextReqId = 1 + #pending = new Map() + #lastClosing: { reason: CloseReason; code: number } | null = null + #state: 'idle' | 'connecting' | 'open' | 'closed' = 'idle' + + constructor(options: ProtocolClientOptions) { + this.#url = options.url ?? wsUrl() + this.#createSocket = options.createSocket ?? defaultSocket + this.#onEvent = options.onEvent + } + + get state(): 'idle' | 'connecting' | 'open' | 'closed' { + return this.#state + } + + get pendingCount(): number { + return this.#pending.size + } + + connect(): void { + if (this.#state !== 'idle') return + this.#state = 'connecting' + const socket = this.#createSocket(this.#url) + this.#socket = socket + + socket.onopen = () => { + if (this.#state !== 'connecting') return + this.#state = 'open' + this.#onEvent({ type: 'open' }) + } + socket.onmessage = event => { + if (this.#state === 'closed') return // a frame in flight after the client closed + const frame = parseServerFrame(event.data) + if (!frame) return // binary or unreadable: 6.2 says ignore what cannot be read + if (isClosing(frame)) this.#lastClosing = { reason: frame.reason, code: frame.code } + if (isAck(frame)) { + const pending = this.#pending.get(frame.reqId) + if (pending) { + this.#pending.delete(frame.reqId) + pending.resolve(frame) + } + } + this.#onEvent({ type: 'frame', frame }) + } + socket.onerror = () => { + // The browser follows an error with a close; mapping the outcome there keeps it single. + } + socket.onclose = event => { + if (this.#state === 'closed') return + this.#state = 'closed' + const reason = this.#lastClosing?.reason ?? null + const code = this.#lastClosing?.code ?? event.code ?? null + this.#failPending(new Error(`connection closed (${reason ?? code ?? 'no code'})`)) + this.#onEvent({ type: 'close', reason, code }) + } + } + + /** + * Send one intent and resolve with its single `ack` (DESIGN 6 Conventions: exactly one ack per + * readable intent, whatever the outcome). Pending reqIds die with the connection (6.3), and a + * `hello` on a live connection does not drop them. + */ + send(t: string, fields: Record = {}): Promise { + const socket = this.#socket + if (this.#state !== 'open' || !socket) { + return Promise.reject(new Error('not connected')) + } + const reqId = this.#nextReqId++ + const frame = encodeIntent(t, reqId, fields) + return new Promise((resolve, reject) => { + this.#pending.set(reqId, { resolve, reject }) + try { + socket.send(frame) + } catch (error) { + this.#pending.delete(reqId) + reject(error instanceof Error ? error : new Error(String(error))) + } + }) + } + + close(): void { + if (this.#state === 'closed') return + this.#state = 'closed' + try { + this.#socket?.close() + } catch { + // A socket that is already gone is the outcome we wanted. + } + this.#failPending(new Error('connection closed by the client')) + } + + #failPending(error: Error): void { + const pending = [...this.#pending.values()] + this.#pending.clear() + for (const entry of pending) entry.reject(error) + } +} diff --git a/client/test/protocol.test.ts b/client/test/protocol.test.ts new file mode 100644 index 0000000..835543d --- /dev/null +++ b/client/test/protocol.test.ts @@ -0,0 +1,137 @@ +import { describe, expect, it } from 'vitest' +import { + CLOSE_REASONS, + PROTO, + closeOutcome, + encodeIntent, + isAck, + isClosing, + isHello, + parseServerFrame, + wsUrl, +} from '../src/protocol.ts' + +const scene = { + id: 1, + name: 'Cellar', + w: 4096, + h: 4096, + tile_size: 32, + cell: 32, + grid_size: 64, + vision_radius_default: 320, + token_radius_default: 20, + art_version: 1, +} + +describe('server envelope', () => { + it('parses a JSON object with a string t and an integer n >= 1', () => { + const frame = parseServerFrame(JSON.stringify({ t: 'roster', n: 3, players: [] })) + expect(frame).toEqual({ t: 'roster', n: 3, players: [] }) + }) + + it('ignores unknown frame types without dropping them (6.2: additive only)', () => { + const frame = parseServerFrame(JSON.stringify({ t: 'future_frame', n: 2, x: 1 })) + expect(frame?.t).toBe('future_frame') + }) + + it.each([ + ['binary', new Uint8Array([1, 2, 3])], + ['non-JSON', '{not json'], + ['array', '[]'], + ['null', 'null'], + ['no t', JSON.stringify({ n: 1 })], + ['empty t', JSON.stringify({ t: '', n: 1 })], + ['no n', JSON.stringify({ t: 'hello' })], + ['n = 0', JSON.stringify({ t: 'hello', n: 0 })], + ['fractional n', JSON.stringify({ t: 'hello', n: 1.5 })], + ['string n', JSON.stringify({ t: 'hello', n: '1' })], + ])('rejects %s', (_name, raw) => { + expect(parseServerFrame(raw)).toBeNull() + }) +}) + +describe('hello', () => { + it('accepts the DESIGN 6.1 shape and carries the scene block', () => { + const frame = parseServerFrame( + JSON.stringify({ t: 'hello', n: 1, proto: 2, role: 'player', me: { id: 4, name: 'Ann' }, scene }), + ) + expect(frame && isHello(frame)).toBe(true) + if (frame && isHello(frame)) { + expect(frame.proto).toBe(2) + expect(frame.scene?.w).toBe(4096) + } + }) + + it('accepts the unnamed-player minimum (proto, role, me only)', () => { + const frame = parseServerFrame( + JSON.stringify({ t: 'hello', n: 1, proto: 2, role: 'player', me: { id: 4, name: null } }), + ) + expect(frame && isHello(frame)).toBe(true) + }) + + it('rejects a wrong role or proto', () => { + const badRole = parseServerFrame( + JSON.stringify({ t: 'hello', n: 1, proto: 2, role: 'admin', me: { id: 1, name: null } }), + ) + const badProto = parseServerFrame( + JSON.stringify({ t: 'hello', n: 1, proto: '2', role: 'gm', me: { id: 1, name: null } }), + ) + expect(badRole && isHello(badRole)).toBe(false) + expect(badProto && isHello(badProto)).toBe(false) + }) +}) + +describe('ack', () => { + it('is the envelope plus reqId and ok', () => { + const frame = parseServerFrame(JSON.stringify({ t: 'ack', n: 2, reqId: 7, ok: true, pos: [1, 2] })) + expect(frame && isAck(frame)).toBe(true) + if (frame && isAck(frame)) expect(frame.pos).toEqual([1, 2]) + }) + + it('is not an ack without an integer reqId or a boolean ok', () => { + for (const body of [ + { t: 'ack', n: 1, ok: true }, + { t: 'ack', n: 1, reqId: '7', ok: true }, + { t: 'ack', n: 1, reqId: 7, ok: 'yes' }, + ]) { + const frame = parseServerFrame(JSON.stringify(body)) + expect(frame && isAck(frame)).toBe(false) + } + }) +}) + +describe('closing and outcomes', () => { + it('accepts every static reason of DESIGN 6.5', () => { + for (const reason of CLOSE_REASONS) { + const frame = parseServerFrame( + JSON.stringify({ t: 'closing', n: 9, reason, code: 4001 }), + ) + expect(frame && isClosing(frame)).toBe(true) + } + }) + + it('maps reasons to the shell outcome', () => { + expect(closeOutcome('proto-mismatch')).toBe('reload') + expect(closeOutcome('revoked')).toBe('signin') + expect(closeOutcome('evicted')).toBe('offline') + expect(closeOutcome('malformed-flood')).toBe('offline') + expect(closeOutcome(null)).toBe('offline') + }) +}) + +describe('intents', () => { + it('always carry t and reqId and nothing secret', () => { + const raw = encodeIntent('conn.ping', 3, { ts: 99 }) + expect(JSON.parse(raw)).toEqual({ t: 'conn.ping', reqId: 3, ts: 99 }) + }) + + it('builds the /ws URL with the required proto parameter', () => { + expect(wsUrl({ protocol: 'https:', host: 'table.example' })).toBe( + `wss://table.example/ws?proto=${PROTO}`, + ) + expect(wsUrl({ protocol: 'http:', host: '127.0.0.1:8080' })).toBe( + `ws://127.0.0.1:8080/ws?proto=${PROTO}`, + ) + }) +}) diff --git a/client/test/reducer.test.ts b/client/test/reducer.test.ts new file mode 100644 index 0000000..574c23d --- /dev/null +++ b/client/test/reducer.test.ts @@ -0,0 +1,184 @@ +import { describe, expect, it } from 'vitest' +import { SLICES, initialState, reduce, rosterOf } from '../src/reducer.ts' +import type { ReducerEvent, RootState } from '../src/reducer.ts' +import { parseServerFrame } from '../src/protocol.ts' +import type { RosterEntry } from '../src/protocol.ts' + +const scene = (name: string) => ({ + id: 1, + name, + w: 4096, + h: 4096, + tile_size: 32, + cell: 32, + grid_size: 64, + vision_radius_default: 320, + token_radius_default: 20, + art_version: 1, +}) + +const frame = (body: Record): ReducerEvent => { + const parsed = parseServerFrame(JSON.stringify(body)) + if (!parsed) throw new Error(`bad test frame ${JSON.stringify(body)}`) + return { type: 'frame', frame: parsed } +} + +const hello = (n: number, extra: Record = {}): ReducerEvent => + frame({ + t: 'hello', + n, + proto: 2, + role: 'player', + me: { id: 2, name: 'Ann' }, + scene: scene('Cellar'), + ...extra, + }) + +const roster = (n: number, players: RosterEntry[]): ReducerEvent => + frame({ t: 'roster', n, players }) + +const run = (...events: ReducerEvent[]): RootState => + events.reduce((state, event) => reduce(state, event), initialState()) + +describe('hello resets the whole view (6.1/6.3)', () => { + it('clears every slice and replaces session fields on a second hello', () => { + const first = run( + { type: 'connecting' }, + hello(1), + roster(2, [ + { id: 2, name: 'Ann', role: 'player', colour: '#f00', connected: true }, + { id: 1, name: 'GM', role: 'gm', colour: '#0f0', connected: true }, + ]), + ) + expect(first.connection.phase).toBe('live') + expect(first.session.role).toBe('player') + expect(first.session.me).toEqual({ id: 2, name: 'Ann' }) + expect(first.session.scene?.name).toBe('Cellar') + expect(rosterOf(first)).toHaveLength(2) + + // Reconnect: the server sends hello first, then the resync. Nothing from the old connection + // may survive, otherwise a token that left the view would stay on screen. + const second = reduce(first, hello(9, { role: 'gm', me: { id: 1, name: 'GM' }, scene: scene('Attic') })) + expect(rosterOf(second)).toEqual([]) + expect(second.session.role).toBe('gm') + expect(second.session.scene?.name).toBe('Attic') + expect(second.connection.phase).toBe('live') + expect(second.connection.frames).toBe(3) + expect(second.connection.lastN).toBe(9) + }) + + it('stays on the other slices while a hello resets them', () => { + const state = run( + { type: 'connecting' }, + hello(1), + roster(2, [{ id: 2, name: 'Ann', role: 'player', colour: '#f00', connected: true }]), + hello(3), + ) + expect(Object.keys(state.slices).sort()).toEqual(SLICES.map(slice => slice.name).sort()) + expect(rosterOf(state)).toEqual([]) + }) +}) + +describe('no data before join', () => { + it('connecting clears session and slices, so a stranger is shown nothing', () => { + const live = run( + { type: 'connecting' }, + hello(1), + roster(2, [{ id: 1, name: 'GM', role: 'gm', colour: '#0f0', connected: true }]), + ) + const cleared = reduce(live, { type: 'connecting' }) + expect(cleared.connection.phase).toBe('connecting') + expect(cleared.session).toEqual({ role: null, me: null, proto: null, scene: null }) + expect(rosterOf(cleared)).toEqual([]) + }) + + it('a refused upgrade (close before hello) lands on sign-in', () => { + const state = run({ type: 'connecting' }, { type: 'close', reason: null, code: 1006 }) + expect(state.connection.phase).toBe('signin') + expect(state.session.me).toBeNull() + }) + + it('a failed key shows a sign-in error and no session', () => { + const state = run({ type: 'connecting' }, { type: 'signin-failed', message: 'Key not recognised.' }) + expect(state.connection.phase).toBe('signin') + expect(state.connection.error).toBe('Key not recognised.') + expect(state.session.me).toBeNull() + }) +}) + +describe('connection outcomes (6.5)', () => { + it('proto-mismatch asks for a reload', () => { + const state = run( + { type: 'connecting' }, + hello(1), + frame({ t: 'closing', n: 2, reason: 'proto-mismatch', code: 4003 }), + { type: 'close', reason: 'proto-mismatch', code: 4003 }, + ) + expect(state.connection.phase).toBe('reload') + }) + + it('revoked returns to sign-in and clears the view', () => { + const state = run( + { type: 'connecting' }, + hello(1), + roster(2, [{ id: 2, name: 'Ann', role: 'player', colour: '#f00', connected: true }]), + frame({ t: 'closing', n: 3, reason: 'revoked', code: 4001 }), + { type: 'close', reason: 'revoked', code: 4001 }, + ) + expect(state.connection.phase).toBe('signin') + expect(state.connection.notice).toMatch(/session has ended/i) + expect(state.session.me).toBeNull() + expect(rosterOf(state)).toEqual([]) + }) + + it('evicted goes offline but keeps the tab usable', () => { + const state = run( + { type: 'connecting' }, + hello(1), + frame({ t: 'closing', n: 2, reason: 'evicted', code: 4002 }), + ) + expect(state.connection.phase).toBe('offline') + }) + + it('a transport close while live is offline, not a silent sign-out', () => { + const state = run({ type: 'connecting' }, hello(1), { type: 'close', reason: null, code: 1006 }) + expect(state.connection.phase).toBe('offline') + }) +}) + +describe('frames', () => { + it('ignores an unknown server message type (6.2) without touching the view', () => { + const state = run( + { type: 'connecting' }, + hello(1), + frame({ t: 'future_frame', n: 2, payload: 42 }), + ) + expect(state.connection.phase).toBe('live') + expect(state.connection.lastN).toBe(2) + }) + + it('a roster frame replaces the list instead of merging', () => { + const a: RosterEntry = { id: 1, name: 'GM', role: 'gm', colour: '#0f0', connected: true } + const b: RosterEntry = { id: 2, name: 'Ann', role: 'player', colour: '#f00', connected: true } + const state = run({ type: 'connecting' }, hello(1), roster(2, [a, b]), roster(3, [b])) + expect(rosterOf(state)).toEqual([b]) + }) + + it('keeps the session intact when a non-hello frame arrives', () => { + const state = run({ type: 'connecting' }, hello(1), frame({ t: 'error', n: 2, code: 'malformed' })) + expect(state.session.me).toEqual({ id: 2, name: 'Ann' }) + }) +}) + +describe('registry', () => { + it('registers the roster slice without an import list', () => { + expect(SLICES.map(slice => slice.name)).toContain('roster') + }) + + it('rotates every server frame through the slice too', () => { + const state = run({ type: 'connecting' }, hello(1)) + const withRoster = reduce(state, roster(2, [{ id: 1, name: 'GM', role: 'gm', colour: '#0f0', connected: true }])) + expect(rosterOf(withRoster)).toHaveLength(1) + }) +}) + diff --git a/client/test/ws.test.ts b/client/test/ws.test.ts new file mode 100644 index 0000000..d29a0a6 --- /dev/null +++ b/client/test/ws.test.ts @@ -0,0 +1,147 @@ +import { describe, expect, it } from 'vitest' +import { ProtocolClient } from '../src/ws.ts' +import type { ClientEvent, SocketLike } from '../src/ws.ts' + +class FakeSocket implements SocketLike { + onopen: (() => void) | null = null + onmessage: ((event: { data: unknown }) => void) | null = null + onclose: ((event: { code: number; reason: string }) => void) | null = null + onerror: ((event: unknown) => void) | null = null + sent: string[] = [] + closed = false + + send(data: string): void { + if (this.closed) throw new Error('socket is closed') + this.sent.push(data) + } + + close(): void { + this.closed = true + } + + open(): void { + this.onopen?.() + } + + receive(body: unknown): void { + this.onmessage?.({ data: typeof body === 'string' ? body : JSON.stringify(body) }) + } + + serverClose(code = 1005, reason = ''): void { + this.closed = true + this.onclose?.({ code, reason }) + } +} + +function connect(): { + client: ProtocolClient + socket: FakeSocket + events: ClientEvent[] +} { + const socket = new FakeSocket() + const events: ClientEvent[] = [] + const client = new ProtocolClient({ + url: 'wss://test/ws?proto=2', + createSocket: () => socket, + onEvent: event => events.push(event), + }) + client.connect() + socket.open() + return { client, socket, events } +} + +describe('protocol client', () => { + it('parses text frames and ignores binary or unreadable ones', () => { + const { socket, events } = connect() + socket.receive({ t: 'hello', n: 1, proto: 2, role: 'player', me: { id: 1, name: null } }) + socket.receive('not json') + socket.onmessage?.({ data: new Uint8Array([1, 2]) }) + expect(events.filter(event => event.type === 'frame')).toHaveLength(1) + }) + + it('correlates one ack per reqId and ignores an unknown ack', async () => { + const { client, socket } = connect() + const first = client.send('conn.ping', { ts: 11 }) + const second = client.send('conn.ping', { ts: 12 }) + expect(client.pendingCount).toBe(2) + const sent = socket.sent.map(raw => JSON.parse(raw) as { t: string; reqId: number; ts: number }) + expect(sent.map(intent => intent.t)).toEqual(['conn.ping', 'conn.ping']) + expect(sent[0]?.reqId).toBe(1) + expect(sent[1]?.reqId).toBe(2) + + socket.receive({ t: 'ack', n: 1, reqId: 2, ok: true, ts: 12 }) + socket.receive({ t: 'ack', n: 2, reqId: 99, ok: true }) + expect(client.pendingCount).toBe(1) + await expect(second).resolves.toMatchObject({ reqId: 2, ok: true }) + + socket.receive({ t: 'ack', n: 3, reqId: 1, ok: false, code: 'invalid' }) + await expect(first).resolves.toMatchObject({ reqId: 1, ok: false, code: 'invalid' }) + expect(client.pendingCount).toBe(0) + }) + + it('keeps pending requests across a hello on a live connection (6.3)', async () => { + const { client, socket } = connect() + const pending = client.send('player.setname', { name: 'Ann' }) + socket.receive({ t: 'hello', n: 1, proto: 2, role: 'player', me: { id: 1, name: 'Ann' } }) + expect(client.pendingCount).toBe(1) + socket.receive({ t: 'ack', n: 2, reqId: 1, ok: true }) + await expect(pending).resolves.toMatchObject({ ok: true }) + }) + + it('drops pending requests with the connection (6.3)', async () => { + const { client, socket } = connect() + const pending = client.send('conn.ping', { ts: 1 }) + socket.serverClose(1006) + expect(client.pendingCount).toBe(0) + await expect(pending).rejects.toThrow(/closed/) + }) + + it('reads a server close reason from the last closing frame (6.5, FIXED #18)', () => { + const { socket, events } = connect() + socket.receive({ t: 'closing', n: 2, reason: 'revoked', code: 4001 }) + socket.serverClose(1005) + expect(events.at(-1)).toEqual({ type: 'close', reason: 'revoked', code: 4001 }) + }) + + it('treats a close without a closing frame as a transport failure', () => { + const { socket, events } = connect() + socket.serverClose(1006) + expect(events.at(-1)).toEqual({ type: 'close', reason: null, code: 1006 }) + }) + + it('does not reconnect to a terminal outcome (single connect)', () => { + const socket = new FakeSocket() + const sockets: FakeSocket[] = [socket] + const client = new ProtocolClient({ + url: 'wss://test/ws?proto=2', + createSocket: () => socket, + onEvent: () => {}, + }) + client.connect() + socket.open() + socket.receive({ t: 'closing', n: 1, reason: 'proto-mismatch', code: 4003 }) + socket.serverClose(1005) + client.connect() // a no-op once closed + expect(sockets).toHaveLength(1) + expect(client.state).toBe('closed') + }) + + it('ignores a frame that arrives after the client closed the socket', () => { + const { client, socket, events } = connect() + client.close() + const before = events.length + socket.receive({ t: 'hello', n: 1, proto: 2, role: 'player', me: { id: 1, name: null } }) + expect(events).toHaveLength(before) + }) + + it('refuses to send before the socket opens', async () => { + const socket = new FakeSocket() + const client = new ProtocolClient({ + url: 'wss://test/ws?proto=2', + createSocket: () => socket, + onEvent: () => {}, + }) + client.connect() + await expect(client.send('conn.ping', { ts: 1 })).rejects.toThrow(/not connected/) + }) +}) diff --git a/client/tsconfig.json b/client/tsconfig.json new file mode 100644 index 0000000..e675443 --- /dev/null +++ b/client/tsconfig.json @@ -0,0 +1,19 @@ +{ + "compilerOptions": { + "target": "ES2022", + "module": "ESNext", + "moduleResolution": "bundler", + "lib": ["ES2022", "DOM", "DOM.Iterable"], + "strict": true, + "noEmit": true, + "skipLibCheck": true, + "isolatedModules": true, + "verbatimModuleSyntax": true, + "erasableSyntaxOnly": true, + "allowImportingTsExtensions": true, + "noUncheckedIndexedAccess": true, + "noImplicitOverride": true, + "types": ["vite/client"] + }, + "include": ["src", "test"] +} diff --git a/client/vite.config.ts b/client/vite.config.ts new file mode 100644 index 0000000..f5b9a5f --- /dev/null +++ b/client/vite.config.ts @@ -0,0 +1,13 @@ +import { defineConfig } from 'vitest/config' + +// The client is served from `/` by the nginx vhost (DESIGN 11.1, #66), so assets are absolute +// (`/assets/...`) and content-hashed. Tests are pure modules (no DOM): the reducer seam has no +// Pixi import, so Vitest needs no browser environment. +export default defineConfig({ + base: '/', + build: { target: 'es2022' }, + test: { + include: ['test/**/*.test.ts'], + environment: 'node', + }, +}) diff --git a/devbox.json b/devbox.json index 3c585cc..0b60421 100644 --- a/devbox.json +++ b/devbox.json @@ -26,7 +26,10 @@ "tools/test.sh" ], "e2e": [ - "e2e/run.sh" + "client/e2e/run.sh" + ], + "client-test": [ + "client/run-tests.sh" ], "mutation": [ "tools/mutation.sh" diff --git a/docs/DESIGN.md b/docs/DESIGN.md index b9c93fc..6c3117e 100644 --- a/docs/DESIGN.md +++ b/docs/DESIGN.md @@ -1898,6 +1898,9 @@ they are not fed until resync, and nginx closes dead peers (M5). 6. **DOM overlay**: toolbars, token panel, player keys dialog, connection status; plain HTML on top of the canvas (no framework) [FIXED]. +The module layout and the append-only extension rules (one reducer slice file, one render module +file per feature; no shared registry edit) are written in `client/README.md` [T4, #67]. + ### 7.2 Rendering techniques kept from the perf prototype [MEASURED, `prototype-pixi-perf/README.md`] - Verdict: Pixi v8 renders a VTT scene at 60 fps on Radeon 780M (WebGL and WebGPU) and Galaxy Note 10 (WebGL) up to 1000 tokens (Note 10 js ~14 ms, 2000 tokens -> 32-36 fps, CPU-bound; laptop js diff --git a/docs/TESTING.md b/docs/TESTING.md index 288face..322bcb6 100644 --- a/docs/TESTING.md +++ b/docs/TESTING.md @@ -344,7 +344,7 @@ from the prototype, what was missing, what the M3 build added, and the tools it | Negative control / fault injection | `tools/faulttest.sh`, `-d:leakfault` build | 8 faults, exact failure-class set each, clean build passes, `LEAK_FAULT` string asserted absent from clean binary [MEASURED 8/8]. Port and extend. | | Restart | `tools/restart.mjs` | SIGTERM + SIGKILL, identical player keys/positions/doors/vision/explored/hello+state. | | Concurrency | `tools/concurrency.mjs` | 60 s, 3 clients, gseq monotonic, every intent acked, quiesced views == fresh connection. **M5 port [FIXED, #15]:** 6 walkers on one GM socket (~200/s) exceeds the 30/s per-connection rate (DESIGN §6.4); spread walkers across connections (4 per player, 16 total; DESIGN §4.3). | -| Client reducer tests | `client/src/state.test.ts` | Incl. reconnect reset. | +| Client reducer tests | `client/test/*.test.ts` (Vitest) | Pure frame/ack -> state; `hello` resets every slice. No Pixi or DOM import at the seam. | | Smoke | `tools/smoke.mjs` | auth/cookie/tile/steal/garbage. | | Isolation harness | `tools/withserver.sh` | own DB/ports (`run/test/`), never touch a live session. | @@ -555,16 +555,22 @@ from the prototype, what was missing, what the M3 build added, and the tools it already drives devbox chromium, `prototype-pixi-perf/bench.mjs`; SwiftShader is fine for correctness, not for perf). Checks: join -> canvas renders; pixel probe shows unexplored area black, visible area map-coloured, dimmed explored area; GM sees walls, player DOM/network contains none; reconnect - restores view; drag moves token and rollback works. The harness is `e2e/` and the gate is - `devbox run e2e`, separate from `devbox run test` (§11.1). + restores view; drag moves token and rollback works. The harness is `client/e2e/` (the client package + owns `playwright-core`, outside `tools/`; TESTING 10.4 keeps the black-box harnesses npm-free) and the + gate is `devbox run e2e`, which builds the real client and is separate from `devbox run test` (§11.1). + T4's slice of it (`client/e2e/shell.test.mjs`, `mismatch.test.mjs`): no session shows only the + sign-in door and no canvas; a wrong and an unknown key give the same `401` and the same + "Key not recognised." text; GM and player join, get the canvas and the `hello`/`roster` HUD; a + server `closing{proto-mismatch}` shows reload and stops; a revoked key returns the page to sign-in + with no reconnection. - **TLS/HTTP2 vhost (#66)**: `tools/vhost.test.mjs` (built-ins, `node:http2`) is the independent client for the vhost itself: the generated certificate is self-signed and names loopback, ALPN selects `h2`, `/` serves the client `dist` with index `no-cache`, `/assets/` with a year-immutable cache and no SPA fallback for a missing hash, a client route falls back to `index.html`, and direct - `/_tiles/` is still 404. `e2e/h2.test.mjs` proves the same from real Chromium: it loads the dist and - `performance.getEntriesByType('navigation')[0].nextHopProtocol` is `h2` over TLS. Before the client - exists the served `dist` is the throwaway fixture of `tools/distfixture.mjs`; T4 replaces it with - the real Vite build and extends the same gate. + `/_tiles/` is still 404. `client/e2e/h2.test.mjs` proves the same from real Chromium against the + real Vite build (`client/e2e/run.sh` runs `npm run build` first): + `performance.getEntriesByType('navigation')[0].nextHopProtocol` is `h2` over TLS. The vhost group + keeps a local stub dist because `devbox run test` must not depend on the client's npm install. - **Independent traffic audit in e2e**: record all WS frames and HTTP responses seen by a player browser and run the leak checker's (a)(e) assertions over them. @@ -583,15 +589,19 @@ from the prototype, what was missing, what the M3 build added, and the tools it `tools/wsheaders.test.mjs` so a Node upgrade that drops the option fails loudly. - Root `devbox.json` pins `nodejs` 26 and the `nginx` used only by the test harness (DESIGN §11.1); no global tooling. M4 (#66) adds `chromium` (the browser e2e) and `openssl` (generating the test - certificate); the e2e's only npm dependency, `playwright-core`, is pinned by `e2e/package-lock.json` - and lives outside `tools/`, so this built-ins-only rule keeps holding. -- `devbox run test` = Nim tests first, then Node harnesses. + certificate); the e2e's only npm dependency, `playwright-core`, is pinned by + `client/package-lock.json` and lives with the client, outside `tools/`, so this built-ins-only rule + keeps holding. +- `devbox run test` = Nim tests first, then Node harnesses. `devbox run client-test` = the client's + Vitest seam (pure reducer, protocol client, envelope); `devbox run e2e` = the built client through + the real server and vhost. The finish gate runs all three. - The nine M3 accept groups and their proving harness tests are mapped in `tools/groups.mjs`; `tools/groups.test.mjs` fails if a group file or its named evidence test disappears, so the acceptance checklist cannot silently go stale. Harnesses that are not an accept group (`smoke`, `walls`, `tokens`, `details`, `scene`, `wsheaders`) run in the same pass. - In-process tests stay Nim (`nimble test`, unchanged). -- Browser e2e details: M4, not decided here. +- Browser e2e details and the client-side extension rules (append-only reducer slices and render + modules): `client/README.md`. --- diff --git a/e2e/h2.test.mjs b/e2e/h2.test.mjs deleted file mode 100644 index 4394cbe..0000000 --- a/e2e/h2.test.mjs +++ /dev/null @@ -1,80 +0,0 @@ -// The browser e2e gate (TESTING 10.3 "Browser e2e"; #66 first slice). `playwright-core` drives the -// devbox `chromium` against the real server through the TLS/HTTP2 test nginx: the one proof that -// matters before a phone is asked to measure is that real browsers negotiate h2 over the vhost and -// execute the built client from `/`. -// -// The app's own e2e (join, fog pixels, drag, reconnect, traffic audit) lands with the client in T4+ -// on this same harness. Here the page is the fixture `dist` of tools/distfixture.mjs, so the gate -// exists and is green before the client package does. -import test from 'node:test' -import assert from 'node:assert/strict' -import fs from 'node:fs' -import { chromium } from 'playwright-core' -import { freePort, httpsBaseUrl } from '../tools/lib.mjs' -import { makeStateDir, startServer, stopServer } from '../tools/withserver.mjs' -import { startTestNginx, stopTestNginx } from '../tools/nginx.mjs' -import { writeClientDist } from '../tools/distfixture.mjs' - -// Nix's chromium is a wrapper around the real binary; playwright-core launches it by path (the -// perf prototype does the same). SwiftShader is enough for correctness, never for a perf number. -const CHROMIUM = process.env.CHROMIUM ?? 'chromium' -const LAUNCH_ARGS = ['--no-sandbox', '--use-angle=swiftshader', '--enable-unsafe-swiftshader', - '--ignore-gpu-blocklist'] - -async function stack(fn) { - const stateDir = makeStateDir() - const dist = writeClientDist(`${stateDir}/dist`) - const nginxPort = await freePort() - const server = await startServer({ stateDir, publicOrigin: httpsBaseUrl(nginxPort) }) - let nginx - try { - nginx = await startTestNginx({ backendPort: server.port, stateDir, port: nginxPort, distDir: dist.dir }) - return await fn({ stateDir, server, nginx, dist, origin: nginx.origin }) - } finally { - await stopTestNginx(nginx) - await stopServer(server) - fs.rmSync(stateDir, { recursive: true, force: true }) - } -} - -test('e2e: headless chromium loads the client dist and the page reports h2', async () => { - await stack(async ({ origin, dist }) => { - const browser = await chromium.launch({ executablePath: CHROMIUM, args: LAUNCH_ARGS }) - try { - // The certificate is a generated self-signed one (tools/tlsdev.mjs); a browser must be told - // to accept it. Every other security property of the page is the real thing. - const context = await browser.newContext({ ignoreHTTPSErrors: true }) - const page = await context.newPage() - const loaded = [] - page.on('response', r => loaded.push({ url: r.url(), status: r.status() })) - const errors = [] - page.on('pageerror', e => errors.push(e.message)) - page.on('console', m => { if (m.type() === 'error') errors.push(m.text()) }) - - await page.goto(`${origin}/`, { waitUntil: 'load' }) - - assert.equal(await page.title(), 'fff-vtt client fixture') - assert.equal(await page.textContent('#fixture'), 'client dist fixture') - // The hashed asset was fetched and executed by the vhost's immutable-cache location. - assert.equal(await page.evaluate(() => document.documentElement.dataset.fixture), 'loaded') - assert.deepEqual(errors, []) - const assetResponse = loaded.find(r => r.url.endsWith(dist.assetPath)) - assert.ok(assetResponse, `the page loaded ${dist.assetPath}: ${JSON.stringify(loaded)}`) - assert.equal(assetResponse.status, 200) - - // The acceptance criterion: the browser's own view of the connection is h2 over TLS. - const proto = await page.evaluate(() => { - const nav = performance.getEntriesByType('navigation')[0] - const resources = performance.getEntriesByType('resource') - .map(e => ({ name: e.name, protocol: e.nextHopProtocol })) - return { scheme: location.protocol, navigation: nav.nextHopProtocol, resources } - }) - assert.equal(proto.scheme, 'https:') - assert.equal(proto.navigation, 'h2', 'the document came over HTTP/2') - assert.ok(proto.resources.some(r => r.protocol === 'h2' && r.name.endsWith('.js')), - `subresources are h2 too: ${JSON.stringify(proto.resources)}`) - } finally { - await browser.close() - } - }) -}) diff --git a/e2e/package-lock.json b/e2e/package-lock.json deleted file mode 100644 index 3f7aa26..0000000 --- a/e2e/package-lock.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "name": "fff-vtt-e2e", - "version": "1.0.0", - "lockfileVersion": 3, - "requires": true, - "packages": { - "": { - "name": "fff-vtt-e2e", - "version": "1.0.0", - "devDependencies": { - "playwright-core": "1.65.1" - } - }, - "node_modules/playwright-core": { - "version": "1.65.1", - "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.65.1.tgz", - "integrity": "sha512-hqPpz7blSMPxWVdoeE1yiBSzXsKiVOd2k+kjCvmUywD2GPO2Dd9HfcWnq9NN0GHbNZDFgZ9JfBFr+X5/BLo0qw==", - "dev": true, - "license": "Apache-2.0", - "bin": { - "playwright-core": "cli.js" - }, - "engines": { - "node": ">=20" - } - } - } -} diff --git a/e2e/package.json b/e2e/package.json deleted file mode 100644 index a73388e..0000000 --- a/e2e/package.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "name": "fff-vtt-e2e", - "version": "1.0.0", - "private": true, - "type": "module", - "description": "Headless-browser e2e for fff-vtt (playwright-core + the devbox chromium). Lives outside tools/ because TESTING 10.4 keeps the black-box harnesses npm-dependency-free.", - "devDependencies": { - "playwright-core": "1.65.1" - } -} diff --git a/e2e/run.sh b/e2e/run.sh deleted file mode 100755 index bad1307..0000000 --- a/e2e/run.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/env bash -# devbox run e2e: the headless-browser gate (TESTING 10.3). Separate from `devbox run test` so the -# fast server gate stays fast (TESTING 11.1 note in #66). Requires the root devbox's `chromium` and -# the e2e/ npm dependency (`playwright-core`); the client build test in T4+ extends this script. -set -euo pipefail -cd "$(dirname "$0")/.." || exit 1 -mkdir -p results -export CHROMIUM="${CHROMIUM:-$(command -v chromium || true)}" -if [ -z "$CHROMIUM" ]; then - echo "e2e: chromium not found; it is a root devbox package (devbox.json) - run inside devbox" >&2 - exit 1 -fi -# npm deps stay out of tools/ (TESTING 10.4) and out of git; install once per checkout. -( cd e2e && { [ -d node_modules ] || npm ci --no-audit --no-fund; } ) -node --test --test-concurrency=1 --test-reporter=spec e2e/*.test.mjs > results/e2e.log 2>&1 -rc=$? -cat results/e2e.log -exit $rc diff --git a/tools/distfixture.mjs b/tools/distfixture.mjs deleted file mode 100644 index c6bbf61..0000000 --- a/tools/distfixture.mjs +++ /dev/null @@ -1,24 +0,0 @@ -// A throwaway client build for the vhost tests (#66). The real Vite build lands in T4; until then the -// test nginx's `/` needs *some* `dist` to serve, with the shape DESIGN 11.1 pins: an index.html that -// names a content-hashed asset under /assets/. Nothing here is committed: the fixture is written into -// the run's state dir, and no version of it pretends to be the client. -import fs from 'node:fs' -import path from 'node:path' - -export const ASSET_HASH = 'a1b2c3d4e5f6' - -export function writeClientDist(dir, { hash = ASSET_HASH } = {}) { - const assetPath = `/assets/app-${hash}.js` - fs.mkdirSync(path.join(dir, 'assets'), { recursive: true }) - const index = ` - -fff-vtt client fixture - -

client dist fixture

- -` - const asset = `// content-hashed fixture asset (#66)\ndocument.documentElement.dataset.fixture = 'loaded'\n` - fs.writeFileSync(path.join(dir, 'index.html'), index) - fs.writeFileSync(path.join(dir, assetPath.slice(1)), asset) - return { dir, indexHtml: index, assetPath } -} diff --git a/tools/tlsdev.mjs b/tools/tlsdev.mjs index c1ebfdc..bfea2dd 100644 --- a/tools/tlsdev.mjs +++ b/tools/tlsdev.mjs @@ -4,7 +4,7 @@ // // One directory per run (`run/tls`, gitignored) is shared by every harness file in the run: the // certificate is a trust anchor for the Node side through NODE_EXTRA_CA_CERTS (set by tools/test.sh -// and e2e/run.sh), and nginx loads the same pair. The SANs are what a client checks on loopback. +// and client/e2e/run.sh), and nginx loads the same pair. The SANs are what a client checks on loopback. import { spawnSync } from 'node:child_process' import fs from 'node:fs' import path from 'node:path' diff --git a/tools/vhost.test.mjs b/tools/vhost.test.mjs index f22a175..a3d26fa 100644 --- a/tools/vhost.test.mjs +++ b/tools/vhost.test.mjs @@ -2,20 +2,43 @@ // by ALPN, the client build at `/` (SPA fallback, index no-cache, hashed assets immutable), and the // tile gate's `internal` location still unreachable from outside. The certificate is generated per // run by tools/tlsdev.mjs. Here a Node HTTP/2 client (built-in `node:http2`, TESTING 10.4) is the -// independent client; the headless-browser proof lives in `e2e/` (npm dep, outside tools/). +// independent client; the headless-browser proof against the real build lives in `client/e2e/` +// (`devbox run e2e`, npm deps outside tools/). import test from 'node:test' import assert from 'node:assert/strict' import fs from 'node:fs' import http2 from 'node:http2' +import path from 'node:path' import { X509Certificate } from 'node:crypto' import { freePort, httpsBaseUrl, refuseLivePort } from './lib.mjs' import { makeStateDir, startServer, stopServer } from './withserver.mjs' import { startTestNginx, stopTestNginx } from './nginx.mjs' -import { writeClientDist } from './distfixture.mjs' + +// This group proves nginx's config, not the app, and runs inside `devbox run test`, which must not +// need the client's npm build. The stub has the exact shape DESIGN 11.1 pins (hashed asset under +// /assets/ named by index.html); `client/e2e/h2.test.mjs` repeats the same assertions on the real +// Vite output. +const STUB_HASH = 'a1b2c3d4e5f6' + +function writeStubDist(dir) { + const assetPath = `/assets/app-${STUB_HASH}.js` + fs.mkdirSync(path.join(dir, 'assets'), { recursive: true }) + const indexHtml = ` + +vhost stub + +

dist stub

+ +` + const asset = `// content-hashed stub asset (#66)\ndocument.documentElement.dataset.stub = 'loaded'\n` + fs.writeFileSync(path.join(dir, 'index.html'), indexHtml) + fs.writeFileSync(path.join(dir, assetPath.slice(1)), asset) + return { dir, indexHtml, assetPath } +} async function stack(fn) { const stateDir = makeStateDir() - const dist = writeClientDist(`${stateDir}/dist`) + const dist = writeStubDist(`${stateDir}/dist`) const nginxPort = await freePort() refuseLivePort(nginxPort) const server = await startServer({ stateDir, publicOrigin: httpsBaseUrl(nginxPort) }) @@ -85,7 +108,7 @@ test('vhost: hashed assets are immutable, the SPA falls back, a missing asset is assert.equal(asset.alpn, 'h2') assert.match(asset.headers['content-type'], /^application\/javascript/) assert.equal(asset.headers['cache-control'], 'public, max-age=31536000, immutable') - assert.match(asset.body, /content-hashed fixture asset/) + assert.match(asset.body, /content-hashed stub asset/) // A client-side route with no file behind it is index.html (SPA fallback), revalidated. const route = await h2Get(nginx.origin, '/scene/abc/tokens')