@threenative/playtest 0.1.0 → 0.3.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.
@@ -1,14 +1,39 @@
1
- import { n as IPlaytestSetupRequest, r as JsonValue, b as IPlaytestBridgeDescription, m as IPlaytestSampleRequest, l as IPlaytestObservationSnapshot } from '../protocol-CeC1lz_G.js';
2
- import { s as IPlaytestProtocolDiagnostic, z as IPlaytestScenario, u as IPlaytestReport, n as IPlaytestObservations, j as IPlaytestDiagnostic } from '../diagnostics-Ckm_5lrw.js';
1
+ import { IPlaytestObservationSnapshot, IPlaytestSetupRequest, JsonValue, IPlaytestBridgeDescription, IPlaytestBridgeReady, IPlaytestSampleRequest } from '../protocol.js';
2
+ import { b as IPlaytestScenario, s as IPlaytestObservations, r as IPlaytestFramebufferCoverageObservation, j as IPlaytestCaptureProvenance, y as IPlaytestSetupApplication, l as IPlaytestDeviceMetricsObservation, e as IPlaytestDiagnostic, w as IPlaytestProtocolDiagnostic, i as IPlaytestArtifactRequest, v as IPlaytestPointer } from '../diagnostics-D89qJhf0.js';
3
3
  import { Page } from 'playwright';
4
+ import { I as IStandalonePlaytestConfig, b as IRunnerConsoleEntry, c as ILabeledPlaytestSample, d as IMovementSampleInterval, a as IStandalonePlaytestReport } from '../shared-Ax3-pneQ.js';
5
+ export { e as IPlaytestFlagHelp, f as IPlaytestServerConfig, g as IRunStepSamples, M as ManagedServerError, P as PLAYTEST_FLAGS, h as PlaytestCliUsageError, i as failedDiagnosticsAssertion, j as formatUsage, p as parseStandalonePlaytestArgs } from '../shared-Ax3-pneQ.js';
6
+ import { ChildProcess } from 'node:child_process';
7
+
8
+ declare function preflightDisplay(config: Pick<IStandalonePlaytestConfig, "headless">, scenario: Pick<IPlaytestScenario, "artifacts" | "assert" | "steps">, environment?: NodeJS.ProcessEnv, platform?: NodeJS.Platform): IPlaytestDiagnostic | undefined;
9
+ declare function buildReport(config: IStandalonePlaytestConfig, scenario: IPlaytestScenario, beforeSnapshot: IPlaytestObservationSnapshot | undefined, afterSnapshot: IPlaytestObservationSnapshot | undefined, consoleEntries: IRunnerConsoleEntry[], networkEntries: Array<{
10
+ method: string;
11
+ url: string;
12
+ }>, pathLength?: number | undefined, hud?: Record<string, {
13
+ after?: unknown;
14
+ before?: unknown;
15
+ }>, runtimeReady?: boolean, visual?: IPlaytestObservations["visual"], labeledSamples?: readonly ILabeledPlaytestSample[], framebufferCoverage?: IPlaytestFramebufferCoverageObservation | undefined, capture?: IPlaytestCaptureProvenance | undefined, captureFailure?: {
16
+ code: "TN_CAPTURE_BLANK";
17
+ label: string;
18
+ reason: string;
19
+ } | undefined, movementSamples?: readonly IMovementSampleInterval[], setup?: IPlaytestSetupApplication | undefined, deviceMetrics?: IPlaytestDeviceMetricsObservation | undefined, movementBaselineSnapshot?: IPlaytestObservationSnapshot | undefined, startup?: IStandalonePlaytestReport["startup"]): IStandalonePlaytestReport;
4
20
 
5
21
  /** The only seam between assertion orchestration and an application bridge. */
