@wildshard/engine 0.1.20 → 0.1.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/lint/engine-sides.json +1 -0
  3. package/package.json +2 -1
  4. package/scripts/chaos-proxy-core.mjs +14 -1
  5. package/scripts/chaos-proxy-proof.mjs +22 -0
  6. package/scripts/failmode-cases.d.mts +8 -0
  7. package/scripts/failmode-cases.mjs +97 -0
  8. package/scripts/failmode-proof.mjs +532 -0
  9. package/scripts/grid-crossing-nightly.mjs +5 -4
  10. package/scripts/grid-crossing-report.mjs +5 -2
  11. package/scripts/grid-crossing-tour.mjs +25 -8
  12. package/scripts/hover-speed-probe.mjs +136 -0
  13. package/scripts/net-lag-proof.mjs +3 -2
  14. package/scripts/online-rig.mjs +9 -7
  15. package/scripts/release-cook.mjs +109 -0
  16. package/scripts/vps/rebuild.sh +35 -9
  17. package/scripts/vps/wildshard-apply.mjs +5 -1
  18. package/scripts/vps/wildshard-config +117 -1
  19. package/src/client/engine/boot/contentRead.ts +54 -5
  20. package/src/client/engine/boot/gpuFiles.ts +3 -3
  21. package/src/client/engine/boot/leaveAfterPaint.ts +4 -1
  22. package/src/client/engine/core/shadowLayer.ts +18 -0
  23. package/src/client/engine/explore/pick.ts +13 -1
  24. package/src/client/engine/net/predictor.ts +12 -4
  25. package/src/client/engine/player/TouchControls.ts +3 -2
  26. package/src/client/engine/render/families/sceneSurface.ts +3 -1
  27. package/src/client/engine/telemetry/browserErrors.ts +3 -1
  28. package/src/client/engine/ui/ErrorModal.ts +1 -1
  29. package/src/client/engine/ui/Loading.ts +14 -2
  30. package/src/client/engine/ui/errorScreen.ts +51 -9
  31. package/src/client/engine/ui/hoverBoost.ts +31 -4
  32. package/src/client/engine/ui/styles/touch.css +6 -0
  33. package/src/client/game/boot/spawnDownload.ts +44 -6
  34. package/src/client/game/grid/live.ts +2 -2
  35. package/src/client/game/grid/liveSession.ts +2 -2
  36. package/src/client/game/grid/session.ts +2 -0
  37. package/src/client/game/grid/shardfileFar.ts +13 -2
  38. package/src/client/game/shardfile/clientSource.ts +7 -3
  39. package/src/client/game/shardfile/clientWorker.ts +4 -4
  40. package/src/client/game/shardfile/groundMerge.ts +5 -3
  41. package/src/client/host/online/linkScreens.ts +12 -6
  42. package/src/client/host/online/reconnectStrip.ts +3 -2
  43. package/src/client/host/online/release.ts +87 -16
  44. package/src/client/host/online/releaseScreens.ts +108 -0
  45. package/src/client/host/online/shell.ts +11 -1
  46. package/src/client/host/online/voice.ts +45 -1
  47. package/src/client/host/online/voiceUi.ts +24 -6
  48. package/src/server/engine/sim/playerSim.ts +1 -1
  49. package/src/server/game/grid/simulation.ts +12 -6
  50. package/src/server/host/dedicated/cellHost.ts +7 -0
  51. package/src/server/host/dedicated/cellWorker.ts +1 -1
  52. package/src/server/host/dedicated/dedicatedRoom.ts +14 -1
  53. package/src/server/host/dedicated/roadRoom.ts +3 -0
  54. package/src/server/host/standalone/gridServer.ts +1 -1
  55. package/src/shared/engine/boot/loadingWaits.ts +10 -2
  56. package/src/shared/engine/core/config.ts +3 -0
  57. package/src/shared/engine/player/hoverSpeed.ts +3 -3
  58. package/src/shared/engine/strings.ts +12 -1
  59. package/src/shared/game/grid/rules.ts +12 -0
