@threenative/playtest 0.3.11 → 0.3.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/capture.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { I as IToneMetrics, a as IPlaytestToneAssertion, b as IPlaytestRegionalToneObservation } from './schema-base-B26KSBoa.js';
1
+ import { I as IToneMetrics, a as IPlaytestToneAssertion, b as IPlaytestRegionalToneObservation } from './schema-base-C2pIQ165.js';
2
2
  import './protocol.js';
3
3
 
4
4
  declare const CAPTURE_GUARD_LIMITS: {
@@ -1,4 +1,4 @@
1
- import { x as IPlaytestToneCaptureObservation, t as IPlaytestVisualRegionBounds, u as IPlaytestVisualRegionTarget, y as IPlaytestDiagnosticsAssertion } from './schema-base-B26KSBoa.js';
1
+ import { x as IPlaytestToneCaptureObservation, t as IPlaytestVisualRegionBounds, u as IPlaytestVisualRegionTarget, y as IPlaytestDiagnosticsAssertion } from './schema-base-C2pIQ165.js';
2
2
  import { JsonValue, IPlaytestRenderChainObservation, IPlaytestSceneObservation, IPlaytestSceneNodesObservation, IPlaytestSightLineObservation, IPlaytestStartupOffscreenBytes, IPlaytestStartupTimeline, IPlaytestStartupCoverObservation } from './protocol.js';
3
3
 
4
4
  interface IAndroidDriverOptions {
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { c as IPlaytestStep, d as IPlaytestScenarioDiagnostic, e as IPlaytestScenario, P as PlaytestTarget } from './schema-base-B26KSBoa.js';
2
- export { f as IPlaytestArtifactRequest, g as IPlaytestFramebufferCoverageAssertion, h as IPlaytestMedia, i as IPlaytestPathAssertion, j as IPlaytestPerformanceAssertion, k as IPlaytestPointer, l as IPlaytestRenderChainAssertion, m as IPlaytestResourceWait, n as IPlaytestSignalAssertion, o as IPlaytestStartupAssertion, a as IPlaytestToneAssertion, p as IPlaytestToneObservation, q as IPlaytestVisualAssertion, r as IPlaytestVisualElementRegion, s as IPlaytestVisualRegion, t as IPlaytestVisualRegionBounds, u as IPlaytestVisualRegionTarget, v as IPlaytestWheel, w as IPlaytestWorldRuntimeAssertion, I as IToneMetrics } from './schema-base-B26KSBoa.js';
3
- import { I as IPlaytestReport, a as IPlaytestAssertionResult, b as IPlaytestDiagnostic } from './diagnostics-BKg7C6Lf.js';
4
- export { D as DEVICE_METRICS_CADENCE_MS, c as DEVICE_METRICS_MAX_SAMPLES, d as DeviceMetricsError, e as DeviceMetricsRecorder, H as HOT_START_TEMPERATURE_C, f as IPlaytestCaptureProvenance, g as IPlaytestDeviceBattery, h as IPlaytestDeviceMetricsObservation, i as IPlaytestDeviceMetricsSample, j as IPlaytestDeviceMetricsVerdict, k as IPlaytestDeviceThermal, l as IPlaytestDiagnosticsPolicy, m as IPlaytestFootSlipObservation, n as IPlaytestFramebufferCoverageObservation, o as IPlaytestObservations, p as IPlaytestProtocolDiagnostic, q as IPlaytestSetupApplication, r as IPlaytestSetupRecord, s as IPlaytestTrivialityOptOut, t as IPlaytestVisualElementRegionObservation, P as PlaytestDeviceMeasurement, u as PlaytestDevicePowerRails, v as PlaytestVec3, w as parseDeviceBattery, x as parseDeviceCurrent, y as parseDevicePowerRails, z as parseDeviceThermal, A as playtestDiagnostic, B as resolveDiagnosticsPolicy, C as summarizeDeviceMetrics } from './diagnostics-BKg7C6Lf.js';
1
+ import { c as IPlaytestStep, d as IPlaytestScenarioDiagnostic, e as IPlaytestScenario, P as PlaytestTarget } from './schema-base-C2pIQ165.js';
2
+ export { f as IPlaytestArtifactRequest, g as IPlaytestFramebufferCoverageAssertion, h as IPlaytestMedia, i as IPlaytestPathAssertion, j as IPlaytestPerformanceAssertion, k as IPlaytestPointer, l as IPlaytestRenderChainAssertion, m as IPlaytestResourceWait, n as IPlaytestSignalAssertion, o as IPlaytestStartupAssertion, a as IPlaytestToneAssertion, p as IPlaytestToneObservation, q as IPlaytestVisualAssertion, r as IPlaytestVisualElementRegion, s as IPlaytestVisualRegion, t as IPlaytestVisualRegionBounds, u as IPlaytestVisualRegionTarget, v as IPlaytestWheel, w as IPlaytestWorldRuntimeAssertion, I as IToneMetrics } from './schema-base-C2pIQ165.js';
3
+ import { I as IPlaytestReport, a as IPlaytestAssertionResult, b as IPlaytestDiagnostic } from './diagnostics-BPaaU6JB.js';
4
+ export { D as DEVICE_METRICS_CADENCE_MS, c as DEVICE_METRICS_MAX_SAMPLES, d as DeviceMetricsError, e as DeviceMetricsRecorder, H as HOT_START_TEMPERATURE_C, f as IPlaytestCaptureProvenance, g as IPlaytestDeviceBattery, h as IPlaytestDeviceMetricsObservation, i as IPlaytestDeviceMetricsSample, j as IPlaytestDeviceMetricsVerdict, k as IPlaytestDeviceThermal, l as IPlaytestDiagnosticsPolicy, m as IPlaytestFootSlipObservation, n as IPlaytestFramebufferCoverageObservation, o as IPlaytestObservations, p as IPlaytestProtocolDiagnostic, q as IPlaytestSetupApplication, r as IPlaytestSetupRecord, s as IPlaytestTrivialityOptOut, t as IPlaytestVisualElementRegionObservation, P as PlaytestDeviceMeasurement, u as PlaytestDevicePowerRails, v as PlaytestVec3, w as parseDeviceBattery, x as parseDeviceCurrent, y as parseDevicePowerRails, z as parseDeviceThermal, A as playtestDiagnostic, B as resolveDiagnosticsPolicy, C as summarizeDeviceMetrics } from './diagnostics-BPaaU6JB.js';
5
5
  export { IPlaytestBridgeDescription, IPlaytestBridgeReady, IPlaytestBridgeV1, IPlaytestCameraObservation, IPlaytestContactObservation, IPlaytestDeviceRequest, IPlaytestDeviceResponse, IPlaytestFogObservation, IPlaytestFramePassSample, IPlaytestGameplayObservation, IPlaytestLightObservation, IPlaytestObservationSnapshot, IPlaytestPerformanceObservation, IPlaytestRenderChainObservation, IPlaytestRuntimeDiagnosticsSample, IPlaytestSampleRequest, IPlaytestSceneObservation, IPlaytestSetupConfirmation, IPlaytestSetupRequest, IPlaytestSightLineObservation, IPlaytestStartupObservation, IPlaytestStartupTimeline, IPlaytestStrideObservation, IPlaytestWorldObservation, IPlaytestWorldRuntimeObservation, JsonValue, PLAYTEST_ADVANCE_TICK_BUDGET_MS, PLAYTEST_BRIDGE_GLOBAL, PLAYTEST_FRAME_PASS_KINDS, PLAYTEST_FROZEN_MARKER, PLAYTEST_PROTOCOL_LIMITS, PLAYTEST_PROTOCOL_VERSION, PLAYTEST_STARTUP_COMPILE_BUDGET_MS, PLAYTEST_STARTUP_READY_TIMEOUT_MS, PlaytestFramePassKind, assertJsonSafe, jsonByteLength } from './protocol.js';
6
6
 
7
7
  type PlaytestCapability = "browser.canvas" | "browser.console" | "browser.dom" | "browser.input" | "browser.network" | "browser.screenshot" | "browser.trace" | "camera.observe" | "device.metrics" | "entity.bounds" | "entity.observe" | "entity.setup" | "runtime.animation" | "runtime.audio" | "runtime.components" | "runtime.contacts" | "runtime.diagnostics" | "runtime.events" | "runtime.fixedStep" | "runtime.geometry" | "runtime.physics" | "runtime.network" | "runtime.performance" | "runtime.pipelineCensus" | "runtime.renderChain" | "runtime.renderOnly" | "runtime.resources" | "runtime.startup" | "runtime.state" | "runtime.tags" | "runtime.transitions" | "runtime.ui" | "runtime.world" | "scene.nodes" | "scene.observe";
package/dist/index.js CHANGED
@@ -1004,6 +1004,7 @@ var PLAYTEST_SETUP_REGISTRY = [
1004
1004
  function requiredPlaytestCapabilities(scenario, target) {
1005
1005
  const required = /* @__PURE__ */ new Set();
1006
1006
  if (scenario.startTick !== void 0) required.add("runtime.fixedStep");
1007
+ if (scenario.drawEvery !== void 0) required.add("runtime.fixedStep");
1007
1008
  if (scenario.steps.some((step) => step.waitForResource !== void 0)) {
1008
1009
  required.add("runtime.resources");
1009
1010
  }
@@ -8190,6 +8191,7 @@ var PLAYTEST_ROOT_KEYS = [
8190
8191
  "awaitStartup",
8191
8192
  "bootFailure",
8192
8193
  "clock",
8194
+ "drawEvery",
8193
8195
  "inputDelivery",
8194
8196
  "name",
8195
8197
  "network",
@@ -8225,6 +8227,9 @@ function validatePlaytestScenario(value, scenarioPath, absolutePath) {
8225
8227
  if (value.startTick !== void 0 && (!Number.isSafeInteger(value.startTick) || value.startTick < 0)) {
8226
8228
  throw invalidScenario(scenarioPath, "Scenario startTick must be a nonnegative safe integer when present.");
8227
8229
  }
8230
+ if (value.drawEvery !== void 0 && (!Number.isSafeInteger(value.drawEvery) || value.drawEvery <= 0)) {
8231
+ throw invalidScenario(scenarioPath, "Scenario drawEvery must be a positive safe integer when present.");
8232
+ }
8228
8233
  if (value.bootFailure !== void 0 && value.bootFailure !== "renderer-no-adapter") {
8229
8234
  throw invalidScenario(scenarioPath, "Scenario bootFailure must be 'renderer-no-adapter' when present.");
8230
8235
  }
@@ -8281,6 +8286,7 @@ function validatePlaytestScenario(value, scenarioPath, absolutePath) {
8281
8286
  ...typeof value.awaitStartup === "boolean" ? { awaitStartup: value.awaitStartup } : {},
8282
8287
  ...value.bootFailure === "renderer-no-adapter" ? { bootFailure: value.bootFailure } : {},
8283
8288
  ...value.clock === "wall-clock" ? { clock: value.clock } : {},
8289
+ ...value.drawEvery === void 0 ? {} : { drawEvery: value.drawEvery },
8284
8290
  inputDelivery,
8285
8291
  name,
8286
8292
  ...network === void 0 ? {} : { network },
@@ -1,8 +1,8 @@
1
- import { I as IStandalonePlaytestConfig, a as IStandalonePlaytestReport } from '../shared-Dg-3kiU8.js';
2
- import '../schema-base-B26KSBoa.js';
1
+ import { I as IStandalonePlaytestConfig, a as IStandalonePlaytestReport } from '../shared-D52a_m0V.js';
2
+ import '../schema-base-C2pIQ165.js';
3
3
  import '../protocol.js';
4
4
  import 'playwright';
5
- import '../diagnostics-BKg7C6Lf.js';
5
+ import '../diagnostics-BPaaU6JB.js';
6
6
 
7
7
  interface IRunnerDiagnostic {
8
8
  code: string;
@@ -565,6 +565,7 @@ var init_assertion_report = __esm({
565
565
  function requiredPlaytestCapabilities(scenario, target) {
566
566
  const required = /* @__PURE__ */ new Set();
567
567
  if (scenario.startTick !== void 0) required.add("runtime.fixedStep");
568
+ if (scenario.drawEvery !== void 0) required.add("runtime.fixedStep");
568
569
  if (scenario.steps.some((step) => step.waitForResource !== void 0)) {
569
570
  required.add("runtime.resources");
570
571
  }
@@ -8729,6 +8730,9 @@ function validatePlaytestScenario(value, scenarioPath, absolutePath) {
8729
8730
  if (value.startTick !== void 0 && (!Number.isSafeInteger(value.startTick) || value.startTick < 0)) {
8730
8731
  throw invalidScenario(scenarioPath, "Scenario startTick must be a nonnegative safe integer when present.");
8731
8732
  }
8733
+ if (value.drawEvery !== void 0 && (!Number.isSafeInteger(value.drawEvery) || value.drawEvery <= 0)) {
8734
+ throw invalidScenario(scenarioPath, "Scenario drawEvery must be a positive safe integer when present.");
8735
+ }
8732
8736
  if (value.bootFailure !== void 0 && value.bootFailure !== "renderer-no-adapter") {
8733
8737
  throw invalidScenario(scenarioPath, "Scenario bootFailure must be 'renderer-no-adapter' when present.");
8734
8738
  }
@@ -8785,6 +8789,7 @@ function validatePlaytestScenario(value, scenarioPath, absolutePath) {
8785
8789
  ...typeof value.awaitStartup === "boolean" ? { awaitStartup: value.awaitStartup } : {},
8786
8790
  ...value.bootFailure === "renderer-no-adapter" ? { bootFailure: value.bootFailure } : {},
8787
8791
  ...value.clock === "wall-clock" ? { clock: value.clock } : {},
8792
+ ...value.drawEvery === void 0 ? {} : { drawEvery: value.drawEvery },
8788
8793
  inputDelivery,
8789
8794
  name,
8790
8795
  ...network === void 0 ? {} : { network },
@@ -9986,6 +9991,7 @@ var init_schema_validate = __esm({
9986
9991
  "awaitStartup",
9987
9992
  "bootFailure",
9988
9993
  "clock",
9994
+ "drawEvery",
9989
9995
  "inputDelivery",
9990
9996
  "name",
9991
9997
  "network",
@@ -11960,8 +11966,8 @@ function isProcessAlive(pid) {
11960
11966
  try {
11961
11967
  process.kill(pid, 0);
11962
11968
  return true;
11963
- } catch {
11964
- return false;
11969
+ } catch (error) {
11970
+ return error instanceof Error && error.code === "EPERM";
11965
11971
  }
11966
11972
  }
11967
11973
  var execFileAsync = promisify(execFile);
@@ -14106,6 +14112,7 @@ function parsePerformanceMarkers(text) {
14106
14112
  if (playerFrame !== void 0) playerFrames.push(playerFrame);
14107
14113
  const budget = parseMarkerLine(line, FRAME_BUDGET_MARKER2);
14108
14114
  if (budget !== void 0) {
14115
+ assertBudgetSurface(budget);
14109
14116
  const payload = JSON.stringify(budget);
14110
14117
  if (!budgetPayloads.has(payload)) {
14111
14118
  budgetPayloads.add(payload);
@@ -14180,6 +14187,22 @@ function assertProjectionTimings(projection) {
14180
14187
  }
14181
14188
  }
14182
14189
  }
14190
+ function assertBudgetSurface(budget) {
14191
+ const surface = budget.surface;
14192
+ if (surface === void 0) return;
14193
+ if (typeof surface !== "object" || surface === null || Array.isArray(surface)) {
14194
+ throw new Error(
14195
+ `TN_PERF_MARKER_MALFORMED: a TN_FRAME_BUDGET line carried a non-object surface (${JSON.stringify(surface)}).`
14196
+ );
14197
+ }
14198
+ const compiling = surface.compiling;
14199
+ if (compiling === void 0) return;
14200
+ if (typeof compiling !== "boolean") {
14201
+ throw new Error(
14202
+ `TN_PERF_MARKER_MALFORMED: a TN_FRAME_BUDGET line carried surface.compiling = ${JSON.stringify(compiling)} \u2014 it must be a boolean.`
14203
+ );
14204
+ }
14205
+ }
14183
14206
  function parseMarkerLine(line, marker2) {
14184
14207
  const start = line.indexOf(marker2);
14185
14208
  if (start === -1) return void 0;
@@ -14194,9 +14217,9 @@ function parseMarkerLine(line, marker2) {
14194
14217
  }
14195
14218
  }
14196
14219
  function assessPerfMarkers(parse, bounds, source, display) {
14197
- const discardCount = parse.budgets.length > 1 ? 1 : 0;
14198
- const discardedWindows = parse.budgets.slice(0, discardCount).map(({ window: window2 }) => window2);
14199
- const steady = parse.budgets.slice(discardCount);
14220
+ const discard = (window2, index) => index === 0 && parse.budgets.length > 1 || window2.surface?.compiling === true;
14221
+ const discardedWindows = parse.budgets.filter(discard).map(({ window: window2 }) => window2);
14222
+ const steady = parse.budgets.filter((window2, index) => !discard(window2, index));
14200
14223
  const violations = [];
14201
14224
  const unassessableWindows = [];
14202
14225
  const tick = parse.presents.at(-1);
@@ -14699,7 +14722,7 @@ function formatPerfReport(report) {
14699
14722
  ].join(" ")
14700
14723
  );
14701
14724
  }
14702
- if (report.discardedWindows.length > 0) lines.push("* discarded as startup (window 1 always lies)");
14725
+ if (report.discardedWindows.length > 0) lines.push("* discarded as startup or active compilation");
14703
14726
  lines.push(...formatMainPassTriangles(report.budgets));
14704
14727
  const presentedNothing = report.budgets.filter((window2) => window2.presents === 0);
14705
14728
  if (presentedNothing.length > 0) {
@@ -15914,7 +15937,7 @@ async function captureVisualSurface(page, artifactPath) {
15914
15937
  const canvas = canvases.nth(sourceIndex);
15915
15938
  const bounds = await canvas.boundingBox();
15916
15939
  if (bounds === null || ![bounds.x, bounds.y, bounds.width, bounds.height].every(Number.isFinite) || bounds.width <= 0 || bounds.height <= 0) return void 0;
15917
- const content = await page.screenshot({ clip: bounds });
15940
+ const content = await page.screenshot({ clip: bounds, timeout: SCREENSHOT_TIMEOUT_MS });
15918
15941
  if (artifactPath !== void 0) await writeFile(artifactPath, content);
15919
15942
  return content;
15920
15943
  }
@@ -16051,7 +16074,8 @@ function laplacianVariance(luma, width, height) {
16051
16074
  }
16052
16075
  return count === 0 ? 0 : squares / count - (sum / count) ** 2;
16053
16076
  }
16054
- async function runStep(page, bridge, step, viewport, pathEntity, pathPositions, inputState, movementSampleRequest, finalStep, subject, liveClock = false, cpuWindow, stepWindow, sightLine) {
16077
+ async function runStep(page, bridge, step, viewport, pathEntity, pathPositions, inputState, movementSampleRequest, finalStep, subject, liveClock = false, cpuWindow, stepWindow, sightLine, drawEvery) {
16078
+ const draw = drawEvery === void 0 ? void 0 : { every: drawEvery, ticks: 0 };
16055
16079
  if (step.waitForResource !== void 0) {
16056
16080
  if (bridge === void 0 || movementSampleRequest === void 0) {
16057
16081
  throw new PlaytestBridgeError(playtestDiagnostic(
@@ -16071,7 +16095,7 @@ async function runStep(page, bridge, step, viewport, pathEntity, pathPositions,
16071
16095
  ));
16072
16096
  }
16073
16097
  const after = await waitForResource({
16074
- advance: !liveClock && bridge.description.capabilities.includes("runtime.fixedStep") ? () => advanceFixedStep(page, bridge, 1) : void 0,
16098
+ advance: !liveClock && bridge.description.capabilities.includes("runtime.fixedStep") ? () => advanceFixedStep(page, bridge, 1, false, draw) : void 0,
16075
16099
  id: wait.id,
16076
16100
  path: wait.path,
16077
16101
  predicate: wait,
@@ -16085,7 +16109,7 @@ async function runStep(page, bridge, step, viewport, pathEntity, pathPositions,
16085
16109
  await executeClickStep(page, bridge, step, viewport);
16086
16110
  const frames2 = Math.max(step.waitFrames ?? 0, step.waitTicks ?? 0, 1);
16087
16111
  if (bridge?.description.capabilities.includes("runtime.fixedStep") === true && step.waitTicks !== void 0) {
16088
- await advanceFixedStep(page, bridge, step.waitTicks);
16112
+ await advanceFixedStep(page, bridge, step.waitTicks, false, draw);
16089
16113
  } else {
16090
16114
  await waitFrames(page, frames2);
16091
16115
  }
@@ -16162,7 +16186,7 @@ async function runStep(page, bridge, step, viewport, pathEntity, pathPositions,
16162
16186
  const sampleTicks = 10;
16163
16187
  for (let index = 0; index < ticks; index += sampleTicks) {
16164
16188
  const batch = Math.min(sampleTicks, ticks - index);
16165
- await advanceFixedStep(page, bridge, batch);
16189
+ await advanceFixedStep(page, bridge, batch, false, draw);
16166
16190
  await samplePathPosition(bridge, pathEntity, pathPositions);
16167
16191
  await sampleSightLine(bridge, sightLine);
16168
16192
  }
@@ -16181,7 +16205,7 @@ async function runStep(page, bridge, step, viewport, pathEntity, pathPositions,
16181
16205
  }
16182
16206
  if (!finalStep) {
16183
16207
  if (bridge?.description.capabilities.includes("runtime.fixedStep") === true) {
16184
- await advanceFixedStep(page, bridge, 1);
16208
+ await advanceFixedStep(page, bridge, 1, false, draw);
16185
16209
  } else {
16186
16210
  await waitFrames(page, 1);
16187
16211
  }
@@ -16196,7 +16220,7 @@ async function runStep(page, bridge, step, viewport, pathEntity, pathPositions,
16196
16220
  if (step.pointers !== void 0 && step.release) {
16197
16221
  await setBrowserPointers(page, inputState, [], viewport);
16198
16222
  if (bridge?.description.capabilities.includes("runtime.fixedStep") === true) {
16199
- await advanceFixedStep(page, bridge, 1);
16223
+ await advanceFixedStep(page, bridge, 1, false, draw);
16200
16224
  } else {
16201
16225
  await waitFrames(page, 1);
16202
16226
  }
@@ -16315,14 +16339,16 @@ async function executeAimAtStep(bridge, step, subject) {
16315
16339
  );
16316
16340
  }
16317
16341
  }
16318
- async function advanceFixedStep(page, bridge, ticks, render = false) {
16342
+ async function advanceFixedStep(page, bridge, ticks, render = false, draw) {
16319
16343
  if (!Number.isInteger(ticks) || ticks <= 0)
16320
16344
  throw new Error("advance ticks must be a positive integer.");
16321
16345
  for (let tick = 0; tick < ticks; ) {
16346
+ const drawn = render || draw !== void 0 && draw.ticks % draw.every === 0;
16347
+ let ran = 1;
16322
16348
  for (let attempt = 0; ; attempt += 1) {
16323
16349
  try {
16324
- const advanced = render ? await bridge.advance(1, { render: true }) : await bridge.advance(1);
16325
- tick += typeof advanced === "number" && advanced > 1 ? advanced : 1;
16350
+ const advanced = drawn ? await bridge.advance(1, { render: true }) : await bridge.advance(1);
16351
+ ran = typeof advanced === "number" && advanced > 1 ? advanced : 1;
16326
16352
  break;
16327
16353
  } catch (error) {
16328
16354
  if (!(error instanceof Error) || !error.message.includes(STOPPED_LOOP_ERROR) || attempt >= MAX_FIXED_STEP_STARTUP_RETRIES)
@@ -16330,7 +16356,9 @@ async function advanceFixedStep(page, bridge, ticks, render = false) {
16330
16356
  await waitFrames(page, 1);
16331
16357
  }
16332
16358
  }
16333
- if (render && tick < ticks) await waitFrames(page, 1);
16359
+ tick += ran;
16360
+ if (draw !== void 0) draw.ticks += ran;
16361
+ if (drawn && tick < ticks) await waitFrames(page, 1);
16334
16362
  }
16335
16363
  }
16336
16364
  function playtestStepDrivesMovement(step, hasHeldInput) {
@@ -17351,6 +17379,7 @@ var DeviceMailboxTransport = class {
17351
17379
  nextId = 1;
17352
17380
  nextOrder = 1;
17353
17381
  pendingRequest;
17382
+ responsePoll;
17354
17383
  // Calls that gave up before the host answered. The host still answers them, late, and that
17355
17384
  // answer is theirs, not an error in whichever call is waiting when it lands.
17356
17385
  abandonedIds = /* @__PURE__ */ new Set();
@@ -17394,13 +17423,21 @@ var DeviceMailboxTransport = class {
17394
17423
  id,
17395
17424
  method
17396
17425
  }));
17397
- const response = await this.waitForResponse(id, method, order, timeoutMs);
17426
+ const pending = this.waitForResponse(id, method, order, timeoutMs);
17427
+ this.responsePoll = pending;
17428
+ let response;
17429
+ try {
17430
+ response = await pending;
17431
+ } finally {
17432
+ if (this.responsePoll === pending) this.responsePoll = void 0;
17433
+ }
17398
17434
  this.pendingRequest = void 0;
17399
17435
  if (response.error !== void 0) throw new Error(response.error.message);
17400
17436
  return response.result;
17401
17437
  }
17402
17438
  async close() {
17403
17439
  this.closed = true;
17440
+ await this.responsePoll?.catch(() => void 0);
17404
17441
  this.pendingRequest = void 0;
17405
17442
  await this.mailbox.remove(this.paths.request).catch(() => void 0);
17406
17443
  await this.mailbox.remove(this.paths.response).catch(() => void 0);
@@ -17427,7 +17464,7 @@ var DeviceMailboxTransport = class {
17427
17464
  const raw = await readMailboxFile(this.mailbox, this.paths.response);
17428
17465
  if (raw !== void 0) {
17429
17466
  const response = parseResponse(raw);
17430
- this.responseObserver?.({ body: raw, method, order, requestId: response.id });
17467
+ await this.responseObserver?.({ body: raw, method, order, requestId: response.id });
17431
17468
  await this.mailbox.remove(this.paths.response);
17432
17469
  if (response.id === id) return response;
17433
17470
  if (this.abandonedIds.has(response.id)) continue;
@@ -18340,9 +18377,15 @@ async function runStandalonePlaytestOnce(config, options) {
18340
18377
  pageLifecycle.closed = true;
18341
18378
  });
18342
18379
  const activePage = page;
18380
+ if (activeConfig.cpuProfilePath !== void 0) {
18381
+ cpuProfile = await startBrowserCpuProfile(activePage, activeConfig.cpuProfilePath);
18382
+ }
18343
18383
  const coverRecorder = scenario.assert?.startup?.steadyCover === true ? await recordStartupCover(page) : void 0;
18344
18384
  const bridge = await openRunnerPage(page, browserConfig, scenario, options.remoteBrowser);
18345
- if (options.gameThread === void 0 && measurementArgs.includes("--disable-frame-rate-limit") && await runsGameInWorker(page)) throw new WorkerGameRelaunch();
18385
+ if (options.gameThread === void 0 && measurementArgs.includes("--disable-frame-rate-limit") && await runsGameInWorker(page)) {
18386
+ cpuProfile = void 0;
18387
+ throw new WorkerGameRelaunch();
18388
+ }
18346
18389
  pageLifecycle.settled = true;
18347
18390
  const setupApplication2 = bridge?.setupApplication;
18348
18391
  if (scenario.setup !== void 0) {
@@ -18365,6 +18408,13 @@ async function runStandalonePlaytestOnce(config, options) {
18365
18408
  const readyMs = startupOutcome?.startup.timeline?.readyMs;
18366
18409
  const startupCover = coverRecorder === void 0 || readyMs === void 0 ? void 0 : await coverRecorder.finish(readyMs);
18367
18410
  await alignScenarioStartTick(bridge, scenario.startTick, activeConfig.liveClock === true);
18411
+ if (scenario.drawEvery !== void 0 && activeConfig.liveClock === true) {
18412
+ throw new PlaytestBridgeError(playtestDiagnostic(
18413
+ "TN_PLAYTEST_UNSUPPORTED_ON_TARGET",
18414
+ "Scenario drawEvery draws a frame every N counted ticks, and this run advances no counted ticks.",
18415
+ 'Drop --live-clock (and any scenario clock: "wall-clock"), or drop drawEvery and measure the standing scene another way.'
18416
+ ));
18417
+ }
18368
18418
  const runtimeReady = await page.evaluate(
18369
18419
  () => document.readyState !== "loading" && document.querySelector("canvas") !== null
18370
18420
  ).catch(() => false);
@@ -18549,9 +18599,6 @@ async function runStandalonePlaytestOnce(config, options) {
18549
18599
  scenario.artifacts?.screenshots === "before-after" ? join(activeConfig.artifactDirectory, "before.png") : void 0
18550
18600
  ) : await capturePage("before.png", scenario.artifacts?.screenshots === "before-after" ? { path: join(activeConfig.artifactDirectory, "before.png") } : {}) : void 0;
18551
18601
  let framebufferCoverage;
18552
- if (activeConfig.cpuProfilePath !== void 0) {
18553
- cpuProfile = await startBrowserCpuProfile(activePage, activeConfig.cpuProfilePath);
18554
- }
18555
18602
  const footSlip = [];
18556
18603
  const footSlipAt = (label) => label === void 0 ? void 0 : scenario.assert?.footSlip?.find(({ atStep }) => atStep === label);
18557
18604
  const sightLineAssertion = scenario.assert?.sightLine;
@@ -18624,7 +18671,8 @@ async function runStandalonePlaytestOnce(config, options) {
18624
18671
  await samplePathPosition(bridge, pathEntity, pathPositions);
18625
18672
  await sampleSightLine(bridge, sightLine);
18626
18673
  },
18627
- sightLine
18674
+ sightLine,
18675
+ scenario.drawEvery
18628
18676
  );
18629
18677
  if (movementBaselineSnapshot === void 0 && movementNeedsBaseline && movementEntity !== void 0) {
18630
18678
  const candidate = stepSamples.afterStep ?? stepSamples.afterInput;
@@ -19100,6 +19148,13 @@ async function runDevicePlaytestInternal(config, target, cleanupState) {
19100
19148
  canDriveAndroidLifecycle(target.driver)
19101
19149
  );
19102
19150
  if (unsupported !== void 0) return failureReport(config, scenario, unsupported, target.name);
19151
+ if (scenario.drawEvery !== void 0) {
19152
+ return failureReport(config, scenario, unsupportedDiagnostic(
19153
+ "a drawEvery tick cadence",
19154
+ "Run this scenario on --target browser, which owns the fixed-step draw cadence, or remove drawEvery.",
19155
+ target.name
19156
+ ), target.name);
19157
+ }
19103
19158
  if (target.name === "android" && scenario.assert?.framebufferCoverage !== void 0 && (typeof target.driver.startScreenRecording !== "function" || typeof target.driver.stopScreenRecording !== "function")) {
19104
19159
  return failureReport(config, scenario, unsupportedDiagnostic(
19105
19160
  "framebuffer coverage recording",
@@ -19126,10 +19181,22 @@ async function runDevicePlaytestInternal(config, target, cleanupState) {
19126
19181
  let coverageRecordingStarted = false;
19127
19182
  let framebufferCoverage;
19128
19183
  const coverageVideoPath = join(config.artifactDirectory, "framebuffer-coverage.mp4");
19129
- const responseObservations = [];
19130
- transport.setResponseObserver?.((observation) => responseObservations.push(observation));
19184
+ let responseArchive;
19185
+ let responseWritten = false;
19186
+ let responseWrite = Promise.resolve();
19131
19187
  const metrics = deviceMetricsRecorder(target);
19132
19188
  try {
19189
+ const archive = await open(join(config.artifactDirectory, "device-response-observations.json"), "w");
19190
+ responseArchive = archive;
19191
+ await archive.writeFile(`{
19192
+ "responsePath": ${JSON.stringify(target.mailboxPaths.response)},
19193
+ "observations": [`, "utf8");
19194
+ transport.setResponseObserver?.((observation) => {
19195
+ responseWrite = archive.writeFile(`${responseWritten ? "," : ""}
19196
+ ${JSON.stringify(observation)}`, "utf8");
19197
+ responseWritten = true;
19198
+ return responseWrite;
19199
+ });
19133
19200
  await throwIfAborted(target);
19134
19201
  await transport.start();
19135
19202
  await throwIfAborted(target);
@@ -19537,17 +19604,6 @@ async function runDevicePlaytestInternal(config, target, cleanupState) {
19537
19604
  cleanupErrors.push(error);
19538
19605
  }
19539
19606
  };
19540
- await attemptCleanup(async () => {
19541
- await writeFile(
19542
- join(config.artifactDirectory, "device-response-observations.json"),
19543
- `${JSON.stringify({
19544
- responsePath: target.mailboxPaths.response,
19545
- observations: responseObservations
19546
- }, null, 2)}
19547
- `,
19548
- "utf8"
19549
- );
19550
- });
19551
19607
  if (scenario.steps.some((step) => step.pointers !== void 0)) {
19552
19608
  await attemptCleanup(async () => {
19553
19609
  if (target.name === "ios") {
@@ -19572,6 +19628,16 @@ async function runDevicePlaytestInternal(config, target, cleanupState) {
19572
19628
  await bridge?.close();
19573
19629
  });
19574
19630
  await attemptCleanup(() => transport.close());
19631
+ const archive = responseArchive;
19632
+ if (archive !== void 0) {
19633
+ await attemptCleanup(async () => {
19634
+ await responseWrite;
19635
+ await archive.writeFile(`${responseWritten ? "\n " : ""}]
19636
+ }
19637
+ `, "utf8");
19638
+ });
19639
+ await attemptCleanup(() => archive.close());
19640
+ }
19575
19641
  metrics?.stop();
19576
19642
  if (cleanupErrors.length > 0) cleanupState.error = cleanupFailure(cleanupErrors);
19577
19643
  }
@@ -22636,9 +22702,11 @@ function classifyRunnerError(error, options = {}) {
22636
22702
  if (message.includes("ENOENT") || /Playtest scenario .*could not be read/u.test(message)) {
22637
22703
  return scenarioUnreadable(message, options);
22638
22704
  }
22705
+ const diagnosticMessage = error instanceof Error && error.stack !== void 0 ? `${message}
22706
+ ${error.stack}` : message;
22639
22707
  return diagnostic(
22640
22708
  "TN_PLAYTEST_RUNNER_FAILED",
22641
- message,
22709
+ diagnosticMessage,
22642
22710
  "Unexpected runner error; inspect this message and rerun the command."
22643
22711
  );
22644
22712
  }
@@ -1,10 +1,10 @@
1
1
  import { IPlaytestSetupRequest, JsonValue, IPlaytestBridgeDescription, IPlaytestBridgeReady, IPlaytestSampleRequest, IPlaytestObservationSnapshot } from '../protocol.js';
2
- import { e as IPlaytestScenario, f as IPlaytestArtifactRequest, k as IPlaytestPointer } from '../schema-base-B26KSBoa.js';
3
- import { q as IPlaytestSetupApplication, p as IPlaytestProtocolDiagnostic, o as IPlaytestObservations, n as IPlaytestFramebufferCoverageObservation, f as IPlaytestCaptureProvenance, h as IPlaytestDeviceMetricsObservation, b as IPlaytestDiagnostic, E as IAndroidAppState, F as IAndroidPointer, G as IAndroidPointerInjection, J as IAndroidDriver } from '../diagnostics-BKg7C6Lf.js';
4
- export { K as AdbAndroidDriver, L as IAndroidDriverOptions, M as IAndroidLifecycleOperation, N as IAndroidTouchViewport, O as IPlaytestDeviceLifecycleObservation, Q as IPlaytestDeviceLifecyclePhase, R as IPlaytestDeviceLifecyclePhysics, S as IPlaytestDeviceLifecycleSteps, T as androidTouchBatches, U as discoverAdb, V as keyboardIsShown, W as parseAndroidConsole, X as parseAndroidTouchViewport, Y as rotatedTouchPosition, Z as tapCommand, _ as touchPositionForViewport, $ as touchRotationFromWindowDump, a0 as viewportPresentationCommands, a1 as viewportPresentationObserved, a2 as viewportRestoreCommands } from '../diagnostics-BKg7C6Lf.js';
2
+ import { e as IPlaytestScenario, f as IPlaytestArtifactRequest, k as IPlaytestPointer } from '../schema-base-C2pIQ165.js';
3
+ import { q as IPlaytestSetupApplication, p as IPlaytestProtocolDiagnostic, o as IPlaytestObservations, n as IPlaytestFramebufferCoverageObservation, f as IPlaytestCaptureProvenance, h as IPlaytestDeviceMetricsObservation, b as IPlaytestDiagnostic, E as IAndroidAppState, F as IAndroidPointer, G as IAndroidPointerInjection, J as IAndroidDriver } from '../diagnostics-BPaaU6JB.js';
4
+ export { K as AdbAndroidDriver, L as IAndroidDriverOptions, M as IAndroidLifecycleOperation, N as IAndroidTouchViewport, O as IPlaytestDeviceLifecycleObservation, Q as IPlaytestDeviceLifecyclePhase, R as IPlaytestDeviceLifecyclePhysics, S as IPlaytestDeviceLifecycleSteps, T as androidTouchBatches, U as discoverAdb, V as keyboardIsShown, W as parseAndroidConsole, X as parseAndroidTouchViewport, Y as rotatedTouchPosition, Z as tapCommand, _ as touchPositionForViewport, $ as touchRotationFromWindowDump, a0 as viewportPresentationCommands, a1 as viewportPresentationObserved, a2 as viewportRestoreCommands } from '../diagnostics-BPaaU6JB.js';
5
5
  import { Page } from 'playwright';
6
- import { I as IStandalonePlaytestConfig, b as IRunnerConsoleEntry, c as ILabeledPlaytestSample, d as IMovementSampleInterval, a as IStandalonePlaytestReport } from '../shared-Dg-3kiU8.js';
7
- export { e as IPlaytestFlagHelp, f as IPlaytestServerConfig, g as IRunStepSamples, M as ManagedServerError, P as PLAYTEST_FLAGS, h as PlaytestCliUsageError, i as advanceFixedStep, j as captureVisualSurface, k as failedDiagnosticsAssertion, l as formatUsage, p as parseStandalonePlaytestArgs, m as playtestStepDrivesMovement, w as withScenarioClock } from '../shared-Dg-3kiU8.js';
6
+ import { I as IStandalonePlaytestConfig, b as IRunnerConsoleEntry, c as ILabeledPlaytestSample, d as IMovementSampleInterval, a as IStandalonePlaytestReport } from '../shared-D52a_m0V.js';
7
+ export { e as IPlaytestFlagHelp, f as IPlaytestServerConfig, g as IRunStepSamples, M as ManagedServerError, P as PLAYTEST_FLAGS, h as PlaytestCliUsageError, i as advanceFixedStep, j as captureVisualSurface, k as failedDiagnosticsAssertion, l as formatUsage, p as parseStandalonePlaytestArgs, m as playtestStepDrivesMovement, w as withScenarioClock } from '../shared-D52a_m0V.js';
8
8
  import { ChildProcess } from 'node:child_process';
9
9
 
10
10
  /** The only seam between assertion orchestration and an application bridge. */
@@ -269,7 +269,7 @@ interface IDeviceRequestContext {
269
269
  }
270
270
  interface IDevicePlaytestTransport extends IBridgeTransport {
271
271
  start(): Promise<void>;
272
- setResponseObserver?(observer: (observation: IDeviceResponseObservation) => void): void;
272
+ setResponseObserver?(observer: (observation: IDeviceResponseObservation) => unknown): void;
273
273
  getPendingRequest?(): IDeviceRequestContext | undefined;
274
274
  }
275
275
  declare class DeviceBridgeTransport implements IDevicePlaytestTransport {
@@ -299,10 +299,11 @@ declare class DeviceMailboxTransport implements IDevicePlaytestTransport {
299
299
  private nextId;
300
300
  private nextOrder;
301
301
  private pendingRequest?;
302
+ private responsePoll?;
302
303
  private readonly abandonedIds;
303
304
  private responseObserver?;
304
305
  constructor(mailbox: IDeviceMailbox, paths: IDeviceMailboxPaths, operationTimeoutMs?: number);
305
- setResponseObserver(observer: (observation: IDeviceResponseObservation) => void): void;
306
+ setResponseObserver(observer: (observation: IDeviceResponseObservation) => unknown): void;
306
307
  getPendingRequest(): IDeviceRequestContext | undefined;
307
308
  start(): Promise<void>;
308
309
  call<T>(method: string, argument?: unknown, timeoutMs?: number): Promise<T>;
@@ -2,7 +2,7 @@
2
2
  import { existsSync, readdirSync, rmSync, constants, readFileSync } from 'fs';
3
3
  import { join, resolve, relative, dirname, isAbsolute, basename } from 'path';
4
4
  import { execFile, spawnSync, spawn } from 'child_process';
5
- import { writeFile, stat, mkdtemp, rm, mkdir, readFile, access, unlink, rename, open, readdir, copyFile, rmdir } from 'fs/promises';
5
+ import { writeFile, stat, mkdtemp, rm, mkdir, open, readFile, access, unlink, rename, readdir, copyFile, rmdir } from 'fs/promises';
6
6
  import { tmpdir, homedir } from 'os';
7
7
  import { promisify } from 'util';
8
8
  import { PNG } from 'pngjs';
@@ -1011,6 +1011,7 @@ var PLAYTEST_SETUP_REGISTRY = [
1011
1011
  function requiredPlaytestCapabilities(scenario, target) {
1012
1012
  const required = /* @__PURE__ */ new Set();
1013
1013
  if (scenario.startTick !== void 0) required.add("runtime.fixedStep");
1014
+ if (scenario.drawEvery !== void 0) required.add("runtime.fixedStep");
1014
1015
  if (scenario.steps.some((step) => step.waitForResource !== void 0)) {
1015
1016
  required.add("runtime.resources");
1016
1017
  }
@@ -8519,6 +8520,7 @@ var PLAYTEST_ROOT_KEYS = [
8519
8520
  "awaitStartup",
8520
8521
  "bootFailure",
8521
8522
  "clock",
8523
+ "drawEvery",
8522
8524
  "inputDelivery",
8523
8525
  "name",
8524
8526
  "network",
@@ -8554,6 +8556,9 @@ function validatePlaytestScenario(value, scenarioPath, absolutePath) {
8554
8556
  if (value.startTick !== void 0 && (!Number.isSafeInteger(value.startTick) || value.startTick < 0)) {
8555
8557
  throw invalidScenario(scenarioPath, "Scenario startTick must be a nonnegative safe integer when present.");
8556
8558
  }
8559
+ if (value.drawEvery !== void 0 && (!Number.isSafeInteger(value.drawEvery) || value.drawEvery <= 0)) {
8560
+ throw invalidScenario(scenarioPath, "Scenario drawEvery must be a positive safe integer when present.");
8561
+ }
8557
8562
  if (value.bootFailure !== void 0 && value.bootFailure !== "renderer-no-adapter") {
8558
8563
  throw invalidScenario(scenarioPath, "Scenario bootFailure must be 'renderer-no-adapter' when present.");
8559
8564
  }
@@ -8610,6 +8615,7 @@ function validatePlaytestScenario(value, scenarioPath, absolutePath) {
8610
8615
  ...typeof value.awaitStartup === "boolean" ? { awaitStartup: value.awaitStartup } : {},
8611
8616
  ...value.bootFailure === "renderer-no-adapter" ? { bootFailure: value.bootFailure } : {},
8612
8617
  ...value.clock === "wall-clock" ? { clock: value.clock } : {},
8618
+ ...value.drawEvery === void 0 ? {} : { drawEvery: value.drawEvery },
8613
8619
  inputDelivery,
8614
8620
  name,
8615
8621
  ...network === void 0 ? {} : { network },
@@ -12370,8 +12376,8 @@ function isProcessAlive(pid) {
12370
12376
  try {
12371
12377
  process.kill(pid, 0);
12372
12378
  return true;
12373
- } catch {
12374
- return false;
12379
+ } catch (error) {
12380
+ return error instanceof Error && error.code === "EPERM";
12375
12381
  }
12376
12382
  }
12377
12383
  var DEFAULT_COLUMNS = 32;
@@ -12621,7 +12627,7 @@ async function captureVisualSurface(page, artifactPath) {
12621
12627
  const canvas = canvases.nth(sourceIndex);
12622
12628
  const bounds = await canvas.boundingBox();
12623
12629
  if (bounds === null || ![bounds.x, bounds.y, bounds.width, bounds.height].every(Number.isFinite) || bounds.width <= 0 || bounds.height <= 0) return void 0;
12624
- const content = await page.screenshot({ clip: bounds });
12630
+ const content = await page.screenshot({ clip: bounds, timeout: SCREENSHOT_TIMEOUT_MS });
12625
12631
  if (artifactPath !== void 0) await writeFile(artifactPath, content);
12626
12632
  return content;
12627
12633
  }
@@ -12758,7 +12764,8 @@ function laplacianVariance(luma, width, height) {
12758
12764
  }
12759
12765
  return count === 0 ? 0 : squares / count - (sum / count) ** 2;
12760
12766
  }
12761
- async function runStep(page, bridge, step, viewport, pathEntity, pathPositions, inputState, movementSampleRequest, finalStep, subject, liveClock = false, cpuWindow, stepWindow, sightLine) {
12767
+ async function runStep(page, bridge, step, viewport, pathEntity, pathPositions, inputState, movementSampleRequest, finalStep, subject, liveClock = false, cpuWindow, stepWindow, sightLine, drawEvery) {
12768
+ const draw = drawEvery === void 0 ? void 0 : { every: drawEvery, ticks: 0 };
12762
12769
  if (step.waitForResource !== void 0) {
12763
12770
  if (bridge === void 0 || movementSampleRequest === void 0) {
12764
12771
  throw new PlaytestBridgeError(playtestDiagnostic(
@@ -12778,7 +12785,7 @@ async function runStep(page, bridge, step, viewport, pathEntity, pathPositions,
12778
12785
  ));
12779
12786
  }
12780
12787
  const after = await waitForResource({
12781
- advance: !liveClock && bridge.description.capabilities.includes("runtime.fixedStep") ? () => advanceFixedStep(page, bridge, 1) : void 0,
12788
+ advance: !liveClock && bridge.description.capabilities.includes("runtime.fixedStep") ? () => advanceFixedStep(page, bridge, 1, false, draw) : void 0,
12782
12789
  id: wait.id,
12783
12790
  path: wait.path,
12784
12791
  predicate: wait,
@@ -12792,7 +12799,7 @@ async function runStep(page, bridge, step, viewport, pathEntity, pathPositions,
12792
12799
  await executeClickStep(page, bridge, step, viewport);
12793
12800
  const frames2 = Math.max(step.waitFrames ?? 0, step.waitTicks ?? 0, 1);
12794
12801
  if (bridge?.description.capabilities.includes("runtime.fixedStep") === true && step.waitTicks !== void 0) {
12795
- await advanceFixedStep(page, bridge, step.waitTicks);
12802
+ await advanceFixedStep(page, bridge, step.waitTicks, false, draw);
12796
12803
  } else {
12797
12804
  await waitFrames(page, frames2);
12798
12805
  }
@@ -12869,7 +12876,7 @@ async function runStep(page, bridge, step, viewport, pathEntity, pathPositions,
12869
12876
  const sampleTicks = 10;
12870
12877
  for (let index = 0; index < ticks; index += sampleTicks) {
12871
12878
  const batch = Math.min(sampleTicks, ticks - index);
12872
- await advanceFixedStep(page, bridge, batch);
12879
+ await advanceFixedStep(page, bridge, batch, false, draw);
12873
12880
  await samplePathPosition(bridge, pathEntity, pathPositions);
12874
12881
  await sampleSightLine(bridge, sightLine);
12875
12882
  }
@@ -12888,7 +12895,7 @@ async function runStep(page, bridge, step, viewport, pathEntity, pathPositions,
12888
12895
  }
12889
12896
  if (!finalStep) {
12890
12897
  if (bridge?.description.capabilities.includes("runtime.fixedStep") === true) {
12891
- await advanceFixedStep(page, bridge, 1);
12898
+ await advanceFixedStep(page, bridge, 1, false, draw);
12892
12899
  } else {
12893
12900
  await waitFrames(page, 1);
12894
12901
  }
@@ -12903,7 +12910,7 @@ async function runStep(page, bridge, step, viewport, pathEntity, pathPositions,
12903
12910
  if (step.pointers !== void 0 && step.release) {
12904
12911
  await setBrowserPointers(page, inputState, [], viewport);
12905
12912
  if (bridge?.description.capabilities.includes("runtime.fixedStep") === true) {
12906
- await advanceFixedStep(page, bridge, 1);
12913
+ await advanceFixedStep(page, bridge, 1, false, draw);
12907
12914
  } else {
12908
12915
  await waitFrames(page, 1);
12909
12916
  }
@@ -13022,14 +13029,16 @@ async function executeAimAtStep(bridge, step, subject) {
13022
13029
  );
13023
13030
  }
13024
13031
  }
13025
- async function advanceFixedStep(page, bridge, ticks, render = false) {
13032
+ async function advanceFixedStep(page, bridge, ticks, render = false, draw) {
13026
13033
  if (!Number.isInteger(ticks) || ticks <= 0)
13027
13034
  throw new Error("advance ticks must be a positive integer.");
13028
13035
  for (let tick = 0; tick < ticks; ) {
13036
+ const drawn = render || draw !== void 0 && draw.ticks % draw.every === 0;
13037
+ let ran = 1;
13029
13038
  for (let attempt = 0; ; attempt += 1) {
13030
13039
  try {
13031
- const advanced = render ? await bridge.advance(1, { render: true }) : await bridge.advance(1);
13032
- tick += typeof advanced === "number" && advanced > 1 ? advanced : 1;
13040
+ const advanced = drawn ? await bridge.advance(1, { render: true }) : await bridge.advance(1);
13041
+ ran = typeof advanced === "number" && advanced > 1 ? advanced : 1;
13033
13042
  break;
13034
13043
  } catch (error) {
13035
13044
  if (!(error instanceof Error) || !error.message.includes(STOPPED_LOOP_ERROR) || attempt >= MAX_FIXED_STEP_STARTUP_RETRIES)
@@ -13037,7 +13046,9 @@ async function advanceFixedStep(page, bridge, ticks, render = false) {
13037
13046
  await waitFrames(page, 1);
13038
13047
  }
13039
13048
  }
13040
- if (render && tick < ticks) await waitFrames(page, 1);
13049
+ tick += ran;
13050
+ if (draw !== void 0) draw.ticks += ran;
13051
+ if (drawn && tick < ticks) await waitFrames(page, 1);
13041
13052
  }
13042
13053
  }
13043
13054
  function playtestStepDrivesMovement(step, hasHeldInput) {
@@ -14911,6 +14922,7 @@ var DeviceMailboxTransport = class {
14911
14922
  nextId = 1;
14912
14923
  nextOrder = 1;
14913
14924
  pendingRequest;
14925
+ responsePoll;
14914
14926
  // Calls that gave up before the host answered. The host still answers them, late, and that
14915
14927
  // answer is theirs, not an error in whichever call is waiting when it lands.
14916
14928
  abandonedIds = /* @__PURE__ */ new Set();
@@ -14954,13 +14966,21 @@ var DeviceMailboxTransport = class {
14954
14966
  id,
14955
14967
  method
14956
14968
  }));
14957
- const response = await this.waitForResponse(id, method, order, timeoutMs);
14969
+ const pending = this.waitForResponse(id, method, order, timeoutMs);
14970
+ this.responsePoll = pending;
14971
+ let response;
14972
+ try {
14973
+ response = await pending;
14974
+ } finally {
14975
+ if (this.responsePoll === pending) this.responsePoll = void 0;
14976
+ }
14958
14977
  this.pendingRequest = void 0;
14959
14978
  if (response.error !== void 0) throw new Error(response.error.message);
14960
14979
  return response.result;
14961
14980
  }
14962
14981
  async close() {
14963
14982
  this.closed = true;
14983
+ await this.responsePoll?.catch(() => void 0);
14964
14984
  this.pendingRequest = void 0;
14965
14985
  await this.mailbox.remove(this.paths.request).catch(() => void 0);
14966
14986
  await this.mailbox.remove(this.paths.response).catch(() => void 0);
@@ -14987,7 +15007,7 @@ var DeviceMailboxTransport = class {
14987
15007
  const raw = await readMailboxFile(this.mailbox, this.paths.response);
14988
15008
  if (raw !== void 0) {
14989
15009
  const response = parseResponse(raw);
14990
- this.responseObserver?.({ body: raw, method, order, requestId: response.id });
15010
+ await this.responseObserver?.({ body: raw, method, order, requestId: response.id });
14991
15011
  await this.mailbox.remove(this.paths.response);
14992
15012
  if (response.id === id) return response;
14993
15013
  if (this.abandonedIds.has(response.id)) continue;
@@ -15861,9 +15881,15 @@ async function runStandalonePlaytestOnce(config, options) {
15861
15881
  pageLifecycle.closed = true;
15862
15882
  });
15863
15883
  const activePage = page;
15884
+ if (activeConfig.cpuProfilePath !== void 0) {
15885
+ cpuProfile = await startBrowserCpuProfile(activePage, activeConfig.cpuProfilePath);
15886
+ }
15864
15887
  const coverRecorder = scenario.assert?.startup?.steadyCover === true ? await recordStartupCover(page) : void 0;
15865
15888
  const bridge = await openRunnerPage(page, browserConfig, scenario, options.remoteBrowser);
15866
- if (options.gameThread === void 0 && measurementArgs.includes("--disable-frame-rate-limit") && await runsGameInWorker(page)) throw new WorkerGameRelaunch();
15889
+ if (options.gameThread === void 0 && measurementArgs.includes("--disable-frame-rate-limit") && await runsGameInWorker(page)) {
15890
+ cpuProfile = void 0;
15891
+ throw new WorkerGameRelaunch();
15892
+ }
15867
15893
  pageLifecycle.settled = true;
15868
15894
  const setupApplication2 = bridge?.setupApplication;
15869
15895
  if (scenario.setup !== void 0) {
@@ -15886,6 +15912,13 @@ async function runStandalonePlaytestOnce(config, options) {
15886
15912
  const readyMs = startupOutcome?.startup.timeline?.readyMs;
15887
15913
  const startupCover = coverRecorder === void 0 || readyMs === void 0 ? void 0 : await coverRecorder.finish(readyMs);
15888
15914
  await alignScenarioStartTick(bridge, scenario.startTick, activeConfig.liveClock === true);
15915
+ if (scenario.drawEvery !== void 0 && activeConfig.liveClock === true) {
15916
+ throw new PlaytestBridgeError(playtestDiagnostic(
15917
+ "TN_PLAYTEST_UNSUPPORTED_ON_TARGET",
15918
+ "Scenario drawEvery draws a frame every N counted ticks, and this run advances no counted ticks.",
15919
+ 'Drop --live-clock (and any scenario clock: "wall-clock"), or drop drawEvery and measure the standing scene another way.'
15920
+ ));
15921
+ }
15889
15922
  const runtimeReady = await page.evaluate(
15890
15923
  () => document.readyState !== "loading" && document.querySelector("canvas") !== null
15891
15924
  ).catch(() => false);
@@ -16070,9 +16103,6 @@ async function runStandalonePlaytestOnce(config, options) {
16070
16103
  scenario.artifacts?.screenshots === "before-after" ? join(activeConfig.artifactDirectory, "before.png") : void 0
16071
16104
  ) : await capturePage("before.png", scenario.artifacts?.screenshots === "before-after" ? { path: join(activeConfig.artifactDirectory, "before.png") } : {}) : void 0;
16072
16105
  let framebufferCoverage;
16073
- if (activeConfig.cpuProfilePath !== void 0) {
16074
- cpuProfile = await startBrowserCpuProfile(activePage, activeConfig.cpuProfilePath);
16075
- }
16076
16106
  const footSlip = [];
16077
16107
  const footSlipAt = (label) => label === void 0 ? void 0 : scenario.assert?.footSlip?.find(({ atStep }) => atStep === label);
16078
16108
  const sightLineAssertion = scenario.assert?.sightLine;
@@ -16145,7 +16175,8 @@ async function runStandalonePlaytestOnce(config, options) {
16145
16175
  await samplePathPosition(bridge, pathEntity, pathPositions);
16146
16176
  await sampleSightLine(bridge, sightLine);
16147
16177
  },
16148
- sightLine
16178
+ sightLine,
16179
+ scenario.drawEvery
16149
16180
  );
16150
16181
  if (movementBaselineSnapshot === void 0 && movementNeedsBaseline && movementEntity !== void 0) {
16151
16182
  const candidate = stepSamples.afterStep ?? stepSamples.afterInput;
@@ -16619,6 +16650,13 @@ async function runDevicePlaytestInternal(config, target, cleanupState) {
16619
16650
  canDriveAndroidLifecycle(target.driver)
16620
16651
  );
16621
16652
  if (unsupported !== void 0) return failureReport(config, scenario, unsupported, target.name);
16653
+ if (scenario.drawEvery !== void 0) {
16654
+ return failureReport(config, scenario, unsupportedDiagnostic(
16655
+ "a drawEvery tick cadence",
16656
+ "Run this scenario on --target browser, which owns the fixed-step draw cadence, or remove drawEvery.",
16657
+ target.name
16658
+ ), target.name);
16659
+ }
16622
16660
  if (target.name === "android" && scenario.assert?.framebufferCoverage !== void 0 && (typeof target.driver.startScreenRecording !== "function" || typeof target.driver.stopScreenRecording !== "function")) {
16623
16661
  return failureReport(config, scenario, unsupportedDiagnostic(
16624
16662
  "framebuffer coverage recording",
@@ -16645,10 +16683,22 @@ async function runDevicePlaytestInternal(config, target, cleanupState) {
16645
16683
  let coverageRecordingStarted = false;
16646
16684
  let framebufferCoverage;
16647
16685
  const coverageVideoPath = join(config.artifactDirectory, "framebuffer-coverage.mp4");
16648
- const responseObservations = [];
16649
- transport.setResponseObserver?.((observation) => responseObservations.push(observation));
16686
+ let responseArchive;
16687
+ let responseWritten = false;
16688
+ let responseWrite = Promise.resolve();
16650
16689
  const metrics = deviceMetricsRecorder(target);
16651
16690
  try {
16691
+ const archive = await open(join(config.artifactDirectory, "device-response-observations.json"), "w");
16692
+ responseArchive = archive;
16693
+ await archive.writeFile(`{
16694
+ "responsePath": ${JSON.stringify(target.mailboxPaths.response)},
16695
+ "observations": [`, "utf8");
16696
+ transport.setResponseObserver?.((observation) => {
16697
+ responseWrite = archive.writeFile(`${responseWritten ? "," : ""}
16698
+ ${JSON.stringify(observation)}`, "utf8");
16699
+ responseWritten = true;
16700
+ return responseWrite;
16701
+ });
16652
16702
  await throwIfAborted(target);
16653
16703
  await transport.start();
16654
16704
  await throwIfAborted(target);
@@ -17056,17 +17106,6 @@ async function runDevicePlaytestInternal(config, target, cleanupState) {
17056
17106
  cleanupErrors.push(error);
17057
17107
  }
17058
17108
  };
17059
- await attemptCleanup(async () => {
17060
- await writeFile(
17061
- join(config.artifactDirectory, "device-response-observations.json"),
17062
- `${JSON.stringify({
17063
- responsePath: target.mailboxPaths.response,
17064
- observations: responseObservations
17065
- }, null, 2)}
17066
- `,
17067
- "utf8"
17068
- );
17069
- });
17070
17109
  if (scenario.steps.some((step) => step.pointers !== void 0)) {
17071
17110
  await attemptCleanup(async () => {
17072
17111
  if (target.name === "ios") {
@@ -17091,6 +17130,16 @@ async function runDevicePlaytestInternal(config, target, cleanupState) {
17091
17130
  await bridge?.close();
17092
17131
  });
17093
17132
  await attemptCleanup(() => transport.close());
17133
+ const archive = responseArchive;
17134
+ if (archive !== void 0) {
17135
+ await attemptCleanup(async () => {
17136
+ await responseWrite;
17137
+ await archive.writeFile(`${responseWritten ? "\n " : ""}]
17138
+ }
17139
+ `, "utf8");
17140
+ });
17141
+ await attemptCleanup(() => archive.close());
17142
+ }
17094
17143
  metrics?.stop();
17095
17144
  if (cleanupErrors.length > 0) cleanupState.error = cleanupFailure(cleanupErrors);
17096
17145
  }
@@ -929,6 +929,13 @@ interface IPlaytestScenario {
929
929
  sourcePath?: string;
930
930
  /** Absolute fixed-step tick reached after startup and warmup, before baseline and input. */
931
931
  startTick?: number;
932
+ /**
933
+ * Draw one frame every this many fixed-step ticks, in every tick-advancing step. A component
934
+ * that samples a GPU readback lands at most one sample per drawn frame, so without a cadence the
935
+ * number of samples a scenario gets is a property of the adapter's frame rate and not of its
936
+ * ticks. Absent, ticks advance undrawn as they always did.
937
+ */
938
+ drawEvery?: number;
932
939
  steps: IPlaytestStep[];
933
940
  subject?: string;
934
941
  target: PlaytestTarget;
@@ -1,10 +1,18 @@
1
- import { e as IPlaytestScenario, j as IPlaytestPerformanceAssertion } from './schema-base-B26KSBoa.js';
1
+ import { e as IPlaytestScenario, j as IPlaytestPerformanceAssertion } from './schema-base-C2pIQ165.js';
2
2
  import { IPlaytestObservationSnapshot } from './protocol.js';
3
3
  import { Page } from 'playwright';
4
- import { I as IPlaytestReport, p as IPlaytestProtocolDiagnostic, l as IPlaytestDiagnosticsPolicy, a as IPlaytestAssertionResult } from './diagnostics-BKg7C6Lf.js';
4
+ import { I as IPlaytestReport, p as IPlaytestProtocolDiagnostic, l as IPlaytestDiagnosticsPolicy, a as IPlaytestAssertionResult } from './diagnostics-BPaaU6JB.js';
5
5
 
6
6
  /** Capture the largest rendered canvas bounds without waiting for locator screenshot stability. */
7
7
  declare function captureVisualSurface(page: Page, artifactPath?: string): Promise<Buffer | undefined>;
8
+ /**
9
+ * A step's draw cadence: one rendered frame every `every` ticks. `ticks` counts what the step has
10
+ * already advanced, so a later call (the 10-tick path cadence) continues the same phase.
11
+ */
12
+ interface IFixedStepDraw {
13
+ every: number;
14
+ ticks: number;
15
+ }
8
16
  /**
9
17
  * The core bridge is installed before an async scene load completes, so its describe/ready
10
18
  * handshake can finish one browser frame before the fixed-step loop starts. Retry only that
@@ -14,7 +22,7 @@ declare function advanceFixedStep(page: Page, bridge: {
14
22
  advance(ticks: number, options?: {
15
23
  render?: boolean;
16
24
  }): Promise<number | undefined | void>;
17
- }, ticks: number, render?: boolean): Promise<void>;
25
+ }, ticks: number, render?: boolean, draw?: IFixedStepDraw): Promise<void>;
18
26
  declare function playtestStepDrivesMovement(step: IPlaytestScenario["steps"][number], hasHeldInput: boolean): boolean;
19
27
  interface ICompletionWindow {
20
28
  label: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@threenative/playtest",
3
- "version": "0.3.11",
3
+ "version": "0.3.12",
4
4
  "license": "MIT",
5
5
  "description": "Scenario-driven playtest harness for Three.js games. Runs on plain Three.js with zero ThreeNative dependencies.",
6
6
  "keywords": [
@@ -18,7 +18,7 @@
18
18
  },
19
19
  "repository": {
20
20
  "type": "git",
21
- "url": "git+https://github.com/ThreeNativeHQ/threenative.git",
21
+ "url": "git+https://github.com/ThreeNativeHQ/threenative-engine.git",
22
22
  "directory": "packages/playtest"
23
23
  },
24
24
  "type": "module",