ravensight-playtest 0.10.2 → 0.10.3

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ravensight-playtest",
3
- "version": "0.10.2",
3
+ "version": "0.10.3",
4
4
  "description": "Local AI playtests and seeded game simulations with reports in Ravensight.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://ravensight.io/docs/#playtest",
@@ -1557,9 +1557,14 @@ async function playLoop({
1557
1557
  log(`the tester probes did not finish: ${String(error && error.message)}`);
1558
1558
  }
1559
1559
  }
1560
+ // A page the probes left unable to answer (an input it never took: a click handler that never returns), or a browser that
1561
+ // closed under them, has nothing more to check: the edge checks and the probe on a loading page are skipped, said in the
1562
+ // record, and the run goes on to its report and upload (0.10.1 waited 2 h 52 min on one such click).
1563
+ const probesStopped = honesty.probes && honesty.probes.stopped ? honesty.probes.stopped : null;
1564
+ if (probesStopped) transcript.write({ kind: 'edge_pass_skipped', reason: `the tester probes stopped: ${probesStopped}` });
1560
1565
  // The edge behaviour pass: scripted, no model call, after the last screen
1561
1566
  // has been saved. A canceled run and a game that already ended skip it.
1562
- if (edgePass && !gameEnded && !canceled && !budgetExceeded && typeof driver.edgeSession === 'function' && !(argsSignal && argsSignal.aborted)) {
1567
+ if (edgePass && !probesStopped && !gameEnded && !canceled && !budgetExceeded && typeof driver.edgeSession === 'function' && !(argsSignal && argsSignal.aborted)) {
1563
1568
  try {
1564
1569
  honesty.edge = await runEdgePass({ driver, actionRecords, screenshots, observation: observations.length, signal: argsSignal, log });
1565
1570
  transcript.write({ kind: 'edge_pass', restored: honesty.edge.restored, elapsed_ms: honesty.edge.elapsedMs, checks: honesty.edge.checks.map(check => ({ name: check.name, status: check.status, detail: check.detail })) });
@@ -1577,7 +1582,7 @@ async function playLoop({
1577
1582
  }
1578
1583
  // [tester hook] Input while the page loads: a reload, so it comes after the edge checks have asked their own reload what survived.
1579
1584
  if (probing && honesty.probes) {
1580
- try {
1585
+ if (!probesStopped) try {
1581
1586
  const loaded = await runTesterProbes({ driver, actionRecords, screenshots, observation: observations.length, signal: argsSignal, log, loading: true });
1582
1587
  honesty.probes.checks.push(...loaded.checks);
1583
1588
  honesty.probes.suspects.push(...loaded.suspects);
@@ -32,6 +32,11 @@ export const PROBES_HEADING = '## Tester probes (run by the runner after play, n
32
32
  export const PROBE_TIMING = Object.freeze({ settleMs: 300, rapidClicks: 15, rapidGapMs: 12, holdMs: 700, edgeHoldMs: 400, edgeMaxMs: 4000, longText: 5000, maxSweep: 6, retries: 2, loadInputMs: 1200, budgetMs: 60000 });
33
33
 
34
34
  /** The probes, in the order they run, with the words the report uses. */
35
+ // One input to the page waits this long at most. A page whose main thread is stuck (a click handler that never
36
+ // returns) never answers one, and the paid 0.10.1 run pt_job_e8c2ea4d636362e50109 waited on such a click for 2 h 52 min.
37
+ export const INPUT_MS = 5000;
38
+ // Past its own budget the pass waits this long for a probe still in flight, then ends with what it has.
39
+ export const PASS_GRACE_MS = 10000;
35
40
  export const PROBES = Object.freeze([
36
41
  ['overflow', 'text that overflows or is cut off'],
37
42
  ['rapid', 'rapid repeated input on one control'],
@@ -177,36 +182,52 @@ export async function runTesterProbes({ driver, actionRecords = [], screenshots
177
182
  const started = Date.now();
178
183
  const left = () => timing.budgetMs - (Date.now() - started);
179
184
  const checks = [];
180
- const stopped = () => Boolean(signal && signal.aborted) || Boolean(session.gameEnded && session.gameEnded());
181
- const evaluate = (fn, arg) => { let timer; return Promise.race([Promise.resolve().then(() => page.evaluate(fn, arg)), new Promise((resolve, reject) => { timer = setTimeout(() => reject(new Error('the page did not answer')), 8000); })]).finally(() => clearTimeout(timer)); };
182
- const controls = () => evaluate(pageControls).catch(() => ({ buttons: [], fields: [], text: '', canvas: null }));
183
- const print = async () => { try { return pngFingerprint(await page.screenshot({ type: 'png', timeout: 10000 })); } catch { return null; } };
185
+ // Why the page or its browser can take no more input: then every probe after it is not checked, and the pass ends.
186
+ let hung = null;
187
+ const browserGone = () => { try { const browser = page.context().browser(); return page.isClosed() || Boolean(browser && !browser.isConnected()); } catch { return true; } };
188
+ const stopped = () => Boolean(signal && signal.aborted) || Boolean(session.gameEnded && session.gameEnded()) || Boolean(hung) || browserGone();
189
+ const stopWhy = () => (hung || (browserGone() ? 'the browser closed' : 'the page had ended'));
190
+ /** One input to the page, bounded: true when it was taken, false when it failed; one the page never answers stops the pass. */
191
+ const input = async (work, ms = INPUT_MS) => {
192
+ if (hung || browserGone()) return false;
193
+ let timer;
194
+ const took = await Promise.race([Promise.resolve().then(work).then(() => true, () => false), new Promise(resolve => { timer = setTimeout(() => resolve(null), ms); })]).finally(() => clearTimeout(timer));
195
+ if (took === null) hung = hung || 'the page stopped answering input';
196
+ return took === true;
197
+ };
198
+ const mouse = { click: (x, y, options) => input(() => page.mouse.click(x, y, options)), move: (x, y) => input(() => page.mouse.move(x, y)) };
199
+ const keys = { down: key => input(() => page.keyboard.down(key)), up: key => input(() => page.keyboard.up(key)), press: key => input(() => page.keyboard.press(key)) };
200
+ const evaluate = (fn, arg) => { if (hung) return Promise.reject(new Error(hung)); let timer; return Promise.race([Promise.resolve().then(() => page.evaluate(fn, arg)), new Promise((resolve, reject) => { timer = setTimeout(() => reject(new Error('the page did not answer')), 8000); })]).finally(() => clearTimeout(timer)); };
201
+ // A page that stopped answering is not asked again: each ask would wait out its own timeout.
202
+ const controls = () => (hung ? Promise.resolve({ buttons: [], fields: [], text: '', canvas: null }) : evaluate(pageControls).catch(() => ({ buttons: [], fields: [], text: '', canvas: null })));
203
+ const print = async () => { if (hung) return null; try { return pngFingerprint(await page.screenshot({ type: 'png', timeout: 10000 })); } catch { return null; } };
184
204
  const look = async () => { const c = await controls(); return { ...c, print: await print(), sig: `${c.text}\n${c.buttons.map(b => `${b.name}|${b.disabled ? 1 : 0}`).join('\n')}` }; };
185
205
  const differs = (a, b) => a.sig !== b.sig || (a.print && b.print ? significant(screenDelta(a.print, b.print)) : false);
186
206
  const errors = () => (session.drainErrors ? session.drainErrors() : []).filter(entry => entry && (entry.type === 'pageerror' || (entry.type === 'console' && !/favicon|Failed to load resource/i.test(String(entry.text))))).map(entry => ({ thrown: entry.type === 'pageerror', text: String(entry.text || '').slice(0, 200) }));
187
207
  const alive = async () => { let timer; try { return await Promise.race([Promise.resolve().then(() => page.evaluate(() => 1)).then(() => true, () => true), new Promise(resolve => { timer = setTimeout(() => resolve(false), 5000); })]); } finally { clearTimeout(timer); } };
188
208
  const shot = async (name, reason) => {
189
- if (!save) return null;
209
+ if (!save || hung) return null;
190
210
  try {
191
- const saved = await driver.screenshot(name);
211
+ let timer;
212
+ const saved = await Promise.race([Promise.resolve().then(() => driver.screenshot(name)), new Promise(resolve => { timer = setTimeout(() => resolve(null), 10000); })]).finally(() => clearTimeout(timer));
192
213
  if (saved && saved.relativePath) { screenshots.push({ ...saved, edge: true, reason: `tester probe: ${reason} (saved by the runner)`, ...(Number.isInteger(observation) ? { observation } : {}), at: Date.now(), order: Number.MAX_SAFE_INTEGER - 200 + screenshots.length }); return saved.relativePath; }
193
214
  } catch { /* no picture is still a check */ }
194
215
  return null;
195
216
  };
196
- const park = async () => { await page.mouse.move(1, 1).catch(() => {}); await evaluate(pageRings, true).catch(() => {}); };
217
+ const park = async () => { await mouse.move(1, 1).catch(() => {}); await evaluate(pageRings, true).catch(() => {}); };
197
218
  /** Click a button by its name as it is on the page now. `{ ok, changed }`. */
198
219
  const click = async name => {
199
220
  await park();
200
221
  const before = await look();
201
222
  const button = before.buttons.find(b => b.name === name);
202
223
  if (!button) return { ok: false, changed: false, before };
203
- await page.mouse.click(button.x, button.y).catch(() => {});
204
- await page.mouse.move(1, 1).catch(() => {});
224
+ await mouse.click(button.x, button.y).catch(() => {});
225
+ await mouse.move(1, 1).catch(() => {});
205
226
  await sleep(timing.settleMs);
206
227
  const after = await look();
207
228
  return { ok: true, disabled: button.disabled, changed: differs(before, after), before, after };
208
229
  };
209
- const press = async (key, ms = 120) => { await park(); const before = await look(); await page.keyboard.down(key).catch(() => {}); await sleep(ms); await page.keyboard.up(key).catch(() => {}); await sleep(timing.settleMs); const after = await look(); return { changed: differs(before, after), before, after }; };
230
+ const press = async (key, ms = 120) => { await park(); const before = await look(); await keys.down(key).catch(() => {}); await sleep(ms); await keys.up(key).catch(() => {}); await sleep(timing.settleMs); const after = await look(); return { changed: differs(before, after), before, after }; };
210
231
  const pressable = list => list.filter(b => !b.disabled && !RISKY.test(b.name));
211
232
  const answered = new Set();
212
233
  const names = l => l.buttons.map(b => b.name).join('|');
@@ -237,7 +258,7 @@ export async function runTesterProbes({ driver, actionRecords = [], screenshots
237
258
  const judge = async (what, { before = null, softLock = true } = {}) => {
238
259
  const hits = [];
239
260
  if (session.gameEnded && session.gameEnded()) { hits.push({ oracle: 'crash', severity: 'blocker', category: 'bug', title: `The page ended after ${what}`, description: `The page running the game ended after ${what}. It had run through play.` }); return hits; }
240
- if (!(await alive())) { hits.push({ oracle: 'frozen', severity: 'major', category: 'bug', title: `The page stopped answering after ${what}`, description: `After ${what} the page did not answer for five seconds: its main thread is busy or stuck.` }); return hits; }
261
+ if (hung || !(await alive())) { hits.push({ oracle: 'frozen', severity: 'major', category: 'bug', title: `The page stopped answering after ${what}`, description: `After ${what} the page did not answer for five seconds: its main thread is busy or stuck.` }); return hits; }
241
262
  for (const e of errors()) hits.push({ oracle: 'error', key: e.text.replace(/\d+/g, '#'), ...(e.thrown ? { thrown: true } : {}), severity: e.thrown ? 'major' : 'minor', category: 'bug', title: e.thrown ? `A script error was raised when ${what}` : `The game logged an error when ${what}`, description: `${e.thrown ? 'The game threw an error that nothing caught' : 'The game wrote an error to the console'} when ${what}: ${q(e.text)}.` });
242
263
  const now = await look();
243
264
  const share = flatShare(now.print);
@@ -263,7 +284,7 @@ export async function runTesterProbes({ driver, actionRecords = [], screenshots
263
284
  if ((id === 'loading') !== Boolean(loading)) return;
264
285
  const title = PROBES.find(p => p[0] === id)[1];
265
286
  const add = check => { checks.push({ name: id, title, ...check }); log(`tester probe, ${title}: ${check.status}${check.detail ? ` (${check.detail})` : ''}`); };
266
- if (stopped()) return add({ status: 'not_checked', detail: 'the page had ended' });
287
+ if (stopped()) return add({ status: 'not_checked', detail: stopWhy() });
267
288
  const stuck = suspects.find(s => ['soft_lock', 'frozen', 'crash', 'blank'].includes(s.oracle));
268
289
  if (stuck) return add({ status: 'not_checked', detail: `the game had stopped answering after ${stuck.what}` });
269
290
  if (left() < 5000) return add({ status: 'not_checked', detail: 'no time was left for it' });
@@ -278,246 +299,260 @@ export async function runTesterProbes({ driver, actionRecords = [], screenshots
278
299
  }
279
300
  };
280
301
 
281
- await session.releaseClock();
282
- if (session.dismissDialogs) session.dismissDialogs(true);
283
- // The element play left focused gets the focus back afterwards: the edge
284
- // checks that follow press the session's keys where play left them, not on
285
- // the last button a probe clicked.
286
- const focusMark = loading ? false : await evaluate(() => { const el = document.activeElement; if (!el || el === document.body) return false; el.setAttribute('data-ravensight-play-focus', '1'); return true; }).catch(() => false);
287
- try {
288
- errors();
289
- await evaluate(pageRings, true).catch(() => {});
290
- const start = await look();
291
- const keyboard = Boolean(start.canvas) || actionRecords.some(r => r && r.kind === 'action' && r.tool === 'key' && r.ok);
292
- if (!only || !loading) for (const name of workedButtons(actionRecords)) { const a = await click(name); const b = a.ok && a.changed ? await click(name) : null; if (b && b.ok && b.changed) canaries.push(name); }
293
-
294
- await run('overflow', async () => {
295
- const r = await evaluate(pageOverflow, 6).catch(() => null);
296
- if (!r) return { skip: 'the page could not be measured' };
297
- if (!r.texts) return { skip: r.canvas ? 'the game draws its text on a canvas, which the runner cannot measure' : 'the page shows no text to measure' };
298
- const what = 'the page was measured';
299
- const hits = r.found.length ? [{ oracle: 'overflow', key: r.found[0].text, severity: 'minor', category: 'ux', title: `Text is cut off: ${q(r.found[0].text)}`, description: `${r.found.slice(0, 4).map(f => `${q(f.text)} is ${f.px} pixels ${f.how}`).join('; ')}.` }] : [];
300
- return { hits, what, again: async () => { const n = await evaluate(pageOverflow, 6).catch(() => null); return Boolean(n && n.found.some(f => f.text === r.found[0].text)); } };
301
- });
302
-
303
- await run('rapid', async () => {
304
- const now = await look();
305
- const name = canaries[0] || (pressable(now.buttons)[0] || {}).name;
306
- if (!name) return { skip: 'no button was known to do anything on this screen' };
307
- const what = `${q(name)} was clicked ${timing.rapidClicks} times as fast as possible`;
308
- const once = async () => {
309
- const before = await look();
310
- const button = before.buttons.find(b => b.name === name);
311
- if (!button) return [];
312
- errors();
313
- for (let i = 0; i < timing.rapidClicks; i += 1) { await page.mouse.click(button.x, button.y).catch(() => {}); await sleep(timing.rapidGapMs); }
314
- await sleep(timing.settleMs);
315
- return judge(what, { before });
316
- };
317
- const hits = await once();
318
- if (names(await look()) !== names(now)) { answered.add(name); await comeBack(now); }
319
- return { hits, what, again: async hit => {
320
- // A control the game has since disabled or taken away cannot be pressed again: that try was never made.
321
- const button = (await look()).buttons.find(b => b.name === name);
322
- if (!button || button.disabled) return { untried: `${q(name)} was ${button ? 'disabled' : 'gone'} by then, so it could only be tried again from a fresh start` };
323
- return (await once()).some(h => h.oracle === hit.oracle && h.key === hit.key);
324
- } };
325
- });
326
-
327
- await run('untried', async () => {
328
- const now = await look();
329
- const played = namedInPlay(actionRecords);
330
- const list = pressable(now.buttons).filter(b => !played.has(b.name.toLowerCase()) && ![...played].some(p => p.includes(`"${b.name.toLowerCase()}"`))).slice(0, timing.maxSweep);
331
- if (pressable(now.buttons).length === 0) return { skip: 'the page play ended on lists no buttons' };
332
- if (list.length === 0) return { detail: 'play had already named every button on this page' };
333
- const beside = b => now.fields.some(f => Math.abs(f.y - b.y) <= 40);
334
- const hits = [];
335
- let dead = null;
336
- for (const b of list) {
337
- if (left() < 5000 || stopped()) break;
338
- errors();
339
- const first = await click(b.name);
340
- if (!first.ok) continue;
341
- if (first.changed) answered.add(b.name);
342
- if (!first.changed && !UNSEEN_EFFECT.test(b.name) && !answered.has(b.name) && !beside(b)) {
343
- await press('Escape');
344
- const second = await click(b.name);
345
- if (second.ok && second.changed) await comeBack(now);
346
- if (second.ok && !second.changed && !dead) { dead = b.name; hits.push({ oracle: 'dead_control', key: b.name, severity: 'minor', category: 'ux', title: `${q(b.name)} does nothing when clicked`, description: `The button ${q(b.name)} was clicked twice, with Escape pressed in between in case something was open over it. The page was answering, and its picture, its text and its buttons were the same before and after. Play had never named it.` }); }
347
- }
348
- hits.push(...await judge(`${q(b.name)} was clicked`, { before: first.before, softLock: false }));
349
- if (first.changed && !(await comeBack(now))) break;
350
- }
351
- return { hits, what: dead ? `${q(dead)} was clicked` : 'the buttons play never named were clicked', again: async hit => { if (hit.oracle !== 'dead_control') return false; const r = await click(hit.key); return r.ok && !r.changed; }, detail: `${list.length} pressed` };
352
- });
353
-
354
- await run('text', async () => {
355
- const now = await look();
356
- if (now.fields.length === 0) return { skip: now.canvas ? 'no text field is on the page (one drawn on a canvas cannot be filled by this probe)' : 'the page play ended on has no text field' };
357
- const field = now.fields[0];
358
- const hits = [];
359
- const tryText = async (label, text) => {
360
- const at = (await look()).fields.find(f => f.name === field.name);
361
- if (!at) return [];
362
- errors();
363
- const before = await look();
364
- const filled = await evaluate(pageFill, [at.x, at.y, text]).catch(() => null);
365
- if (!filled) return [];
366
- await page.keyboard.press('Enter').catch(() => {});
367
- await sleep(timing.settleMs);
368
- const what = `${label} was entered in ${q(field.name)} and Enter was pressed`;
369
- const found = await judge(what, { before, softLock: false });
370
- if (text === ODD_TEXT && await evaluate(pageMarkup, MARKUP_ID).catch(() => false)) found.push({ oracle: 'markup', severity: 'major', category: 'bug', title: 'Text the player types is inserted into the page as markup', description: `Text typed into ${q(field.name)} that contained a markup tag was put into the page as markup, not shown as the characters typed. A player's name or message can change the page it is shown on.` });
371
- if (text.length >= 1000) { const over = await evaluate(pageOverflow, 3).catch(() => null); const long = over ? over.found.find(o => /A{20}/.test(o.text)) : null; if (long) found.push({ oracle: 'overflow_input', severity: 'minor', category: 'ux', title: 'Very long typed text runs out of its box', description: `After ${label} was entered in ${q(field.name)}, the game showed it ${long.px} pixels ${long.how}. The field takes ${filled.max ? `up to ${filled.max}` : 'any number of'} characters.` }); }
372
- return found.map(h => ({ ...h, text, label }));
373
- };
374
- for (const [label, text] of [['nothing', ''], [`${timing.longText} characters`, 'A'.repeat(timing.longText)], ['unusual text (markup, quotes, other scripts, an emoji)', ODD_TEXT]]) hits.push(...await tryText(label, text));
375
- const back = (await look()).fields.find(f => f.name === field.name);
376
- if (back) await evaluate(pageFill, [back.x, back.y, '']).catch(() => {});
302
+ // The pass keeps to its time whatever a probe waits on: past its budget and a grace it ends with what it has.
303
+ let deadlineTimer, failure = null;
304
+ const work = (async () => {
305
+ await session.releaseClock();
306
+ if (session.dismissDialogs) session.dismissDialogs(true);
307
+ // The element play left focused gets the focus back afterwards: the edge
308
+ // checks that follow press the session's keys where play left them, not on
309
+ // the last button a probe clicked.
310
+ const focusMark = loading ? false : await evaluate(() => { const el = document.activeElement; if (!el || el === document.body) return false; el.setAttribute('data-ravensight-play-focus', '1'); return true; }).catch(() => false);
311
+ try {
312
+ errors();
377
313
  await evaluate(pageRings, true).catch(() => {});
378
- return { hits, what: `text was entered in ${q(field.name)}`, again: async hit => (await tryText(hit.label, hit.text)).some(h => h.oracle === hit.oracle && h.key === hit.key) };
379
- });
380
-
381
- await run('menu', async () => {
382
- const now = await look();
383
- const opener = pressable(now.buttons).find(b => MENU.test(b.name));
384
- if (!opener) return { skip: 'no menu, shop, settings or help button was found on the page play ended on' };
385
- const numbers = text => new Map(readings(text).map(r => [r.label, r.value]));
386
- const what = `${q(opener.name)} was opened and closed twice, the second time at once`;
387
- let opened = true;
388
- const once = async () => {
389
- // Something is done first: a menu that undoes what was just done shows only when there is something to undo.
390
- for (const name of canaries) await click(name);
391
- errors();
392
- const before = await look();
393
- const n0 = numbers(before.text);
394
- const first = await click(opener.name);
395
- if (!first.ok || !first.changed) { opened = false; return []; }
396
- await comeBack(before);
397
- const again = (await look()).buttons.find(b => b.name === opener.name);
398
- if (again) { await page.mouse.click(again.x, again.y).catch(() => {}); await page.keyboard.press('Escape').catch(() => {}); await sleep(timing.settleMs); }
399
- await comeBack(before);
400
- const n1 = numbers((await look()).text);
401
- const found = await judge(what, { before });
402
- for (const [label, was] of n0) { if (!n1.has(label) || n1.get(label) === was || CLOCK.test(label)) continue; found.push({ oracle: 'menu_state', key: label, severity: 'major', category: 'bug', title: `Opening and closing ${q(opener.name)} changes "${label}"`, description: `"${label}" was ${was} before ${q(opener.name)} was opened and ${n1.get(label)} after it was closed again. Nothing was done in between but opening and leaving it.` }); break; }
403
- return found;
404
- };
405
- const hits = await once();
406
- if (!opened) return { skip: `clicking ${q(opener.name)} did not open anything` };
407
- return { hits, what, again: async hit => (await once()).some(h => h.oracle === hit.oracle && h.key === hit.key) };
408
- });
409
-
410
- await run('pause', async () => {
411
- const now = await look();
412
- const control = now.buttons.find(b => !b.disabled && PAUSE.test(b.name));
413
- if (!control) return { skip: 'no pause button was found on the page play ended on' };
414
- const what = `the game was paused with ${q(control.name)} and resumed`;
415
- const frames = () => evaluate(() => new Promise(resolve => { let n = 0; const tick = () => { n += 1; requestAnimationFrame(tick); }; requestAnimationFrame(tick); setTimeout(() => resolve(n), 400); })).catch(() => null);
416
- const moving = async () => { const a = await print(); await sleep(400); const b = await print(); return Boolean(a && b && significant(screenDelta(a, b))); };
417
- const once = async () => {
418
- errors();
419
- const before = await look();
420
- const movedBefore = await moving();
421
- const paused = await click(control.name);
422
- if (!paused.ok) return [];
423
- const resume = pressable((await look()).buttons).find(b => RESUME.test(b.name) || PAUSE.test(b.name));
424
- if (resume) await click(resume.name);
425
- const found = await judge(what, { before });
426
- // The page still draws frames; a game that moved before the pause and stands still after the resume did not come back.
427
- if (movedBefore && found.length === 0 && (await frames()) !== null && !(await moving())) found.push({ oracle: 'pause_stuck', severity: 'major', category: 'bug', title: `The game does not come back after a pause with ${q(control.name)}`, description: `Before the pause the screen moved on its own. After pausing with ${q(control.name)} and resuming, it stood still: the game stayed paused, or its loop did not start again.` });
428
- return found;
429
- };
430
- return { hits: await once(), what, again: async hit => (await once()).some(h => h.oracle === hit.oracle && h.key === hit.key) };
431
- });
432
-
433
- await run('opposite', async () => {
434
- if (!keyboard) return { skip: 'the game has no canvas and play pressed no key, so it does not seem to be played by keys' };
435
- const what = `opposite keys were held together (${OPPOSITES.map(p => p.join(' with ')).join(', ')})`;
436
- const once = async () => {
437
- errors();
438
- const before = await look();
439
- for (const [a, b] of OPPOSITES) { await page.keyboard.down(a).catch(() => {}); await page.keyboard.down(b).catch(() => {}); await sleep(timing.holdMs); await page.keyboard.up(a).catch(() => {}); await page.keyboard.up(b).catch(() => {}); await sleep(100); }
440
- await sleep(timing.settleMs);
441
- return judge(what, { before });
442
- };
443
- return { hits: await once(), what, again: async hit => (await once()).some(h => h.oracle === hit.oracle && h.key === hit.key) };
444
- });
445
-
446
- await run('edges', async () => {
447
- if (!keyboard) return { skip: 'the game has no canvas and play pressed no key, so there is no player to push to an edge' };
448
- const what = 'the player was pushed to the edges of the play area';
449
- const once = async () => {
450
- errors();
451
- const before = await look();
452
- for (const key of ['ArrowLeft', 'ArrowUp', 'ArrowRight', 'ArrowDown']) {
453
- if (left() < 4000 || stopped()) break;
454
- const from = Date.now();
455
- await page.keyboard.down(key).catch(() => {});
456
- let last = await print();
457
- while (Date.now() - from < timing.edgeMaxMs) { await sleep(timing.edgeHoldMs); const now = await print(); const moved = last && now && significant(screenDelta(last, now)); last = now; if (!moved) break; }
458
- await page.keyboard.up(key).catch(() => {});
459
- await sleep(80);
314
+ const start = await look();
315
+ const keyboard = Boolean(start.canvas) || actionRecords.some(r => r && r.kind === 'action' && r.tool === 'key' && r.ok);
316
+ if (!only || !loading) for (const name of workedButtons(actionRecords)) { const a = await click(name); const b = a.ok && a.changed ? await click(name) : null; if (b && b.ok && b.changed) canaries.push(name); }
317
+
318
+ await run('overflow', async () => {
319
+ const r = await evaluate(pageOverflow, 6).catch(() => null);
320
+ if (!r) return { skip: 'the page could not be measured' };
321
+ if (!r.texts) return { skip: r.canvas ? 'the game draws its text on a canvas, which the runner cannot measure' : 'the page shows no text to measure' };
322
+ const what = 'the page was measured';
323
+ const hits = r.found.length ? [{ oracle: 'overflow', key: r.found[0].text, severity: 'minor', category: 'ux', title: `Text is cut off: ${q(r.found[0].text)}`, description: `${r.found.slice(0, 4).map(f => `${q(f.text)} is ${f.px} pixels ${f.how}`).join('; ')}.` }] : [];
324
+ return { hits, what, again: async () => { const n = await evaluate(pageOverflow, 6).catch(() => null); return Boolean(n && n.found.some(f => f.text === r.found[0].text)); } };
325
+ });
326
+
327
+ await run('rapid', async () => {
328
+ const now = await look();
329
+ const name = canaries[0] || (pressable(now.buttons)[0] || {}).name;
330
+ if (!name) return { skip: 'no button was known to do anything on this screen' };
331
+ const what = `${q(name)} was clicked ${timing.rapidClicks} times as fast as possible`;
332
+ const once = async () => {
333
+ const before = await look();
334
+ const button = before.buttons.find(b => b.name === name);
335
+ if (!button) return [];
336
+ errors();
337
+ for (let i = 0; i < timing.rapidClicks; i += 1) { await mouse.click(button.x, button.y).catch(() => {}); await sleep(timing.rapidGapMs); }
338
+ await sleep(timing.settleMs);
339
+ return judge(what, { before });
340
+ };
341
+ const hits = await once();
342
+ if (names(await look()) !== names(now)) { answered.add(name); await comeBack(now); }
343
+ return { hits, what, again: async hit => {
344
+ // A control the game has since disabled or taken away cannot be pressed again: that try was never made.
345
+ const button = (await look()).buttons.find(b => b.name === name);
346
+ if (!button || button.disabled) return { untried: `${q(name)} was ${button ? 'disabled' : 'gone'} by then, so it could only be tried again from a fresh start` };
347
+ return (await once()).some(h => h.oracle === hit.oracle && h.key === hit.key);
348
+ } };
349
+ });
350
+
351
+ await run('untried', async () => {
352
+ const now = await look();
353
+ const played = namedInPlay(actionRecords);
354
+ const list = pressable(now.buttons).filter(b => !played.has(b.name.toLowerCase()) && ![...played].some(p => p.includes(`"${b.name.toLowerCase()}"`))).slice(0, timing.maxSweep);
355
+ if (pressable(now.buttons).length === 0) return { skip: 'the page play ended on lists no buttons' };
356
+ if (list.length === 0) return { detail: 'play had already named every button on this page' };
357
+ const beside = b => now.fields.some(f => Math.abs(f.y - b.y) <= 40);
358
+ const hits = [];
359
+ let dead = null;
360
+ for (const b of list) {
361
+ if (left() < 5000 || stopped()) break;
362
+ errors();
363
+ const first = await click(b.name);
364
+ if (!first.ok) continue;
365
+ if (first.changed) answered.add(b.name);
366
+ if (!first.changed && !UNSEEN_EFFECT.test(b.name) && !answered.has(b.name) && !beside(b)) {
367
+ await press('Escape');
368
+ const second = await click(b.name);
369
+ if (second.ok && second.changed) await comeBack(now);
370
+ if (second.ok && !second.changed && !dead) { dead = b.name; hits.push({ oracle: 'dead_control', key: b.name, severity: 'minor', category: 'ux', title: `${q(b.name)} does nothing when clicked`, description: `The button ${q(b.name)} was clicked twice, with Escape pressed in between in case something was open over it. The page was answering, and its picture, its text and its buttons were the same before and after. Play had never named it.` }); }
371
+ }
372
+ hits.push(...await judge(`${q(b.name)} was clicked`, { before: first.before, softLock: false }));
373
+ if (first.changed && !(await comeBack(now))) break;
460
374
  }
461
- await sleep(timing.settleMs);
462
- return judge(what, { before });
463
- };
464
- return { hits: await once(), what, again: async hit => (await once()).some(h => h.oracle === hit.oracle && h.key === hit.key) };
465
- });
466
-
467
- await run('order', async () => {
468
- const now = await look();
469
- const list = pressable(now.buttons).filter(b => !UNSEEN_EFFECT.test(b.name)).slice(0, timing.maxSweep).reverse();
470
- if (list.length < 2) return { skip: 'the page lists fewer than two buttons to press out of order' };
471
- const what = 'the buttons were pressed in reverse order with no pause';
472
- const once = async () => {
473
- errors();
474
- const before = await look();
475
- for (const b of list) { const at = (await controls()).buttons.find(x => x.name === b.name && !x.disabled); if (at) { await page.mouse.click(at.x, at.y).catch(() => {}); await sleep(60); } }
476
- await sleep(timing.settleMs);
477
- return judge(what, { before });
478
- };
479
- return { hits: await once(), what, again: async hit => (await once()).some(h => h.oracle === hit.oracle && h.key === hit.key) };
480
- });
481
-
482
- await run('loading', async () => {
483
- const what = 'clicks and keys were sent while the page was still loading';
484
- const size = page.viewportSize() || { width: 1280, height: 720 };
485
- const once = async () => {
486
- errors();
487
- const going = page.reload({ waitUntil: 'load', timeout: 15000 }).then(() => true, () => false);
488
- const until = Date.now() + timing.loadInputMs;
489
- while (Date.now() < until) { await page.mouse.click(Math.round(size.width / 2), Math.round(size.height / 2)).catch(() => {}); await page.keyboard.press('Enter').catch(() => {}); await page.keyboard.press(' ').catch(() => {}); await sleep(40); }
490
- const loaded = await going;
491
- await sleep(timing.settleMs + 400);
492
- if (!loaded) return [{ oracle: 'no_load', severity: 'major', category: 'bug', title: 'The game does not load when input arrives while it is loading', description: 'With clicks and keys sent while the page was loading, it did not finish loading. It had loaded when left alone.' }];
493
- return judge(what, { softLock: false });
494
- };
495
- return { hits: await once(), what, again: async hit => (await once()).some(h => h.oracle === hit.oracle && h.key === hit.key) };
496
- });
497
-
498
- // Try each suspect again where it stands; a game left stuck waits for the replay.
499
- for (const s of suspects) {
500
- s.tries = 0; s.hits = 0; s.why = null; s.uncounted = false;
501
- if (['soft_lock', 'frozen', 'crash', 'blank', 'pause_stuck', 'no_load'].includes(s.oracle) && s.probe !== 'loading') { s.why = 'the game was left stuck, so it can only be tried again from a fresh start'; continue; }
502
- for (let i = 0; i < retries && left() > 3000 && !stopped() && typeof s.again === 'function'; i += 1) {
503
- const r = await Promise.resolve().then(() => s.again(s)).catch(() => false);
504
- // A try the game could not take is not a try: it is never counted as "not reproduced" (the replay tries it from a fresh start).
505
- if (r && typeof r === 'object' && r.untried) { if (!s.tries) s.why = r.untried; break; }
506
- // An error nothing caught can leave the game unable to raise it again where it stands (a game loop it
507
- // stopped): a second try that sees nothing is not counted, and the replay tries it from a fresh start.
508
- if (!r && s.thrown) { if (!s.tries) { s.why = 'an error nothing caught can leave the game unable to raise it again where it stands, so the run\'s replay tries it from a fresh start'; s.uncounted = true; } break; }
509
- s.tries += 1;
510
- if (r) s.hits += 1;
375
+ return { hits, what: dead ? `${q(dead)} was clicked` : 'the buttons play never named were clicked', again: async hit => { if (hit.oracle !== 'dead_control') return false; const r = await click(hit.key); return r.ok && !r.changed; }, detail: `${list.length} pressed` };
376
+ });
377
+
378
+ await run('text', async () => {
379
+ const now = await look();
380
+ if (now.fields.length === 0) return { skip: now.canvas ? 'no text field is on the page (one drawn on a canvas cannot be filled by this probe)' : 'the page play ended on has no text field' };
381
+ const field = now.fields[0];
382
+ const hits = [];
383
+ const tryText = async (label, text) => {
384
+ const at = (await look()).fields.find(f => f.name === field.name);
385
+ if (!at) return [];
386
+ errors();
387
+ const before = await look();
388
+ const filled = await evaluate(pageFill, [at.x, at.y, text]).catch(() => null);
389
+ if (!filled) return [];
390
+ await keys.press('Enter').catch(() => {});
391
+ await sleep(timing.settleMs);
392
+ const what = `${label} was entered in ${q(field.name)} and Enter was pressed`;
393
+ const found = await judge(what, { before, softLock: false });
394
+ if (text === ODD_TEXT && await evaluate(pageMarkup, MARKUP_ID).catch(() => false)) found.push({ oracle: 'markup', severity: 'major', category: 'bug', title: 'Text the player types is inserted into the page as markup', description: `Text typed into ${q(field.name)} that contained a markup tag was put into the page as markup, not shown as the characters typed. A player's name or message can change the page it is shown on.` });
395
+ if (text.length >= 1000) { const over = await evaluate(pageOverflow, 3).catch(() => null); const long = over ? over.found.find(o => /A{20}/.test(o.text)) : null; if (long) found.push({ oracle: 'overflow_input', severity: 'minor', category: 'ux', title: 'Very long typed text runs out of its box', description: `After ${label} was entered in ${q(field.name)}, the game showed it ${long.px} pixels ${long.how}. The field takes ${filled.max ? `up to ${filled.max}` : 'any number of'} characters.` }); }
396
+ return found.map(h => ({ ...h, text, label }));
397
+ };
398
+ for (const [label, text] of [['nothing', ''], [`${timing.longText} characters`, 'A'.repeat(timing.longText)], ['unusual text (markup, quotes, other scripts, an emoji)', ODD_TEXT]]) hits.push(...await tryText(label, text));
399
+ const back = (await look()).fields.find(f => f.name === field.name);
400
+ if (back) await evaluate(pageFill, [back.x, back.y, '']).catch(() => {});
401
+ await evaluate(pageRings, true).catch(() => {});
402
+ return { hits, what: `text was entered in ${q(field.name)}`, again: async hit => (await tryText(hit.label, hit.text)).some(h => h.oracle === hit.oracle && h.key === hit.key) };
403
+ });
404
+
405
+ await run('menu', async () => {
406
+ const now = await look();
407
+ const opener = pressable(now.buttons).find(b => MENU.test(b.name));
408
+ if (!opener) return { skip: 'no menu, shop, settings or help button was found on the page play ended on' };
409
+ const numbers = text => new Map(readings(text).map(r => [r.label, r.value]));
410
+ const what = `${q(opener.name)} was opened and closed twice, the second time at once`;
411
+ let opened = true;
412
+ const once = async () => {
413
+ // Something is done first: a menu that undoes what was just done shows only when there is something to undo.
414
+ for (const name of canaries) await click(name);
415
+ errors();
416
+ const before = await look();
417
+ const n0 = numbers(before.text);
418
+ const first = await click(opener.name);
419
+ if (!first.ok || !first.changed) { opened = false; return []; }
420
+ await comeBack(before);
421
+ const again = (await look()).buttons.find(b => b.name === opener.name);
422
+ if (again) { await mouse.click(again.x, again.y).catch(() => {}); await keys.press('Escape').catch(() => {}); await sleep(timing.settleMs); }
423
+ await comeBack(before);
424
+ const n1 = numbers((await look()).text);
425
+ const found = await judge(what, { before });
426
+ for (const [label, was] of n0) { if (!n1.has(label) || n1.get(label) === was || CLOCK.test(label)) continue; found.push({ oracle: 'menu_state', key: label, severity: 'major', category: 'bug', title: `Opening and closing ${q(opener.name)} changes "${label}"`, description: `"${label}" was ${was} before ${q(opener.name)} was opened and ${n1.get(label)} after it was closed again. Nothing was done in between but opening and leaving it.` }); break; }
427
+ return found;
428
+ };
429
+ const hits = await once();
430
+ if (!opened) return { skip: `clicking ${q(opener.name)} did not open anything` };
431
+ return { hits, what, again: async hit => (await once()).some(h => h.oracle === hit.oracle && h.key === hit.key) };
432
+ });
433
+
434
+ await run('pause', async () => {
435
+ const now = await look();
436
+ const control = now.buttons.find(b => !b.disabled && PAUSE.test(b.name));
437
+ if (!control) return { skip: 'no pause button was found on the page play ended on' };
438
+ const what = `the game was paused with ${q(control.name)} and resumed`;
439
+ const frames = () => evaluate(() => new Promise(resolve => { let n = 0; const tick = () => { n += 1; requestAnimationFrame(tick); }; requestAnimationFrame(tick); setTimeout(() => resolve(n), 400); })).catch(() => null);
440
+ const moving = async () => { const a = await print(); await sleep(400); const b = await print(); return Boolean(a && b && significant(screenDelta(a, b))); };
441
+ const once = async () => {
442
+ errors();
443
+ const before = await look();
444
+ const movedBefore = await moving();
445
+ const paused = await click(control.name);
446
+ if (!paused.ok) return [];
447
+ const resume = pressable((await look()).buttons).find(b => RESUME.test(b.name) || PAUSE.test(b.name));
448
+ if (resume) await click(resume.name);
449
+ const found = await judge(what, { before });
450
+ // The page still draws frames; a game that moved before the pause and stands still after the resume did not come back.
451
+ if (movedBefore && found.length === 0 && (await frames()) !== null && !(await moving())) found.push({ oracle: 'pause_stuck', severity: 'major', category: 'bug', title: `The game does not come back after a pause with ${q(control.name)}`, description: `Before the pause the screen moved on its own. After pausing with ${q(control.name)} and resuming, it stood still: the game stayed paused, or its loop did not start again.` });
452
+ return found;
453
+ };
454
+ return { hits: await once(), what, again: async hit => (await once()).some(h => h.oracle === hit.oracle && h.key === hit.key) };
455
+ });
456
+
457
+ await run('opposite', async () => {
458
+ if (!keyboard) return { skip: 'the game has no canvas and play pressed no key, so it does not seem to be played by keys' };
459
+ const what = `opposite keys were held together (${OPPOSITES.map(p => p.join(' with ')).join(', ')})`;
460
+ const once = async () => {
461
+ errors();
462
+ const before = await look();
463
+ for (const [a, b] of OPPOSITES) { await keys.down(a).catch(() => {}); await keys.down(b).catch(() => {}); await sleep(timing.holdMs); await keys.up(a).catch(() => {}); await keys.up(b).catch(() => {}); await sleep(100); }
464
+ await sleep(timing.settleMs);
465
+ return judge(what, { before });
466
+ };
467
+ return { hits: await once(), what, again: async hit => (await once()).some(h => h.oracle === hit.oracle && h.key === hit.key) };
468
+ });
469
+
470
+ await run('edges', async () => {
471
+ if (!keyboard) return { skip: 'the game has no canvas and play pressed no key, so there is no player to push to an edge' };
472
+ const what = 'the player was pushed to the edges of the play area';
473
+ const once = async () => {
474
+ errors();
475
+ const before = await look();
476
+ for (const key of ['ArrowLeft', 'ArrowUp', 'ArrowRight', 'ArrowDown']) {
477
+ if (left() < 4000 || stopped()) break;
478
+ const from = Date.now();
479
+ await keys.down(key).catch(() => {});
480
+ let last = await print();
481
+ while (Date.now() - from < timing.edgeMaxMs) { await sleep(timing.edgeHoldMs); const now = await print(); const moved = last && now && significant(screenDelta(last, now)); last = now; if (!moved) break; }
482
+ await keys.up(key).catch(() => {});
483
+ await sleep(80);
484
+ }
485
+ await sleep(timing.settleMs);
486
+ return judge(what, { before });
487
+ };
488
+ return { hits: await once(), what, again: async hit => (await once()).some(h => h.oracle === hit.oracle && h.key === hit.key) };
489
+ });
490
+
491
+ await run('order', async () => {
492
+ const now = await look();
493
+ const list = pressable(now.buttons).filter(b => !UNSEEN_EFFECT.test(b.name)).slice(0, timing.maxSweep).reverse();
494
+ if (list.length < 2) return { skip: 'the page lists fewer than two buttons to press out of order' };
495
+ const what = 'the buttons were pressed in reverse order with no pause';
496
+ const once = async () => {
497
+ errors();
498
+ const before = await look();
499
+ for (const b of list) { const at = (await controls()).buttons.find(x => x.name === b.name && !x.disabled); if (at) { await mouse.click(at.x, at.y).catch(() => {}); await sleep(60); } }
500
+ await sleep(timing.settleMs);
501
+ return judge(what, { before });
502
+ };
503
+ return { hits: await once(), what, again: async hit => (await once()).some(h => h.oracle === hit.oracle && h.key === hit.key) };
504
+ });
505
+
506
+ await run('loading', async () => {
507
+ const what = 'clicks and keys were sent while the page was still loading';
508
+ const size = page.viewportSize() || { width: 1280, height: 720 };
509
+ const once = async () => {
510
+ errors();
511
+ const going = page.reload({ waitUntil: 'load', timeout: 15000 }).then(() => true, () => false);
512
+ const until = Date.now() + timing.loadInputMs;
513
+ while (Date.now() < until) { await mouse.click(Math.round(size.width / 2), Math.round(size.height / 2)).catch(() => {}); await keys.press('Enter').catch(() => {}); await keys.press(' ').catch(() => {}); await sleep(40); }
514
+ const loaded = await going;
515
+ await sleep(timing.settleMs + 400);
516
+ if (!loaded) return [{ oracle: 'no_load', severity: 'major', category: 'bug', title: 'The game does not load when input arrives while it is loading', description: 'With clicks and keys sent while the page was loading, it did not finish loading. It had loaded when left alone.' }];
517
+ return judge(what, { softLock: false });
518
+ };
519
+ return { hits: await once(), what, again: async hit => (await once()).some(h => h.oracle === hit.oracle && h.key === hit.key) };
520
+ });
521
+
522
+ // Try each suspect again where it stands; a game left stuck waits for the replay.
523
+ for (const s of suspects) {
524
+ s.tries = 0; s.hits = 0; s.why = null; s.uncounted = false;
525
+ if (['soft_lock', 'frozen', 'crash', 'blank', 'pause_stuck', 'no_load'].includes(s.oracle) && s.probe !== 'loading') { s.why = 'the game was left stuck, so it can only be tried again from a fresh start'; continue; }
526
+ for (let i = 0; i < retries && left() > 3000 && !stopped() && typeof s.again === 'function'; i += 1) {
527
+ const r = await Promise.resolve().then(() => s.again(s)).catch(() => false);
528
+ // A try the game could not take is not a try: it is never counted as "not reproduced" (the replay tries it from a fresh start).
529
+ if (r && typeof r === 'object' && r.untried) { if (!s.tries) s.why = r.untried; break; }
530
+ // An error nothing caught can leave the game unable to raise it again where it stands (a game loop it
531
+ // stopped): a second try that sees nothing is not counted, and the replay tries it from a fresh start.
532
+ if (!r && s.thrown) { if (!s.tries) { s.why = 'an error nothing caught can leave the game unable to raise it again where it stands, so the run\'s replay tries it from a fresh start'; s.uncounted = true; } break; }
533
+ s.tries += 1;
534
+ if (r) s.hits += 1;
535
+ }
536
+ if (!s.tries && retries > 0 && !s.why) s.why = 'no time was left';
537
+ }
538
+ } finally {
539
+ // A page that stopped answering has nothing to put back, and every ask would wait out its timeout.
540
+ if (!hung) {
541
+ if (focusMark) await evaluate(() => { const el = document.querySelector('[data-ravensight-play-focus]'); if (el) { el.removeAttribute('data-ravensight-play-focus'); el.focus(); } }).catch(() => {});
542
+ await evaluate(pageRings, false).catch(() => {});
543
+ if (session.dismissDialogs) session.dismissDialogs(false);
544
+ await Promise.resolve().then(() => session.parkClock()).catch(() => {});
511
545
  }
512
- if (!s.tries && retries > 0 && !s.why) s.why = 'no time was left';
513
546
  }
514
- } finally {
515
- if (focusMark) await evaluate(() => { const el = document.querySelector('[data-ravensight-play-focus]'); if (el) { el.removeAttribute('data-ravensight-play-focus'); el.focus(); } }).catch(() => {});
516
- await evaluate(pageRings, false).catch(() => {});
517
- if (session.dismissDialogs) session.dismissDialogs(false);
518
- await Promise.resolve().then(() => session.parkClock()).catch(() => {});
547
+ })().catch(error => { failure = error; });
548
+ const late = await Promise.race([work.then(() => false), new Promise(resolve => { deadlineTimer = setTimeout(() => resolve(true), Math.max(0, timing.budgetMs) + PASS_GRACE_MS); })]);
549
+ clearTimeout(deadlineTimer);
550
+ if (late) {
551
+ hung = hung || 'the probes ran out of time';
552
+ for (const [id, title] of PROBES) if (!checks.some(c => c.name === id) && (id === 'loading') === Boolean(loading) && (!only || only.includes(id))) { checks.push({ name: id, title, status: 'not_checked', detail: hung }); log(`tester probe, ${title}: not_checked (${hung})`); }
519
553
  }
520
- return { checks, suspects: suspects.map(({ again: _again, ...rest }) => rest), canaries, elapsedMs: Date.now() - started };
554
+ if (failure && !late) throw failure;
555
+ return { checks: [...checks], suspects: suspects.map(({ again: _again, ...rest }) => rest), canaries: [...canaries], elapsedMs: Date.now() - started, ...(hung ? { stopped: hung } : {}) };
521
556
  }
522
557
 
523
558
  /**