ravensight-playtest 0.13.0 → 0.13.2

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.
@@ -13,6 +13,7 @@ import path from 'node:path';
13
13
 
14
14
  import { detectFfmpeg } from '../detect.js';
15
15
  import { replayTrace } from './replay.js';
16
+ import { noEffectTries } from './stillWatch.js';
16
17
  import { TRACE_FILE, parseTrace } from './trace.js';
17
18
 
18
19
  /* ------------------------------------------------------------------- mood */
@@ -398,15 +399,26 @@ export function traceWebInputs(driver, { fingerprint }) {
398
399
  * step log, as for a Godot run.
399
400
  *
400
401
  * A finding is `reproduced` when every replay showed the same screen after
401
- * its input (or, for an input that changed nothing, changed nothing again),
402
- * `diverged` when the replay was already on a different screen before that
403
- * input, `not_reproduced` when one replay matched and one did not, and
404
- * `not_run` when the replay did not reach it.
402
+ * its input, `diverged` when the replay was already on a different screen
403
+ * before that input, `not_reproduced` when one replay matched and one did
404
+ * not, and `not_run` when the replay did not reach it.
405
+ *
406
+ * A finding that says nothing happened (a claim that nothing happens, by its
407
+ * words: `stuck`; or one placed at an input that changed nothing) is held to
408
+ * the hosted replay's rule (lib/verify.mjs replayOnce and replayResult): the
409
+ * input changing nothing again says nothing alone, so the last replay, after
410
+ * the first, watches the screen while game time runs with no input (`watch`,
411
+ * ./stillWatch.js watchWebStill). It is `reproduced` only beside a watch that
412
+ * saw nothing change, with `watched_ms`, the game time the watch covered; with
413
+ * no watch it is `not_possible`, "not verifiable", and never passed.
414
+ *
415
+ * `prior` holds results already made for findings (the watch the claim judge
416
+ * asked for, before the report): each is written as it is, not replayed again.
405
417
  *
406
418
  * @param {Object} args
407
419
  * @returns {Promise<{ran: boolean, runs: number, skipped: string|null, results: Array<Object>}>}
408
420
  */
409
- export async function replayWebFindings({ report, index = [], traceSteps = new Map(), trace = [], makeDriver, target, viewport = null, playMs = 0, transcript, signal = null, fingerprint, differs, observer = null, now = Date.now, runs = REPLAY_RUNS, tempDir = null }) {
421
+ export async function replayWebFindings({ report, index = [], traceSteps = new Map(), trace = [], makeDriver, target, viewport = null, playMs = 0, transcript, signal = null, fingerprint, differs, observer = null, now = Date.now, runs = REPLAY_RUNS, tempDir = null, watch = null, stuck = new Set(), prior = new Map() }) {
410
422
  const issues = (report && Array.isArray(report.findings) ? report.findings : []).filter(finding => finding && SEVERITY_ORDER.includes(finding.severity));
411
423
  const finish = (pass, results) => {
412
424
  for (const result of results) transcript.write({ kind: 'replay_check', ...result });
@@ -414,25 +426,38 @@ export async function replayWebFindings({ report, index = [], traceSteps = new M
414
426
  return { ...pass, results };
415
427
  };
416
428
  if (issues.length === 0) return finish({ ran: false, runs: 0, skipped: 'the report has no issue to replay' }, []);
429
+ // Results the watch before the judge already made: written as they are.
430
+ const earlier = issues.filter(finding => prior.has(finding.id)).map(finding => prior.get(finding.id));
417
431
  // Findings of the runner's own scripted probes are not about one recorded input: the observer runs those probes again at the end of the replay (./testerProbes.js).
418
432
  const scripted = new Set(observer && Array.isArray(observer.ids) ? observer.ids : []);
419
- const targets = replayTargets({ ...report, findings: issues.filter(finding => !scripted.has(finding.id)) }, index, traceSteps).filter(entry => entry.trace_steps <= trace.length);
420
- const rest = issues.filter(finding => !scripted.has(finding.id) && !targets.some(entry => entry.id === finding.id)).map(finding => {
433
+ const replayed = issues.filter(finding => !prior.has(finding.id));
434
+ const targets = replayTargets({ ...report, findings: replayed.filter(finding => !scripted.has(finding.id)) }, index, traceSteps).filter(entry => entry.trace_steps <= trace.length);
435
+ const rest = replayed.filter(finding => !scripted.has(finding.id) && !targets.some(entry => entry.id === finding.id)).map(finding => {
421
436
  const tied = Number.isInteger(index.find(entry => entry.id === finding.id)?.action);
422
437
  const capped = tied && targets.length >= MAX_REPLAY_FINDINGS;
423
438
  return { id: finding.id, state: capped ? 'not_run' : 'not_possible', runs: 0, of: 0, trace_steps: 0, detail: capped ? `the replay looks at the ${MAX_REPLAY_FINDINGS} most severe findings` : 'the finding is not tied to an input the run recorded' };
424
439
  });
425
- if (targets.length === 0 && scripted.size === 0) return finish({ ran: false, runs: 0, skipped: 'no finding is tied to an input the run recorded' }, rest);
440
+ if (targets.length === 0 && scripted.size === 0) {
441
+ if (earlier.length > 0) return finish({ ran: true, runs: Math.max(...earlier.map(result => Number(result.of) || 0)), skipped: null }, [...earlier, ...rest]);
442
+ return finish({ ran: false, runs: 0, skipped: 'no finding is tied to an input the run recorded' }, rest);
443
+ }
444
+ // A finding that says nothing happened: watched on the last replay (the hosted runner's `still`).
445
+ const still = new Set(targets.filter(entry => stuck.has(entry.id) || trace[entry.trace_steps - 1]?.changed === false).map(entry => entry.id));
426
446
  // With probes to run again, the replay plays every recorded input, to the screen play ended on.
427
447
  const last = Math.max(0, ...targets.map(entry => entry.trace_steps), scripted.size > 0 ? trace.length : 0);
448
+ const lastStill = Math.max(0, ...targets.filter(entry => still.has(entry.id)).map(entry => entry.trace_steps));
428
449
  const started = now();
429
450
  const deadline = started + replayBudget(playMs);
430
451
  const verdicts = new Map([...targets.map(entry => [entry.id, []]), ...[...scripted].map(id => [id, []])]);
431
452
  const same = (a, b) => (a && b ? !differs(a, b) : null);
453
+ const seconds = ms => (ms / 1000).toFixed(1);
432
454
  let made = 0, problem = null, longest = 0;
433
455
  for (let i = 0; i < runs; i++) {
434
456
  if (i > 0 && now() + longest > deadline) break;
435
457
  if (signal && signal.aborted) { problem = 'the run was cancelled'; break; }
458
+ // The watch moves the game past the recording, so it has a run of its own: the last, after the first, played to the last finding it watches.
459
+ const watchRun = Boolean(watch) && still.size > 0 && i > 0 && i === runs - 1;
460
+ let watched = false;
436
461
  const at = now();
437
462
  const dir = tempDir ? await tempDir() : null;
438
463
  let driver = null;
@@ -442,33 +467,56 @@ export async function replayWebFindings({ report, index = [], traceSteps = new M
442
467
  await driver.observe();
443
468
  let before = null;
444
469
  try { before = fingerprint(await driver.screenProbe()); } catch { before = null; }
445
- for (let n = 0; n < last; n++) {
470
+ for (let n = 0; n < (watchRun ? lastStill : last); n++) {
446
471
  if (now() > deadline) break;
447
472
  const entry = trace[n];
448
473
  // An input the run refused because the brief asks to stay out of it is never sent by the replay either.
449
474
  if (!entry.avoided) await driver.act(entry.action);
450
475
  let after = null;
451
476
  try { after = fingerprint(await driver.screenProbe()); } catch { after = null; }
452
- for (const hit of targets.filter(candidate => candidate.trace_steps === n + 1)) {
453
- // Where the run itself stood before this input: the screen after the input before it.
454
- const was = n > 0 ? trace[n - 1].print : null;
455
- const sameBefore = n > 0 ? same(before, was) : true;
456
- let verdict, detail;
457
- if (sameBefore === false) { verdict = 'diverged'; detail = 'the replay was on a different screen before this input'; }
458
- else if (entry.changed === false) {
459
- const quiet = same(before, after);
460
- verdict = quiet === null ? 'unchecked' : quiet ? 'match' : 'no_match';
461
- detail = quiet === null ? 'the screen could not be read to compare' : quiet ? 'the input changed nothing again' : 'the input changed the screen this time';
462
- } else {
477
+ // Where the run itself stood before this input: the screen after the input before it.
478
+ const was = n > 0 ? trace[n - 1].print : null;
479
+ const sameBefore = n > 0 ? same(before, was) : true;
480
+ const hits = targets.filter(candidate => candidate.trace_steps === n + 1);
481
+ const quiet = same(before, after);
482
+ // One watch for the step, from the screen the input left, when a finding of it says nothing happened and the input changed nothing again.
483
+ let seen = null;
484
+ if (watchRun && sameBefore !== false && quiet === true && hits.some(hit => still.has(hit.id))) {
485
+ seen = await Promise.resolve().then(() => watch(driver, { from: after, deadline, now })).catch(() => ({ verifiable: false, changed: null, gameMs: 0, why: 'the screen could not be watched' }));
486
+ }
487
+ for (const hit of hits) {
488
+ let verdict, detail, gameMs;
489
+ if (still.has(hit.id)) {
490
+ if (sameBefore === false) ({ verdict, detail } = watched ? { verdict: 'unverifiable', detail: 'not verifiable: the watch of an earlier finding moved the game on, so this moment was not reached again' } : { verdict: 'diverged', detail: 'the replay was on a different screen before this input' });
491
+ // An input the brief kept the run out of was never sent, by play or by the replay: its quiet screen says nothing.
492
+ else if (entry.avoided) ({ verdict, detail } = { verdict: 'unchecked', detail: 'the recorded input was never sent, as the brief asks to stay out of it, so nothing can be compared' });
493
+ else if (quiet === null) ({ verdict, detail } = { verdict: 'unchecked', detail: 'the screen could not be read to compare' });
494
+ else if (!quiet) ({ verdict, detail } = { verdict: 'no_match', detail: stuck.has(hit.id) ? 'the screen changed when the recorded input was played again' : 'the input changed the screen this time' });
495
+ // Quiet on a replay that does not watch: it counts beside a watch that found the screen still, and says nothing alone.
496
+ else if (!watchRun) ({ verdict, detail } = { verdict: 'unwatched', detail: 'the input changed nothing again' });
497
+ else if (!seen || !seen.verifiable) ({ verdict, detail } = { verdict: 'unverifiable', detail: `not verifiable: ${seen?.why || 'the screen could not be watched while game time ran'}` });
498
+ else if (seen.changed) ({ verdict, detail } = { verdict: 'no_match', detail: `the screen changed on its own while game time ran for ${seconds(seen.gameMs)} seconds with no input` });
499
+ else ({ verdict, detail, gameMs } = { verdict: 'match', gameMs: seen.gameMs, detail: `${entry.changed === false ? 'the input changed nothing again, and ' : ''}nothing on screen changed while game time ran for ${seconds(seen.gameMs)} seconds with no input` });
500
+ } else if (watchRun && watched) {
501
+ // After a watch the game is past the recording: this moment was not reached again, which says nothing about it.
502
+ continue;
503
+ } else if (sameBefore === false) { verdict = 'diverged'; detail = 'the replay was on a different screen before this input'; }
504
+ else {
463
505
  const again = same(after, entry.print);
464
506
  verdict = again === null ? 'unchecked' : again ? 'match' : 'no_match';
465
507
  detail = again === null ? 'the run kept no picture of the screen after this input to compare with' : again ? 'the same screen followed the input' : 'a different screen followed the input';
466
508
  }
467
- verdicts.get(hit.id).push({ verdict, detail });
509
+ verdicts.get(hit.id).push({ verdict, detail, ...(Number.isFinite(gameMs) ? { gameMs } : {}) });
510
+ }
511
+ if (seen) {
512
+ // The screen the next input is made on is the one the watch left.
513
+ watched = true;
514
+ try { after = fingerprint(await driver.screenProbe()); } catch { after = null; }
468
515
  }
469
516
  before = after;
470
517
  }
471
- if (scripted.size > 0 && now() < deadline) {
518
+ // The probes are run again where play ended, which a watch replay neither reaches nor leaves as it was.
519
+ if (!watchRun && scripted.size > 0 && now() < deadline) {
472
520
  const again = await observer.end(driver).catch(() => new Map());
473
521
  for (const id of scripted) if (again.has(id)) verdicts.get(id).push({ verdict: again.get(id) ? 'match' : 'no_match', detail: again.get(id) ? 'the probe was run again at the end of the replay and the same thing happened' : 'the probe was run again at the end of the replay and it did not happen' });
474
522
  }
@@ -483,14 +531,59 @@ export async function replayWebFindings({ report, index = [], traceSteps = new M
483
531
  longest = Math.max(longest, now() - at);
484
532
  }
485
533
  const results = [...targets, ...[...scripted].map(id => ({ id, trace_steps: trace.length }))].map(entry => {
486
- const all = verdicts.get(entry.id);
487
- const usable = all.filter(item => item.verdict !== 'unchecked');
488
534
  const base = { id: entry.id, trace_steps: entry.trace_steps };
535
+ let all = verdicts.get(entry.id);
489
536
  if (all.length === 0) return { ...base, state: 'not_run', runs: 0, of: 0, detail: problem || (scripted.has(entry.id) ? 'the replay ran out of its time before the probe could be run again' : 'the replay ran out of its time before it reached this input') };
537
+ // "Nothing happened" needs a watch (the hosted replayResult): a replay that could not watch, and one that only saw the input change
538
+ // nothing again, say nothing alone. With no replay that saw the screen change and no watch that found it still, it is not verifiable.
539
+ const blind = all.filter(item => item.verdict === 'unverifiable');
540
+ const unwatched = all.filter(item => item.verdict === 'unwatched');
541
+ const negative = all.some(item => item.verdict === 'no_match');
542
+ const watchedStill = all.some(item => item.verdict === 'match' && Number.isFinite(item.gameMs));
543
+ if ((blind.length || unwatched.length) && !negative && (blind.length || !watchedStill)) {
544
+ return { ...base, state: 'not_possible', runs: 0, of: 0, detail: blind[0]?.detail || `not verifiable: the input changed nothing again on ${unwatched.length} ${unwatched.length === 1 ? 'replay' : 'replays'}, and no replay was left to watch the screen with game time running` };
545
+ }
546
+ // Beside a watch that found the screen still, a quiet replay that did not watch is one more match; beside one that saw it change, it is nothing.
547
+ all = all.filter(item => item.verdict !== 'unverifiable').map(item => (item.verdict !== 'unwatched' ? item : watchedStill && !negative ? { ...item, verdict: 'match' } : null)).filter(Boolean);
548
+ const usable = all.filter(item => item.verdict !== 'unchecked');
490
549
  if (usable.length === 0) return { ...base, state: 'not_possible', runs: 0, of: 0, detail: all[0].detail };
491
550
  const matched = usable.filter(item => item.verdict === 'match').length;
492
551
  const diverged = usable.filter(item => item.verdict === 'diverged').length;
493
- return { ...base, state: matched === usable.length ? 'reproduced' : matched === 0 && diverged > 0 ? 'diverged' : 'not_reproduced', runs: matched, of: usable.length, detail: [...new Set(usable.map(item => item.detail))].join('; ') };
552
+ const state = matched === usable.length ? 'reproduced' : matched === 0 && diverged > 0 ? 'diverged' : 'not_reproduced';
553
+ // How long game time ran, at least, in the watches that found the screen still: what lets "nothing happens" count as reproduced (./judge.js).
554
+ const watches = usable.filter(item => item.verdict === 'match' && Number.isFinite(item.gameMs));
555
+ const words = state === 'reproduced' && watches.length ? watches : usable;
556
+ return { ...base, state, runs: matched, of: usable.length, ...(state === 'reproduced' && watches.length ? { watched_ms: Math.min(...watches.map(item => item.gameMs)) } : {}), detail: [...new Set(words.map(item => item.detail))].join('; ') };
494
557
  });
495
- return finish({ ran: made > 0, runs: made, skipped: made > 0 ? null : problem, elapsed_ms: now() - started }, [...results, ...rest]);
558
+ return finish({ ran: made > 0 || earlier.length > 0, runs: Math.max(made, ...earlier.map(result => Number(result.of) || 0)), skipped: made > 0 || earlier.length > 0 ? null : problem, elapsed_ms: now() - started }, [...results, ...earlier, ...rest]);
559
+ }
560
+
561
+ /* ------------------------------------------- the watch the claim judge asks */
562
+
563
+ /**
564
+ * The evidence the claim judge needs for claims that nothing happens, on a
565
+ * web run, before the report is settled: for each, what the run measured of
566
+ * its input (./stillWatch.js noEffectTries), and for each one measured, a
567
+ * replay of the recorded inputs that watches the screen while game time runs
568
+ * (replayWebFindings with every target watched). Nothing is written here; the
569
+ * judge keeps a `still_check` line per claim, and the replay after the report
570
+ * writes the results it reuses.
571
+ *
572
+ * @param {Object} args `wanted`: [{id, action}], and replayWebFindings' own arguments
573
+ * @returns {Promise<Map<string, {measured: Object|null, replay: Object|null}>>}
574
+ */
575
+ export async function watchClaimsStill({ wanted = [], trace = [], traceSteps = new Map(), replay = replayWebFindings, ...rest }) {
576
+ const out = new Map();
577
+ const measured = new Map();
578
+ for (const { id, action } of wanted) {
579
+ const steps = Number.isInteger(action) ? traceSteps.get(action) : undefined;
580
+ const tries = noEffectTries(trace, steps);
581
+ out.set(id, { measured: tries, replay: null });
582
+ if (tries) measured.set(id, action);
583
+ }
584
+ if (measured.size === 0) return out;
585
+ const pass = await replay({ ...rest, trace, traceSteps, report: { findings: [...measured.keys()].map(id => ({ id, severity: 'major' })) },
586
+ index: [...measured].map(([id, action]) => ({ id, action })), stuck: new Set(measured.keys()), transcript: { write() {} } });
587
+ for (const result of pass.results || []) if (out.has(result.id)) out.set(result.id, { ...out.get(result.id), replay: result });
588
+ return out;
496
589
  }
@@ -0,0 +1,114 @@
1
+ // The game's own Ravensight SDK opening its session, on a local web run.
2
+ //
3
+ // A web game's SDK opens a session (POST /api/v1/session, with the build's
4
+ // ingest key in X-API-Key and the run's playtest tag) before it sends any
5
+ // event. When the server refuses that session, the SDK sends nothing: the
6
+ // run has none of the game's events to read as ground truth, and nothing is
7
+ // recorded in the game's analytics. The server refuses a playtest run's tag
8
+ // on a public key by design (a public key ships inside every build; only a
9
+ // cloud run's runner, which keeps its tag out of the page, may carry one), so
10
+ // a local run of a build with a public key records no game events.
11
+ //
12
+ // The proof run of 2026-11-19 (pt_job_7b2fcf8b8bf3eb3a000a) had exactly that,
13
+ // and its report called the 403 "the signed-out session-check pattern". Here
14
+ // the driver reads each answer to the SDK's session request (status, key
15
+ // kind, whether it carried the tag, the error code; never the key or the
16
+ // token), and the report says plainly that no game events were recorded and
17
+ // why. Nothing here changes a request or asks a model anything.
18
+
19
+ const SESSION_PATH = /\/api\/v1\/session\/?$/;
20
+ const ERROR_CODE = /^[a-z0-9_]{1,60}$/;
21
+
22
+ /** What kind of ingest key a request carried, by its prefix only; null when it carried no Ravensight key. */
23
+ function keyKind(value) {
24
+ const key = String(value || '').trim();
25
+ if (!key.startsWith('gt_')) return null;
26
+ if (key.startsWith('gt_pub_')) return 'public';
27
+ if (key.startsWith('gt_live_')) return 'live';
28
+ return 'other';
29
+ }
30
+
31
+ /**
32
+ * The answer to one request, when it is the game's own Ravensight SDK
33
+ * opening its session: `{ status, key, tagged, error }`, else null. Never
34
+ * throws.
35
+ *
36
+ * @param {any} response a Playwright response
37
+ * @returns {Promise<{status: number, key: string, tagged: boolean, error: string|null}|null>}
38
+ */
39
+ export async function sdkSessionAnswer(response) {
40
+ try {
41
+ if (!response || typeof response.request !== 'function') return null;
42
+ const request = response.request();
43
+ if (!request || typeof request.method !== 'function' || request.method() !== 'POST') return null;
44
+ const url = new URL(typeof request.url === 'function' ? request.url() : response.url());
45
+ if (!/^https?:$/.test(url.protocol) || !SESSION_PATH.test(url.pathname)) return null;
46
+ const headers = typeof request.headers === 'function' ? request.headers() || {} : {};
47
+ const key = keyKind(headers['x-api-key']);
48
+ if (!key) return null;
49
+ const status = Number(response.status());
50
+ if (!Number.isInteger(status)) return null;
51
+ let error = null;
52
+ if (status >= 400) {
53
+ const body = await Promise.resolve().then(() => response.json()).catch(() => null);
54
+ if (body && typeof body.error === 'string' && ERROR_CODE.test(body.error)) error = body.error;
55
+ }
56
+ return { status, key, tagged: Boolean(String(headers['x-ravensight-playtest'] || '').trim()), error };
57
+ } catch {
58
+ return null;
59
+ }
60
+ }
61
+
62
+ /** The run's record of the SDK's session answers: how many opened, and each kind of refusal, counted. */
63
+ export function createSdkSessions() {
64
+ let opened = 0;
65
+ const refused = new Map();
66
+ return {
67
+ record(answer) {
68
+ if (!answer || !Number.isInteger(answer.status)) return;
69
+ if (answer.status >= 200 && answer.status < 300) { opened += 1; return; }
70
+ if (answer.status < 400) return;
71
+ const id = `${answer.status}|${answer.error || ''}|${answer.key}|${answer.tagged}`;
72
+ const seen = refused.get(id) || { status: answer.status, key: answer.key, tagged: answer.tagged, error: answer.error || null, times: 0 };
73
+ seen.times += 1;
74
+ refused.set(id, seen);
75
+ },
76
+ summary() {
77
+ return { opened, refused: [...refused.values()].map(entry => ({ ...entry })) };
78
+ }
79
+ };
80
+ }
81
+
82
+ /** The refusal the run had, when the SDK asked for a session and none ever opened; null otherwise. */
83
+ export function sessionRefusal(summary) {
84
+ if (!summary || summary.opened > 0 || !Array.isArray(summary.refused) || summary.refused.length === 0) return null;
85
+ return { ...summary.refused.reduce((most, entry) => (entry.times > most.times ? entry : most)) };
86
+ }
87
+
88
+ const codeWords = refusal => `${refusal.status}${refusal.error ? ` ${refusal.error}` : ''}`;
89
+
90
+ /** Why, in plain words, for the refusals the server gives a reason for; empty for the rest. */
91
+ function because(refusal) {
92
+ if (refusal.error === 'public_key_forbidden' && refusal.tagged) return ' The build sends a public ingest key, and a public key cannot carry a local playtest run\'s tag, so a local run of this build cannot record them; a cloud playtest of the same build records them.';
93
+ if (refusal.error === 'tracking_disabled') return ' The server said tracking is switched off for this game.';
94
+ if (refusal.error === 'playtest_job_closed') return ' The server said this playtest had already finished.';
95
+ if (refusal.error === 'invalid_playtest_token') return ' The server did not accept the run\'s playtest tag for the game this build\'s key belongs to.';
96
+ return '';
97
+ }
98
+
99
+ /**
100
+ * The plain statement report.md carries under "Measured from the game's own
101
+ * events" when the SDK's session was refused.
102
+ *
103
+ * @param {{status: number, error: string|null, key: string, tagged: boolean}} refusal
104
+ */
105
+ export function refusedEventsBody(refusal) {
106
+ return `No game events were recorded in this run. The game's Ravensight SDK asked to open its session and the server refused it (${codeWords(refusal)}), so the SDK sent none of its events.${because(refusal)} Nothing in this report was measured from the game's own events.`;
107
+ }
108
+
109
+ /** What the report step is told, so its network notes say the same thing and never call the refusal benign. */
110
+ export function refusedReportInstruction(refusal) {
111
+ return `The game's own Ravensight SDK asked to open its analytics session and the server refused it (${codeWords(refusal)}), so no game events were recorded in this run.${because(refusal)} When report.md lists this request under "Network notes", say exactly that: it is not a sign-in check, never call it benign, expected or harmless, and do not write that it caused no problem. It is not a finding about the game either.`;
112
+ }
113
+
114
+ export default { sdkSessionAnswer, createSdkSessions, sessionRefusal, refusedEventsBody, refusedReportInstruction };
@@ -0,0 +1,123 @@
1
+ // A claim that nothing happens, on a local web run, held to the hosted
2
+ // runner's evidence: the run measured it (the same control pressed again and
3
+ // again, changing nothing every time and answering at no other moment), and
4
+ // a replay watched the screen while game time ran with no input and nothing
5
+ // on it changed. The watch is the hosted runner's own (the platform repo,
6
+ // infrastructure/hosted-playtest/direct-runner/lib/verify.mjs watchStill,
7
+ // and STILL_MIN_GAME_MS in lib/claims.mjs), ported: the replay plays the
8
+ // recorded inputs to the claim's input, lets game time run, and compares
9
+ // every frame with the screen the input left. The gate that reads the result
10
+ // is ./judge.js, by the hosted gate's stuck rule.
11
+ //
12
+ // Nothing here asks a model anything, and a watch that cannot show game time
13
+ // ran is never counted as still: it is "not verifiable", with the reason.
14
+ import { DEAD_END_AFTER } from './anygame/memory.js';
15
+
16
+ /** A claim that nothing happens is confirmed only when nothing on screen changed over at least this much game time with no input. */
17
+ export const STILL_MIN_GAME_MS = 2000;
18
+ /** The watch gives up after this much wall time. */
19
+ export const STILL_WALL_CAP_MS = 8 * 1000;
20
+
21
+ /* c8 ignore start */
22
+ /** Runs in the page: lets `ms` of the page's own clock pass and counts the frames it drew meanwhile. The hosted runner's own. */
23
+ export function pageClockWindow(ms) {
24
+ return new Promise(resolve => {
25
+ const t0 = performance.now();
26
+ let frames = 0, done = false;
27
+ const end = () => { if (done) return; done = true; resolve({ ms: performance.now() - t0, frames }); };
28
+ const tick = () => { frames++; if (performance.now() - t0 >= ms) end(); else requestAnimationFrame(tick); };
29
+ requestAnimationFrame(tick);
30
+ setTimeout(end, ms + 1500);
31
+ });
32
+ }
33
+ /* c8 ignore stop */
34
+
35
+ /**
36
+ * Watch the screen with no input while game time runs: the hosted watch with
37
+ * no time gate, where the page's clock is the game's and the frames it drew
38
+ * are counted, so a page that is not running is not taken for a still game.
39
+ * The caller lets go of any gate of its own first (./timeFreeze.js).
40
+ *
41
+ * @param {Object} args
42
+ * @param {(ms: number) => Promise<{ms: number, frames: number}|null>} args.clockWindow the page's clock over a window (pageClockWindow, in the page)
43
+ * @param {() => Promise<any>} args.shot the screen now, as `differs` compares it; null when it cannot be read
44
+ * @param {any} args.from the screen the input left
45
+ * @param {(a: any, b: any) => boolean} args.differs whether a player would notice a difference
46
+ * @returns {Promise<{verifiable: boolean, changed: boolean|null, gameMs: number, why: string|null}>}
47
+ */
48
+ export async function watchStill({ clockWindow, shot, from, differs, minGameMs = STILL_MIN_GAME_MS, capMs = STILL_WALL_CAP_MS, deadline = Infinity, now = Date.now }) {
49
+ const started = now();
50
+ const until = Math.min(started + capMs, deadline);
51
+ const frames = [];
52
+ let gameMs = 0, drawn = 0, why = null;
53
+ while (gameMs < minGameMs && now() < until) {
54
+ const r = await Promise.resolve().then(() => clockWindow(Math.max(100, Math.min(1000, minGameMs - gameMs)))).catch(() => null);
55
+ if (!r || !Number.isFinite(r.ms) || r.ms <= 0) { why = 'the page did not answer while it was watched'; break; }
56
+ gameMs += r.ms; drawn += Number(r.frames) || 0;
57
+ frames.push(await Promise.resolve().then(() => shot()).catch(() => null));
58
+ }
59
+ if (!why && drawn < 2) why = 'the page drew no frames while it was watched, so its time cannot be shown to have run';
60
+ if (!why && gameMs < minGameMs) why = `game time ran for ${(gameMs / 1000).toFixed(1)} of the ${(minGameMs / 1000).toFixed(1)} seconds the watch needs`;
61
+ if (!why && frames.some(frame => frame === null || frame === undefined)) why = 'the screen could not be read while it was watched';
62
+ if (why) return { verifiable: false, changed: null, gameMs: Math.round(gameMs), why };
63
+ return { verifiable: true, changed: frames.some(frame => differs(from, frame)), gameMs: Math.round(gameMs), why: null };
64
+ }
65
+
66
+ /**
67
+ * The watch on a playwright_web driver (a replay's): game time is let go for
68
+ * the watch (a canvas game's clock is parked between inputs) and parked again
69
+ * after it, whatever happens.
70
+ *
71
+ * @param {Object} driver
72
+ * @param {{from: any, fingerprint: Function, differs: Function, deadline?: number, now?: Function}} opts
73
+ */
74
+ export async function watchWebStill(driver, { from, fingerprint, differs, deadline = Infinity, now = Date.now }) {
75
+ const session = driver && typeof driver.edgeSession === 'function' ? driver.edgeSession() : null;
76
+ if (!session || !session.page || typeof session.page.evaluate !== 'function') return { verifiable: false, changed: null, gameMs: 0, why: 'this run has no page it can watch' };
77
+ await Promise.resolve().then(() => session.releaseClock && session.releaseClock()).catch(() => {});
78
+ try {
79
+ return await watchStill({
80
+ clockWindow: ms => session.page.evaluate(pageClockWindow, ms),
81
+ shot: async () => fingerprint(await driver.screenProbe()),
82
+ from, differs, deadline, now
83
+ });
84
+ } finally {
85
+ await Promise.resolve().then(() => session.parkClock && session.parkClock()).catch(() => {});
86
+ }
87
+ }
88
+
89
+ /** The control a click names, by its accessible name: a point on a canvas, or a ref read off one screen, is not one. */
90
+ function controlOf(entry) {
91
+ const action = entry && entry.action;
92
+ if (!action || action.kind !== 'click' || typeof action.target !== 'string') return null;
93
+ const name = action.target.trim();
94
+ return name ? name : null;
95
+ }
96
+
97
+ /**
98
+ * What the run measured of the input a claim that nothing happens is placed
99
+ * at: the same named control pressed at least DEAD_END_AFTER times (the
100
+ * any-game memory's own rule for a dead end), the page taking every press and
101
+ * the screen changing on none, and the control answering at no other moment
102
+ * of the run (the hosted report's rule: a control that answered once depends
103
+ * on the game's state, and is not dead). Null otherwise.
104
+ *
105
+ * @param {Array<{action: Object, ok: boolean, changed: boolean|null, avoided?: boolean}>} trace the run's web inputs (./reportChecks.js traceWebInputs)
106
+ * @param {number} steps the inputs played by the end of the claim's action (its trace length then)
107
+ * @returns {{target: string, tries: number, steps: Array<number>}|null}
108
+ */
109
+ export function noEffectTries(trace, steps, { min = DEAD_END_AFTER } = {}) {
110
+ if (!Array.isArray(trace) || !Number.isInteger(steps) || steps < 1 || steps > trace.length) return null;
111
+ const at = trace[steps - 1];
112
+ const name = controlOf(at);
113
+ if (!name || at.ok !== true || at.changed !== false || at.avoided) return null;
114
+ const key = name.toLowerCase();
115
+ const same = [];
116
+ trace.forEach((entry, i) => { if (controlOf(entry)?.toLowerCase() === key) same.push({ entry, step: i + 1 }); });
117
+ if (same.some(({ entry }) => entry.changed === true)) return null;
118
+ const tries = same.filter(({ entry }) => entry.ok === true && entry.changed === false && !entry.avoided);
119
+ if (tries.length < min) return null;
120
+ return { target: name, tries: tries.length, steps: tries.map(({ step }) => step) };
121
+ }
122
+
123
+ export default { STILL_MIN_GAME_MS, STILL_WALL_CAP_MS, pageClockWindow, watchStill, watchWebStill, noEffectTries };
@@ -15,6 +15,24 @@ import path from 'node:path';
15
15
  /** The heading the explanation is written under in report.md. */
16
16
  export const THIN_RUN_HEADING = '## Why this run was short';
17
17
 
18
+ /**
19
+ * The heading for a run that played to its budget and was still billed as a thin run: it was not short, and report.md does not
20
+ * say it was (the paid local run of 2026-11-20 played 39 of its 40 actions and was written up as "stopped early").
21
+ */
22
+ export const PLAYED_HEADING = '## How this run was billed';
23
+
24
+ /**
25
+ * The server's sentence for a run that played to its budget, without "stopped early": the one thing the CLI knows better than
26
+ * the server's words is how its own play ended (its action and model budget, with the report reserve). Everything else, the
27
+ * money above all, is the server's, word for word.
28
+ *
29
+ * @param {string} why
30
+ * @returns {string}
31
+ */
32
+ export function playedWhy(why) {
33
+ return String(why || '').replace(/\bstopped early after (\d+ actions?)\b/g, 'played to its budget ($1)').replace(/\bstopped early\b/g, 'played to its budget');
34
+ }
35
+
18
36
  /**
19
37
  * The capability notes a `complete` may carry: what the playtester could not
20
38
  * read or press, as `{ input, reason }`. The server bounds them again and only
@@ -35,12 +53,13 @@ export function capabilityNotesBody(outcome) {
35
53
  * The server's thin run record, when the answer carries one with words in it.
36
54
  *
37
55
  * @param {any} record `run.thin_run`, or one entry of `thin_runs`
56
+ * @param {{played?: boolean}} [options] played: this run played to its budget (./intent.js playedToBudget)
38
57
  * @returns {{why: string, next: string, money: string|null, limited: boolean}|null}
39
58
  */
40
- export function thinRunOf(record) {
59
+ export function thinRunOf(record, { played = false } = {}) {
41
60
  if (!record || typeof record.why !== 'string' || !record.why) return null;
42
61
  return {
43
- why: record.why,
62
+ why: played ? playedWhy(record.why) : record.why,
44
63
  next: typeof record.next === 'string' ? record.next : '',
45
64
  money: typeof record.money === 'string' && record.money ? record.money : null,
46
65
  limited: record.limited === true
@@ -51,24 +70,27 @@ export function thinRunOf(record) {
51
70
  * The lines a thin run prints: why, what to try, then the money.
52
71
  *
53
72
  * @param {any} record
73
+ * @param {{played?: boolean}} [options]
54
74
  * @returns {Array<string>} empty when the run is not a thin run
55
75
  */
56
- export function thinRunLines(record) {
57
- const thin = thinRunOf(record);
76
+ export function thinRunLines(record, options = {}) {
77
+ const thin = thinRunOf(record, options);
58
78
  if (!thin) return [];
59
79
  return [thin.why, thin.next, thin.money].filter(Boolean);
60
80
  }
61
81
 
62
82
  /**
63
- * The section report.md gets, so the report itself says why it is short.
83
+ * The section report.md gets, so the report itself says why it is short, or, for a run that played to its budget, how it
84
+ * was billed.
64
85
  *
65
86
  * @param {any} record
87
+ * @param {{played?: boolean}} [options]
66
88
  * @returns {string} '' when the run is not a thin run
67
89
  */
68
- export function thinRunSection(record) {
69
- const lines = thinRunLines(record);
90
+ export function thinRunSection(record, options = {}) {
91
+ const lines = thinRunLines(record, options);
70
92
  if (lines.length === 0) return '';
71
- return `${THIN_RUN_HEADING}\n\n${lines.join('\n\n')}\n`;
93
+ return `${options.played ? PLAYED_HEADING : THIN_RUN_HEADING}\n\n${lines.join('\n\n')}\n`;
72
94
  }
73
95
 
74
96
  /**
@@ -79,10 +101,11 @@ export function thinRunSection(record) {
79
101
  *
80
102
  * @param {string} directory the run directory
81
103
  * @param {any} record
104
+ * @param {{played?: boolean}} [options]
82
105
  * @returns {Promise<boolean>} whether the section was written
83
106
  */
84
- export async function writeThinRunSection(directory, record) {
85
- const section = thinRunSection(record);
107
+ export async function writeThinRunSection(directory, record, options = {}) {
108
+ const section = thinRunSection(record, options);
86
109
  if (!section || !directory) return false;
87
110
  const file = path.join(directory, 'report.md');
88
111
  try {
@@ -92,7 +115,8 @@ export async function writeThinRunSection(directory, record) {
92
115
  } catch (error) {
93
116
  if (!error || error.code !== 'ENOENT') throw error;
94
117
  }
95
- const at = text.indexOf(THIN_RUN_HEADING);
118
+ const found = [THIN_RUN_HEADING, PLAYED_HEADING].map(heading => text.indexOf(heading)).filter(index => index !== -1);
119
+ const at = found.length > 0 ? Math.min(...found) : -1;
96
120
  const kept = (at === -1 ? text : text.slice(0, at)).replace(/\s+$/, '');
97
121
  await fs.writeFile(file, `${kept}${kept ? '\n\n' : ''}${section}`);
98
122
  return true;