ravensight-playtest 0.8.3 → 0.10.0
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/README.md +280 -66
- package/addons/ravensight_driver/driver.gd +666 -21
- package/docs/ADAPTERS.md +11 -7
- package/docs/NATIVE_RUNNER.md +3 -1
- package/docs/godot-driver.md +127 -13
- package/package.json +8 -6
- package/src/api/client.js +4 -3
- package/src/cli.js +84 -25
- package/src/commands/check.js +30 -4
- package/src/commands/fakeCore.js +1 -0
- package/src/commands/hosted.js +41 -12
- package/src/commands/init.js +17 -1
- package/src/commands/run.js +209 -14
- package/src/commands/upload.js +6 -2
- package/src/commands/validate.js +1 -1
- package/src/commands/validateHosted.js +50 -5
- package/src/config.js +33 -2
- package/src/hosted/archivePreflight.js +7 -7
- package/src/hosted/buildUpload.js +89 -8
- package/src/hosted/recordedRun.js +141 -26
- package/src/hosted/status.js +19 -10
- package/src/run/actionSelector.js +14 -3
- package/src/run/aggregate.js +57 -3
- package/src/run/anygame/controlbook.js +179 -0
- package/src/run/anygame/genre.js +179 -0
- package/src/run/anygame/index.js +258 -0
- package/src/run/anygame/language.js +336 -0
- package/src/run/anygame/memory.js +330 -0
- package/src/run/anygame/shared-hashes.json +10 -0
- package/src/run/anygame/shared.js +24 -0
- package/src/run/anygame/sound.js +342 -0
- package/src/run/args.js +75 -8
- package/src/run/choiceCheck.js +312 -0
- package/src/run/context.js +254 -13
- package/src/run/drivers/godot-observation.js +93 -6
- package/src/run/drivers/godot.js +769 -46
- package/src/run/drivers/recording.js +24 -4
- package/src/run/drivers/web.js +1242 -77
- package/src/run/edgePass.js +731 -0
- package/src/run/fixLoop.js +5 -4
- package/src/run/focus.js +65 -0
- package/src/run/gamepad.js +108 -0
- package/src/run/godotEdgePass.js +235 -0
- package/src/run/godotTesterProbes.js +192 -0
- package/src/run/headings.js +21 -0
- package/src/run/honesty.js +544 -0
- package/src/run/inputs.js +256 -0
- package/src/run/marks.js +142 -0
- package/src/run/personaLoop.js +1000 -79
- package/src/run/phone.js +7 -0
- package/src/run/pixels.js +215 -0
- package/src/run/playClock.js +162 -0
- package/src/run/readiness.js +585 -0
- package/src/run/refusal.js +67 -0
- package/src/run/regions.js +119 -0
- package/src/run/report.js +14 -2
- package/src/run/reportChecks.js +472 -0
- package/src/run/resume.js +3 -2
- package/src/run/screenshots.js +161 -0
- package/src/run/strip.js +114 -0
- package/src/run/testerLedger.js +312 -0
- package/src/run/testerProbes.js +584 -0
- package/src/run/thinRun.js +102 -0
- package/src/run/timeFreeze.js +79 -0
- package/src/run/tools.js +454 -29
- package/src/runDefaults.js +24 -2
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
// Places worth clicking on a canvas game, measured from the screenshot alone.
|
|
2
|
+
//
|
|
3
|
+
// Ported from the cloud runner. A canvas game has no DOM controls, so the
|
|
4
|
+
// persona used to aim every click by reading pixel coordinates off a picture.
|
|
5
|
+
// This finds the shapes drawn on the screen (anything that stands out from
|
|
6
|
+
// the most common colour, with nearby marks joined), drops letterbox bars and
|
|
7
|
+
// full-screen art, and names what is left by size and position: "an outlined
|
|
8
|
+
// box, maybe a button, in the centre (640,360)". No text is read from the image.
|
|
9
|
+
|
|
10
|
+
export const MAX_REGIONS = 8;
|
|
11
|
+
const TOLERANCE = 24;
|
|
12
|
+
// Marks this many blocks apart still join one shape (letters of one word, a button's outline).
|
|
13
|
+
const JOIN = 2;
|
|
14
|
+
|
|
15
|
+
/** Where on the screen a point is, in words. */
|
|
16
|
+
export function placeName(x, y, { width, height }) {
|
|
17
|
+
const h = x < width / 3 ? 'left' : x > (2 * width) / 3 ? 'right' : 'centre';
|
|
18
|
+
const v = y < height / 3 ? 'upper' : y > (2 * height) / 3 ? 'lower' : '';
|
|
19
|
+
if (!v) return h === 'centre' ? 'the centre' : `the ${h} middle`;
|
|
20
|
+
return `the ${v} ${h}`;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Shapes on the screen from a fingerprint (./pixels.js), at most `max`:
|
|
25
|
+
* `[{ x, y, width, height, field, label }]`, centre points in the
|
|
26
|
+
* fingerprint's own pixels. An empty wide box comes first (`field: true`,
|
|
27
|
+
* likely a text field), then button sized boxes, then the rest by size.
|
|
28
|
+
*
|
|
29
|
+
* @param {{cols: number, rows: number, block: number, width: number, height: number, rgb: Uint8Array}|null} fp
|
|
30
|
+
* @param {{max?: number}} [options]
|
|
31
|
+
* @returns {Array<{x: number, y: number, width: number, height: number, field: boolean, label: string}>}
|
|
32
|
+
*/
|
|
33
|
+
export function findRegions(fp, { max = MAX_REGIONS } = {}) {
|
|
34
|
+
if (!fp) return [];
|
|
35
|
+
const { cols, rows, block, rgb, width, height } = fp;
|
|
36
|
+
const counts = new Map();
|
|
37
|
+
for (let c = 0; c < cols * rows; c += 1) {
|
|
38
|
+
const key = ((rgb[c * 3] >> 4) << 8) | ((rgb[c * 3 + 1] >> 4) << 4) | (rgb[c * 3 + 2] >> 4);
|
|
39
|
+
counts.set(key, (counts.get(key) || 0) + 1);
|
|
40
|
+
}
|
|
41
|
+
let top = 0;
|
|
42
|
+
let topN = -1;
|
|
43
|
+
for (const [k, n] of counts) if (n > topN) { top = k; topN = n; }
|
|
44
|
+
const dom = [((top >> 8) & 15) * 16 + 8, ((top >> 4) & 15) * 16 + 8, (top & 15) * 16 + 8];
|
|
45
|
+
const mask = new Uint8Array(cols * rows);
|
|
46
|
+
for (let c = 0; c < cols * rows; c += 1) {
|
|
47
|
+
const i = c * 3;
|
|
48
|
+
if (Math.abs(rgb[i] - dom[0]) > TOLERANCE || Math.abs(rgb[i + 1] - dom[1]) > TOLERANCE || Math.abs(rgb[i + 2] - dom[2]) > TOLERANCE) mask[c] = 1;
|
|
49
|
+
}
|
|
50
|
+
const seen = new Uint8Array(cols * rows);
|
|
51
|
+
const shapes = [];
|
|
52
|
+
for (let start = 0; start < cols * rows; start += 1) {
|
|
53
|
+
if (!mask[start] || seen[start]) continue;
|
|
54
|
+
const stack = [start];
|
|
55
|
+
seen[start] = 1;
|
|
56
|
+
let n = 0;
|
|
57
|
+
let x0 = Infinity;
|
|
58
|
+
let y0 = Infinity;
|
|
59
|
+
let x1 = -1;
|
|
60
|
+
let y1 = -1;
|
|
61
|
+
while (stack.length) {
|
|
62
|
+
const c = stack.pop();
|
|
63
|
+
const cx = c % cols;
|
|
64
|
+
const cy = (c / cols) | 0;
|
|
65
|
+
n += 1;
|
|
66
|
+
if (cx < x0) x0 = cx;
|
|
67
|
+
if (cx > x1) x1 = cx;
|
|
68
|
+
if (cy < y0) y0 = cy;
|
|
69
|
+
if (cy > y1) y1 = cy;
|
|
70
|
+
for (let dy = -JOIN; dy <= JOIN; dy += 1) {
|
|
71
|
+
const ny = cy + dy;
|
|
72
|
+
if (ny < 0 || ny >= rows) continue;
|
|
73
|
+
for (let dx = -JOIN; dx <= JOIN; dx += 1) {
|
|
74
|
+
const nx = cx + dx;
|
|
75
|
+
if (nx < 0 || nx >= cols) continue;
|
|
76
|
+
const nc = ny * cols + nx;
|
|
77
|
+
if (mask[nc] && !seen[nc]) { seen[nc] = 1; stack.push(nc); }
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
const w = (x1 - x0 + 1) * block;
|
|
82
|
+
const h = (y1 - y0 + 1) * block;
|
|
83
|
+
// Letterbox bars and full-screen art are not something to click; specks are noise.
|
|
84
|
+
if (w >= 0.9 * width || h >= 0.9 * height || w * h > 0.4 * width * height) continue;
|
|
85
|
+
if (w < 16 || h < 12 || n < 6) continue;
|
|
86
|
+
// How much of the inside (two blocks in from the edge) is drawn: an outlined, empty box is near 0.
|
|
87
|
+
let inner = 0;
|
|
88
|
+
let innerN = 0;
|
|
89
|
+
for (let y = y0 + 2; y <= y1 - 2; y += 1) for (let x = x0 + 2; x <= x1 - 2; x += 1) { innerN += 1; inner += mask[y * cols + x]; }
|
|
90
|
+
const fill = innerN ? inner / innerN : 1;
|
|
91
|
+
// How much of each side (a band two blocks deep) is drawn: a closed outline has all four.
|
|
92
|
+
const band = (xa, xb, ya, yb, alongX) => {
|
|
93
|
+
let hit = 0;
|
|
94
|
+
let len = 0;
|
|
95
|
+
if (alongX) for (let x = xa; x <= xb; x += 1) { len += 1; let any = 0; for (let y = ya; y <= yb; y += 1) any |= mask[y * cols + x]; hit += any; }
|
|
96
|
+
else for (let y = ya; y <= yb; y += 1) { len += 1; let any = 0; for (let x = xa; x <= xb; x += 1) any |= mask[y * cols + x]; hit += any; }
|
|
97
|
+
return len ? hit / len : 0;
|
|
98
|
+
};
|
|
99
|
+
const sides = Math.min(band(x0, x1, y0, Math.min(y1, y0 + 1), true), band(x0, x1, Math.max(y0, y1 - 1), y1, true), band(x0, Math.min(x1, x0 + 1), y0, y1, false), band(Math.max(x0, x1 - 1), x1, y0, y1, false));
|
|
100
|
+
const boxed = sides >= 0.7;
|
|
101
|
+
shapes.push({ x0: x0 * block, y0: y0 * block, x1: (x1 + 1) * block, y1: (y1 + 1) * block, width: w, height: h, fill, boxed, outlined: boxed && innerN > 0 && fill < 0.6, button: boxed && w >= 40 && w <= 600 && h >= 20 && h <= 200 });
|
|
102
|
+
}
|
|
103
|
+
// A shape inside another (a button's label inside its outline) is reached through the outer one.
|
|
104
|
+
const outer = shapes.filter(s => !shapes.some(o => o !== s && o.x0 <= s.x0 && o.y0 <= s.y0 && o.x1 >= s.x1 && o.y1 >= s.y1 && o.width * o.height > s.width * s.height));
|
|
105
|
+
for (const s of outer) s.field = s.outlined && s.width >= 4 * s.height && s.width >= 120 && s.width <= 0.75 * width && s.height >= 20 && s.height <= 120 && s.fill <= 0.2;
|
|
106
|
+
outer.sort((a, b) => (b.field - a.field) || (b.button - a.button) || (b.width * b.height - a.width * a.height));
|
|
107
|
+
return outer.slice(0, max).map(s => {
|
|
108
|
+
const x = Math.min(width - 1, Math.round((s.x0 + s.x1) / 2));
|
|
109
|
+
const y = Math.min(height - 1, Math.round((s.y0 + s.y1) / 2));
|
|
110
|
+
const size = s.width * s.height >= 30000 ? 'large ' : s.width * s.height < 4000 ? 'small ' : '';
|
|
111
|
+
const kind = s.field ? 'an empty wide box, likely a text field,'
|
|
112
|
+
: s.button ? `${size ? `a ${size}` : s.outlined ? 'an ' : 'a '}${s.outlined ? 'outlined' : 'filled'} box, maybe a button,`
|
|
113
|
+
: s.boxed && s.width > 600 ? 'a large panel'
|
|
114
|
+
: s.width >= 3 * s.height ? 'a wide drawn shape' : s.height >= 2 * s.width ? 'a tall drawn shape' : 'a drawn shape';
|
|
115
|
+
return { x, y, width: s.width, height: s.height, field: Boolean(s.field), label: `${kind} in ${placeName(x, y, { width, height })} (${x},${y})` };
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export default { findRegions, placeName };
|
package/src/run/report.js
CHANGED
|
@@ -177,10 +177,22 @@ export function stampReport(report, facts) {
|
|
|
177
177
|
//
|
|
178
178
|
// The one thing the runner cannot know is whether a persona that chose to stop
|
|
179
179
|
// had finished what it came for, so the model's own `goal_reached` stands over a
|
|
180
|
-
// plain `persona_quit`.
|
|
181
|
-
//
|
|
180
|
+
// plain `persona_quit`. A validation's completion measure reads the difference,
|
|
181
|
+
// and so does the price of a short run: a persona that reached the goal in a few
|
|
182
|
+
// actions finished the game and is a full run, where one that only stopped is
|
|
183
|
+
// billed at what it cost (the server decides; see `goal_reached` below).
|
|
182
184
|
const reachedGoal = facts.quitReason === 'persona_quit' && stamped.quit_reason === 'goal_reached';
|
|
183
185
|
if (facts.quitReason && !reachedGoal) stamped.quit_reason = facts.quitReason;
|
|
186
|
+
// THE REPORT'S OWN CHECK OF THE SUCCESS CRITERIA, as `data_points.goal_reached`.
|
|
187
|
+
// The runner owns it, so anything a model wrote there is dropped first. It is
|
|
188
|
+
// true only when the persona stopped by itself (nothing cut it off) and the
|
|
189
|
+
// report, which is written against the brief's success criteria, says the goal
|
|
190
|
+
// was reached. Written only when the server's report schema has the field.
|
|
191
|
+
const points = stamped.data_points && typeof stamped.data_points === 'object' && !Array.isArray(stamped.data_points) ? { ...stamped.data_points } : null;
|
|
192
|
+
if (points) delete points.goal_reached;
|
|
193
|
+
if (reachedGoal && facts.goalCheck === true) stamped.data_points = { ...(points || {}), goal_reached: true };
|
|
194
|
+
else if (points && Object.keys(points).length > 0) stamped.data_points = points;
|
|
195
|
+
else delete stamped.data_points;
|
|
184
196
|
// Why it stopped, in the runner's words rather than the model's guess: the
|
|
185
197
|
// action budget ran out, the screen stopped changing, the proxy cut it off.
|
|
186
198
|
if (facts.quitDetail) stamped.quit_detail = facts.quitDetail;
|
|
@@ -0,0 +1,472 @@
|
|
|
1
|
+
// What a local run records for the evidence report in the dashboard, beyond
|
|
2
|
+
// its inputs: a mood with each action, a screen id for each observation, a
|
|
3
|
+
// frame cut from the session video for each finding, and a replay of the
|
|
4
|
+
// findings' recorded inputs (Godot lockstep runs, by state hash, no model).
|
|
5
|
+
//
|
|
6
|
+
// Everything here writes plain lines into transcript.jsonl (the step log) or
|
|
7
|
+
// a JPEG under screenshots/. None of it can fail a run: a frame that cannot
|
|
8
|
+
// be cut and a replay that cannot run are recorded as not made, with the
|
|
9
|
+
// reason, and are never counted as passed.
|
|
10
|
+
import { execFile } from 'node:child_process';
|
|
11
|
+
import { mkdir, readFile, rm, stat } from 'node:fs/promises';
|
|
12
|
+
import path from 'node:path';
|
|
13
|
+
|
|
14
|
+
import { detectFfmpeg } from '../detect.js';
|
|
15
|
+
import { replayTrace } from './replay.js';
|
|
16
|
+
import { TRACE_FILE, parseTrace } from './trace.js';
|
|
17
|
+
|
|
18
|
+
/* ------------------------------------------------------------------- mood */
|
|
19
|
+
|
|
20
|
+
/** The tool input field a persona states its mood in: a word and 1 to 5. */
|
|
21
|
+
export const mood = {
|
|
22
|
+
type: 'string',
|
|
23
|
+
description: 'How you feel right now as this persona: one lowercase word and a number from 1 (barely) to 5 (strongly), such as "curious 3" or "frustrated 4". A feeling, not a fact about the game.'
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* A stated mood as `{ tag, intensity }`, or null when it is not one word of
|
|
28
|
+
* letters (the number is 3 when it is missing or out of range).
|
|
29
|
+
*
|
|
30
|
+
* @param {Object} input a tool input
|
|
31
|
+
* @returns {{tag: string, intensity: number}|null}
|
|
32
|
+
*/
|
|
33
|
+
export function moodOf(input) {
|
|
34
|
+
const raw = input && typeof input.mood === 'string' ? input.mood.trim().toLowerCase() : '';
|
|
35
|
+
const match = raw.match(/^([a-z]{2,20})(?:[\s,:]+([1-5]))?\b/);
|
|
36
|
+
if (!match) return null;
|
|
37
|
+
return { tag: match[1], intensity: match[2] ? Number(match[2]) : 3 };
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/* ---------------------------------------------------------------- screens */
|
|
41
|
+
|
|
42
|
+
const GENERIC = new Set(['ui', 'screens', 'center', 'centre', 'margin', 'column', 'row', 'root', 'main', 'control', 'canvaslayer', 'menu', 'vbox', 'hbox', 'panel', 'container', 'content', 'body', 'layout']);
|
|
43
|
+
|
|
44
|
+
function nameFromPath(nodePath) {
|
|
45
|
+
const parts = String(nodePath).split('/').filter(Boolean);
|
|
46
|
+
const i = parts.findIndex(part => /^screens?$/i.test(part));
|
|
47
|
+
if (i >= 0 && parts[i + 1]) return parts[i + 1];
|
|
48
|
+
return parts.find(part => !GENERIC.has(part.toLowerCase())) || parts.at(-1) || 'Screen';
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** A Godot scene outline as `{ id, name, by: 'outline' }`, or null. */
|
|
52
|
+
function outlineScreen(text) {
|
|
53
|
+
const scene = (text.match(/^scene:\s*(\S+)/m) || [])[1];
|
|
54
|
+
const start = text.indexOf('Window root');
|
|
55
|
+
if (!scene && start < 0) return null;
|
|
56
|
+
const nodes = (start >= 0 ? text.slice(start).split('\n').slice(1) : []).map(line => {
|
|
57
|
+
const match = line.match(/^(\s*)(\w+)\s+(\S+)/);
|
|
58
|
+
return match ? { depth: match[1].length, path: match[3] } : null;
|
|
59
|
+
}).filter(Boolean);
|
|
60
|
+
const sceneName = (scene || '').split('/').pop().replace(/\.tscn$/, '');
|
|
61
|
+
if (nodes.length === 0) return scene ? { id: scene, name: sceneName, by: 'outline' } : null;
|
|
62
|
+
const top = Math.min(...nodes.map(node => node.depth));
|
|
63
|
+
const second = nodes.filter(node => node.depth > top).reduce((least, node) => Math.min(least, node.depth), Infinity);
|
|
64
|
+
const children = [...new Set(nodes.filter(node => node.depth === second).map(node => node.path.replace(/\d+$/, '')))];
|
|
65
|
+
const names = [...new Set(children.map(nameFromPath))];
|
|
66
|
+
return { id: `${scene || ''}|${children.join(',')}`.slice(0, 300), name: (names.length ? names.slice(0, 2).join(' + ') : sceneName || 'Screen').slice(0, 60), by: 'outline' };
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** A web page's outline as `{ id, name, by: 'route' }` (its path, then its open dialog or first heading), or null. */
|
|
70
|
+
function pageScreen(text, url) {
|
|
71
|
+
if (!/^\s*- \w+/m.test(text)) return null;
|
|
72
|
+
const dialog = (text.match(/^\s*- (?:dialog|alertdialog) "([^"]+)"/m) || [])[1];
|
|
73
|
+
const headings = [...text.matchAll(/^\s*- heading "([^"]+)"(?: \[level=(\d)\])?/gm)].map(match => ({ text: match[1], level: Number(match[2] || 9) }));
|
|
74
|
+
const first = headings.slice().sort((a, b) => a.level - b.level)[0];
|
|
75
|
+
if (!first && !dialog) return null;
|
|
76
|
+
let route = '';
|
|
77
|
+
try { const parsed = new URL(String(url)); route = `${parsed.pathname}${parsed.hash}`; } catch { route = ''; }
|
|
78
|
+
return { id: `${route}|${dialog || ''}|${headings.slice(0, 3).map(heading => heading.text).join('|')}`.slice(0, 300), name: (dialog ? `${dialog} (dialog)` : first.text).slice(0, 60), by: 'route' };
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* The screen an observation shows, told from what the persona itself read: a
|
|
83
|
+
* Godot scene and its top container, or a web page's path and first heading.
|
|
84
|
+
* Null when the observation has neither (a game drawn on a canvas): the
|
|
85
|
+
* report then groups such a run's screenshots by how alike they look.
|
|
86
|
+
*
|
|
87
|
+
* @param {string} text the observation's text
|
|
88
|
+
* @param {string} [url]
|
|
89
|
+
* @returns {{id: string, name: string, by: 'outline'|'route'}|null}
|
|
90
|
+
*/
|
|
91
|
+
export function screenOf(text, url) {
|
|
92
|
+
const source = String(text || '');
|
|
93
|
+
return outlineScreen(source) || pageScreen(source, url);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/* ----------------------------------------------------------------- frames */
|
|
97
|
+
|
|
98
|
+
/** The frame is taken this long after the finding's moment, so the result of the input is on screen. */
|
|
99
|
+
export const FRAME_AFTER_MS = 600;
|
|
100
|
+
export const FRAME_WIDTH = 960;
|
|
101
|
+
export const FRAME_TIMEOUT_MS = 20000;
|
|
102
|
+
/** Frames cut for one run at most. */
|
|
103
|
+
export const MAX_FRAMES = 20;
|
|
104
|
+
|
|
105
|
+
/** The run-relative path of a finding's frame. */
|
|
106
|
+
export const framePath = id => `screenshots/frame-${String(id).replace(/[^A-Za-z0-9_-]/g, '')}.jpg`;
|
|
107
|
+
|
|
108
|
+
const TOOL_ENV = Object.freeze({ PATH: process.env.PATH || '', LANG: 'C.UTF-8' });
|
|
109
|
+
|
|
110
|
+
function runTool(file, args, { exec = execFile, timeout = FRAME_TIMEOUT_MS } = {}) {
|
|
111
|
+
return new Promise(resolve => {
|
|
112
|
+
try { exec(file, args, { timeout, env: TOOL_ENV, windowsHide: true, maxBuffer: 1024 * 1024 }, error => resolve(!error)); } catch { resolve(false); }
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const sized = async file => (await stat(file).then(info => info.size, () => 0)) > 0;
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Cut one frame of a video into a JPEG. True when the file was written.
|
|
120
|
+
*
|
|
121
|
+
* @param {Object} args
|
|
122
|
+
* @returns {Promise<boolean>}
|
|
123
|
+
*/
|
|
124
|
+
export async function cutFrame({ ffmpeg, video, atMs, out, width = FRAME_WIDTH, exec = execFile }) {
|
|
125
|
+
if (!ffmpeg || !(await sized(video))) return false;
|
|
126
|
+
await mkdir(path.dirname(out), { recursive: true });
|
|
127
|
+
await rm(out, { force: true });
|
|
128
|
+
const ok = await runTool(ffmpeg, ['-hide_banner', '-loglevel', 'error', '-nostdin', '-y', '-ss', (Math.max(0, atMs) / 1000).toFixed(3), '-i', video, '-frames:v', '1', '-vf', `scale=${width}:-2`, '-q:v', '5', '-f', 'image2', out], { exec });
|
|
129
|
+
if (ok && await sized(out)) return true;
|
|
130
|
+
await rm(out, { force: true });
|
|
131
|
+
return false;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* A frame for each finding the run can place in its video, cut at the
|
|
136
|
+
* finding's own moment and written as a `finding_frame` line of the step log.
|
|
137
|
+
* A finding with no video time, or whose frame cannot be cut, gets no line:
|
|
138
|
+
* the report then shows the screenshot it cites.
|
|
139
|
+
*
|
|
140
|
+
* @param {Object} args
|
|
141
|
+
* @param {string} args.runDirectory
|
|
142
|
+
* @param {Array<{id: string, action: number|null, video_ms: number|null}>} args.index where each finding is (honesty.js)
|
|
143
|
+
* @param {{file?: string, durationMs?: number}|null} args.video
|
|
144
|
+
* @param {{write: Function}} args.transcript
|
|
145
|
+
* @param {{width: number, height: number}|null} [args.viewport] the size of the view the inputs were made in
|
|
146
|
+
* @returns {Promise<Map<string, {path: string, video_ms: number}>>}
|
|
147
|
+
*/
|
|
148
|
+
export async function cutFindingFrames({ runDirectory, index = [], video = null, transcript, viewport = null, detect = detectFfmpeg, cut = cutFrame }) {
|
|
149
|
+
const frames = new Map();
|
|
150
|
+
const wanted = index.filter(entry => entry && typeof entry.id === 'string' && Number.isFinite(entry.video_ms)).slice(0, MAX_FRAMES);
|
|
151
|
+
if (!video || !video.file || wanted.length === 0) return frames;
|
|
152
|
+
let ffmpeg = null;
|
|
153
|
+
try { ffmpeg = (await detect())?.path || null; } catch { ffmpeg = null; }
|
|
154
|
+
if (!ffmpeg) {
|
|
155
|
+
transcript.write({ kind: 'finding_frames_skipped', reason: 'ffmpeg was not found, so no frame was cut from the video' });
|
|
156
|
+
return frames;
|
|
157
|
+
}
|
|
158
|
+
const file = path.join(runDirectory, video.file);
|
|
159
|
+
const end = Number.isFinite(video.durationMs) && video.durationMs > 0 ? Math.max(0, video.durationMs - 200) : Infinity;
|
|
160
|
+
for (const entry of wanted) {
|
|
161
|
+
const at = Math.round(Math.min(entry.video_ms + FRAME_AFTER_MS, end));
|
|
162
|
+
const relative = framePath(entry.id);
|
|
163
|
+
let ok = false;
|
|
164
|
+
try { ok = await cut({ ffmpeg, video: file, atMs: at, out: path.join(runDirectory, relative) }); } catch { ok = false; }
|
|
165
|
+
if (!ok) continue;
|
|
166
|
+
frames.set(entry.id, { path: relative, video_ms: at });
|
|
167
|
+
transcript.write({ kind: 'finding_frame', id: entry.id, path: relative, source: 'video', video_ms: at, ...(Number.isInteger(entry.action) ? { action: entry.action } : {}), ...(viewport && viewport.width > 0 && viewport.height > 0 ? { viewport: { width: viewport.width, height: viewport.height } } : {}) });
|
|
168
|
+
}
|
|
169
|
+
return frames;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/* ----------------------------------------------------------------- replay */
|
|
173
|
+
|
|
174
|
+
/** Findings a replay looks at, the most severe first. */
|
|
175
|
+
export const MAX_REPLAY_FINDINGS = 3;
|
|
176
|
+
export const REPLAY_RUNS = 2;
|
|
177
|
+
/** A replay takes at most a quarter of the play time, at least the floor and never more than two minutes. */
|
|
178
|
+
export const REPLAY_SHARE = 0.25;
|
|
179
|
+
export const REPLAY_FLOOR_MS = 20000;
|
|
180
|
+
export const REPLAY_MAX_MS = 120000;
|
|
181
|
+
|
|
182
|
+
const SEVERITY_ORDER = ['blocker', 'major', 'minor', 'cosmetic'];
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* The findings to replay: issues the run tied to a played input that the
|
|
186
|
+
* trace holds, the most severe first, at most three.
|
|
187
|
+
*
|
|
188
|
+
* @param {Object} report
|
|
189
|
+
* @param {Array<{id: string, action: number|null}>} index
|
|
190
|
+
* @param {Map<number, number>} traceSteps trace steps written by the end of each action
|
|
191
|
+
* @returns {Array<{id: string, action: number, trace_steps: number}>}
|
|
192
|
+
*/
|
|
193
|
+
export function replayTargets(report, index = [], traceSteps = new Map(), max = MAX_REPLAY_FINDINGS) {
|
|
194
|
+
const where = new Map(index.map(entry => [entry.id, entry]));
|
|
195
|
+
const issues = (report && Array.isArray(report.findings) ? report.findings : [])
|
|
196
|
+
.filter(finding => finding && SEVERITY_ORDER.includes(finding.severity))
|
|
197
|
+
.sort((a, b) => SEVERITY_ORDER.indexOf(a.severity) - SEVERITY_ORDER.indexOf(b.severity));
|
|
198
|
+
const out = [];
|
|
199
|
+
for (const finding of issues) {
|
|
200
|
+
const action = where.get(finding.id)?.action;
|
|
201
|
+
const steps = Number.isInteger(action) ? traceSteps.get(action) : undefined;
|
|
202
|
+
if (!Number.isInteger(steps) || steps < 1) continue;
|
|
203
|
+
out.push({ id: finding.id, action, trace_steps: steps });
|
|
204
|
+
if (out.length >= max) break;
|
|
205
|
+
}
|
|
206
|
+
return out;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/** The first `steps` steps of a trace, as trace text a replay reads. */
|
|
210
|
+
export function tracePrefix(text, steps) {
|
|
211
|
+
const lines = [];
|
|
212
|
+
let kept = 0;
|
|
213
|
+
for (const line of String(text).split('\n')) {
|
|
214
|
+
if (!line.trim()) continue;
|
|
215
|
+
let entry;
|
|
216
|
+
try { entry = JSON.parse(line); } catch { continue; }
|
|
217
|
+
if (entry.type === 'step') { if (kept >= steps) continue; kept += 1; }
|
|
218
|
+
if (entry.type === 'end' || entry.type === 'truncated') continue;
|
|
219
|
+
lines.push(line);
|
|
220
|
+
}
|
|
221
|
+
return `${lines.join('\n')}\n`;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/** How long the replay may take for a session that played for `playMs`. */
|
|
225
|
+
export function replayBudget(playMs) {
|
|
226
|
+
const played = Number.isFinite(playMs) && playMs > 0 ? playMs : 0;
|
|
227
|
+
return Math.min(Math.max(Math.round(played * REPLAY_SHARE), REPLAY_FLOOR_MS), REPLAY_MAX_MS);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Replay the findings' recorded inputs and write the result of each into the
|
|
232
|
+
* step log as `replay_check` lines, with one `replay_pass` line for the pass.
|
|
233
|
+
*
|
|
234
|
+
* A Godot lockstep run records every input and a state hash after each. The
|
|
235
|
+
* inputs up to the last finding's step are played again on the same project
|
|
236
|
+
* with no model, twice when the time allows. A finding whose step came back
|
|
237
|
+
* with the same hashes each time is `reproduced`; one a replay parted from
|
|
238
|
+
* before reaching is `diverged` (the game is not the same twice from the same
|
|
239
|
+
* inputs); one the replay never reached is `not_run`. Any other run has no
|
|
240
|
+
* hashes to compare and says `not_possible`.
|
|
241
|
+
*
|
|
242
|
+
* @param {Object} args
|
|
243
|
+
* @returns {Promise<{ran: boolean, runs: number, skipped: string|null, results: Array<Object>}>}
|
|
244
|
+
*/
|
|
245
|
+
/**
|
|
246
|
+
* What a replay says when its game started in a different state: it checks
|
|
247
|
+
* nothing, so it is never evidence against a finding, and the developer is
|
|
248
|
+
* told what makes a game start differently.
|
|
249
|
+
*/
|
|
250
|
+
export const REPLAY_START_DIFFERED = 'the game started in a different state, so this replay could not check the finding: a game starts differently when it picks its own random seed, reads the clock or the date, or reacts to window focus as it starts';
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* The capability note for a replay pass in which a game started differently
|
|
254
|
+
* (a limit of the runner, never a finding), or null.
|
|
255
|
+
*
|
|
256
|
+
* @param {{startDiffered?: boolean}|null} pass what replayFindings returned
|
|
257
|
+
* @returns {{input: string, reason: string}|null}
|
|
258
|
+
*/
|
|
259
|
+
export function replayCapabilityNote(pass) {
|
|
260
|
+
return pass && pass.startDiffered ? { input: 'replay', reason: REPLAY_START_DIFFERED } : null;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
export async function replayFindings({ report, index = [], traceSteps = new Map(), runDirectory, driver = null, playMs = 0, transcript, signal = null, replay = replayTrace, now = Date.now, runs = REPLAY_RUNS }) {
|
|
264
|
+
const issues = (report && Array.isArray(report.findings) ? report.findings : []).filter(finding => finding && SEVERITY_ORDER.includes(finding.severity));
|
|
265
|
+
const finish = (pass, results) => {
|
|
266
|
+
for (const result of results) transcript.write({ kind: 'replay_check', ...result });
|
|
267
|
+
transcript.write({ kind: 'replay_pass', ran: pass.ran, runs: pass.runs, skipped: pass.skipped, ...(Number.isFinite(pass.elapsed_ms) ? { elapsed_ms: pass.elapsed_ms } : {}) });
|
|
268
|
+
return { ...pass, results };
|
|
269
|
+
};
|
|
270
|
+
const none = (state, detail) => finish({ ran: false, runs: 0, skipped: detail }, issues.map(finding => ({ id: finding.id, state, runs: 0, of: 0, trace_steps: 0, detail })));
|
|
271
|
+
if (issues.length === 0) return finish({ ran: false, runs: 0, skipped: 'the report has no issue to replay' }, []);
|
|
272
|
+
if (!driver || !driver.projectDir || !driver.trace) return none('not_possible', 'this run has no input trace with state hashes, so its inputs cannot be played again without a model');
|
|
273
|
+
let text;
|
|
274
|
+
try { text = await readFile(path.join(runDirectory, TRACE_FILE), 'utf8'); parseTrace(text); } catch { return none('not_possible', 'the input trace of this run could not be read'); }
|
|
275
|
+
const targets = replayTargets(report, index, traceSteps);
|
|
276
|
+
const others = issues.filter(finding => !targets.some(target => target.id === finding.id));
|
|
277
|
+
const rest = others.map(finding => {
|
|
278
|
+
const tied = Number.isInteger(index.find(entry => entry.id === finding.id)?.action);
|
|
279
|
+
return { id: finding.id, state: tied && targets.length >= MAX_REPLAY_FINDINGS ? 'not_run' : 'not_possible', runs: 0, of: 0, trace_steps: 0, detail: tied && targets.length >= MAX_REPLAY_FINDINGS ? `the replay looks at the ${MAX_REPLAY_FINDINGS} most severe findings` : 'the finding is not tied to an input the trace holds' };
|
|
280
|
+
});
|
|
281
|
+
if (targets.length === 0) return finish({ ran: false, runs: 0, skipped: 'no finding is tied to an input the trace holds' }, rest);
|
|
282
|
+
const last = Math.max(...targets.map(target => target.trace_steps));
|
|
283
|
+
const prefix = tracePrefix(text, last);
|
|
284
|
+
const started = now();
|
|
285
|
+
const deadline = started + replayBudget(playMs);
|
|
286
|
+
const verdicts = new Map(targets.map(target => [target.id, []]));
|
|
287
|
+
let made = 0, problem = null, longest = 0, startDiffered = false;
|
|
288
|
+
for (let i = 0; i < runs; i++) {
|
|
289
|
+
if (i > 0 && now() + longest > deadline) break;
|
|
290
|
+
if (signal && signal.aborted) { problem = 'the run was cancelled'; break; }
|
|
291
|
+
const at = now();
|
|
292
|
+
const timer = new AbortController();
|
|
293
|
+
const stop = setTimeout(() => timer.abort(), Math.max(1000, deadline - at));
|
|
294
|
+
const onAbort = () => timer.abort();
|
|
295
|
+
if (signal) signal.addEventListener('abort', onAbort, { once: true });
|
|
296
|
+
let result;
|
|
297
|
+
try {
|
|
298
|
+
result = await replay({ text: prefix, projectDir: driver.projectDir, godotPath: driver.godotPath, headless: driver.headless, runDir: path.join(runDirectory, '.replay'), signal: timer.signal, ...(driver.env ? { env: driver.env } : {}) });
|
|
299
|
+
} catch (error) {
|
|
300
|
+
problem = timer.signal.aborted ? 'the replay ran out of its time' : `a replay could not finish (${String(error && error.message ? error.message : error).slice(0, 80)})`;
|
|
301
|
+
break;
|
|
302
|
+
} finally {
|
|
303
|
+
clearTimeout(stop);
|
|
304
|
+
if (signal) signal.removeEventListener('abort', onAbort);
|
|
305
|
+
}
|
|
306
|
+
longest = Math.max(longest, now() - at);
|
|
307
|
+
made += 1;
|
|
308
|
+
// The step the replay parted from the recording at (0 for the boot state), or none when every hash matched.
|
|
309
|
+
const parted = result.matched ? null : result.first_divergence && Number.isInteger(result.first_divergence.step) ? result.first_divergence.step : 0;
|
|
310
|
+
const stoppedAt = result.stopped === 'redacted_input' ? result.steps_compared : null;
|
|
311
|
+
// A game that did not start, or started in a different state, checks no finding:
|
|
312
|
+
// the run is set aside, never counted against one.
|
|
313
|
+
const atStart = parted === 0 ? (result.boot_failed ? 'the game did not start for the replay' : REPLAY_START_DIFFERED) : null;
|
|
314
|
+
if (atStart === REPLAY_START_DIFFERED) startDiffered = true;
|
|
315
|
+
for (const target of targets) {
|
|
316
|
+
if (atStart) verdicts.get(target.id).push({ verdict: 'start', detail: atStart });
|
|
317
|
+
else if (parted !== null && parted < target.trace_steps) verdicts.get(target.id).push({ verdict: 'diverged', detail: `a different state hash at recorded step ${parted + 1} of ${target.trace_steps}` });
|
|
318
|
+
else if (stoppedAt !== null && stoppedAt < target.trace_steps) verdicts.get(target.id).push({ verdict: 'unchecked', detail: 'the replay stops at an input that was a secret from the local brief' });
|
|
319
|
+
else verdicts.get(target.id).push({ verdict: 'match', detail: 'the same state hash came back at this step' });
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
await rm(path.join(runDirectory, '.replay'), { recursive: true, force: true }).catch(() => {});
|
|
323
|
+
const results = targets.map(target => {
|
|
324
|
+
const all = verdicts.get(target.id);
|
|
325
|
+
const usable = all.filter(entry => entry.verdict !== 'unchecked' && entry.verdict !== 'start');
|
|
326
|
+
const starts = all.filter(entry => entry.verdict === 'start');
|
|
327
|
+
const base = { id: target.id, trace_steps: target.trace_steps };
|
|
328
|
+
if (all.length === 0) return { ...base, state: 'not_run', runs: 0, of: 0, detail: problem || 'the replay ran out of its time before it started' };
|
|
329
|
+
// Every replay started differently: the finding could not be confirmed either way.
|
|
330
|
+
if (usable.length === 0 && starts.length > 0) return { ...base, state: 'diverged', runs: 0, of: 0, detail: starts[0].detail };
|
|
331
|
+
if (usable.length === 0) return { ...base, state: 'not_possible', runs: 0, of: 0, detail: all[0].detail };
|
|
332
|
+
const matched = usable.filter(entry => entry.verdict === 'match').length;
|
|
333
|
+
const detail = [...new Set([...usable, ...starts].map(entry => entry.detail))].join('; ');
|
|
334
|
+
return { ...base, state: matched === usable.length ? 'reproduced' : matched === 0 ? 'diverged' : 'not_reproduced', runs: matched, of: usable.length, detail };
|
|
335
|
+
});
|
|
336
|
+
return { ...finish({ ran: made > 0, runs: made, skipped: made > 0 ? null : problem, elapsed_ms: now() - started }, [...results, ...rest]), startDiffered };
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
/* -------------------------------------------------------------- web replay */
|
|
340
|
+
|
|
341
|
+
/**
|
|
342
|
+
* Keep a web run's inputs as it plays, so its findings can be replayed after
|
|
343
|
+
* the report: every action the driver was handed, in order, with whether the
|
|
344
|
+
* screen changed and a fingerprint of the screen that followed.
|
|
345
|
+
*
|
|
346
|
+
* The trace lives in this process only. It is never written to disk and never
|
|
347
|
+
* uploaded, because it holds the inputs as they were typed, a test account's
|
|
348
|
+
* password included; the step log has the scrubbed copy.
|
|
349
|
+
*
|
|
350
|
+
* @param {Object} driver a playwright_web driver, changed in place: `act` is wrapped and `webTrace` added
|
|
351
|
+
* @param {{fingerprint: Function}} deps
|
|
352
|
+
* @returns {Array<Object>} the trace, which grows as the run plays
|
|
353
|
+
*/
|
|
354
|
+
export function traceWebInputs(driver, { fingerprint }) {
|
|
355
|
+
const trace = [];
|
|
356
|
+
if (!driver || typeof driver.act !== 'function' || typeof driver.screenProbe !== 'function') return trace;
|
|
357
|
+
const act = driver.act.bind(driver);
|
|
358
|
+
driver.act = async action => {
|
|
359
|
+
const result = await act(action);
|
|
360
|
+
let print = null;
|
|
361
|
+
try { print = fingerprint(await driver.screenProbe()); } catch { print = null; }
|
|
362
|
+
trace.push({ action, ok: Boolean(result) && result.ok !== false && !result.refused, changed: result ? result.changed : null, print });
|
|
363
|
+
return result;
|
|
364
|
+
};
|
|
365
|
+
driver.webTrace = trace;
|
|
366
|
+
return trace;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
/**
|
|
370
|
+
* Replay a web run's findings: a fresh browser on the same target, the
|
|
371
|
+
* recorded inputs played again from launch with no model, and at each
|
|
372
|
+
* finding's input the screen compared with the one the run saw (the same
|
|
373
|
+
* "would a player notice a difference" measure the run's own change check
|
|
374
|
+
* uses). Twice when the time allows. Results are `replay_check` lines of the
|
|
375
|
+
* step log, as for a Godot run.
|
|
376
|
+
*
|
|
377
|
+
* A finding is `reproduced` when every replay showed the same screen after
|
|
378
|
+
* its input (or, for an input that changed nothing, changed nothing again),
|
|
379
|
+
* `diverged` when the replay was already on a different screen before that
|
|
380
|
+
* input, `not_reproduced` when one replay matched and one did not, and
|
|
381
|
+
* `not_run` when the replay did not reach it.
|
|
382
|
+
*
|
|
383
|
+
* @param {Object} args
|
|
384
|
+
* @returns {Promise<{ran: boolean, runs: number, skipped: string|null, results: Array<Object>}>}
|
|
385
|
+
*/
|
|
386
|
+
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 }) {
|
|
387
|
+
const issues = (report && Array.isArray(report.findings) ? report.findings : []).filter(finding => finding && SEVERITY_ORDER.includes(finding.severity));
|
|
388
|
+
const finish = (pass, results) => {
|
|
389
|
+
for (const result of results) transcript.write({ kind: 'replay_check', ...result });
|
|
390
|
+
transcript.write({ kind: 'replay_pass', ran: pass.ran, runs: pass.runs, skipped: pass.skipped, ...(Number.isFinite(pass.elapsed_ms) ? { elapsed_ms: pass.elapsed_ms } : {}) });
|
|
391
|
+
return { ...pass, results };
|
|
392
|
+
};
|
|
393
|
+
if (issues.length === 0) return finish({ ran: false, runs: 0, skipped: 'the report has no issue to replay' }, []);
|
|
394
|
+
// 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).
|
|
395
|
+
const scripted = new Set(observer && Array.isArray(observer.ids) ? observer.ids : []);
|
|
396
|
+
const targets = replayTargets({ ...report, findings: issues.filter(finding => !scripted.has(finding.id)) }, index, traceSteps).filter(entry => entry.trace_steps <= trace.length);
|
|
397
|
+
const rest = issues.filter(finding => !scripted.has(finding.id) && !targets.some(entry => entry.id === finding.id)).map(finding => {
|
|
398
|
+
const tied = Number.isInteger(index.find(entry => entry.id === finding.id)?.action);
|
|
399
|
+
const capped = tied && targets.length >= MAX_REPLAY_FINDINGS;
|
|
400
|
+
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' };
|
|
401
|
+
});
|
|
402
|
+
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);
|
|
403
|
+
// With probes to run again, the replay plays every recorded input, to the screen play ended on.
|
|
404
|
+
const last = Math.max(0, ...targets.map(entry => entry.trace_steps), scripted.size > 0 ? trace.length : 0);
|
|
405
|
+
const started = now();
|
|
406
|
+
const deadline = started + replayBudget(playMs);
|
|
407
|
+
const verdicts = new Map([...targets.map(entry => [entry.id, []]), ...[...scripted].map(id => [id, []])]);
|
|
408
|
+
const same = (a, b) => (a && b ? !differs(a, b) : null);
|
|
409
|
+
let made = 0, problem = null, longest = 0;
|
|
410
|
+
for (let i = 0; i < runs; i++) {
|
|
411
|
+
if (i > 0 && now() + longest > deadline) break;
|
|
412
|
+
if (signal && signal.aborted) { problem = 'the run was cancelled'; break; }
|
|
413
|
+
const at = now();
|
|
414
|
+
const dir = tempDir ? await tempDir() : null;
|
|
415
|
+
let driver = null;
|
|
416
|
+
try {
|
|
417
|
+
driver = await makeDriver();
|
|
418
|
+
await driver.launch({ target, runDir: dir, recordVideo: false, ...(viewport ? { viewport } : {}), ...(signal ? { signal } : {}) });
|
|
419
|
+
await driver.observe();
|
|
420
|
+
let before = null;
|
|
421
|
+
try { before = fingerprint(await driver.screenProbe()); } catch { before = null; }
|
|
422
|
+
for (let n = 0; n < last; n++) {
|
|
423
|
+
if (now() > deadline) break;
|
|
424
|
+
const entry = trace[n];
|
|
425
|
+
await driver.act(entry.action);
|
|
426
|
+
let after = null;
|
|
427
|
+
try { after = fingerprint(await driver.screenProbe()); } catch { after = null; }
|
|
428
|
+
for (const hit of targets.filter(candidate => candidate.trace_steps === n + 1)) {
|
|
429
|
+
// Where the run itself stood before this input: the screen after the input before it.
|
|
430
|
+
const was = n > 0 ? trace[n - 1].print : null;
|
|
431
|
+
const sameBefore = n > 0 ? same(before, was) : true;
|
|
432
|
+
let verdict, detail;
|
|
433
|
+
if (sameBefore === false) { verdict = 'diverged'; detail = 'the replay was on a different screen before this input'; }
|
|
434
|
+
else if (entry.changed === false) {
|
|
435
|
+
const quiet = same(before, after);
|
|
436
|
+
verdict = quiet === null ? 'unchecked' : quiet ? 'match' : 'no_match';
|
|
437
|
+
detail = quiet === null ? 'the screen could not be read to compare' : quiet ? 'the input changed nothing again' : 'the input changed the screen this time';
|
|
438
|
+
} else {
|
|
439
|
+
const again = same(after, entry.print);
|
|
440
|
+
verdict = again === null ? 'unchecked' : again ? 'match' : 'no_match';
|
|
441
|
+
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';
|
|
442
|
+
}
|
|
443
|
+
verdicts.get(hit.id).push({ verdict, detail });
|
|
444
|
+
}
|
|
445
|
+
before = after;
|
|
446
|
+
}
|
|
447
|
+
if (scripted.size > 0 && now() < deadline) {
|
|
448
|
+
const again = await observer.end(driver).catch(() => new Map());
|
|
449
|
+
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' });
|
|
450
|
+
}
|
|
451
|
+
made += 1;
|
|
452
|
+
} catch (error) {
|
|
453
|
+
problem = `a replay could not finish (${String(error && error.message ? error.message : error).split('\n')[0].slice(0, 80)})`;
|
|
454
|
+
} finally {
|
|
455
|
+
if (driver) await Promise.resolve(driver.stop({ reason: 'replay' })).catch(() => {});
|
|
456
|
+
if (dir) await rm(dir, { recursive: true, force: true }).catch(() => {});
|
|
457
|
+
}
|
|
458
|
+
if (problem) break;
|
|
459
|
+
longest = Math.max(longest, now() - at);
|
|
460
|
+
}
|
|
461
|
+
const results = [...targets, ...[...scripted].map(id => ({ id, trace_steps: trace.length }))].map(entry => {
|
|
462
|
+
const all = verdicts.get(entry.id);
|
|
463
|
+
const usable = all.filter(item => item.verdict !== 'unchecked');
|
|
464
|
+
const base = { id: entry.id, trace_steps: entry.trace_steps };
|
|
465
|
+
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') };
|
|
466
|
+
if (usable.length === 0) return { ...base, state: 'not_possible', runs: 0, of: 0, detail: all[0].detail };
|
|
467
|
+
const matched = usable.filter(item => item.verdict === 'match').length;
|
|
468
|
+
const diverged = usable.filter(item => item.verdict === 'diverged').length;
|
|
469
|
+
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('; ') };
|
|
470
|
+
});
|
|
471
|
+
return finish({ ran: made > 0, runs: made, skipped: made > 0 ? null : problem, elapsed_ms: now() - started }, [...results, ...rest]);
|
|
472
|
+
}
|
package/src/run/resume.js
CHANGED
|
@@ -189,7 +189,7 @@ export async function resumeJob({ api, gameId, jobId, job, runs, state, repoRoot
|
|
|
189
189
|
repo: { commit: '', dirty: false },
|
|
190
190
|
max_actions: (journal.options && journal.options.maxActions) ?? null,
|
|
191
191
|
// The same body as the first register, so a long job replays as long.
|
|
192
|
-
...(journal.options?.runLength === '
|
|
192
|
+
...(typeof journal.options?.runLength === 'string' && journal.options.runLength !== 'standard' ? { run_length: journal.options.runLength } : {}),
|
|
193
193
|
pack_versions: { pack: pack.pack_version }
|
|
194
194
|
}, { idempotencyKey: journal.idempotency_key });
|
|
195
195
|
|
|
@@ -208,7 +208,8 @@ export async function resumeJob({ api, gameId, jobId, job, runs, state, repoRoot
|
|
|
208
208
|
recordVideo: options.recordVideo ?? journal.options?.recordVideo,
|
|
209
209
|
maxActions: (journal.options && journal.options.maxActions) ?? options.maxActions,
|
|
210
210
|
// The journal's answer, never the flag: a job is long or standard for good.
|
|
211
|
-
runLength: journal.options?.runLength === '
|
|
211
|
+
runLength: typeof journal.options?.runLength === 'string' ? journal.options.runLength : 'standard',
|
|
212
|
+
...(Array.isArray(journal.options?.focus) ? { focus: journal.options.focus } : {}), ...(Array.isArray(journal.options?.avoid) ? { avoid: journal.options.avoid } : {}),
|
|
212
213
|
...(Number.isInteger(journal.options?.longRunFactor) ? { longRunFactor: journal.options.longRunFactor } : {}),
|
|
213
214
|
concurrency: options.concurrency ?? (journal.options && journal.options.concurrency),
|
|
214
215
|
uploadVideo: options.uploadVideo ?? (journal.options && journal.options.uploadVideo),
|