@@ -0,0 +1,532 @@
1
+ #!/usr/bin/env node
2
+ // FM3 (meta docs/plans/MMO-FAILURE-MODES-PLAN.md): the failure proof. Real faults, real screens, on this Mac only. The rig of
3
+ // online-rig.mjs (the built server, a signed release file on loopback) sits behind FM2's chaos proxy (chaos-proxy-core.mjs), and a
4
+ // headless browser at 402x874 plays a build stamped with the proxy's release address. Each case (scripts/failmode-cases.mjs) gets a fresh
5
+ // browser context: a play case enters Driftwood, then the Node driver arms the fault through the proxy's control (never page script);
6
+ // a boot or load case arms it before navigation. The case passes only when the injection is seen (a proxy match, or the browser's own
7
+ // offline/freeze event), the catalogued screen (`data-failmode`) shows with primary copy free of raw errors, and the page recovers to a
8
+ // real frame (or the named terminal page) once the fault is healed. Every case is recorded in `<work>/failmodes/receipt.json`, with
9
+ // its screenshot under `<work>/failmodes/shots/`.
10
+ //
11
+ // Exit 0: every selected case passed. Exit 1: a screen is missing or wrong, a dependency row isn't built, or the engine can't produce
12
+ // the fault (all named in the receipt). Exit 2: the harness failed (setup, an injection that matched nothing, cleanup). `--baseline`
13
+ // runs every case either way; it never changes the verdict. These are Ring 2 proofs: real 35 s/120 s clocks, minutes per engine.
14
+ // Never in pre-push or CI (FM11 owns the nightly).
15
+ //
16
+ // The server lets 10 connects a minute in per address and every page here is 127.0.0.1, so play cases wait out the minute between
17
+ // them (`--cooldown=<s>`, 60) rather than lifting the cap; a long outage is held by refused upgrades that never reach the server.
18
+ //
19
+ // node scripts/failmode-proof.mjs --prepare <work> a fixture key (<work>/key.json, 0600) and a Driftwood build stamped with the
20
+ // proxy's release address (<work>/dist); prints both paths
21
+ // scripts/browser-lane.sh node scripts/failmode-proof.mjs <dist> <work> <key.json> <pg bin|memory:> <pg data>
22
+ // [--engine=chromium|webkit] [--scenario=<id,...>|all] [--baseline] [--cooldown=<s>]
23
+ // Ports: the rig from WS_RIG_PORTS (18856 here: Postgres 18856, world 18857, pages 18858, release 18859), the proxy's pages on 18851 and
24
+ // its world door on 18852. The fixture release is signed by the owned key only, channel production on loopback (staging for mode 46).
25
+ import { spawnSync } from 'node:child_process';
26
+ import { generateKeyPairSync } from 'node:crypto';
27
+ import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
28
+ import { join, resolve as absolute } from 'node:path';
29
+ import { chromium, devices, webkit } from 'playwright';
30
+ import { openChaosProxy } from './chaos-proxy-core.mjs';
31
+ import { KEYCHAIN_ARGS } from './chromium-keychain.mjs';
32
+ import { saveFixture } from './debug-settings.mjs';
33
+ import { FLOOR_GRID_ENTER } from './frame-floor-navigation.mjs';
34
+ import { rawLeak, selectCases, verdict } from './failmode-cases.mjs';
35
+
36
+ process.env.WS_RIG_PORTS ??= '18856';
37
+ const ROOT = absolute(import.meta.dirname, '..'), PROXY_PAGE = 18851, PROXY_WORLD = 18852, SHARD = 'driftwood-isle';
38
+ const PAGE_ORIGIN = `http://127.0.0.1:${String(PROXY_PAGE)}`, RELEASE_URL = `${PAGE_ORIGIN}/__release.json`, SOCKET = `ws://127.0.0.1:${String(PROXY_WORLD)}/`;
39
+ const args = process.argv.slice(2), positional = args.filter(value => !value.startsWith('--'));
40
+ /** @param {string} name @param {string} fallback */
41
+ const flag = (name, fallback) => args.find(value => value.startsWith(`--${name}=`))?.slice(name.length + 3) ?? fallback;
42
+ /** @param {number} ms */
43
+ const sleep = ms => new Promise(resolve => { setTimeout(resolve, ms); });
44
+
45
+ if (args[0] === '--prepare') {
46
+ const named = args[1];
47
+ if (named === undefined || named.startsWith('--')) throw new Error('--prepare <work>');
48
+ const work = absolute(named);
49
+ mkdirSync(work, { recursive: true });
50
+ const keyFile = join(work, 'key.json');
51
+ if (!existsSync(keyFile)) {
52
+ const pair = generateKeyPairSync('ed25519');
53
+ writeFileSync(keyFile, JSON.stringify({ public: pair.publicKey.export({ type: 'spki', format: 'der' }).toString('hex'), private: pair.privateKey.export({ type: 'pkcs8', format: 'pem' }) }), { mode: 0o600, flag: 'wx' });
54
+ }
55
+ const key = JSON.parse(readFileSync(keyFile, 'utf8')), owner = `failmode-${String(process.pid)}`;
56
+ const built = spawnSync('bash', ['scripts/serve-build.sh', '--shard', SHARD, '--name', 'failmode', '--hours', '1'], { cwd: ROOT, encoding: 'utf8',
57
+ env: { ...process.env, SERVE_OWNER: owner, WILDSHARD_RELEASE_URL: RELEASE_URL, WILDSHARD_RELEASE_KEY: key.public }, stdio: ['ignore', 'pipe', 'pipe'] });
58
+ const out = /→ (\S+)/u.exec(built.stderr)?.[1], port = /127\.0\.0\.1:(\d+)/u.exec(built.stdout)?.[1];
59
+ try {
60
+ if (built.status !== 0 || out === undefined) throw new Error(`the build failed: ${built.stderr.slice(-2000)}`);
61
+ const dist = join(work, 'dist');
62
+ rmSync(dist, { recursive: true, force: true });
63
+ if (spawnSync('cp', ['-cR', out, dist], { stdio: 'inherit' }).status !== 0) throw new Error('copying the build failed');
64
+ if (!readFileSync(join(dist, 'index.html'), 'utf8').includes(RELEASE_URL)) throw new Error('the build is not stamped with the proxy release address');
65
+ console.log(JSON.stringify({ dist, keyFile }));
66
+ } finally {
67
+ if (port !== undefined) spawnSync('bash', ['scripts/serve-build.sh', 'stop', port], { cwd: ROOT, env: { ...process.env, SERVE_OWNER: owner }, stdio: 'ignore' });
68
+ }
69
+ process.exit(0);
70
+ }
71
+
72
+ const [dist = '', work = '', keyFile = '', pgBin = '', pgData = ''] = positional;
73
+ if (pgData === '' && pgBin !== 'memory:') throw new Error('failmode-proof <dist> <work> <key.json> <pg bin|memory:> <pg data>');
74
+ const engine = flag('engine', 'chromium'), baseline = args.includes('--baseline'), cooldownMs = Number(flag('cooldown', '60')) * 1000;
75
+ if (engine !== 'chromium' && engine !== 'webkit') throw new Error('--engine=chromium|webkit');
76
+ // `--refusal=screen|injection` proves strict mode refuses: a drop that must show a screen no build has (exit 1), and a fault armed on
77
+ // a route the page never reads, so it matches nothing (exit 2). Neither is a catalogue case.
78
+ const refusal = flag('refusal', '');
79
+ if (!['', 'screen', 'injection'].includes(refusal)) throw new Error('--refusal=screen|injection');
80
+ const drop = selectCases('drop')[0];
81
+ const cases = refusal === '' ? selectCases(flag('scenario', 'all')) : drop === undefined ? [] : [refusal === 'screen' ? { ...drop, id: 'drop', screen: 'no-such-screen', mode: 'R1' } : { ...drop, id: 'unmatched', run: 'unmatched', mode: 'R2' }], out = join(absolute(work), 'failmodes'), shots = join(out, 'shots');
82
+ if (!readFileSync(join(dist, 'index.html'), 'utf8').includes(RELEASE_URL)) throw new Error(`${dist} is not stamped with ${RELEASE_URL}: build it with --prepare`);
83
+ rmSync(out, { recursive: true, force: true }); mkdirSync(shots, { recursive: true });
84
+ const sha = spawnSync('git', ['rev-parse', 'HEAD'], { cwd: ROOT, encoding: 'utf8' }).stdout.trim();
85
+
86
+ /** @typedef {import('./failmode-cases.mjs').Case} Case */
87
+ /** @typedef {import('./failmode-cases.mjs').Outcome} Outcome */
88
+ /** @typedef {{ page: import('playwright').Page, context: import('playwright').BrowserContext, errors: string[] }} Entered */
89
+ /** @typedef {{ outcome: Outcome, reason?: string, seen?: Seen | null, injection?: unknown, recovery?: string, shot?: string, notes?: unknown }} Result */
90
+ /** @typedef {{ ids: string, ms: number, copy: string, leak: string | null }} Seen */
91
+
92
+ const { openRig } = await import('./online-rig.mjs');
93
+ const rig = await openRig({ dist, work: join(absolute(work), 'rig'), keyFile, pgBin, pgData, shard: SHARD, socket: SOCKET, origins: [PAGE_ORIGIN] });
94
+ let proxy = /** @type {Awaited<ReturnType<typeof openChaosProxy>> | null} */ (null), launched = /** @type {import('playwright').Browser | null} */ (null);
95
+ const rows = /** @type {(Result & { mode: string, id: string, owner: string, screen: string, inject: string, ms: number })[]} */ ([]);
96
+ let harnessFault = /** @type {string | null} */ (null);
97
+ try {
98
+ rmSync(join(absolute(work), 'proxy'), { recursive: true, force: true });
99
+ proxy = await openChaosProxy({ work: join(absolute(work), 'proxy'), pageUpstream: rig.base, releaseUpstream: `http://127.0.0.1:${String(Number(process.env.WS_RIG_PORTS) + 3)}`, worldUpstream: `http://127.0.0.1:${String(Number(process.env.WS_RIG_PORTS) + 1)}`, pagePort: PROXY_PAGE, worldPort: PROXY_WORLD });
100
+ const token = readFileSync(proxy.ready.tokenFile, 'utf8');
101
+ /** The proxy's state, or its rules replaced. @param {{ scenario: string, rules: object[] }} [body] */
102
+ const control = async body => {
103
+ const response = await fetch(proxy?.ready.controlUrl ?? '', { method: body === undefined ? 'GET' : 'POST', headers: { authorization: `Bearer ${token}`, 'content-type': 'application/json' }, ...body === undefined ? {} : { body: JSON.stringify(body) } });
104
+ if (!response.ok) throw new Error(`chaos control ${String(response.status)}`);
105
+ return /** @type {{ counters: { upgrades: number, matches: Record<string, number> }, events: object[], activeConnections: number }} */ (await response.json());
106
+ };
107
+ /** @param {string} scenario @param {object[]} rules */
108
+ const arm = (scenario, rules) => control({ scenario, rules });
109
+ const heal = () => control({ scenario: 'healthy', rules: [] });
110
+ /** matches on a route since a snapshot @param {Awaited<ReturnType<typeof control>>} before @param {string} route */
111
+ const matchedSince = async (before, route) => ((await control()).counters.matches[route] ?? 0) - (before.counters.matches[route] ?? 0);
112
+
113
+ launched = await (engine === 'webkit' ? webkit : chromium).launch({ headless: true, args: engine === 'webkit' ? [] : [...KEYCHAIN_ARGS, '--use-angle=metal', '--ignore-gpu-blocklist'] });
114
+ const { defaultBrowserType: _engine, ...phone } = devices['iPhone 16 Pro'];
115
+ const URL_PLAY = `${PAGE_ORIGIN}/?chunk=${SHARD}&mute=1&nolock=1&skipintro=1`;
116
+ /** A fresh device: its own context, Developer on, its errors and visibility changes kept. @param {() => void} [init] */
117
+ const fresh = async init => {
118
+ const context = await /** @type {import('playwright').Browser} */ (launched).newContext(phone), errors = /** @type {string[]} */ ([]);
119
+ await saveFixture(context, { scope: 'device', key: 'devMode', data: true });
120
+ await context.addInitScript(() => { const seen = /** @type {string[]} */ ([]); Object.defineProperty(globalThis, '__fmVisibility', { value: seen }); document.addEventListener('visibilitychange', () => { seen.push(document.visibilityState); }); });
121
+ if (init !== undefined) await context.addInitScript(init);
122
+ const page = await context.newPage();
123
+ page.on('pageerror', error => { errors.push(error.message.slice(0, 240)); });
124
+ page.on('console', line => { if (line.type() === 'error') errors.push(line.text().slice(0, 240)); });
125
+ return { page, context, errors };
126
+ };
127
+ /** Through the Name box (if it asks) into the world, to 30 frames. @param {Entered} entered @param {number} [timeout] */
128
+ const intoWorld = async (entered, timeout = 150_000) => {
129
+ const { page } = entered, until = Date.now() + timeout;
130
+ for (;;) {
131
+ if (await page.locator('#ws-name-box input').isVisible().catch(() => false)) {
132
+ await page.locator('#ws-name-box input').fill(`fm${String(Date.now() % 100_000)}`);
133
+ await page.locator('#ws-name-box button[type=submit]').click();
134
+ }
135
+ if (await page.evaluate(() => typeof window.__workerClient === 'function' && window.__wildshard?.world?.player !== undefined).catch(() => false)) break;
136
+ if (Date.now() > until) {
137
+ const marks = await page.evaluate(() => ({ marks: Object.entries(document.documentElement.dataset).map(([key, value]) => `${key}=${value ?? ''}`).join(' '), sw: navigator.serviceWorker?.controller?.state ?? 'none', url: location.href, seen: [...document.querySelectorAll('[data-failmode]')].map(node => node instanceof HTMLElement ? node.dataset.failmode : '') })).catch(() => null);
138
+ throw new Error(`the page never reached the world (${JSON.stringify({ marks, errors: entered.errors.slice(-4) }).slice(0, 900)})`);
139
+ }
140
+ await sleep(250);
141
+ }
142
+ await page.evaluate(FLOOR_GRID_ENTER);
143
+ await page.waitForFunction(() => (/** @type {NonNullable<typeof window.__workerClient>} */ (window.__workerClient))().frames > 30, undefined, { timeout: Math.max(5000, until - Date.now()) });
144
+ };
145
+ /** The frames the page has heard. @param {import('playwright').Page} page */
146
+ const frames = page => page.evaluate(() => (typeof window.__workerClient === 'function' ? window.__workerClient().frames : -1)).catch(() => -1);
147
+ /** Every visible catalogued screen's ids. @param {import('playwright').Page} page */
148
+ const visibleIds = page => page.evaluate(() => [...document.querySelectorAll('[data-failmode]')].filter(node => node instanceof HTMLElement && !node.hidden && getComputedStyle(node).display !== 'none' && getComputedStyle(node).visibility !== 'hidden' && node.getBoundingClientRect().width > 0).map(node => (node instanceof HTMLElement ? node.dataset.failmode : undefined) ?? '')).catch(() => /** @type {string[]} */ ([]));
149
+ /** Waits for the screen `id`; what shows, how fast, and its primary copy (a Details/Copy diagnostics part is not primary).
150
+ * @param {import('playwright').Page} page @param {string} id @param {number} timeout @param {number} [from] */
151
+ const screen = async (page, id, timeout, from = Date.now()) => {
152
+ const until = Date.now() + timeout;
153
+ while (Date.now() < until) {
154
+ const found = await page.evaluate(wanted => {
155
+ for (const node of document.querySelectorAll('[data-failmode]')) {
156
+ if (!(node instanceof HTMLElement) || !(node.dataset.failmode ?? '').split(/\s+/u).includes(wanted)) continue;
157
+ const style = getComputedStyle(node), box = node.getBoundingClientRect();
158
+ if (node.hidden || style.display === 'none' || style.visibility === 'hidden' || box.width === 0 || box.height === 0) continue;
159
+ const copy = /** @type {HTMLElement} */ (node.cloneNode(true));
160
+ for (const part of copy.querySelectorAll('details, [data-details], .details, button')) part.remove();
161
+ return { ids: node.dataset.failmode ?? '', copy: (copy.textContent ?? '').replaceAll(/\s+/gu, ' ').trim().slice(0, 300) };
162
+ }
163
+ return null;
164
+ }, id).catch(() => null);
165
+ if (found !== null) return { ...found, ms: Date.now() - from, leak: rawLeak(found.copy) };
166
+ await sleep(200);
167
+ }
168
+ return null;
169
+ };
170
+ /** What a player reads now, for a case whose screen never came. @param {import('playwright').Page} page */
171
+ const onScreen = async page => ({ visible: await visibleIds(page), text: (await page.evaluate(() => document.body.textContent).catch(() => '') ?? '').replaceAll(/\s+/gu, ' ').slice(0, 300) });
172
+ /** A shot named for the case. @param {import('playwright').Page} page @param {string} id @param {string} what */
173
+ const shoot = async (page, id, what) => { const file = `${id.replace('/', '-')}-${what}.png`; await page.screenshot({ path: join(shots, file) }).catch(() => undefined); return file; };
174
+ /** Back in play: frames move on and no card or page is up (a notice may be). @param {import('playwright').Page} page @param {number} timeout */
175
+ const recovered = async (page, timeout) => {
176
+ const until = Date.now() + timeout, start = await frames(page);
177
+ while (Date.now() < until) {
178
+ const now = await frames(page), up = await visibleIds(page);
179
+ if (now > start + 10 && up.every(ids => /\b(?:reconnected|slow|lossy|staging)\b/u.test(ids))) return true;
180
+ await sleep(300);
181
+ }
182
+ return false;
183
+ };
184
+ /** The screen's verdict once seen. @param {Seen | null} seen @param {Case} item @param {import('playwright').Page} page @returns {Promise<Result>} */
185
+ const judged = async (seen, item, page) => {
186
+ if (seen === null) return { outcome: 'ui-fail', reason: `no ${item.screen} screen`, seen: null, notes: await onScreen(page) };
187
+ if (seen.leak !== null) return { outcome: 'ui-fail', reason: `primary copy leaks "${seen.leak}"`, seen };
188
+ return { outcome: 'pass', seen };
189
+ };
190
+ /** Clicks a button on the case's screen. @param {import('playwright').Page} page @param {string} id @param {string} label */
191
+ const press = (page, id, label) => page.locator(`[data-failmode~="${id}"] button`, { hasText: label }).first().click({ timeout: 5000 });
192
+
193
+ /** @type {Record<string, (item: Case) => Promise<Result>>} */
194
+ const runners = {
195
+ // a fault on the world's socket, held, then healed
196
+ socketDown: async item => {
197
+ const entered = await fresh(); const { page } = entered;
198
+ try {
199
+ await page.goto(URL_PLAY); await intoWorld(entered);
200
+ const before = await control(), started = Date.now();
201
+ /** @type {Record<string, { first: object, hold: object | null, holdMs: number, wait: number, button?: string, reloads?: boolean }>} */
202
+ const plans = {
203
+ drop: { first: { route: 'socket', kind: 'drop-after', afterMs: 0 }, hold: { route: 'socket', kind: 'refuse-upgrade', code: 503 }, holdMs: 2500, wait: 4000 },
204
+ reset: { first: { route: 'socket', kind: 'drop-after', afterMs: 0 }, hold: { route: 'socket', kind: 'refuse-upgrade', code: 503 }, holdMs: 2500, wait: 4000 },
205
+ reconnected: { first: { route: 'socket', kind: 'drop-after', afterMs: 0 }, hold: { route: 'socket', kind: 'refuse-upgrade', code: 503 }, holdMs: 2000, wait: 15_000 },
206
+ 'half-open': { first: { route: 'socket', kind: 'half-open' }, hold: null, holdMs: 2500, wait: 4000 },
207
+ restart: { first: { route: 'socket', kind: 'close', code: 4005, reason: 'restart' }, hold: null, holdMs: 4000, wait: 4000 },
208
+ resuming: { first: { route: 'socket', kind: 'drop-after', afterMs: 0 }, hold: { route: 'socket', kind: 'refuse-upgrade', code: 503 }, holdMs: 37_000, wait: 40_000 },
209
+ lost: { first: { route: 'socket', kind: 'drop-after', afterMs: 0 }, hold: { route: 'socket', kind: 'refuse-upgrade', code: 503 }, holdMs: 122_000, wait: 126_000, button: 'Try again' },
210
+ full: { first: { route: 'socket', kind: 'close', code: 4002, reason: 'full' }, hold: null, holdMs: 3000, wait: 6000 },
211
+ refused: { first: { route: 'socket', kind: 'close', code: 4001, reason: 'refused' }, hold: null, holdMs: 3000, wait: 6000, button: 'Play again', reloads: true },
212
+ 'version-skew': { first: { route: 'socket', kind: 'close', code: 4000, reason: 'reload' }, hold: null, holdMs: 15_000, wait: 20_000, button: 'Reload', reloads: true },
213
+ };
214
+ const plan = plans[item.id];
215
+ if (plan === undefined) throw new Error(`socketDown has no plan for ${item.id}`);
216
+ await arm(item.id, [plan.first]);
217
+ for (let tries = 0; tries < 40 && await matchedSince(before, 'socket') === 0; tries++) await sleep(100);
218
+ const injected = await matchedSince(before, 'socket');
219
+ if (injected === 0) return { outcome: 'harness-fail', reason: 'the socket fault matched nothing' };
220
+ if (plan.hold !== null) await arm(`${item.id}-held`, [plan.hold]);
221
+ const seenWhileDown = item.id === 'reconnected' ? null : await screen(page, item.screen, plan.wait, started);
222
+ const shot = seenWhileDown === null ? '' : await shoot(page, item.id, 'down');
223
+ await sleep(Math.max(0, plan.holdMs - (Date.now() - started)));
224
+ const injection = { socketMatches: await matchedSince(before, 'socket'), downMs: Date.now() - started };
225
+ await heal();
226
+ if (item.id === 'reconnected') {
227
+ const chip = await screen(page, 'reconnected', plan.wait, Date.now());
228
+ const chipShot = chip === null ? undefined : await shoot(page, item.id, 'chip');
229
+ const gone = chip !== null && await page.locator('[data-failmode~="reconnected"]').waitFor({ state: 'detached', timeout: 6000 }).then(() => true, () => false);
230
+ const verdictRow = await judged(chip, item, page);
231
+ return { ...verdictRow, ...verdictRow.outcome === 'pass' && !gone ? { outcome: 'ui-fail', reason: 'the Reconnected notice never went' } : {}, injection, ...chipShot === undefined ? {} : { shot: chipShot }, recovery: gone ? 'chip gone by itself' : 'chip stayed' };
232
+ }
233
+ const result = await judged(seenWhileDown, item, page);
234
+ if (result.outcome !== 'pass') return { ...result, injection, shot };
235
+ if (plan.button !== undefined) {
236
+ const reloading = plan.reloads === true ? page.waitForEvent('load', { timeout: 30_000 }).catch(() => null) : null;
237
+ await press(page, item.screen, plan.button).catch(() => undefined);
238
+ if (reloading !== null) { await reloading; await intoWorld(entered, 90_000).catch(() => undefined); }
239
+ }
240
+ const back = await recovered(page, item.id === 'full' ? 45_000 : 30_000);
241
+ return back ? { ...result, injection, shot, recovery: 'a real frame, no card' } : { outcome: 'ui-fail', reason: 'no recovery after heal', seen: seenWhileDown, injection, shot, after: await shoot(page, item.id, 'after'), url: page.url(), notes: await onScreen(page) };
242
+ } finally { await heal(); await entered.context.close(); }
243
+ },
244
+ // FM4: Send while the link is down holds one visible line, sent once on the way back
245
+ heldChat: async item => {
246
+ const entered = await fresh(); const { page } = entered;
247
+ try {
248
+ await page.goto(URL_PLAY); await intoWorld(entered);
249
+ const before = await control();
250
+ await arm('reset', [{ route: 'socket', kind: 'drop-after', afterMs: 0 }]);
251
+ for (let tries = 0; tries < 40 && await matchedSince(before, 'socket') === 0; tries++) await sleep(100);
252
+ if (await matchedSince(before, 'socket') === 0) return { outcome: 'harness-fail', reason: 'the socket fault matched nothing' };
253
+ await arm('reset-held', [{ route: 'socket', kind: 'refuse-upgrade', code: 503 }]);
254
+ await screen(page, 'drop', 4000);
255
+ const line = `held ${String(Date.now() % 10_000)}`;
256
+ await page.locator('#ws-chat input').fill(line); await page.locator('#ws-chat input').press('Enter');
257
+ const seen = await screen(page, item.screen, 3000), shot = await shoot(page, item.id, 'held');
258
+ await sleep(1500); await heal();
259
+ const result = await judged(seen, item, page);
260
+ const sent = await page.locator('#ws-chat', { hasText: line }).waitFor({ timeout: 15_000 }).then(() => true, () => false);
261
+ await sleep(2000);
262
+ const copies = await page.evaluate(text => [...document.querySelectorAll('#ws-chat [data-lines] > *')].filter(node => (node.textContent ?? '').includes(text)).length, line);
263
+ if (result.outcome !== 'pass') return { ...result, shot };
264
+ return sent && copies === 1 ? { ...result, shot, recovery: 'the held line sent once' } : { outcome: 'ui-fail', reason: `held line sent ${String(copies)} times`, seen, shot };
265
+ } finally { await heal(); await entered.context.close(); }
266
+ },
267
+ // a second tab of the same device takes the seat; Play here takes it back
268
+ replaced: async item => {
269
+ const entered = await fresh(); const { page, context } = entered;
270
+ try {
271
+ await page.goto(URL_PLAY); await intoWorld(entered);
272
+ const second = await context.newPage(), started = Date.now();
273
+ await second.goto(URL_PLAY);
274
+ const seen = await screen(page, item.screen, 120_000, started), shot = seen === null ? undefined : await shoot(page, item.id, 'card');
275
+ const result = await judged(seen, item, page);
276
+ await second.close();
277
+ if (result.outcome !== 'pass') return { ...result, ...shot === undefined ? {} : { shot } };
278
+ const reloading = page.waitForEvent('load', { timeout: 30_000 }).catch(() => null);
279
+ await press(page, item.screen, 'Play here'); await reloading; await intoWorld(entered, 90_000).catch(() => undefined);
280
+ const back = await recovered(page, 30_000);
281
+ return back ? { ...result, ...shot === undefined ? {} : { shot }, injection: { secondTab: true }, recovery: 'Play here: seated' } : { outcome: 'ui-fail', reason: 'Play here never seated', seen, notes: await onScreen(page) };
282
+ } finally { await entered.context.close(); }
283
+ },
284
+ // --refusal=injection: a fault on a route this page never reads matches nothing, and that is a harness failure, never a pass
285
+ unmatched: async () => {
286
+ const entered = await fresh(); const { page } = entered;
287
+ try {
288
+ await page.goto(URL_PLAY); await intoWorld(entered);
289
+ const before = await control(); await arm('unmatched', [{ route: 'doctor', kind: 'status', code: 503 }]);
290
+ await sleep(5000);
291
+ const matches = await matchedSince(before, 'doctor');
292
+ return matches === 0 ? { outcome: 'harness-fail', reason: 'the doctor fault matched nothing in 5 s', injection: { matches } } : { outcome: 'pass', injection: { matches } };
293
+ } finally { await heal(); await entered.context.close(); }
294
+ },
295
+ // FM8 mode 14: the doctor's page doesn't answer its preflight; the world page stays, with a card
296
+ doctorHttp: async item => {
297
+ const entered = await fresh(); const { page } = entered;
298
+ try {
299
+ await page.goto(URL_PLAY); await intoWorld(entered);
300
+ const before = await control(), here = page.url(), started = Date.now();
301
+ await arm(item.id, [{ route: 'doctor', kind: 'status', code: 503 }]);
302
+ await page.evaluate(() => { document.dispatchEvent(new CustomEvent('ws:doctor', { detail: 'link' })); });
303
+ const seen = await screen(page, item.screen, 15_000, started), shot = await shoot(page, item.id, seen === null ? 'missing' : 'card');
304
+ const injection = { doctorMatches: await matchedSince(before, 'doctor'), stayed: page.url() === here };
305
+ await heal();
306
+ if (injection.doctorMatches === 0) return { outcome: 'harness-fail', reason: 'the doctor fault matched nothing', injection, notes: await onScreen(page) };
307
+ const result = await judged(seen, item, page);
308
+ if (result.outcome !== 'pass') return { ...result, injection, shot };
309
+ if (!injection.stayed) return { outcome: 'ui-fail', reason: 'the page left for a doctor that did not answer', seen, injection, shot };
310
+ await Promise.all([page.waitForURL(/\/doctor\//u, { timeout: 20_000 }), press(page, item.screen, 'Try again')]).catch(() => undefined);
311
+ return /\/doctor\//u.test(page.url()) ? { ...result, injection, shot, recovery: 'healed, Try again: the doctor opened' } : { outcome: 'ui-fail', reason: 'Try again never opened the doctor', seen, injection, shot };
312
+ } finally { await heal(); await entered.context.close(); }
313
+ },
314
+ // FM4b: the browser goes offline in the world
315
+ offlinePlay: async item => {
316
+ const entered = await fresh(); const { page, context } = entered;
317
+ try {
318
+ await page.goto(URL_PLAY); await intoWorld(entered);
319
+ const started = Date.now(); await context.setOffline(true);
320
+ const seen = await screen(page, item.screen, 8000, started), shot = seen === null ? undefined : await shoot(page, item.id, 'card');
321
+ await sleep(2000); await context.setOffline(false);
322
+ const result = await judged(seen, item, page);
323
+ const back = result.outcome === 'pass' && await recovered(page, 30_000);
324
+ return result.outcome !== 'pass' ? { ...result, injection: { setOffline: true } } : back ? { ...result, ...shot === undefined ? {} : { shot }, injection: { setOffline: true }, recovery: 'online: a frame, no card' } : { outcome: 'ui-fail', reason: 'no recovery online', seen, notes: await onScreen(page) };
325
+ } finally { await context.setOffline(false).catch(() => undefined); await entered.context.close(); }
326
+ },
327
+ // J298: a world the device holds loads offline and says so
328
+ offlineLaunch: async item => {
329
+ const entered = await fresh(); const { page, context } = entered;
330
+ try {
331
+ await page.goto(URL_PLAY); await intoWorld(entered);
332
+ // a first visit's worker takes control from the next load (no clients.claim on a world page): a second online visit is the warm one.
333
+ // Visits open the play address: the page drops its query once it starts, so a reload would land on the title
334
+ const controlling = () => page.waitForFunction(() => navigator.serviceWorker?.controller !== null && navigator.serviceWorker?.controller !== undefined, undefined, { timeout: 20_000 }).then(() => true, () => false);
335
+ if (!await controlling()) { await page.waitForFunction(async () => (await navigator.serviceWorker?.getRegistration())?.active !== undefined, undefined, { timeout: 60_000 }).catch(() => undefined); await page.goto(URL_PLAY); await intoWorld(entered); }
336
+ const controlled = await controlling();
337
+ if (!controlled) return { outcome: 'unsupported', reason: `${engine}: no controlling service worker after the warm visit, so nothing can launch offline` };
338
+ await sleep(3000);
339
+ await context.setOffline(true);
340
+ const started = Date.now(); await page.goto(URL_PLAY).catch(() => undefined);
341
+ await intoWorld(entered, 60_000).catch(() => undefined);
342
+ const seen = await screen(page, item.screen, 15_000, started), shot = seen === null ? await shoot(page, item.id, 'missing') : await shoot(page, item.id, 'card');
343
+ await context.setOffline(false);
344
+ const result = await judged(seen, item, page);
345
+ if (result.outcome !== 'pass') return { ...result, shot };
346
+ return await recovered(page, 45_000) ? { ...result, shot, injection: { warmed: true, setOffline: true }, recovery: 'online: a frame, no card' } : { outcome: 'ui-fail', reason: 'no recovery online', seen, shot, notes: await onScreen(page) };
347
+ } finally { await context.setOffline(false).catch(() => undefined); await entered.context.close(); }
348
+ },
349
+ // the page frozen (CDP), with or without a visibility change
350
+ freeze: async item => {
351
+ if (engine !== 'chromium') return { outcome: 'unsupported', reason: 'WebKit has no lifecycle freeze; a native-Safari Ring 2 proof is owed' };
352
+ const entered = await fresh(); const { page, context } = entered;
353
+ try {
354
+ await page.goto(URL_PLAY); await intoWorld(entered);
355
+ const cdp = await context.newCDPSession(page), awayMs = item.id === 'background-short' ? 4000 : 35_000, started = Date.now();
356
+ await cdp.send('Page.setWebLifecycleState', { state: 'frozen' });
357
+ await sleep(awayMs);
358
+ await cdp.send('Page.setWebLifecycleState', { state: 'active' });
359
+ const visibility = await page.evaluate(() => /** @type {string[]} */ (/** @type {any} */ (globalThis).__fmVisibility));
360
+ const seen = await screen(page, item.screen, 8000, Date.now()), shot = await shoot(page, item.id, seen === null ? 'missing' : 'card');
361
+ const injection = { frozenMs: Date.now() - started, visibility };
362
+ if (seen === null && item.id !== 'sleep-wake' && !visibility.includes('hidden'))
363
+ return { outcome: 'unsupported', reason: 'headless Chromium kept the page visible through the freeze; a real hidden/visible return (native-Safari Ring 2) is owed', injection, shot, notes: await onScreen(page) };
364
+ const result = await judged(seen, item, page);
365
+ if (result.outcome !== 'pass') return { ...result, injection, shot };
366
+ return await recovered(page, 30_000) ? { ...result, injection, shot, recovery: 'seated again' } : { outcome: 'ui-fail', reason: 'no recovery after the return', seen, injection, shot, notes: await onScreen(page) };
367
+ } finally { await entered.context.close(); }
368
+ },
369
+ // FM4b: slow and unstable links (measured RTT; the proxy holds frames)
370
+ linkQuality: async item => {
371
+ const entered = await fresh(); const { page } = entered;
372
+ try {
373
+ await page.goto(URL_PLAY); await intoWorld(entered);
374
+ const before = await control(), started = Date.now();
375
+ await arm(item.id, [item.id === 'slow' ? { route: 'socket', kind: 'delay-frames', direction: 'both', ms: 160, jitterMs: 0, seed: 7 } : { route: 'socket', kind: 'delay-frames', direction: 'down', ms: 20, jitterMs: 200, seed: 7 }]);
376
+ const seen = await screen(page, item.screen, 15_000, started), shot = seen === null ? undefined : await shoot(page, item.id, 'chip');
377
+ const injection = { socketMatches: await matchedSince(before, 'socket') };
378
+ await heal();
379
+ if (injection.socketMatches === 0) return { outcome: 'harness-fail', reason: 'the delay matched no frame', injection };
380
+ const result = await judged(seen, item, page);
381
+ if (result.outcome !== 'pass') return { ...result, injection };
382
+ const cleared = await page.locator(`[data-failmode~="${item.screen}"]`).waitFor({ state: 'detached', timeout: 20_000 }).then(() => true, () => false);
383
+ return cleared ? { ...result, injection, ...shot === undefined ? {} : { shot }, recovery: 'cleared after good seconds' } : { outcome: 'ui-fail', reason: 'the chip never cleared', seen, injection };
384
+ } finally { await heal(); await entered.context.close(); }
385
+ },
386
+ // FM5: the release file fails before the page can dial
387
+ releaseFault: async item => {
388
+ const signed = await (await fetch(`http://127.0.0.1:${String(Number(process.env.WS_RIG_PORTS) + 3)}/release.json`)).text();
389
+ const badSignature = JSON.stringify({ ...JSON.parse(signed), signature: '00'.repeat(64) });
390
+ /** @type {Record<string, object>} */
391
+ const rules = {
392
+ 'release-5xx': { route: 'release', kind: 'status', code: 503 },
393
+ 'release-429': { route: 'release', kind: 'status', code: 429, retryAfter: '3' },
394
+ 'release-404': { route: 'release', kind: 'status', code: 404 },
395
+ 'captive-portal': { route: 'release', kind: 'body', text: '<!doctype html><title>Wi-Fi sign in</title><form>Sign in to this network</form>', contentType: 'text/html' },
396
+ 'release-unsigned': { route: 'release', kind: 'body', text: badSignature, contentType: 'application/json' },
397
+ };
398
+ const rule = rules[item.id];
399
+ if (rule === undefined) throw new Error(`releaseFault has no rule for ${item.id}`);
400
+ const entered = await fresh(); const { page } = entered;
401
+ try {
402
+ const before = await control(); await arm(item.id, [rule]);
403
+ const started = Date.now(); await page.goto(URL_PLAY);
404
+ // the Name box comes before the read on a page with no seat yet
405
+ const seen = await (async () => { const until = Date.now() + 30_000; while (Date.now() < until) { if (await page.locator('#ws-name-box input').isVisible().catch(() => false)) { await page.locator('#ws-name-box input').fill('fmboot'); await page.locator('#ws-name-box button[type=submit]').click(); } const found = await screen(page, item.screen, 500, started); if (found !== null) return found; } return null; })();
406
+ const shot = await shoot(page, item.id, seen === null ? 'missing' : 'page');
407
+ const injection = { releaseMatches: await matchedSince(before, 'release'), upgrades: (await control()).counters.upgrades - before.counters.upgrades };
408
+ if (injection.releaseMatches === 0) return { outcome: 'harness-fail', reason: 'the release fault matched nothing', injection, notes: await onScreen(page) };
409
+ if (item.id === 'release-unsigned' && injection.upgrades > 0) return { outcome: 'ui-fail', reason: 'the page dialled on a release it could not verify', seen, injection, shot };
410
+ const result = await judged(seen, item, page);
411
+ await heal();
412
+ if (result.outcome !== 'pass') return { ...result, injection, shot };
413
+ await press(page, item.screen, 'Try').catch(() => undefined);
414
+ await intoWorld(entered, 60_000).catch(() => undefined);
415
+ return await recovered(page, 30_000) ? { ...result, injection, shot, recovery: 'healed: the world loads' } : { outcome: 'ui-fail', reason: 'no recovery after heal', seen, injection, shot, notes: await onScreen(page) };
416
+ } finally { await heal(); await entered.context.close(); }
417
+ },
418
+ // FM6: packs and the spawn book fail on the loading card
419
+ packsFault: async item => {
420
+ /** @type {Record<string, object>} */
421
+ const rules = {
422
+ 'packs-5xx': { route: 'packs', kind: 'status', code: 503 },
423
+ 'packs-429': { route: 'packs', kind: 'status', code: 429, retryAfter: '3' },
424
+ 'book-5xx': { route: 'book', kind: 'status', code: 503 },
425
+ 'download-failed': { route: 'packs', kind: 'status', code: 503 },
426
+ 'pack-broken': { route: 'packs', kind: 'truncate', bytes: 64 },
427
+ };
428
+ const rule = rules[item.id];
429
+ if (rule === undefined) throw new Error(`packsFault has no rule for ${item.id}`);
430
+ const entered = await fresh(); const { page } = entered, route = item.id === 'book-5xx' ? 'book' : 'packs';
431
+ try {
432
+ const before = await control(); await arm(item.id, [rule]);
433
+ const started = Date.now(); await page.goto(URL_PLAY);
434
+ const seen = await (async () => { const until = Date.now() + (item.id === 'download-failed' ? 120_000 : 40_000); while (Date.now() < until) { if (await page.locator('#ws-name-box input').isVisible().catch(() => false)) { await page.locator('#ws-name-box input').fill('fmload'); await page.locator('#ws-name-box button[type=submit]').click(); } const found = await screen(page, item.screen, 500, started); if (found !== null) return found; } return null; })();
435
+ const shot = await shoot(page, item.id, seen === null ? 'missing' : 'line');
436
+ const injection = { matches: await matchedSince(before, route) };
437
+ await heal();
438
+ if (injection.matches === 0) return { outcome: 'harness-fail', reason: `the ${route} fault matched nothing (the proxy learns pack URLs from the manifests it forwards)`, injection, notes: await onScreen(page) };
439
+ const result = await judged(seen, item, page);
440
+ if (result.outcome !== 'pass') return { ...result, injection, shot };
441
+ // the budgeted retries were spent before the line showed: healed, the card's Retry is the player's way on
442
+ const retry = page.locator('.ws-load-retry:visible').first(), pressed = await retry.click({ timeout: 5000 }).then(() => true, () => false);
443
+ await intoWorld(entered, 90_000).catch(() => undefined);
444
+ return await recovered(page, 30_000) ? { ...result, injection, shot, recovery: pressed ? 'heal, Retry: the world loads' : 'heal: the world loads' } : { outcome: 'ui-fail', reason: 'no recovery after heal', seen, injection, shot, notes: await onScreen(page) };
445
+ } finally { await heal(); await entered.context.close(); }
446
+ },
447
+ // FM6: the Cache API refuses with QuotaExceededError (an injection at the public boundary, labelled; never a full disk)
448
+ storageFull: async item => {
449
+ const entered = await fresh(() => { Cache.prototype.put = () => Promise.reject(new DOMException('failmode-proof injected quota refusal', 'QuotaExceededError')); });
450
+ const { page } = entered;
451
+ try {
452
+ const started = Date.now(); await page.goto(URL_PLAY);
453
+ await intoWorld(entered, 90_000).catch(() => undefined);
454
+ const seen = await screen(page, item.screen, 10_000, started), shot = await shoot(page, item.id, seen === null ? 'missing' : 'line');
455
+ const result = await judged(seen, item, page), playing = await recovered(page, 15_000);
456
+ const injection = { cachePut: 'QuotaExceededError (page realm only; the service worker is not injected)' };
457
+ if (result.outcome !== 'pass') return { ...result, injection, shot };
458
+ return playing ? { ...result, injection, shot, recovery: 'plays on from memory' } : { outcome: 'ui-fail', reason: 'the world never played', seen, injection, shot };
459
+ } finally { await entered.context.close(); }
460
+ },
461
+ // FM4b mode 42: the device clock 2 min ahead; the Doctor measures it against the page's host
462
+ clockSkew: async item => {
463
+ const entered = await fresh(() => {
464
+ const Real = Date, skew = () => /** @type {number} */ (/** @type {any} */ (globalThis).__fmSkew ?? 120_000);
465
+ class Skewed extends Real { constructor(/** @type {any[]} */ ...given) { if (given.length === 0) super(Real.now() + skew()); else super(.../** @type {[any]} */ (given)); } static now() { return Real.now() + skew(); } }
466
+ globalThis.Date = /** @type {DateConstructor} */ (/** @type {unknown} */ (Skewed));
467
+ });
468
+ const { page } = entered;
469
+ try {
470
+ await page.goto(URL_PLAY); await intoWorld(entered);
471
+ const started = Date.now();
472
+ await Promise.all([page.waitForURL(/\/doctor\//u, { timeout: 20_000 }), page.evaluate(() => { document.dispatchEvent(new CustomEvent('ws:doctor', { detail: 'link' })); })]);
473
+ const seen = await screen(page, item.screen, 45_000, started), shot = await shoot(page, item.id, seen === null ? 'missing' : 'doctor');
474
+ const result = await judged(seen, item, page), injection = { pageClockAheadMs: 120_000 };
475
+ if (result.outcome !== 'pass') return { ...result, injection, shot };
476
+ await page.evaluate(() => { /** @type {any} */ (globalThis).__fmSkew = 0; });
477
+ await page.locator('button', { hasText: 'Run again' }).first().click();
478
+ const cleared = await page.locator(`[data-failmode~="${item.screen}"]`).waitFor({ state: 'detached', timeout: 45_000 }).then(() => true, () => false);
479
+ return cleared ? { ...result, injection, shot, recovery: 'Run again with the clock right: no warning' } : { outcome: 'ui-fail', reason: 'the warning stayed after Run again with the clock right', seen, injection, shot };
480
+ } finally { await entered.context.close(); }
481
+ },
482
+ // FM5 mode 46: a release signed for staging (loopback fixture only)
483
+ staging: async item => {
484
+ rig.publish(2, rig.build, 'staging');
485
+ const entered = await fresh(); const { page } = entered;
486
+ try {
487
+ await page.goto(URL_PLAY); await intoWorld(entered);
488
+ const seen = await screen(page, item.screen, 10_000), shot = await shoot(page, item.id, seen === null ? 'missing' : 'notice');
489
+ const result = await judged(seen, item, page);
490
+ return { ...result, shot, injection: { channel: 'staging', loopback: true }, ...result.outcome === 'pass' ? { recovery: 'stays for the session' } : {} };
491
+ } finally { rig.publish(3, rig.build, 'production'); await entered.context.close(); }
492
+ },
493
+ };
494
+
495
+ let lastPlay = 0;
496
+ for (const item of cases) {
497
+ const started = Date.now();
498
+ /** @type {Result} */
499
+ let result;
500
+ if (item.blocked !== undefined) result = { outcome: 'blocked-dependency', reason: item.blocked };
501
+ else if (item.chromiumOnly === true && engine !== 'chromium') result = { outcome: 'unsupported', reason: `${engine} cannot produce this lifecycle fault; a native-Safari Ring 2 proof is owed` };
502
+ else {
503
+ const runner = runners[item.run ?? ''];
504
+ if (runner === undefined) throw new Error(`no runner ${String(item.run)} for ${item.id}`);
505
+ // the server's 10 connects a minute per address: play cases wait it out, never lift it
506
+ if (item.phase !== 'boot' || item.id === 'offline-launch') { const wait = lastPlay + cooldownMs - Date.now(); if (wait > 0) { console.log(`.. ${item.id}: waiting ${String(Math.round(wait / 1000))} s for the connect window`); await sleep(wait); } }
507
+ try { result = await runner(item); } catch (error) { result = { outcome: 'harness-fail', reason: String(error).slice(0, 400) }; }
508
+ lastPlay = Date.now();
509
+ }
510
+ const row = { mode: item.mode, id: item.id, owner: item.owner, screen: item.screen, inject: item.inject, ms: Date.now() - started, ...result };
511
+ rows.push(row);
512
+ console.log(`${result.outcome.padEnd(18)} ${item.mode.padEnd(4)} ${item.id}${result.reason === undefined ? '' : `: ${result.reason}`}`);
513
+ if (result.outcome === 'harness-fail' && !baseline) break;
514
+ }
515
+ } catch (error) {
516
+ harnessFault = String(error).slice(0, 600);
517
+ console.log(`harness-fail: ${harnessFault}`);
518
+ } finally {
519
+ const cleanup = /** @type {string[]} */ ([]);
520
+ await launched?.close().catch((/** @type {unknown} */ error) => { cleanup.push(`browser: ${String(error)}`); });
521
+ await proxy?.close().catch((/** @type {unknown} */ error) => { cleanup.push(`proxy: ${String(error)}`); });
522
+ await rig.close().catch((/** @type {unknown} */ error) => { cleanup.push(`rig: ${String(error)}`); });
523
+ if (cleanup.length > 0) harnessFault = `${harnessFault ?? ''} cleanup: ${cleanup.join('; ')}`.trim();
524
+ }
525
+ const code = harnessFault !== null ? 2 : verdict(rows);
526
+ /** @type {Record<string, number>} */
527
+ const counts = {};
528
+ for (const row of rows) counts[row.outcome] = (counts[row.outcome] ?? 0) + 1;
529
+ writeFileSync(join(out, 'receipt.json'), JSON.stringify({ schema: 'failmode-proof/1', sha, engine, browser: engine, baseline, at: new Date().toISOString(), pages: PAGE_ORIGIN, socket: SOCKET,
530
+ saves: pgBin === 'memory:' ? 'memory (no persistence case selected reads them)' : 'owned Postgres', harnessFault, counts, exit: code, cases: rows }, null, 1));
531
+ console.log(`${JSON.stringify(counts)} -> ${join(out, 'receipt.json')}`);
532
+ process.exit(code);
@@ -8,16 +8,17 @@
8
8
  // `test/grid-crossing-ratchet.json` is red. Every run appends one line to ~/.cache/wildshard/lane-receipts.log (`grid-nightly DONE` or
9
9
  // `grid-nightly RED`, naming the red pairs), which the coordinator reads to open a QA-FEEDBACK row. State (the last serial and night) is
10
10
  // <root>/state.json.
11
- // node scripts/grid-crossing-nightly.mjs [--root=<dir>] [--force=release|nightly] [--dry-run]
11
+ // node scripts/grid-crossing-nightly.mjs [--root=<dir>] [--force=release|nightly] [--dry-run] [--ratchet=<file>]
12
+ // --ratchet hands the report another ratchet file (the seeded break that proves a worse pair turns the run red).
12
13
  // --root defaults to ~/.cache/wildshard/plan-artifacts/grid/nightly. --dry-run prints what is due and runs nothing.
13
14
  import { spawnSync } from 'node:child_process';
14
15
  import { appendFileSync, existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
15
16
  import { homedir } from 'node:os';
16
- import { join } from 'node:path';
17
+ import { join, resolve } from 'node:path';
17
18
 
18
19
  /** @param {string} name @param {string} fallback */
19
20
  const flag = (name, fallback) => process.argv.find(arg => arg.startsWith(`--${name}=`))?.slice(name.length + 3) ?? fallback;
20
- const root = flag('root', join(homedir(), '.cache/wildshard/plan-artifacts/grid/nightly')), force = flag('force', ''), dry = process.argv.includes('--dry-run');
21
+ const root = flag('root', join(homedir(), '.cache/wildshard/plan-artifacts/grid/nightly')), force = flag('force', ''), dry = process.argv.includes('--dry-run'), ratchet = flag('ratchet', '') === '' ? '' : resolve(flag('ratchet', ''));
21
22
  const RECEIPTS = join(homedir(), '.cache/wildshard/lane-receipts.log'), STATE = join(root, 'state.json'), here = join(import.meta.dirname, '..');
22
23
  mkdirSync(root, { recursive: true });
23
24
  /** @type {{ serial: number | null, night: string | null }} */
@@ -46,7 +47,7 @@ for (const kind of due) {
46
47
  ? run(['scripts/grid-crossing-qa.mjs', '--base=https://staging.wildshard.io', `--out=${join(dir, 'walks')}`])
47
48
  : run(['scripts/grid-crossing-tour.mjs', '--base=https://preview.wildshard.io', `--out=${join(dir, 'tour')}`, '--lane=grid-nightly']);
48
49
  const runs = kind === 'release' ? join(dir, 'walks/rows.json') : join(dir, 'tour');
49
- const report = spawnSync('node', ['scripts/grid-crossing-report.mjs', join(dir, 'report'), `--runs=${runs}`], { cwd: here, encoding: 'utf8' });
50
+ const report = spawnSync('node', ['scripts/grid-crossing-report.mjs', join(dir, 'report'), `--runs=${runs}`, ...(ratchet === '' ? [] : [`--ratchet=${ratchet}`])], { cwd: here, encoding: 'utf8' });
50
51
  writeFileSync(join(dir, 'report.log'), `${report.stdout}${report.stderr}`);
51
52
  const worse = report.stdout.split('\n').filter(line => line.startsWith('WORSE ')).slice(0, 8).join('; ');
52
53
  const ok = report.status === 0;
@@ -3,7 +3,8 @@
3
3
  // on preview or a loopback page) and the online walks (`grid-crossing-qa.mjs`'s `rows.json` on staging: the pairs a walker can reach by
4
4
  // input), writes report.html (pairs × the goal's measures, worst first, and thumbnails of the failed or walled crossings in shots/) and checks every
5
5
  // crossing against the ratchet `test/grid-crossing-ratchet.json`: a pair worse than its ratchet makes the run exit 1.
6
- // node scripts/grid-crossing-report.mjs <out dir> --runs=<tour dir or rows.json>,… [--tighten]
6
+ // node scripts/grid-crossing-report.mjs <out dir> --runs=<tour dir or rows.json>,… [--tighten] [--ratchet=<file>]
7
+ // --ratchet reads another ratchet file (GC17's seeded break proves a worse pair turns the run red)
7
8
  // --tighten writes the ratchet after the run (new pairs join, numbers only go down); without it the ratchet is read only.
8
9
  import { existsSync, mkdirSync, readdirSync, readFileSync, statSync, writeFileSync } from 'node:fs';
9
10
  import { basename, dirname, join, resolve as absolute } from 'node:path';
@@ -15,7 +16,7 @@ const flag = (name, fallback) => process.argv.find(arg => arg.startsWith(`--${na
15
16
  const out = absolute(process.argv.slice(2).find(arg => !arg.startsWith('--')) ?? '');
16
17
  const sources = flag('runs', '').split(',').filter(Boolean).map(path => absolute(path));
17
18
  if (out === absolute('') || sources.length === 0) throw new Error('usage: grid-crossing-report.mjs <out dir> --runs=<tour dir or rows.json>,… [--tighten]');
18
- const RATCHET = join(import.meta.dirname, '../test/grid-crossing-ratchet.json');
19
+ const RATCHET = absolute(flag('ratchet', join(import.meta.dirname, '../test/grid-crossing-ratchet.json')));
19
20
 
20
21
  /** @typedef {{ site: string, run: string, from: string, to: string, boost: boolean, repeat: boolean, ok: boolean, why: string, borderToControlMs: number | null, freezeMs: number | null, wallMs: number | null, over50: number | null, over33: number | null, build: string, shot: string | null }} Row */
21
22
  /** @type {Row[]} */
@@ -47,6 +48,8 @@ for (const source of sources) {
47
48
  const scored = new Map();
48
49
  for (const row of rows) { const key = pairKey(row.site, row.run, row.from, row.to), had = scored.get(key); if (had === undefined || (had.repeat && !row.repeat)) scored.set(key, row); }
49
50
  const now = Object.fromEntries([...scored].map(([key, row]) => [key, { ok: row.ok, borderToControlMs: row.borderToControlMs, freezeMs: row.freezeMs, wallMs: row.wallMs, over50: row.over50 }]));
51
+ // a named --ratchet that is missing would read as {} and pass everything (GC17's seeded break must not go green by a typo)
52
+ if (!existsSync(RATCHET) && process.argv.some(arg => arg.startsWith('--ratchet='))) throw new Error(`No ratchet file at ${RATCHET}`);
50
53
  const ratchet = existsSync(RATCHET) ? JSON.parse(readFileSync(RATCHET, 'utf8')) : {};
51
54
  const worsened = worse(ratchet, now);
52
55
  if (process.argv.includes('--tighten')) writeFileSync(RATCHET, `${JSON.stringify(tighten(ratchet, now), null, 2)}\n`);