6
- interface BridgeTransport {
22
+ interface IBridgeTransport {
7
23
  readonly capabilities: readonly string[];
8
- call<T>(method: string, argument?: unknown): Promise<T>;
24
+ call<T>(method: string, argument?: unknown, timeoutMs?: number): Promise<T>;
9
25
  close(): Promise<void>;
10
26
  waitForBridge(timeoutMs: number): Promise<boolean>;
11
27
  }
28
+ /**
29
+ * The budget for one `advance` call: the round-trip allowance plus time for the ticks themselves.
30
+ *
31
+ * Every other bridge method is a request and a reply, so `operationTimeoutMs` fits. `advance` runs
32
+ * the game loop N times before replying, so its honest bound grows with N. Fixed at 5 s it failed
33
+ * `starter-game-over` — 600 ticks in one call — on a two-core runner, and reported it as
34
+ * `TN_PLAYTEST_OPERATION_TIMEOUT`, which reads as a hung page rather than a slow one.
35
+ */
36
+ declare function advanceTimeoutMs(ticks: number, perTickMs?: number): number;
12
37
  declare class PlaytestBridgeError extends Error {
13
38
  readonly diagnostic: IPlaytestProtocolDiagnostic;
14
39
  constructor(diagnostic: IPlaytestProtocolDiagnostic);
@@ -19,217 +44,343 @@ interface IPlaytestBridgeClient {
19
44
  close(): Promise<void>;
20
45
  drainEvents(limit?: number): Promise<JsonValue[]>;
21
46
  description: IPlaytestBridgeDescription;
47
+ /** Re-reads the bridge's readiness, including startup progress when it reports any. */
48
+ readiness(): Promise<IPlaytestBridgeReady>;
22
49
  sample(request: IPlaytestSampleRequest): Promise<IPlaytestObservationSnapshot>;
23
50
  }
24
- declare class PlaywrightTransport implements BridgeTransport {
51
+ declare class PlaywrightTransport implements IBridgeTransport {
25
52
  private readonly page;
26
- readonly capabilities: readonly ["browser.canvas", "browser.console", "browser.dom", "browser.input", "browser.network", "browser.screenshot", "browser.trace", "runtime.ui"];
27
- constructor(page: Page);
28
- call<T>(method: string, argument?: unknown): Promise<T>;
53
+ private readonly operationTimeoutMs;
54
+ readonly capabilities: readonly ["browser.canvas", "browser.console", "browser.dom", "browser.input", "browser.network", "browser.screenshot", "browser.trace", "runtime.diagnostics", "runtime.ui"];
55
+ constructor(page: Page, operationTimeoutMs?: number);
56
+ call<T>(method: string, argument?: unknown, timeoutMs?: number): Promise<T>;
29
57
  close(): Promise<void>;
30
58
  waitForBridge(timeoutMs: number): Promise<boolean>;
31
59
  }
32
60
  declare function connectPlaytestBridge(page: Page, scenario: IPlaytestScenario, timeoutMs?: number): Promise<IPlaytestBridgeClient | undefined>;
33
- declare function connectPlaytestBridgeTransport(transport: BridgeTransport, scenario: IPlaytestScenario, timeoutMs?: number): Promise<IPlaytestBridgeClient | undefined>;
61
+ /**
62
+ * How long to wait for the page to install its playtest bridge.
63
+ *
64
+ * The bridge appears during application startup, not during a request/response round trip, so
65
+ * `operationTimeoutMs` is the wrong budget for it by construction — the same mistake, in the same
66
+ * direction, as timing a bulk `advance` with it. On a software-rendered two-core runner the
67
+ * scaffolded starter spends seconds in first-use compilation before the bridge exists, and the run
68
+ * was reported as `TN_PLAYTEST_BRIDGE_MISSING` with `frames: 0`: not a page without a bridge, a
69
+ * page that had not finished booting yet.
70
+ *
71
+ * One operation plus the startup budget, matching `advanceTimeoutMs`. A page that genuinely
72
+ * installs no bridge still fails with the same diagnostic, just later.
73
+ */
74
+ declare function bridgeWaitTimeoutMs(operationMs?: number): number;
75
+ declare function connectPlaytestBridgeTransport(transport: IBridgeTransport, scenario: IPlaytestScenario, timeoutMs?: number): Promise<IPlaytestBridgeClient | undefined>;
76
+
77
+ /** Capture the largest rendered canvas without composited DOM overlays. */
78
+ declare function captureVisualSurface(page: Page, artifactPath?: string): Promise<Buffer | undefined>;
79
+ /**
80
+ * The core bridge is installed before an async scene load completes, so its describe/ready
81
+ * handshake can finish one browser frame before the fixed-step loop starts. Retry only that
82
+ * exact startup race; a stopped loop that does not recover remains a runner failure.
83
+ */
84
+ declare function advanceFixedStep(page: Page, bridge: Pick<IPlaytestBridgeClient, "advance">, ticks: number): Promise<void>;
85
+ declare function playtestStepDrivesMovement(step: IPlaytestScenario["steps"][number], hasHeldInput: boolean): boolean;
86
+
87
+ /**
88
+ * A published diagnostic that is unmistakably a *readout* rather than an error.
89
+ *
90
+ * The bridge's `diagnostics` channel is typed `() => JsonValue[]` and the generated project
91
+ * AGENTS.md says it "returns current runtime diagnostics", so a game publishes its debug HUD
92
+ * through it — that is the documented use. Every entry then landed in `recentRuntimeErrors`, and
93
+ * a proof with `noRuntimeDiagnostics` failed the build for owning a frame counter. Round 9 lost
94
+ * a sealed scenario to `{id:"fps",label:"FPS",value:30}` being counted as a runtime error.
95
+ *
96
+ * This does **not** guess. Ambiguous entries stay errors, because this package fails closed and
97
+ * an error counter that quietly stops counting is the exact defect it exists to prevent. Only
98
+ * the unambiguous readout shape — a labelled scalar, carrying no error marker — is reclassified,
99
+ * and nothing is dropped: readouts move to `runtimeReadouts` on the same object and stay observable.
100
+ */
101
+ declare function isRuntimeReadout(entry: unknown): boolean;
102
+
103
+ declare function resolveManagedServerCommand(config: IStandalonePlaytestConfig, dynamicPort?: number): string;
104
+ declare function substituteManagedPort(command: string, port: number): string;
105
+ /**
106
+ * Await one teardown step, but never longer than `timeoutMs`. Returns true when the step
107
+ * finished (or there was nothing to do) and false when it ran out of time, so the caller can
108
+ * escalate. Teardown runs after the report is written, so a step that hangs costs the process
109
+ * its exit rather than costing the run its result.
110
+ */
111
+ declare function boundedTeardownStep(step: Promise<unknown> | undefined, timeoutMs: number): Promise<boolean>;
112
+ interface IPageLifecycle {
113
+ closed: boolean;
114
+ crashed: boolean;
115
+ /** Every main-frame navigation, including the run's own initial one. */
116
+ frameNavigations: string[];
117
+ /** Main-frame navigations after the handshake settled — the ones that break a run. */
118
+ navigations: string[];
119
+ settled: boolean;
120
+ /** The last console lines before the failure, which is where a device loss announces itself. */
121
+ tail: string[];
122
+ }
123
+ /**
124
+ * Playwright reports a crashed renderer and a navigated document with the same
125
+ * "Execution context was destroyed" message, and the two have opposite fixes: a crash is an
126
+ * environment or content problem, a navigation is the page moving under the run. The listeners
127
+ * on the page record which one happened, so the report names it rather than falling through to
128
+ * the unexplained-error catch-all. Returns undefined when the error is neither, leaving it to
129
+ * propagate untouched.
130
+ */
131
+ declare function pageLifecycleDiagnostic(error: unknown, lifecycle: IPageLifecycle, url: string): IPlaytestProtocolDiagnostic | undefined;
132
+ /**
133
+ * Navigate and complete the bridge handshake, re-navigating when the page reloads itself
134
+ * before the handshake finishes. This never retries past the handshake: no observation has
135
+ * been taken and no assertion has been evaluated yet, so a reattempt cannot hide a failure.
136
+ * A bridge that is genuinely missing or incompatible still fails on its own diagnostic, and
137
+ * an exhausted retry budget fails closed on TN_PLAYTEST_PAGE_NAVIGATED rather than passing.
138
+ */
139
+ declare function openPageAndConnectBridge(page: Page, config: IStandalonePlaytestConfig, scenario: IPlaytestScenario): Promise<IPlaytestBridgeClient | undefined>;
140
+
141
+ declare const STANDALONE_PLAYTEST_OBSERVATION_FIELDS: readonly ["components", "componentSeries", "console", "effectLogBefore", "framebufferCoverage", "hud", "network", "physicsDebugSeries", "performanceSeries", "renderChain", "physicsDebugBefore", "resources", "resourceSeries", "runtimeDiagnostics", "runtimeDiagnosticsBefore", "runtimeObservations", "signals", "signalSeries", "visual"];
142
+
143
+ declare function handlePlaytestSignal(teardown: (stopManagedServer: boolean) => Promise<void>, setExitCode?: (code: number) => void, exit?: (code: number) => void, target?: string, writeMessage?: (message: string) => void): Promise<void>;
144
+ declare function writeCaptureProvenance(artifactDirectory: string, provenance: IPlaytestCaptureProvenance): Promise<void>;
145
+ /**
146
+ * Diagnostics name `console.json` and `runtime-trace.json`, and `artifacts.console`,
147
+ * `artifacts.network` and `artifacts.runtimeTrace` accept a request for them. Neither was
148
+ * written: a build hitting TN_PLAYTEST_CONSOLE_ERROR found the artifact directory holding
149
+ * only `after.png` and `capture.json`, and had to reconstruct the errors from provenance.
150
+ * A message that names a file the runner never writes sends the reader somewhere empty, so
151
+ * write each one whenever it has content or was asked for.
152
+ */
153
+ declare function writeObservationArtifacts(artifactDirectory: string, requested: IPlaytestArtifactRequest | undefined, observations: {
154
+ console: readonly unknown[];
155
+ network: readonly unknown[];
156
+ runtimeTrace: {
157
+ readonly recentRuntimeErrors?: readonly unknown[];
158
+ readonly [key: string]: unknown;
159
+ } | undefined;
160
+ }): Promise<readonly string[]>;
161
+ interface IStandalonePlaytestRunOptions {
162
+ managedServer?: ChildProcess;
163
+ }
164
+ declare function runStandalonePlaytest(config: IStandalonePlaytestConfig, options?: IStandalonePlaytestRunOptions): Promise<IStandalonePlaytestReport>;
165
+ declare function runStandalonePlaytests(config: IStandalonePlaytestConfig): Promise<readonly IStandalonePlaytestReport[]>;
166
+ declare function batchArtifactDirectory(base: string, scenarioPath: string, index: number): string;
167
+ declare function resolveManagedServerConfig(config: IStandalonePlaytestConfig): Promise<IStandalonePlaytestConfig>;
168
+
169
+ declare const WEBGPU_BROWSER_ARGS: readonly ["--ozone-platform=x11", "--enable-unsafe-webgpu", "--disable-gpu-sandbox", "--ignore-gpu-blocklist", "--enable-features=Vulkan"];
170
+ /** Allow performance probes to sample render work instead of Xvfb's compositor cadence. */
171
+ declare const PERFORMANCE_BROWSER_ARGS: readonly ["--disable-frame-rate-limit", "--disable-gpu-vsync"];
172
+ declare function resolveBrowserArguments(browserArgs: readonly string[] | undefined): string[];
173
+ /**
174
+ * Name a software adapter from what `adapter.info` reported. Every field is searched because
175
+ * which one carries the giveaway depends on the platform: Linux Dawn puts `swiftshader` in
176
+ * `architecture`, Mesa reports `llvmpipe` in `description`, and a headless Windows run says
177
+ * `Microsoft Basic Render Driver` in `device`.
178
+ */
179
+ declare function softwareAdapterName(adapter: Readonly<Record<string, string>> | undefined): string | undefined;
180
+ interface IBrowserPointerChange {
181
+ isPrimary: boolean;
182
+ pointer: Required<IPlaytestPointer>;
183
+ type: "pointerdown" | "pointermove" | "pointerup";
184
+ }
185
+ declare function reconcileBrowserPointers(previous: ReadonlyMap<number, Required<IPlaytestPointer>>, next: readonly IPlaytestPointer[]): IBrowserPointerChange[];
34
186
 
35
187
  interface IAndroidDriverOptions {
36
188
  activity: string;
37
189
  adbPath?: string;
38
190
  packageName: string;
39
191
  serial?: string;
192
+ /**
193
+ * The rotation between the touchscreen's raw axes and the frame the app draws in, when the
194
+ * device cannot be asked.
195
+ *
196
+ * Normally this is read from the window — `dumpsys window`'s `mRotation`, inverted, and then
197
+ * `dumpsys input`'s `SurfaceOrientation` and the `user_rotation` setting behind it. Those two
198
+ * older sources are why this option exists: an orientation-locked game on a device whose
199
+ * display never rotated reads 0 from both while its window is turned 90° from the panel, so an
200
+ * injected touch lands somewhere else entirely and every input assertion fails for a reason
201
+ * that has nothing to do with the game.
202
+ *
203
+ * Set explicitly to make such a run reproducible, and say so in the evidence. Fails closed on
204
+ * anything but 0, 1, 2 or 3.
205
+ */
206
+ touchRotation?: number;
40
207
  }
41
208
  interface IAndroidDriver {
42
209
  captureConsole(): Promise<Array<{
43
210
  text: string;
44
211
  type: string;
45
212
  }>>;
213
+ /** The device this driver is bound to, when it knows; reported next to its metric samples. */
214
+ deviceSerial?(): string | undefined;
46
215
  isAlive(): Promise<boolean>;
47
- prepare(endpoint: string, mailboxRoot?: string): Promise<void>;
216
+ prepare(endpoint: string, mailboxRoot?: string, viewport?: {
217
+ height: number;
218
+ width: number;
219
+ }): Promise<void>;
48
220
  readFile?(path: string): Promise<string | undefined>;
49
221
  removeFile?(path: string): Promise<void>;
222
+ /** Raw adb passthrough, so the host can measure the device itself. Read-only probes only. */
223
+ runAdb?(args: readonly string[]): Promise<string>;
50
224
  screenshot(path: string): Promise<void>;
225
+ setPointers?(pointers: readonly IAndroidPointer[]): Promise<IAndroidPointerInjection>;
226
+ startScreenRecording?(): Promise<void>;
227
+ /** One OS tap in viewport pixels. Works on emulators and physical devices alike. */
228
+ tap?(x: number, y: number): Promise<void>;
229
+ /** Put the soft keyboard away, and report whether one was up. */
230
+ hideKeyboard?(): Promise<boolean>;
51
231
  stop(): Promise<void>;
232
+ stopScreenRecording?(path: string): Promise<void>;
52
233
  writeFile?(path: string, contents: string): Promise<void>;
53
234
  }
235
+ interface IAndroidPointer {
236
+ buttons?: number;
237
+ id: number;
238
+ x: number;
239
+ y: number;
240
+ }
241
+ interface IAndroidPointerInjection {
242
+ activeIds: number[];
243
+ injection: "adb-emu-event-protocol-b";
244
+ rotation: number;
245
+ trackingIds: number[];
246
+ }
54
247
  declare class AdbAndroidDriver implements IAndroidDriver {
55
248
  private readonly options;
249
+ private static readonly COVERAGE_VIDEO_PATH;
56
250
  private readonly adbPath;
251
+ private screenrecord?;
252
+ private screenrecordError?;
253
+ private readonly touchSlots;
254
+ private nextTrackingId;
255
+ private rotation?;
256
+ private viewportPresented;
57
257
  constructor(options: IAndroidDriverOptions);
58
- prepare(endpoint: string, mailboxRoot?: string): Promise<void>;
258
+ prepare(endpoint: string, mailboxRoot?: string, viewport?: {
259
+ height: number;
260
+ width: number;
261
+ }): Promise<void>;
262
+ /**
263
+ * Put the device into the scenario's viewport, and fail closed if it did not take.
264
+ *
265
+ * A silent failure here is the expensive one: the run continues, the touches arrive, the
266
+ * assertions go red, and the report blames the game for a device that was never showing the
267
+ * viewport the scenario asked for.
268
+ */
269
+ private presentViewport;
270
+ tap(x: number, y: number): Promise<void>;
271
+ /**
272
+ * Dismiss the soft keyboard and wait for it to actually be gone.
273
+ *
274
+ * Measured on the physical Pixel 8: focusing a text field opens the IME, the WebView reflows
275
+ * into the space left above it, and the page's centred menu rides up — so a coordinate computed
276
+ * against the scenario's viewport now points at the keyboard. A tap there does not merely miss
277
+ * the control; it types a character into the field it meant to submit.
278
+ *
279
+ * BACK is the dismissal the platform guarantees. The wait is the point: the reflow happens on
280
+ * the next layout pass, and a click sent into the middle of it lands wherever the menu was
281
+ * halfway through moving.
282
+ */
283
+ hideKeyboard(): Promise<boolean>;
59
284
  captureConsole(): Promise<Array<{
60
285
  text: string;
61
286
  type: string;
62
287
  }>>;
63
288
  screenshot(path: string): Promise<void>;
289
+ startScreenRecording(): Promise<void>;
290
+ stopScreenRecording(path: string): Promise<void>;
64
291
  isAlive(): Promise<boolean>;
292
+ setPointers(pointers: readonly IAndroidPointer[]): Promise<IAndroidPointerInjection>;
65
293
  readFile(path: string): Promise<string | undefined>;
66
294
  removeFile(path: string): Promise<void>;
67
295
  stop(): Promise<void>;
296
+ private readRotation;
68
297
  writeFile(path: string, contents: string): Promise<void>;
298
+ deviceSerial(): string | undefined;
299
+ /**
300
+ * The device-metrics probes read `dumpsys`, `logcat` and sysfs through here. Deliberately a
301
+ * thin passthrough rather than a metrics API: the parsing belongs to deviceMetrics.ts, which
302
+ * is unit-tested against real captured device output.
303
+ */
304
+ runAdb(args: readonly string[]): Promise<string>;
69
305
  private adb;
306
+ private waitForScreenRecorder;
307
+ private abortScreenRecording;
70
308
  private serialArgs;
71
309
  }
310
+ declare function parseAndroidConsole(output: string): Array<{
311
+ text: string;
312
+ type: string;
313
+ }>;
314
+ /**
315
+ * Splits slot identity from coordinates into separate synced `adb emu event send` batches.
316
+ *
317
+ * The emulator console drops ABS_MT_POSITION_X/Y from any batch that also carries an
318
+ * ABS_MT_TRACKING_ID: the command reports `OK` and the coordinates never reach the device, so
319
+ * every contact lands at (0, 0) and a two-finger gesture reads as two touches in the same
320
+ * screen half — the exact failure that made the simultaneous-touch proof unprovable.
321
+ * Confirmed against `getevent -lt /dev/input/event2` on emulator 36.6.11 with the android-35
322
+ * google_apis image. Identity goes first so a slot exists before it is positioned.
323
+ */
324
+ declare function androidTouchBatches(identity: readonly string[], positions: readonly string[]): string[][];
325
+ /**
326
+ * The touch rotation for the window `dumpsys window` just described, or `undefined`.
327
+ *
328
+ * `mRotation` says how far the window's content is turned from the panel's natural frame.
329
+ * {@link rotatedTouchPosition} converts the other way — a point in that content back to the
330
+ * panel's raw axes — so the value it needs is the inverse, and handing it `mRotation` directly
331
+ * is a 180-degree error on either odd rotation.
332
+ *
333
+ * This is the source of truth because it describes the *window*. `dumpsys input`'s
334
+ * `SurfaceOrientation` is absent on the emulator, and `user_rotation` is the user's preference:
335
+ * an orientation-locked game on a device the user never turned reads 0 there while its window
336
+ * is turned 90 degrees off the panel, so every injected touch lands somewhere else.
337
+ */
338
+ declare function touchRotationFromWindowDump(dump: string): number | undefined;
339
+ /**
340
+ * Make the device present a scenario's declared viewport, one device pixel per CSS pixel.
341
+ *
342
+ * A scenario's `viewport` is a declared test condition, and the browser target honours it by
343
+ * sizing the window. Without the same courtesy here, a UI page lays out at whatever CSS viewport
344
+ * the device's density happens to give — 914x411 on a 2400x1080 panel at 420dpi — and a step
345
+ * that names a point in viewport pixels lands on whatever the device's own layout put there.
346
+ * Nothing about that failure looks like a coordinate problem: the touch arrives, the host
347
+ * hit-tests it honestly, and the control simply is not where the scenario said.
348
+ *
349
+ * Density 160 is the whole mechanism: it makes `devicePixelRatio` 1, so a viewport pixel, a CSS
350
+ * pixel and a device pixel are the same pixel and the page lays out exactly as it does on web.
351
+ * The size is written in the panel's natural frame, which is why it is transposed for the
352
+ * portrait-natural devices every phone and emulator here happens to be.
353
+ */
354
+ declare function viewportPresentationCommands(viewport: {
355
+ height: number;
356
+ width: number;
357
+ }, physical: {
358
+ height: number;
359
+ width: number;
360
+ }): string[][];
361
+ /**
362
+ * One OS-level tap, in the display's current orientation.
363
+ *
364
+ * With the viewport presented, that orientation *is* the scenario's viewport and the coordinate
365
+ * needs no rotation — which is the second reason to prefer this over the emulator's pointer
366
+ * protocol. The first is that `adb emu event send` exists only on emulators, and a click step
367
+ * that only works on an emulator is a click step that does not work.
368
+ */
369
+ declare function tapCommand(x: number, y: number): string[];
370
+ /** Whether an input method window is on screen, from `dumpsys input_method`. */
371
+ declare function keyboardIsShown(dump: string): boolean;
372
+ /**
373
+ * Undo the presentation.
374
+ *
375
+ * `reset` and never the numbers read beforehand: a run that crashed between reading and writing
376
+ * would restore a size it had already replaced, and leave the device quietly wrong for whoever
377
+ * measures on it next.
378
+ */
379
+ declare function viewportRestoreCommands(): string[][];
380
+ declare function rotatedTouchPosition(x: number, y: number, rotation: number): [number, number];
72
381
  declare function discoverAdb(environment?: NodeJS.ProcessEnv): string;
73
382
 
74
- interface IPlaytestServerConfig {
75
- command: string;
76
- cwd?: string;
77
- timeoutMs?: number;
78
- }
79
- interface IStandalonePlaytestConfig {
80
- android?: {
81
- activity: string;
82
- packageName: string;
83
- };
84
- adbPath?: string;
85
- artifactDirectory: string;
86
- browserArgs?: readonly string[];
87
- device?: string;
88
- endpoint?: string;
89
- headless: boolean;
90
- ios?: {
91
- appPath?: string;
92
- bundleId: string;
93
- transport: "device" | "simulator";
94
- };
95
- mailboxRoot?: string;
96
- projectPath: string;
97
- scenarioPath: string;
98
- server?: IPlaytestServerConfig;
99
- timeoutMs: number;
100
- target?: "android" | "browser" | "ios";
101
- trace: boolean;
102
- url: string;
103
- xcrunPath?: string;
104
- }
105
- interface IPlaytestFlagHelp {
106
- default: string;
107
- summary: string;
108
- takesValue: boolean;
109
- allowDashValue?: boolean;
110
- repeatable?: boolean;
111
- }
112
- declare const PLAYTEST_FLAGS: {
113
- readonly "--adb": {
114
- readonly default: "auto-discover";
115
- readonly summary: "absolute adb executable path";
116
- readonly takesValue: true;
117
- };
118
- readonly "--activity": {
119
- readonly default: ".MystralActivity";
120
- readonly summary: "Android launch activity";
121
- readonly takesValue: true;
122
- };
123
- readonly "--app": {
124
- readonly default: "required for iOS";
125
- readonly summary: "built iOS .app bundle";
126
- readonly takesValue: true;
127
- };
128
- readonly "--artifacts": {
129
- readonly default: "artifacts/playtest";
130
- readonly summary: "artifact output directory";
131
- readonly takesValue: true;
132
- };
133
- readonly "--browser-arg": {
134
- readonly allowDashValue: true;
135
- readonly default: "none (repeatable)";
136
- readonly repeatable: true;
137
- readonly summary: "one additional Chromium argument";
138
- readonly takesValue: true;
139
- };
140
- readonly "--browser-recipe": {
141
- readonly default: "none";
142
- readonly summary: "named browser recipe (webgpu)";
143
- readonly takesValue: true;
144
- };
145
- readonly "--bundle-id": {
146
- readonly default: "dev.threenative.runtime";
147
- readonly summary: "iOS application bundle identifier";
148
- readonly takesValue: true;
149
- };
150
- readonly "--device": {
151
- readonly default: "platform default";
152
- readonly summary: "Android serial or iOS device identifier";
153
- readonly takesValue: true;
154
- };
155
- readonly "--endpoint": {
156
- readonly default: "http://127.0.0.1:41777/playtest";
157
- readonly summary: "device bridge endpoint";
158
- readonly takesValue: true;
159
- };
160
- readonly "--headed": {
161
- readonly default: "false";
162
- readonly summary: "show the browser window";
163
- readonly takesValue: false;
164
- };
165
- readonly "--mailbox-root": {
166
- readonly default: "Android external files directory";
167
- readonly summary: "native device mailbox directory";
168
- readonly takesValue: true;
169
- };
170
- readonly "--ios-transport": {
171
- readonly default: "simulator";
172
- readonly summary: "iOS transport (simulator or device)";
173
- readonly takesValue: true;
174
- };
175
- readonly "--project": {
176
- readonly default: ".";
177
- readonly summary: "project root used to resolve paths";
178
- readonly takesValue: true;
179
- };
180
- readonly "--package": {
181
- readonly default: "com.mystral.engine";
182
- readonly summary: "Android application id";
183
- readonly takesValue: true;
184
- };
185
- readonly "--scenario": {
186
- readonly default: "required (or positional)";
187
- readonly summary: "scenario JSON path";
188
- readonly takesValue: true;
189
- };
190
- readonly "--server-command": {
191
- readonly default: "none";
192
- readonly summary: "command for a managed app server";
193
- readonly takesValue: true;
194
- };
195
- readonly "--server-timeout": {
196
- readonly default: "15000";
197
- readonly summary: "managed server readiness timeout in ms";
198
- readonly takesValue: true;
199
- };
200
- readonly "--timeout": {
201
- readonly default: "15000";
202
- readonly summary: "page operation timeout in ms";
203
- readonly takesValue: true;
204
- };
205
- readonly "--target": {
206
- readonly default: "browser";
207
- readonly summary: "execution target (browser, android, or ios)";
208
- readonly takesValue: true;
209
- };
210
- readonly "--trace": {
211
- readonly default: "false";
212
- readonly summary: "write a Playwright trace";
213
- readonly takesValue: false;
214
- };
215
- readonly "--url": {
216
- readonly default: "http://127.0.0.1:5173";
217
- readonly summary: "application URL";
218
- readonly takesValue: true;
219
- };
220
- readonly "--xcrun": {
221
- readonly default: "auto-discover";
222
- readonly summary: "absolute xcrun executable path";
223
- readonly takesValue: true;
224
- };
225
- };
226
- declare class PlaytestCliUsageError extends Error {
227
- constructor(message: string);
228
- }
229
- declare function formatUsage(): string;
230
- declare function parseStandalonePlaytestArgs(argv: readonly string[], cwd?: string): IStandalonePlaytestConfig;
231
-
232
- declare const ANDROID_TRANSPORT_CAPABILITIES: readonly ["browser.console", "browser.input", "browser.screenshot"];
383
+ declare const ANDROID_TRANSPORT_CAPABILITIES: readonly ["browser.console", "browser.input", "browser.screenshot", "device.metrics", "runtime.diagnostics"];
233
384
  interface IDeviceMailbox {
234
385
  read(path: string): Promise<string | undefined>;
235
386
  remove(path: string): Promise<void>;
@@ -239,11 +390,11 @@ interface IDeviceMailboxPaths {
239
390
  request: string;
240
391
  response: string;
241
392
  }
242
- interface DevicePlaytestTransport extends BridgeTransport {
393
+ interface IDevicePlaytestTransport extends IBridgeTransport {
243
394
  start(): Promise<void>;
244
395
  }
245
- declare class DeviceBridgeTransport implements DevicePlaytestTransport {
246
- readonly capabilities: readonly ["browser.console", "browser.input", "browser.screenshot"];
396
+ declare class DeviceBridgeTransport implements IDevicePlaytestTransport {
397
+ readonly capabilities: readonly ["browser.console", "browser.input", "browser.screenshot", "device.metrics", "runtime.diagnostics"];
247
398
  readonly endpoint: URL;
248
399
  private connected;
249
400
  private nextId;
@@ -259,14 +410,15 @@ declare class DeviceBridgeTransport implements DevicePlaytestTransport {
259
410
  private handle;
260
411
  private markConnected;
261
412
  }
262
- declare class DeviceMailboxTransport implements DevicePlaytestTransport {
413
+ declare class DeviceMailboxTransport implements IDevicePlaytestTransport {
263
414
  private readonly mailbox;
264
415
  private readonly paths;
265
- readonly capabilities: readonly ["browser.console", "browser.input", "browser.screenshot"];
416
+ private readonly operationTimeoutMs;
417
+ readonly capabilities: readonly ["browser.console", "browser.input", "browser.screenshot", "device.metrics", "runtime.diagnostics"];
266
418
  private connected;
267
419
  private closed;
268
420
  private nextId;
269
- constructor(mailbox: IDeviceMailbox, paths: IDeviceMailboxPaths);
421
+ constructor(mailbox: IDeviceMailbox, paths: IDeviceMailboxPaths, operationTimeoutMs?: number);
270
422
  start(): Promise<void>;
271
423
  call<T>(method: string, argument?: unknown): Promise<T>;
272
424
  close(): Promise<void>;
@@ -275,64 +427,102 @@ declare class DeviceMailboxTransport implements DevicePlaytestTransport {
275
427
  private readResponse;
276
428
  }
277
429
  declare function androidMailboxPaths(packageName: string, root?: string): IDeviceMailboxPaths;
430
+ /**
431
+ * Names what stopped answering when an operation times out (PRD-167).
432
+ *
433
+ * A timed-out operation is ambiguous between two failures with different owners: a host whose
434
+ * process died mid-run, and a live host whose mailbox stopped polling. When the driver can prove
435
+ * the process exited, the diagnostic says so and carries the host's last console lines — a crash
436
+ * message must not be hidden behind a generic timeout.
437
+ */
438
+ declare function deviceTimeoutDiagnostic(diagnostic: IPlaytestProtocolDiagnostic, hostAlive: boolean | undefined, lastConsoleLines: readonly string[]): IPlaytestProtocolDiagnostic;
278
439
  declare function deviceMailboxPaths(root: string): IDeviceMailboxPaths;
279
440
  declare function validateDeviceEndpoint(value: string): URL;
280
441
 
281
- declare const STANDALONE_PLAYTEST_OBSERVATION_FIELDS: readonly ["components", "componentSeries", "console", "hud", "network", "resources", "resourceSeries", "runtimeDiagnostics", "runtimeObservations", "signals", "signalSeries", "visual"];
282
-
283
- interface IStandalonePlaytestReport extends IPlaytestReport {
284
- artifactDirectory: string;
285
- pass: boolean;
286
- runtime: "native" | "web";
287
- scenario: string;
288
- target: string;
289
- url: string;
290
- }
291
- interface LabeledPlaytestSample {
292
- label: string;
293
- signals: unknown[];
294
- snapshot: IPlaytestObservationSnapshot;
295
- }
296
- declare function runStandalonePlaytest(config: IStandalonePlaytestConfig): Promise<IStandalonePlaytestReport>;
297
- declare function preflightDisplay(config: Pick<IStandalonePlaytestConfig, "headless">, scenario: Pick<IPlaytestScenario, "artifacts" | "assert" | "steps">, environment?: NodeJS.ProcessEnv, platform?: NodeJS.Platform): IPlaytestDiagnostic | undefined;
298
- declare function buildReport(config: IStandalonePlaytestConfig, scenario: IPlaytestScenario, beforeSnapshot: IPlaytestObservationSnapshot | undefined, afterSnapshot: IPlaytestObservationSnapshot | undefined, consoleEntries: Array<{
299
- text: string;
300
- type: string;
301
- }>, networkEntries: Array<{
302
- method: string;
303
- url: string;
304
- }>, pathLength?: number | undefined, hud?: Record<string, {
305
- after?: unknown;
306
- before?: unknown;
307
- }>, runtimeReady?: boolean, visual?: IPlaytestObservations["visual"], labeledSamples?: readonly LabeledPlaytestSample[]): IStandalonePlaytestReport;
308
-
309
442
  interface IAndroidPlaytestDependencies {
443
+ abortSignal?: AbortSignal;
310
444
  driver?: IAndroidDriver;
311
- transport?: DevicePlaytestTransport;
445
+ transport?: IDevicePlaytestTransport;
312
446
  }
313
447
  interface IDevicePlaytestDriver {
314
448
  captureConsole(): Promise<Array<{
315
449
  text: string;
316
450
  type: string;
317
451
  }>>;
452
+ deviceSerial?(): string | undefined;
318
453
  isAlive(): Promise<boolean>;
319
- prepare(endpoint: string, mailboxRoot?: string): Promise<void>;
454
+ prepare(endpoint: string, mailboxRoot?: string, viewport?: {
455
+ height: number;
456
+ width: number;
457
+ }): Promise<void>;
320
458
  readFile?(path: string): Promise<string | undefined>;
321
459
  removeFile?(path: string): Promise<void>;
460
+ runAdb?(args: readonly string[]): Promise<string>;
322
461
  screenshot(path: string): Promise<void>;
462
+ setPointers?(pointers: readonly IAndroidPointer[]): Promise<IAndroidPointerInjection>;
463
+ tap?(x: number, y: number): Promise<void>;
464
+ hideKeyboard?(): Promise<boolean>;
465
+ startScreenRecording?(): Promise<void>;
323
466
  stop(): Promise<void>;
467
+ stopScreenRecording?(path: string): Promise<void>;
324
468
  writeFile?(path: string, contents: string): Promise<void>;
325
469
  }
326
470
  interface IDevicePlaytestTarget {
471
+ abortCleanup?: () => Promise<void>;
472
+ abortSignal?: AbortSignal;
327
473
  driver: IDevicePlaytestDriver;
328
474
  mailboxPaths: ReturnType<typeof androidMailboxPaths>;
329
- name: "android" | "ios";
475
+ name: "android" | "desktop" | "ios";
330
476
  processName: string;
331
- transport?: DevicePlaytestTransport;
477
+ transport?: IDevicePlaytestTransport;
332
478
  }
333
479
  declare function runAndroidPlaytest(config: IStandalonePlaytestConfig, dependencies?: IAndroidPlaytestDependencies): Promise<IStandalonePlaytestReport>;
334
480
  declare function runDevicePlaytest(config: IStandalonePlaytestConfig, target: IDevicePlaytestTarget): Promise<IStandalonePlaytestReport>;
335
481
 
482
+ interface IDesktopPlaytestDriverOptions {
483
+ args?: readonly string[];
484
+ cwd?: string;
485
+ env?: NodeJS.ProcessEnv;
486
+ executable: string;
487
+ mailboxRoot?: string;
488
+ screenshotTimeoutMs?: number;
489
+ }
490
+ /** A local mailbox implementation with atomic request writes. */
491
+ declare class LocalDeviceMailbox {
492
+ read(path: string): Promise<string | undefined>;
493
+ remove(path: string): Promise<void>;
494
+ write(path: string, contents: string): Promise<void>;
495
+ }
496
+ /**
497
+ * Launches a packaged native desktop game and exposes the same driver contract as device runs.
498
+ * The native runtime consumes TN_PLAYTEST_MAILBOX_ROOT before it evaluates the game entry.
499
+ */
500
+ declare class DesktopPlaytestDriver implements IDevicePlaytestDriver {
501
+ private readonly options;
502
+ private child?;
503
+ private mailboxRoot?;
504
+ private readonly consoleEntries;
505
+ private readonly pendingOutput;
506
+ constructor(options: IDesktopPlaytestDriverOptions);
507
+ captureConsole(): Promise<Array<{
508
+ text: string;
509
+ type: string;
510
+ }>>;
511
+ isAlive(): Promise<boolean>;
512
+ prepare(_endpoint: string, mailboxRoot?: string): Promise<void>;
513
+ screenshot(path: string): Promise<void>;
514
+ stop(): Promise<void>;
515
+ private recordOutput;
516
+ private flushOutput;
517
+ }
518
+
519
+ interface IDesktopPlaytestDependencies {
520
+ driver?: IDevicePlaytestDriver;
521
+ mailboxRoot?: string;
522
+ transport?: IDevicePlaytestTransport;
523
+ }
524
+ declare function runDesktopPlaytest(config: IStandalonePlaytestConfig, dependencies?: IDesktopPlaytestDependencies): Promise<IStandalonePlaytestReport>;
525
+
336
526
  declare function initStandalonePlaytest(projectPath?: string): Promise<{
337
527
  created: string[];
338
528
  }>;
@@ -377,14 +567,15 @@ declare class XcrunIosDriver implements IDevicePlaytestDriver {
377
567
  declare function parseLaunchedPid(output: string): string;
378
568
 
379
569
  interface IIosPlaytestDependencies {
570
+ abortSignal?: AbortSignal;
380
571
  driver?: IDevicePlaytestDriver & {
381
572
  getMailboxRoot?(): string;
382
573
  };
383
- transport?: DevicePlaytestTransport;
574
+ transport?: IDevicePlaytestTransport;
384
575
  }
385
576
  declare function runIosPlaytest(config: IStandalonePlaytestConfig, dependencies?: IIosPlaytestDependencies): Promise<IStandalonePlaytestReport>;
386
577
 
387
578
  declare function requireAssertions(value: IPlaytestScenario["assert"], scenarioPath: string): NonNullable<IPlaytestScenario["assert"]>;
388
579
  declare function recordToScenario(value: unknown, scenarioPath?: string, oracleValue?: unknown): IPlaytestScenario;
389
580
 
390
- export { ANDROID_TRANSPORT_CAPABILITIES, AdbAndroidDriver, type BridgeTransport, DeviceBridgeTransport, DeviceMailboxTransport, type DevicePlaytestTransport, type IAndroidDriver, type IAndroidDriverOptions, type IAndroidPlaytestDependencies, type IDeviceMailbox, type IDeviceMailboxPaths, type IDevicePlaytestDriver, type IDevicePlaytestTarget, type IIosCommandOptions, type IIosDriverOptions, type IIosPlaytestDependencies, type IPlaytestBridgeClient, type IPlaytestFlagHelp, type IPlaytestServerConfig, type IRunIosCommand, type IStandalonePlaytestConfig, type IStandalonePlaytestReport, type IosTransportKind, PLAYTEST_FLAGS, PlaytestBridgeError, PlaytestCliUsageError, PlaywrightTransport, STANDALONE_PLAYTEST_OBSERVATION_FIELDS, XcrunIosDriver, androidMailboxPaths, buildReport, connectPlaytestBridge, connectPlaytestBridgeTransport, deviceMailboxPaths, discoverAdb, formatUsage, initStandalonePlaytest, parseLaunchedPid, parseStandalonePlaytestArgs, preflightDisplay, recordToScenario, requireAssertions, runAndroidPlaytest, runDevicePlaytest, runIosPlaytest, runStandalonePlaytest, validateDeviceEndpoint };
581
+ export { ANDROID_TRANSPORT_CAPABILITIES, AdbAndroidDriver, DesktopPlaytestDriver, DeviceBridgeTransport, DeviceMailboxTransport, type IAndroidDriver, type IAndroidDriverOptions, type IAndroidPlaytestDependencies, type IAndroidPointer, type IAndroidPointerInjection, type IBridgeTransport, type IBrowserPointerChange, type IDesktopPlaytestDependencies, type IDesktopPlaytestDriverOptions, type IDeviceMailbox, type IDeviceMailboxPaths, type IDevicePlaytestDriver, type IDevicePlaytestTarget, type IDevicePlaytestTransport, type IIosCommandOptions, type IIosDriverOptions, type IIosPlaytestDependencies, ILabeledPlaytestSample, IMovementSampleInterval, type IPlaytestBridgeClient, type IRunIosCommand, IRunnerConsoleEntry, IStandalonePlaytestConfig, IStandalonePlaytestReport, type IStandalonePlaytestRunOptions, type IosTransportKind, LocalDeviceMailbox, PERFORMANCE_BROWSER_ARGS, PlaytestBridgeError, PlaywrightTransport, STANDALONE_PLAYTEST_OBSERVATION_FIELDS, WEBGPU_BROWSER_ARGS, XcrunIosDriver, advanceFixedStep, advanceTimeoutMs, androidMailboxPaths, androidTouchBatches, batchArtifactDirectory, boundedTeardownStep, bridgeWaitTimeoutMs, buildReport, captureVisualSurface, connectPlaytestBridge, connectPlaytestBridgeTransport, deviceMailboxPaths, deviceTimeoutDiagnostic, discoverAdb, handlePlaytestSignal, initStandalonePlaytest, isRuntimeReadout, keyboardIsShown, openPageAndConnectBridge, pageLifecycleDiagnostic, parseAndroidConsole, parseLaunchedPid, playtestStepDrivesMovement, preflightDisplay, reconcileBrowserPointers, recordToScenario, requireAssertions, resolveBrowserArguments, resolveManagedServerCommand, resolveManagedServerConfig, rotatedTouchPosition, runAndroidPlaytest, runDesktopPlaytest, runDevicePlaytest, runIosPlaytest, runStandalonePlaytest, runStandalonePlaytests, softwareAdapterName, substituteManagedPort, tapCommand, touchRotationFromWindowDump, validateDeviceEndpoint, viewportPresentationCommands, viewportRestoreCommands, writeCaptureProvenance, writeObservationArtifacts };