@threenative/playtest 0.2.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.
@@ -0,0 +1,264 @@
1
+ declare const PLAYTEST_BRIDGE_GLOBAL = "__THREENATIVE_PLAYTEST_BRIDGE__";
2
+ declare const PLAYTEST_PROTOCOL_VERSION: 1;
3
+ /**
4
+ * userData key the setup channel sets on an entity placed with `frozen: true`. Games read
5
+ * this marker and suppress physics motion for the entity — placement stays data the game
6
+ * interprets, never a runner-side per-frame teleport.
7
+ */
8
+ declare const PLAYTEST_FROZEN_MARKER = "__threenativeFrozen";
9
+ /**
10
+ * How much wall clock one advanced tick may take before the runner calls the page hung.
11
+ *
12
+ * `operationTimeoutMs` bounds a request/response round trip, which is the right shape for every
13
+ * bridge call except one: `advance` is bulk work whose duration scales with the ticks asked for,
14
+ * so a fixed budget is wrong for it by construction. A scenario advancing 600 ticks in a single
15
+ * call exceeded 5 s on a two-core CI runner and was reported as a timed-out operation — the page
16
+ * was not hung, it was doing exactly what it was told, slowly.
17
+ *
18
+ * 250 ms is about 2.5x the ~100 ms per tick measured on the slowest lane this repository runs
19
+ * (SwiftShader on a two-core runner). It is a hang detector, not a schedule: no measurement
20
+ * anywhere reads it, and a run that needs it is already reporting its own tick counts.
21
+ */
22
+ declare const PLAYTEST_ADVANCE_TICK_BUDGET_MS = 250;
23
+ /**
24
+ * Core's own bound on first-use compilation, restated here because `playtest` must not depend on
25
+ * `core`. Kept equal to `STARTUP_COMPILE_BUDGET_MS` in `packages/core/src/startup-readiness.ts`;
26
+ * an advance that can overlap that work has to allow for it.
27
+ */
28
+ declare const PLAYTEST_STARTUP_COMPILE_BUDGET_MS = 15000;
29
+ declare const PLAYTEST_PROTOCOL_LIMITS: {
30
+ readonly maxEntitiesPerSample: 100;
31
+ readonly maxEventsPerDrain: 1000;
32
+ readonly maxPayloadBytes: 1000000;
33
+ readonly operationTimeoutMs: 5000;
34
+ };
35
+ type JsonPrimitive = boolean | number | string | null;
36
+ type JsonValue = JsonPrimitive | JsonValue[] | {
37
+ [key: string]: JsonValue;
38
+ };
39
+ type PlaytestClockMode = "fixed-step" | "render-frame" | "wall-clock";
40
+ interface IPlaytestBridgeDescription {
41
+ capabilities: readonly string[];
42
+ limits: typeof PLAYTEST_PROTOCOL_LIMITS;
43
+ name: string;
44
+ protocolVersion: typeof PLAYTEST_PROTOCOL_VERSION;
45
+ }
46
+ /**
47
+ * How far the application is through its own first-use startup work.
48
+ *
49
+ * A fixed-step runner advances ticks as fast as the machine allows, so a scenario can finish
50
+ * before a loading screen has closed — and everything a game gates on startup (compute
51
+ * dispatch, the first world present) then never happens inside the run. Reported so the runner
52
+ * can wait for the world instead of photographing the loader and asserting against a frozen
53
+ * simulation.
54
+ */
55
+ interface IPlaytestStartupObservation {
56
+ phase: "observing" | "collapsing" | "ready";
57
+ /** 0 while first-use work is pending, then 1. */
58
+ progress: number;
59
+ /**
60
+ * Whether first-use compilation has settled, which happens strictly before `phase` reaches
61
+ * `"ready"`: readiness additionally requires a sustained in-budget frame window. Reported
62
+ * separately because that window is a player-experience gate, and a lane that has been told
63
+ * the machine has no GPU has already conceded it is not measuring that.
64
+ */
65
+ compileSettled?: boolean;
66
+ }
67
+ /**
68
+ * How long a run will wait for an application to finish its own first-use startup work.
69
+ *
70
+ * Derived, not picked. Core bounds its own launch twice — `STARTUP_COMPILE_BUDGET_MS` (15s) for
71
+ * first-use compilation, then `STARTUP_STABLE_WINDOW_MS` (10s) for the sustained-frame window,
72
+ * which resolves anyway — so the readiness gate itself is bounded at 25s. Measured end to end on
73
+ * a real SwiftShader adapter, a starter scenario took ~57s to report ready, because the scene
74
+ * build and first-use work that happen *before* that gate opens are not inside those budgets.
75
+ *
76
+ * This deadline is a backstop for a page that has hung, not a schedule anything should approach,
77
+ * so it is set at roughly 3x that measured software launch and >7x the gate's own bound. A margin
78
+ * of a few seconds over a worst case measured on one machine is a coin flip, not headroom.
79
+ *
80
+ * Pinned against core's constants by packages/core/__tests__/startup-ready-bound.spec.ts, which
81
+ * fails if either budget is raised past it.
82
+ */
83
+ declare const PLAYTEST_STARTUP_READY_TIMEOUT_MS = 180000;
84
+ interface IPlaytestBridgeReady {
85
+ ready: boolean;
86
+ reason?: string;
87
+ /** Present only when the application advertises `runtime.startup`. */
88
+ startup?: IPlaytestStartupObservation;
89
+ }
90
+ interface IPlaytestEntityTransform {
91
+ position?: [number, number, number];
92
+ rotation?: [number, number, number, number];
93
+ scale?: [number, number, number];
94
+ }
95
+ interface IPlaytestSetupRequest {
96
+ entities?: Array<{
97
+ entity: string;
98
+ /** Marks the placed entity with {@link PLAYTEST_FROZEN_MARKER} for the game to read. */
99
+ frozen?: boolean;
100
+ transform: IPlaytestEntityTransform;
101
+ }>;
102
+ resources?: Array<{
103
+ id: string;
104
+ path?: string;
105
+ value: JsonValue;
106
+ }>;
107
+ }
108
+ interface IPlaytestSampleRequest {
109
+ entities?: readonly string[];
110
+ include?: readonly string[];
111
+ /** Scenario-step label for providers that retain labelled observation series. */
112
+ label?: string;
113
+ resources?: readonly string[];
114
+ }
115
+ interface IPlaytestEntityObservation {
116
+ bounds?: {
117
+ height: number;
118
+ width: number;
119
+ x: number;
120
+ y: number;
121
+ };
122
+ id: string;
123
+ transform?: IPlaytestEntityTransform;
124
+ visible?: boolean;
125
+ }
126
+ interface IPlaytestAnimationObservation {
127
+ advancedFrames: number;
128
+ clip: string;
129
+ finished?: boolean;
130
+ }
131
+ interface IPlaytestContactObservation {
132
+ entity: string;
133
+ kind: string;
134
+ with: string;
135
+ }
136
+ interface IPlaytestTagObservation {
137
+ count: number;
138
+ }
139
+ interface IPlaytestPerformanceObservation {
140
+ drawCalls?: number;
141
+ triangles?: number;
142
+ }
143
+ interface IPlaytestRenderChainObservation {
144
+ dropped: Array<{
145
+ name: string;
146
+ reason: string;
147
+ }>;
148
+ requested: string[];
149
+ source: "pinned" | "auto";
150
+ stages: string[];
151
+ tier: "high" | "medium" | "low" | "off";
152
+ velocity: {
153
+ measurementFrame?: number;
154
+ provisioned: boolean;
155
+ required: boolean;
156
+ rejectionFraction?: number;
157
+ source: "mrt" | "per-object" | null;
158
+ };
159
+ }
160
+ interface IPlaytestWorldRuntimeObservation {
161
+ agent: string;
162
+ core: string;
163
+ randomState: number;
164
+ rapier: string | null;
165
+ step: number;
166
+ }
167
+ interface IPlaytestWorldObservation {
168
+ runtime?: IPlaytestWorldRuntimeObservation;
169
+ seed: number | null;
170
+ }
171
+ interface IPlaytestGameplayObservation {
172
+ animation: Record<string, IPlaytestAnimationObservation>;
173
+ contacts?: IPlaytestContactObservation[];
174
+ states: Record<string, string>;
175
+ tags?: Record<string, IPlaytestTagObservation>;
176
+ world?: IPlaytestWorldObservation;
177
+ }
178
+ /** Per-render samples shared by the browser and native playtest bridges. */
179
+ /**
180
+ * The named parts of one presented frame. Closed on purpose: a budget naming anything else is a
181
+ * typo, and a typo that evaluated no bound would report green on a ceiling nobody checked.
182
+ */
183
+ declare const PLAYTEST_FRAME_BUDGET_PHASES: readonly ["hostGap", "overlay", "render", "residual", "update"];
184
+ type PlaytestFramePhase = (typeof PLAYTEST_FRAME_BUDGET_PHASES)[number];
185
+ /**
186
+ * Where a frame's milliseconds went, by phase. Every phase optional so a producer that measures
187
+ * only some of them is describable; a ceiling on a phase the producer omitted fails naming the
188
+ * missing evidence rather than passing on nothing.
189
+ */
190
+ type PlaytestFramePhaseSample = Partial<Record<PlaytestFramePhase, number>>;
191
+ interface IPlaytestRuntimeDiagnosticsSample {
192
+ drawCalls?: number;
193
+ frameMs: number;
194
+ /**
195
+ * Supplied by an engine that measures its own frame — `@threenative/core` fills it from the
196
+ * frame budget. Absent for a plain Three.js bridge.
197
+ */
198
+ phases?: PlaytestFramePhaseSample;
199
+ triangles?: number;
200
+ }
201
+ interface IPlaytestObservationSnapshot {
202
+ clock: {
203
+ mode: PlaytestClockMode;
204
+ tick?: number;
205
+ timeMs?: number;
206
+ };
207
+ diagnostics?: JsonValue[];
208
+ components?: Record<string, Record<string, JsonValue>>;
209
+ entities?: IPlaytestEntityObservation[];
210
+ gameplay?: IPlaytestGameplayObservation;
211
+ physicsDebugSeries?: Array<{
212
+ label: string;
213
+ snapshot: JsonValue;
214
+ tick: number;
215
+ }>;
216
+ performance?: IPlaytestPerformanceObservation;
217
+ renderChain?: IPlaytestRenderChainObservation;
218
+ runtimeDiagnosticsSeries?: IPlaytestRuntimeDiagnosticsSample[];
219
+ resources?: Record<string, JsonValue>;
220
+ }
221
+ interface IPlaytestAdvanceResult {
222
+ clock: IPlaytestObservationSnapshot["clock"];
223
+ ticks: number;
224
+ }
225
+ interface IPlaytestBridgeV1 {
226
+ advance?(ticks: number): Promise<IPlaytestAdvanceResult>;
227
+ applySetup?(request: IPlaytestSetupRequest): Promise<void>;
228
+ describe(): IPlaytestBridgeDescription | Promise<IPlaytestBridgeDescription>;
229
+ drainEvents?(limit?: number): Promise<JsonValue[]>;
230
+ focus?(): boolean | Promise<boolean>;
231
+ ready(): IPlaytestBridgeReady | Promise<IPlaytestBridgeReady>;
232
+ sample(request: IPlaytestSampleRequest): IPlaytestObservationSnapshot | Promise<IPlaytestObservationSnapshot>;
233
+ }
234
+ /** Request/response envelope used by the host-neutral device transport. */
235
+ interface IPlaytestDeviceRequest {
236
+ argument?: JsonValue;
237
+ id: string;
238
+ method: string;
239
+ }
240
+ interface IPlaytestDeviceResponse {
241
+ error?: {
242
+ message: string;
243
+ };
244
+ id: string;
245
+ result?: JsonValue;
246
+ }
247
+ interface IPlaytestBridgeHost {
248
+ [PLAYTEST_BRIDGE_GLOBAL]?: IPlaytestBridgeV1;
249
+ }
250
+ /**
251
+ * Measure a payload's wire size in bytes.
252
+ * @situation check a runtime observation against the protocol payload limit before sampling
253
+ * @example const bytes = jsonByteLength(observation);
254
+ */
255
+ declare function jsonByteLength(value: JsonValue): number;
256
+ /**
257
+ * Reject any value that would not survive JSON serialization.
258
+ * @situation validate entity components and gameplay observations before crossing the bridge
259
+ * @constraint throws instead of silently dropping the offending field
260
+ * @example assertJsonSafe(snapshot, "$.components");
261
+ */
262
+ declare function assertJsonSafe(value: unknown, path?: string): asserts value is JsonValue;
263
+
264
+ export { type IPlaytestAdvanceResult, type IPlaytestAnimationObservation, type IPlaytestBridgeDescription, type IPlaytestBridgeHost, type IPlaytestBridgeReady, type IPlaytestBridgeV1, type IPlaytestContactObservation, type IPlaytestDeviceRequest, type IPlaytestDeviceResponse, type IPlaytestEntityObservation, type IPlaytestEntityTransform, type IPlaytestGameplayObservation, type IPlaytestObservationSnapshot, type IPlaytestPerformanceObservation, type IPlaytestRenderChainObservation, type IPlaytestRuntimeDiagnosticsSample, type IPlaytestSampleRequest, type IPlaytestSetupRequest, type IPlaytestStartupObservation, type IPlaytestTagObservation, type IPlaytestWorldObservation, type IPlaytestWorldRuntimeObservation, type JsonPrimitive, type JsonValue, PLAYTEST_ADVANCE_TICK_BUDGET_MS, PLAYTEST_BRIDGE_GLOBAL, PLAYTEST_FRAME_BUDGET_PHASES, PLAYTEST_FROZEN_MARKER, PLAYTEST_PROTOCOL_LIMITS, PLAYTEST_PROTOCOL_VERSION, PLAYTEST_STARTUP_COMPILE_BUDGET_MS, PLAYTEST_STARTUP_READY_TIMEOUT_MS, type PlaytestClockMode, type PlaytestFramePhase, type PlaytestFramePhaseSample, assertJsonSafe, jsonByteLength };
@@ -0,0 +1,42 @@
1
+ #!/usr/bin/env node
2
+ // src/protocol.ts
3
+ var PLAYTEST_BRIDGE_GLOBAL = "__THREENATIVE_PLAYTEST_BRIDGE__";
4
+ var PLAYTEST_PROTOCOL_VERSION = 1;
5
+ var PLAYTEST_FROZEN_MARKER = "__threenativeFrozen";
6
+ var PLAYTEST_ADVANCE_TICK_BUDGET_MS = 250;
7
+ var PLAYTEST_STARTUP_COMPILE_BUDGET_MS = 15e3;
8
+ var PLAYTEST_PROTOCOL_LIMITS = {
9
+ maxEntitiesPerSample: 100,
10
+ maxEventsPerDrain: 1e3,
11
+ maxPayloadBytes: 1e6,
12
+ operationTimeoutMs: 5e3
13
+ };
14
+ var PLAYTEST_STARTUP_READY_TIMEOUT_MS = 18e4;
15
+ var PLAYTEST_FRAME_BUDGET_PHASES = ["hostGap", "overlay", "render", "residual", "update"];
16
+ function jsonByteLength(value) {
17
+ return new TextEncoder().encode(JSON.stringify(value)).byteLength;
18
+ }
19
+ function assertJsonSafe(value, path = "$") {
20
+ if (value === null || typeof value === "string" || typeof value === "boolean") {
21
+ return;
22
+ }
23
+ if (typeof value === "number") {
24
+ if (Number.isFinite(value)) {
25
+ return;
26
+ }
27
+ throw new TypeError(`${path} must contain only finite JSON numbers.`);
28
+ }
29
+ if (Array.isArray(value)) {
30
+ value.forEach((item, index) => assertJsonSafe(item, `${path}[${index}]`));
31
+ return;
32
+ }
33
+ if (typeof value === "object") {
34
+ for (const [key, item] of Object.entries(value)) {
35
+ assertJsonSafe(item, `${path}.${key}`);
36
+ }
37
+ return;
38
+ }
39
+ throw new TypeError(`${path} must be JSON-safe.`);
40
+ }
41
+
42
+ export { PLAYTEST_ADVANCE_TICK_BUDGET_MS, PLAYTEST_BRIDGE_GLOBAL, PLAYTEST_FRAME_BUDGET_PHASES, PLAYTEST_FROZEN_MARKER, PLAYTEST_PROTOCOL_LIMITS, PLAYTEST_PROTOCOL_VERSION, PLAYTEST_STARTUP_COMPILE_BUDGET_MS, PLAYTEST_STARTUP_READY_TIMEOUT_MS, assertJsonSafe, jsonByteLength };
@@ -0,0 +1,51 @@
1
+ import { I as IStandalonePlaytestConfig, a as IStandalonePlaytestReport } from '../shared-Ax3-pneQ.js';
2
+ import '../protocol.js';
3
+ import '../diagnostics-D89qJhf0.js';
4
+
5
+ interface IRunnerDiagnostic {
6
+ code: string;
7
+ fix: {
8
+ instruction: string;
9
+ };
10
+ message: string;
11
+ severity: "error";
12
+ }
13
+ type IConfiguredPlaytestRunner = (config: IStandalonePlaytestConfig) => Promise<IStandalonePlaytestReport>;
14
+ interface IPlaytestTargetRunners {
15
+ android: IConfiguredPlaytestRunner;
16
+ androidBrowser?: IConfiguredPlaytestRunner;
17
+ browser: IConfiguredPlaytestRunner;
18
+ desktop: IConfiguredPlaytestRunner;
19
+ ios: IConfiguredPlaytestRunner;
20
+ }
21
+ declare function runConfiguredPlaytest(config: IStandalonePlaytestConfig, runners?: IPlaytestTargetRunners): Promise<IStandalonePlaytestReport>;
22
+ declare function exitCodeForReport(report: {
23
+ assertionResults?: readonly unknown[];
24
+ diagnostics?: ReadonlyArray<{
25
+ code?: string;
26
+ }>;
27
+ pass: boolean;
28
+ }): 0 | 1 | 2;
29
+ declare function classifyRunnerError(error: unknown, options?: {
30
+ cwd?: string;
31
+ scenarioPath?: string;
32
+ }): IRunnerDiagnostic;
33
+ /**
34
+ * `doctor` answers "can this machine run a playtest", `doctor --url` additionally answers "and
35
+ * what is actually in the game running there" — the question asked while staring at a screenshot
36
+ * that looks wrong — and `doctor --device` answers "is the phone cool enough to measure on",
37
+ * which `observations.deviceMetrics` can only answer once the run is already spent.
38
+ */
39
+ interface IDoctorArgs {
40
+ readonly browserArgs: readonly string[];
41
+ readonly device: string | undefined;
42
+ readonly text: boolean;
43
+ readonly url: string | undefined;
44
+ }
45
+ declare function parseDoctorArgs(argv: readonly string[]): IDoctorArgs;
46
+ /** Extra arguments extend the WebGPU recipe; replacing it would silently reintroduce SwiftShader. */
47
+ declare function doctorBrowserArgs(extra: readonly string[]): string[];
48
+ declare function doctorCommand(argv: readonly string[]): Promise<number>;
49
+ declare function main(argv?: readonly string[]): Promise<number>;
50
+
51
+ export { type IConfiguredPlaytestRunner, type IDoctorArgs, type IPlaytestTargetRunners, type IRunnerDiagnostic, classifyRunnerError, doctorBrowserArgs, doctorCommand, exitCodeForReport, main, parseDoctorArgs, runConfiguredPlaytest };