@threenative/playtest 0.2.0 → 0.3.1

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.
@@ -0,0 +1,785 @@
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, z as IPlaytestSetupApplication, l as IPlaytestDeviceMetricsObservation, e as IPlaytestDiagnostic, w as IPlaytestProtocolDiagnostic, i as IPlaytestArtifactRequest, v as IPlaytestPointer } from '../diagnostics-f8464bJw.js';
3
+ import { Page } from 'playwright';
4
+ import { I as IStandalonePlaytestConfig, b as IRunnerConsoleEntry, c as ILabeledPlaytestSample, d as IMovementSampleInterval, a as IStandalonePlaytestReport } from '../shared-BGwYk5HG.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-BGwYk5HG.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;
20
+
21
+ /** The only seam between assertion orchestration and an application bridge. */
22
+ interface IBridgeTransport {
23
+ readonly capabilities: readonly string[];
24
+ call<T>(method: string, argument?: unknown, timeoutMs?: number): Promise<T>;
25
+ close(): Promise<void>;
26
+ waitForBridge(timeoutMs: number): Promise<boolean>;
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;
37
+ declare class PlaytestBridgeError extends Error {
38
+ readonly diagnostic: IPlaytestProtocolDiagnostic;
39
+ constructor(diagnostic: IPlaytestProtocolDiagnostic);
40
+ }
41
+ interface IPlaytestBridgeClient {
42
+ advance(ticks: number): Promise<void>;
43
+ applySetup(request: IPlaytestSetupRequest): Promise<void>;
44
+ close(): Promise<void>;
45
+ drainEvents(limit?: number): Promise<JsonValue[]>;
46
+ description: IPlaytestBridgeDescription;
47
+ /** Setup applied before the handshake released a held game, when the scenario declared setup. */
48
+ setupApplication?: IPlaytestSetupApplication;
49
+ /** Re-reads the bridge's readiness, including startup progress when it reports any. */
50
+ readiness(): Promise<IPlaytestBridgeReady>;
51
+ sample(request: IPlaytestSampleRequest): Promise<IPlaytestObservationSnapshot>;
52
+ }
53
+ declare class PlaywrightTransport implements IBridgeTransport {
54
+ private readonly page;
55
+ private readonly operationTimeoutMs;
56
+ readonly capabilities: readonly ["browser.canvas", "browser.console", "browser.dom", "browser.input", "browser.network", "browser.screenshot", "browser.trace", "runtime.diagnostics", "runtime.ui"];
57
+ constructor(page: Page, operationTimeoutMs?: number);
58
+ call<T>(method: string, argument?: unknown, timeoutMs?: number): Promise<T>;
59
+ close(): Promise<void>;
60
+ waitForBridge(timeoutMs: number): Promise<boolean>;
61
+ }
62
+ declare function connectPlaytestBridge(page: Page, scenario: IPlaytestScenario, timeoutMs?: number): Promise<IPlaytestBridgeClient | undefined>;
63
+ /**
64
+ * How long to wait for the page to install its playtest bridge.
65
+ *
66
+ * The bridge appears during application startup, not during a request/response round trip, so
67
+ * `operationTimeoutMs` is the wrong budget for it by construction — the same mistake, in the same
68
+ * direction, as timing a bulk `advance` with it. On a software-rendered two-core runner the
69
+ * scaffolded starter spends seconds in first-use compilation before the bridge exists, and the run
70
+ * was reported as `TN_PLAYTEST_BRIDGE_MISSING` with `frames: 0`: not a page without a bridge, a
71
+ * page that had not finished booting yet.
72
+ *
73
+ * One operation plus the startup budget, matching `advanceTimeoutMs`. A page that genuinely
74
+ * installs no bridge still fails with the same diagnostic, just later.
75
+ */
76
+ declare function bridgeWaitTimeoutMs(operationMs?: number): number;
77
+ declare function connectPlaytestBridgeTransport(transport: IBridgeTransport, scenario: IPlaytestScenario, timeoutMs?: number, target?: string): Promise<IPlaytestBridgeClient | undefined>;
78
+
79
+ /** Capture the largest rendered canvas without composited DOM overlays. */
80
+ declare function captureVisualSurface(page: Page, artifactPath?: string): Promise<Buffer | undefined>;
81
+ /**
82
+ * The core bridge is installed before an async scene load completes, so its describe/ready
83
+ * handshake can finish one browser frame before the fixed-step loop starts. Retry only that
84
+ * exact startup race; a stopped loop that does not recover remains a runner failure.
85
+ */
86
+ declare function advanceFixedStep(page: Page, bridge: Pick<IPlaytestBridgeClient, "advance">, ticks: number): Promise<void>;
87
+ declare function playtestStepDrivesMovement(step: IPlaytestScenario["steps"][number], hasHeldInput: boolean): boolean;
88
+
89
+ /**
90
+ * A published diagnostic that is unmistakably a *readout* rather than an error.
91
+ *
92
+ * The bridge's `diagnostics` channel is typed `() => JsonValue[]` and the generated project
93
+ * AGENTS.md says it "returns current runtime diagnostics", so a game publishes its debug HUD
94
+ * through it — that is the documented use. Every entry then landed in `recentRuntimeErrors`, and
95
+ * a proof with `noRuntimeDiagnostics` failed the build for owning a frame counter. Round 9 lost
96
+ * a sealed scenario to `{id:"fps",label:"FPS",value:30}` being counted as a runtime error.
97
+ *
98
+ * This does **not** guess. Ambiguous entries stay errors, because this package fails closed and
99
+ * an error counter that quietly stops counting is the exact defect it exists to prevent. Only
100
+ * the unambiguous readout shape — a labelled scalar, carrying no error marker — is reclassified,
101
+ * and nothing is dropped: readouts move to `runtimeReadouts` on the same object and stay observable.
102
+ */
103
+ declare function isRuntimeReadout(entry: unknown): boolean;
104
+
105
+ declare function resolveManagedServerCommand(config: IStandalonePlaytestConfig, dynamicPort?: number): string;
106
+ declare function substituteManagedPort(command: string, port: number): string;
107
+ /**
108
+ * Await one teardown step, but never longer than `timeoutMs`. Returns true when the step
109
+ * finished (or there was nothing to do) and false when it ran out of time, so the caller can
110
+ * escalate. Teardown runs after the report is written, so a step that hangs costs the process
111
+ * its exit rather than costing the run its result.
112
+ */
113
+ declare function boundedTeardownStep(step: Promise<unknown> | undefined, timeoutMs: number): Promise<boolean>;
114
+ interface IPageLifecycle {
115
+ closed: boolean;
116
+ crashed: boolean;
117
+ /** Every main-frame navigation, including the run's own initial one. */
118
+ frameNavigations: string[];
119
+ /** Main-frame navigations after the handshake settled — the ones that break a run. */
120
+ navigations: string[];
121
+ settled: boolean;
122
+ /** The last console lines before the failure, which is where a device loss announces itself. */
123
+ tail: string[];
124
+ }
125
+ /**
126
+ * Playwright reports a crashed renderer and a navigated document with the same
127
+ * "Execution context was destroyed" message, and the two have opposite fixes: a crash is an
128
+ * environment or content problem, a navigation is the page moving under the run. The listeners
129
+ * on the page record which one happened, so the report names it rather than falling through to
130
+ * the unexplained-error catch-all. Returns undefined when the error is neither, leaving it to
131
+ * propagate untouched.
132
+ */
133
+ declare function pageLifecycleDiagnostic(error: unknown, lifecycle: IPageLifecycle, url: string): IPlaytestProtocolDiagnostic | undefined;
134
+ /**
135
+ * Navigate and complete the bridge handshake, re-navigating when the page reloads itself
136
+ * before the handshake finishes. This never retries past the handshake: no observation has
137
+ * been taken and no assertion has been evaluated yet, so a reattempt cannot hide a failure.
138
+ * A bridge that is genuinely missing or incompatible still fails on its own diagnostic, and
139
+ * an exhausted retry budget fails closed on TN_PLAYTEST_PAGE_NAVIGATED rather than passing.
140
+ */
141
+ declare function openPageAndConnectBridge(page: Page, config: IStandalonePlaytestConfig, scenario: IPlaytestScenario): Promise<IPlaytestBridgeClient | undefined>;
142
+
143
+ declare const STANDALONE_PLAYTEST_OBSERVATION_FIELDS: readonly ["components", "componentSeries", "console", "effectLogBefore", "framebufferCoverage", "hud", "network", "physicsDebugSeries", "performanceSeries", "pipelineCensus", "renderChain", "physicsDebugBefore", "resources", "resourceSeries", "runtimeDiagnostics", "runtimeDiagnosticsBefore", "runtimeObservations", "scene", "sceneNodes", "signals", "signalSeries", "startup", "visual"];
144
+
145
+ declare function handlePlaytestSignal(teardown: (stopManagedServer: boolean) => Promise<void>, setExitCode?: (code: number) => void, exit?: (code: number) => void, target?: string, writeMessage?: (message: string) => void): Promise<void>;
146
+ declare function writeCaptureProvenance(artifactDirectory: string, provenance: IPlaytestCaptureProvenance): Promise<void>;
147
+ /**
148
+ * Diagnostics name `console.json` and `runtime-trace.json`, and `artifacts.console`,
149
+ * `artifacts.network` and `artifacts.runtimeTrace` accept a request for them. Neither was
150
+ * written: a build hitting TN_PLAYTEST_CONSOLE_ERROR found the artifact directory holding
151
+ * only `after.png` and `capture.json`, and had to reconstruct the errors from provenance.
152
+ * A message that names a file the runner never writes sends the reader somewhere empty, so
153
+ * write each one whenever it has content or was asked for.
154
+ */
155
+ declare function writeObservationArtifacts(artifactDirectory: string, requested: IPlaytestArtifactRequest | undefined, observations: {
156
+ console: readonly unknown[];
157
+ network: readonly unknown[];
158
+ runtimeTrace: {
159
+ readonly recentRuntimeErrors?: readonly unknown[];
160
+ readonly [key: string]: unknown;
161
+ } | undefined;
162
+ }): Promise<readonly string[]>;
163
+ interface IStandalonePlaytestRunOptions {
164
+ managedServer?: ChildProcess;
165
+ }
166
+ declare function runStandalonePlaytest(config: IStandalonePlaytestConfig, options?: IStandalonePlaytestRunOptions): Promise<IStandalonePlaytestReport>;
167
+ declare function runStandalonePlaytests(config: IStandalonePlaytestConfig): Promise<readonly IStandalonePlaytestReport[]>;
168
+ declare function batchArtifactDirectory(base: string, scenarioPath: string, index: number): string;
169
+ declare function resolveManagedServerConfig(config: IStandalonePlaytestConfig): Promise<IStandalonePlaytestConfig>;
170
+
171
+ declare const WEBGPU_BROWSER_ARGS: readonly ["--ozone-platform=x11", "--enable-unsafe-webgpu", "--disable-gpu-sandbox", "--ignore-gpu-blocklist", "--enable-features=Vulkan"];
172
+ /** Allow performance probes to sample render work instead of Xvfb's compositor cadence. */
173
+ declare const PERFORMANCE_BROWSER_ARGS: readonly ["--disable-frame-rate-limit", "--disable-gpu-vsync"];
174
+ declare function resolveBrowserArguments(browserArgs: readonly string[] | undefined): string[];
175
+ /**
176
+ * Name a software adapter from what `adapter.info` reported. Every field is searched because
177
+ * which one carries the giveaway depends on the platform: Linux Dawn puts `swiftshader` in
178
+ * `architecture`, Mesa reports `llvmpipe` in `description`, and a headless Windows run says
179
+ * `Microsoft Basic Render Driver` in `device`.
180
+ */
181
+ declare function softwareAdapterName(adapter: Readonly<Record<string, string>> | undefined): string | undefined;
182
+ interface IBrowserPointerChange {
183
+ isPrimary: boolean;
184
+ pointer: Required<IPlaytestPointer>;
185
+ type: "pointerdown" | "pointermove" | "pointerup";
186
+ }
187
+ declare function reconcileBrowserPointers(previous: ReadonlyMap<number, Required<IPlaytestPointer>>, next: readonly IPlaytestPointer[]): IBrowserPointerChange[];
188
+
189
+ interface IAndroidDriverOptions {
190
+ activity: string;
191
+ adbPath?: string;
192
+ packageName: string;
193
+ serial?: string;
194
+ /** Android user id to target; when omitted, the device's current foreground user is detected. */
195
+ user?: string;
196
+ /**
197
+ * The rotation between the touchscreen's raw axes and the frame the app draws in, when the
198
+ * device cannot be asked.
199
+ *
200
+ * Normally this is read from the window — `dumpsys window`'s `mRotation`, inverted, and then
201
+ * `dumpsys input`'s `SurfaceOrientation` and the `user_rotation` setting behind it. Those two
202
+ * older sources are why this option exists: an orientation-locked game on a device whose
203
+ * display never rotated reads 0 from both while its window is turned 90° from the panel, so an
204
+ * injected touch lands somewhere else entirely and every input assertion fails for a reason
205
+ * that has nothing to do with the game.
206
+ *
207
+ * Set explicitly to make such a run reproducible, and say so in the evidence. Fails closed on
208
+ * anything but 0, 1, 2 or 3.
209
+ */
210
+ touchRotation?: number;
211
+ }
212
+ interface IAndroidDriver {
213
+ captureConsole(): Promise<Array<{
214
+ text: string;
215
+ type: string;
216
+ }>>;
217
+ /** The device this driver is bound to, when it knows; reported next to its metric samples. */
218
+ deviceSerial?(): string | undefined;
219
+ isAlive(): Promise<boolean>;
220
+ prepare(endpoint: string, mailboxRoot?: string, viewport?: {
221
+ height: number;
222
+ width: number;
223
+ }): Promise<void>;
224
+ readFile?(path: string): Promise<string | undefined>;
225
+ removeFile?(path: string): Promise<void>;
226
+ /** Raw adb passthrough, so the host can measure the device itself. Read-only probes only. */
227
+ runAdb?(args: readonly string[]): Promise<string>;
228
+ screenshot(path: string): Promise<void>;
229
+ setPointers?(pointers: readonly IAndroidPointer[]): Promise<IAndroidPointerInjection>;
230
+ startScreenRecording?(): Promise<void>;
231
+ /** One OS tap in viewport pixels. Works on emulators and physical devices alike. */
232
+ tap?(x: number, y: number): Promise<void>;
233
+ /** Put the soft keyboard away, and report whether one was up. */
234
+ hideKeyboard?(): Promise<boolean>;
235
+ stop(): Promise<void>;
236
+ stopScreenRecording?(path: string): Promise<void>;
237
+ writeFile?(path: string, contents: string): Promise<void>;
238
+ }
239
+ interface IAndroidPointer {
240
+ buttons?: number;
241
+ id: number;
242
+ x: number;
243
+ y: number;
244
+ }
245
+ interface IAndroidPointerInjection {
246
+ activeIds: number[];
247
+ injection: "adb-emu-event-protocol-b";
248
+ rotation: number;
249
+ trackingIds: number[];
250
+ }
251
+ interface IAndroidTouchViewport {
252
+ device: {
253
+ height: number;
254
+ width: number;
255
+ };
256
+ logical: {
257
+ bottom: number;
258
+ left: number;
259
+ right: number;
260
+ top: number;
261
+ };
262
+ orientation: number | undefined;
263
+ physical: {
264
+ bottom: number;
265
+ left: number;
266
+ right: number;
267
+ top: number;
268
+ };
269
+ }
270
+ declare class AdbAndroidDriver implements IAndroidDriver {
271
+ private readonly options;
272
+ private static readonly COVERAGE_VIDEO_PATH;
273
+ private readonly adbPath;
274
+ private screenrecord?;
275
+ private screenrecordError?;
276
+ private readonly touchSlots;
277
+ private nextTrackingId;
278
+ private rotation?;
279
+ private touchViewport?;
280
+ private readonly user?;
281
+ private activeUser?;
282
+ private viewportPresented;
283
+ constructor(options: IAndroidDriverOptions);
284
+ prepare(endpoint: string, mailboxRoot?: string, viewport?: {
285
+ height: number;
286
+ width: number;
287
+ }): Promise<void>;
288
+ private resolveUser;
289
+ /**
290
+ * Put the device into the scenario's viewport, and fail closed if it did not take.
291
+ *
292
+ * A silent failure here is the expensive one: the run continues, the touches arrive, the
293
+ * assertions go red, and the report blames the game for a device that was never showing the
294
+ * viewport the scenario asked for.
295
+ */
296
+ private presentViewport;
297
+ tap(x: number, y: number): Promise<void>;
298
+ /**
299
+ * Dismiss the soft keyboard and wait for it to actually be gone.
300
+ *
301
+ * Measured on the physical Pixel 8: focusing a text field opens the IME, the WebView reflows
302
+ * into the space left above it, and the page's centred menu rides up — so a coordinate computed
303
+ * against the scenario's viewport now points at the keyboard. A tap there does not merely miss
304
+ * the control; it types a character into the field it meant to submit.
305
+ *
306
+ * BACK is the dismissal the platform guarantees. The wait is the point: the reflow happens on
307
+ * the next layout pass, and a click sent into the middle of it lands wherever the menu was
308
+ * halfway through moving.
309
+ */
310
+ hideKeyboard(): Promise<boolean>;
311
+ captureConsole(): Promise<Array<{
312
+ text: string;
313
+ type: string;
314
+ }>>;
315
+ screenshot(path: string): Promise<void>;
316
+ startScreenRecording(): Promise<void>;
317
+ stopScreenRecording(path: string): Promise<void>;
318
+ isAlive(): Promise<boolean>;
319
+ setPointers(pointers: readonly IAndroidPointer[]): Promise<IAndroidPointerInjection>;
320
+ readFile(path: string): Promise<string | undefined>;
321
+ removeFile(path: string): Promise<void>;
322
+ stop(): Promise<void>;
323
+ private readRotation;
324
+ writeFile(path: string, contents: string): Promise<void>;
325
+ deviceSerial(): string | undefined;
326
+ /**
327
+ * The device-metrics probes read `dumpsys`, `logcat` and sysfs through here. Deliberately a
328
+ * thin passthrough rather than a metrics API: the parsing belongs to deviceMetrics.ts, which
329
+ * is unit-tested against real captured device output.
330
+ */
331
+ runAdb(args: readonly string[]): Promise<string>;
332
+ private adb;
333
+ private waitForScreenRecorder;
334
+ private abortScreenRecording;
335
+ private serialArgs;
336
+ }
337
+ declare function parseAndroidConsole(output: string): Array<{
338
+ text: string;
339
+ type: string;
340
+ }>;
341
+ declare function parseAndroidTouchViewport(output: string): IAndroidTouchViewport;
342
+ /** Map a normalized logical-display point to the raw touchscreen axes. */
343
+ declare function touchPositionForViewport(x: number, y: number, viewport: IAndroidTouchViewport, rotationOverride?: number): [number, number];
344
+ /**
345
+ * Splits slot identity from coordinates into separate synced `adb emu event send` batches.
346
+ *
347
+ * The emulator console drops ABS_MT_POSITION_X/Y from any batch that also carries an
348
+ * ABS_MT_TRACKING_ID: the command reports `OK` and the coordinates never reach the device, so
349
+ * every contact lands at (0, 0) and a two-finger gesture reads as two touches in the same
350
+ * screen half — the exact failure that made the simultaneous-touch proof unprovable.
351
+ * Confirmed against `getevent -lt /dev/input/event2` on emulator 36.6.11 with the android-35
352
+ * google_apis image. Identity goes first so a slot exists before it is positioned.
353
+ */
354
+ declare function androidTouchBatches(identity: readonly string[], positions: readonly string[]): string[][];
355
+ /**
356
+ * Confirm that Android reported the requested viewport, including the physical-size omission.
357
+ *
358
+ * @situation verify that an Android device presented the requested viewport
359
+ * @situation accept the physical panel size when `wm size` omits its override line
360
+ * @example viewportPresentationObserved(undefined, "1080x2400", { width: 1080, height: 2400 });
361
+ */
362
+ declare function viewportPresentationObserved(override: string | undefined, expected: string | undefined, physical: {
363
+ height: number;
364
+ width: number;
365
+ }): boolean;
366
+ /**
367
+ * The touch rotation for the window `dumpsys window` just described, or `undefined`.
368
+ *
369
+ * `mRotation` says how far the window's content is turned from the panel's natural frame.
370
+ * {@link rotatedTouchPosition} converts the other way — a point in that content back to the
371
+ * panel's raw axes — so the value it needs is the inverse, and handing it `mRotation` directly
372
+ * is a 180-degree error on either odd rotation.
373
+ *
374
+ * This is the source of truth because it describes the *window*. `dumpsys input`'s
375
+ * `SurfaceOrientation` is absent on the emulator, and `user_rotation` is the user's preference:
376
+ * an orientation-locked game on a device the user never turned reads 0 there while its window
377
+ * is turned 90 degrees off the panel, so every injected touch lands somewhere else.
378
+ */
379
+ declare function touchRotationFromWindowDump(dump: string): number | undefined;
380
+ /**
381
+ * Make the device present a scenario's declared viewport, one device pixel per CSS pixel.
382
+ *
383
+ * A scenario's `viewport` is a declared test condition, and the browser target honours it by
384
+ * sizing the window. Without the same courtesy here, a UI page lays out at whatever CSS viewport
385
+ * the device's density happens to give — 914x411 on a 2400x1080 panel at 420dpi — and a step
386
+ * that names a point in viewport pixels lands on whatever the device's own layout put there.
387
+ * Nothing about that failure looks like a coordinate problem: the touch arrives, the host
388
+ * hit-tests it honestly, and the control simply is not where the scenario said.
389
+ *
390
+ * Density 160 is the whole mechanism: it makes `devicePixelRatio` 1, so a viewport pixel, a CSS
391
+ * pixel and a device pixel are the same pixel and the page lays out exactly as it does on web.
392
+ * The size is written in the panel's natural frame, which is why it is transposed for the
393
+ * portrait-natural devices every phone and emulator here happens to be.
394
+ */
395
+ declare function viewportPresentationCommands(viewport: {
396
+ height: number;
397
+ width: number;
398
+ }, physical: {
399
+ height: number;
400
+ width: number;
401
+ }): string[][];
402
+ /**
403
+ * One OS-level tap, in the display's current orientation.
404
+ *
405
+ * With the viewport presented, that orientation *is* the scenario's viewport and the coordinate
406
+ * needs no rotation — which is the second reason to prefer this over the emulator's pointer
407
+ * protocol. The first is that `adb emu event send` exists only on emulators, and a click step
408
+ * that only works on an emulator is a click step that does not work.
409
+ */
410
+ declare function tapCommand(x: number, y: number): string[];
411
+ /** Whether an input method window is on screen, from `dumpsys input_method`. */
412
+ declare function keyboardIsShown(dump: string): boolean;
413
+ /**
414
+ * Undo the presentation.
415
+ *
416
+ * `reset` and never the numbers read beforehand: a run that crashed between reading and writing
417
+ * would restore a size it had already replaced, and leave the device quietly wrong for whoever
418
+ * measures on it next.
419
+ */
420
+ declare function viewportRestoreCommands(): string[][];
421
+ declare function rotatedTouchPosition(x: number, y: number, rotation: number): [number, number];
422
+ declare function discoverAdb(environment?: NodeJS.ProcessEnv): string;
423
+
424
+ declare const ANDROID_TRANSPORT_CAPABILITIES: readonly ["browser.console", "browser.input", "browser.screenshot", "device.metrics", "runtime.diagnostics"];
425
+ interface IDeviceMailbox {
426
+ read(path: string): Promise<string | undefined>;
427
+ remove(path: string): Promise<void>;
428
+ write(path: string, contents: string): Promise<void>;
429
+ }
430
+ interface IDeviceMailboxPaths {
431
+ request: string;
432
+ response: string;
433
+ }
434
+ /** The raw response and request position captured before a mailbox file is consumed. */
435
+ interface IDeviceResponseObservation {
436
+ body: string;
437
+ method: string;
438
+ order: number;
439
+ requestId: string;
440
+ }
441
+ interface IDevicePlaytestTransport extends IBridgeTransport {
442
+ start(): Promise<void>;
443
+ setResponseObserver?(observer: (observation: IDeviceResponseObservation) => void): void;
444
+ }
445
+ declare class DeviceBridgeTransport implements IDevicePlaytestTransport {
446
+ readonly capabilities: readonly ["browser.console", "browser.input", "browser.screenshot", "device.metrics", "runtime.diagnostics"];
447
+ readonly endpoint: URL;
448
+ private connected;
449
+ private nextId;
450
+ private readonly pending;
451
+ private readonly queue;
452
+ private server?;
453
+ private waiters;
454
+ constructor(endpoint: string);
455
+ start(): Promise<void>;
456
+ call<T>(method: string, argument?: unknown): Promise<T>;
457
+ close(): Promise<void>;
458
+ waitForBridge(timeoutMs: number): Promise<boolean>;
459
+ private handle;
460
+ private markConnected;
461
+ }
462
+ declare class DeviceMailboxTransport implements IDevicePlaytestTransport {
463
+ private readonly mailbox;
464
+ private readonly paths;
465
+ private readonly operationTimeoutMs;
466
+ readonly capabilities: readonly ["browser.console", "browser.input", "browser.screenshot", "device.metrics", "runtime.diagnostics"];
467
+ private connected;
468
+ private closed;
469
+ private nextId;
470
+ private nextOrder;
471
+ private responseObserver?;
472
+ constructor(mailbox: IDeviceMailbox, paths: IDeviceMailboxPaths, operationTimeoutMs?: number);
473
+ setResponseObserver(observer: (observation: IDeviceResponseObservation) => void): void;
474
+ start(): Promise<void>;
475
+ call<T>(method: string, argument?: unknown, timeoutMs?: number): Promise<T>;
476
+ close(): Promise<void>;
477
+ waitForBridge(timeoutMs: number): Promise<boolean>;
478
+ private waitForResponse;
479
+ private readResponse;
480
+ }
481
+ declare function androidMailboxPaths(packageName: string, root?: string): IDeviceMailboxPaths;
482
+ /**
483
+ * Names what stopped answering when an operation times out (PRD-167).
484
+ *
485
+ * A timed-out operation is ambiguous between two failures with different owners: a host whose
486
+ * process died mid-run, and a live host whose mailbox stopped polling. When the driver can prove
487
+ * the process exited, the diagnostic says so and carries the host's last console lines — a crash
488
+ * message must not be hidden behind a generic timeout.
489
+ */
490
+ declare function deviceTimeoutDiagnostic(diagnostic: IPlaytestProtocolDiagnostic, hostAlive: boolean | undefined, lastConsoleLines: readonly string[]): IPlaytestProtocolDiagnostic;
491
+ declare function deviceMailboxPaths(root: string): IDeviceMailboxPaths;
492
+ declare function validateDeviceEndpoint(value: string): URL;
493
+
494
+ interface IAndroidPlaytestDependencies {
495
+ abortSignal?: AbortSignal;
496
+ driver?: IAndroidDriver;
497
+ transport?: IDevicePlaytestTransport;
498
+ }
499
+ interface IDevicePlaytestDriver {
500
+ captureConsole(): Promise<Array<{
501
+ text: string;
502
+ type: string;
503
+ }>>;
504
+ deviceSerial?(): string | undefined;
505
+ isAlive(): Promise<boolean>;
506
+ prepare(endpoint: string, mailboxRoot?: string, viewport?: {
507
+ height: number;
508
+ width: number;
509
+ }): Promise<void>;
510
+ readFile?(path: string): Promise<string | undefined>;
511
+ removeFile?(path: string): Promise<void>;
512
+ runAdb?(args: readonly string[]): Promise<string>;
513
+ screenshot(path: string): Promise<void>;
514
+ setPointers?(pointers: readonly IAndroidPointer[]): Promise<IAndroidPointerInjection>;
515
+ tap?(x: number, y: number): Promise<void>;
516
+ hideKeyboard?(): Promise<boolean>;
517
+ startScreenRecording?(): Promise<void>;
518
+ stop(): Promise<void>;
519
+ stopScreenRecording?(path: string): Promise<void>;
520
+ writeFile?(path: string, contents: string): Promise<void>;
521
+ }
522
+ interface IDevicePlaytestTarget {
523
+ abortCleanup?: () => Promise<void>;
524
+ abortSignal?: AbortSignal;
525
+ driver: IDevicePlaytestDriver;
526
+ mailboxPaths: ReturnType<typeof androidMailboxPaths>;
527
+ name: "android" | "desktop" | "ios";
528
+ processName: string;
529
+ transport?: IDevicePlaytestTransport;
530
+ }
531
+ declare function runAndroidPlaytest(config: IStandalonePlaytestConfig, dependencies?: IAndroidPlaytestDependencies): Promise<IStandalonePlaytestReport>;
532
+ declare function runDevicePlaytest(config: IStandalonePlaytestConfig, target: IDevicePlaytestTarget): Promise<IStandalonePlaytestReport>;
533
+
534
+ interface IDesktopPlaytestDriverOptions {
535
+ args?: readonly string[];
536
+ cwd?: string;
537
+ env?: NodeJS.ProcessEnv;
538
+ executable: string;
539
+ mailboxRoot?: string;
540
+ screenshotTimeoutMs?: number;
541
+ }
542
+ /** A local mailbox implementation with atomic request writes. */
543
+ declare class LocalDeviceMailbox {
544
+ read(path: string): Promise<string | undefined>;
545
+ remove(path: string): Promise<void>;
546
+ write(path: string, contents: string): Promise<void>;
547
+ }
548
+ /**
549
+ * Launches a packaged native desktop game and exposes the same driver contract as device runs.
550
+ * The native runtime consumes TN_PLAYTEST_MAILBOX_ROOT before it evaluates the game entry.
551
+ */
552
+ declare class DesktopPlaytestDriver implements IDevicePlaytestDriver {
553
+ private readonly options;
554
+ private child?;
555
+ private mailboxRoot?;
556
+ private readonly consoleEntries;
557
+ private readonly pendingOutput;
558
+ constructor(options: IDesktopPlaytestDriverOptions);
559
+ captureConsole(): Promise<Array<{
560
+ text: string;
561
+ type: string;
562
+ }>>;
563
+ isAlive(): Promise<boolean>;
564
+ prepare(_endpoint: string, mailboxRoot?: string): Promise<void>;
565
+ screenshot(path: string): Promise<void>;
566
+ stop(): Promise<void>;
567
+ private recordOutput;
568
+ private flushOutput;
569
+ }
570
+
571
+ interface IDesktopPlaytestDependencies {
572
+ driver?: IDevicePlaytestDriver;
573
+ /** Builds the driver when one is not injected, so a test can watch what it is given. */
574
+ driverFactory?: (options: IDesktopPlaytestDriverOptions) => IDevicePlaytestDriver;
575
+ mailboxRoot?: string;
576
+ transport?: IDevicePlaytestTransport;
577
+ }
578
+ declare function runDesktopPlaytest(config: IStandalonePlaytestConfig, dependencies?: IDesktopPlaytestDependencies): Promise<IStandalonePlaytestReport>;
579
+
580
+ declare function initStandalonePlaytest(projectPath?: string): Promise<{
581
+ created: string[];
582
+ }>;
583
+
584
+ type IosTransportKind = "device" | "simulator";
585
+ interface IIosDriverOptions {
586
+ appPath: string;
587
+ bundleId: string;
588
+ device?: string;
589
+ transport: IosTransportKind;
590
+ xcrunPath?: string;
591
+ }
592
+ interface IIosCommandOptions {
593
+ env?: NodeJS.ProcessEnv;
594
+ }
595
+ type IRunIosCommand = (args: readonly string[], options?: IIosCommandOptions) => Promise<string>;
596
+ declare class XcrunIosDriver implements IDevicePlaytestDriver {
597
+ private readonly options;
598
+ private readonly run;
599
+ private mailboxRoot?;
600
+ private pid?;
601
+ private suppressedResponse?;
602
+ constructor(options: IIosDriverOptions, run?: IRunIosCommand);
603
+ prepare(endpoint: string, mailboxRoot?: string): Promise<void>;
604
+ captureConsole(): Promise<Array<{
605
+ text: string;
606
+ type: string;
607
+ }>>;
608
+ isAlive(): Promise<boolean>;
609
+ screenshot(path: string): Promise<void>;
610
+ readFile(path: string): Promise<string | undefined>;
611
+ removeFile(path: string): Promise<void>;
612
+ stop(): Promise<void>;
613
+ writeFile(path: string, contents: string): Promise<void>;
614
+ getMailboxRoot(): string;
615
+ private prepareSimulator;
616
+ private prepareDevice;
617
+ private device;
618
+ private processName;
619
+ private mailboxPath;
620
+ }
621
+ declare function parseLaunchedPid(output: string): string;
622
+
623
+ interface IIosPlaytestDependencies {
624
+ abortSignal?: AbortSignal;
625
+ driver?: IDevicePlaytestDriver & {
626
+ getMailboxRoot?(): string;
627
+ };
628
+ transport?: IDevicePlaytestTransport;
629
+ }
630
+ declare function runIosPlaytest(config: IStandalonePlaytestConfig, dependencies?: IIosPlaytestDependencies): Promise<IStandalonePlaytestReport>;
631
+
632
+ declare function requireAssertions(value: IPlaytestScenario["assert"], scenarioPath: string): NonNullable<IPlaytestScenario["assert"]>;
633
+ declare function recordToScenario(value: unknown, scenarioPath?: string, oracleValue?: unknown): IPlaytestScenario;
634
+
635
+ /** Shared parser and aggregation for browser pipeline censuses and native pipeline markers. */
636
+ declare const PIPELINE_CAPTURE_VERSION: 1;
637
+ declare const PIPELINE_EVENT_MARKER = "TN_PIPELINE_EVENT:";
638
+ type PipelineCaptureSource = "browser" | "native";
639
+ type PipelineCaptureKind = "compute" | "render";
640
+ type PipelineCaptureMode = "sync" | "async";
641
+ type PipelineCaptureStatus = "created" | "failed" | "pending";
642
+ interface IPipelineCaptureShader {
643
+ readonly bytes: number;
644
+ readonly hash: string;
645
+ }
646
+ interface IPipelineCaptureProvenance {
647
+ readonly material?: {
648
+ readonly id?: number;
649
+ readonly name?: string;
650
+ readonly type?: string;
651
+ };
652
+ readonly object?: {
653
+ readonly id?: number;
654
+ readonly name?: string;
655
+ readonly uuid?: string;
656
+ };
657
+ readonly unknown: boolean;
658
+ }
659
+ interface IPipelineCaptureEvent {
660
+ readonly sequence: number;
661
+ readonly programIdentity: string;
662
+ readonly pipelineIdentity: string;
663
+ readonly kind: PipelineCaptureKind;
664
+ readonly pass: string;
665
+ readonly mode: PipelineCaptureMode;
666
+ readonly status: PipelineCaptureStatus;
667
+ readonly vertex?: IPipelineCaptureShader;
668
+ readonly fragment?: IPipelineCaptureShader;
669
+ readonly compute?: IPipelineCaptureShader;
670
+ readonly provenance: IPipelineCaptureProvenance;
671
+ readonly reasons: readonly string[];
672
+ readonly startedMs: number;
673
+ readonly settledMs?: number;
674
+ readonly serviceMs?: number;
675
+ readonly promiseMs?: number;
676
+ readonly queueMs?: number;
677
+ readonly wallMs?: number;
678
+ readonly label?: string;
679
+ readonly error?: string;
680
+ readonly beforeFirstPresent?: boolean;
681
+ }
682
+ interface IPipelineCaptureCounts {
683
+ readonly lookups: number;
684
+ readonly creations: number;
685
+ readonly failures: number;
686
+ readonly pending: number;
687
+ readonly uniquePrograms: number;
688
+ readonly uniquePipelines: number;
689
+ readonly recordedEvents: number;
690
+ readonly droppedEvents: number;
691
+ }
692
+ /**
693
+ * What ended the capture, and therefore what "complete" is allowed to mean.
694
+ *
695
+ * `finalized` is a process that exited: the host drained its compile pool and printed a final
696
+ * count. `checkpoint` is a live snapshot from a present, which is all a run ended by
697
+ * `am force-stop` can produce — every event up to that present is accounted for and nothing was
698
+ * still compiling, and the capture claims nothing about the run after it.
699
+ */
700
+ interface IPipelineCaptureBoundary {
701
+ readonly kind: "checkpoint" | "finalized";
702
+ readonly events: number;
703
+ readonly outstanding?: number;
704
+ readonly present?: number;
705
+ }
706
+ interface IPipelineCapture {
707
+ readonly version: number;
708
+ readonly source: PipelineCaptureSource;
709
+ readonly boundary?: IPipelineCaptureBoundary;
710
+ readonly complete: boolean;
711
+ readonly overflowed: boolean;
712
+ readonly backend?: Readonly<Record<string, unknown>>;
713
+ readonly clock?: Readonly<Record<string, unknown>>;
714
+ readonly build?: Readonly<Record<string, unknown>>;
715
+ readonly adapter?: Readonly<Record<string, unknown>>;
716
+ readonly firstPresent?: {
717
+ readonly boundaryMs: number;
718
+ readonly eventsSettled: number;
719
+ };
720
+ readonly counts: IPipelineCaptureCounts;
721
+ readonly events: readonly IPipelineCaptureEvent[];
722
+ readonly incompleteReasons: readonly string[];
723
+ }
724
+ interface IPipelinePassSummary {
725
+ readonly creations: number;
726
+ readonly failures: number;
727
+ readonly beforeFirstPresent: number;
728
+ /** Sum of observed device-call service durations; absent when the driver did not expose them. */
729
+ readonly serviceMs?: number;
730
+ readonly serviceSamples: number;
731
+ readonly pass: string;
732
+ }
733
+ interface IPipelineContributorSummary {
734
+ readonly creations: number;
735
+ readonly failures: number;
736
+ readonly label: string;
737
+ readonly sampleCount: number;
738
+ /** Sum of observed device-call service durations; absent when the driver did not expose them. */
739
+ readonly serviceMs?: number;
740
+ }
741
+ interface IPipelineProgramReasonSummary {
742
+ readonly creations: number;
743
+ readonly programIdentity: string;
744
+ readonly reasons: readonly string[];
745
+ }
746
+ interface IPipelineSizeTimePassSummary {
747
+ readonly meanBytes: number;
748
+ readonly meanServiceMs: number;
749
+ readonly pass: string;
750
+ readonly samples: number;
751
+ }
752
+ interface IPipelineSizeTimeSummary {
753
+ readonly byPass: readonly IPipelineSizeTimePassSummary[];
754
+ readonly samples: number;
755
+ readonly statement: string;
756
+ }
757
+ interface IPipelineWarmupSummary {
758
+ readonly afterFirstPresent: number;
759
+ readonly beforeFirstPresent: number;
760
+ readonly eventsSettledAtFirstPresent?: number;
761
+ readonly total: number;
762
+ readonly unreported: number;
763
+ }
764
+ interface IPipelineSummary {
765
+ readonly adapter?: Readonly<Record<string, unknown>>;
766
+ readonly boundary?: IPipelineCaptureBoundary;
767
+ readonly build?: Readonly<Record<string, unknown>>;
768
+ readonly complete: boolean;
769
+ readonly counts: IPipelineCaptureCounts;
770
+ readonly contributors: readonly IPipelineContributorSummary[];
771
+ readonly incompleteReasons: readonly string[];
772
+ readonly passTotals: readonly IPipelinePassSummary[];
773
+ readonly programReasons: readonly IPipelineProgramReasonSummary[];
774
+ readonly sizeTime: IPipelineSizeTimeSummary;
775
+ readonly source: PipelineCaptureSource;
776
+ readonly warmup: IPipelineWarmupSummary;
777
+ }
778
+ /** Parse a capture file, either as a JSON browser census or a native log containing markers. */
779
+ declare function parsePipelineCapture(input: string | unknown): IPipelineCapture;
780
+ /** Parse only native marker lines, preserving the same malformed-input contract as perf. */
781
+ declare function parsePipelineEventMarkers(text: string): IPipelineCaptureEvent[];
782
+ declare function summarizePipelineCapture(capture: IPipelineCapture): IPipelineSummary;
783
+ declare function formatPipelineSummary(summary: IPipelineSummary): string;
784
+
785
+ export { ANDROID_TRANSPORT_CAPABILITIES, AdbAndroidDriver, DesktopPlaytestDriver, DeviceBridgeTransport, DeviceMailboxTransport, type IAndroidDriver, type IAndroidDriverOptions, type IAndroidPlaytestDependencies, type IAndroidPointer, type IAndroidPointerInjection, type IAndroidTouchViewport, type IBridgeTransport, type IBrowserPointerChange, type IDesktopPlaytestDependencies, type IDesktopPlaytestDriverOptions, type IDeviceMailbox, type IDeviceMailboxPaths, type IDevicePlaytestDriver, type IDevicePlaytestTarget, type IDevicePlaytestTransport, type IDeviceResponseObservation, type IIosCommandOptions, type IIosDriverOptions, type IIosPlaytestDependencies, ILabeledPlaytestSample, IMovementSampleInterval, type IPipelineCapture, type IPipelineCaptureBoundary, type IPipelineCaptureCounts, type IPipelineCaptureEvent, type IPipelineCaptureProvenance, type IPipelineCaptureShader, type IPipelineContributorSummary, type IPipelinePassSummary, type IPipelineProgramReasonSummary, type IPipelineSizeTimePassSummary, type IPipelineSizeTimeSummary, type IPipelineSummary, type IPipelineWarmupSummary, type IPlaytestBridgeClient, type IRunIosCommand, IRunnerConsoleEntry, IStandalonePlaytestConfig, IStandalonePlaytestReport, type IStandalonePlaytestRunOptions, type IosTransportKind, LocalDeviceMailbox, PERFORMANCE_BROWSER_ARGS, PIPELINE_CAPTURE_VERSION, PIPELINE_EVENT_MARKER, type PipelineCaptureKind, type PipelineCaptureMode, type PipelineCaptureSource, type PipelineCaptureStatus, PlaytestBridgeError, PlaywrightTransport, STANDALONE_PLAYTEST_OBSERVATION_FIELDS, WEBGPU_BROWSER_ARGS, XcrunIosDriver, advanceFixedStep, advanceTimeoutMs, androidMailboxPaths, androidTouchBatches, batchArtifactDirectory, boundedTeardownStep, bridgeWaitTimeoutMs, buildReport, captureVisualSurface, connectPlaytestBridge, connectPlaytestBridgeTransport, deviceMailboxPaths, deviceTimeoutDiagnostic, discoverAdb, formatPipelineSummary, handlePlaytestSignal, initStandalonePlaytest, isRuntimeReadout, keyboardIsShown, openPageAndConnectBridge, pageLifecycleDiagnostic, parseAndroidConsole, parseAndroidTouchViewport, parseLaunchedPid, parsePipelineCapture, parsePipelineEventMarkers, playtestStepDrivesMovement, preflightDisplay, reconcileBrowserPointers, recordToScenario, requireAssertions, resolveBrowserArguments, resolveManagedServerCommand, resolveManagedServerConfig, rotatedTouchPosition, runAndroidPlaytest, runDesktopPlaytest, runDevicePlaytest, runIosPlaytest, runStandalonePlaytest, runStandalonePlaytests, softwareAdapterName, substituteManagedPort, summarizePipelineCapture, tapCommand, touchPositionForViewport, touchRotationFromWindowDump, validateDeviceEndpoint, viewportPresentationCommands, viewportPresentationObserved, viewportRestoreCommands, writeCaptureProvenance, writeObservationArtifacts };