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,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether a markdown line is a given report heading.
|
|
3
|
+
*
|
|
4
|
+
* A report written for a brief in another language may carry a heading as its
|
|
5
|
+
* English words plus a translation in brackets, as the hosted runner writes it
|
|
6
|
+
* ("## What worked (うまくいったこと)"). The English words are what every
|
|
7
|
+
* reader looks a section up by, so a bracketed tail after them is accepted.
|
|
8
|
+
* Nothing else is: "## What worked well" is not "## What worked".
|
|
9
|
+
*
|
|
10
|
+
* @param {string} line
|
|
11
|
+
* @param {string} heading the heading with its hashes, such as "## What worked"
|
|
12
|
+
* @returns {boolean}
|
|
13
|
+
*/
|
|
14
|
+
export function isHeading(line, heading) {
|
|
15
|
+
const text = String(line == null ? '' : line).trim().toLowerCase();
|
|
16
|
+
const want = String(heading).trim().toLowerCase();
|
|
17
|
+
if (text === want) return true;
|
|
18
|
+
return text.startsWith(want) && /^\s*\([^()]*\)$/u.test(text.slice(want.length));
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export default { isHeading };
|
|
@@ -0,0 +1,544 @@
|
|
|
1
|
+
// What the runner itself knows to be true of a run, kept apart from what the
|
|
2
|
+
// model writes about it:
|
|
3
|
+
//
|
|
4
|
+
// - the inputs it could not send, and why (capability notes, never findings);
|
|
5
|
+
// - a crash, a freeze or a blank screen it watched happen (findings, with the
|
|
6
|
+
// steps that led there);
|
|
7
|
+
// - browser dialogs and how they were answered;
|
|
8
|
+
// - for every finding, the step it was seen at, a screenshot, and where to
|
|
9
|
+
// look in the video when one was recorded.
|
|
10
|
+
//
|
|
11
|
+
// Nothing here asks a model anything.
|
|
12
|
+
import { pngFingerprint } from './pixels.js';
|
|
13
|
+
import { missingInputs } from './inputs.js';
|
|
14
|
+
|
|
15
|
+
/* ------------------------------------------------------- capability notes */
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The inputs a run could not send, each said once.
|
|
19
|
+
*
|
|
20
|
+
* @returns {{add: (note: {input: string, reason: string}) => boolean, list: () => Array<{input: string, reason: string}>}}
|
|
21
|
+
*/
|
|
22
|
+
export function createCapabilityLedger() {
|
|
23
|
+
const notes = new Map();
|
|
24
|
+
return {
|
|
25
|
+
add(note) {
|
|
26
|
+
if (!note || !note.input || !note.reason) return false;
|
|
27
|
+
const key = String(note.input).toLowerCase();
|
|
28
|
+
if (notes.has(key)) return false;
|
|
29
|
+
notes.set(key, { input: String(note.input), reason: String(note.reason) });
|
|
30
|
+
return true;
|
|
31
|
+
},
|
|
32
|
+
list() {
|
|
33
|
+
return [...notes.values()];
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** The heading the runner writes its capability notes under. */
|
|
39
|
+
export const CAPABILITY_HEADING = '## Inputs this run could not send (limits of the runner, not findings)';
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* The capability notes as report lines: what this run met and could not do,
|
|
43
|
+
* then what this driver never has.
|
|
44
|
+
*
|
|
45
|
+
* @param {string} driverName
|
|
46
|
+
* @param {Array<{input: string, reason: string}>} met
|
|
47
|
+
* @returns {Array<string>}
|
|
48
|
+
*/
|
|
49
|
+
export function capabilityLines(driverName, met = []) {
|
|
50
|
+
const lines = met.map(note => `- ${note.input}: ${note.reason}.`.replace(/\.\.$/, '.'));
|
|
51
|
+
const metInputs = met.map(note => String(note.input).toLowerCase());
|
|
52
|
+
for (const missing of missingInputs(driverName)) {
|
|
53
|
+
const head = missing.split(/[ :(,]/)[0].toLowerCase();
|
|
54
|
+
if (metInputs.some(input => input.includes(head))) continue;
|
|
55
|
+
lines.push(`- Not available on ${driverName}: ${missing}.`);
|
|
56
|
+
}
|
|
57
|
+
return lines;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* The runner's capability notes written into report.md, in place of any
|
|
62
|
+
* earlier copy of the same section.
|
|
63
|
+
*
|
|
64
|
+
* @param {string} markdown
|
|
65
|
+
* @param {string} driverName
|
|
66
|
+
* @param {Array<{input: string, reason: string}>} met
|
|
67
|
+
* @returns {string}
|
|
68
|
+
*/
|
|
69
|
+
export function writeCapabilitySection(markdown, driverName, met = []) {
|
|
70
|
+
const lines = capabilityLines(driverName, met);
|
|
71
|
+
if (lines.length === 0) return markdown;
|
|
72
|
+
return replaceSection(markdown, CAPABILITY_HEADING, lines.join('\n'));
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** Put a `## ` section at the end of a markdown file, replacing an earlier one of the same heading. */
|
|
76
|
+
export function replaceSection(markdown, heading, body) {
|
|
77
|
+
const text = String(markdown || '').replace(/\s+$/, '');
|
|
78
|
+
const at = text.indexOf(heading);
|
|
79
|
+
let kept = text;
|
|
80
|
+
if (at >= 0) {
|
|
81
|
+
const rest = text.slice(at + heading.length);
|
|
82
|
+
const next = rest.search(/\n## /);
|
|
83
|
+
kept = `${text.slice(0, at).replace(/\s+$/, '')}${next >= 0 ? `\n${rest.slice(next)}` : ''}`.replace(/\s+$/, '');
|
|
84
|
+
}
|
|
85
|
+
return `${kept}\n\n${heading}\n${body}\n`;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** What the report step is told about capability notes the runner collected. */
|
|
89
|
+
export function capabilityPrompt(driverName, met = []) {
|
|
90
|
+
const lines = capabilityLines(driverName, met);
|
|
91
|
+
if (lines.length === 0) return '';
|
|
92
|
+
return [
|
|
93
|
+
'Inputs this run could not send. These are limits of the runner, recorded by the runner. Never write a finding of any severity or category about them, or about anything the game did or did not do because of them (a control that needs one of these and did not respond is not a bug). Mention the ones that mattered under "What this run didn\'t cover". The runner writes the full list into the report itself:',
|
|
94
|
+
...lines
|
|
95
|
+
].join('\n');
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/* ------------------------------------------------------------ blank screens */
|
|
99
|
+
|
|
100
|
+
/** A screen is blank when this share of it is one flat colour. */
|
|
101
|
+
export const BLANK_SHARE = 0.995;
|
|
102
|
+
|
|
103
|
+
/** How far a block may be from the commonest colour and still count as it. */
|
|
104
|
+
export const BLANK_TOLERANCE = 10;
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* The share of a screen that is one flat colour.
|
|
108
|
+
*
|
|
109
|
+
* @param {{cols: number, rows: number, rgb: Uint8Array}|null} print a fingerprint from ./pixels.js
|
|
110
|
+
* @returns {number|null}
|
|
111
|
+
*/
|
|
112
|
+
export function flatShare(print) {
|
|
113
|
+
if (!print || !print.rgb || !print.cols || !print.rows) return null;
|
|
114
|
+
const blocks = print.cols * print.rows;
|
|
115
|
+
const counts = new Map();
|
|
116
|
+
let best = 0;
|
|
117
|
+
let bestKey = 0;
|
|
118
|
+
for (let c = 0; c < blocks; c += 1) {
|
|
119
|
+
const key = ((print.rgb[c * 3] >> 3) << 10) | ((print.rgb[c * 3 + 1] >> 3) << 5) | (print.rgb[c * 3 + 2] >> 3);
|
|
120
|
+
const n = (counts.get(key) || 0) + 1;
|
|
121
|
+
counts.set(key, n);
|
|
122
|
+
if (n > best) { best = n; bestKey = c; }
|
|
123
|
+
}
|
|
124
|
+
const r = print.rgb[bestKey * 3];
|
|
125
|
+
const g = print.rgb[bestKey * 3 + 1];
|
|
126
|
+
const b = print.rgb[bestKey * 3 + 2];
|
|
127
|
+
let same = 0;
|
|
128
|
+
for (let c = 0; c < blocks; c += 1) {
|
|
129
|
+
if (Math.abs(print.rgb[c * 3] - r) <= BLANK_TOLERANCE && Math.abs(print.rgb[c * 3 + 1] - g) <= BLANK_TOLERANCE && Math.abs(print.rgb[c * 3 + 2] - b) <= BLANK_TOLERANCE) same += 1;
|
|
130
|
+
}
|
|
131
|
+
return same / blocks;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** @param {Buffer} png @returns {boolean|null} null when the picture cannot be read */
|
|
135
|
+
export function isBlankScreen(png) {
|
|
136
|
+
const share = flatShare(pngFingerprint(png));
|
|
137
|
+
return share === null ? null : share >= BLANK_SHARE;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** A blank screen is a finding once it has outlasted this many further inputs. */
|
|
141
|
+
export const BLANK_AFTER_INPUTS = 3;
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Watches for a game that went blank and stayed blank.
|
|
145
|
+
*
|
|
146
|
+
* A fade or a load is one flat frame for a moment. A screen that showed the
|
|
147
|
+
* game, turned one flat colour and stayed that way through BLANK_AFTER_INPUTS
|
|
148
|
+
* further inputs is a black screen a player is left looking at.
|
|
149
|
+
*
|
|
150
|
+
* @returns {{check: Function, pending: () => Object|null, confirmed: () => Object|null}}
|
|
151
|
+
*/
|
|
152
|
+
export function createBlankWatch({ after = BLANK_AFTER_INPUTS } = {}) {
|
|
153
|
+
let sawContent = false;
|
|
154
|
+
let candidate = null;
|
|
155
|
+
let confirmed = null;
|
|
156
|
+
return {
|
|
157
|
+
/**
|
|
158
|
+
* @param {Buffer|null} png the screen now
|
|
159
|
+
* @param {{action: number, label: string}} at the input just played
|
|
160
|
+
* @returns {'content'|'blank'|'confirmed'|'unknown'}
|
|
161
|
+
*/
|
|
162
|
+
check(png, at = {}) {
|
|
163
|
+
const blank = png ? isBlankScreen(png) : null;
|
|
164
|
+
if (blank === null) return 'unknown';
|
|
165
|
+
if (!blank) {
|
|
166
|
+
sawContent = true;
|
|
167
|
+
candidate = null;
|
|
168
|
+
return 'content';
|
|
169
|
+
}
|
|
170
|
+
if (!sawContent || confirmed) return 'blank';
|
|
171
|
+
if (!candidate) {
|
|
172
|
+
candidate = { sinceAction: Number(at.action) || 0, after: String(at.label || ''), inputs: [], at: Date.now() };
|
|
173
|
+
return 'blank';
|
|
174
|
+
}
|
|
175
|
+
candidate.inputs.push(String(at.label || ''));
|
|
176
|
+
if (candidate.inputs.length >= after) {
|
|
177
|
+
confirmed = candidate;
|
|
178
|
+
return 'confirmed';
|
|
179
|
+
}
|
|
180
|
+
return 'blank';
|
|
181
|
+
},
|
|
182
|
+
/** A blank screen still open when play ended, with at least one input tried on it. */
|
|
183
|
+
pending() {
|
|
184
|
+
return !confirmed && candidate && candidate.inputs.length >= 1 ? candidate : null;
|
|
185
|
+
},
|
|
186
|
+
confirmed() {
|
|
187
|
+
return confirmed;
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/* ---------------------------------------------------------- runner findings */
|
|
193
|
+
|
|
194
|
+
/** The most recent inputs a runner finding lists as its steps. */
|
|
195
|
+
export const MAX_REPRO_STEPS = 10;
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* What a tool call was, in a few words a person can follow.
|
|
199
|
+
*
|
|
200
|
+
* @param {{tool: string, input?: Object}} record an action line
|
|
201
|
+
* @returns {string}
|
|
202
|
+
*/
|
|
203
|
+
export function describeInput(record) {
|
|
204
|
+
const input = (record && record.input && typeof record.input === 'object') ? record.input : {};
|
|
205
|
+
const where = value => (typeof value === 'string' && value.trim() ? value.trim() : null);
|
|
206
|
+
const point = (x, y) => (Number.isFinite(Number(x)) && Number.isFinite(Number(y)) && x !== null && y !== null ? `(${x},${y})` : null);
|
|
207
|
+
const target = where(input.ref) || where(input.target) || point(input.x, input.y) || 'the focused element';
|
|
208
|
+
switch (record && record.tool) {
|
|
209
|
+
case 'click': {
|
|
210
|
+
const how = [input.double ? 'double click' : null, input.button && input.button !== 'left' ? `${input.button} click` : null, input.hold_ms ? `press held ${input.hold_ms} ms` : null].filter(Boolean).join(', ') || 'click';
|
|
211
|
+
return `${how} on ${target}`;
|
|
212
|
+
}
|
|
213
|
+
case 'type': return `type ${JSON.stringify(String(input.text == null ? '' : input.text).slice(0, 40))}${input.submit ? ' and press Enter' : ''}`;
|
|
214
|
+
case 'key':
|
|
215
|
+
if (Array.isArray(input.sequence) && input.sequence.length > 0) return `timed sequence of ${input.sequence.length} input(s): ${input.sequence.slice(0, 6).map(step => `${step.key || point(step.x, step.y) || '?'}@${step.at_ms}ms`).join(', ')}`;
|
|
216
|
+
if (!input.key) return 'key press the runner could not read';
|
|
217
|
+
return `key ${String(input.key || '')}${Array.isArray(input.with_keys) && input.with_keys.length > 0 ? ` with ${input.with_keys.join(', ')}` : ''}${input.hold_ms ? ` held ${input.hold_ms} ms` : ''}`;
|
|
218
|
+
case 'drag':
|
|
219
|
+
case 'swipe': return `drag from ${where(input.from) || point(input.x, input.y) || '?'} to ${where(input.to) || point(input.toX, input.toY) || '?'}`;
|
|
220
|
+
case 'hover': return `hover over ${target}`;
|
|
221
|
+
case 'scroll': return `scroll ${input.dy ? `${Math.abs(input.dy)} px ${input.dy > 0 ? 'down' : 'up'}` : ''}${input.dx ? ` ${Math.abs(input.dx)} px ${input.dx > 0 ? 'right' : 'left'}` : ''} over ${where(input.ref) || where(input.target) || point(input.x, input.y) || 'the middle of the screen'}`.replace(/\s+/g, ' ');
|
|
222
|
+
case 'select': return `choose ${input.option !== undefined ? JSON.stringify(String(input.option)) : input.value} in ${target}`;
|
|
223
|
+
case 'navigate': return `go to ${String(input.url || '')}`;
|
|
224
|
+
case 'wait': return `wait ${Number(input.ms) || 0} ms`;
|
|
225
|
+
default: return String((record && record.tool) || 'input');
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* The inputs that led to a moment, as numbered steps: the last
|
|
231
|
+
* MAX_REPRO_STEPS inputs that went through, each with its action number.
|
|
232
|
+
*
|
|
233
|
+
* @param {Array<Object>} actionRecords the loop's action and observation lines
|
|
234
|
+
* @returns {Array<string>}
|
|
235
|
+
*/
|
|
236
|
+
export function stepsBefore(actionRecords, max = MAX_REPRO_STEPS) {
|
|
237
|
+
const all = (actionRecords || []).filter(record => record && record.kind === 'action' && record.tool !== 'snapshot' && record.tool !== 'screenshot');
|
|
238
|
+
// What reached the game is a step. An input that did not go through is not
|
|
239
|
+
// one, except the very last: that may be the input the game ended under.
|
|
240
|
+
const inputs = all.filter((record, index) => record.ok !== false || index === all.length - 1);
|
|
241
|
+
const tail = inputs.slice(-max);
|
|
242
|
+
const steps = tail.map(record => `Action ${Number(record.actions) || 0}: ${describeInput(record)}${record.ok === false ? ' (did not go through)' : ''}.`);
|
|
243
|
+
if (inputs.length > tail.length) steps.unshift(`(${inputs.length - tail.length} earlier input(s) are in the action list of report.md.)`);
|
|
244
|
+
return steps.length > 0 ? ['Start the game from its first screen.', ...steps] : ['Start the game from its first screen.'];
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* A finding the runner itself witnessed, in the report schema's shape but
|
|
249
|
+
* without an id (ids are given when it joins a report).
|
|
250
|
+
*
|
|
251
|
+
* @param {Object} args
|
|
252
|
+
* @returns {Object}
|
|
253
|
+
*/
|
|
254
|
+
export function runnerFinding({ severity, category = 'bug', title, description, steps = [], screenshot = null, action = null, key = null }) {
|
|
255
|
+
const evidence = [];
|
|
256
|
+
if (screenshot) evidence.push({ type: 'screenshot', ref: String(screenshot).replace(/\\/g, '/') });
|
|
257
|
+
if (Number.isInteger(action)) evidence.push({ type: 'transcript_step', ref: `action ${action}` });
|
|
258
|
+
return {
|
|
259
|
+
severity,
|
|
260
|
+
category,
|
|
261
|
+
title: String(title).slice(0, 120),
|
|
262
|
+
description: String(description),
|
|
263
|
+
repro_steps: steps.length > 0 ? steps : ['Start the game from its first screen.'],
|
|
264
|
+
evidence,
|
|
265
|
+
// Kept off the report: how the runner tells its own findings apart.
|
|
266
|
+
runner: { key: key || String(title), at: Date.now(), ...(Number.isInteger(action) ? { action } : {}) }
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* How the game ended under an input, when it did: asked of the driver, which
|
|
272
|
+
* is the one that knows a crashed game from its own failure.
|
|
273
|
+
*
|
|
274
|
+
* @param {Object} driver
|
|
275
|
+
* @param {Error} error what the driver threw
|
|
276
|
+
* @returns {Promise<{kind: 'crashed'|'frozen'|'exited', message: string}|null>}
|
|
277
|
+
*/
|
|
278
|
+
export async function gameEndedOf(driver, error) {
|
|
279
|
+
if (!driver || typeof driver.gameEnded !== 'function') return null;
|
|
280
|
+
let ended = driver.gameEnded(error);
|
|
281
|
+
// A process that died closes its socket a moment before its exit is seen.
|
|
282
|
+
if (!ended && error && /closed|ECONNRESET|EPIPE|timed out/i.test(String(error.message || ''))) {
|
|
283
|
+
await new Promise(resolve => setTimeout(resolve, 400));
|
|
284
|
+
ended = driver.gameEnded(error);
|
|
285
|
+
}
|
|
286
|
+
return ended && ended.kind ? { kind: ended.kind, message: String(ended.message || ''), ...(ended.log ? { log: ended.log } : {}) } : null;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/** A crash or a freeze as the runner's finding, with the inputs that led to it. */
|
|
290
|
+
export function gameEndedFinding(ended, { actionRecords = [], screenshot = null, action = 0, errors = [] } = {}) {
|
|
291
|
+
const inputs = (actionRecords || []).filter(record => record && record.kind === 'action' && record.tool !== 'snapshot' && record.tool !== 'screenshot');
|
|
292
|
+
const last = inputs[inputs.length - 1];
|
|
293
|
+
const crashed = ended.kind === 'crashed';
|
|
294
|
+
const logged = (errors || []).map(entry => String(entry && entry.text ? entry.text : entry)).filter(Boolean).slice(-3);
|
|
295
|
+
return runnerFinding({
|
|
296
|
+
severity: 'blocker',
|
|
297
|
+
category: 'bug',
|
|
298
|
+
key: `game_${ended.kind}`,
|
|
299
|
+
title: crashed ? 'The game crashed during play' : 'The game froze and stopped responding',
|
|
300
|
+
description: [
|
|
301
|
+
`${crashed ? 'The game crashed' : 'The game stopped responding'} on action ${action}${last ? ` (${describeInput(last)})` : ''}: ${ended.message}.`,
|
|
302
|
+
crashed ? 'Nothing could be played after it, so the session ended there.' : 'Its screen stayed up but it answered no further input, so the session ended there.',
|
|
303
|
+
screenshot ? `The screenshot cited is ${crashed ? 'the last one saved before the crash' : 'the screen it froze on, or the last one saved before it'}.` : '',
|
|
304
|
+
logged.length > 0 ? `Errors logged just before: ${logged.join(' | ').slice(0, 600)}` : '',
|
|
305
|
+
ended.log ? `Last output of the game: ${String(ended.log).slice(-600)}` : ''
|
|
306
|
+
].filter(Boolean).join(' '),
|
|
307
|
+
steps: stepsBefore(actionRecords),
|
|
308
|
+
screenshot,
|
|
309
|
+
action
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/** A screen that went blank and stayed blank, as the runner's finding. */
|
|
314
|
+
export function blankFinding(blank, { actionRecords = [], screenshot = null, action = 0 } = {}) {
|
|
315
|
+
const tried = (blank.inputs || []).filter(Boolean);
|
|
316
|
+
const upTo = (actionRecords || []).filter(record => record && record.kind === 'action' && (Number(record.actions) || 0) <= Math.max(blank.sinceAction, 1));
|
|
317
|
+
return runnerFinding({
|
|
318
|
+
severity: 'major',
|
|
319
|
+
category: 'bug',
|
|
320
|
+
key: 'blank_screen',
|
|
321
|
+
title: 'The screen went blank and stayed blank',
|
|
322
|
+
description: `After action ${blank.sinceAction}${blank.after ? ` (${blank.after})` : ''} the whole screen was one flat colour, where it had shown the game before, and it was still blank after ${tried.length} further input(s)${tried.length > 0 ? `: ${tried.slice(0, 6).join('; ')}` : ''}. The screenshot cited shows it.`,
|
|
323
|
+
steps: [...stepsBefore(upTo), 'Look at the screen: it is a single flat colour and stays that way.'],
|
|
324
|
+
screenshot,
|
|
325
|
+
action: Math.max(blank.sinceAction, 0) || action
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/** The heading the runner lists its own findings under. */
|
|
330
|
+
export const RUNNER_FINDINGS_HEADING = '## Found by the runner (seen happen, not the persona\'s opinion)';
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* Add the runner's findings to a report: new ids after the report's own, the
|
|
334
|
+
* `runner` bookkeeping taken off, and the anchors kept for the evidence pass.
|
|
335
|
+
*
|
|
336
|
+
* @param {Object} report
|
|
337
|
+
* @param {Array<Object>} findings from {@link runnerFinding}
|
|
338
|
+
* @returns {{report: Object, added: Array<Object>, anchors: Map<string, Object>}}
|
|
339
|
+
*/
|
|
340
|
+
export function addRunnerFindings(report, findings = []) {
|
|
341
|
+
const anchors = new Map();
|
|
342
|
+
if (!report || !Array.isArray(report.findings) || findings.length === 0) return { report, added: [], anchors };
|
|
343
|
+
let next = report.findings.reduce((max, finding) => {
|
|
344
|
+
const n = Number(String((finding && finding.id) || '').replace(/^F/, ''));
|
|
345
|
+
return Number.isFinite(n) && n > max ? n : max;
|
|
346
|
+
}, 0);
|
|
347
|
+
const added = [];
|
|
348
|
+
for (const finding of findings) {
|
|
349
|
+
next += 1;
|
|
350
|
+
const { runner, ...rest } = finding;
|
|
351
|
+
const id = `F${String(next).padStart(3, '0')}`;
|
|
352
|
+
added.push({ id, ...rest });
|
|
353
|
+
anchors.set(id, runner || {});
|
|
354
|
+
}
|
|
355
|
+
return { report: { ...report, findings: [...report.findings, ...added] }, added, anchors };
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/** The runner's findings as a markdown section body. */
|
|
359
|
+
export function runnerFindingsMarkdown(added = []) {
|
|
360
|
+
return added.map(finding => [
|
|
361
|
+
`### ${finding.id} [${finding.severity}/${finding.category}] ${finding.title}`,
|
|
362
|
+
finding.description,
|
|
363
|
+
'',
|
|
364
|
+
'Steps:',
|
|
365
|
+
...finding.repro_steps.map((step, i) => `${i + 1}. ${step}`),
|
|
366
|
+
'',
|
|
367
|
+
`Evidence: ${finding.evidence.map(item => item.ref).join(', ') || '(none)'}`
|
|
368
|
+
].join('\n')).join('\n\n');
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
/* ------------------------------------------------------------------ dialogs */
|
|
372
|
+
|
|
373
|
+
/**
|
|
374
|
+
* A browser dialog as a run note: what it said and how it was answered.
|
|
375
|
+
*
|
|
376
|
+
* @param {{type: string, message: string, answer: string, text?: string, automatic?: boolean}} event
|
|
377
|
+
* @returns {{kind: 'dialog', text: string, automatic: true}}
|
|
378
|
+
*/
|
|
379
|
+
export function dialogNote(event) {
|
|
380
|
+
const said = JSON.stringify(String(event.message || '').slice(0, 300));
|
|
381
|
+
const how = event.answer === 'accepted' ? 'answered OK' : 'answered Cancel';
|
|
382
|
+
const by = event.automatic ? ' by the runner' : ' by the persona';
|
|
383
|
+
const text = event.text !== undefined ? ` with the text ${JSON.stringify(String(event.text))}` : '';
|
|
384
|
+
return { kind: 'dialog', automatic: true, text: `browser ${event.type} dialog ${said} was ${how}${text}${by}` };
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
/** The heading browser dialogs are listed under in report.md. */
|
|
388
|
+
export const DIALOGS_HEADING = '## Browser dialogs (what the game asked, and the answer given)';
|
|
389
|
+
|
|
390
|
+
/* ------------------------------------------------- steps, pictures and video */
|
|
391
|
+
|
|
392
|
+
/** A time into the video as minutes and seconds. */
|
|
393
|
+
export function videoTime(ms) {
|
|
394
|
+
const seconds = Math.max(0, Math.round(Number(ms) / 1000));
|
|
395
|
+
return `${String(Math.floor(seconds / 60)).padStart(2, '0')}:${String(seconds % 60).padStart(2, '0')}`;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
/** The heading of the runner's evidence index. */
|
|
399
|
+
export const EVIDENCE_HEADING = '## Where to look (added by the runner)';
|
|
400
|
+
|
|
401
|
+
/**
|
|
402
|
+
* Give every finding the step it was seen at, a screenshot and, when the run
|
|
403
|
+
* was recorded, a time in the video.
|
|
404
|
+
*
|
|
405
|
+
* The moment a finding belongs to is read from what it already cites: the
|
|
406
|
+
* latest observation or note it names, else its screenshot, else (for the
|
|
407
|
+
* runner's own findings) the moment the runner saw it. From that moment come
|
|
408
|
+
* the action number, the screenshot taken at or after it, and the video time.
|
|
409
|
+
* Nothing a finding already cites is removed or rewritten.
|
|
410
|
+
*
|
|
411
|
+
* @param {Object} report
|
|
412
|
+
* @param {Object} context
|
|
413
|
+
* @param {Array<Object>} context.observations entries with `index`, `at` and `actions`
|
|
414
|
+
* @param {Array<Object>} context.notes
|
|
415
|
+
* @param {Array<Object>} context.screenshots entries with `relativePath`, `observation`, `at`
|
|
416
|
+
* @param {{startedAt: number, durationMs?: number, file?: string}|null} [context.video]
|
|
417
|
+
* @param {Map<string, Object>} [context.anchors] the runner's own findings, by id
|
|
418
|
+
* @returns {{report: Object, index: Array<{id: string, action: number|null, screenshot: string|null, video: string|null}>}}
|
|
419
|
+
*/
|
|
420
|
+
export function attachWhereToLook(report, { observations = [], notes = [], screenshots = [], video = null, anchors = new Map() } = {}) {
|
|
421
|
+
if (!report || !Array.isArray(report.findings)) return { report, index: [] };
|
|
422
|
+
const byIndex = new Map(observations.map(entry => [entry.index, entry]));
|
|
423
|
+
const every = (screenshots || []).filter(shot => shot && typeof shot.relativePath === 'string' && shot.relativePath);
|
|
424
|
+
const shotByPath = new Map(every.map(shot => [String(shot.relativePath).replace(/\\/g, '/'), shot]));
|
|
425
|
+
// A picture the edge checks took after play shows the session's end under
|
|
426
|
+
// another window size or after a reload: evidence for the check that took
|
|
427
|
+
// it, never for something the persona saw.
|
|
428
|
+
const shots = every.filter(shot => !shot.edge);
|
|
429
|
+
const index = [];
|
|
430
|
+
const findings = report.findings.map(finding => {
|
|
431
|
+
if (!finding || typeof finding !== 'object') return finding;
|
|
432
|
+
const evidence = Array.isArray(finding.evidence) ? [...finding.evidence] : [];
|
|
433
|
+
let at = null;
|
|
434
|
+
let action = null;
|
|
435
|
+
let observation = null;
|
|
436
|
+
const later = (time, step, seen) => {
|
|
437
|
+
if (Number.isFinite(time) && (at === null || time > at)) at = time;
|
|
438
|
+
if (Number.isFinite(step) && (action === null || step > action)) action = step;
|
|
439
|
+
if (Number.isFinite(seen) && (observation === null || seen > observation)) observation = seen;
|
|
440
|
+
};
|
|
441
|
+
for (const item of evidence) {
|
|
442
|
+
if (!item || typeof item.ref !== 'string') continue;
|
|
443
|
+
if (item.type === 'transcript_step') {
|
|
444
|
+
const seen = item.ref.match(/^\s*observation\s*#?\s*(\d+)\s*$/i);
|
|
445
|
+
const noted = item.ref.match(/^\s*note\s*#?\s*(\d+)\s*$/i);
|
|
446
|
+
const acted = item.ref.match(/^\s*(?:action|step)\s*#?\s*(\d+)\s*$/i);
|
|
447
|
+
if (seen && byIndex.has(Number(seen[1]))) {
|
|
448
|
+
const entry = byIndex.get(Number(seen[1]));
|
|
449
|
+
later(entry.at, entry.actions, entry.index);
|
|
450
|
+
} else if (noted && notes[Number(noted[1]) - 1]) {
|
|
451
|
+
const note = notes[Number(noted[1]) - 1];
|
|
452
|
+
later(note.at, Number(note.at_action), Number(note.observation));
|
|
453
|
+
} else if (acted) {
|
|
454
|
+
later(NaN, Number(acted[1]), NaN);
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
const cited = evidence.filter(item => item && item.type === 'screenshot' && shotByPath.has(String(item.ref))).map(item => shotByPath.get(String(item.ref)));
|
|
459
|
+
if (at === null && cited.length > 0) {
|
|
460
|
+
const shot = cited[cited.length - 1];
|
|
461
|
+
const entry = byIndex.get(Number(shot.observation));
|
|
462
|
+
// A step the finding already names stands; the picture only places it in time.
|
|
463
|
+
later(shot.at, action === null && entry ? entry.actions : NaN, Number(shot.observation));
|
|
464
|
+
}
|
|
465
|
+
const anchor = anchors.get(finding.id);
|
|
466
|
+
if (anchor) later(anchor.at, anchor.action, NaN);
|
|
467
|
+
// The action a moment belongs to, when only its time is known.
|
|
468
|
+
if (action === null && at !== null) {
|
|
469
|
+
const before = observations.filter(entry => Number.isFinite(entry.at) && entry.at <= at);
|
|
470
|
+
if (before.length > 0) action = before[before.length - 1].actions;
|
|
471
|
+
}
|
|
472
|
+
if (at === null && action !== null) {
|
|
473
|
+
const entry = observations.find(candidate => Number(candidate.actions) >= action && Number.isFinite(candidate.at));
|
|
474
|
+
if (entry) at = entry.at;
|
|
475
|
+
}
|
|
476
|
+
let screenshot = cited.length > 0 ? String(cited[cited.length - 1].relativePath).replace(/\\/g, '/') : null;
|
|
477
|
+
if (!screenshot && shots.length > 0) {
|
|
478
|
+
const after = observation !== null ? shots.filter(shot => Number.isFinite(shot.observation) && shot.observation >= observation) : [];
|
|
479
|
+
const timed = at !== null ? shots.filter(shot => Number.isFinite(shot.at) && shot.at >= at) : [];
|
|
480
|
+
const pick = after[0] || timed[0] || shots[shots.length - 1];
|
|
481
|
+
screenshot = String(pick.relativePath).replace(/\\/g, '/');
|
|
482
|
+
evidence.push({ type: 'screenshot', ref: screenshot });
|
|
483
|
+
}
|
|
484
|
+
if (Number.isFinite(action) && action !== null && !evidence.some(item => item && item.type === 'transcript_step' && new RegExp(`^\\s*action\\s*#?\\s*${action}\\s*$`, 'i').test(String(item.ref)))) {
|
|
485
|
+
evidence.push({ type: 'transcript_step', ref: `action ${action}` });
|
|
486
|
+
}
|
|
487
|
+
let stamp = null;
|
|
488
|
+
// The same moment in milliseconds of the video, for the frame cut at it (reportChecks.js).
|
|
489
|
+
let videoMs = null;
|
|
490
|
+
if (video && Number.isFinite(video.startedAt) && at !== null && !(Number.isFinite(video.durationMs) && video.durationMs > 0 && Math.max(0, at - video.startedAt) > video.durationMs + 2000)) {
|
|
491
|
+
videoMs = Math.round(Number.isFinite(video.durationMs) && video.durationMs > 0 ? Math.min(Math.max(0, at - video.startedAt), video.durationMs) : Math.max(0, at - video.startedAt));
|
|
492
|
+
}
|
|
493
|
+
if (video && Number.isFinite(video.startedAt) && at !== null && !evidence.some(item => item && item.type === 'video_ts')) {
|
|
494
|
+
const offset = Math.max(0, at - video.startedAt);
|
|
495
|
+
// A moment after the recording stopped has no place in it.
|
|
496
|
+
if (!(Number.isFinite(video.durationMs) && video.durationMs > 0 && offset > video.durationMs + 2000)) {
|
|
497
|
+
stamp = videoTime(Number.isFinite(video.durationMs) && video.durationMs > 0 ? Math.min(offset, video.durationMs) : offset);
|
|
498
|
+
evidence.push({ type: 'video_ts', ref: stamp });
|
|
499
|
+
}
|
|
500
|
+
} else {
|
|
501
|
+
const existing = evidence.find(item => item && item.type === 'video_ts');
|
|
502
|
+
if (existing) {
|
|
503
|
+
stamp = String(existing.ref);
|
|
504
|
+
// The time the finding itself cites stands.
|
|
505
|
+
const parts = stamp.split(':').map(Number);
|
|
506
|
+
if (parts.length >= 2 && parts.every(Number.isFinite)) videoMs = parts.reduce((total, part) => total * 60 + part, 0) * 1000;
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
index.push({ id: finding.id, action: Number.isFinite(action) ? action : null, screenshot, video: stamp, video_ms: videoMs });
|
|
510
|
+
return { ...finding, evidence };
|
|
511
|
+
});
|
|
512
|
+
return { report: { ...report, findings }, index };
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
/** The evidence index as a markdown table body. */
|
|
516
|
+
export function whereToLookMarkdown(index, video = null) {
|
|
517
|
+
if (!index || index.length === 0) return '';
|
|
518
|
+
const lines = [
|
|
519
|
+
video && video.file ? `The video is ${video.file}. Times are minutes and seconds into it.` : 'No video was recorded for this run.',
|
|
520
|
+
'',
|
|
521
|
+
'| Finding | Seen at | Screenshot | Video |',
|
|
522
|
+
'| --- | --- | --- | --- |',
|
|
523
|
+
...index.map(row => `| ${row.id} | ${row.action === null ? 'not tied to one action' : `action ${row.action}`} | ${row.screenshot || 'none'} | ${row.video || 'none'} |`)
|
|
524
|
+
];
|
|
525
|
+
return lines.join('\n');
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
/* --------------------------------------------------------- a win is not the end */
|
|
529
|
+
|
|
530
|
+
/** A closing message that says the game was won or a level finished. */
|
|
531
|
+
export const WIN_TEXT = /\b(?:won|win|victory|victorious|beat(?:en)? (?:the|it)|complet(?:e|ed|ing)|finished|cleared|reached the (?:goal|end|flag)|goal reached|success criteria|all (?:levels|puzzles)|credits)\b/i;
|
|
532
|
+
|
|
533
|
+
/** How many times a run that stopped on a win with budget left is sent back in. */
|
|
534
|
+
export const MAX_WIN_CONTINUES = 3;
|
|
535
|
+
|
|
536
|
+
/** What a persona that stopped on a win is told. */
|
|
537
|
+
export function playOnText(actions, maxActions) {
|
|
538
|
+
return `You stopped after ${actions} of ${maxActions} actions. A win, a finished level or a reached goal is not the end of a playtest: the developer paid for the whole session and learns as much from what comes after. Note the win, then keep playing until the action budget is spent: start the next level or a new game, take a different route or choice, try what you skipped, and test the edges (lose on purpose, the pause and settings, the inputs you have not used). Only a stop condition of your persona that has nothing to do with winning ends the session early; if one fired, say which in one line with no tool call.`;
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
export default {
|
|
542
|
+
createCapabilityLedger, capabilityLines, writeCapabilitySection, capabilityPrompt, flatShare, isBlankScreen, createBlankWatch,
|
|
543
|
+
describeInput, stepsBefore, runnerFinding, addRunnerFindings, runnerFindingsMarkdown, dialogNote, videoTime, attachWhereToLook, whereToLookMarkdown, playOnText
|
|
544
|
+
};
|