ravensight-playtest 0.19.0 → 0.20.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 +49 -8
- package/docs/ADAPTERS.md +2 -0
- package/docs/DESKTOP.md +46 -2
- package/docs/UNITY.md +40 -0
- package/docs/UNREAL.md +43 -0
- package/docs/godot-driver.md +11 -0
- package/package.json +1 -1
- package/src/cli.js +18 -1
- package/src/commands/run.js +21 -3
- package/src/run/anygame/genre.js +16 -5
- package/src/run/anygame/genre2d.js +34 -3
- package/src/run/anygame/index.js +2 -1
- package/src/run/anygame/shared-hashes.json +2 -2
- package/src/run/args.js +12 -3
- package/src/run/drivers/desktop/app.js +1 -1
- package/src/run/drivers/desktop/common.js +59 -1
- package/src/run/drivers/desktop/driver.js +99 -27
- package/src/run/drivers/desktop/runHome.js +158 -0
- package/src/run/drivers/godot.js +8 -1
- package/src/run/drivers/mobile/native.js +5 -3
- package/src/run/drivers/mobile/target.js +3 -2
- package/src/run/drivers/stdio.js +6 -3
- package/src/run/drivers/unreal/driver.js +142 -52
- package/src/run/drivers/web.js +1 -1
- package/src/run/drivers/webdriver.js +4 -2
- package/src/run/launchArgs.js +58 -0
- package/src/run/pauseHook.js +128 -5
- package/src/run/personaLoop.js +30 -5
- package/src/run/replay.js +3 -1
- package/src/run/reportChecks.js +8 -1
- package/src/run/resume.js +4 -0
- package/src/run/sessions.js +11 -6
- package/src/run/slowMotion.js +151 -0
- package/src/run/startFrom.js +42 -9
package/src/run/drivers/stdio.js
CHANGED
|
@@ -62,7 +62,7 @@ export async function readBridgeConfig(file) {
|
|
|
62
62
|
return config;
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
export function createStdioDriver({ spawn: spawnImpl = spawn, timeoutMs = 30000, playtest = null, pauseHook = true, timeControl: makeTimeControl = createTimeControl } = {}) {
|
|
65
|
+
export function createStdioDriver({ spawn: spawnImpl = spawn, timeoutMs = 30000, playtest = null, pauseHook = true, slowMotion = null, timeControl: makeTimeControl = createTimeControl } = {}) {
|
|
66
66
|
let child, childState, buffer = '', nextId = 0, runDirectory, step = 0, shots = 0, lastHash, time = null;
|
|
67
67
|
const pending = new Map();
|
|
68
68
|
// The game's own 3D view through the pause hook (../view3dState.js, contract section 9), read the same
|
|
@@ -93,7 +93,8 @@ export function createStdioDriver({ spawn: spawnImpl = spawn, timeoutMs = 30000,
|
|
|
93
93
|
if (time) await time.park();
|
|
94
94
|
const value = await request('observe');
|
|
95
95
|
if (!value || typeof value.text !== 'string') throw new DriverError('Bridge observation needs text.');
|
|
96
|
-
const
|
|
96
|
+
const slowed = time ? time.timingLine() : null;
|
|
97
|
+
const observation = { step: ++step, text: truncateObservation(slowed ? `${value.text}\n${slowed}` : value.text), elapsedMs: 0 };
|
|
97
98
|
if (typeof value.screenshotBase64 === 'string' && value.screenshotBase64.startsWith('iVBORw0KGgo')) {
|
|
98
99
|
observation.screenshotBase64 = value.screenshotBase64;
|
|
99
100
|
observation.screenshotMediaType = 'image/png';
|
|
@@ -159,7 +160,7 @@ export function createStdioDriver({ spawn: spawnImpl = spawn, timeoutMs = 30000,
|
|
|
159
160
|
// whose SDK never connects is played exactly as without this.
|
|
160
161
|
let env;
|
|
161
162
|
if (config.pauseHook === true && pauseHook !== false) {
|
|
162
|
-
time = makeTimeControl({ playtest, realtime: pauseHook === 'realtime' });
|
|
163
|
+
time = makeTimeControl({ playtest, realtime: pauseHook === 'realtime', ...(slowMotion ? { slowMotion } : {}) });
|
|
163
164
|
const extra = await time.start();
|
|
164
165
|
if (Object.keys(extra).length) env = { ...process.env, ...extra };
|
|
165
166
|
else time = null;
|
|
@@ -196,6 +197,8 @@ export function createStdioDriver({ spawn: spawnImpl = spawn, timeoutMs = 30000,
|
|
|
196
197
|
},
|
|
197
198
|
/** The inputs this bridge named at launch, for the run log. */
|
|
198
199
|
get bridgeInputs() { return [...inputs]; },
|
|
200
|
+
/** Slow the game while the playtester decides, once its kind is settled as an action game (../slowMotion.js). */
|
|
201
|
+
async slowDown(options) { return time ? time.slowDown(options) : { status: 'not_supported', reason: 'style', scale: null }; },
|
|
199
202
|
observe,
|
|
200
203
|
async act(action) {
|
|
201
204
|
if (action.kind === 'type' && (action.replace || action.target)) return { ok: false, changed: false, error: 'replace (empty a field, then type) and a typing target are only available on playwright_web; this driver can only type more text into what has focus' };
|
|
@@ -15,6 +15,15 @@
|
|
|
15
15
|
// world, a player stuck on geometry, a camera in a wall or upside down, and
|
|
16
16
|
// moves that get nowhere. The game's log and crash reports (./logs.js) are
|
|
17
17
|
// read for its errors and for why it died.
|
|
18
|
+
//
|
|
19
|
+
// A run that starts from a save or plays several sessions gives the game a
|
|
20
|
+
// folder of the run's own (../desktop/runHome.js) with the saves in it: a
|
|
21
|
+
// home for a Unity player (unity:persistent://, desktop:appdata://,
|
|
22
|
+
// desktop:home://), a user folder for an Unreal game (-userdir,
|
|
23
|
+
// unreal:saved://). The start spec is in its environment
|
|
24
|
+
// (RAVENSIGHT_PLAYTEST_START, first launch only). Between sessions the game
|
|
25
|
+
// is quit the way a player quits it (relaunch) and started again on the same
|
|
26
|
+
// folder.
|
|
18
27
|
import { spawn } from 'node:child_process';
|
|
19
28
|
import fs from 'node:fs/promises';
|
|
20
29
|
import os from 'node:os';
|
|
@@ -31,7 +40,9 @@ import { inspectUnrealApp } from './app.js';
|
|
|
31
40
|
import { startDesktopHelper } from '../desktop/helper.js';
|
|
32
41
|
import { createFrameChannel } from './frames.js';
|
|
33
42
|
import { actionKeyCodes, actionKeyCodeNames } from '../desktop/keys.js';
|
|
34
|
-
import {
|
|
43
|
+
import { createRunHome, needsRunHome, startAnswerOf } from '../desktop/runHome.js';
|
|
44
|
+
import { START_ENV } from '../../startFrom.js';
|
|
45
|
+
import { bundleOf, crashWait, quitLikeAPlayer, QUIT_WAIT_MS, TERM_WAIT_MS, sessionTimeSummary, captureWindow, launchThroughLaunchServices, DEFAULT_RESOLUTION, DESKTOP_LOCK, describeEnd, gameEnvironment, gamePixel, launchGame, lookSteps, MODEL_LONG_EDGE, RECORD_INTERVAL_MS, round1, runScreenshot, screenPoint, startFrameRecorder, stopGame as stopProcess, viewText } from '../desktop/common.js';
|
|
35
46
|
import { PIPE_MAX_LOOK, PIPE_NAME } from './frames.js';
|
|
36
47
|
import { createLogTail, findCrash, unrealPaths } from './logs.js';
|
|
37
48
|
import { touchesTimeline, parseFingers } from '../../fingers.js';
|
|
@@ -60,6 +71,7 @@ const EARLY_CRASH_MS = 15000;
|
|
|
60
71
|
const MIN_KEY_MS = 60;
|
|
61
72
|
/** How long a closed frames link waits for the game's exit to be seen, so a crash is told from a dropped link. */
|
|
62
73
|
const GAME_EXIT_GRACE_MS = 3000;
|
|
74
|
+
const NO_ACCESS = 'macOS has not allowed this terminal to send mouse and keyboard input (System Settings, Privacy and Security, Accessibility).';
|
|
63
75
|
|
|
64
76
|
/**
|
|
65
77
|
* What differs between engines: how the game is recognised, started and
|
|
@@ -77,6 +89,8 @@ export const UNREAL_ENGINE = Object.freeze({
|
|
|
77
89
|
moduleAdvice: 'Add the Unreal SDK (it includes the RavensightPlaytest module) and package again',
|
|
78
90
|
rebuild: 'update the Unreal SDK and package again',
|
|
79
91
|
osKeysOnly: true,
|
|
92
|
+
// A run's own folder is the game's user folder (-userdir), inside its container when it is sandboxed (../desktop/runHome.js).
|
|
93
|
+
runHome: 'userdir',
|
|
80
94
|
inspect: inspectUnrealApp,
|
|
81
95
|
paths: unrealPaths,
|
|
82
96
|
logTail: (paths, options) => createLogTail(paths, { ...options, readyLine: UNREAL_READY_LINE }),
|
|
@@ -142,11 +156,31 @@ export function createUnrealDriver({
|
|
|
142
156
|
native: plan = {}, startHelper = startDesktopHelper, spawnGame = spawn, lock = lockDevice,
|
|
143
157
|
digest = buildDigest, windowCapture = captureWindow, encode = encodeFrames, now = Date.now, platform = process.platform,
|
|
144
158
|
settleMs = 200, windowTimeoutMs = 90000, helloTimeoutMs = 15000, raiseTimeoutMs = 20000, recordIntervalMs = RECORD_INTERVAL_MS,
|
|
145
|
-
playtest = null, pauseHook = true, timeControl:
|
|
159
|
+
playtest = null, pauseHook = true, slowMotion = null, timeControl: givenTimeControl = createTimeControl, home = os.homedir(), crashWaitMs = 6000,
|
|
146
160
|
findCrashImpl = findCrash, engine = UNREAL_ENGINE, inspect: inspectGiven = null,
|
|
147
161
|
helloCapMs = HELLO_STARTING_CAP_MS, helloAfterReadyMs = HELLO_AFTER_READY_MS,
|
|
148
|
-
launchServices = true, launchApp = launchThroughLaunchServices
|
|
162
|
+
launchServices = true, launchApp = launchThroughLaunchServices,
|
|
163
|
+
makeRunHome = createRunHome, quitWaitMs = QUIT_WAIT_MS, termWaitMs = TERM_WAIT_MS
|
|
149
164
|
} = {}) {
|
|
165
|
+
// The time control is made again for each session's launch, with the options of the first (relaunch).
|
|
166
|
+
let timeOptions = null;
|
|
167
|
+
// Slow motion asked for after a hello (an action game, ../../slowMotion.js) is asked of each relaunch's hook again.
|
|
168
|
+
let slowAsked = null;
|
|
169
|
+
const makeTimeControl = options => { timeOptions = options; return givenTimeControl(options); };
|
|
170
|
+
// Where the run starts (../../startFrom.js): a home of the run's own, with the saves in it, and the start spec.
|
|
171
|
+
const start = plan.start && ((plan.start.saves && plan.start.saves.length) || plan.start.spec) ? plan.start : null;
|
|
172
|
+
let runHome = null, timeSummaries = [];
|
|
173
|
+
/** The game's environment beyond the cleaned one: the run's home and, on the first launch only, the start spec. */
|
|
174
|
+
const ownEnv = first => ({ ...(runHome ? runHome.env : {}), ...(first && start && start.spec ? { [START_ENV]: start.spec } : {}) });
|
|
175
|
+
/** The game's arguments: the engine's window switches, the run's own user folder, then the project's and --launch-arg's. */
|
|
176
|
+
const gameArgs = () => [...engine.args(plan.resolution || DEFAULT_RESOLUTION), ...(runHome ? runHome.args : []), ...(plan.args || [])];
|
|
177
|
+
/** Where the game logs and crashes: in the run's own folder first when it has one, then where it always does. */
|
|
178
|
+
function gamePaths() {
|
|
179
|
+
const mine = engine.paths(metadata, { home });
|
|
180
|
+
if (!runHome) return mine;
|
|
181
|
+
const own = runHome.kind === 'home' ? engine.paths(metadata, { home: runHome.home }) : { logs: runHome.logs, crashes: runHome.crashes, engines: [] };
|
|
182
|
+
return { ...mine, logs: [...own.logs, ...mine.logs], crashes: [...own.crashes, ...mine.crashes], engines: [...own.engines, ...mine.engines] };
|
|
183
|
+
}
|
|
150
184
|
const inspectApp = inspectGiven || engine.inspect;
|
|
151
185
|
let metadata, runDirectory, signal, unlock, helper, game, frames, source, pointer, window, frame, pendingFrame, startedAt, stopPromise;
|
|
152
186
|
let step = 0, shots = 0, gameEnded = null, exited = null, launched = false;
|
|
@@ -172,6 +206,7 @@ export function createUnrealDriver({
|
|
|
172
206
|
stopPromise = null; unlock = null; helper = null; game = null; frames = null; source = null; pointer = null; window = null;
|
|
173
207
|
frame = null; pendingFrame = null; gameEnded = null; exited = null; launched = false; recorder = null; time = null; lastView = undefined;
|
|
174
208
|
names = []; paths = null; logTail = null; ending = null; link = null; access = null; step = 0; shots = 0;
|
|
209
|
+
runHome = null; timeSummaries = []; slowAsked = null; driver.sessions = 0;
|
|
175
210
|
heldErrors.length = 0; world = createWorldWatch(); Object.assign(metrics, freshMetrics());
|
|
176
211
|
}
|
|
177
212
|
/** The game's module takes this request (./frames.js can). */
|
|
@@ -245,13 +280,13 @@ export function createUnrealDriver({
|
|
|
245
280
|
if (stopPromise) return stopPromise;
|
|
246
281
|
stopPromise = (async () => {
|
|
247
282
|
let result = { videoPath: null };
|
|
248
|
-
const timeControl = time ? time.summary() : null;
|
|
283
|
+
const timeControl = sessionTimeSummary(timeSummaries, time ? time.summary() : null);
|
|
249
284
|
try {
|
|
250
285
|
// Resume the game before it is stopped, so nothing is left frozen.
|
|
251
286
|
if (time) await time.close().catch(() => {});
|
|
252
287
|
if (recorder) result = await recorder.stop(exited && !['stopped', 'preflight', 'completed'].includes(reason) ? 'game_exited' : reason);
|
|
253
288
|
} finally {
|
|
254
|
-
try { frames?.close(); await stopGame(); await helper?.stop(); await link?.close(); }
|
|
289
|
+
try { frames?.close(); await stopGame(); await helper?.stop(); await link?.close(); await runHome?.remove(); }
|
|
255
290
|
finally { await unlock?.(); }
|
|
256
291
|
}
|
|
257
292
|
return timeControl ? { ...result, timeControl } : result;
|
|
@@ -326,11 +361,59 @@ export function createUnrealDriver({
|
|
|
326
361
|
if (missing.length) text += ` ${list(missing).replace(/^./, c => c.toUpperCase())} ${missing.length === 1 ? 'is' : 'are'} not available: ${source !== 'game' ? `${missing.length === 1 ? 'it needs' : 'they need'} ${engine.module}` : osOnlyInput() && !frames.capabilities.includes('input_new') ? 'the game reads Unity\'s old Input Manager, which takes only what the operating system delivers' : `${missing.length === 1 ? 'it needs' : 'they need'} ${engine.module}${engine.osKeysOnly ? ' at protocol 3' : ' with the Input System'}`}.`;
|
|
327
362
|
return text;
|
|
328
363
|
}
|
|
364
|
+
/**
|
|
365
|
+
* Start the game once with `env` and wait for its window. `exited` is this launch's own: an earlier launch's
|
|
366
|
+
* exit is never read as this one's.
|
|
367
|
+
*/
|
|
368
|
+
async function openGame(env) {
|
|
369
|
+
exited = null;
|
|
370
|
+
let child = null;
|
|
371
|
+
const onExit = ended => { if (game === child) exited = ended; };
|
|
372
|
+
// An engine whose window takes the mouse only in front (Unity) starts through LaunchServices, as Finder
|
|
373
|
+
// starts an app, which is the start macOS lets come to the front; one started straight from this process
|
|
374
|
+
// in the background is refused the front, and a press at the pointer then never reaches it.
|
|
375
|
+
const bundle = engine.launchServices && launchServices ? bundleOf(metadata) : null;
|
|
376
|
+
metrics.launch = bundle ? 'launch-services' : 'direct';
|
|
377
|
+
({ child } = bundle
|
|
378
|
+
? await launchApp(bundle, metadata.executablePath, gameArgs(), { env, now, find: request => helper.send({ kind: 'find', ...request }), onExit })
|
|
379
|
+
: launchGame(metadata.executablePath, gameArgs(), { stdio: link.stdio, env, spawnGame, now, onExit }));
|
|
380
|
+
game = child;
|
|
381
|
+
frames = link.channel(child, helloTimeoutMs + windowTimeoutMs);
|
|
382
|
+
const deadline = now() + windowTimeoutMs;
|
|
383
|
+
while (!exited && !await refreshWindow()) {
|
|
384
|
+
if (now() > deadline) throw new Error('The game did not open a window in time.');
|
|
385
|
+
await sleep(250, signal);
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
/** How the runner sees the started game and sends it input: its module's frames and input, or macOS's. */
|
|
389
|
+
async function settleGame() {
|
|
390
|
+
if (await waitForModule()) source = 'game';
|
|
391
|
+
else if (stillStarting) throw new Error(`The game had not finished starting ${Math.round(helloCapMs / 1000)} s after its window opened (its log never reached the end of the engine's start up), so the runner stopped waiting for its playtest module. This is a limit of this runner on a busy computer, not a problem found in the game; run again when the computer is less busy.`);
|
|
392
|
+
else if (access.screenCapture) source = 'window';
|
|
393
|
+
else throw new Error(`This build does not include the Ravensight playtest frames module, and macOS has not allowed this terminal to record the screen. ${engine.moduleAdvice}, or allow Screen Recording for this terminal in System Settings, Privacy and Security.`);
|
|
394
|
+
// A game whose module takes the mouse needs no cursor moves and no window on top. A game that reads only the
|
|
395
|
+
// operating system's input (Unity's old Input Manager) gets its mouse and keys from macOS, which every system reads.
|
|
396
|
+
pointer = gameCan('pointer') && !osOnlyInput() ? 'game' : 'system';
|
|
397
|
+
metrics.pointerInput = pointer;
|
|
398
|
+
metrics.keyInput = keysInGame() ? 'game' : 'system';
|
|
399
|
+
metrics.frameSource = source;
|
|
400
|
+
metrics.protocol = source === 'game' ? frames.version : 0;
|
|
401
|
+
metrics.inputSystems = source === 'game' && frames.capabilities ? frames.capabilities.filter(word => word.startsWith('input_')).map(word => word.slice(6)) : null;
|
|
402
|
+
if (!access.accessibility && (pointer === 'system' || !keysInGame())) {
|
|
403
|
+
throw new Error(`${NO_ACCESS}${source === 'game' && frames.capabilities ? ' This game takes its mouse or keys from the operating system, so the runner sends them through macOS.' : ''}`);
|
|
404
|
+
}
|
|
405
|
+
// A just started game cannot be brought forward until it has finished
|
|
406
|
+
// starting; wait for that here, so the persona's first click is not lost.
|
|
407
|
+
const raiseBy = now() + raiseTimeoutMs;
|
|
408
|
+
while (pointer === 'system' && !(await helper.send({ kind: 'raise', pid: game.pid }, 10000).catch(() => ({}))).onTop && now() < raiseBy && !exited) await sleep(500, signal);
|
|
409
|
+
}
|
|
329
410
|
const driver = {
|
|
330
411
|
name: engine.driver, touch: false, exactScreenshots: true, supportsHold: true,
|
|
331
412
|
supportedActions: ['click', 'key', 'type', 'wait'],
|
|
332
413
|
/** Frozen between actions while the SDK pause hook holds the game. */
|
|
333
414
|
get frozenBetweenActions() { return Boolean(time && time.engaged); },
|
|
415
|
+
/** Slow the game while the playtester decides, once its kind is settled as an action game (../../slowMotion.js). */
|
|
416
|
+
async slowDown(options) { slowAsked = { ...(options || {}) }; return time ? time.slowDown(options) : { status: 'not_supported', reason: 'style', scale: null }; },
|
|
334
417
|
/** Drag always; with the module at protocol 3, mouse look and hover, the wheel and the gamepad too. */
|
|
335
418
|
get pointerTools() {
|
|
336
419
|
return ['drag', ...(full() ? ['look'] : []), ...(gameCan('wheel') ? ['scroll'] : []), ...(gameCan('pad') ? ['gamepad'] : []), ...(gameCan('touch') ? ['touches'] : [])];
|
|
@@ -359,22 +442,21 @@ export function createUnrealDriver({
|
|
|
359
442
|
if (platform !== 'darwin') throw new Error(`Local ${engine.label} playtests run on macOS. Cloud playtests play web builds only.`);
|
|
360
443
|
if (plan.buildHash && await digest(file) !== plan.buildHash) throw new Error('The native build changed since preflight or the saved job. Start a new job for the changed build.');
|
|
361
444
|
metadata = plan.metadata || await inspectApp(file);
|
|
362
|
-
paths = engine.paths(metadata, { home });
|
|
363
|
-
logTail = engine.logTail(paths, { since: startedAt });
|
|
364
445
|
unlock = await lock(DESKTOP_LOCK);
|
|
446
|
+
// Saves and sessions play in a home of the run's own, never the developer's (../desktop/runHome.js).
|
|
447
|
+
if (needsRunHome(plan)) runHome = await makeRunHome({ plan, metadata, bundle: bundleOf(metadata), kind: engine.runHome || 'home', userHome: home });
|
|
448
|
+
paths = gamePaths();
|
|
449
|
+
logTail = engine.logTail(paths, { since: startedAt });
|
|
365
450
|
helper = await startHelper({ signal });
|
|
366
451
|
access = await helper.send({ kind: 'access' });
|
|
367
|
-
const noAccess = 'macOS has not allowed this terminal to send mouse and keyboard input (System Settings, Privacy and Security, Accessibility).';
|
|
368
452
|
// An engine whose keys always go through macOS needs the permission before anything starts.
|
|
369
|
-
if (!access.accessibility && engine.osKeysOnly) throw new Error(
|
|
370
|
-
|
|
371
|
-
// The game's own arguments only: the pause hook's and the frames link's secrets go in the environment, never argv.
|
|
372
|
-
const args = [...engine.args(resolution), ...(plan.args || [])];
|
|
453
|
+
if (!access.accessibility && engine.osKeysOnly) throw new Error(NO_ACCESS);
|
|
454
|
+
// The game's own arguments only (gameArgs): the pause hook's and the frames link's secrets go in the environment, never argv.
|
|
373
455
|
for (let attempt = 1; ; attempt++) {
|
|
374
456
|
// The SDK pause hook: the variables go to this game only. A game whose SDK never connects plays as without it.
|
|
375
457
|
let env = gameEnvironment();
|
|
376
458
|
if (pauseHook !== false) {
|
|
377
|
-
time = makeTimeControl({ playtest, realtime: pauseHook === 'realtime' });
|
|
459
|
+
time = makeTimeControl({ playtest, realtime: pauseHook === 'realtime', ...(slowMotion ? { slowMotion } : {}) });
|
|
378
460
|
const extra = await time.start();
|
|
379
461
|
if (Object.keys(extra).length) env = { ...env, ...extra };
|
|
380
462
|
else time = null;
|
|
@@ -382,26 +464,9 @@ export function createUnrealDriver({
|
|
|
382
464
|
// Unreal: -NoLogThread -FORCELOGFLUSH write and flush each log line where it is logged, not later on the engine's log
|
|
383
465
|
// thread, so what the game logged just before a crash is in the file (./logs.js).
|
|
384
466
|
link = await engine.frames();
|
|
385
|
-
env = { ...env, ...link.env };
|
|
467
|
+
env = { ...env, ...link.env, ...ownEnv(true) };
|
|
386
468
|
const spawnedAt = now();
|
|
387
|
-
|
|
388
|
-
let child = null;
|
|
389
|
-
const onExit = ended => { if (game === child) exited = ended; };
|
|
390
|
-
// An engine whose window takes the mouse only in front (Unity) starts through LaunchServices, as Finder
|
|
391
|
-
// starts an app, which is the start macOS lets come to the front; one started straight from this process
|
|
392
|
-
// in the background is refused the front, and a press at the pointer then never reaches it.
|
|
393
|
-
const bundle = engine.launchServices && launchServices ? bundleOf(metadata) : null;
|
|
394
|
-
metrics.launch = bundle ? 'launch-services' : 'direct';
|
|
395
|
-
({ child } = bundle
|
|
396
|
-
? await launchApp(bundle, metadata.executablePath, args, { env, now, find: request => helper.send({ kind: 'find', ...request }), onExit })
|
|
397
|
-
: launchGame(metadata.executablePath, args, { stdio: link.stdio, env, spawnGame, now, onExit }));
|
|
398
|
-
game = child;
|
|
399
|
-
frames = link.channel(child, helloTimeoutMs + windowTimeoutMs);
|
|
400
|
-
const deadline = now() + windowTimeoutMs;
|
|
401
|
-
while (!exited && !await refreshWindow()) {
|
|
402
|
-
if (now() > deadline) throw new Error('The game did not open a window in time.');
|
|
403
|
-
await sleep(250, signal);
|
|
404
|
-
}
|
|
469
|
+
await openGame(env);
|
|
405
470
|
if (!exited) break;
|
|
406
471
|
const how = exited.signal || `code ${exited.code}`;
|
|
407
472
|
// A crash in the game's first seconds, before it has a window, is started once more. A Development or Test
|
|
@@ -418,25 +483,8 @@ export function createUnrealDriver({
|
|
|
418
483
|
}
|
|
419
484
|
throw new Error(`The game exited during launch (${how}).`);
|
|
420
485
|
}
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
else if (access.screenCapture) source = 'window';
|
|
424
|
-
else throw new Error(`This build does not include the Ravensight playtest frames module, and macOS has not allowed this terminal to record the screen. ${engine.moduleAdvice}, or allow Screen Recording for this terminal in System Settings, Privacy and Security.`);
|
|
425
|
-
// A game whose module takes the mouse needs no cursor moves and no window on top. A game that reads only the
|
|
426
|
-
// operating system's input (Unity's old Input Manager) gets its mouse and keys from macOS, which every system reads.
|
|
427
|
-
pointer = gameCan('pointer') && !osOnlyInput() ? 'game' : 'system';
|
|
428
|
-
metrics.pointerInput = pointer;
|
|
429
|
-
metrics.keyInput = keysInGame() ? 'game' : 'system';
|
|
430
|
-
metrics.frameSource = source;
|
|
431
|
-
metrics.protocol = source === 'game' ? frames.version : 0;
|
|
432
|
-
metrics.inputSystems = source === 'game' && frames.capabilities ? frames.capabilities.filter(word => word.startsWith('input_')).map(word => word.slice(6)) : null;
|
|
433
|
-
if (!access.accessibility && (pointer === 'system' || !keysInGame())) {
|
|
434
|
-
throw new Error(`${noAccess}${source === 'game' && frames.capabilities ? ' This game takes its mouse or keys from the operating system, so the runner sends them through macOS.' : ''}`);
|
|
435
|
-
}
|
|
436
|
-
// A just started game cannot be brought forward until it has finished
|
|
437
|
-
// starting; wait for that here, so the persona's first click is not lost.
|
|
438
|
-
const raiseBy = now() + raiseTimeoutMs;
|
|
439
|
-
while (pointer === 'system' && !(await helper.send({ kind: 'raise', pid: game.pid }, 10000).catch(() => ({}))).onTop && now() < raiseBy && !exited) await sleep(500, signal);
|
|
486
|
+
await settleGame();
|
|
487
|
+
driver.sessions = 1;
|
|
440
488
|
// The SDK connects a moment after the game starts; give it that before the first look.
|
|
441
489
|
if (time) await time.waitForHello(5000);
|
|
442
490
|
launched = true;
|
|
@@ -447,12 +495,54 @@ export function createUnrealDriver({
|
|
|
447
495
|
throw new DriverError(error.message, { fatal: true });
|
|
448
496
|
}
|
|
449
497
|
},
|
|
498
|
+
/** What the game was told about where to start: it reads the spec itself, so the run only knows it was sent. */
|
|
499
|
+
get startAnswer() { return startAnswerOf(start, runHome); },
|
|
500
|
+
/** Launches of the game so far in this run. */
|
|
501
|
+
sessions: 0,
|
|
502
|
+
/**
|
|
503
|
+
* A new session of the same run (../../sessions.js): the game is quit the way a player quits it and started
|
|
504
|
+
* again on the run's own home, with what it saved there and no start spec. The video goes on through it.
|
|
505
|
+
*/
|
|
506
|
+
async relaunch() {
|
|
507
|
+
if (!launched || !game) throw new Error('The game has not launched.');
|
|
508
|
+
if (exited) throw new Error('The game has exited.');
|
|
509
|
+
// The hook's close lets the game run, so it can save as it quits.
|
|
510
|
+
if (time) { timeSummaries.push(time.summary()); await time.close().catch(() => {}); time = null; }
|
|
511
|
+
// Command-Q goes through macOS, so it needs the input permission; without it the game gets the stop signal.
|
|
512
|
+
const commandQ = access && access.accessibility ? async () => { await helper.send({ kind: 'raise', pid: game.pid }, 10000).catch(() => null); await helper.send({ kind: 'keys', pid: game.pid, codes: actionKeyCodes({ key: 'Meta+q' }), holdMs: 0 }); } : null;
|
|
513
|
+
const closed = await quitLikeAPlayer(game, { exited: () => exited, commandQ, quitWaitMs, termWaitMs });
|
|
514
|
+
if (logTail) heldErrors.push(...await logTail.read().catch(() => []));
|
|
515
|
+
frames?.close();
|
|
516
|
+
await link?.close().catch(() => {});
|
|
517
|
+
ending = null; gameEnded = null; window = null; pendingFrame = null; lastView = undefined; names = []; stillStarting = false;
|
|
518
|
+
logTail = engine.logTail(paths, { since: now() });
|
|
519
|
+
let env = gameEnvironment();
|
|
520
|
+
if (timeOptions) {
|
|
521
|
+
time = makeTimeControl(timeOptions);
|
|
522
|
+
const extra = await time.start();
|
|
523
|
+
if (Object.keys(extra).length) env = { ...env, ...extra };
|
|
524
|
+
else time = null;
|
|
525
|
+
}
|
|
526
|
+
link = await engine.frames();
|
|
527
|
+
const cameBack = async () => {
|
|
528
|
+
await openGame({ ...env, ...link.env, ...ownEnv(false) });
|
|
529
|
+
if (exited) throw new Error('it exited');
|
|
530
|
+
await settleGame();
|
|
531
|
+
if (time) await time.waitForHello(5000);
|
|
532
|
+
frame = await capture();
|
|
533
|
+
};
|
|
534
|
+
// A game that dies as it starts again is said as that, whichever step saw it go.
|
|
535
|
+
await cameBack().catch(error => { throw exited ? new Error(`The game exited as it started again (${exited.signal || `code ${exited.code}`}).`) : error; });
|
|
536
|
+
if (time && slowAsked) await time.slowDown(slowAsked).catch(() => null);
|
|
537
|
+
driver.sessions += 1;
|
|
538
|
+
return { session: driver.sessions, scene: null, files: runHome ? await runHome.savedFiles().catch(() => null) : null, closed };
|
|
539
|
+
},
|
|
450
540
|
async observe() {
|
|
451
541
|
if (time && !pendingFrame) await time.park();
|
|
452
542
|
frame = pendingFrame || await capture(); pendingFrame = null;
|
|
453
543
|
if (gameCan('names')) names = await frames.names().catch(() => names);
|
|
454
544
|
if (time && time.offersView3d && lastView === undefined) lastView = await time.view3d();
|
|
455
|
-
const timing = time && time.engaged ? 'The game is paused until your next input.' : 'The game is running in real time.';
|
|
545
|
+
const timing = time && time.engaged ? 'The game is paused until your next input.' : (time && time.timingLine()) || 'The game is running in real time.';
|
|
456
546
|
const view = viewText(lastView || null, names);
|
|
457
547
|
return { step: ++step, text: `${engine.label} game window on macOS, ${frame.width} by ${frame.height} pixels. Use x,y screenshot coordinates. ${timing}${view ? `\n${view}` : ''}`, screenshotBase64: frame.png.toString('base64'), screenshotMediaType: 'image/png', elapsedMs: now() - startedAt };
|
|
458
548
|
},
|
package/src/run/drivers/web.js
CHANGED
|
@@ -82,7 +82,7 @@ export const PHONE_USER_AGENT = 'Mozilla/5.0 (Linux; Android 14; Pixel 8) AppleW
|
|
|
82
82
|
export const TAP_MS = 60;
|
|
83
83
|
|
|
84
84
|
/** What the persona is told about a run played with touch. */
|
|
85
|
-
export const TOUCH_PLAY_NOTE = 'This run plays on a phone sized screen with touch, as a player holding a phone would: there is no mouse and no hover. click is a tap with one finger (hold_ms makes it a long press, double a double tap). drag is a finger put down, moved and lifted: a swipe, a flick, a pull on a joystick, a card carried to a slot (duration_ms sets how fast). The pinch tool, when this run has it, puts two fingers down and moves them apart or together; the touches tool puts down one or two fingers each on its own path and clock, such as a thumb held on a stick while the other taps a button. A finding about hover, right click or the mouse wheel is not one this run can make.';
|
|
85
|
+
export const TOUCH_PLAY_NOTE = 'This run plays on a phone sized screen with touch, as a player holding a phone would: there is no mouse and no hover. click is a tap with one finger (hold_ms makes it a long press, double a double tap). drag is a finger put down, moved and lifted: a swipe, a flick, a pull on a joystick, a card carried to a slot (duration_ms sets how fast). The pinch tool, when this run has it, puts two fingers down and moves them apart or together; the touches tool puts down one or two fingers each on its own path and clock, such as a thumb held on a stick while the other taps a button. Keys reach the game only if it listens for a keyboard, and a game made for a phone usually does not: when keys change nothing, play with your thumbs (touches to hold a stick and fire together, stick for an on-screen stick), not more keys. A finding about hover, right click or the mouse wheel is not one this run can make.';
|
|
86
86
|
|
|
87
87
|
/**
|
|
88
88
|
* The frame a canvas observation sends the model: JPEG at this quality, at the
|
|
@@ -35,7 +35,7 @@ export async function readDriverConfig(file) {
|
|
|
35
35
|
if(config.pauseHook&&environment!==undefined&&(!environment||Array.isArray(environment)||typeof environment!=='object')) throw new DriverError(`${PAUSE_HOOK_ENV_CAPABILITY} must be an object to add the pause hook variables.`,{fatal:true});
|
|
36
36
|
return {...config,endpoint:url.href.replace(/\/$/,'')};
|
|
37
37
|
}
|
|
38
|
-
export function createWebDriverAdapter({name='desktop_driver',fetch:fetchImpl=globalThis.fetch,sleep=ms=>new Promise(resolve=>setTimeout(resolve,ms)),playtest=null,pauseHook=true,timeControl:makeTimeControl=createTimeControl}={}) {
|
|
38
|
+
export function createWebDriverAdapter({name='desktop_driver',fetch:fetchImpl=globalThis.fetch,sleep=ms=>new Promise(resolve=>setTimeout(resolve,ms)),playtest=null,pauseHook=true,slowMotion=null,timeControl:makeTimeControl=createTimeControl}={}) {
|
|
39
39
|
let config,session,runDirectory,step=0,shots=0,lastHash=null,time=null;
|
|
40
40
|
// The game's own 3D view through the pause hook (../view3dState.js, contract section 9): read before the
|
|
41
41
|
// first input and after each one, for the world watch (../world3d.js). A game that offers none gets no 3D findings.
|
|
@@ -82,7 +82,7 @@ export function createWebDriverAdapter({name='desktop_driver',fetch:fetchImpl=gl
|
|
|
82
82
|
let capabilities=config.capabilities;
|
|
83
83
|
if(config.pauseHook===true&&pauseHook!==false&&PAUSE_HOOK_DRIVERS.includes(name)){
|
|
84
84
|
// A game whose SDK never connects is played exactly as without this.
|
|
85
|
-
time=makeTimeControl({playtest,realtime:pauseHook==='realtime',sleep});
|
|
85
|
+
time=makeTimeControl({playtest,realtime:pauseHook==='realtime',...(slowMotion?{slowMotion}:{}),sleep});
|
|
86
86
|
const env=await time.start();
|
|
87
87
|
if(Object.keys(env).length)capabilities={...capabilities,[PAUSE_HOOK_ENV_CAPABILITY]:{...(capabilities[PAUSE_HOOK_ENV_CAPABILITY]||{}),...env}};
|
|
88
88
|
else time=null;
|
|
@@ -93,6 +93,8 @@ export function createWebDriverAdapter({name='desktop_driver',fetch:fetchImpl=gl
|
|
|
93
93
|
if(!answer||typeof answer.sessionId!=='string'){if(time){await time.close().catch(()=>{});time=null;}throw new DriverError('The device server did not create a session.',{fatal:true});}
|
|
94
94
|
session=answer.sessionId;await fs.mkdir(path.join(runDir,'screenshots'),{recursive:true});
|
|
95
95
|
},observe,
|
|
96
|
+
// Slow the game while the playtester decides, once its kind is settled as an action game (../slowMotion.js).
|
|
97
|
+
async slowDown(options){return time?time.slowDown(options):{status:'not_supported',reason:'style',scale:null};},
|
|
96
98
|
async act(action){
|
|
97
99
|
const before=lastHash;const touch=['android_driver','ios_driver'].includes(name)?'touch':'mouse';
|
|
98
100
|
let viewBefore=null;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Launch arguments for a native local build (`--launch-arg`, repeatable):
|
|
3
|
+
* words the studio hands its own game, such as `-level=3` or `--skip-intro`.
|
|
4
|
+
* They go to the game as an argument list, never through a shell, and the
|
|
5
|
+
* model can never add or change one.
|
|
6
|
+
*
|
|
7
|
+
* | Driver | Where they go |
|
|
8
|
+
* |---|---|
|
|
9
|
+
* | godot_driver | after Godot's `--`, so the game reads them with OS.get_cmdline_user_args() |
|
|
10
|
+
* | desktop_driver | after the project settings' `native.args`, to the game (after the game file for LÖVE) |
|
|
11
|
+
* | unity_driver | after the runner's window switches (`-screen-width` and so on) |
|
|
12
|
+
* | unreal_driver | after the runner's window and pipe switches |
|
|
13
|
+
*
|
|
14
|
+
* At most 32 arguments in all (with `native.args`), each at most 1,024
|
|
15
|
+
* characters, one line each. An argument that names the runner's own switches
|
|
16
|
+
* (`--ravensight...`, `-RavensightPlaytest...`, and `-userdir=` on Unreal) is
|
|
17
|
+
* refused, so the game can never be pointed at another driver port, pipe or
|
|
18
|
+
* save folder.
|
|
19
|
+
*/
|
|
20
|
+
import { MAX_GAME_ARGS, MAX_GAME_ARG_CHARS } from './drivers/desktop/app.js';
|
|
21
|
+
|
|
22
|
+
/** The drivers that hand `--launch-arg` to the game they start. */
|
|
23
|
+
export const LAUNCH_ARG_DRIVERS = Object.freeze(['godot_driver', 'desktop_driver', 'unity_driver', 'unreal_driver']);
|
|
24
|
+
|
|
25
|
+
/** The runner's own switches, which a launch argument may not name. */
|
|
26
|
+
const RESERVED = /^-{1,2}ravensight/i;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* What is wrong with --launch-arg for this driver, one sentence each, before
|
|
30
|
+
* anything is priced.
|
|
31
|
+
*
|
|
32
|
+
* @param {{launchArg?: string[]}} options
|
|
33
|
+
* @param {string} driverName
|
|
34
|
+
* @returns {string[]}
|
|
35
|
+
*/
|
|
36
|
+
export function launchArgProblems(options = {}, driverName = '') {
|
|
37
|
+
if (options.launchArg === undefined) return [];
|
|
38
|
+
const args = [].concat(options.launchArg);
|
|
39
|
+
if (!LAUNCH_ARG_DRIVERS.includes(driverName)) return [`--launch-arg hands arguments to a game this machine starts (Godot, or a desktop, Unity or Unreal game on a Mac), and this run uses ${driverName || 'no driver'}.`];
|
|
40
|
+
const problems = [];
|
|
41
|
+
if (args.length > MAX_GAME_ARGS) problems.push(`Give --launch-arg at most ${MAX_GAME_ARGS} times.`);
|
|
42
|
+
for (const arg of args) {
|
|
43
|
+
const text = String(arg);
|
|
44
|
+
if (!text) { problems.push('A --launch-arg is never empty.'); continue; }
|
|
45
|
+
if (text.length > MAX_GAME_ARG_CHARS) { problems.push(`Each --launch-arg is at most ${MAX_GAME_ARG_CHARS} characters.`); continue; }
|
|
46
|
+
if (/[\u0000-\u001f\u007f]/.test(text)) { problems.push('Each --launch-arg is one line of text with no control characters.'); continue; }
|
|
47
|
+
if (RESERVED.test(text)) problems.push(`"${text.slice(0, 40)}" names one of the runner's own switches; a launch argument cannot.`);
|
|
48
|
+
else if (driverName === 'unreal_driver' && /^-userdir=/i.test(text)) problems.push('-userdir is set by the runner for a run that starts from a save or plays sessions; a launch argument cannot set it.');
|
|
49
|
+
}
|
|
50
|
+
return [...new Set(problems)];
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** The launch arguments as given, or an empty list. */
|
|
54
|
+
export function launchArgsOf(options = {}) {
|
|
55
|
+
return options.launchArg === undefined ? [] : [].concat(options.launchArg).map(String);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export default { launchArgProblems, launchArgsOf, LAUNCH_ARG_DRIVERS };
|