@threenative/playtest 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +556 -127
- package/dist/runner/cli.js +2033 -216
- package/dist/runner/index.js +2036 -230
- package/dist/three/index.js +523 -8
- package/package.json +1 -1
- package/dist/diagnostics-Ckm_5lrw.d.ts +0 -549
- package/dist/index.d.ts +0 -25
- package/dist/protocol-CeC1lz_G.d.ts +0 -130
- package/dist/runner/cli.d.ts +0 -20
- package/dist/runner/index.d.ts +0 -390
- package/dist/three/index.d.ts +0 -65
package/dist/runner/cli.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
2
|
+
import { existsSync, realpathSync } from 'fs';
|
|
3
|
+
import { access, mkdir, writeFile, readFile, stat, mkdtemp, rm, unlink, rename, readdir, copyFile } from 'fs/promises';
|
|
3
4
|
import { resolve, dirname, join, basename } from 'path';
|
|
4
5
|
import { fileURLToPath } from 'url';
|
|
5
6
|
import { execFile, spawn } from 'child_process';
|
|
6
|
-
import { existsSync } from 'fs';
|
|
7
7
|
import { tmpdir, homedir } from 'os';
|
|
8
8
|
import { promisify } from 'util';
|
|
9
9
|
import { createServer } from 'http';
|
|
@@ -12,6 +12,30 @@ import { chromium } from 'playwright';
|
|
|
12
12
|
|
|
13
13
|
// src/assertions.ts
|
|
14
14
|
var PLAYTEST_ASSERTION_REGISTRY = [
|
|
15
|
+
{
|
|
16
|
+
description: "Samples the framebuffer on every render frame inside a labeled loading window and requires every coarse-grid RGB sample to match the declared backdrop.",
|
|
17
|
+
example: {
|
|
18
|
+
framebufferCoverage: {
|
|
19
|
+
backdrop: [5, 7, 11],
|
|
20
|
+
grid: { columns: 32, rows: 18 },
|
|
21
|
+
tolerance: 8,
|
|
22
|
+
window: { endStep: "loading-end", startStep: "loading-start" }
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
fields: [
|
|
26
|
+
{ description: "Backdrop RGB byte channels every sampled pixel must match.", name: "backdrop", required: true, type: "[integer 0..255, integer 0..255, integer 0..255]" },
|
|
27
|
+
{ description: "Coarse sample grid. Defaults to 32x18, which catches the loading leak while limiting synchronous readback work.", name: "grid", type: "{ columns: positive integer <= 256, rows: positive integer <= 256 }" },
|
|
28
|
+
{ description: "Maximum absolute difference allowed for each RGB channel.", name: "tolerance", required: true, type: "integer 0..255" },
|
|
29
|
+
{ description: "Inclusive labeled-step boundaries for the loading-covered interval.", name: "window", required: true, type: "{ startStep: string, endStep: string }" }
|
|
30
|
+
],
|
|
31
|
+
cardinality: "object",
|
|
32
|
+
kind: "framebufferCoverage",
|
|
33
|
+
observationPath: "framebufferCoverage",
|
|
34
|
+
requiredCapabilities: ["browser.screenshot"],
|
|
35
|
+
resultIdPrefix: "framebufferCoverage",
|
|
36
|
+
supportedOn: ["web", "desktop", "bevy"],
|
|
37
|
+
triviality: "not-applicable"
|
|
38
|
+
},
|
|
15
39
|
{
|
|
16
40
|
description: "Checks every consecutive platform against a measured static movement-envelope fit; it does not simulate traversal, walls, ceilings, run-up, or air control.",
|
|
17
41
|
example: { reachability: { artifact: "artifacts/character-envelope/player.json", entities: ["platform.a", "platform.b"] } },
|
|
@@ -64,7 +88,7 @@ var PLAYTEST_ASSERTION_REGISTRY = [
|
|
|
64
88
|
description: "Proves the subject moved, reached a minimum velocity, or changed rotation during held input.",
|
|
65
89
|
example: { movement: { entity: "player", minDistance: 0.5, minVelocity: 0.01, rotationChanged: true } },
|
|
66
90
|
fields: [
|
|
67
|
-
{ description: "
|
|
91
|
+
{ description: "Optional entity id to measure; when omitted, choose an observed mover.", name: "entity", type: "string" },
|
|
68
92
|
{ description: "Require distance to a fixed world position to decrease by at least min.", name: "closesDistanceToPosition", type: "{ position: [number, number, number], min: number }" },
|
|
69
93
|
{ description: "Maximum yaw error from resolved movement direction.", name: "facesMovementWithinDegrees", type: "number" },
|
|
70
94
|
{ description: "Expected movement axis: x, y, or z.", name: "axis", type: "string" },
|
|
@@ -184,10 +208,10 @@ var PLAYTEST_ASSERTION_REGISTRY = [
|
|
|
184
208
|
triviality: "not-applicable"
|
|
185
209
|
},
|
|
186
210
|
{
|
|
187
|
-
description: "Proves an entity's final runtime-owned state-machine state.",
|
|
188
|
-
example: { states: [{
|
|
211
|
+
description: "Proves an observed entity's final runtime-owned state-machine state.",
|
|
212
|
+
example: { states: [{ equals: "completed" }] },
|
|
189
213
|
fields: [
|
|
190
|
-
{ description: "
|
|
214
|
+
{ description: "Optional entity id; when omitted, choose an observed state candidate.", name: "entity", type: "string" },
|
|
191
215
|
{ description: "Expected current state name.", name: "equals", required: true, type: "string" }
|
|
192
216
|
],
|
|
193
217
|
cardinality: "array",
|
|
@@ -244,6 +268,8 @@ var PLAYTEST_ASSERTION_REGISTRY = [
|
|
|
244
268
|
{ description: "Fail on captured console errors.", name: "noConsoleErrors", type: "boolean" },
|
|
245
269
|
{ description: "Fail on captured network errors.", name: "noNetworkErrors", type: "boolean" },
|
|
246
270
|
{ description: "Fail on runtime diagnostics.", name: "noRuntimeDiagnostics", type: "boolean" },
|
|
271
|
+
{ description: "Required bounded justification when noConsoleErrors is false.", name: "consoleErrorsOptOutReason", type: "non-empty string" },
|
|
272
|
+
{ description: "Required bounded justification when noNetworkErrors is false.", name: "networkErrorsOptOutReason", type: "non-empty string" },
|
|
247
273
|
{ description: "Required bounded justification when noRuntimeDiagnostics is false.", name: "runtimeDiagnosticsOptOutReason", type: "non-empty string" },
|
|
248
274
|
{ description: "Require runtime readiness.", name: "runtimeReady", type: "boolean" }
|
|
249
275
|
],
|
|
@@ -255,6 +281,22 @@ var PLAYTEST_ASSERTION_REGISTRY = [
|
|
|
255
281
|
supportedOn: ["web"],
|
|
256
282
|
triviality: "not-applicable"
|
|
257
283
|
},
|
|
284
|
+
{
|
|
285
|
+
description: "Proves a live render sample exists and optionally bounds frame time, draw calls, and triangles.",
|
|
286
|
+
example: { performance: { maxDrawCalls: 100, maxFrameMsP95: 33, maxTriangles: 1e4 } },
|
|
287
|
+
fields: [
|
|
288
|
+
{ description: "Maximum nearest-rank 95th-percentile frame time in milliseconds.", name: "maxFrameMsP95", type: "number" },
|
|
289
|
+
{ description: "Maximum observed renderer draw-call count.", name: "maxDrawCalls", type: "number" },
|
|
290
|
+
{ description: "Maximum observed renderer triangle count.", name: "maxTriangles", type: "number" }
|
|
291
|
+
],
|
|
292
|
+
cardinality: "object",
|
|
293
|
+
kind: "performance",
|
|
294
|
+
observationPath: "performanceSeries",
|
|
295
|
+
requiredCapabilities: ["runtime.performance"],
|
|
296
|
+
resultIdPrefix: "performance.",
|
|
297
|
+
supportedOn: ["web", "desktop", "bevy"],
|
|
298
|
+
triviality: "not-applicable"
|
|
299
|
+
},
|
|
258
300
|
{
|
|
259
301
|
description: "Proves projected entity visibility in the viewport.",
|
|
260
302
|
example: { visibility: [{ entity: "player", minProjectedPixels: 1200, maxOffscreenRatio: 0.05 }] },
|
|
@@ -292,7 +334,7 @@ var PLAYTEST_ASSERTION_REGISTRY = [
|
|
|
292
334
|
example: { contacts: [{ entity: "player", with: "pickup", kind: "trigger", minCount: 1 }] },
|
|
293
335
|
fields: [
|
|
294
336
|
{ description: "Retained step label to inspect instead of the full observation history.", name: "atStep", type: "string" },
|
|
295
|
-
{ description: "
|
|
337
|
+
{ description: "Optional entity id; when omitted, choose an observed contact candidate.", name: "entity", type: "string" },
|
|
296
338
|
{ description: "Other entity or tag token expected in the contact evidence.", name: "with", type: "string" },
|
|
297
339
|
{ description: "Contact kind token, such as contact or trigger.", name: "kind", type: "string" },
|
|
298
340
|
{ description: "Minimum number of matching observations.", name: "minCount", type: "number" },
|
|
@@ -308,10 +350,10 @@ var PLAYTEST_ASSERTION_REGISTRY = [
|
|
|
308
350
|
triviality: "not-applicable"
|
|
309
351
|
},
|
|
310
352
|
{
|
|
311
|
-
description: "Proves matching physics bodies
|
|
312
|
-
example: { settled: [{ atStep: "fall-and-settle",
|
|
353
|
+
description: "Proves an observed cohort of matching physics bodies is asleep in a retained physics-debug sample.",
|
|
354
|
+
example: { settled: [{ atStep: "fall-and-settle", minBodies: 15 }] },
|
|
313
355
|
fields: [
|
|
314
|
-
{ description: "
|
|
356
|
+
{ description: "Optional exact entity id or stable entity-id prefix; when omitted, choose an observed cohort.", name: "entity", type: "string" },
|
|
315
357
|
{ description: "Optional labeled step whose physics-debug sample must be used.", name: "atStep", type: "string" },
|
|
316
358
|
{ description: "Minimum number of matching bodies required.", name: "minBodies", type: "positive integer" },
|
|
317
359
|
{ description: "Optional earlier labeled step whose matching body positions are compared.", name: "compareToStep", type: "string" },
|
|
@@ -373,7 +415,7 @@ var PLAYTEST_SETUP_REGISTRY = [
|
|
|
373
415
|
];
|
|
374
416
|
function requiredPlaytestCapabilities(scenario) {
|
|
375
417
|
const required = /* @__PURE__ */ new Set();
|
|
376
|
-
if (scenario.steps.some((step) => step.kind !== "wait" && (step.press !== void 0 || step.pointerPosition !== void 0))) {
|
|
418
|
+
if (scenario.steps.some((step) => step.kind !== "wait" && (step.press !== void 0 || step.pointerPosition !== void 0 || step.pointers !== void 0))) {
|
|
377
419
|
required.add("browser.input");
|
|
378
420
|
}
|
|
379
421
|
if (scenario.artifacts?.screenshots !== false) {
|
|
@@ -398,10 +440,75 @@ function requiredPlaytestCapabilities(scenario) {
|
|
|
398
440
|
}
|
|
399
441
|
return [...required].sort();
|
|
400
442
|
}
|
|
443
|
+
function resolveDiagnosticsPolicy(policy) {
|
|
444
|
+
return {
|
|
445
|
+
...policy?.consoleErrorsOptOutReason === void 0 ? {} : { consoleErrorsOptOutReason: policy.consoleErrorsOptOutReason },
|
|
446
|
+
...policy?.networkErrorsOptOutReason === void 0 ? {} : { networkErrorsOptOutReason: policy.networkErrorsOptOutReason },
|
|
447
|
+
noConsoleErrors: policy?.noConsoleErrors ?? true,
|
|
448
|
+
noNetworkErrors: policy?.noNetworkErrors ?? true,
|
|
449
|
+
noRuntimeDiagnostics: policy?.noRuntimeDiagnostics ?? true,
|
|
450
|
+
...policy?.runtimeReady === void 0 ? {} : { runtimeReady: policy.runtimeReady },
|
|
451
|
+
...policy?.runtimeDiagnosticsOptOutReason === void 0 ? {} : { runtimeDiagnosticsOptOutReason: policy.runtimeDiagnosticsOptOutReason }
|
|
452
|
+
};
|
|
453
|
+
}
|
|
401
454
|
function evaluateRichPlaytestAssertions(input) {
|
|
402
455
|
const assertions = [];
|
|
403
456
|
const diagnostics = [];
|
|
404
457
|
const scenarioAssertions = input.scenario.assert ?? {};
|
|
458
|
+
if (scenarioAssertions.framebufferCoverage !== void 0) {
|
|
459
|
+
const observation = input.report.observations?.framebufferCoverage;
|
|
460
|
+
const started = observation?.windowStarted === true;
|
|
461
|
+
const completed = observation?.windowCompleted === true;
|
|
462
|
+
const framesObserved = (observation?.frameCount ?? 0) > 0;
|
|
463
|
+
const readable = observation?.unreadableReason === void 0;
|
|
464
|
+
const violation = observation?.firstViolation;
|
|
465
|
+
const evidenceComplete = violation === void 0 || violation.grid.samples.length === violation.grid.columns * violation.grid.rows && violation.screenshotPath.length > 0;
|
|
466
|
+
const pass = started && completed && framesObserved && readable && violation === void 0 && evidenceComplete;
|
|
467
|
+
assertions.push({
|
|
468
|
+
details: {
|
|
469
|
+
boundarySource: observation?.boundarySource ?? null,
|
|
470
|
+
evidenceComplete,
|
|
471
|
+
firstViolation: violation ?? null,
|
|
472
|
+
frameCount: observation?.frameCount ?? 0,
|
|
473
|
+
unreadableReason: observation?.unreadableReason ?? null,
|
|
474
|
+
windowCompleted: completed,
|
|
475
|
+
windowStarted: started
|
|
476
|
+
},
|
|
477
|
+
id: "framebufferCoverage",
|
|
478
|
+
pass
|
|
479
|
+
});
|
|
480
|
+
if (!readable) {
|
|
481
|
+
diagnostics.push({
|
|
482
|
+
code: "TN_PLAYTEST_FRAMEBUFFER_PIXELS_UNREADABLE",
|
|
483
|
+
message: `Framebuffer pixels could not be read: ${observation?.unreadableReason}.`,
|
|
484
|
+
severity: "error",
|
|
485
|
+
suggestion: "On headless Linux, prefix the command with xvfb-run -a -s '-screen 0 1600x900x24'."
|
|
486
|
+
});
|
|
487
|
+
} else if (!started || !completed) {
|
|
488
|
+
diagnostics.push({
|
|
489
|
+
code: "TN_PLAYTEST_FRAMEBUFFER_WINDOW_NOT_REACHED",
|
|
490
|
+
message: !started ? "The run never reached the declared framebuffer coverage window." : "The run entered but never completed the declared framebuffer coverage window.",
|
|
491
|
+
severity: "error",
|
|
492
|
+
suggestion: "Check the assertion's startStep/endStep labels and keep the run alive through the complete loading interval."
|
|
493
|
+
});
|
|
494
|
+
} else if (!framesObserved) {
|
|
495
|
+
diagnostics.push({
|
|
496
|
+
code: "TN_PLAYTEST_FRAMEBUFFER_FRAMES_MISSING",
|
|
497
|
+
message: "The framebuffer coverage window completed without observing any render frames.",
|
|
498
|
+
severity: "error",
|
|
499
|
+
suggestion: "Keep at least one requestAnimationFrame-driven frame inside the labeled loading window."
|
|
500
|
+
});
|
|
501
|
+
} else if (violation !== void 0) {
|
|
502
|
+
diagnostics.push({
|
|
503
|
+
artifactPath: violation.screenshotPath,
|
|
504
|
+
code: evidenceComplete ? "TN_PLAYTEST_FRAMEBUFFER_COVERAGE_FAILED" : "TN_PLAYTEST_FRAMEBUFFER_EVIDENCE_MISSING",
|
|
505
|
+
message: evidenceComplete ? `Framebuffer coverage first diverged from the declared backdrop at frame ${violation.frameIndex}.` : `Framebuffer coverage diverged at frame ${violation.frameIndex}, but its grid or screenshot evidence is incomplete.`,
|
|
506
|
+
observedRuntimePath: "observations.json/framebufferCoverage/firstViolation/grid",
|
|
507
|
+
severity: "error",
|
|
508
|
+
suggestion: "Inspect the violating-frame screenshot and RGB sample grid; fix the render pass that drew during the loading-covered window."
|
|
509
|
+
});
|
|
510
|
+
}
|
|
511
|
+
}
|
|
405
512
|
if (scenarioAssertions.reachability !== void 0) {
|
|
406
513
|
const { entities, envelope } = scenarioAssertions.reachability;
|
|
407
514
|
for (let index = 0; index < entities.length - 1; index += 1) {
|
|
@@ -455,8 +562,17 @@ function evaluateRichPlaytestAssertions(input) {
|
|
|
455
562
|
suggestion: "Inspect observations.json/overlayNodes and verify the overlay subscription, selector, attribute, and computed style."
|
|
456
563
|
});
|
|
457
564
|
}
|
|
458
|
-
const
|
|
459
|
-
|
|
565
|
+
const captureFailure = input.report.observations?.visual?.captureFailure;
|
|
566
|
+
const hasVisualSamples = input.report.observations?.visual !== void 0 && captureFailure === void 0;
|
|
567
|
+
if ((scenarioAssertions.visual?.length ?? 0) > 0 && captureFailure !== void 0) {
|
|
568
|
+
for (const [index] of scenarioAssertions.visual.entries()) {
|
|
569
|
+
assertions.push({
|
|
570
|
+
details: { captureFailure, reason: "not-evaluated" },
|
|
571
|
+
id: `visual.${index}`,
|
|
572
|
+
pass: true
|
|
573
|
+
});
|
|
574
|
+
}
|
|
575
|
+
} else if ((scenarioAssertions.visual?.length ?? 0) > 0 && !hasVisualSamples) {
|
|
460
576
|
for (const [index] of scenarioAssertions.visual.entries()) {
|
|
461
577
|
assertions.push({ id: `visual.${index}`, pass: false, details: { reason: "target-unsupported", target: input.scenario.target } });
|
|
462
578
|
diagnostics.push(assertionNotEvaluatedDiagnostic(`visual.${index}`, `target '${input.scenario.target}' does not expose visual assertion samples`));
|
|
@@ -505,6 +621,15 @@ function evaluateRichPlaytestAssertions(input) {
|
|
|
505
621
|
if (!pass) diagnostics.push({ code: "TN_PLAYTEST_ENTITY_VISIBILITY_DROPPED", message: `Entity '${visual.entityVisible.entity}' dropped below ${visual.entityVisible.minProjectedPixels} projected pixels.`, severity: "error", suggestion: "Check per-frame visibility, camera clipping, scale, and renderer state." });
|
|
506
622
|
}
|
|
507
623
|
}
|
|
624
|
+
if (scenarioAssertions.performance !== void 0) {
|
|
625
|
+
const result = evaluatePerformanceAssertion(
|
|
626
|
+
scenarioAssertions.performance,
|
|
627
|
+
input.report.observations?.performanceSeries,
|
|
628
|
+
input.scenario.sourcePath
|
|
629
|
+
);
|
|
630
|
+
assertions.push(...result.assertions);
|
|
631
|
+
diagnostics.push(...result.diagnostics);
|
|
632
|
+
}
|
|
508
633
|
for (const assertion of scenarioAssertions.resources ?? []) {
|
|
509
634
|
if (assertion.anyOf !== void 0) {
|
|
510
635
|
const result = evaluateResourceAnyOfAssertion(assertion, input.report.observations?.resources[assertion.id], {
|
|
@@ -684,31 +809,27 @@ function evaluateRichPlaytestAssertions(input) {
|
|
|
684
809
|
diagnostics.push(result.diagnostic);
|
|
685
810
|
}
|
|
686
811
|
}
|
|
687
|
-
for (const assertion of scenarioAssertions.states ?? []) {
|
|
688
|
-
const result = evaluateStateAssertion(assertion, input.report.observations
|
|
812
|
+
for (const [stateIndex, assertion] of (scenarioAssertions.states ?? []).entries()) {
|
|
813
|
+
const result = evaluateStateAssertion(assertion, input.report.observations, input.scenario, stateIndex);
|
|
689
814
|
assertions.push(result.assertion);
|
|
690
815
|
if (result.diagnostic !== void 0) {
|
|
691
816
|
diagnostics.push(result.diagnostic);
|
|
692
817
|
}
|
|
693
818
|
}
|
|
694
819
|
{
|
|
695
|
-
const diagnosticsPolicy =
|
|
696
|
-
...scenarioAssertions.diagnostics,
|
|
697
|
-
noRuntimeDiagnostics: scenarioAssertions.diagnostics?.noRuntimeDiagnostics ?? true
|
|
698
|
-
};
|
|
820
|
+
const diagnosticsPolicy = resolveDiagnosticsPolicy(scenarioAssertions.diagnostics);
|
|
699
821
|
const policyDiagnostics = evaluateDiagnosticsPolicy(input.report, diagnosticsPolicy);
|
|
700
822
|
diagnostics.push(...policyDiagnostics);
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
}
|
|
823
|
+
assertions.push({
|
|
824
|
+
details: {
|
|
825
|
+
consoleErrors: consoleErrors(input.report.observations?.console ?? []).length,
|
|
826
|
+
networkErrors: input.report.observations?.network.length ?? 0,
|
|
827
|
+
policy: diagnosticsPolicy,
|
|
828
|
+
runtimeDiagnostics: runtimeDiagnostics(input.report.observations?.runtimeDiagnostics).length
|
|
829
|
+
},
|
|
830
|
+
id: "diagnostics",
|
|
831
|
+
pass: policyDiagnostics.length === 0
|
|
832
|
+
});
|
|
712
833
|
}
|
|
713
834
|
if (scenarioAssertions.movement?.minVelocity !== void 0) {
|
|
714
835
|
const velocity = input.report.frames <= 0 ? 0 : input.report.distance / input.report.frames;
|
|
@@ -726,7 +847,7 @@ function evaluateRichPlaytestAssertions(input) {
|
|
|
726
847
|
if (scenarioAssertions.movement?.minDistance !== void 0) {
|
|
727
848
|
const pass = input.report.distance >= scenarioAssertions.movement.minDistance;
|
|
728
849
|
assertions.push({
|
|
729
|
-
details: { distance: input.report.distance, minimum: scenarioAssertions.movement.minDistance },
|
|
850
|
+
details: { distance: input.report.distance, entity: input.report.entity, minimum: scenarioAssertions.movement.minDistance },
|
|
730
851
|
id: "movement.distance",
|
|
731
852
|
pass
|
|
732
853
|
});
|
|
@@ -954,36 +1075,48 @@ function evaluateRichPlaytestAssertions(input) {
|
|
|
954
1075
|
diagnostics.push(result.diagnostic);
|
|
955
1076
|
}
|
|
956
1077
|
}
|
|
957
|
-
for (const assertion of scenarioAssertions.contacts ?? []) {
|
|
958
|
-
const entity = assertion.entity ?? input.scenario.subject
|
|
1078
|
+
for (const [contactIndex, assertion] of (scenarioAssertions.contacts ?? []).entries()) {
|
|
1079
|
+
const entity = assertion.entity ?? input.scenario.subject;
|
|
1080
|
+
const anonymous = entity === void 0;
|
|
959
1081
|
if (assertion.requiredOn !== void 0 && !assertion.requiredOn.includes(input.scenario.target)) {
|
|
960
1082
|
assertions.push({
|
|
961
|
-
details: { entity, requiredOn: assertion.requiredOn, skipped: true, target: input.scenario.target },
|
|
962
|
-
id: `contact.${entity}`,
|
|
1083
|
+
details: { entity: entity || "anonymous", requiredOn: assertion.requiredOn, skipped: true, target: input.scenario.target },
|
|
1084
|
+
id: assertion.entity === void 0 ? `contact.${contactIndex}` : `contact.${entity}`,
|
|
963
1085
|
pass: true
|
|
964
1086
|
});
|
|
965
1087
|
continue;
|
|
966
1088
|
}
|
|
967
1089
|
const tokens = [entity, assertion.with, assertion.kind].filter((item) => item !== void 0);
|
|
968
1090
|
const selectedSample = assertion.atStep === void 0 ? void 0 : input.report.observations?.physicsDebugSeries?.find((sample) => sample.label === assertion.atStep);
|
|
969
|
-
const
|
|
1091
|
+
const runtimeStepAvailable = assertion.atStep === void 0 || runtimeGameplayAtStep(input.report.observations?.runtimeObservations, assertion.atStep) !== void 0;
|
|
1092
|
+
const stepAvailable = assertion.atStep === void 0 || selectedSample !== void 0 || runtimeStepAvailable;
|
|
970
1093
|
const effectEvidence = assertion.atStep === void 0 ? mergeEffectLogs(input.report.effectLog, input.report.observations?.effectLogSeries) : [];
|
|
971
1094
|
const effectCount = countMatchingEntries(effectEvidence, tokens);
|
|
972
1095
|
const runtimeCount = assertion.atStep === void 0 ? countRuntimeContacts(input.report.observations?.runtimeObservations, entity, assertion.with, assertion.kind) : 0;
|
|
973
|
-
const
|
|
974
|
-
const
|
|
1096
|
+
const physicsEvidence = assertion.kind === void 0 || assertion.kind === "contact" ? physicsDebugContactEvidence(input.report.observations, entity, assertion.with, selectedSample?.snapshot) : { candidates: [], count: 0 };
|
|
1097
|
+
const runtimeEvidence = runtimeContactEvidence(
|
|
1098
|
+
input.report.observations?.runtimeObservations,
|
|
1099
|
+
entity,
|
|
1100
|
+
assertion.with,
|
|
1101
|
+
assertion.kind,
|
|
1102
|
+
assertion.atStep
|
|
1103
|
+
);
|
|
1104
|
+
const candidates = [.../* @__PURE__ */ new Set([...physicsEvidence.candidates, ...runtimeEvidence.candidates])];
|
|
1105
|
+
const count = effectCount + physicsEvidence.count + (assertion.atStep === void 0 ? runtimeCount : runtimeEvidence.count);
|
|
975
1106
|
const minCount = assertion.minCount ?? (assertion.maxCount === void 0 ? 1 : 0);
|
|
976
|
-
const
|
|
977
|
-
|
|
1107
|
+
const candidatesAvailable = !anonymous || candidates.length > 0;
|
|
1108
|
+
const pass = stepAvailable && candidatesAvailable && count >= minCount && (assertion.maxCount === void 0 || count <= assertion.maxCount);
|
|
1109
|
+
const resultEntity = entity || "anonymous";
|
|
1110
|
+
assertions.push({ details: { atStep: assertion.atStep, candidates, count, entity: resultEntity, kind: assertion.kind, maxCount: assertion.maxCount, minCount, with: assertion.with }, id: assertion.entity === void 0 ? `contact.${contactIndex}` : `contact.${resultEntity}`, pass });
|
|
978
1111
|
if (!pass) {
|
|
979
1112
|
const partial = summarizeMatchingEntries(effectEvidence, [entity, assertion.with].filter((item) => item !== void 0));
|
|
980
1113
|
const hasPhysicsDebugEvidence = input.report.observations?.physicsDebug !== void 0 || (input.report.observations?.physicsDebugSeries?.length ?? 0) > 0;
|
|
981
1114
|
diagnostics.push({
|
|
982
1115
|
artifactPath: partial !== void 0 || !hasPhysicsDebugEvidence ? "effect-log.json" : "observations.json",
|
|
983
|
-
code: !stepAvailable ? "TN_PLAYTEST_CONTACT_STEP_NOT_OBSERVED" : assertion.maxCount !== void 0 && count > assertion.maxCount ? "TN_PLAYTEST_CONTACT_COUNT_EXCEEDED" : "TN_PLAYTEST_CONTACT_NOT_OBSERVED",
|
|
984
|
-
message: !stepAvailable ? `Contact assertion step '${assertion.atStep}' was not retained.` : assertion.maxCount !== void 0 && count > assertion.maxCount ? `Contact/trigger for '${
|
|
985
|
-
observedRuntimePath: `observations.json/physicsDebugSeries/artifact/primitives[category=contact,entity=${
|
|
986
|
-
path: `${input.scenario.sourcePath ?? "playtest"}/assert/contacts/${
|
|
1116
|
+
code: !stepAvailable ? "TN_PLAYTEST_CONTACT_STEP_NOT_OBSERVED" : !candidatesAvailable ? "TN_PLAYTEST_CONTACT_CANDIDATES_UNAVAILABLE" : assertion.maxCount !== void 0 && count > assertion.maxCount ? "TN_PLAYTEST_CONTACT_COUNT_EXCEEDED" : "TN_PLAYTEST_CONTACT_NOT_OBSERVED",
|
|
1117
|
+
message: !stepAvailable ? `Contact assertion step '${assertion.atStep}' was not retained.` : !candidatesAvailable ? "No observed contact candidate was retained for the anonymous contact assertion." : assertion.maxCount !== void 0 && count > assertion.maxCount ? `Contact/trigger for '${resultEntity}' was observed ${count} time(s), above allowed ${assertion.maxCount}.` : `Expected contact/trigger for '${resultEntity}' was not observed ${minCount} time(s).`,
|
|
1118
|
+
observedRuntimePath: `observations.json/physicsDebugSeries/artifact/primitives[category=contact,entity=${resultEntity}] | effect-log.json/entries[kind=service|event,entity=${resultEntity}]`,
|
|
1119
|
+
path: `${input.scenario.sourcePath ?? "playtest"}/assert/contacts/${resultEntity}`,
|
|
987
1120
|
severity: "error",
|
|
988
1121
|
...input.scenario.sourcePath === void 0 ? {} : { sourcePath: input.scenario.sourcePath },
|
|
989
1122
|
...partial?.systemId === void 0 ? {} : { systemId: partial.systemId, sourcePath: partial.sourcePath },
|
|
@@ -991,34 +1124,39 @@ function evaluateRichPlaytestAssertions(input) {
|
|
|
991
1124
|
});
|
|
992
1125
|
}
|
|
993
1126
|
}
|
|
994
|
-
for (const assertion of scenarioAssertions.settled ?? []) {
|
|
1127
|
+
for (const [settledIndex, assertion] of (scenarioAssertions.settled ?? []).entries()) {
|
|
995
1128
|
if (assertion.requiredOn !== void 0 && !assertion.requiredOn.includes(input.scenario.target)) {
|
|
996
1129
|
assertions.push({
|
|
997
|
-
details: { entity: assertion.entity, requiredOn: assertion.requiredOn, skipped: true, target: input.scenario.target },
|
|
998
|
-
id: `settled.${assertion.entity}`,
|
|
1130
|
+
details: { entity: assertion.entity ?? "anonymous", requiredOn: assertion.requiredOn, skipped: true, target: input.scenario.target },
|
|
1131
|
+
id: `settled.${assertion.entity ?? "anonymous"}`,
|
|
999
1132
|
pass: true
|
|
1000
1133
|
});
|
|
1001
1134
|
continue;
|
|
1002
1135
|
}
|
|
1003
1136
|
const snapshot = assertion.atStep === void 0 ? input.report.observations?.physicsDebugSeries?.at(-1)?.snapshot ?? input.report.observations?.physicsDebug : input.report.observations?.physicsDebugSeries?.find((sample) => sample.label === assertion.atStep)?.snapshot;
|
|
1004
|
-
const bodies = physicsDebugSleepStates(snapshot, assertion.entity);
|
|
1005
1137
|
const minimum = assertion.minBodies ?? 1;
|
|
1138
|
+
const candidate = settledCandidate(snapshot, assertion.entity);
|
|
1139
|
+
const bodies = candidate?.bodies ?? [];
|
|
1140
|
+
const omittedBodies = physicsDebugOmittedBodies(snapshot);
|
|
1006
1141
|
const sleeping = bodies.filter((body) => body.sleeping).length;
|
|
1007
1142
|
const comparisonSnapshot = assertion.compareToStep === void 0 ? void 0 : input.report.observations?.physicsDebugSeries?.find((sample) => sample.label === assertion.compareToStep)?.snapshot;
|
|
1008
|
-
const
|
|
1143
|
+
const selectedEntity = candidate?.selector ?? assertion.entity ?? "";
|
|
1144
|
+
const poseDistance = assertion.compareToStep === void 0 ? void 0 : physicsDebugMeanPoseDistance(snapshot, comparisonSnapshot, selectedEntity);
|
|
1009
1145
|
const posePass = assertion.minMeanPoseDistance === void 0 || poseDistance !== void 0 && poseDistance.sharedBodies >= minimum && poseDistance.mean >= assertion.minMeanPoseDistance;
|
|
1010
|
-
const
|
|
1146
|
+
const complete = omittedBodies === 0;
|
|
1147
|
+
const pass = complete && candidate !== void 0 && bodies.length >= minimum && sleeping === bodies.length && posePass;
|
|
1148
|
+
const resultEntity = candidate?.selector ?? assertion.entity ?? "anonymous";
|
|
1011
1149
|
assertions.push({
|
|
1012
|
-
details: { atStep: assertion.atStep, bodies: bodies.length, compareToStep: assertion.compareToStep, entity:
|
|
1013
|
-
id: `settled.${assertion.entity}`,
|
|
1150
|
+
details: { atStep: assertion.atStep, bodies: bodies.length, candidates: candidate?.candidates ?? [], compareToStep: assertion.compareToStep, entity: resultEntity, minimum, omittedBodies, poseDistance, sleeping },
|
|
1151
|
+
id: assertion.entity === void 0 ? `settled.${settledIndex}` : `settled.${assertion.entity}`,
|
|
1014
1152
|
pass
|
|
1015
1153
|
});
|
|
1016
1154
|
if (!pass) diagnostics.push({
|
|
1017
1155
|
artifactPath: "observations.json",
|
|
1018
|
-
code: !posePass ? "TN_PLAYTEST_RAGDOLL_POSE_NOT_DISTINCT" : "TN_PLAYTEST_PHYSICS_NOT_SETTLED",
|
|
1019
|
-
message: !posePass ? `Expected mean settled-pose distance for '${
|
|
1156
|
+
code: !complete ? "TN_PLAYTEST_PHYSICS_EVIDENCE_TRUNCATED" : !posePass ? "TN_PLAYTEST_RAGDOLL_POSE_NOT_DISTINCT" : "TN_PLAYTEST_PHYSICS_NOT_SETTLED",
|
|
1157
|
+
message: !complete ? `Physics evidence omitted ${omittedBodies} bod${omittedBodies === 1 ? "y" : "ies"}; settled cannot pass on a partial snapshot.` : !posePass ? `Expected mean settled-pose distance for '${resultEntity}' to reach ${assertion.minMeanPoseDistance}m from step '${assertion.compareToStep}'; observed ${poseDistance?.mean ?? "unavailable"}m across ${poseDistance?.sharedBodies ?? 0} bodies.` : `Expected at least ${minimum} physics bod${minimum === 1 ? "y" : "ies"} matching '${resultEntity}' to be asleep; observed ${sleeping} of ${bodies.length}.`,
|
|
1020
1158
|
observedRuntimePath: "observations.json/physicsDebugSeries/artifact/primitives[category=sleep]",
|
|
1021
|
-
path: `${input.scenario.sourcePath ?? "playtest"}/assert/settled/${
|
|
1159
|
+
path: `${input.scenario.sourcePath ?? "playtest"}/assert/settled/${resultEntity}`,
|
|
1022
1160
|
severity: "error",
|
|
1023
1161
|
...input.scenario.sourcePath === void 0 ? {} : { sourcePath: input.scenario.sourcePath },
|
|
1024
1162
|
suggestion: "Allow a longer settle window or fix damping, contacts, joints, and persistent forces that keep the bodies awake."
|
|
@@ -1078,7 +1216,7 @@ function evaluateRichPlaytestAssertions(input) {
|
|
|
1078
1216
|
assertions.push({ details: { reason: "registered-without-evaluator" }, id, pass: false });
|
|
1079
1217
|
diagnostics.push(assertionNotEvaluatedDiagnostic(id, "the registered assertion produced no evaluator result"));
|
|
1080
1218
|
}
|
|
1081
|
-
if (assertions.length === 0) {
|
|
1219
|
+
if (assertions.length === 0 || scenarioAssertions.diagnostics === void 0 && !assertions.some(({ id }) => id !== "diagnostics")) {
|
|
1082
1220
|
const id = "scenario.assertions";
|
|
1083
1221
|
assertions.push({ details: { reason: "no-evaluated-assertions" }, id, pass: false });
|
|
1084
1222
|
diagnostics.push({
|
|
@@ -1106,28 +1244,57 @@ function movementEnvelopeHorizontalLimit(envelope, rise) {
|
|
|
1106
1244
|
if (envelope.maxRise === 0) return rise === 0 ? envelope.forwardReach : void 0;
|
|
1107
1245
|
return envelope.forwardReach * (1 + Math.sqrt(dropFromApex / envelope.maxRise));
|
|
1108
1246
|
}
|
|
1109
|
-
function
|
|
1247
|
+
function physicsDebugContactEvidence(observations, entity, withEntity, selectedSnapshot) {
|
|
1110
1248
|
const snapshots = selectedSnapshot === void 0 ? [
|
|
1111
1249
|
observations?.physicsDebug,
|
|
1112
1250
|
...(observations?.physicsDebugSeries ?? []).map((sample) => sample.snapshot)
|
|
1113
1251
|
] : [selectedSnapshot];
|
|
1114
|
-
|
|
1252
|
+
const candidates = [];
|
|
1115
1253
|
for (const snapshot of snapshots) {
|
|
1116
1254
|
if (!isRecord(snapshot) || !isRecord(snapshot.artifact) || !Array.isArray(snapshot.artifact.primitives)) continue;
|
|
1117
|
-
|
|
1118
|
-
if (!isRecord(primitive) || primitive.category !== "contact" || typeof primitive.id !== "string")
|
|
1119
|
-
|
|
1120
|
-
|
|
1255
|
+
for (const primitive of snapshot.artifact.primitives) {
|
|
1256
|
+
if (!isRecord(primitive) || primitive.category !== "contact" || typeof primitive.id !== "string") continue;
|
|
1257
|
+
if (primitive.id.includes(entity ?? "") && (withEntity === void 0 || primitive.id.includes(withEntity))) {
|
|
1258
|
+
candidates.push(primitive.id);
|
|
1259
|
+
}
|
|
1260
|
+
}
|
|
1121
1261
|
}
|
|
1122
|
-
return count;
|
|
1262
|
+
return { candidates: [...new Set(candidates)], count: candidates.length };
|
|
1263
|
+
}
|
|
1264
|
+
function settledCandidate(snapshot, entity) {
|
|
1265
|
+
const bodies = physicsDebugSleepStates(snapshot, entity);
|
|
1266
|
+
if (entity !== void 0) {
|
|
1267
|
+
return bodies.length === 0 ? void 0 : { bodies, candidates: bodies.map(({ entity: body }) => body), selector: entity };
|
|
1268
|
+
}
|
|
1269
|
+
const groups = /* @__PURE__ */ new Map();
|
|
1270
|
+
for (const body of bodies) {
|
|
1271
|
+
const selector2 = bodySelector(body.entity);
|
|
1272
|
+
const group = groups.get(selector2) ?? [];
|
|
1273
|
+
group.push(body);
|
|
1274
|
+
groups.set(selector2, group);
|
|
1275
|
+
}
|
|
1276
|
+
const selected = [...groups.entries()].sort(([leftSelector, leftBodies], [rightSelector, rightBodies]) => rightBodies.length - leftBodies.length || leftSelector.localeCompare(rightSelector))[0];
|
|
1277
|
+
if (selected === void 0) return void 0;
|
|
1278
|
+
const [selector, selectedBodies] = selected;
|
|
1279
|
+
return { bodies: selectedBodies, candidates: selectedBodies.map(({ entity: body }) => body), selector };
|
|
1280
|
+
}
|
|
1281
|
+
function bodySelector(entity) {
|
|
1282
|
+
return /\d$/.test(entity) ? entity.replace(/\d+$/, "") : entity;
|
|
1123
1283
|
}
|
|
1124
1284
|
function physicsDebugSleepStates(snapshot, entity) {
|
|
1125
1285
|
if (!isRecord(snapshot) || !isRecord(snapshot.artifact) || !Array.isArray(snapshot.artifact.primitives)) return [];
|
|
1126
1286
|
return snapshot.artifact.primitives.flatMap((primitive) => {
|
|
1127
|
-
if (!isRecord(primitive) || primitive.category !== "sleep" || typeof primitive.entity !== "string" || primitive.entity !== entity && !primitive.entity.startsWith(entity) || typeof primitive.value !== "number") return [];
|
|
1287
|
+
if (!isRecord(primitive) || primitive.category !== "sleep" || typeof primitive.entity !== "string" || entity !== void 0 && primitive.entity !== entity && !primitive.entity.startsWith(entity) || typeof primitive.value !== "number") return [];
|
|
1128
1288
|
return [{ entity: primitive.entity, sleeping: primitive.value >= 1 }];
|
|
1129
1289
|
});
|
|
1130
1290
|
}
|
|
1291
|
+
function physicsDebugOmittedBodies(snapshot) {
|
|
1292
|
+
if (!isRecord(snapshot) || !isRecord(snapshot.artifact) || !isRecord(snapshot.artifact.overflow)) {
|
|
1293
|
+
return 0;
|
|
1294
|
+
}
|
|
1295
|
+
const omitted = snapshot.artifact.overflow.omittedBodies;
|
|
1296
|
+
return typeof omitted === "number" && Number.isInteger(omitted) && omitted >= 0 ? omitted : 1;
|
|
1297
|
+
}
|
|
1131
1298
|
function physicsDebugMeanPoseDistance(snapshot, comparisonSnapshot, entity) {
|
|
1132
1299
|
const positions = physicsDebugBodyPositions(snapshot, entity);
|
|
1133
1300
|
const comparison = physicsDebugBodyPositions(comparisonSnapshot, entity);
|
|
@@ -1184,22 +1351,85 @@ function evaluateTagCountAssertion(assertion, observations) {
|
|
|
1184
1351
|
}
|
|
1185
1352
|
};
|
|
1186
1353
|
}
|
|
1187
|
-
function evaluateStateAssertion(assertion, observations) {
|
|
1188
|
-
const gameplay = gameplayObservations(observations);
|
|
1354
|
+
function evaluateStateAssertion(assertion, observations, scenario, index) {
|
|
1355
|
+
const gameplay = gameplayObservations(runtimeObservationValue(observations));
|
|
1189
1356
|
const states = isRecord(gameplay?.states) ? gameplay.states : void 0;
|
|
1190
|
-
const
|
|
1191
|
-
const
|
|
1192
|
-
const
|
|
1357
|
+
const candidates = Object.entries(states ?? {}).filter((entry) => typeof entry[1] === "string");
|
|
1358
|
+
const matching = assertion.entity === void 0 ? candidates.filter(([, state]) => state === assertion.equals) : candidates.filter(([entity]) => entity === assertion.entity);
|
|
1359
|
+
const terminalStep = assertion.entity === void 0 ? terminalContactStep(scenario, assertion.equals) : void 0;
|
|
1360
|
+
const terminal = terminalStep === void 0 ? { contactObserved: true, historyComplete: true, preExisting: false, preExistingEntities: [], step: null } : terminalStateEvidence(terminalStep, observations, scenario, matching.map(([entity]) => entity));
|
|
1361
|
+
const selected = matching.find(([entity]) => !terminal.preExistingEntities.includes(entity)) ?? matching[0];
|
|
1362
|
+
const selectedEntity = selected?.[0] ?? assertion.entity;
|
|
1363
|
+
const observed = selected?.[1];
|
|
1364
|
+
const selectedPreExisting = selected === void 0 ? terminal.preExisting : terminal.preExistingEntities.includes(selected[0]);
|
|
1365
|
+
const pass = observed === assertion.equals && terminal.contactObserved && terminal.historyComplete && !selectedPreExisting;
|
|
1366
|
+
const result = {
|
|
1367
|
+
details: {
|
|
1368
|
+
candidates: candidates.map(([entity, state]) => ({ entity, state })),
|
|
1369
|
+
entity: selectedEntity ?? "anonymous",
|
|
1370
|
+
expected: assertion.equals,
|
|
1371
|
+
observed: observed ?? null,
|
|
1372
|
+
terminal: { contactObserved: terminal.contactObserved, historyComplete: terminal.historyComplete, preExisting: selectedPreExisting, step: terminal.step }
|
|
1373
|
+
},
|
|
1374
|
+
id: assertion.entity === void 0 ? `states.${index}` : `states.${assertion.entity}`,
|
|
1375
|
+
pass
|
|
1376
|
+
};
|
|
1193
1377
|
return pass ? { assertion: result } : {
|
|
1194
1378
|
assertion: result,
|
|
1195
1379
|
diagnostic: {
|
|
1196
|
-
code: "TN_PLAYTEST_STATE_ASSERTION_FAILED",
|
|
1197
|
-
message: `
|
|
1380
|
+
code: observed === assertion.equals && (!terminal.contactObserved || !terminal.historyComplete || selectedPreExisting) ? "TN_PLAYTEST_STATE_ORDERING_FAILED" : "TN_PLAYTEST_STATE_ASSERTION_FAILED",
|
|
1381
|
+
message: observed === assertion.equals && (!terminal.contactObserved || !terminal.historyComplete || selectedPreExisting) ? `Terminal state '${assertion.equals}' was not observed after retained contact evidence at '${terminal.step ?? "an unavailable step"}'.` : `Entity '${selectedEntity ?? "anonymous"}' state ${observed === void 0 ? "was unavailable" : `'${observed}'`} did not equal '${assertion.equals}'.`,
|
|
1198
1382
|
severity: "error",
|
|
1199
1383
|
suggestion: "Ensure the entity has a StateMachine component and inspect runtimeObservations.gameplay.states in the playtest artifact."
|
|
1200
1384
|
}
|
|
1201
1385
|
};
|
|
1202
1386
|
}
|
|
1387
|
+
function terminalContactStep(scenario, expectedState) {
|
|
1388
|
+
if (expectedState !== "won") return void 0;
|
|
1389
|
+
return [...scenario.assert?.contacts ?? []].reverse().find((assertion) => {
|
|
1390
|
+
const minimum = assertion.minCount ?? (assertion.maxCount === void 0 ? 1 : 0);
|
|
1391
|
+
return assertion.atStep !== void 0 && minimum > 0 && (assertion.requiredOn === void 0 || assertion.requiredOn.includes(scenario.target));
|
|
1392
|
+
})?.atStep;
|
|
1393
|
+
}
|
|
1394
|
+
function terminalStateEvidence(contactStep, observations, scenario, candidateEntities) {
|
|
1395
|
+
const contactAssertion = [...scenario.assert?.contacts ?? []].reverse().find((assertion) => assertion.atStep === contactStep);
|
|
1396
|
+
const contactObserved = contactAssertion === void 0 ? false : contactAssertionSatisfiedAtStep(contactAssertion, observations, scenario);
|
|
1397
|
+
const labeledSteps = scenario.steps.flatMap(({ label }) => label === void 0 ? [] : [label]);
|
|
1398
|
+
const contactIndex = labeledSteps.indexOf(contactStep);
|
|
1399
|
+
const samples = runtimeGameplaySeries(observations);
|
|
1400
|
+
const samplesByLabel = new Map(samples.map((sample) => [sample.label, sample.states]));
|
|
1401
|
+
const historyComplete = contactIndex >= 0 && labeledSteps.slice(0, contactIndex + 1).every((label) => samplesByLabel.has(label));
|
|
1402
|
+
const preExistingEntities = candidateEntities.filter((entity) => {
|
|
1403
|
+
if (contactIndex < 0) return false;
|
|
1404
|
+
return labeledSteps.slice(0, contactIndex).some((label) => samplesByLabel.get(label)?.[entity] === "won");
|
|
1405
|
+
});
|
|
1406
|
+
return {
|
|
1407
|
+
contactObserved,
|
|
1408
|
+
historyComplete,
|
|
1409
|
+
preExisting: preExistingEntities.length > 0,
|
|
1410
|
+
preExistingEntities,
|
|
1411
|
+
step: contactStep
|
|
1412
|
+
};
|
|
1413
|
+
}
|
|
1414
|
+
function contactAssertionSatisfiedAtStep(assertion, observations, scenario) {
|
|
1415
|
+
const selectedSample = physicsDebugSeries(observations).find((sample) => sample.label === assertion.atStep);
|
|
1416
|
+
const runtimeSamples = runtimeGameplaySeries(observations);
|
|
1417
|
+
const runtimeStepAvailable = runtimeSamples.some(({ label }) => label === assertion.atStep);
|
|
1418
|
+
const stepAvailable = selectedSample !== void 0 || runtimeStepAvailable;
|
|
1419
|
+
const entity = assertion.entity ?? scenario.subject;
|
|
1420
|
+
const anonymous = assertion.entity === void 0 && scenario.subject === void 0;
|
|
1421
|
+
const physicsEvidence = assertion.kind === void 0 || assertion.kind === "contact" ? physicsDebugContactEvidence(
|
|
1422
|
+
observationsForPhysics(observations),
|
|
1423
|
+
entity,
|
|
1424
|
+
assertion.with,
|
|
1425
|
+
selectedSample?.snapshot
|
|
1426
|
+
) : { candidates: [], count: 0 };
|
|
1427
|
+
const runtimeEvidence = runtimeContactEvidence(observations, entity, assertion.with, assertion.kind, assertion.atStep);
|
|
1428
|
+
const candidates = [.../* @__PURE__ */ new Set([...physicsEvidence.candidates, ...runtimeEvidence.candidates])];
|
|
1429
|
+
const count = physicsEvidence.count + runtimeEvidence.count;
|
|
1430
|
+
const minimum = assertion.minCount ?? (assertion.maxCount === void 0 ? 1 : 0);
|
|
1431
|
+
return stepAvailable && (!anonymous || candidates.length > 0) && count >= minimum && (assertion.maxCount === void 0 || count <= assertion.maxCount);
|
|
1432
|
+
}
|
|
1203
1433
|
function evaluateWorldAssertion(assertion, observations) {
|
|
1204
1434
|
const gameplay = gameplayObservations(observations);
|
|
1205
1435
|
const world = isRecord(gameplay?.world) ? gameplay.world : void 0;
|
|
@@ -1237,12 +1467,57 @@ function gameplayObservations(value) {
|
|
|
1237
1467
|
const gameplay = value.gameplay;
|
|
1238
1468
|
return isRecord(gameplay) ? gameplay : void 0;
|
|
1239
1469
|
}
|
|
1470
|
+
function runtimeObservationValue(value) {
|
|
1471
|
+
if (!isRecord(value) || !Object.hasOwn(value, "runtimeObservations")) return value;
|
|
1472
|
+
return value.runtimeObservations;
|
|
1473
|
+
}
|
|
1474
|
+
function runtimeGameplaySamples(value) {
|
|
1475
|
+
const runtime = runtimeObservationValue(value);
|
|
1476
|
+
if (!isRecord(runtime) || !Array.isArray(runtime.gameplaySeries)) return [];
|
|
1477
|
+
return runtime.gameplaySeries.flatMap((entry) => {
|
|
1478
|
+
if (!isRecord(entry) || typeof entry.label !== "string") return [];
|
|
1479
|
+
const direct = isRecord(entry.gameplay) ? entry.gameplay : void 0;
|
|
1480
|
+
const nested = isRecord(entry.snapshot) && isRecord(entry.snapshot.gameplay) ? entry.snapshot.gameplay : void 0;
|
|
1481
|
+
return direct === void 0 && nested === void 0 ? [] : [{ gameplay: direct ?? nested, label: entry.label }];
|
|
1482
|
+
});
|
|
1483
|
+
}
|
|
1484
|
+
function runtimeGameplaySeries(value) {
|
|
1485
|
+
return runtimeGameplaySamples(value).map(({ gameplay, label }) => ({
|
|
1486
|
+
label,
|
|
1487
|
+
states: isRecord(gameplay.states) ? Object.fromEntries(Object.entries(gameplay.states).filter((entry) => typeof entry[1] === "string")) : {}
|
|
1488
|
+
}));
|
|
1489
|
+
}
|
|
1490
|
+
function runtimeGameplayAtStep(value, atStep) {
|
|
1491
|
+
const runtime = runtimeObservationValue(value);
|
|
1492
|
+
if (atStep === void 0) return gameplayObservations(runtime);
|
|
1493
|
+
return runtimeGameplaySamples(runtime).find(({ label }) => label === atStep)?.gameplay;
|
|
1494
|
+
}
|
|
1495
|
+
function physicsDebugSeries(value) {
|
|
1496
|
+
if (!isRecord(value) || !Array.isArray(value.physicsDebugSeries)) return [];
|
|
1497
|
+
return value.physicsDebugSeries.flatMap((sample) => {
|
|
1498
|
+
if (!isRecord(sample) || typeof sample.label !== "string") return [];
|
|
1499
|
+
return [{ label: sample.label, snapshot: sample.snapshot }];
|
|
1500
|
+
});
|
|
1501
|
+
}
|
|
1502
|
+
function observationsForPhysics(value) {
|
|
1503
|
+
return isRecord(value) ? value : void 0;
|
|
1504
|
+
}
|
|
1505
|
+
function runtimeContactEvidence(observations, entity, withEntity, kind, atStep) {
|
|
1506
|
+
const gameplay = runtimeGameplayAtStep(observations, atStep);
|
|
1507
|
+
if (!Array.isArray(gameplay?.contacts)) return { candidates: [], count: 0 };
|
|
1508
|
+
const candidates = [];
|
|
1509
|
+
for (const contact of gameplay.contacts) {
|
|
1510
|
+
if (!isRecord(contact) || typeof contact.entity !== "string" || typeof contact.with !== "string" || typeof contact.kind !== "string" || entity !== void 0 && contact.entity !== entity || withEntity !== void 0 && contact.with !== withEntity || kind !== void 0 && contact.kind !== kind) continue;
|
|
1511
|
+
candidates.push(`${contact.entity}:${contact.with}:${contact.kind}`);
|
|
1512
|
+
}
|
|
1513
|
+
return { candidates: [...new Set(candidates)], count: candidates.length };
|
|
1514
|
+
}
|
|
1240
1515
|
function countRuntimeContacts(observations, entity, withEntity, kind) {
|
|
1241
1516
|
const gameplay = gameplayObservations(observations);
|
|
1242
1517
|
if (!Array.isArray(gameplay?.contacts)) return 0;
|
|
1243
1518
|
return gameplay.contacts.filter((contact) => {
|
|
1244
1519
|
if (!isRecord(contact)) return false;
|
|
1245
|
-
return contact.entity === entity && (withEntity === void 0 || contact.with === withEntity) && (kind === void 0 || contact.kind === kind);
|
|
1520
|
+
return (entity === void 0 || contact.entity === entity) && (withEntity === void 0 || contact.with === withEntity) && (kind === void 0 || contact.kind === kind);
|
|
1246
1521
|
}).length;
|
|
1247
1522
|
}
|
|
1248
1523
|
function runtimeAnimationObservations(value) {
|
|
@@ -1504,7 +1779,7 @@ function evaluateDiagnosticsPolicy(report, policy) {
|
|
|
1504
1779
|
});
|
|
1505
1780
|
}
|
|
1506
1781
|
const capturedConsoleErrors = consoleErrors(report.observations?.console ?? []);
|
|
1507
|
-
if (policy
|
|
1782
|
+
if (policy.noConsoleErrors && capturedConsoleErrors.length > 0) {
|
|
1508
1783
|
diagnostics.push({
|
|
1509
1784
|
code: "TN_PLAYTEST_CONSOLE_ERROR",
|
|
1510
1785
|
message: `${capturedConsoleErrors.length} browser console error(s) were captured during playtest.`,
|
|
@@ -1512,7 +1787,7 @@ function evaluateDiagnosticsPolicy(report, policy) {
|
|
|
1512
1787
|
suggestion: "Open console.json in the playtest artifact directory and fix the first runtime error."
|
|
1513
1788
|
});
|
|
1514
1789
|
}
|
|
1515
|
-
if (policy
|
|
1790
|
+
if (policy.noNetworkErrors && (report.observations?.network.length ?? 0) > 0) {
|
|
1516
1791
|
diagnostics.push({
|
|
1517
1792
|
code: "TN_PLAYTEST_NETWORK_ERROR",
|
|
1518
1793
|
message: `${report.observations?.network.length ?? 0} failed network request(s) were captured during playtest.`,
|
|
@@ -1521,7 +1796,7 @@ function evaluateDiagnosticsPolicy(report, policy) {
|
|
|
1521
1796
|
});
|
|
1522
1797
|
}
|
|
1523
1798
|
const runtimeErrors = runtimeDiagnostics(report.observations?.runtimeDiagnostics);
|
|
1524
|
-
if (policy
|
|
1799
|
+
if (policy.noRuntimeDiagnostics && runtimeErrors.length > 0) {
|
|
1525
1800
|
diagnostics.push({
|
|
1526
1801
|
code: "TN_PLAYTEST_RUNTIME_DIAGNOSTIC",
|
|
1527
1802
|
message: `${runtimeErrors.length} runtime diagnostic error(s) were captured during playtest.`,
|
|
@@ -1603,6 +1878,86 @@ function countMatchingEntries(effectLog, tokens) {
|
|
|
1603
1878
|
return tokens.every((token) => text.includes(token));
|
|
1604
1879
|
}).length;
|
|
1605
1880
|
}
|
|
1881
|
+
function evaluatePerformanceAssertion(assertion, series, sourcePath) {
|
|
1882
|
+
const samples = series ?? [];
|
|
1883
|
+
const validSamples = samples.length > 0 && samples.every(isRuntimeDiagnosticsSample);
|
|
1884
|
+
const observed = validSamples ? samples : [];
|
|
1885
|
+
const frameTimes = observed.map(({ frameMs }) => frameMs);
|
|
1886
|
+
const drawCalls = observed.flatMap(({ drawCalls: value }) => value === void 0 ? [] : [value]);
|
|
1887
|
+
const triangles = observed.flatMap(({ triangles: value }) => value === void 0 ? [] : [value]);
|
|
1888
|
+
const frameMsP95 = nearestRank(frameTimes, 0.95);
|
|
1889
|
+
const maxObservedDrawCalls = drawCalls.length === 0 ? void 0 : Math.max(...drawCalls);
|
|
1890
|
+
const maxObservedTriangles = triangles.length === 0 ? void 0 : Math.max(...triangles);
|
|
1891
|
+
const results = [];
|
|
1892
|
+
const diagnostics = [];
|
|
1893
|
+
const path = `${sourcePath ?? "playtest"}/observations.json/performanceSeries`;
|
|
1894
|
+
const samplesPass = validSamples;
|
|
1895
|
+
results.push({
|
|
1896
|
+
details: { sampleCount: samples.length, valid: validSamples },
|
|
1897
|
+
id: "performance.samples",
|
|
1898
|
+
pass: samplesPass
|
|
1899
|
+
});
|
|
1900
|
+
if (!samplesPass) {
|
|
1901
|
+
diagnostics.push({
|
|
1902
|
+
code: "TN_PLAYTEST_PERFORMANCE_SAMPLES_MISSING",
|
|
1903
|
+
message: samples.length === 0 ? "Performance assertion received no render samples." : "Performance assertion received an invalid render sample series.",
|
|
1904
|
+
observedRuntimePath: path,
|
|
1905
|
+
severity: "error",
|
|
1906
|
+
sourcePath,
|
|
1907
|
+
suggestion: "Run the scenario against the real render loop and keep the performance bridge provider installed."
|
|
1908
|
+
});
|
|
1909
|
+
}
|
|
1910
|
+
const addBound = (id, expected, actual, unit, pass) => {
|
|
1911
|
+
results.push({ details: { actual: actual ?? null, expected, sampleCount: samples.length, unit }, id, pass });
|
|
1912
|
+
if (!pass) diagnostics.push({
|
|
1913
|
+
code: "TN_PLAYTEST_PERFORMANCE_ASSERTION_FAILED",
|
|
1914
|
+
message: `${id} expected at most ${expected} ${unit}, observed ${actual ?? "unavailable"}.`,
|
|
1915
|
+
observedRuntimePath: path,
|
|
1916
|
+
severity: "error",
|
|
1917
|
+
sourcePath,
|
|
1918
|
+
suggestion: "Inspect the recorded frame-cost series and reduce the authored scene cost that owns the regression."
|
|
1919
|
+
});
|
|
1920
|
+
};
|
|
1921
|
+
if (assertion.maxFrameMsP95 !== void 0) {
|
|
1922
|
+
addBound(
|
|
1923
|
+
"performance.maxFrameMsP95",
|
|
1924
|
+
assertion.maxFrameMsP95,
|
|
1925
|
+
frameMsP95,
|
|
1926
|
+
"ms",
|
|
1927
|
+
samplesPass && frameMsP95 !== void 0 && frameMsP95 <= assertion.maxFrameMsP95
|
|
1928
|
+
);
|
|
1929
|
+
}
|
|
1930
|
+
if (assertion.maxDrawCalls !== void 0) {
|
|
1931
|
+
addBound(
|
|
1932
|
+
"performance.maxDrawCalls",
|
|
1933
|
+
assertion.maxDrawCalls,
|
|
1934
|
+
maxObservedDrawCalls,
|
|
1935
|
+
"draw calls",
|
|
1936
|
+
samplesPass && drawCalls.length === samples.length && maxObservedDrawCalls !== void 0 && maxObservedDrawCalls <= assertion.maxDrawCalls
|
|
1937
|
+
);
|
|
1938
|
+
}
|
|
1939
|
+
if (assertion.maxTriangles !== void 0) {
|
|
1940
|
+
addBound(
|
|
1941
|
+
"performance.maxTriangles",
|
|
1942
|
+
assertion.maxTriangles,
|
|
1943
|
+
maxObservedTriangles,
|
|
1944
|
+
"triangles",
|
|
1945
|
+
samplesPass && triangles.length === samples.length && maxObservedTriangles !== void 0 && maxObservedTriangles <= assertion.maxTriangles
|
|
1946
|
+
);
|
|
1947
|
+
}
|
|
1948
|
+
return { assertions: results, diagnostics };
|
|
1949
|
+
}
|
|
1950
|
+
function isRuntimeDiagnosticsSample(value) {
|
|
1951
|
+
if (!isRecord(value) || typeof value.frameMs !== "number" || !Number.isFinite(value.frameMs) || value.frameMs <= 0) {
|
|
1952
|
+
return false;
|
|
1953
|
+
}
|
|
1954
|
+
return (value.drawCalls === void 0 || typeof value.drawCalls === "number" && Number.isFinite(value.drawCalls) && value.drawCalls >= 0) && (value.triangles === void 0 || typeof value.triangles === "number" && Number.isFinite(value.triangles) && value.triangles >= 0);
|
|
1955
|
+
}
|
|
1956
|
+
function nearestRank(values, percentile) {
|
|
1957
|
+
if (values.length === 0) return void 0;
|
|
1958
|
+
const sorted = [...values].sort((left, right) => left - right);
|
|
1959
|
+
return sorted[Math.max(0, Math.ceil(values.length * percentile) - 1)];
|
|
1960
|
+
}
|
|
1606
1961
|
function mergeEffectLogs(effectLog, series) {
|
|
1607
1962
|
return {
|
|
1608
1963
|
entries: [effectLog, ...(series ?? []).map((sample) => sample.snapshot)].flatMap((log) => isRecord(log) && Array.isArray(log.entries) ? log.entries : [])
|
|
@@ -2089,6 +2444,7 @@ function validateStep(value, scenarioPath, index) {
|
|
|
2089
2444
|
"label",
|
|
2090
2445
|
"overlayMessage",
|
|
2091
2446
|
"pointerPosition",
|
|
2447
|
+
"pointers",
|
|
2092
2448
|
"press",
|
|
2093
2449
|
"release",
|
|
2094
2450
|
"screenshot",
|
|
@@ -2108,19 +2464,23 @@ function validateStep(value, scenarioPath, index) {
|
|
|
2108
2464
|
x: value.pointerPosition.x,
|
|
2109
2465
|
y: value.pointerPosition.y
|
|
2110
2466
|
} : void 0;
|
|
2467
|
+
const pointers = Array.isArray(value.pointers) ? value.pointers.map((pointer, pointerIndex) => validatePointer(pointer, scenarioPath, index, pointerIndex)) : void 0;
|
|
2111
2468
|
if (isRecord2(value.overlayMessage)) {
|
|
2112
2469
|
rejectUnknownKeys(value.overlayMessage, ["overlayId", "payload", "type"], scenarioPath, `steps[${index}].overlayMessage`);
|
|
2113
2470
|
}
|
|
2114
2471
|
if (isRecord2(value.pointerPosition)) {
|
|
2115
2472
|
rejectUnknownKeys(value.pointerPosition, ["buttons", "x", "y"], scenarioPath, `steps[${index}].pointerPosition`);
|
|
2116
2473
|
}
|
|
2474
|
+
if (pointers !== void 0 && new Set(pointers.map(({ id }) => id)).size !== pointers.length) {
|
|
2475
|
+
throw invalidStep(scenarioPath, `Scenario step ${index} pointers must use unique ids.`);
|
|
2476
|
+
}
|
|
2117
2477
|
const holdFrames = positiveInteger(value.holdFrames);
|
|
2118
2478
|
const holdTicks = positiveInteger(value.holdTicks);
|
|
2119
2479
|
const waitFrames2 = positiveInteger(value.waitFrames);
|
|
2120
2480
|
const waitTicks = positiveInteger(value.waitTicks);
|
|
2121
2481
|
const kind = value.kind === "wait" ? "wait" : value.kind === "input" ? "input" : void 0;
|
|
2122
2482
|
const screenshot = typeof value.screenshot === "string" && /^[A-Za-z0-9._-]+$/.test(value.screenshot) ? value.screenshot : void 0;
|
|
2123
|
-
const
|
|
2483
|
+
const window2 = isRecord2(value.window) && (value.window.operation === "minimize" || value.window.operation === "resize" || value.window.operation === "restore") && (value.window.operation !== "resize" || typeof value.window.width === "number" && Number.isFinite(value.window.width) && value.window.width >= 1 && typeof value.window.height === "number" && Number.isFinite(value.window.height) && value.window.height >= 1) ? {
|
|
2124
2484
|
operation: value.window.operation,
|
|
2125
2485
|
...typeof value.window.width === "number" ? { width: value.window.width } : {},
|
|
2126
2486
|
...typeof value.window.height === "number" ? { height: value.window.height } : {}
|
|
@@ -2141,17 +2501,20 @@ function validateStep(value, scenarioPath, index) {
|
|
|
2141
2501
|
if (value.pointerPosition !== void 0 && pointerPosition === void 0) {
|
|
2142
2502
|
throw invalidStep(scenarioPath, `Scenario step ${index} pointerPosition must define normalized x and y values from 0 through 1.`);
|
|
2143
2503
|
}
|
|
2504
|
+
if (value.pointers !== void 0 && pointers === void 0) {
|
|
2505
|
+
throw invalidStep(scenarioPath, `Scenario step ${index} pointers must be an array.`);
|
|
2506
|
+
}
|
|
2144
2507
|
if (value.screenshot !== void 0 && screenshot === void 0) {
|
|
2145
2508
|
throw invalidStep(scenarioPath, `Scenario step ${index} screenshot must be a stable file-safe name.`);
|
|
2146
2509
|
}
|
|
2147
2510
|
if (value.label !== void 0 && (typeof value.label !== "string" || value.label.trim() === "")) {
|
|
2148
2511
|
throw invalidStep(scenarioPath, `Scenario step ${index} label must be a non-empty string.`);
|
|
2149
2512
|
}
|
|
2150
|
-
if (value.window !== void 0 &&
|
|
2513
|
+
if (value.window !== void 0 && window2 === void 0) {
|
|
2151
2514
|
throw invalidStep(scenarioPath, `Scenario step ${index} window must define minimize, restore, or resize with positive width and height.`);
|
|
2152
2515
|
}
|
|
2153
|
-
if (press === void 0 && overlayMessage === void 0 && pointerPosition === void 0 &&
|
|
2154
|
-
throw invalidStep(scenarioPath, `Scenario step ${index} must define press, overlayMessage, pointerPosition, window, or waitFrames/waitTicks.`);
|
|
2516
|
+
if (press === void 0 && overlayMessage === void 0 && pointerPosition === void 0 && pointers === void 0 && window2 === void 0 && waitFrames2 === void 0 && waitTicks === void 0) {
|
|
2517
|
+
throw invalidStep(scenarioPath, `Scenario step ${index} must define press, overlayMessage, pointerPosition, pointers, window, or waitFrames/waitTicks.`);
|
|
2155
2518
|
}
|
|
2156
2519
|
if (value.holdFrames !== void 0 && holdFrames === void 0) {
|
|
2157
2520
|
throw invalidStep(scenarioPath, `Scenario step ${index} holdFrames must be a positive integer.`);
|
|
@@ -2181,12 +2544,33 @@ function validateStep(value, scenarioPath, index) {
|
|
|
2181
2544
|
...typeof value.label === "string" ? { label: value.label } : {},
|
|
2182
2545
|
...overlayMessage === void 0 ? {} : { overlayMessage },
|
|
2183
2546
|
...pointerPosition === void 0 ? {} : { pointerPosition },
|
|
2547
|
+
...pointers === void 0 ? {} : { pointers },
|
|
2184
2548
|
...press === void 0 ? {} : { press },
|
|
2185
2549
|
release: typeof value.release === "boolean" ? value.release : true,
|
|
2186
2550
|
...screenshot === void 0 ? {} : { screenshot },
|
|
2187
2551
|
...waitFrames2 === void 0 ? {} : { waitFrames: waitFrames2 },
|
|
2188
2552
|
...waitTicks === void 0 ? {} : { waitTicks },
|
|
2189
|
-
...
|
|
2553
|
+
...window2 === void 0 ? {} : { window: window2 }
|
|
2554
|
+
};
|
|
2555
|
+
}
|
|
2556
|
+
function validatePointer(value, scenarioPath, stepIndex, pointerIndex) {
|
|
2557
|
+
const path = `steps[${stepIndex}].pointers[${pointerIndex}]`;
|
|
2558
|
+
if (!isRecord2(value)) throw invalidStep(scenarioPath, `${path} must be an object.`);
|
|
2559
|
+
rejectUnknownKeys(value, ["buttons", "id", "x", "y"], scenarioPath, path);
|
|
2560
|
+
if (!Number.isInteger(value.id) || value.id < 1) {
|
|
2561
|
+
throw invalidStep(scenarioPath, `${path}.id must be a positive integer.`);
|
|
2562
|
+
}
|
|
2563
|
+
if (typeof value.x !== "number" || !Number.isFinite(value.x) || value.x < 0 || value.x > 1 || typeof value.y !== "number" || !Number.isFinite(value.y) || value.y < 0 || value.y > 1) {
|
|
2564
|
+
throw invalidStep(scenarioPath, `${path} must define normalized x and y values from 0 through 1.`);
|
|
2565
|
+
}
|
|
2566
|
+
if (value.buttons !== void 0 && (!Number.isInteger(value.buttons) || value.buttons < 1)) {
|
|
2567
|
+
throw invalidStep(scenarioPath, `${path}.buttons must be a positive integer when present.`);
|
|
2568
|
+
}
|
|
2569
|
+
return {
|
|
2570
|
+
...typeof value.buttons === "number" ? { buttons: value.buttons } : {},
|
|
2571
|
+
id: value.id,
|
|
2572
|
+
x: value.x,
|
|
2573
|
+
y: value.y
|
|
2190
2574
|
};
|
|
2191
2575
|
}
|
|
2192
2576
|
function validateStepLabels(steps, assertions, scenarioPath) {
|
|
@@ -2228,6 +2612,18 @@ function validateStepLabels(steps, assertions, scenarioPath) {
|
|
|
2228
2612
|
requireLabel(assertion.compareToStep, `assert.settled[${index}].compareToStep`);
|
|
2229
2613
|
}
|
|
2230
2614
|
requireLabel(assertions.movement?.reachesPositionWithin?.atStep, "assert.movement.reachesPositionWithin.atStep");
|
|
2615
|
+
requireLabel(assertions.framebufferCoverage?.window.startStep, "assert.framebufferCoverage.window.startStep");
|
|
2616
|
+
requireLabel(assertions.framebufferCoverage?.window.endStep, "assert.framebufferCoverage.window.endStep");
|
|
2617
|
+
if (assertions.framebufferCoverage !== void 0) {
|
|
2618
|
+
const startIndex = steps.findIndex(({ label }) => label === assertions.framebufferCoverage?.window.startStep);
|
|
2619
|
+
const endIndex = steps.findIndex(({ label }) => label === assertions.framebufferCoverage?.window.endStep);
|
|
2620
|
+
if (endIndex < startIndex) {
|
|
2621
|
+
throw invalidScenario(
|
|
2622
|
+
scenarioPath,
|
|
2623
|
+
"Assertion 'assert.framebufferCoverage.window.endStep' must not precede startStep."
|
|
2624
|
+
);
|
|
2625
|
+
}
|
|
2626
|
+
}
|
|
2231
2627
|
}
|
|
2232
2628
|
function playtestStepHoldTicks(step, fallback = 1) {
|
|
2233
2629
|
if (step.press === void 0 || step.holdFrames !== void 0 || step.waitFrames !== void 0) return 0;
|
|
@@ -2246,12 +2642,25 @@ function validateAssertions(value, scenarioPath) {
|
|
|
2246
2642
|
const movement = isRecord2(value.movement) ? value.movement : void 0;
|
|
2247
2643
|
const camera = isRecord2(value.camera) ? value.camera : void 0;
|
|
2248
2644
|
const diagnostics = isRecord2(value.diagnostics) ? value.diagnostics : void 0;
|
|
2645
|
+
const performance = isRecord2(value.performance) ? validatePerformanceAssertion(value.performance, scenarioPath, "assert.performance") : void 0;
|
|
2646
|
+
const framebufferCoverage = isRecord2(value.framebufferCoverage) ? validateFramebufferCoverageAssertion(
|
|
2647
|
+
value.framebufferCoverage,
|
|
2648
|
+
scenarioPath,
|
|
2649
|
+
"assert.framebufferCoverage"
|
|
2650
|
+
) : void 0;
|
|
2249
2651
|
const world = isRecord2(value.world) ? value.world : void 0;
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2652
|
+
const optOuts = [
|
|
2653
|
+
["noConsoleErrors", "consoleErrorsOptOutReason"],
|
|
2654
|
+
["noNetworkErrors", "networkErrorsOptOutReason"],
|
|
2655
|
+
["noRuntimeDiagnostics", "runtimeDiagnosticsOptOutReason"]
|
|
2656
|
+
];
|
|
2657
|
+
for (const [policyKey, reasonKey] of optOuts) {
|
|
2658
|
+
if (diagnostics?.[policyKey] === false && (typeof diagnostics[reasonKey] !== "string" || diagnostics[reasonKey].trim() === "")) {
|
|
2659
|
+
throw invalidScenario(
|
|
2660
|
+
scenarioPath,
|
|
2661
|
+
`Assertion 'assert.diagnostics.${policyKey}' may be false only when '${reasonKey}' explains the bounded exception.`
|
|
2662
|
+
);
|
|
2663
|
+
}
|
|
2255
2664
|
}
|
|
2256
2665
|
return {
|
|
2257
2666
|
...Array.isArray(value.aerodynamics) ? { aerodynamics: value.aerodynamics.map(validateAerodynamicsAssertion).filter((item) => item !== void 0) } : {},
|
|
@@ -2275,11 +2684,15 @@ function validateAssertions(value, scenarioPath) {
|
|
|
2275
2684
|
...typeof diagnostics.noConsoleErrors === "boolean" ? { noConsoleErrors: diagnostics.noConsoleErrors } : {},
|
|
2276
2685
|
...typeof diagnostics.noNetworkErrors === "boolean" ? { noNetworkErrors: diagnostics.noNetworkErrors } : {},
|
|
2277
2686
|
...typeof diagnostics.noRuntimeDiagnostics === "boolean" ? { noRuntimeDiagnostics: diagnostics.noRuntimeDiagnostics } : {},
|
|
2687
|
+
...typeof diagnostics.consoleErrorsOptOutReason === "string" ? { consoleErrorsOptOutReason: diagnostics.consoleErrorsOptOutReason } : {},
|
|
2688
|
+
...typeof diagnostics.networkErrorsOptOutReason === "string" ? { networkErrorsOptOutReason: diagnostics.networkErrorsOptOutReason } : {},
|
|
2278
2689
|
...typeof diagnostics.runtimeDiagnosticsOptOutReason === "string" ? { runtimeDiagnosticsOptOutReason: diagnostics.runtimeDiagnosticsOptOutReason } : {},
|
|
2279
2690
|
...typeof diagnostics.runtimeReady === "boolean" ? { runtimeReady: diagnostics.runtimeReady } : {}
|
|
2280
2691
|
}
|
|
2281
2692
|
},
|
|
2282
2693
|
...Array.isArray(value.hud) ? { hud: value.hud.map(validatePathAssertion).filter((item) => item !== void 0) } : {},
|
|
2694
|
+
...performance === void 0 ? {} : { performance },
|
|
2695
|
+
...framebufferCoverage === void 0 ? {} : { framebufferCoverage },
|
|
2283
2696
|
...movement === void 0 ? {} : {
|
|
2284
2697
|
movement: {
|
|
2285
2698
|
...typeof movement.axis === "string" ? { axis: movement.axis } : {},
|
|
@@ -2382,7 +2795,7 @@ function validateSettledAssertion(value, scenarioPath, objectPath) {
|
|
|
2382
2795
|
return {
|
|
2383
2796
|
...present("atStep", optionalString(record2, "atStep", scenarioPath, objectPath)),
|
|
2384
2797
|
...present("compareToStep", optionalString(record2, "compareToStep", scenarioPath, objectPath)),
|
|
2385
|
-
entity
|
|
2798
|
+
...present("entity", optionalString(record2, "entity", scenarioPath, objectPath)),
|
|
2386
2799
|
...present("minBodies", optionalPositiveInteger(record2, "minBodies", scenarioPath, objectPath)),
|
|
2387
2800
|
...present("minMeanPoseDistance", optionalPositiveNumber(record2, "minMeanPoseDistance", scenarioPath, objectPath)),
|
|
2388
2801
|
...present("requiredOn", optionalTargetArray(record2, "requiredOn", scenarioPath, objectPath))
|
|
@@ -2552,6 +2965,14 @@ function optionalNumber(value, key, scenarioPath, objectPath) {
|
|
|
2552
2965
|
}
|
|
2553
2966
|
return raw;
|
|
2554
2967
|
}
|
|
2968
|
+
function optionalNonNegativeNumber(value, key, scenarioPath, objectPath) {
|
|
2969
|
+
const raw = value[key];
|
|
2970
|
+
if (raw === void 0) return void 0;
|
|
2971
|
+
if (typeof raw !== "number" || !Number.isFinite(raw) || raw < 0) {
|
|
2972
|
+
throw invalidScenario(scenarioPath, `'${objectPath}.${key}' must be a finite non-negative number, received ${describeValue(raw)}.`);
|
|
2973
|
+
}
|
|
2974
|
+
return raw;
|
|
2975
|
+
}
|
|
2555
2976
|
function optionalNonNegativeInteger(value, key, scenarioPath, objectPath) {
|
|
2556
2977
|
const raw = value[key];
|
|
2557
2978
|
if (raw === void 0) return void 0;
|
|
@@ -2592,11 +3013,61 @@ function optionalTargetArray(value, key, scenarioPath, objectPath) {
|
|
|
2592
3013
|
function present(key, value) {
|
|
2593
3014
|
return value === void 0 ? {} : { [key]: value };
|
|
2594
3015
|
}
|
|
3016
|
+
function validatePerformanceAssertion(value, scenarioPath, objectPath) {
|
|
3017
|
+
const record2 = requireRecord(value, scenarioPath, objectPath);
|
|
3018
|
+
rejectUnknownKeys(record2, ["maxDrawCalls", "maxFrameMsP95", "maxTriangles"], scenarioPath, objectPath);
|
|
3019
|
+
return {
|
|
3020
|
+
...present("maxDrawCalls", optionalNonNegativeNumber(record2, "maxDrawCalls", scenarioPath, objectPath)),
|
|
3021
|
+
...present("maxFrameMsP95", optionalNonNegativeNumber(record2, "maxFrameMsP95", scenarioPath, objectPath)),
|
|
3022
|
+
...present("maxTriangles", optionalNonNegativeNumber(record2, "maxTriangles", scenarioPath, objectPath))
|
|
3023
|
+
};
|
|
3024
|
+
}
|
|
3025
|
+
function validateFramebufferCoverageAssertion(value, scenarioPath, objectPath) {
|
|
3026
|
+
const record2 = requireRecord(value, scenarioPath, objectPath);
|
|
3027
|
+
rejectUnknownKeys(record2, ["backdrop", "grid", "tolerance", "window"], scenarioPath, objectPath);
|
|
3028
|
+
const backdrop = requireArray(record2, "backdrop", scenarioPath, objectPath);
|
|
3029
|
+
if (backdrop.length !== 3 || backdrop.some((channel) => typeof channel !== "number" || !Number.isInteger(channel) || channel < 0 || channel > 255)) {
|
|
3030
|
+
throw invalidScenario(
|
|
3031
|
+
scenarioPath,
|
|
3032
|
+
`'${objectPath}.backdrop' must be three integer RGB channels from 0 to 255.`
|
|
3033
|
+
);
|
|
3034
|
+
}
|
|
3035
|
+
const tolerance = optionalNonNegativeInteger(record2, "tolerance", scenarioPath, objectPath);
|
|
3036
|
+
if (tolerance === void 0 || tolerance > 255) {
|
|
3037
|
+
throw invalidScenario(scenarioPath, `'${objectPath}.tolerance' must be an integer from 0 to 255.`);
|
|
3038
|
+
}
|
|
3039
|
+
const window2 = requireRecord(record2.window, scenarioPath, `${objectPath}.window`);
|
|
3040
|
+
rejectUnknownKeys(window2, ["endStep", "startStep"], scenarioPath, `${objectPath}.window`);
|
|
3041
|
+
const gridValue = record2.grid;
|
|
3042
|
+
let grid;
|
|
3043
|
+
if (gridValue !== void 0) {
|
|
3044
|
+
const gridRecord = requireRecord(gridValue, scenarioPath, `${objectPath}.grid`);
|
|
3045
|
+
rejectUnknownKeys(gridRecord, ["columns", "rows"], scenarioPath, `${objectPath}.grid`);
|
|
3046
|
+
const columns = optionalPositiveInteger(gridRecord, "columns", scenarioPath, `${objectPath}.grid`);
|
|
3047
|
+
const rows = optionalPositiveInteger(gridRecord, "rows", scenarioPath, `${objectPath}.grid`);
|
|
3048
|
+
if (columns === void 0 || rows === void 0 || columns > 256 || rows > 256) {
|
|
3049
|
+
throw invalidScenario(
|
|
3050
|
+
scenarioPath,
|
|
3051
|
+
`'${objectPath}.grid' columns and rows must be positive integers no greater than 256.`
|
|
3052
|
+
);
|
|
3053
|
+
}
|
|
3054
|
+
grid = { columns, rows };
|
|
3055
|
+
}
|
|
3056
|
+
return {
|
|
3057
|
+
backdrop,
|
|
3058
|
+
...grid === void 0 ? {} : { grid },
|
|
3059
|
+
tolerance,
|
|
3060
|
+
window: {
|
|
3061
|
+
endStep: requireString(window2, "endStep", scenarioPath, `${objectPath}.window`),
|
|
3062
|
+
startStep: requireString(window2, "startStep", scenarioPath, `${objectPath}.window`)
|
|
3063
|
+
}
|
|
3064
|
+
};
|
|
3065
|
+
}
|
|
2595
3066
|
function validateStateAssertion(value, scenarioPath, objectPath) {
|
|
2596
3067
|
const record2 = requireRecord(value, scenarioPath, objectPath);
|
|
2597
3068
|
rejectUnknownKeys(record2, ["entity", "equals"], scenarioPath, objectPath);
|
|
2598
3069
|
return {
|
|
2599
|
-
entity
|
|
3070
|
+
...present("entity", optionalString(record2, "entity", scenarioPath, objectPath)),
|
|
2600
3071
|
equals: requireString(record2, "equals", scenarioPath, objectPath)
|
|
2601
3072
|
};
|
|
2602
3073
|
}
|
|
@@ -2896,12 +3367,55 @@ var WEBGPU_BROWSER_ARGS = [
|
|
|
2896
3367
|
"--ozone-platform=x11",
|
|
2897
3368
|
"--enable-unsafe-webgpu",
|
|
2898
3369
|
"--disable-gpu-sandbox",
|
|
2899
|
-
"--ignore-gpu-blocklist"
|
|
3370
|
+
"--ignore-gpu-blocklist",
|
|
3371
|
+
// Without this Chromium never reaches the Vulkan driver on Linux and silently serves WebGPU
|
|
3372
|
+
// from SwiftShader, its CPU rasteriser. Nothing errors: the adapter answers, the run
|
|
3373
|
+
// proceeds, and the results are a software renderer's. Measured on an RTX 2080 under Xvfb,
|
|
3374
|
+
// `adapter.info` reads `swiftshader / google` without the flag and `turing / nvidia` with it,
|
|
3375
|
+
// which is the difference between blank captures and a rendered frame.
|
|
3376
|
+
"--enable-features=Vulkan"
|
|
2900
3377
|
];
|
|
3378
|
+
function resolveBrowserArguments(browserArgs) {
|
|
3379
|
+
return [...browserArgs ?? []];
|
|
3380
|
+
}
|
|
3381
|
+
var SOFTWARE_ADAPTER = /swiftshader|llvmpipe|lavapipe|softwarerasterizer|software adapter|basic render/i;
|
|
3382
|
+
function softwareAdapterName(adapter) {
|
|
3383
|
+
if (adapter === void 0) return void 0;
|
|
3384
|
+
for (const value of Object.values(adapter)) {
|
|
3385
|
+
if (typeof value === "string" && SOFTWARE_ADAPTER.test(value)) return value;
|
|
3386
|
+
}
|
|
3387
|
+
return void 0;
|
|
3388
|
+
}
|
|
3389
|
+
function reconcileBrowserPointers(previous, next) {
|
|
3390
|
+
const normalized = new Map(next.map((pointer) => [pointer.id, {
|
|
3391
|
+
buttons: pointer.buttons ?? 1,
|
|
3392
|
+
id: pointer.id,
|
|
3393
|
+
x: pointer.x,
|
|
3394
|
+
y: pointer.y
|
|
3395
|
+
}]));
|
|
3396
|
+
const previousPrimary = previous.keys().next().value;
|
|
3397
|
+
const nextPrimary = normalized.keys().next().value;
|
|
3398
|
+
const changes = [];
|
|
3399
|
+
for (const pointer of previous.values()) {
|
|
3400
|
+
if (!normalized.has(pointer.id)) {
|
|
3401
|
+
changes.push({ isPrimary: pointer.id === previousPrimary, pointer: { ...pointer, buttons: 0 }, type: "pointerup" });
|
|
3402
|
+
}
|
|
3403
|
+
}
|
|
3404
|
+
for (const pointer of normalized.values()) {
|
|
3405
|
+
const old = previous.get(pointer.id);
|
|
3406
|
+
if (old === void 0) {
|
|
3407
|
+
changes.push({ isPrimary: pointer.id === nextPrimary, pointer, type: "pointerdown" });
|
|
3408
|
+
} else if (old.x !== pointer.x || old.y !== pointer.y || old.buttons !== pointer.buttons) {
|
|
3409
|
+
changes.push({ isPrimary: pointer.id === nextPrimary, pointer, type: "pointermove" });
|
|
3410
|
+
}
|
|
3411
|
+
}
|
|
3412
|
+
return changes;
|
|
3413
|
+
}
|
|
2901
3414
|
|
|
2902
3415
|
// src/runner/config.ts
|
|
2903
3416
|
var PLAYTEST_FLAGS = {
|
|
2904
3417
|
"--adb": { default: "auto-discover", summary: "absolute adb executable path", takesValue: true },
|
|
3418
|
+
"--allow-software": { default: "false", summary: "accept a software WebGPU adapter as evidence", takesValue: false },
|
|
2905
3419
|
"--activity": { default: ".MystralActivity", summary: "Android launch activity", takesValue: true },
|
|
2906
3420
|
"--app": { default: "required for iOS", summary: "built iOS .app bundle", takesValue: true },
|
|
2907
3421
|
"--artifacts": { default: "artifacts/playtest", summary: "artifact output directory", takesValue: true },
|
|
@@ -2983,6 +3497,7 @@ function parseStandalonePlaytestArgs(argv, cwd = process.cwd()) {
|
|
|
2983
3497
|
const browserArgs = explicitBrowserArgs.length > 0 ? explicitBrowserArgs : browserRecipe === "webgpu" ? [...WEBGPU_BROWSER_ARGS] : [];
|
|
2984
3498
|
return {
|
|
2985
3499
|
...flags.get("--adb")?.[0] === void 0 ? {} : { adbPath: flags.get("--adb")[0] },
|
|
3500
|
+
allowSoftwareAdapter: argv.includes("--allow-software"),
|
|
2986
3501
|
android: {
|
|
2987
3502
|
activity: flags.get("--activity")?.[0] ?? ".MystralActivity",
|
|
2988
3503
|
packageName: flags.get("--package")?.[0] ?? "com.mystral.engine"
|
|
@@ -3103,10 +3618,11 @@ var PLAYTEST_CAPABILITY_REGISTRY = [
|
|
|
3103
3618
|
capability("runtime.audio", "Samples application-owned audio runtime state."),
|
|
3104
3619
|
capability("runtime.components", "Samples registered JSON-safe component state."),
|
|
3105
3620
|
capability("runtime.contacts", "Samples bounded collision and trigger contacts."),
|
|
3106
|
-
capability("runtime.diagnostics", "
|
|
3621
|
+
capability("runtime.diagnostics", "Captures application runtime errors."),
|
|
3107
3622
|
capability("runtime.events", "Drains bounded application event observations."),
|
|
3108
3623
|
capability("runtime.fixedStep", "Advances an application-owned deterministic tick."),
|
|
3109
3624
|
capability("runtime.physics", "Samples bounded application-owned physics observations."),
|
|
3625
|
+
capability("runtime.performance", "Samples bounded per-render frame cost and renderer counts."),
|
|
3110
3626
|
capability("runtime.resources", "Reads and writes registered JSON-safe application state."),
|
|
3111
3627
|
capability("runtime.state", "Samples application-owned state-machine state."),
|
|
3112
3628
|
capability("runtime.tags", "Samples bounded application-owned entity tags."),
|
|
@@ -3144,8 +3660,6 @@ function playtestDiagnostic(code, message, instruction, details = {}) {
|
|
|
3144
3660
|
var PLAYTEST_BRIDGE_GLOBAL = "__THREENATIVE_PLAYTEST_BRIDGE__";
|
|
3145
3661
|
var PLAYTEST_PROTOCOL_VERSION = 1;
|
|
3146
3662
|
var PLAYTEST_PROTOCOL_LIMITS = {
|
|
3147
|
-
maxEntitiesPerSample: 100,
|
|
3148
|
-
maxEventsPerDrain: 1e3,
|
|
3149
3663
|
maxPayloadBytes: 1e6,
|
|
3150
3664
|
operationTimeoutMs: 5e3
|
|
3151
3665
|
};
|
|
@@ -3175,13 +3689,19 @@ function assertJsonSafe(value, path = "$") {
|
|
|
3175
3689
|
throw new TypeError(`${path} must be JSON-safe.`);
|
|
3176
3690
|
}
|
|
3177
3691
|
var execFileAsync = promisify(execFile);
|
|
3178
|
-
var AdbAndroidDriver = class {
|
|
3692
|
+
var AdbAndroidDriver = class _AdbAndroidDriver {
|
|
3179
3693
|
constructor(options) {
|
|
3180
3694
|
this.options = options;
|
|
3181
3695
|
this.adbPath = options.adbPath ?? discoverAdb();
|
|
3182
3696
|
}
|
|
3183
3697
|
options;
|
|
3698
|
+
static COVERAGE_VIDEO_PATH = "/sdcard/tn-playtest-framebuffer-coverage.mp4";
|
|
3184
3699
|
adbPath;
|
|
3700
|
+
screenrecord;
|
|
3701
|
+
screenrecordError;
|
|
3702
|
+
touchSlots = /* @__PURE__ */ new Map();
|
|
3703
|
+
nextTrackingId = 100;
|
|
3704
|
+
rotation;
|
|
3185
3705
|
async prepare(endpoint, mailboxRoot) {
|
|
3186
3706
|
const url = new URL(endpoint);
|
|
3187
3707
|
const port = url.port;
|
|
@@ -3203,10 +3723,7 @@ var AdbAndroidDriver = class {
|
|
|
3203
3723
|
}
|
|
3204
3724
|
async captureConsole() {
|
|
3205
3725
|
const output = await this.adb(["logcat", "-d", "-v", "brief"]);
|
|
3206
|
-
return output
|
|
3207
|
-
text,
|
|
3208
|
-
type: /^(?:E|F)\//u.test(text) || /\b(?:Error|FATAL|FAILED)\b/u.test(text) ? "error" : "log"
|
|
3209
|
-
}));
|
|
3726
|
+
return parseAndroidConsole(output);
|
|
3210
3727
|
}
|
|
3211
3728
|
async screenshot(path) {
|
|
3212
3729
|
const { stdout } = await execFileAsync(this.adbPath, [
|
|
@@ -3217,9 +3734,116 @@ var AdbAndroidDriver = class {
|
|
|
3217
3734
|
], { encoding: "buffer", maxBuffer: 32 * 1024 * 1024 });
|
|
3218
3735
|
await writeFile(path, stdout);
|
|
3219
3736
|
}
|
|
3737
|
+
async startScreenRecording() {
|
|
3738
|
+
if (this.screenrecord !== void 0) {
|
|
3739
|
+
throw new Error("TN_PLAYTEST_FRAMEBUFFER_COVERAGE_RECORDING_ACTIVE");
|
|
3740
|
+
}
|
|
3741
|
+
if ((await this.adb(["shell", "pidof", "screenrecord"]).catch(() => "")).trim().length > 0) {
|
|
3742
|
+
throw new Error("TN_PLAYTEST_FRAMEBUFFER_COVERAGE_OTHER_RECORDING_ACTIVE");
|
|
3743
|
+
}
|
|
3744
|
+
try {
|
|
3745
|
+
await this.adb(["shell", "rm", "-f", _AdbAndroidDriver.COVERAGE_VIDEO_PATH]);
|
|
3746
|
+
this.screenrecordError = void 0;
|
|
3747
|
+
this.screenrecord = spawn(this.adbPath, [
|
|
3748
|
+
...this.serialArgs(),
|
|
3749
|
+
"shell",
|
|
3750
|
+
"screenrecord",
|
|
3751
|
+
"--time-limit",
|
|
3752
|
+
"180",
|
|
3753
|
+
"--bit-rate",
|
|
3754
|
+
"20000000",
|
|
3755
|
+
_AdbAndroidDriver.COVERAGE_VIDEO_PATH
|
|
3756
|
+
], { stdio: "ignore" });
|
|
3757
|
+
this.screenrecord.once("error", (error) => {
|
|
3758
|
+
this.screenrecordError = error;
|
|
3759
|
+
});
|
|
3760
|
+
await this.waitForScreenRecorder();
|
|
3761
|
+
} catch (error) {
|
|
3762
|
+
await this.abortScreenRecording();
|
|
3763
|
+
throw error;
|
|
3764
|
+
}
|
|
3765
|
+
}
|
|
3766
|
+
async stopScreenRecording(path) {
|
|
3767
|
+
const recorder = this.screenrecord;
|
|
3768
|
+
if (recorder === void 0) {
|
|
3769
|
+
throw new Error("TN_PLAYTEST_FRAMEBUFFER_COVERAGE_RECORDING_NOT_ACTIVE");
|
|
3770
|
+
}
|
|
3771
|
+
this.screenrecord = void 0;
|
|
3772
|
+
this.screenrecordError = void 0;
|
|
3773
|
+
try {
|
|
3774
|
+
const pids = (await this.adb(["shell", "pidof", "screenrecord"]).catch(() => "")).trim().split(/\s+/u).filter((pid) => /^\d+$/u.test(pid));
|
|
3775
|
+
for (const pid of pids) await this.adb(["shell", "kill", "-2", pid]);
|
|
3776
|
+
await waitForProcessExit(recorder, 5e3);
|
|
3777
|
+
await this.adb(["pull", _AdbAndroidDriver.COVERAGE_VIDEO_PATH, path]);
|
|
3778
|
+
if ((await stat(path)).size === 0) {
|
|
3779
|
+
throw new Error("TN_PLAYTEST_FRAMEBUFFER_COVERAGE_RECORDING_EMPTY");
|
|
3780
|
+
}
|
|
3781
|
+
} finally {
|
|
3782
|
+
recorder.kill();
|
|
3783
|
+
await this.adb(["shell", "rm", "-f", _AdbAndroidDriver.COVERAGE_VIDEO_PATH]).catch(() => void 0);
|
|
3784
|
+
}
|
|
3785
|
+
}
|
|
3220
3786
|
async isAlive() {
|
|
3221
3787
|
return (await this.adb(["shell", "pidof", this.options.packageName])).trim().length > 0;
|
|
3222
3788
|
}
|
|
3789
|
+
async setPointers(pointers) {
|
|
3790
|
+
const serial = (await this.adb(["get-serialno"])).trim();
|
|
3791
|
+
if (!serial.startsWith("emulator-")) {
|
|
3792
|
+
throw new Error("TN_PLAYTEST_ANDROID_MULTITOUCH_EMULATOR_REQUIRED: multi-pointer injection uses rootless adb emu event send.");
|
|
3793
|
+
}
|
|
3794
|
+
if (new Set(pointers.map(({ id }) => id)).size !== pointers.length) {
|
|
3795
|
+
throw new Error("Android complete held-pointer sets require unique pointer ids.");
|
|
3796
|
+
}
|
|
3797
|
+
if (pointers.some(({ buttons }) => buttons !== void 0 && buttons !== 1)) {
|
|
3798
|
+
throw new Error("Android touch injection supports buttons=1 only.");
|
|
3799
|
+
}
|
|
3800
|
+
this.rotation ??= await this.readRotation();
|
|
3801
|
+
const next = new Map(pointers.map((pointer) => [pointer.id, pointer]));
|
|
3802
|
+
const identity = [];
|
|
3803
|
+
const positions = [];
|
|
3804
|
+
const append = (batch, type, code, value) => {
|
|
3805
|
+
batch.push(`${type}:${code}:${value}`);
|
|
3806
|
+
};
|
|
3807
|
+
for (const [id, held] of [...this.touchSlots]) {
|
|
3808
|
+
if (next.has(id)) continue;
|
|
3809
|
+
append(identity, "EV_ABS", "ABS_MT_SLOT", held.slot);
|
|
3810
|
+
append(identity, "EV_ABS", "ABS_MT_TRACKING_ID", -1);
|
|
3811
|
+
this.touchSlots.delete(id);
|
|
3812
|
+
}
|
|
3813
|
+
for (const pointer of pointers) {
|
|
3814
|
+
const [x, y] = rotatedTouchPosition(pointer.x, pointer.y, this.rotation);
|
|
3815
|
+
let held = this.touchSlots.get(pointer.id);
|
|
3816
|
+
if (held === void 0) {
|
|
3817
|
+
const usedSlots = new Set([...this.touchSlots.values()].map(({ slot: slot2 }) => slot2));
|
|
3818
|
+
let slot = 0;
|
|
3819
|
+
while (usedSlots.has(slot)) slot += 1;
|
|
3820
|
+
held = { slot, trackingId: this.nextTrackingId++, x, y };
|
|
3821
|
+
this.touchSlots.set(pointer.id, held);
|
|
3822
|
+
append(identity, "EV_ABS", "ABS_MT_SLOT", slot);
|
|
3823
|
+
append(identity, "EV_ABS", "ABS_MT_TRACKING_ID", held.trackingId);
|
|
3824
|
+
append(positions, "EV_ABS", "ABS_MT_SLOT", slot);
|
|
3825
|
+
append(positions, "EV_ABS", "ABS_MT_POSITION_X", x);
|
|
3826
|
+
append(positions, "EV_ABS", "ABS_MT_POSITION_Y", y);
|
|
3827
|
+
append(positions, "EV_ABS", "ABS_MT_TOUCH_MAJOR", 1);
|
|
3828
|
+
append(positions, "EV_ABS", "ABS_MT_PRESSURE", 512);
|
|
3829
|
+
} else if (held.x !== x || held.y !== y) {
|
|
3830
|
+
append(positions, "EV_ABS", "ABS_MT_SLOT", held.slot);
|
|
3831
|
+
append(positions, "EV_ABS", "ABS_MT_POSITION_X", x);
|
|
3832
|
+
append(positions, "EV_ABS", "ABS_MT_POSITION_Y", y);
|
|
3833
|
+
held.x = x;
|
|
3834
|
+
held.y = y;
|
|
3835
|
+
}
|
|
3836
|
+
}
|
|
3837
|
+
for (const batch of androidTouchBatches(identity, positions)) {
|
|
3838
|
+
await this.adb(["emu", "event", "send", ...batch]);
|
|
3839
|
+
}
|
|
3840
|
+
return {
|
|
3841
|
+
activeIds: [...this.touchSlots.keys()],
|
|
3842
|
+
injection: "adb-emu-event-protocol-b",
|
|
3843
|
+
rotation: this.rotation,
|
|
3844
|
+
trackingIds: [...this.touchSlots.values()].map(({ trackingId }) => trackingId)
|
|
3845
|
+
};
|
|
3846
|
+
}
|
|
3223
3847
|
async readFile(path) {
|
|
3224
3848
|
try {
|
|
3225
3849
|
const contents = await this.adb(["exec-out", "cat", path]);
|
|
@@ -3233,9 +3857,19 @@ var AdbAndroidDriver = class {
|
|
|
3233
3857
|
await this.adb(["shell", "rm", "-f", path]);
|
|
3234
3858
|
}
|
|
3235
3859
|
async stop() {
|
|
3860
|
+
await this.abortScreenRecording();
|
|
3861
|
+
await this.setPointers([]).catch(() => void 0);
|
|
3236
3862
|
await this.adb(["shell", "am", "force-stop", this.options.packageName]).catch(() => void 0);
|
|
3237
3863
|
await this.adb(["reverse", "--remove-all"]).catch(() => void 0);
|
|
3238
3864
|
}
|
|
3865
|
+
async readRotation() {
|
|
3866
|
+
const input = await this.adb(["shell", "dumpsys", "input"]);
|
|
3867
|
+
const surface = /SurfaceOrientation:\s*([0-3])/u.exec(input)?.[1];
|
|
3868
|
+
if (surface !== void 0) return Number(surface);
|
|
3869
|
+
const setting = (await this.adb(["shell", "settings", "get", "system", "user_rotation"])).trim();
|
|
3870
|
+
if (/^[0-3]$/u.test(setting)) return Number(setting);
|
|
3871
|
+
throw new Error("TN_PLAYTEST_ANDROID_ROTATION_UNKNOWN: dumpsys input and user_rotation did not report 0 through 3.");
|
|
3872
|
+
}
|
|
3239
3873
|
async writeFile(path, contents) {
|
|
3240
3874
|
const directory = await mkdtemp(join(tmpdir(), "threenative-adb-mailbox-"));
|
|
3241
3875
|
const localPath = join(directory, "payload.json");
|
|
@@ -3256,6 +3890,9 @@ var AdbAndroidDriver = class {
|
|
|
3256
3890
|
[...this.serialArgs(), ...args],
|
|
3257
3891
|
{ encoding: "utf8", maxBuffer: 8 * 1024 * 1024 }
|
|
3258
3892
|
);
|
|
3893
|
+
if (/^KO:/mu.test(stdout)) {
|
|
3894
|
+
throw new Error(`adb ${args.join(" ")} failed: ${stdout.trim()}`);
|
|
3895
|
+
}
|
|
3259
3896
|
return stdout;
|
|
3260
3897
|
} catch (error) {
|
|
3261
3898
|
const detail = error;
|
|
@@ -3264,10 +3901,79 @@ var AdbAndroidDriver = class {
|
|
|
3264
3901
|
);
|
|
3265
3902
|
}
|
|
3266
3903
|
}
|
|
3904
|
+
async waitForScreenRecorder() {
|
|
3905
|
+
for (let attempt = 0; attempt < 100; attempt += 1) {
|
|
3906
|
+
if (this.screenrecordError !== void 0) {
|
|
3907
|
+
throw new Error(`TN_PLAYTEST_FRAMEBUFFER_COVERAGE_RECORDING_FAILED:${this.screenrecordError.message}`);
|
|
3908
|
+
}
|
|
3909
|
+
if (this.screenrecord?.exitCode !== null) {
|
|
3910
|
+
throw new Error("TN_PLAYTEST_FRAMEBUFFER_COVERAGE_RECORDING_EXITED");
|
|
3911
|
+
}
|
|
3912
|
+
const pid = await this.adb(["shell", "pidof", "screenrecord"]).catch(() => "");
|
|
3913
|
+
if (pid.trim().length > 0) return;
|
|
3914
|
+
await new Promise((resolve6) => setTimeout(resolve6, 20));
|
|
3915
|
+
}
|
|
3916
|
+
throw new Error("TN_PLAYTEST_FRAMEBUFFER_COVERAGE_RECORDING_NOT_READY");
|
|
3917
|
+
}
|
|
3918
|
+
async abortScreenRecording() {
|
|
3919
|
+
const recorder = this.screenrecord;
|
|
3920
|
+
this.screenrecord = void 0;
|
|
3921
|
+
this.screenrecordError = void 0;
|
|
3922
|
+
if (recorder !== void 0) {
|
|
3923
|
+
const pids = (await this.adb(["shell", "pidof", "screenrecord"]).catch(() => "")).trim().split(/\s+/u).filter((pid) => /^\d+$/u.test(pid));
|
|
3924
|
+
for (const pid of pids) await this.adb(["shell", "kill", "-2", pid]).catch(() => void 0);
|
|
3925
|
+
await waitForProcessExit(recorder, 5e3).catch(() => recorder.kill());
|
|
3926
|
+
await this.adb(["shell", "rm", "-f", _AdbAndroidDriver.COVERAGE_VIDEO_PATH]).catch(() => void 0);
|
|
3927
|
+
}
|
|
3928
|
+
}
|
|
3267
3929
|
serialArgs() {
|
|
3268
3930
|
return this.options.serial === void 0 ? [] : ["-s", this.options.serial];
|
|
3269
3931
|
}
|
|
3270
3932
|
};
|
|
3933
|
+
async function waitForProcessExit(child, timeoutMs) {
|
|
3934
|
+
if (child.exitCode !== null) return;
|
|
3935
|
+
await new Promise((resolve6, reject) => {
|
|
3936
|
+
const timeout = setTimeout(() => {
|
|
3937
|
+
cleanup();
|
|
3938
|
+
reject(new Error("TN_PLAYTEST_FRAMEBUFFER_COVERAGE_RECORDING_STOP_TIMEOUT"));
|
|
3939
|
+
}, timeoutMs);
|
|
3940
|
+
const onExit = () => {
|
|
3941
|
+
cleanup();
|
|
3942
|
+
resolve6();
|
|
3943
|
+
};
|
|
3944
|
+
const cleanup = () => {
|
|
3945
|
+
clearTimeout(timeout);
|
|
3946
|
+
child.off("exit", onExit);
|
|
3947
|
+
};
|
|
3948
|
+
child.once("exit", onExit);
|
|
3949
|
+
if (child.exitCode !== null) onExit();
|
|
3950
|
+
});
|
|
3951
|
+
}
|
|
3952
|
+
function parseAndroidConsole(output) {
|
|
3953
|
+
return output.split(/\r?\n/u).filter((line) => !/^[VDIWEF]\/SurfaceSyncGroup\(/u.test(line)).filter((line) => /Mystral|THREENATIVE|chromium/u.test(line)).map((text) => ({
|
|
3954
|
+
text,
|
|
3955
|
+
type: /^(?:E|F)\//u.test(text) || /\b(?:Error|FATAL|FAILED)\b/u.test(text) ? "error" : "log"
|
|
3956
|
+
}));
|
|
3957
|
+
}
|
|
3958
|
+
var TOUCH_AXIS_MAX = 32767;
|
|
3959
|
+
function androidTouchBatches(identity, positions) {
|
|
3960
|
+
const batches = [];
|
|
3961
|
+
for (const batch of [identity, positions]) {
|
|
3962
|
+
if (batch.length === 0) continue;
|
|
3963
|
+
if (batch.some((event) => event.includes("ABS_MT_TRACKING_ID")) && batch.some((event) => event.includes("ABS_MT_POSITION_"))) {
|
|
3964
|
+
throw new Error(
|
|
3965
|
+
"TN_PLAYTEST_ANDROID_TOUCH_BATCH_MIXED: a tracking id and a coordinate cannot share one emulator event batch; the emulator silently drops the coordinate."
|
|
3966
|
+
);
|
|
3967
|
+
}
|
|
3968
|
+
batches.push([...batch, "EV_SYN:0:0"]);
|
|
3969
|
+
}
|
|
3970
|
+
return batches;
|
|
3971
|
+
}
|
|
3972
|
+
function rotatedTouchPosition(x, y, rotation) {
|
|
3973
|
+
const normalized = rotation === 0 ? [x, y] : rotation === 1 ? [y, 1 - x] : rotation === 2 ? [1 - x, 1 - y] : rotation === 3 ? [1 - y, x] : void 0;
|
|
3974
|
+
if (normalized === void 0) throw new Error(`Android display rotation ${rotation} is invalid.`);
|
|
3975
|
+
return normalized.map((value) => Math.round(value * TOUCH_AXIS_MAX));
|
|
3976
|
+
}
|
|
3271
3977
|
function isMissingRemoteFile(error) {
|
|
3272
3978
|
const detail = error;
|
|
3273
3979
|
return isMissingRemoteFileOutput(`${detail.stderr ?? ""}
|
|
@@ -3298,8 +4004,11 @@ var STANDALONE_PLAYTEST_OBSERVATION_FIELDS = [
|
|
|
3298
4004
|
"components",
|
|
3299
4005
|
"componentSeries",
|
|
3300
4006
|
"console",
|
|
4007
|
+
"framebufferCoverage",
|
|
3301
4008
|
"hud",
|
|
3302
4009
|
"network",
|
|
4010
|
+
"physicsDebugSeries",
|
|
4011
|
+
"performanceSeries",
|
|
3303
4012
|
"resources",
|
|
3304
4013
|
"resourceSeries",
|
|
3305
4014
|
"runtimeDiagnostics",
|
|
@@ -3319,6 +4028,7 @@ var BROWSER_CAPABILITIES = [
|
|
|
3319
4028
|
"browser.network",
|
|
3320
4029
|
"browser.screenshot",
|
|
3321
4030
|
"browser.trace",
|
|
4031
|
+
"runtime.diagnostics",
|
|
3322
4032
|
"runtime.ui"
|
|
3323
4033
|
];
|
|
3324
4034
|
var PlaytestBridgeError = class extends Error {
|
|
@@ -3329,13 +4039,15 @@ var PlaytestBridgeError = class extends Error {
|
|
|
3329
4039
|
diagnostic;
|
|
3330
4040
|
};
|
|
3331
4041
|
var PlaywrightTransport = class {
|
|
3332
|
-
constructor(page) {
|
|
4042
|
+
constructor(page, operationTimeoutMs = PLAYTEST_PROTOCOL_LIMITS.operationTimeoutMs) {
|
|
3333
4043
|
this.page = page;
|
|
4044
|
+
this.operationTimeoutMs = operationTimeoutMs;
|
|
3334
4045
|
}
|
|
3335
4046
|
page;
|
|
4047
|
+
operationTimeoutMs;
|
|
3336
4048
|
capabilities = BROWSER_CAPABILITIES;
|
|
3337
4049
|
async call(method, argument) {
|
|
3338
|
-
return bridgeCall(this.page, method, argument);
|
|
4050
|
+
return bridgeCall(this.page, method, argument, this.operationTimeoutMs);
|
|
3339
4051
|
}
|
|
3340
4052
|
async close() {
|
|
3341
4053
|
}
|
|
@@ -3346,16 +4058,14 @@ var PlaywrightTransport = class {
|
|
|
3346
4058
|
}
|
|
3347
4059
|
};
|
|
3348
4060
|
async function connectPlaytestBridge(page, scenario, timeoutMs = PLAYTEST_PROTOCOL_LIMITS.operationTimeoutMs) {
|
|
3349
|
-
return connectPlaytestBridgeTransport(new PlaywrightTransport(page), scenario, timeoutMs);
|
|
4061
|
+
return connectPlaytestBridgeTransport(new PlaywrightTransport(page, timeoutMs), scenario, timeoutMs);
|
|
3350
4062
|
}
|
|
3351
4063
|
async function connectPlaytestBridgeTransport(transport, scenario, timeoutMs = PLAYTEST_PROTOCOL_LIMITS.operationTimeoutMs) {
|
|
3352
4064
|
const required = requiredPlaytestCapabilities(scenario);
|
|
3353
|
-
const
|
|
3354
|
-
(capability2) => !capability2.startsWith("browser.") && capability2 !== "runtime.ui" && (capability2 !== "runtime.diagnostics" || scenario.assert?.diagnostics?.noRuntimeDiagnostics === true)
|
|
3355
|
-
);
|
|
4065
|
+
const bridgeRequired = missingPlaytestCapabilities(required, transport.capabilities);
|
|
3356
4066
|
const exists = await transport.waitForBridge(timeoutMs);
|
|
3357
4067
|
if (!exists) {
|
|
3358
|
-
if (
|
|
4068
|
+
if (bridgeRequired.length === 0) {
|
|
3359
4069
|
return void 0;
|
|
3360
4070
|
}
|
|
3361
4071
|
throw new PlaytestBridgeError(playtestDiagnostic(
|
|
@@ -3487,7 +4197,7 @@ function assertBoundedPayload(value) {
|
|
|
3487
4197
|
));
|
|
3488
4198
|
}
|
|
3489
4199
|
}
|
|
3490
|
-
async function bridgeCall(page, method, argument) {
|
|
4200
|
+
async function bridgeCall(page, method, argument, timeoutMs = PLAYTEST_PROTOCOL_LIMITS.operationTimeoutMs) {
|
|
3491
4201
|
let timeout;
|
|
3492
4202
|
try {
|
|
3493
4203
|
return await Promise.race([
|
|
@@ -3505,9 +4215,9 @@ async function bridgeCall(page, method, argument) {
|
|
|
3505
4215
|
new Promise((_resolve, reject) => {
|
|
3506
4216
|
timeout = setTimeout(() => reject(new PlaytestBridgeError(playtestDiagnostic(
|
|
3507
4217
|
"TN_PLAYTEST_OPERATION_TIMEOUT",
|
|
3508
|
-
`Bridge operation '${method}' exceeded ${
|
|
4218
|
+
`Bridge operation '${method}' exceeded ${timeoutMs}ms.`,
|
|
3509
4219
|
"Bound the provider work or return a smaller observation payload."
|
|
3510
|
-
))),
|
|
4220
|
+
))), timeoutMs);
|
|
3511
4221
|
})
|
|
3512
4222
|
]);
|
|
3513
4223
|
} finally {
|
|
@@ -3517,7 +4227,8 @@ async function bridgeCall(page, method, argument) {
|
|
|
3517
4227
|
var ANDROID_TRANSPORT_CAPABILITIES = [
|
|
3518
4228
|
"browser.console",
|
|
3519
4229
|
"browser.input",
|
|
3520
|
-
"browser.screenshot"
|
|
4230
|
+
"browser.screenshot",
|
|
4231
|
+
"runtime.diagnostics"
|
|
3521
4232
|
];
|
|
3522
4233
|
var DeviceBridgeTransport = class {
|
|
3523
4234
|
capabilities = ANDROID_TRANSPORT_CAPABILITIES;
|
|
@@ -3760,46 +4471,302 @@ async function delayUntil(deadline) {
|
|
|
3760
4471
|
const remaining = deadline - Date.now();
|
|
3761
4472
|
if (remaining > 0) await new Promise((resolve6) => setTimeout(resolve6, Math.min(40, remaining)));
|
|
3762
4473
|
}
|
|
3763
|
-
var
|
|
3764
|
-
|
|
3765
|
-
|
|
3766
|
-
|
|
3767
|
-
|
|
3768
|
-
diagnostic;
|
|
4474
|
+
var CAPTURE_GUARD_LIMITS = {
|
|
4475
|
+
brightLuminance: 0.05,
|
|
4476
|
+
minBrightPixelRatio: 0.05,
|
|
4477
|
+
minDistinctColors: 8,
|
|
4478
|
+
minLuminanceStdDev: 0.01
|
|
3769
4479
|
};
|
|
3770
|
-
|
|
3771
|
-
|
|
3772
|
-
|
|
3773
|
-
|
|
3774
|
-
|
|
3775
|
-
|
|
3776
|
-
|
|
3777
|
-
|
|
3778
|
-
|
|
3779
|
-
|
|
3780
|
-
|
|
3781
|
-
|
|
3782
|
-
|
|
3783
|
-
|
|
3784
|
-
|
|
3785
|
-
|
|
3786
|
-
|
|
3787
|
-
|
|
3788
|
-
|
|
3789
|
-
|
|
3790
|
-
|
|
4480
|
+
var CaptureGuardError = class extends Error {
|
|
4481
|
+
constructor(label, reason, stats) {
|
|
4482
|
+
super(`TN_CAPTURE_BLANK: ${label}: ${reason}`);
|
|
4483
|
+
this.label = label;
|
|
4484
|
+
this.reason = reason;
|
|
4485
|
+
this.stats = stats;
|
|
4486
|
+
this.name = "CaptureGuardError";
|
|
4487
|
+
}
|
|
4488
|
+
label;
|
|
4489
|
+
reason;
|
|
4490
|
+
stats;
|
|
4491
|
+
code = "TN_CAPTURE_BLANK";
|
|
4492
|
+
};
|
|
4493
|
+
function inspectFrame(png) {
|
|
4494
|
+
const image = PNG.sync.read(png);
|
|
4495
|
+
const colors = /* @__PURE__ */ new Set();
|
|
4496
|
+
let luminanceTotal = 0;
|
|
4497
|
+
let luminanceSquaredTotal = 0;
|
|
4498
|
+
let brightPixels = 0;
|
|
4499
|
+
let visiblePixels = 0;
|
|
4500
|
+
for (let offset = 0; offset < image.data.length; offset += 4) {
|
|
4501
|
+
const red = image.data[offset] ?? 0;
|
|
4502
|
+
const green = image.data[offset + 1] ?? 0;
|
|
4503
|
+
const blue = image.data[offset + 2] ?? 0;
|
|
4504
|
+
const alpha = image.data[offset + 3] ?? 0;
|
|
4505
|
+
colors.add((red << 24 | green << 16 | blue << 8 | alpha) >>> 0);
|
|
4506
|
+
if (alpha === 0) continue;
|
|
4507
|
+
const luminance = (0.2126 * red + 0.7152 * green + 0.0722 * blue) / 255;
|
|
4508
|
+
visiblePixels += 1;
|
|
4509
|
+
if (luminance > CAPTURE_GUARD_LIMITS.brightLuminance) brightPixels += 1;
|
|
4510
|
+
luminanceTotal += luminance;
|
|
4511
|
+
luminanceSquaredTotal += luminance * luminance;
|
|
4512
|
+
}
|
|
4513
|
+
const mean = visiblePixels === 0 ? 0 : luminanceTotal / visiblePixels;
|
|
4514
|
+
const variance = visiblePixels === 0 ? 0 : luminanceSquaredTotal / visiblePixels - mean * mean;
|
|
4515
|
+
return {
|
|
4516
|
+
distinctColors: colors.size,
|
|
4517
|
+
brightPixelRatio: image.data.length === 0 ? 0 : brightPixels / (image.data.length / 4),
|
|
4518
|
+
height: image.height,
|
|
4519
|
+
luminanceStdDev: Math.sqrt(Math.max(0, variance)),
|
|
4520
|
+
width: image.width
|
|
3791
4521
|
};
|
|
3792
|
-
|
|
3793
|
-
|
|
3794
|
-
const
|
|
3795
|
-
if (
|
|
3796
|
-
|
|
3797
|
-
|
|
4522
|
+
}
|
|
4523
|
+
function assertCaptureNotBlank(png, label) {
|
|
4524
|
+
const stats = inspectFrame(png);
|
|
4525
|
+
if (stats.distinctColors < CAPTURE_GUARD_LIMITS.minDistinctColors) {
|
|
4526
|
+
throw new CaptureGuardError(
|
|
4527
|
+
label,
|
|
4528
|
+
`only ${stats.distinctColors} distinct color(s); capture is likely uniform or blank`,
|
|
4529
|
+
stats
|
|
4530
|
+
);
|
|
4531
|
+
}
|
|
4532
|
+
if (stats.luminanceStdDev < CAPTURE_GUARD_LIMITS.minLuminanceStdDev) {
|
|
4533
|
+
throw new CaptureGuardError(
|
|
4534
|
+
label,
|
|
4535
|
+
`luminance standard deviation ${stats.luminanceStdDev.toFixed(5)} is below ${CAPTURE_GUARD_LIMITS.minLuminanceStdDev}`,
|
|
4536
|
+
stats
|
|
4537
|
+
);
|
|
4538
|
+
}
|
|
4539
|
+
if (stats.brightPixelRatio < CAPTURE_GUARD_LIMITS.minBrightPixelRatio) {
|
|
4540
|
+
throw new CaptureGuardError(
|
|
4541
|
+
label,
|
|
4542
|
+
`bright pixel ratio ${stats.brightPixelRatio.toFixed(5)} is below ${CAPTURE_GUARD_LIMITS.minBrightPixelRatio}`,
|
|
4543
|
+
stats
|
|
4544
|
+
);
|
|
4545
|
+
}
|
|
4546
|
+
return stats;
|
|
4547
|
+
}
|
|
4548
|
+
var DEFAULT_COLUMNS = 32;
|
|
4549
|
+
var DEFAULT_ROWS = 18;
|
|
4550
|
+
var PROBE_KEY = "__THREENATIVE_FRAMEBUFFER_COVERAGE_PROBE__";
|
|
4551
|
+
async function startFramebufferCoverageProbe(page, assertion) {
|
|
4552
|
+
const columns = assertion.grid?.columns ?? DEFAULT_COLUMNS;
|
|
4553
|
+
const rows = assertion.grid?.rows ?? DEFAULT_ROWS;
|
|
4554
|
+
await page.evaluate(
|
|
4555
|
+
({ backdrop, columns: gridColumns, key, rows: gridRows, tolerance }) => {
|
|
4556
|
+
const host = globalThis;
|
|
4557
|
+
if (host[key] !== void 0) throw new Error("A framebuffer coverage probe is already active.");
|
|
4558
|
+
const canvases = [...document.querySelectorAll("canvas")];
|
|
4559
|
+
const source = canvases.sort(
|
|
4560
|
+
(left, right) => right.width * right.height - left.width * left.height
|
|
4561
|
+
)[0];
|
|
4562
|
+
const state = { active: true, frameCount: 0 };
|
|
4563
|
+
host[key] = state;
|
|
4564
|
+
if (source === void 0) {
|
|
4565
|
+
state.unreadableReason = "the page has no canvas framebuffer";
|
|
4566
|
+
return;
|
|
4567
|
+
}
|
|
4568
|
+
if (source.width <= 0 || source.height <= 0) {
|
|
4569
|
+
state.unreadableReason = `the canvas drawing buffer is ${source.width}x${source.height}`;
|
|
4570
|
+
return;
|
|
4571
|
+
}
|
|
4572
|
+
const sampleCanvas = document.createElement("canvas");
|
|
4573
|
+
sampleCanvas.width = gridColumns;
|
|
4574
|
+
sampleCanvas.height = gridRows;
|
|
4575
|
+
const sampleContext = sampleCanvas.getContext("2d", { willReadFrequently: true });
|
|
4576
|
+
if (sampleContext === null) {
|
|
4577
|
+
state.unreadableReason = "a 2D readback context could not be created";
|
|
4578
|
+
return;
|
|
4579
|
+
}
|
|
4580
|
+
const capture = () => {
|
|
4581
|
+
if (!state.active) return;
|
|
4582
|
+
try {
|
|
4583
|
+
sampleContext.clearRect(0, 0, gridColumns, gridRows);
|
|
4584
|
+
sampleContext.drawImage(source, 0, 0, gridColumns, gridRows);
|
|
4585
|
+
const image = sampleContext.getImageData(0, 0, gridColumns, gridRows);
|
|
4586
|
+
if (image.data.length !== gridColumns * gridRows * 4) {
|
|
4587
|
+
throw new Error(`readback returned ${image.data.length} bytes`);
|
|
4588
|
+
}
|
|
4589
|
+
const samples = [];
|
|
4590
|
+
let hasReadableAlpha = false;
|
|
4591
|
+
let violates = false;
|
|
4592
|
+
for (let offset = 0; offset < image.data.length; offset += 4) {
|
|
4593
|
+
const sample = [
|
|
4594
|
+
image.data[offset],
|
|
4595
|
+
image.data[offset + 1],
|
|
4596
|
+
image.data[offset + 2]
|
|
4597
|
+
];
|
|
4598
|
+
samples.push(sample);
|
|
4599
|
+
if (image.data[offset + 3] > 0) hasReadableAlpha = true;
|
|
4600
|
+
if (sample.some((channel, index) => Math.abs(channel - backdrop[index]) > tolerance)) {
|
|
4601
|
+
violates = true;
|
|
4602
|
+
}
|
|
4603
|
+
}
|
|
4604
|
+
if (!hasReadableAlpha) throw new Error("readback returned only transparent pixels");
|
|
4605
|
+
const frameIndex = state.frameCount;
|
|
4606
|
+
state.frameCount += 1;
|
|
4607
|
+
if (violates && state.firstViolation === void 0) {
|
|
4608
|
+
const fullCanvas = document.createElement("canvas");
|
|
4609
|
+
fullCanvas.width = source.width;
|
|
4610
|
+
fullCanvas.height = source.height;
|
|
4611
|
+
const fullContext = fullCanvas.getContext("2d");
|
|
4612
|
+
if (fullContext === null) throw new Error("a full-frame evidence context could not be created");
|
|
4613
|
+
fullContext.drawImage(source, 0, 0);
|
|
4614
|
+
state.firstViolation = {
|
|
4615
|
+
frameIndex,
|
|
4616
|
+
fullPngDataUrl: fullCanvas.toDataURL("image/png"),
|
|
4617
|
+
grid: { columns: gridColumns, rows: gridRows, samples }
|
|
4618
|
+
};
|
|
4619
|
+
}
|
|
4620
|
+
} catch (error) {
|
|
4621
|
+
state.unreadableReason = error instanceof Error ? error.message : String(error);
|
|
4622
|
+
state.active = false;
|
|
4623
|
+
return;
|
|
4624
|
+
}
|
|
4625
|
+
state.requestId = requestAnimationFrame(capture);
|
|
4626
|
+
};
|
|
4627
|
+
state.requestId = requestAnimationFrame(capture);
|
|
4628
|
+
},
|
|
4629
|
+
{ backdrop: assertion.backdrop, columns, key: PROBE_KEY, rows, tolerance: assertion.tolerance }
|
|
4630
|
+
);
|
|
4631
|
+
}
|
|
4632
|
+
async function finishFramebufferCoverageProbe(page, artifactDirectory) {
|
|
4633
|
+
const result = await page.evaluate((key) => {
|
|
4634
|
+
const host = globalThis;
|
|
4635
|
+
const state = host[key];
|
|
4636
|
+
if (state === void 0) return void 0;
|
|
4637
|
+
state.active = false;
|
|
4638
|
+
if (state.requestId !== void 0) cancelAnimationFrame(state.requestId);
|
|
4639
|
+
delete host[key];
|
|
4640
|
+
return {
|
|
4641
|
+
...state.firstViolation === void 0 ? {} : { firstViolation: state.firstViolation },
|
|
4642
|
+
frameCount: state.frameCount,
|
|
4643
|
+
...state.unreadableReason === void 0 ? {} : { unreadableReason: state.unreadableReason }
|
|
4644
|
+
};
|
|
4645
|
+
}, PROBE_KEY);
|
|
4646
|
+
if (result === void 0) {
|
|
4647
|
+
return {
|
|
4648
|
+
boundarySource: "scenario-steps",
|
|
4649
|
+
frameCount: 0,
|
|
4650
|
+
unreadableReason: "the declared coverage window never installed its framebuffer probe",
|
|
4651
|
+
windowCompleted: false,
|
|
4652
|
+
windowStarted: false
|
|
4653
|
+
};
|
|
4654
|
+
}
|
|
4655
|
+
let firstViolation;
|
|
4656
|
+
let unreadableReason = result.unreadableReason;
|
|
4657
|
+
if (result.firstViolation !== void 0) {
|
|
4658
|
+
const screenshotPath = join(
|
|
4659
|
+
artifactDirectory,
|
|
4660
|
+
`framebuffer-coverage-frame-${result.firstViolation.frameIndex}.png`
|
|
4661
|
+
);
|
|
4662
|
+
const encoded = result.firstViolation.fullPngDataUrl;
|
|
4663
|
+
if (encoded?.startsWith("data:image/png;base64,") === true) {
|
|
4664
|
+
await writeFile(screenshotPath, Buffer.from(encoded.slice("data:image/png;base64,".length), "base64"));
|
|
4665
|
+
} else {
|
|
4666
|
+
unreadableReason ??= "the violating frame could not be encoded as PNG evidence";
|
|
4667
|
+
}
|
|
4668
|
+
firstViolation = {
|
|
4669
|
+
frameIndex: result.firstViolation.frameIndex,
|
|
4670
|
+
grid: result.firstViolation.grid,
|
|
4671
|
+
screenshotPath: encoded?.startsWith("data:image/png;base64,") === true ? screenshotPath : ""
|
|
4672
|
+
};
|
|
4673
|
+
}
|
|
4674
|
+
return {
|
|
4675
|
+
boundarySource: "scenario-steps",
|
|
4676
|
+
...firstViolation === void 0 ? {} : { firstViolation },
|
|
4677
|
+
frameCount: result.frameCount,
|
|
4678
|
+
...unreadableReason === void 0 ? {} : { unreadableReason },
|
|
4679
|
+
windowCompleted: true,
|
|
4680
|
+
windowStarted: true
|
|
4681
|
+
};
|
|
4682
|
+
}
|
|
4683
|
+
|
|
4684
|
+
// src/runner/runner.ts
|
|
4685
|
+
var ManagedServerError = class extends Error {
|
|
4686
|
+
constructor(diagnostic2) {
|
|
4687
|
+
super(diagnostic2.message);
|
|
4688
|
+
this.diagnostic = diagnostic2;
|
|
4689
|
+
}
|
|
4690
|
+
diagnostic;
|
|
4691
|
+
};
|
|
4692
|
+
function failedDiagnosticsAssertion(policy) {
|
|
4693
|
+
return {
|
|
4694
|
+
details: {
|
|
4695
|
+
consoleErrors: 0,
|
|
4696
|
+
networkErrors: 0,
|
|
4697
|
+
policy,
|
|
4698
|
+
reason: "not-evaluated",
|
|
4699
|
+
runtimeDiagnostics: 0
|
|
4700
|
+
},
|
|
4701
|
+
id: "diagnostics",
|
|
4702
|
+
pass: false
|
|
4703
|
+
};
|
|
4704
|
+
}
|
|
4705
|
+
async function writeCaptureProvenance(artifactDirectory, provenance) {
|
|
4706
|
+
await writeFile(join(artifactDirectory, "capture.json"), `${JSON.stringify(provenance, null, 2)}
|
|
4707
|
+
`);
|
|
4708
|
+
}
|
|
4709
|
+
async function writeObservationArtifacts(artifactDirectory, requested, observations) {
|
|
4710
|
+
const runtimeErrors = observations.runtimeTrace?.recentRuntimeErrors ?? [];
|
|
4711
|
+
const files = [
|
|
4712
|
+
["console.json", observations.console, observations.console.length > 0 || requested?.console === true],
|
|
4713
|
+
["network.json", observations.network, observations.network.length > 0 || requested?.network === true],
|
|
4714
|
+
["runtime-trace.json", observations.runtimeTrace, runtimeErrors.length > 0 || requested?.runtimeTrace === true]
|
|
4715
|
+
];
|
|
4716
|
+
const written = [];
|
|
4717
|
+
for (const [name, content, wanted] of files) {
|
|
4718
|
+
if (!wanted || content === void 0) continue;
|
|
4719
|
+
await writeFile(join(artifactDirectory, name), `${JSON.stringify(content, null, 2)}
|
|
4720
|
+
`);
|
|
4721
|
+
written.push(name);
|
|
4722
|
+
}
|
|
4723
|
+
return written;
|
|
4724
|
+
}
|
|
4725
|
+
var UNHANDLED_REJECTION_PREFIX = "__THREENATIVE_PLAYTEST_UNHANDLED_REJECTION__:";
|
|
4726
|
+
async function runStandalonePlaytest(config) {
|
|
4727
|
+
const scenario = await loadPlaytestScenario(config.projectPath, config.scenarioPath);
|
|
4728
|
+
await mkdir(config.artifactDirectory, { recursive: true });
|
|
4729
|
+
let server;
|
|
4730
|
+
let browser;
|
|
4731
|
+
let page;
|
|
4732
|
+
let teardownPromise;
|
|
4733
|
+
const pageLifecycle = {
|
|
4734
|
+
closed: false,
|
|
4735
|
+
crashed: false,
|
|
4736
|
+
frameNavigations: [],
|
|
4737
|
+
navigations: [],
|
|
4738
|
+
settled: false,
|
|
4739
|
+
tail: []
|
|
4740
|
+
};
|
|
4741
|
+
const teardown = async () => {
|
|
4742
|
+
if (teardownPromise !== void 0) return teardownPromise;
|
|
4743
|
+
teardownPromise = (async () => {
|
|
4744
|
+
await boundedTeardownStep(page?.context().close(), 5e3);
|
|
4745
|
+
await boundedTeardownStep(browser?.close(), 1e4);
|
|
4746
|
+
await stopManagedServer(server);
|
|
4747
|
+
})();
|
|
4748
|
+
return teardownPromise;
|
|
4749
|
+
};
|
|
4750
|
+
const handleSignal = () => {
|
|
4751
|
+
void teardown().catch(() => void 0).finally(() => {
|
|
4752
|
+
process.exitCode = 2;
|
|
4753
|
+
process.exit(2);
|
|
4754
|
+
});
|
|
4755
|
+
};
|
|
4756
|
+
process.once("SIGINT", handleSignal);
|
|
4757
|
+
process.once("SIGTERM", handleSignal);
|
|
4758
|
+
const preflight = preflightDisplay(config, scenario);
|
|
4759
|
+
if (preflight !== void 0) {
|
|
4760
|
+
process.stderr.write(`${JSON.stringify({ diagnostics: [preflight] })}
|
|
4761
|
+
`);
|
|
3798
4762
|
}
|
|
3799
4763
|
try {
|
|
3800
|
-
|
|
4764
|
+
if (config.server !== void 0) {
|
|
4765
|
+
await assertManagedUrlAvailable(config.url);
|
|
4766
|
+
server = startManagedServer(config);
|
|
4767
|
+
}
|
|
3801
4768
|
browser = await chromium.launch({
|
|
3802
|
-
...config.browserArgs === void 0 ? {} : { args:
|
|
4769
|
+
...config.browserArgs === void 0 ? {} : { args: resolveBrowserArguments(config.browserArgs) },
|
|
3803
4770
|
headless: config.headless
|
|
3804
4771
|
});
|
|
3805
4772
|
if (server !== void 0) {
|
|
@@ -3810,13 +4777,43 @@ async function runStandalonePlaytest(config) {
|
|
|
3810
4777
|
await context.tracing.start({ screenshots: true, snapshots: true });
|
|
3811
4778
|
}
|
|
3812
4779
|
page = await context.newPage();
|
|
4780
|
+
await page.addInitScript(() => {
|
|
4781
|
+
globalThis.__THREENATIVE_PLAYTEST_RUNNER_EXPECTED__ = true;
|
|
4782
|
+
window.addEventListener("unhandledrejection", (event) => {
|
|
4783
|
+
const reason = event.reason instanceof Error ? event.reason.stack || event.reason.message : String(event.reason);
|
|
4784
|
+
console.error(`__THREENATIVE_PLAYTEST_UNHANDLED_REJECTION__:${reason}`);
|
|
4785
|
+
});
|
|
4786
|
+
});
|
|
3813
4787
|
const consoleEntries = [];
|
|
3814
4788
|
const networkEntries = [];
|
|
3815
|
-
page.on("console", (entry) =>
|
|
3816
|
-
|
|
4789
|
+
page.on("console", (entry) => {
|
|
4790
|
+
const text = entry.text();
|
|
4791
|
+
const unhandledRejection = text.startsWith(UNHANDLED_REJECTION_PREFIX);
|
|
4792
|
+
consoleEntries.push({
|
|
4793
|
+
source: unhandledRejection ? "unhandled-rejection" : "browser-console",
|
|
4794
|
+
text: unhandledRejection ? text.slice(UNHANDLED_REJECTION_PREFIX.length) : text,
|
|
4795
|
+
type: entry.type()
|
|
4796
|
+
});
|
|
4797
|
+
pageLifecycle.tail.push(`${entry.type()}: ${text}`);
|
|
4798
|
+
if (pageLifecycle.tail.length > 8) pageLifecycle.tail.shift();
|
|
4799
|
+
});
|
|
4800
|
+
page.on("pageerror", (error) => consoleEntries.push({ source: "page-error", text: error.stack || error.message, type: "pageerror" }));
|
|
3817
4801
|
page.on("requestfailed", (request) => networkEntries.push({ method: request.method(), url: request.url() }));
|
|
3818
|
-
|
|
3819
|
-
|
|
4802
|
+
const observedPage = page;
|
|
4803
|
+
page.on("crash", () => {
|
|
4804
|
+
pageLifecycle.crashed = true;
|
|
4805
|
+
});
|
|
4806
|
+
page.on("framenavigated", (frame) => {
|
|
4807
|
+
if (frame !== observedPage.mainFrame()) return;
|
|
4808
|
+
pageLifecycle.frameNavigations.push(frame.url());
|
|
4809
|
+
if (pageLifecycle.settled) pageLifecycle.navigations.push(frame.url());
|
|
4810
|
+
});
|
|
4811
|
+
page.on("close", () => {
|
|
4812
|
+
pageLifecycle.closed = true;
|
|
4813
|
+
});
|
|
4814
|
+
const activePage = page;
|
|
4815
|
+
const bridge = await openPageAndConnectBridge(page, config, scenario);
|
|
4816
|
+
pageLifecycle.settled = true;
|
|
3820
4817
|
if (bridge !== void 0 && scenario.setup !== void 0) {
|
|
3821
4818
|
await bridge.applySetup(setupRequest(scenario));
|
|
3822
4819
|
}
|
|
@@ -3826,18 +4823,90 @@ async function runStandalonePlaytest(config) {
|
|
|
3826
4823
|
).catch(() => false);
|
|
3827
4824
|
const entityIds = observedEntityIds(scenario);
|
|
3828
4825
|
const resourceIds = observedResourceIds(scenario);
|
|
3829
|
-
const sampleRequest = {
|
|
4826
|
+
const sampleRequest = {
|
|
4827
|
+
...entityIds === void 0 ? {} : { entities: entityIds },
|
|
4828
|
+
include: [
|
|
4829
|
+
"components",
|
|
4830
|
+
"diagnostics",
|
|
4831
|
+
"entities",
|
|
4832
|
+
"resources",
|
|
4833
|
+
...scenario.assert?.aerodynamics === void 0 && scenario.assert?.contacts === void 0 && scenario.assert?.settled === void 0 ? [] : ["physicsDebugSeries"],
|
|
4834
|
+
...scenario.assert?.performance === void 0 ? [] : ["runtimeDiagnosticsSeries"]
|
|
4835
|
+
],
|
|
4836
|
+
resources: resourceIds
|
|
4837
|
+
};
|
|
3830
4838
|
const labeledSamples = [];
|
|
4839
|
+
const capturesAnonymousMovement = isAnonymousMovementScenario(scenario);
|
|
4840
|
+
const movementSamples = [];
|
|
3831
4841
|
const wantsVisual = (scenario.assert?.visual?.length ?? 0) > 0;
|
|
4842
|
+
const needsCapture = scenario.artifacts?.screenshots !== false || scenario.steps.some((step) => step.screenshot !== void 0) || wantsVisual;
|
|
4843
|
+
const captureProvenance = needsCapture ? await readCaptureProvenance(page, config, scenario) : void 0;
|
|
4844
|
+
if (captureProvenance !== void 0) {
|
|
4845
|
+
await writeCaptureProvenance(config.artifactDirectory, captureProvenance);
|
|
4846
|
+
}
|
|
4847
|
+
let captureFailure;
|
|
4848
|
+
const capturePage = async (label, options) => {
|
|
4849
|
+
let png;
|
|
4850
|
+
try {
|
|
4851
|
+
png = await activePage.screenshot(options);
|
|
4852
|
+
} catch (error) {
|
|
4853
|
+
try {
|
|
4854
|
+
const fallback = await captureVisualSurface(
|
|
4855
|
+
activePage,
|
|
4856
|
+
typeof options?.path === "string" ? options.path : void 0
|
|
4857
|
+
);
|
|
4858
|
+
if (fallback === void 0) throw error;
|
|
4859
|
+
png = fallback;
|
|
4860
|
+
} catch {
|
|
4861
|
+
throw error;
|
|
4862
|
+
}
|
|
4863
|
+
}
|
|
4864
|
+
try {
|
|
4865
|
+
assertCaptureNotBlank(png, label);
|
|
4866
|
+
return png;
|
|
4867
|
+
} catch (error) {
|
|
4868
|
+
if (!(error instanceof CaptureGuardError)) throw error;
|
|
4869
|
+
captureFailure ??= { code: error.code, label: error.label, reason: error.reason };
|
|
4870
|
+
return void 0;
|
|
4871
|
+
}
|
|
4872
|
+
};
|
|
4873
|
+
const captureVisualPage = async (label, artifactPath) => {
|
|
4874
|
+
try {
|
|
4875
|
+
const png = await captureVisualSurface(activePage, artifactPath);
|
|
4876
|
+
if (png === void 0) {
|
|
4877
|
+
captureFailure ??= {
|
|
4878
|
+
code: "TN_CAPTURE_BLANK",
|
|
4879
|
+
label,
|
|
4880
|
+
reason: "no canvas was available for the visual capture"
|
|
4881
|
+
};
|
|
4882
|
+
return void 0;
|
|
4883
|
+
}
|
|
4884
|
+
assertCaptureNotBlank(png, label);
|
|
4885
|
+
return png;
|
|
4886
|
+
} catch (error) {
|
|
4887
|
+
if (!(error instanceof CaptureGuardError)) throw error;
|
|
4888
|
+
captureFailure ??= { code: error.code, label: error.label, reason: error.reason };
|
|
4889
|
+
return void 0;
|
|
4890
|
+
}
|
|
4891
|
+
};
|
|
3832
4892
|
const beforeSnapshot = await bridge?.sample(sampleRequest);
|
|
4893
|
+
let movementCursor = beforeSnapshot;
|
|
3833
4894
|
const pathEntity = scenario.assert?.movement?.pathLength === void 0 ? void 0 : scenario.assert.movement.entity ?? scenario.subject;
|
|
3834
4895
|
const pathPositions = beforeSnapshot === void 0 || pathEntity === void 0 ? [] : [entityPosition(beforeSnapshot, pathEntity)].filter((position) => position !== void 0);
|
|
3835
|
-
const inputState = { heldKeys: /* @__PURE__ */ new Set(), pointerButtons: 0 };
|
|
4896
|
+
const inputState = { heldKeys: /* @__PURE__ */ new Set(), pointerButtons: 0, pointers: /* @__PURE__ */ new Map() };
|
|
3836
4897
|
const hudAssertions = scenario.assert?.hud ?? [];
|
|
3837
4898
|
const beforeHud = await sampleHud(page, hudAssertions);
|
|
3838
|
-
const beforeScreenshot = scenario.artifacts?.screenshots === "before-after" || wantsVisual ?
|
|
4899
|
+
const beforeScreenshot = scenario.artifacts?.screenshots === "before-after" || wantsVisual ? wantsVisual ? await captureVisualPage(
|
|
4900
|
+
"before.png",
|
|
4901
|
+
scenario.artifacts?.screenshots === "before-after" ? join(config.artifactDirectory, "before.png") : void 0
|
|
4902
|
+
) : await capturePage("before.png", scenario.artifacts?.screenshots === "before-after" ? { path: join(config.artifactDirectory, "before.png") } : {}) : void 0;
|
|
4903
|
+
let framebufferCoverage;
|
|
3839
4904
|
for (const [index, step] of scenario.steps.entries()) {
|
|
3840
|
-
|
|
4905
|
+
const framebufferAssertion = scenario.assert?.framebufferCoverage;
|
|
4906
|
+
if (framebufferAssertion !== void 0 && step.label === framebufferAssertion.window.startStep) {
|
|
4907
|
+
await startFramebufferCoverageProbe(page, framebufferAssertion);
|
|
4908
|
+
}
|
|
4909
|
+
const stepSamples = await runStep(
|
|
3841
4910
|
page,
|
|
3842
4911
|
bridge,
|
|
3843
4912
|
step,
|
|
@@ -3845,15 +4914,32 @@ async function runStandalonePlaytest(config) {
|
|
|
3845
4914
|
pathEntity,
|
|
3846
4915
|
pathPositions,
|
|
3847
4916
|
inputState,
|
|
4917
|
+
capturesAnonymousMovement ? sampleRequest : void 0,
|
|
3848
4918
|
index === scenario.steps.length - 1
|
|
3849
4919
|
);
|
|
4920
|
+
if (capturesAnonymousMovement && movementCursor !== void 0 && stepSamples.afterInput !== void 0) {
|
|
4921
|
+
movementSamples.push({
|
|
4922
|
+
after: stepSamples.afterInput,
|
|
4923
|
+
before: movementCursor,
|
|
4924
|
+
inputDriven: stepSamples.inputDriven
|
|
4925
|
+
});
|
|
4926
|
+
}
|
|
4927
|
+
if (capturesAnonymousMovement && stepSamples.afterInput !== void 0 && stepSamples.afterStep !== void 0 && stepSamples.afterStep !== stepSamples.afterInput) {
|
|
4928
|
+
movementSamples.push({ after: stepSamples.afterStep, before: stepSamples.afterInput, inputDriven: false });
|
|
4929
|
+
}
|
|
4930
|
+
if (capturesAnonymousMovement && stepSamples.afterStep !== void 0) {
|
|
4931
|
+
movementCursor = stepSamples.afterStep;
|
|
4932
|
+
}
|
|
4933
|
+
if (step.label === scenario.assert?.framebufferCoverage?.window.endStep) {
|
|
4934
|
+
framebufferCoverage = await finishFramebufferCoverageProbe(page, config.artifactDirectory);
|
|
4935
|
+
}
|
|
3850
4936
|
if (step.label !== void 0 && bridge !== void 0) {
|
|
3851
|
-
const snapshot = await bridge.sample(sampleRequest);
|
|
4937
|
+
const snapshot = await bridge.sample({ ...sampleRequest, label: step.label });
|
|
3852
4938
|
const signals = bridge.description.capabilities.includes("runtime.events") ? await bridge.drainEvents() : [];
|
|
3853
4939
|
labeledSamples.push({ label: step.label, signals, snapshot });
|
|
3854
4940
|
}
|
|
3855
4941
|
if (step.screenshot !== void 0) {
|
|
3856
|
-
await
|
|
4942
|
+
await capturePage(`${safePart(step.screenshot)}.png`, { path: join(config.artifactDirectory, `${safePart(step.screenshot)}.png`) });
|
|
3857
4943
|
}
|
|
3858
4944
|
}
|
|
3859
4945
|
const afterSnapshot = await bridge?.sample(sampleRequest);
|
|
@@ -3862,8 +4948,11 @@ async function runStandalonePlaytest(config) {
|
|
|
3862
4948
|
if (position !== void 0) pathPositions.push(position);
|
|
3863
4949
|
}
|
|
3864
4950
|
const afterHud = await sampleHud(page, hudAssertions);
|
|
3865
|
-
const afterScreenshot = scenario.artifacts?.screenshots !== false || wantsVisual ?
|
|
3866
|
-
|
|
4951
|
+
const afterScreenshot = scenario.artifacts?.screenshots !== false || wantsVisual ? wantsVisual ? await captureVisualPage(
|
|
4952
|
+
"after.png",
|
|
4953
|
+
scenario.artifacts?.screenshots === false ? void 0 : join(config.artifactDirectory, "after.png")
|
|
4954
|
+
) : await capturePage("after.png", scenario.artifacts?.screenshots === false ? {} : { path: join(config.artifactDirectory, "after.png") }) : void 0;
|
|
4955
|
+
const visual = screenshotObservations(beforeScreenshot, afterScreenshot, scenario, captureFailure);
|
|
3867
4956
|
if (config.trace) {
|
|
3868
4957
|
await context.tracing.stop({ path: join(config.artifactDirectory, "trace.zip") });
|
|
3869
4958
|
}
|
|
@@ -3878,14 +4967,27 @@ async function runStandalonePlaytest(config) {
|
|
|
3878
4967
|
pairObservations(beforeHud, afterHud),
|
|
3879
4968
|
runtimeReady,
|
|
3880
4969
|
visual,
|
|
3881
|
-
labeledSamples
|
|
4970
|
+
labeledSamples,
|
|
4971
|
+
framebufferCoverage,
|
|
4972
|
+
captureProvenance,
|
|
4973
|
+
captureFailure,
|
|
4974
|
+
movementSamples
|
|
3882
4975
|
);
|
|
4976
|
+
await writeObservationArtifacts(config.artifactDirectory, scenario.artifacts, {
|
|
4977
|
+
console: consoleEntries,
|
|
4978
|
+
network: networkEntries,
|
|
4979
|
+
runtimeTrace: normalizedRuntimeDiagnostics(afterSnapshot, scenario, consoleEntries)
|
|
4980
|
+
});
|
|
3883
4981
|
await context.close();
|
|
3884
4982
|
return addPreflightDiagnostic(report, preflight);
|
|
3885
4983
|
} catch (error) {
|
|
3886
4984
|
if (error instanceof PlaytestBridgeError || error instanceof ManagedServerError) {
|
|
3887
4985
|
return addPreflightDiagnostic(failureReport(config, scenario, error.diagnostic), preflight);
|
|
3888
4986
|
}
|
|
4987
|
+
const lifecycleDiagnostic = pageLifecycleDiagnostic(error, pageLifecycle, config.url);
|
|
4988
|
+
if (lifecycleDiagnostic !== void 0) {
|
|
4989
|
+
return addPreflightDiagnostic(failureReport(config, scenario, lifecycleDiagnostic), preflight);
|
|
4990
|
+
}
|
|
3889
4991
|
throw error;
|
|
3890
4992
|
} finally {
|
|
3891
4993
|
process.off("SIGINT", handleSignal);
|
|
@@ -3896,28 +4998,33 @@ async function runStandalonePlaytest(config) {
|
|
|
3896
4998
|
function preflightDisplay(config, scenario, environment = process.env, platform = process.platform) {
|
|
3897
4999
|
const takesScreenshot = scenario.artifacts?.screenshots !== false || scenario.steps.some(({ screenshot }) => screenshot !== void 0);
|
|
3898
5000
|
const evaluatesVisual = (scenario.assert?.visual?.length ?? 0) > 0;
|
|
3899
|
-
|
|
5001
|
+
const evaluatesFramebuffer = scenario.assert?.framebufferCoverage !== void 0;
|
|
5002
|
+
if (platform !== "linux" || config.headless !== true || environment.DISPLAY || environment.WAYLAND_DISPLAY || !takesScreenshot && !evaluatesVisual && !evaluatesFramebuffer) {
|
|
3900
5003
|
return void 0;
|
|
3901
5004
|
}
|
|
3902
5005
|
return {
|
|
3903
|
-
code: "TN_PLAYTEST_HEADLESS_WEBGPU",
|
|
3904
|
-
message: "Headless Linux visual runs may render WebGPU blank without a display; use xvfb-run -a -s '-screen 0 1600x900x24'.",
|
|
3905
|
-
severity: "warning",
|
|
5006
|
+
code: evaluatesFramebuffer ? "TN_PLAYTEST_FRAMEBUFFER_PIXELS_UNREADABLE" : "TN_PLAYTEST_HEADLESS_WEBGPU",
|
|
5007
|
+
message: evaluatesFramebuffer ? "Headless Linux cannot provide trusted per-frame WebGPU pixels without a display; use xvfb-run -a -s '-screen 0 1600x900x24'." : "Headless Linux visual runs may render WebGPU blank without a display; use xvfb-run -a -s '-screen 0 1600x900x24'.",
|
|
5008
|
+
severity: evaluatesFramebuffer ? "error" : "warning",
|
|
3906
5009
|
suggestion: "Prefix the command with xvfb-run -a -s '-screen 0 1600x900x24'."
|
|
3907
5010
|
};
|
|
3908
5011
|
}
|
|
3909
5012
|
function addPreflightDiagnostic(report, diagnostic2) {
|
|
3910
5013
|
return diagnostic2 === void 0 ? report : { ...report, diagnostics: [diagnostic2, ...report.diagnostics] };
|
|
3911
5014
|
}
|
|
3912
|
-
function buildReport(config, scenario, beforeSnapshot, afterSnapshot, consoleEntries, networkEntries, pathLength = void 0, hud = {}, runtimeReady = true, visual = void 0, labeledSamples = []) {
|
|
3913
|
-
const
|
|
3914
|
-
const
|
|
3915
|
-
const
|
|
3916
|
-
const
|
|
3917
|
-
const
|
|
5015
|
+
function buildReport(config, scenario, beforeSnapshot, afterSnapshot, consoleEntries, networkEntries, pathLength = void 0, hud = {}, runtimeReady = true, visual = void 0, labeledSamples = [], framebufferCoverage = void 0, capture = void 0, captureFailure = void 0, movementSamples = []) {
|
|
5016
|
+
const movementSample = isAnonymousMovementScenario(scenario) ? observedMovementSample(movementSamples) : void 0;
|
|
5017
|
+
const entity = scenario.assert?.movement?.entity ?? scenario.subject ?? movementSample?.entity ?? "";
|
|
5018
|
+
const movementBeforeSnapshot = movementSample?.before ?? (isAnonymousMovementScenario(scenario) ? void 0 : beforeSnapshot);
|
|
5019
|
+
const movementAfterSnapshot = movementSample?.after ?? (isAnonymousMovementScenario(scenario) ? void 0 : afterSnapshot);
|
|
5020
|
+
const beforePosition = entityPosition(movementBeforeSnapshot, entity);
|
|
5021
|
+
const afterPosition = entityPosition(movementAfterSnapshot, entity);
|
|
5022
|
+
const beforeRotation = entityRotation(movementBeforeSnapshot, entity);
|
|
5023
|
+
const afterRotation = entityRotation(movementAfterSnapshot, entity);
|
|
3918
5024
|
const components = componentObservations(beforeSnapshot, afterSnapshot);
|
|
3919
5025
|
const movementDelta = beforePosition === void 0 || afterPosition === void 0 ? void 0 : subtract(afterPosition, beforePosition);
|
|
3920
5026
|
const distance = movementDelta === void 0 ? 0 : length(movementDelta);
|
|
5027
|
+
const performanceSeries = scenario.assert?.performance === void 0 ? void 0 : afterSnapshot?.runtimeDiagnosticsSeries ?? beforeSnapshot?.runtimeDiagnosticsSeries;
|
|
3921
5028
|
const diagnostics = [];
|
|
3922
5029
|
if (runtimeReady === false && scenario.assert?.diagnostics?.runtimeReady === true) {
|
|
3923
5030
|
diagnostics.push({
|
|
@@ -3931,6 +5038,7 @@ function buildReport(config, scenario, beforeSnapshot, afterSnapshot, consoleEnt
|
|
|
3931
5038
|
...afterPosition === void 0 ? {} : { after: { frame: scenario.steps.length, position: afterPosition, ...afterRotation === void 0 ? {} : { rotation: afterRotation }, tick: afterSnapshot?.clock.tick ?? 0 } },
|
|
3932
5039
|
...beforePosition === void 0 ? {} : { before: { frame: 0, position: beforePosition, ...beforeRotation === void 0 ? {} : { rotation: beforeRotation }, tick: beforeSnapshot?.clock.tick ?? 0 } },
|
|
3933
5040
|
diagnostics,
|
|
5041
|
+
diagnosticsPolicy: resolveDiagnosticsPolicy(scenario.assert?.diagnostics),
|
|
3934
5042
|
distance,
|
|
3935
5043
|
entity,
|
|
3936
5044
|
expectMoved: scenario.assert?.movement?.minDistance !== void 0,
|
|
@@ -3947,10 +5055,20 @@ function buildReport(config, scenario, beforeSnapshot, afterSnapshot, consoleEnt
|
|
|
3947
5055
|
signals: labeledSamples.flatMap(({ signals }) => signals)
|
|
3948
5056
|
},
|
|
3949
5057
|
hud,
|
|
5058
|
+
...framebufferCoverage === void 0 ? {} : { framebufferCoverage },
|
|
3950
5059
|
network: networkEntries,
|
|
5060
|
+
...performanceSeries === void 0 ? {} : { performanceSeries },
|
|
3951
5061
|
resources: resourceObservations(beforeSnapshot, afterSnapshot),
|
|
3952
|
-
...afterSnapshot?.gameplay === void 0
|
|
3953
|
-
|
|
5062
|
+
...afterSnapshot?.gameplay === void 0 && labeledSamples.every(({ snapshot }) => snapshot.gameplay === void 0) ? {} : {
|
|
5063
|
+
runtimeObservations: {
|
|
5064
|
+
...afterSnapshot?.gameplay === void 0 ? {} : { gameplay: afterSnapshot.gameplay },
|
|
5065
|
+
...labeledSamples.every(({ snapshot }) => snapshot.gameplay === void 0) ? {} : {
|
|
5066
|
+
gameplaySeries: labeledSamples.flatMap(({ label, snapshot }) => snapshot.gameplay === void 0 ? [] : [{ gameplay: snapshot.gameplay, label, tick: snapshot.clock.tick ?? 0 }])
|
|
5067
|
+
}
|
|
5068
|
+
}
|
|
5069
|
+
},
|
|
5070
|
+
...afterSnapshot?.physicsDebugSeries === void 0 ? {} : { physicsDebugSeries: afterSnapshot.physicsDebugSeries },
|
|
5071
|
+
runtimeDiagnostics: normalizedRuntimeDiagnostics(afterSnapshot, scenario, consoleEntries),
|
|
3954
5072
|
...visual === void 0 ? {} : { visual }
|
|
3955
5073
|
})
|
|
3956
5074
|
};
|
|
@@ -3961,6 +5079,23 @@ function buildReport(config, scenario, beforeSnapshot, afterSnapshot, consoleEnt
|
|
|
3961
5079
|
const cameraResult = evaluateCamera(scenario, afterSnapshot);
|
|
3962
5080
|
const assertionResults = [...evaluated.assertions, ...cameraResult === void 0 ? [] : [cameraResult]];
|
|
3963
5081
|
const allDiagnostics = [...diagnostics, ...evaluated.diagnostics];
|
|
5082
|
+
const softwareAdapter = capture?.rendererKind === "webgpu" ? softwareAdapterName(capture.adapter) : void 0;
|
|
5083
|
+
if (softwareAdapter !== void 0 && config.allowSoftwareAdapter !== true) {
|
|
5084
|
+
allDiagnostics.push({
|
|
5085
|
+
code: "TN_PLAYTEST_SOFTWARE_ADAPTER",
|
|
5086
|
+
message: `WebGPU was served by a software adapter: '${softwareAdapter}'. Nothing errored, so every result in this run is a CPU rasteriser's.`,
|
|
5087
|
+
severity: "error",
|
|
5088
|
+
suggestion: "Run with --headed under a display and --browser-recipe webgpu so Chromium reaches the GPU driver, or pass --allow-software to accept the fallback deliberately."
|
|
5089
|
+
});
|
|
5090
|
+
}
|
|
5091
|
+
if (captureFailure !== void 0) {
|
|
5092
|
+
allDiagnostics.push({
|
|
5093
|
+
code: captureFailure.code,
|
|
5094
|
+
message: `Visual capture '${captureFailure.label}' was blank: ${captureFailure.reason}.`,
|
|
5095
|
+
severity: "error",
|
|
5096
|
+
suggestion: "Inspect the browser display and GPU adapter before treating this run as render evidence."
|
|
5097
|
+
});
|
|
5098
|
+
}
|
|
3964
5099
|
if (cameraResult?.pass === false) {
|
|
3965
5100
|
allDiagnostics.push({
|
|
3966
5101
|
code: "TN_PLAYTEST_CAMERA_ASSERTION_FAILED",
|
|
@@ -3972,6 +5107,7 @@ function buildReport(config, scenario, beforeSnapshot, afterSnapshot, consoleEnt
|
|
|
3972
5107
|
return {
|
|
3973
5108
|
...base,
|
|
3974
5109
|
artifactDirectory: config.artifactDirectory,
|
|
5110
|
+
...capture === void 0 ? {} : { capture },
|
|
3975
5111
|
assertionResults,
|
|
3976
5112
|
diagnostics: allDiagnostics,
|
|
3977
5113
|
pass: assertionResults.every(({ pass }) => pass) && allDiagnostics.every(({ severity }) => severity !== "error"),
|
|
@@ -3981,6 +5117,25 @@ function buildReport(config, scenario, beforeSnapshot, afterSnapshot, consoleEnt
|
|
|
3981
5117
|
url: config.url
|
|
3982
5118
|
};
|
|
3983
5119
|
}
|
|
5120
|
+
async function captureVisualSurface(page, artifactPath) {
|
|
5121
|
+
const canvases = page.locator("canvas");
|
|
5122
|
+
const sourceIndex = await canvases.evaluateAll((elements) => {
|
|
5123
|
+
let largestArea = 0;
|
|
5124
|
+
let largestIndex = -1;
|
|
5125
|
+
for (const [index, canvas] of elements.entries()) {
|
|
5126
|
+
const area = canvas.width * canvas.height;
|
|
5127
|
+
if (area > largestArea) {
|
|
5128
|
+
largestArea = area;
|
|
5129
|
+
largestIndex = index;
|
|
5130
|
+
}
|
|
5131
|
+
}
|
|
5132
|
+
return largestIndex;
|
|
5133
|
+
});
|
|
5134
|
+
if (sourceIndex < 0) return void 0;
|
|
5135
|
+
const content = await canvases.nth(sourceIndex).screenshot();
|
|
5136
|
+
if (artifactPath !== void 0) await writeFile(artifactPath, content);
|
|
5137
|
+
return content;
|
|
5138
|
+
}
|
|
3984
5139
|
function buildObservations(candidate) {
|
|
3985
5140
|
const observations = {};
|
|
3986
5141
|
for (const field of STANDALONE_PLAYTEST_OBSERVATION_FIELDS) {
|
|
@@ -4002,8 +5157,8 @@ function componentObservations(before, after) {
|
|
|
4002
5157
|
}]))];
|
|
4003
5158
|
}));
|
|
4004
5159
|
}
|
|
4005
|
-
function screenshotObservations(before, after, scenario) {
|
|
4006
|
-
if (after === void 0) return void 0;
|
|
5160
|
+
function screenshotObservations(before, after, scenario, captureFailure = void 0) {
|
|
5161
|
+
if (after === void 0) return captureFailure === void 0 ? void 0 : { captureFailure };
|
|
4007
5162
|
const afterPng = PNG.sync.read(after);
|
|
4008
5163
|
const beforePng = before === void 0 ? void 0 : PNG.sync.read(before);
|
|
4009
5164
|
const sameSize = beforePng !== void 0 && beforePng.width === afterPng.width && beforePng.height === afterPng.height;
|
|
@@ -4025,7 +5180,8 @@ function screenshotObservations(before, after, scenario) {
|
|
|
4025
5180
|
return {
|
|
4026
5181
|
...changedPixelRatio === void 0 ? {} : { changedPixelRatio },
|
|
4027
5182
|
...sameSize ? { comparisonSource: "before-after" } : {},
|
|
4028
|
-
...regions.length === 0 ? {} : { nonblankRegions: regions }
|
|
5183
|
+
...regions.length === 0 ? {} : { nonblankRegions: regions },
|
|
5184
|
+
...captureFailure === void 0 ? {} : { captureFailure }
|
|
4029
5185
|
};
|
|
4030
5186
|
}
|
|
4031
5187
|
function regionMetrics(png, region) {
|
|
@@ -4049,10 +5205,13 @@ function regionMetrics(png, region) {
|
|
|
4049
5205
|
return { darkPixelRatio: dark / pixels, nonblankPixelRatio: nonblank / pixels };
|
|
4050
5206
|
}
|
|
4051
5207
|
function failureReport(config, scenario, diagnostic2) {
|
|
5208
|
+
const diagnosticsPolicy = resolveDiagnosticsPolicy(scenario.assert?.diagnostics);
|
|
4052
5209
|
return {
|
|
4053
5210
|
artifactDirectory: config.artifactDirectory,
|
|
5211
|
+
assertionResults: [failedDiagnosticsAssertion(diagnosticsPolicy)],
|
|
4054
5212
|
debugColliders: false,
|
|
4055
5213
|
diagnostics: [{ ...diagnostic2, suggestion: diagnostic2.fix.instruction }],
|
|
5214
|
+
diagnosticsPolicy,
|
|
4056
5215
|
distance: 0,
|
|
4057
5216
|
entity: scenario.subject ?? "",
|
|
4058
5217
|
expectMoved: false,
|
|
@@ -4087,7 +5246,7 @@ function setupRequest(scenario) {
|
|
|
4087
5246
|
}
|
|
4088
5247
|
};
|
|
4089
5248
|
}
|
|
4090
|
-
async function runStep(page, bridge, step, viewport, pathEntity, pathPositions, inputState, finalStep) {
|
|
5249
|
+
async function runStep(page, bridge, step, viewport, pathEntity, pathPositions, inputState, movementSampleRequest, finalStep) {
|
|
4091
5250
|
if (step.pointerPosition !== void 0) {
|
|
4092
5251
|
await page.mouse.move(
|
|
4093
5252
|
step.pointerPosition.x * viewport.width,
|
|
@@ -4097,6 +5256,9 @@ async function runStep(page, bridge, step, viewport, pathEntity, pathPositions,
|
|
|
4097
5256
|
await setPointerButtons(page, inputState, step.pointerPosition.buttons);
|
|
4098
5257
|
}
|
|
4099
5258
|
}
|
|
5259
|
+
if (step.pointers !== void 0) {
|
|
5260
|
+
await setBrowserPointers(page, inputState, step.pointers, viewport);
|
|
5261
|
+
}
|
|
4100
5262
|
const press = step.press;
|
|
4101
5263
|
if (typeof press === "string") {
|
|
4102
5264
|
await page.keyboard.down(press);
|
|
@@ -4115,28 +5277,97 @@ async function runStep(page, bridge, step, viewport, pathEntity, pathPositions,
|
|
|
4115
5277
|
}
|
|
4116
5278
|
}
|
|
4117
5279
|
}
|
|
5280
|
+
const inputDriven = playtestStepDrivesMovement(step, inputActive(inputState));
|
|
4118
5281
|
const ticks = playtestStepHoldTicks(step, 0) + playtestStepWaitTicks(step);
|
|
4119
5282
|
const frames = (step.holdFrames ?? 0) + (step.waitFrames ?? 0);
|
|
4120
5283
|
if (ticks > 0 && bridge?.description.capabilities.includes("runtime.fixedStep") === true) {
|
|
4121
|
-
|
|
4122
|
-
|
|
5284
|
+
const sampleTicks = 10;
|
|
5285
|
+
for (let index = 0; index < ticks; index += sampleTicks) {
|
|
5286
|
+
await bridge.advance(Math.min(sampleTicks, ticks - index));
|
|
4123
5287
|
await samplePathPosition(bridge, pathEntity, pathPositions);
|
|
4124
5288
|
}
|
|
4125
5289
|
} else {
|
|
4126
5290
|
await waitFrames(page, Math.max(frames, ticks, 1));
|
|
4127
5291
|
await samplePathPosition(bridge, pathEntity, pathPositions);
|
|
4128
5292
|
}
|
|
5293
|
+
const afterInput = bridge === void 0 || movementSampleRequest === void 0 ? void 0 : await bridge.sample(movementSampleRequest);
|
|
5294
|
+
let afterStep = afterInput;
|
|
4129
5295
|
if (press !== void 0 && step.release) {
|
|
4130
5296
|
const released = typeof press === "string" ? [press] : [...inputState.heldKeys];
|
|
4131
5297
|
for (const key of released) {
|
|
4132
5298
|
await page.keyboard.up(key);
|
|
4133
5299
|
inputState.heldKeys.delete(key);
|
|
4134
5300
|
}
|
|
4135
|
-
if (!finalStep)
|
|
5301
|
+
if (!finalStep) {
|
|
5302
|
+
if (bridge?.description.capabilities.includes("runtime.fixedStep") === true) {
|
|
5303
|
+
await bridge.advance(1);
|
|
5304
|
+
} else {
|
|
5305
|
+
await waitFrames(page, 1);
|
|
5306
|
+
}
|
|
5307
|
+
if (bridge !== void 0 && movementSampleRequest !== void 0) {
|
|
5308
|
+
afterStep = await bridge.sample(movementSampleRequest);
|
|
5309
|
+
}
|
|
5310
|
+
}
|
|
4136
5311
|
}
|
|
4137
5312
|
if (step.pointerPosition?.buttons !== void 0 && step.release) {
|
|
4138
5313
|
await setPointerButtons(page, inputState, 0);
|
|
4139
5314
|
}
|
|
5315
|
+
if (step.pointers !== void 0 && step.release) {
|
|
5316
|
+
await setBrowserPointers(page, inputState, [], viewport);
|
|
5317
|
+
if (bridge?.description.capabilities.includes("runtime.fixedStep") === true) {
|
|
5318
|
+
await bridge.advance(1);
|
|
5319
|
+
} else {
|
|
5320
|
+
await waitFrames(page, 1);
|
|
5321
|
+
}
|
|
5322
|
+
if (bridge !== void 0 && movementSampleRequest !== void 0) {
|
|
5323
|
+
afterStep = await bridge.sample(movementSampleRequest);
|
|
5324
|
+
}
|
|
5325
|
+
}
|
|
5326
|
+
return { afterInput, afterStep, inputDriven };
|
|
5327
|
+
}
|
|
5328
|
+
function playtestStepDrivesMovement(step, hasHeldInput) {
|
|
5329
|
+
const hasNewInput = typeof step.press === "string" ? step.press.length > 0 : (step.press?.length ?? 0) > 0 || step.pointerPosition !== void 0 || (step.pointers?.length ?? 0) > 0;
|
|
5330
|
+
return hasNewInput || step.press === void 0 && step.pointers === void 0 && step.pointerPosition === void 0 && hasHeldInput;
|
|
5331
|
+
}
|
|
5332
|
+
function inputActive(inputState) {
|
|
5333
|
+
return inputState.heldKeys.size > 0 || inputState.pointerButtons !== 0 || inputState.pointers.size > 0;
|
|
5334
|
+
}
|
|
5335
|
+
async function setBrowserPointers(page, inputState, next, viewport) {
|
|
5336
|
+
const changes = reconcileBrowserPointers(inputState.pointers, next);
|
|
5337
|
+
if (next.some(({ buttons }) => buttons !== void 0 && buttons !== 1)) {
|
|
5338
|
+
throw new Error("Browser touch injection supports buttons=1 only.");
|
|
5339
|
+
}
|
|
5340
|
+
inputState.touchSession ??= await page.context().newCDPSession(page);
|
|
5341
|
+
const session = inputState.touchSession;
|
|
5342
|
+
const points = (pointers) => pointers.map((pointer) => ({
|
|
5343
|
+
force: 1,
|
|
5344
|
+
id: pointer.id,
|
|
5345
|
+
radiusX: 1,
|
|
5346
|
+
radiusY: 1,
|
|
5347
|
+
x: pointer.x * viewport.width,
|
|
5348
|
+
y: pointer.y * viewport.height
|
|
5349
|
+
}));
|
|
5350
|
+
const removed = changes.filter(({ type }) => type === "pointerup").map(({ pointer }) => pointer);
|
|
5351
|
+
const added = changes.filter(({ type }) => type === "pointerdown").map(({ pointer }) => pointer);
|
|
5352
|
+
const moved = changes.filter(({ type }) => type === "pointermove").map(({ pointer }) => pointer);
|
|
5353
|
+
if (removed.length > 0) {
|
|
5354
|
+
await session.send("Input.dispatchTouchEvent", {
|
|
5355
|
+
touchPoints: points(removed),
|
|
5356
|
+
type: "touchEnd"
|
|
5357
|
+
});
|
|
5358
|
+
}
|
|
5359
|
+
if (added.length > 0) {
|
|
5360
|
+
await session.send("Input.dispatchTouchEvent", { touchPoints: points(added), type: "touchStart" });
|
|
5361
|
+
}
|
|
5362
|
+
if (moved.length > 0) {
|
|
5363
|
+
await session.send("Input.dispatchTouchEvent", { touchPoints: points(moved), type: "touchMove" });
|
|
5364
|
+
}
|
|
5365
|
+
inputState.pointers = new Map(next.map((pointer) => [pointer.id, {
|
|
5366
|
+
buttons: pointer.buttons ?? 1,
|
|
5367
|
+
id: pointer.id,
|
|
5368
|
+
x: pointer.x,
|
|
5369
|
+
y: pointer.y
|
|
5370
|
+
}]));
|
|
4140
5371
|
}
|
|
4141
5372
|
var POINTER_BUTTONS = [
|
|
4142
5373
|
{ button: "left", mask: 1 },
|
|
@@ -4187,13 +5418,15 @@ async function waitFrames(page, frames) {
|
|
|
4187
5418
|
}), frames);
|
|
4188
5419
|
}
|
|
4189
5420
|
function observedEntityIds(scenario) {
|
|
4190
|
-
return
|
|
5421
|
+
if (isAnonymousMovementScenario(scenario)) return void 0;
|
|
5422
|
+
const ids = [...new Set([
|
|
4191
5423
|
scenario.subject,
|
|
4192
5424
|
scenario.assert?.movement?.entity,
|
|
4193
5425
|
scenario.assert?.camera?.entity,
|
|
4194
5426
|
scenario.assert?.camera?.follows,
|
|
4195
5427
|
...(scenario.assert?.visibility ?? []).map(({ entity }) => entity)
|
|
4196
5428
|
].filter((value) => value !== void 0))];
|
|
5429
|
+
return ids.length > 0 ? ids : scenario.assert?.movement === void 0 ? [] : void 0;
|
|
4197
5430
|
}
|
|
4198
5431
|
function observedResourceIds(scenario) {
|
|
4199
5432
|
return [.../* @__PURE__ */ new Set([
|
|
@@ -4229,6 +5462,48 @@ function pairObservations(before, after) {
|
|
|
4229
5462
|
function entityPosition(snapshot, id) {
|
|
4230
5463
|
return snapshot?.entities?.find((entity) => entity.id === id)?.transform?.position;
|
|
4231
5464
|
}
|
|
5465
|
+
function isAnonymousMovementScenario(scenario) {
|
|
5466
|
+
return scenario.assert?.movement !== void 0 && scenario.assert.movement.entity === void 0 && scenario.subject === void 0;
|
|
5467
|
+
}
|
|
5468
|
+
function observedMovementSample(samples) {
|
|
5469
|
+
const inputOff = samples.filter(({ inputDriven }) => !inputDriven);
|
|
5470
|
+
if (inputOff.length === 0) return void 0;
|
|
5471
|
+
return samples.filter(({ inputDriven }) => inputDriven).flatMap((sample) => observedMovementEntities(sample.before, sample.after).flatMap(({ id, distance }) => {
|
|
5472
|
+
const inputOffBaseline = inputOff.every((offSample) => {
|
|
5473
|
+
const offEntity = observedMovementEntities(offSample.before, offSample.after).find(({ id: offId }) => offId === id);
|
|
5474
|
+
return offEntity !== void 0 && offEntity.distance === 0 && movementRate(offSample, id) !== void 0;
|
|
5475
|
+
});
|
|
5476
|
+
const inputOnRate = movementRate(sample, id);
|
|
5477
|
+
return !inputOffBaseline || inputOnRate === void 0 || inputOnRate <= 0 ? [] : [{ ...sample, distance, entity: id, contrast: inputOnRate }];
|
|
5478
|
+
})).sort((left, right) => right.distance - left.distance || right.contrast - left.contrast || left.entity.localeCompare(right.entity))[0];
|
|
5479
|
+
}
|
|
5480
|
+
function observedMovementEntities(before, after) {
|
|
5481
|
+
const beforeEntities = new Map(
|
|
5482
|
+
(before.entities ?? []).filter(({ transform }) => transform?.position !== void 0).map(({ id, transform }) => [id, transform.position])
|
|
5483
|
+
);
|
|
5484
|
+
return (after.entities ?? []).flatMap((entity) => {
|
|
5485
|
+
const beforePosition = beforeEntities.get(entity.id);
|
|
5486
|
+
const afterPosition = entity.transform?.position;
|
|
5487
|
+
return beforePosition === void 0 || afterPosition === void 0 || entity.visible === false ? [] : [{ distance: length(subtract(afterPosition, beforePosition)), id: entity.id }];
|
|
5488
|
+
});
|
|
5489
|
+
}
|
|
5490
|
+
function movementRate(sample, entity) {
|
|
5491
|
+
const beforePosition = entityPosition(sample.before, entity);
|
|
5492
|
+
const afterPosition = entityPosition(sample.after, entity);
|
|
5493
|
+
if (beforePosition === void 0 || afterPosition === void 0) return void 0;
|
|
5494
|
+
const duration = movementDuration(sample);
|
|
5495
|
+
return duration === void 0 ? void 0 : length(subtract(afterPosition, beforePosition)) / duration;
|
|
5496
|
+
}
|
|
5497
|
+
function movementDuration(sample) {
|
|
5498
|
+
if (sample.before.clock.mode !== sample.after.clock.mode) return void 0;
|
|
5499
|
+
const duration = sample.before.clock.mode === "fixed-step" ? positiveFiniteDelta(sample.before.clock.tick, sample.after.clock.tick) : positiveFiniteDelta(sample.before.clock.timeMs, sample.after.clock.timeMs);
|
|
5500
|
+
return duration;
|
|
5501
|
+
}
|
|
5502
|
+
function positiveFiniteDelta(before, after) {
|
|
5503
|
+
if (typeof before !== "number" || typeof after !== "number" || !Number.isFinite(before) || !Number.isFinite(after)) return void 0;
|
|
5504
|
+
const delta = after - before;
|
|
5505
|
+
return Number.isFinite(delta) && delta > 0 ? delta : void 0;
|
|
5506
|
+
}
|
|
4232
5507
|
function entityRotation(snapshot, id) {
|
|
4233
5508
|
return snapshot?.entities?.find((entity) => entity.id === id)?.transform?.rotation;
|
|
4234
5509
|
}
|
|
@@ -4236,9 +5511,22 @@ function resourceObservations(before, after) {
|
|
|
4236
5511
|
const ids = /* @__PURE__ */ new Set([...Object.keys(before?.resources ?? {}), ...Object.keys(after?.resources ?? {})]);
|
|
4237
5512
|
return Object.fromEntries([...ids].map((id) => [id, { before: before?.resources?.[id], after: after?.resources?.[id] }]));
|
|
4238
5513
|
}
|
|
4239
|
-
function
|
|
5514
|
+
function isRuntimeReadout(entry) {
|
|
5515
|
+
if (typeof entry !== "object" || entry === null || Array.isArray(entry)) return false;
|
|
5516
|
+
const record2 = entry;
|
|
5517
|
+
if (record2.severity === "error" || record2.error !== void 0) return false;
|
|
5518
|
+
if (typeof record2.type === "string" && ["assert", "error", "pageerror"].includes(record2.type)) return false;
|
|
5519
|
+
const value = record2.value;
|
|
5520
|
+
return typeof record2.label === "string" && (typeof value === "string" || typeof value === "number" || typeof value === "boolean");
|
|
5521
|
+
}
|
|
5522
|
+
function normalizedRuntimeDiagnostics(snapshot, scenario, consoleEntries) {
|
|
5523
|
+
const published = snapshot?.diagnostics ?? [];
|
|
4240
5524
|
return {
|
|
4241
|
-
recentRuntimeErrors:
|
|
5525
|
+
recentRuntimeErrors: [
|
|
5526
|
+
...published.filter((entry) => !isRuntimeReadout(entry)),
|
|
5527
|
+
...consoleEntries.filter(({ source, type }) => source !== "browser-console" && ["assert", "error", "pageerror"].includes(type))
|
|
5528
|
+
],
|
|
5529
|
+
runtimeReadouts: published.filter(isRuntimeReadout),
|
|
4242
5530
|
scene: {
|
|
4243
5531
|
renderedEntities: (snapshot?.entities ?? []).map((entity) => ({
|
|
4244
5532
|
id: entity.id,
|
|
@@ -4248,6 +5536,88 @@ function normalizedRuntimeDiagnostics(snapshot, scenario) {
|
|
|
4248
5536
|
}
|
|
4249
5537
|
};
|
|
4250
5538
|
}
|
|
5539
|
+
async function readCaptureProvenance(page, config, scenario) {
|
|
5540
|
+
const observed = await page.evaluate(async () => {
|
|
5541
|
+
const gpu = globalThis.navigator.gpu;
|
|
5542
|
+
const adapter = gpu === void 0 ? null : await gpu.requestAdapter().catch(() => null);
|
|
5543
|
+
const infoCandidate = adapter?.info;
|
|
5544
|
+
const legacyInfo = await adapter?.requestAdapterInfo?.().catch(() => void 0);
|
|
5545
|
+
const info = infoCandidate === void 0 || Object.keys(infoCandidate).length === 0 ? legacyInfo ?? infoCandidate : infoCandidate;
|
|
5546
|
+
const adapterIdentityKeys = ["architecture", "description", "device", "vendor"];
|
|
5547
|
+
const adapterIdentityEntries = info === void 0 ? [] : adapterIdentityKeys.flatMap((key) => {
|
|
5548
|
+
const value = info[key];
|
|
5549
|
+
const text = String(value ?? "");
|
|
5550
|
+
return text.length === 0 ? [] : [[key, text]];
|
|
5551
|
+
});
|
|
5552
|
+
const webgpuAdapterEntries = [...adapterIdentityEntries];
|
|
5553
|
+
if (adapterIdentityEntries.length > 0 && adapter?.features !== void 0) {
|
|
5554
|
+
const features = [...adapter.features].map(String).sort();
|
|
5555
|
+
if (features.length > 0) webgpuAdapterEntries.push(["features", features.join(",")]);
|
|
5556
|
+
}
|
|
5557
|
+
if (adapterIdentityEntries.length > 0) {
|
|
5558
|
+
for (const key of ["maxBindGroups", "maxTextureDimension2D", "maxStorageBufferBindingSize"]) {
|
|
5559
|
+
const value = adapter?.limits?.[key];
|
|
5560
|
+
if (typeof value === "number" && Number.isFinite(value)) webgpuAdapterEntries.push([`limit.${key}`, String(value)]);
|
|
5561
|
+
}
|
|
5562
|
+
}
|
|
5563
|
+
const webgpuAdapterInfo = adapterIdentityEntries.length === 0 ? void 0 : Object.fromEntries(webgpuAdapterEntries);
|
|
5564
|
+
const canvas = document.querySelector("canvas");
|
|
5565
|
+
const engine = canvas?.getAttribute("data-engine")?.toLowerCase() ?? "";
|
|
5566
|
+
let rendererKind;
|
|
5567
|
+
if (engine.includes("webgpu")) rendererKind = "webgpu";
|
|
5568
|
+
else if (engine.includes("webgl")) rendererKind = "webgl";
|
|
5569
|
+
else if (adapter !== null && canvas !== null) {
|
|
5570
|
+
try {
|
|
5571
|
+
if (canvas.getContext("webgpu") !== null) rendererKind = "webgpu";
|
|
5572
|
+
} catch {
|
|
5573
|
+
}
|
|
5574
|
+
}
|
|
5575
|
+
let webglAdapterInfo;
|
|
5576
|
+
if (rendererKind === void 0 || rendererKind === "webgl") {
|
|
5577
|
+
try {
|
|
5578
|
+
const context = canvas?.getContext("webgl2") ?? canvas?.getContext("webgl");
|
|
5579
|
+
if (context !== null && context !== void 0) {
|
|
5580
|
+
rendererKind = "webgl";
|
|
5581
|
+
const debugInfo = context.getExtension("WEBGL_debug_renderer_info");
|
|
5582
|
+
const vendor = String(context.getParameter(debugInfo?.UNMASKED_VENDOR_WEBGL ?? context.VENDOR) ?? "");
|
|
5583
|
+
const renderer = String(context.getParameter(debugInfo?.UNMASKED_RENDERER_WEBGL ?? context.RENDERER) ?? "");
|
|
5584
|
+
const webglEntries = [
|
|
5585
|
+
["renderer", renderer],
|
|
5586
|
+
["vendor", vendor]
|
|
5587
|
+
];
|
|
5588
|
+
webglAdapterInfo = Object.fromEntries(webglEntries.filter(([, value]) => value.length > 0));
|
|
5589
|
+
}
|
|
5590
|
+
} catch {
|
|
5591
|
+
}
|
|
5592
|
+
}
|
|
5593
|
+
return {
|
|
5594
|
+
adapter: rendererKind === "webgl" ? webglAdapterInfo : webgpuAdapterInfo,
|
|
5595
|
+
rendererKind
|
|
5596
|
+
};
|
|
5597
|
+
});
|
|
5598
|
+
if (observed.adapter === void 0 || Object.keys(observed.adapter).length === 0) {
|
|
5599
|
+
throw new PlaytestBridgeError(playtestDiagnostic(
|
|
5600
|
+
"TN_PLAYTEST_CAPTURE_PROVENANCE_MISSING",
|
|
5601
|
+
`Visual capture could not read a renderer adapter description (kind=${observed.rendererKind ?? "unknown"}).`,
|
|
5602
|
+
"Run the visual playtest with a working GPU/WebGPU adapter or WebGL renderer; the runner will not write unknown adapter provenance."
|
|
5603
|
+
));
|
|
5604
|
+
}
|
|
5605
|
+
if (observed.rendererKind === void 0) {
|
|
5606
|
+
throw new PlaytestBridgeError(playtestDiagnostic(
|
|
5607
|
+
"TN_PLAYTEST_CAPTURE_PROVENANCE_MISSING",
|
|
5608
|
+
"Visual capture could not identify the page renderer kind.",
|
|
5609
|
+
"Expose a WebGPU/WebGL canvas before capturing the visual artifact, then rerun the playtest."
|
|
5610
|
+
));
|
|
5611
|
+
}
|
|
5612
|
+
return {
|
|
5613
|
+
adapter: observed.adapter,
|
|
5614
|
+
browserArgs: resolveBrowserArguments(config.browserArgs),
|
|
5615
|
+
captureMethod: "page.screenshot",
|
|
5616
|
+
rendererKind: observed.rendererKind,
|
|
5617
|
+
target: scenario.target,
|
|
5618
|
+
viewport: { ...scenario.viewport }
|
|
5619
|
+
};
|
|
5620
|
+
}
|
|
4251
5621
|
function pixelBoundsToNdc(bounds, viewport) {
|
|
4252
5622
|
return {
|
|
4253
5623
|
max: [2 * (bounds.x + bounds.width) / viewport.width - 1, 1 - 2 * bounds.y / viewport.height],
|
|
@@ -4302,6 +5672,74 @@ function startManagedServer(config) {
|
|
|
4302
5672
|
});
|
|
4303
5673
|
return server;
|
|
4304
5674
|
}
|
|
5675
|
+
var PAGE_NAVIGATED_PATTERN = /Execution context was destroyed|frame (?:was )?detached|Target (?:page|closed)/iu;
|
|
5676
|
+
var TEARDOWN_TIMED_OUT = /* @__PURE__ */ Symbol("teardown-timed-out");
|
|
5677
|
+
async function boundedTeardownStep(step, timeoutMs) {
|
|
5678
|
+
if (step === void 0) return true;
|
|
5679
|
+
let timer;
|
|
5680
|
+
const timeout = new Promise((resolveTimeout) => {
|
|
5681
|
+
timer = setTimeout(() => resolveTimeout(TEARDOWN_TIMED_OUT), timeoutMs);
|
|
5682
|
+
});
|
|
5683
|
+
try {
|
|
5684
|
+
return await Promise.race([step.catch(() => void 0), timeout]) !== TEARDOWN_TIMED_OUT;
|
|
5685
|
+
} finally {
|
|
5686
|
+
if (timer !== void 0) clearTimeout(timer);
|
|
5687
|
+
}
|
|
5688
|
+
}
|
|
5689
|
+
function isPageNavigatedRace(error) {
|
|
5690
|
+
return error instanceof Error && PAGE_NAVIGATED_PATTERN.test(error.message);
|
|
5691
|
+
}
|
|
5692
|
+
function pageLifecycleDiagnostic(error, lifecycle, url) {
|
|
5693
|
+
if (!lifecycle.crashed && !isPageNavigatedRace(error)) return void 0;
|
|
5694
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
5695
|
+
if (lifecycle.crashed) {
|
|
5696
|
+
return playtestDiagnostic(
|
|
5697
|
+
"TN_PLAYTEST_PAGE_CRASHED",
|
|
5698
|
+
`The browser page crashed while the scenario was running at '${url}'; runner error: ${detail}.`,
|
|
5699
|
+
"The renderer process died mid-run, so no assertion after that point was observed. Re-run with a smaller scene or a hardware GPU; under a virtual display the software WebGPU path is the usual cause."
|
|
5700
|
+
);
|
|
5701
|
+
}
|
|
5702
|
+
const where = lifecycle.navigations.length === 0 ? "an unrecorded location" : `'${lifecycle.navigations.join("', '")}'`;
|
|
5703
|
+
const observed = [
|
|
5704
|
+
`page closed: ${lifecycle.closed}`,
|
|
5705
|
+
`main-frame navigations: ${lifecycle.frameNavigations.length}`,
|
|
5706
|
+
...lifecycle.tail.length === 0 ? [] : [`last console: ${lifecycle.tail.join(" | ")}`]
|
|
5707
|
+
].join("; ");
|
|
5708
|
+
return playtestDiagnostic(
|
|
5709
|
+
"TN_PLAYTEST_PAGE_NAVIGATED",
|
|
5710
|
+
`The page navigated to ${where} while the scenario was running at '${url}'; runner error: ${detail}. Observed: ${observed}.`,
|
|
5711
|
+
"Something moved the document after the run started, so the observations after that point are from a different page. Remove the navigation from the game, or point --url at a server that does not reload itself mid-run."
|
|
5712
|
+
);
|
|
5713
|
+
}
|
|
5714
|
+
async function openPageAndConnectBridge(page, config, scenario) {
|
|
5715
|
+
const attempts = 3;
|
|
5716
|
+
let lastError;
|
|
5717
|
+
for (let attempt = 1; attempt <= attempts; attempt += 1) {
|
|
5718
|
+
try {
|
|
5719
|
+
await page.goto(config.url, { timeout: config.timeoutMs, waitUntil: "domcontentloaded" });
|
|
5720
|
+
await page.waitForLoadState("load", { timeout: config.timeoutMs }).catch(() => void 0);
|
|
5721
|
+
return await connectPlaytestBridge(page, scenario);
|
|
5722
|
+
} catch (error) {
|
|
5723
|
+
if (error instanceof PlaytestBridgeError || !isPageNavigatedRace(error)) throw error;
|
|
5724
|
+
lastError = error instanceof Error ? error : new Error(String(error));
|
|
5725
|
+
}
|
|
5726
|
+
}
|
|
5727
|
+
throw new PlaytestBridgeError(playtestDiagnostic(
|
|
5728
|
+
"TN_PLAYTEST_PAGE_NAVIGATED",
|
|
5729
|
+
`The page navigated during the bridge handshake on all ${attempts} attempts at '${config.url}'; last runner error: ${lastError?.message ?? "unknown"}.`,
|
|
5730
|
+
"The served page is reloading itself while the run starts. With a Vite dev server this is usually dependency pre-bundling: run the project's build or dev command once before the scenario so the dependency cache is warm, or point --url at a preview server instead.",
|
|
5731
|
+
{ nextCommand: config.server?.command }
|
|
5732
|
+
));
|
|
5733
|
+
}
|
|
5734
|
+
async function assertManagedUrlAvailable(url) {
|
|
5735
|
+
try {
|
|
5736
|
+
const response = await fetch(url, { method: "HEAD", signal: AbortSignal.timeout(500) });
|
|
5737
|
+
await response.body?.cancel();
|
|
5738
|
+
} catch {
|
|
5739
|
+
return;
|
|
5740
|
+
}
|
|
5741
|
+
throw managedServerError("Managed server URL is already in use before startup.", url, 0, []);
|
|
5742
|
+
}
|
|
4305
5743
|
async function waitForUrl(url, timeoutMs, server) {
|
|
4306
5744
|
const started = Date.now();
|
|
4307
5745
|
const output = [];
|
|
@@ -4325,8 +5763,9 @@ async function waitForUrl(url, timeoutMs, server) {
|
|
|
4325
5763
|
}
|
|
4326
5764
|
throw managedServerError(`Managed server did not become ready within ${timeoutMs}ms.`, url, timeoutMs, output);
|
|
4327
5765
|
}
|
|
4328
|
-
function stopManagedServer(server) {
|
|
4329
|
-
if (server?.pid === void 0 || server.exitCode !== null) return;
|
|
5766
|
+
async function stopManagedServer(server) {
|
|
5767
|
+
if (server?.pid === void 0 || server.exitCode !== null || server.signalCode !== null) return;
|
|
5768
|
+
const stopped = waitForProcessExit2(server, 2e3);
|
|
4330
5769
|
if (process.platform === "win32") server.kill();
|
|
4331
5770
|
else {
|
|
4332
5771
|
try {
|
|
@@ -4334,6 +5773,29 @@ function stopManagedServer(server) {
|
|
|
4334
5773
|
} catch {
|
|
4335
5774
|
}
|
|
4336
5775
|
}
|
|
5776
|
+
if (await stopped) return;
|
|
5777
|
+
if (process.platform === "win32") server.kill("SIGKILL");
|
|
5778
|
+
else {
|
|
5779
|
+
try {
|
|
5780
|
+
process.kill(-server.pid, "SIGKILL");
|
|
5781
|
+
} catch {
|
|
5782
|
+
}
|
|
5783
|
+
}
|
|
5784
|
+
await waitForProcessExit2(server, 1e3);
|
|
5785
|
+
}
|
|
5786
|
+
function waitForProcessExit2(server, timeoutMs) {
|
|
5787
|
+
if (server.exitCode !== null || server.signalCode !== null) return Promise.resolve(true);
|
|
5788
|
+
return new Promise((resolveExit) => {
|
|
5789
|
+
const timeout = setTimeout(() => {
|
|
5790
|
+
server.off("exit", onExit);
|
|
5791
|
+
resolveExit(false);
|
|
5792
|
+
}, timeoutMs);
|
|
5793
|
+
const onExit = () => {
|
|
5794
|
+
clearTimeout(timeout);
|
|
5795
|
+
resolveExit(true);
|
|
5796
|
+
};
|
|
5797
|
+
server.once("exit", onExit);
|
|
5798
|
+
});
|
|
4337
5799
|
}
|
|
4338
5800
|
function managedServerError(message, url, timeoutMs, output) {
|
|
4339
5801
|
return new ManagedServerError(playtestDiagnostic(
|
|
@@ -4342,6 +5804,219 @@ function managedServerError(message, url, timeoutMs, output) {
|
|
|
4342
5804
|
"Run the server command directly, fix its first error, then rerun the same playtest command."
|
|
4343
5805
|
));
|
|
4344
5806
|
}
|
|
5807
|
+
var execFileAsync2 = promisify(execFile);
|
|
5808
|
+
var DEFAULT_GRID = { columns: 32, rows: 18 };
|
|
5809
|
+
async function analyzeFramebufferCoverageRecording(videoPath, artifactDirectory, assertion, boundarySource = "video-backdrop-dominance") {
|
|
5810
|
+
await mkdir(artifactDirectory, { recursive: true });
|
|
5811
|
+
const frameDirectory = await mkdtemp(join(artifactDirectory, ".framebuffer-coverage-frames-"));
|
|
5812
|
+
try {
|
|
5813
|
+
const pattern = join(frameDirectory, "frame-%06d.png");
|
|
5814
|
+
await execFileAsync2(
|
|
5815
|
+
"ffmpeg",
|
|
5816
|
+
["-loglevel", "error", "-i", videoPath, "-vsync", "0", pattern],
|
|
5817
|
+
{ maxBuffer: 32 * 1024 * 1024 }
|
|
5818
|
+
);
|
|
5819
|
+
const framePaths = (await readdir(frameDirectory)).filter((name) => /^frame-\d+\.png$/u.test(name)).sort().map((name) => join(frameDirectory, name));
|
|
5820
|
+
if (framePaths.length === 0) {
|
|
5821
|
+
return {
|
|
5822
|
+
boundarySource,
|
|
5823
|
+
frameCount: 0,
|
|
5824
|
+
unreadableReason: "TN_PLAYTEST_FRAMEBUFFER_COVERAGE_VIDEO_NO_FRAMES",
|
|
5825
|
+
windowCompleted: false,
|
|
5826
|
+
windowStarted: false
|
|
5827
|
+
};
|
|
5828
|
+
}
|
|
5829
|
+
const box = await findVideoContentBoxFromFiles(framePaths);
|
|
5830
|
+
if (box === void 0) {
|
|
5831
|
+
return {
|
|
5832
|
+
boundarySource,
|
|
5833
|
+
frameCount: 0,
|
|
5834
|
+
unreadableReason: "TN_PLAYTEST_FRAMEBUFFER_COVERAGE_VIDEO_ALL_BLACK",
|
|
5835
|
+
windowCompleted: false,
|
|
5836
|
+
windowStarted: false
|
|
5837
|
+
};
|
|
5838
|
+
}
|
|
5839
|
+
const gridSize = assertion.grid ?? DEFAULT_GRID;
|
|
5840
|
+
const grids = [];
|
|
5841
|
+
for (const path of framePaths) {
|
|
5842
|
+
grids.push(sampleFramebufferCoverageVideoFrame(PNG.sync.read(await readFile(path)), box, gridSize));
|
|
5843
|
+
}
|
|
5844
|
+
const observation = boundarySource === "scenario-steps" ? analyzeScenarioBracketedCoverageFrames(grids, framePaths, assertion) : analyzeSampledCoverageFrames(grids, framePaths, assertion);
|
|
5845
|
+
if (observation.firstViolation === void 0) return observation;
|
|
5846
|
+
const screenshotPath = join(
|
|
5847
|
+
artifactDirectory,
|
|
5848
|
+
`framebuffer-coverage-failure-${observation.firstViolation.frameIndex}.png`
|
|
5849
|
+
);
|
|
5850
|
+
await copyFile(observation.firstViolation.screenshotPath, screenshotPath);
|
|
5851
|
+
return {
|
|
5852
|
+
...observation,
|
|
5853
|
+
firstViolation: { ...observation.firstViolation, screenshotPath }
|
|
5854
|
+
};
|
|
5855
|
+
} catch (error) {
|
|
5856
|
+
return {
|
|
5857
|
+
boundarySource,
|
|
5858
|
+
frameCount: 0,
|
|
5859
|
+
unreadableReason: `TN_PLAYTEST_FRAMEBUFFER_COVERAGE_VIDEO_UNREADABLE:${errorMessage(error)}`,
|
|
5860
|
+
windowCompleted: false,
|
|
5861
|
+
windowStarted: false
|
|
5862
|
+
};
|
|
5863
|
+
} finally {
|
|
5864
|
+
await rm(frameDirectory, { force: true, recursive: true });
|
|
5865
|
+
}
|
|
5866
|
+
}
|
|
5867
|
+
function analyzeScenarioBracketedCoverageFrames(grids, framePaths, assertion) {
|
|
5868
|
+
const base = {
|
|
5869
|
+
boundarySource: "scenario-steps",
|
|
5870
|
+
windowCompleted: true,
|
|
5871
|
+
windowStarted: true
|
|
5872
|
+
};
|
|
5873
|
+
if (grids.length === 0) {
|
|
5874
|
+
return {
|
|
5875
|
+
...base,
|
|
5876
|
+
frameCount: 0,
|
|
5877
|
+
unreadableReason: "TN_PLAYTEST_FRAMEBUFFER_COVERAGE_VIDEO_NO_FRAMES"
|
|
5878
|
+
};
|
|
5879
|
+
}
|
|
5880
|
+
if (framePaths.length !== grids.length) {
|
|
5881
|
+
return {
|
|
5882
|
+
...base,
|
|
5883
|
+
frameCount: 0,
|
|
5884
|
+
unreadableReason: "TN_PLAYTEST_FRAMEBUFFER_COVERAGE_VIDEO_PATH_COUNT"
|
|
5885
|
+
};
|
|
5886
|
+
}
|
|
5887
|
+
const firstViolationOffset = grids.findIndex(
|
|
5888
|
+
(grid) => grid.samples.some((sample) => !sampleMatches(sample, assertion.backdrop, assertion.tolerance))
|
|
5889
|
+
);
|
|
5890
|
+
if (firstViolationOffset === -1) {
|
|
5891
|
+
return {
|
|
5892
|
+
...base,
|
|
5893
|
+
frameCount: grids.length
|
|
5894
|
+
};
|
|
5895
|
+
}
|
|
5896
|
+
const violationGrid = grids[firstViolationOffset];
|
|
5897
|
+
const violationFramePath = framePaths[firstViolationOffset];
|
|
5898
|
+
if (violationGrid === void 0 || violationFramePath === void 0) {
|
|
5899
|
+
return {
|
|
5900
|
+
...base,
|
|
5901
|
+
frameCount: 0,
|
|
5902
|
+
unreadableReason: "TN_PLAYTEST_FRAMEBUFFER_COVERAGE_VIDEO_PATH_COUNT"
|
|
5903
|
+
};
|
|
5904
|
+
}
|
|
5905
|
+
return {
|
|
5906
|
+
...base,
|
|
5907
|
+
firstViolation: {
|
|
5908
|
+
frameIndex: firstViolationOffset,
|
|
5909
|
+
grid: violationGrid,
|
|
5910
|
+
screenshotPath: violationFramePath
|
|
5911
|
+
},
|
|
5912
|
+
frameCount: grids.length
|
|
5913
|
+
};
|
|
5914
|
+
}
|
|
5915
|
+
async function findVideoContentBoxFromFiles(framePaths) {
|
|
5916
|
+
const appPaths = framePaths.slice(Math.floor(framePaths.length / 2));
|
|
5917
|
+
const firstPath = appPaths[0];
|
|
5918
|
+
if (firstPath === void 0) return void 0;
|
|
5919
|
+
const accumulator = createContentBoxAccumulator(PNG.sync.read(await readFile(firstPath)));
|
|
5920
|
+
for (const path of appPaths) {
|
|
5921
|
+
if (!accumulateContentBox(accumulator, PNG.sync.read(await readFile(path)))) {
|
|
5922
|
+
throw new Error("TN_PLAYTEST_FRAMEBUFFER_COVERAGE_VIDEO_SIZE_CHANGED");
|
|
5923
|
+
}
|
|
5924
|
+
}
|
|
5925
|
+
return finishContentBox(accumulator);
|
|
5926
|
+
}
|
|
5927
|
+
function createContentBoxAccumulator(frame) {
|
|
5928
|
+
return {
|
|
5929
|
+
columnLit: new Uint8Array(frame.width),
|
|
5930
|
+
height: frame.height,
|
|
5931
|
+
rowLit: new Uint8Array(frame.height),
|
|
5932
|
+
width: frame.width
|
|
5933
|
+
};
|
|
5934
|
+
}
|
|
5935
|
+
function accumulateContentBox(accumulator, frame) {
|
|
5936
|
+
if (frame.width !== accumulator.width || frame.height !== accumulator.height) return false;
|
|
5937
|
+
for (let y = 0; y < frame.height; y += 1) {
|
|
5938
|
+
for (let x = 0; x < frame.width; x += 1) {
|
|
5939
|
+
const offset = (y * frame.width + x) * 4;
|
|
5940
|
+
if (frame.data[offset] > 12 || frame.data[offset + 1] > 12 || frame.data[offset + 2] > 12) {
|
|
5941
|
+
accumulator.rowLit[y] = 1;
|
|
5942
|
+
accumulator.columnLit[x] = 1;
|
|
5943
|
+
}
|
|
5944
|
+
}
|
|
5945
|
+
}
|
|
5946
|
+
return true;
|
|
5947
|
+
}
|
|
5948
|
+
function finishContentBox({ columnLit, height, rowLit, width }) {
|
|
5949
|
+
const firstRow = rowLit.indexOf(1);
|
|
5950
|
+
const firstColumn = columnLit.indexOf(1);
|
|
5951
|
+
if (firstRow === -1 || firstColumn === -1) return void 0;
|
|
5952
|
+
let lastRow = height - 1;
|
|
5953
|
+
while (lastRow > firstRow && rowLit[lastRow] === 0) lastRow -= 1;
|
|
5954
|
+
let lastColumn = width - 1;
|
|
5955
|
+
while (lastColumn > firstColumn && columnLit[lastColumn] === 0) lastColumn -= 1;
|
|
5956
|
+
return {
|
|
5957
|
+
height: lastRow - firstRow + 1,
|
|
5958
|
+
width: lastColumn - firstColumn + 1,
|
|
5959
|
+
x: firstColumn,
|
|
5960
|
+
y: firstRow
|
|
5961
|
+
};
|
|
5962
|
+
}
|
|
5963
|
+
function sampleFramebufferCoverageVideoFrame(frame, box, grid = DEFAULT_GRID) {
|
|
5964
|
+
const samples = [];
|
|
5965
|
+
for (let row = 0; row < grid.rows; row += 1) {
|
|
5966
|
+
const y = box.y + Math.min(box.height - 1, Math.floor((row + 0.5) / grid.rows * box.height));
|
|
5967
|
+
for (let column = 0; column < grid.columns; column += 1) {
|
|
5968
|
+
const x = box.x + Math.min(box.width - 1, Math.floor((column + 0.5) / grid.columns * box.width));
|
|
5969
|
+
const offset = (y * frame.width + x) * 4;
|
|
5970
|
+
samples.push([frame.data[offset], frame.data[offset + 1], frame.data[offset + 2]]);
|
|
5971
|
+
}
|
|
5972
|
+
}
|
|
5973
|
+
return { columns: grid.columns, rows: grid.rows, samples };
|
|
5974
|
+
}
|
|
5975
|
+
function analyzeSampledCoverageFrames(grids, framePaths, assertion) {
|
|
5976
|
+
const base = {
|
|
5977
|
+
boundarySource: "video-backdrop-dominance",
|
|
5978
|
+
frameCount: 0,
|
|
5979
|
+
windowCompleted: false,
|
|
5980
|
+
windowStarted: false
|
|
5981
|
+
};
|
|
5982
|
+
const matchingFractions = grids.map(
|
|
5983
|
+
(grid) => grid.samples.reduce(
|
|
5984
|
+
(count, sample) => count + (sampleMatches(sample, assertion.backdrop, assertion.tolerance) ? 1 : 0),
|
|
5985
|
+
0
|
|
5986
|
+
) / grid.samples.length
|
|
5987
|
+
);
|
|
5988
|
+
const dominantFrames = matchingFractions.map((fraction, index) => ({ fraction, index })).filter(({ fraction }) => fraction > 0.5).map(({ index }) => index);
|
|
5989
|
+
const firstVideoFrame = dominantFrames[0];
|
|
5990
|
+
const lastVideoFrame = dominantFrames.at(-1);
|
|
5991
|
+
if (firstVideoFrame === void 0 || lastVideoFrame === void 0) return base;
|
|
5992
|
+
const windowFrames = grids.slice(firstVideoFrame, lastVideoFrame + 1);
|
|
5993
|
+
const firstViolationOffset = windowFrames.findIndex(
|
|
5994
|
+
(grid) => grid.samples.some((sample) => !sampleMatches(sample, assertion.backdrop, assertion.tolerance))
|
|
5995
|
+
);
|
|
5996
|
+
return {
|
|
5997
|
+
...base,
|
|
5998
|
+
frameCount: windowFrames.length,
|
|
5999
|
+
...firstViolationOffset === -1 ? {} : {
|
|
6000
|
+
firstViolation: {
|
|
6001
|
+
frameIndex: firstViolationOffset,
|
|
6002
|
+
grid: windowFrames[firstViolationOffset],
|
|
6003
|
+
screenshotPath: framePaths[firstVideoFrame + firstViolationOffset]
|
|
6004
|
+
}
|
|
6005
|
+
},
|
|
6006
|
+
windowCompleted: lastVideoFrame < grids.length - 1,
|
|
6007
|
+
windowStarted: firstVideoFrame > 0
|
|
6008
|
+
};
|
|
6009
|
+
}
|
|
6010
|
+
function sampleMatches(sample, backdrop, tolerance) {
|
|
6011
|
+
return Math.max(
|
|
6012
|
+
Math.abs(sample[0] - backdrop[0]),
|
|
6013
|
+
Math.abs(sample[1] - backdrop[1]),
|
|
6014
|
+
Math.abs(sample[2] - backdrop[2])
|
|
6015
|
+
) <= tolerance;
|
|
6016
|
+
}
|
|
6017
|
+
function errorMessage(error) {
|
|
6018
|
+
return error instanceof Error ? error.message : String(error);
|
|
6019
|
+
}
|
|
4345
6020
|
|
|
4346
6021
|
// src/runner/androidRunner.ts
|
|
4347
6022
|
async function runAndroidPlaytest(config, dependencies = {}) {
|
|
@@ -4356,7 +6031,7 @@ async function runAndroidPlaytest(config, dependencies = {}) {
|
|
|
4356
6031
|
...config.device === void 0 ? {} : { serial: config.device }
|
|
4357
6032
|
});
|
|
4358
6033
|
const mailboxRoot = config.mailboxRoot ?? `/sdcard/Android/data/${android.packageName}/files`;
|
|
4359
|
-
return runDevicePlaytest(config, {
|
|
6034
|
+
return runDevicePlaytest({ ...config, mailboxRoot }, {
|
|
4360
6035
|
driver,
|
|
4361
6036
|
mailboxPaths: androidMailboxPaths(android.packageName, mailboxRoot),
|
|
4362
6037
|
name: "android",
|
|
@@ -4369,9 +6044,26 @@ async function runDevicePlaytest(config, target) {
|
|
|
4369
6044
|
await mkdir(config.artifactDirectory, { recursive: true });
|
|
4370
6045
|
const unsupported = unsupportedAssertion(scenario, target.name);
|
|
4371
6046
|
if (unsupported !== void 0) return failureReport2(config, scenario, unsupported, target.name);
|
|
6047
|
+
if (target.name === "android" && scenario.assert?.framebufferCoverage !== void 0 && (typeof target.driver.startScreenRecording !== "function" || typeof target.driver.stopScreenRecording !== "function")) {
|
|
6048
|
+
return failureReport2(config, scenario, unsupportedDiagnostic(
|
|
6049
|
+
"framebuffer coverage recording",
|
|
6050
|
+
"Use the adb-backed Android driver; framebuffer coverage requires screenrecord and offline ffmpeg analysis.",
|
|
6051
|
+
target.name
|
|
6052
|
+
), target.name);
|
|
6053
|
+
}
|
|
6054
|
+
if (target.name === "android" && scenario.steps.some((step) => step.pointers !== void 0) && typeof target.driver.setPointers !== "function") {
|
|
6055
|
+
return failureReport2(config, scenario, unsupportedDiagnostic(
|
|
6056
|
+
"complete held-pointer input",
|
|
6057
|
+
"Use the emulator-backed Android driver; multi-pointer steps cannot fall back to one-pointer bridge input.",
|
|
6058
|
+
target.name
|
|
6059
|
+
), target.name);
|
|
6060
|
+
}
|
|
4372
6061
|
const endpoint = config.endpoint ?? "http://127.0.0.1:41777/playtest";
|
|
4373
6062
|
const transport = target.transport ?? createDeviceTransport(target.driver, endpoint, target.mailboxPaths);
|
|
4374
6063
|
let bridge;
|
|
6064
|
+
let coverageRecordingStarted = false;
|
|
6065
|
+
let framebufferCoverage;
|
|
6066
|
+
const coverageVideoPath = join(config.artifactDirectory, "framebuffer-coverage.mp4");
|
|
4375
6067
|
try {
|
|
4376
6068
|
await transport.start();
|
|
4377
6069
|
await target.driver.prepare(endpoint, config.mailboxRoot);
|
|
@@ -4392,19 +6084,40 @@ async function runDevicePlaytest(config, target) {
|
|
|
4392
6084
|
}
|
|
4393
6085
|
if (scenario.setup !== void 0) await bridge.applySetup(setupRequest2(scenario));
|
|
4394
6086
|
if (scenario.warmupFrames > 0) await bridge.advance(scenario.warmupFrames);
|
|
6087
|
+
const entityIds = observedEntityIds2(scenario);
|
|
4395
6088
|
const sampleRequest = {
|
|
4396
|
-
entities:
|
|
4397
|
-
include: [
|
|
6089
|
+
...entityIds === void 0 ? {} : { entities: entityIds },
|
|
6090
|
+
include: [
|
|
6091
|
+
"components",
|
|
6092
|
+
"diagnostics",
|
|
6093
|
+
"entities",
|
|
6094
|
+
"resources",
|
|
6095
|
+
...scenario.assert?.aerodynamics === void 0 && scenario.assert?.contacts === void 0 && scenario.assert?.settled === void 0 ? [] : ["physicsDebugSeries"]
|
|
6096
|
+
],
|
|
4398
6097
|
resources: observedResourceIds2(scenario)
|
|
4399
6098
|
};
|
|
4400
6099
|
const before = await bridge.sample(sampleRequest);
|
|
4401
6100
|
const pathEntity = scenario.assert?.movement?.pathLength === void 0 ? void 0 : scenario.assert.movement.entity ?? scenario.subject;
|
|
4402
6101
|
const pathPositions = [];
|
|
4403
6102
|
appendPosition(pathPositions, before, pathEntity);
|
|
6103
|
+
const capturesAnonymousMovement = scenario.assert?.movement !== void 0 && scenario.assert.movement.entity === void 0 && scenario.subject === void 0;
|
|
6104
|
+
const movementSamples = [];
|
|
6105
|
+
let movementCursor = before;
|
|
4404
6106
|
const labeledSamples = [];
|
|
4405
6107
|
const heldKeys = /* @__PURE__ */ new Set();
|
|
4406
6108
|
let pointerButtons = 0;
|
|
4407
|
-
|
|
6109
|
+
let pointerCount = 0;
|
|
6110
|
+
for (const [index, step] of scenario.steps.entries()) {
|
|
6111
|
+
const framebufferAssertion = scenario.assert?.framebufferCoverage;
|
|
6112
|
+
if (target.name === "android" && framebufferAssertion !== void 0 && step.label === framebufferAssertion.window.startStep) {
|
|
6113
|
+
try {
|
|
6114
|
+
await target.driver.startScreenRecording?.();
|
|
6115
|
+
coverageRecordingStarted = true;
|
|
6116
|
+
await delay(100);
|
|
6117
|
+
} catch (error) {
|
|
6118
|
+
framebufferCoverage = unreadableCoverageObservation(error);
|
|
6119
|
+
}
|
|
6120
|
+
}
|
|
4408
6121
|
if (step.pointerPosition !== void 0) {
|
|
4409
6122
|
pointerButtons = step.pointerPosition.buttons ?? pointerButtons;
|
|
4410
6123
|
await transport.call("input.pointer", {
|
|
@@ -4414,42 +6127,100 @@ async function runDevicePlaytest(config, target) {
|
|
|
4414
6127
|
y: step.pointerPosition.y * scenario.viewport.height
|
|
4415
6128
|
});
|
|
4416
6129
|
}
|
|
4417
|
-
|
|
4418
|
-
|
|
4419
|
-
|
|
4420
|
-
await transport.call("input.keyUp", { key });
|
|
4421
|
-
heldKeys.delete(key);
|
|
4422
|
-
}
|
|
6130
|
+
if (step.pointers !== void 0) {
|
|
6131
|
+
await target.driver.setPointers?.(step.pointers);
|
|
6132
|
+
pointerCount = step.pointers.length;
|
|
4423
6133
|
}
|
|
4424
|
-
|
|
4425
|
-
|
|
4426
|
-
|
|
4427
|
-
|
|
6134
|
+
const pressed = step.press;
|
|
6135
|
+
if (typeof pressed === "string") {
|
|
6136
|
+
if (!heldKeys.has(pressed)) {
|
|
6137
|
+
await transport.call("input.keyDown", { key: pressed });
|
|
6138
|
+
heldKeys.add(pressed);
|
|
6139
|
+
}
|
|
6140
|
+
} else if (pressed !== void 0) {
|
|
6141
|
+
for (const key of [...heldKeys]) {
|
|
6142
|
+
if (!pressed.includes(key)) {
|
|
6143
|
+
await transport.call("input.keyUp", { key });
|
|
6144
|
+
heldKeys.delete(key);
|
|
6145
|
+
}
|
|
6146
|
+
}
|
|
6147
|
+
for (const key of pressed) {
|
|
6148
|
+
if (!heldKeys.has(key)) {
|
|
6149
|
+
await transport.call("input.keyDown", { key });
|
|
6150
|
+
heldKeys.add(key);
|
|
6151
|
+
}
|
|
4428
6152
|
}
|
|
4429
6153
|
}
|
|
6154
|
+
const inputDriven = playtestStepDrivesMovement(
|
|
6155
|
+
step,
|
|
6156
|
+
heldKeys.size > 0 || pointerButtons !== 0 || pointerCount > 0
|
|
6157
|
+
);
|
|
6158
|
+
const movementBefore = capturesAnonymousMovement ? movementCursor : void 0;
|
|
4430
6159
|
const frames = Math.max(
|
|
4431
6160
|
1,
|
|
4432
6161
|
playtestStepHoldTicks(step, 0) + playtestStepWaitTicks(step),
|
|
4433
6162
|
(step.holdFrames ?? 0) + (step.waitFrames ?? 0)
|
|
4434
6163
|
);
|
|
4435
|
-
|
|
4436
|
-
|
|
6164
|
+
if (coverageRecordingStarted) {
|
|
6165
|
+
for (let frame = 0; frame < frames; frame += 1) {
|
|
6166
|
+
await bridge.advance(1);
|
|
6167
|
+
await delay(100);
|
|
6168
|
+
}
|
|
6169
|
+
} else {
|
|
6170
|
+
await bridge.advance(frames);
|
|
6171
|
+
}
|
|
6172
|
+
const afterInput = await bridge.sample(sampleRequest);
|
|
6173
|
+
appendPosition(pathPositions, afterInput, pathEntity);
|
|
6174
|
+
if (movementBefore !== void 0) {
|
|
6175
|
+
movementSamples.push({ after: afterInput, before: movementBefore, inputDriven });
|
|
6176
|
+
}
|
|
6177
|
+
let afterStep = afterInput;
|
|
4437
6178
|
if (step.label !== void 0) {
|
|
4438
|
-
const snapshot = await bridge.sample(sampleRequest);
|
|
6179
|
+
const snapshot = await bridge.sample({ ...sampleRequest, label: step.label });
|
|
4439
6180
|
const signals = bridge.description.capabilities.includes("runtime.events") ? await bridge.drainEvents() : [];
|
|
4440
6181
|
labeledSamples.push({ label: step.label, signals, snapshot });
|
|
4441
6182
|
}
|
|
4442
6183
|
if (step.screenshot !== void 0) {
|
|
4443
6184
|
await target.driver.screenshot(join(config.artifactDirectory, `${safePart2(step.screenshot)}.png`));
|
|
4444
6185
|
}
|
|
4445
|
-
if (step.release) {
|
|
4446
|
-
|
|
6186
|
+
if (step.release && pressed !== void 0) {
|
|
6187
|
+
const released = typeof pressed === "string" ? [pressed] : [...pressed];
|
|
6188
|
+
for (const key of released) {
|
|
4447
6189
|
await transport.call("input.keyUp", { key });
|
|
4448
6190
|
heldKeys.delete(key);
|
|
4449
6191
|
}
|
|
4450
|
-
if (
|
|
4451
|
-
|
|
4452
|
-
|
|
6192
|
+
if (index !== scenario.steps.length - 1) {
|
|
6193
|
+
await bridge.advance(1);
|
|
6194
|
+
if (capturesAnonymousMovement) afterStep = await bridge.sample(sampleRequest);
|
|
6195
|
+
}
|
|
6196
|
+
}
|
|
6197
|
+
if (step.pointerPosition?.buttons !== void 0 && step.release) {
|
|
6198
|
+
pointerButtons = 0;
|
|
6199
|
+
await transport.call("input.pointer", { buttons: 0, type: "up", x: 0, y: 0 });
|
|
6200
|
+
}
|
|
6201
|
+
if (step.pointers !== void 0 && step.release) {
|
|
6202
|
+
await target.driver.setPointers?.([]);
|
|
6203
|
+
pointerCount = 0;
|
|
6204
|
+
await bridge.advance(1);
|
|
6205
|
+
if (capturesAnonymousMovement) afterStep = await bridge.sample(sampleRequest);
|
|
6206
|
+
}
|
|
6207
|
+
if (movementBefore !== void 0 && afterInput !== void 0 && afterStep !== afterInput) {
|
|
6208
|
+
movementSamples.push({ after: afterStep, before: afterInput, inputDriven: false });
|
|
6209
|
+
}
|
|
6210
|
+
if (capturesAnonymousMovement) movementCursor = afterStep;
|
|
6211
|
+
if (coverageRecordingStarted && target.name === "android" && framebufferAssertion !== void 0 && step.label === framebufferAssertion.window.endStep) {
|
|
6212
|
+
try {
|
|
6213
|
+
await target.driver.stopScreenRecording?.(coverageVideoPath);
|
|
6214
|
+
coverageRecordingStarted = false;
|
|
6215
|
+
framebufferCoverage = await analyzeFramebufferCoverageRecording(
|
|
6216
|
+
coverageVideoPath,
|
|
6217
|
+
config.artifactDirectory,
|
|
6218
|
+
framebufferAssertion,
|
|
6219
|
+
"scenario-steps"
|
|
6220
|
+
);
|
|
6221
|
+
} catch (error) {
|
|
6222
|
+
coverageRecordingStarted = false;
|
|
6223
|
+
framebufferCoverage = unreadableCoverageObservation(error);
|
|
4453
6224
|
}
|
|
4454
6225
|
}
|
|
4455
6226
|
}
|
|
@@ -4466,13 +6237,6 @@ async function runDevicePlaytest(config, target) {
|
|
|
4466
6237
|
), target.name);
|
|
4467
6238
|
}
|
|
4468
6239
|
const consoleEntries = await target.driver.captureConsole();
|
|
4469
|
-
if (consoleEntries.some(({ type }) => type === "error" || type === "pageerror")) {
|
|
4470
|
-
return failureReport2(config, scenario, playtestDiagnostic(
|
|
4471
|
-
"TN_PLAYTEST_DEVICE_FAILED",
|
|
4472
|
-
`${targetLabel(target.name)} logs contained a runtime error before assertions were evaluated.`,
|
|
4473
|
-
`Inspect ${target.name === "android" ? "logcat" : "unified logs"}, fix the first native or JavaScript error, then rerun the same scenario.`
|
|
4474
|
-
), target.name);
|
|
4475
|
-
}
|
|
4476
6240
|
const report = buildReport(
|
|
4477
6241
|
config,
|
|
4478
6242
|
scenario,
|
|
@@ -4484,8 +6248,17 @@ async function runDevicePlaytest(config, target) {
|
|
|
4484
6248
|
{},
|
|
4485
6249
|
true,
|
|
4486
6250
|
void 0,
|
|
4487
|
-
labeledSamples
|
|
6251
|
+
labeledSamples,
|
|
6252
|
+
framebufferCoverage,
|
|
6253
|
+
void 0,
|
|
6254
|
+
void 0,
|
|
6255
|
+
movementSamples
|
|
4488
6256
|
);
|
|
6257
|
+
await writeObservationArtifacts(config.artifactDirectory, scenario.artifacts, {
|
|
6258
|
+
console: consoleEntries,
|
|
6259
|
+
network: [],
|
|
6260
|
+
runtimeTrace: void 0
|
|
6261
|
+
});
|
|
4489
6262
|
return { ...report, runtime: "native", target: target.name, url: endpoint };
|
|
4490
6263
|
} catch (error) {
|
|
4491
6264
|
if (error instanceof PlaytestBridgeError) {
|
|
@@ -4493,6 +6266,9 @@ async function runDevicePlaytest(config, target) {
|
|
|
4493
6266
|
}
|
|
4494
6267
|
throw error;
|
|
4495
6268
|
} finally {
|
|
6269
|
+
if (target.name === "android" && scenario.steps.some((step) => step.pointers !== void 0)) {
|
|
6270
|
+
await target.driver.setPointers?.([]).catch(() => void 0);
|
|
6271
|
+
}
|
|
4496
6272
|
await target.driver.stop().catch(() => void 0);
|
|
4497
6273
|
await bridge?.close().catch(() => void 0);
|
|
4498
6274
|
await transport.close().catch(() => void 0);
|
|
@@ -4513,6 +6289,14 @@ function isMailboxDriver(driver) {
|
|
|
4513
6289
|
return typeof driver.readFile === "function" && typeof driver.removeFile === "function" && typeof driver.writeFile === "function";
|
|
4514
6290
|
}
|
|
4515
6291
|
function unsupportedAssertion(scenario, target) {
|
|
6292
|
+
const hasMultiPointerInput = scenario.steps.some((step) => step.pointers !== void 0);
|
|
6293
|
+
if (hasMultiPointerInput && target === "ios") {
|
|
6294
|
+
return unsupportedDiagnostic(
|
|
6295
|
+
"complete held-pointer input",
|
|
6296
|
+
"Run this scenario on --target browser or --target android; iOS multi-pointer injection is not implemented.",
|
|
6297
|
+
target
|
|
6298
|
+
);
|
|
6299
|
+
}
|
|
4516
6300
|
if (scenario.assert?.diagnostics?.noNetworkErrors === true) {
|
|
4517
6301
|
return unsupportedDiagnostic(
|
|
4518
6302
|
"network assertions",
|
|
@@ -4534,6 +6318,13 @@ function unsupportedAssertion(scenario, target) {
|
|
|
4534
6318
|
target
|
|
4535
6319
|
);
|
|
4536
6320
|
}
|
|
6321
|
+
if (scenario.assert?.framebufferCoverage !== void 0 && target === "ios") {
|
|
6322
|
+
return unsupportedDiagnostic(
|
|
6323
|
+
"framebuffer coverage recording",
|
|
6324
|
+
"Run this assertion on --target browser or --target android; the iOS transport has no per-frame recorder observer.",
|
|
6325
|
+
target
|
|
6326
|
+
);
|
|
6327
|
+
}
|
|
4537
6328
|
return void 0;
|
|
4538
6329
|
}
|
|
4539
6330
|
function unsupportedDiagnostic(subject, fix, target) {
|
|
@@ -4545,9 +6336,12 @@ function unsupportedDiagnostic(subject, fix, target) {
|
|
|
4545
6336
|
}
|
|
4546
6337
|
function failureReport2(config, scenario, diagnostic2, target) {
|
|
4547
6338
|
const item = { ...diagnostic2, suggestion: diagnostic2.fix.instruction };
|
|
6339
|
+
const diagnosticsPolicy = resolveDiagnosticsPolicy(scenario.assert?.diagnostics);
|
|
4548
6340
|
return {
|
|
4549
6341
|
artifactDirectory: config.artifactDirectory,
|
|
6342
|
+
assertionResults: [failedDiagnosticsAssertion(diagnosticsPolicy)],
|
|
4550
6343
|
diagnostics: [item],
|
|
6344
|
+
diagnosticsPolicy,
|
|
4551
6345
|
distance: 0,
|
|
4552
6346
|
entity: scenario.subject ?? "",
|
|
4553
6347
|
expectMoved: false,
|
|
@@ -4584,13 +6378,15 @@ function setupRequest2(scenario) {
|
|
|
4584
6378
|
};
|
|
4585
6379
|
}
|
|
4586
6380
|
function observedEntityIds2(scenario) {
|
|
4587
|
-
return
|
|
6381
|
+
if (scenario.assert?.movement !== void 0 && scenario.assert.movement.entity === void 0 && scenario.subject === void 0) return void 0;
|
|
6382
|
+
const ids = [...new Set([
|
|
4588
6383
|
scenario.subject,
|
|
4589
6384
|
scenario.assert?.movement?.entity,
|
|
4590
6385
|
scenario.assert?.camera?.entity,
|
|
4591
6386
|
scenario.assert?.camera?.follows,
|
|
4592
6387
|
...(scenario.assert?.visibility ?? []).map(({ entity }) => entity)
|
|
4593
6388
|
].filter((value) => value !== void 0))];
|
|
6389
|
+
return ids.length > 0 ? ids : scenario.assert?.movement === void 0 ? [] : void 0;
|
|
4594
6390
|
}
|
|
4595
6391
|
function observedResourceIds2(scenario) {
|
|
4596
6392
|
return [.../* @__PURE__ */ new Set([
|
|
@@ -4616,14 +6412,26 @@ function accumulatedPathLength2(positions) {
|
|
|
4616
6412
|
function safePart2(value) {
|
|
4617
6413
|
return value.replace(/[^A-Za-z0-9._-]+/g, "-");
|
|
4618
6414
|
}
|
|
4619
|
-
|
|
6415
|
+
function unreadableCoverageObservation(error) {
|
|
6416
|
+
return {
|
|
6417
|
+
boundarySource: "scenario-steps",
|
|
6418
|
+
frameCount: 0,
|
|
6419
|
+
unreadableReason: error instanceof Error ? error.message : String(error),
|
|
6420
|
+
windowCompleted: false,
|
|
6421
|
+
windowStarted: false
|
|
6422
|
+
};
|
|
6423
|
+
}
|
|
6424
|
+
function delay(milliseconds) {
|
|
6425
|
+
return new Promise((resolve6) => setTimeout(resolve6, milliseconds));
|
|
6426
|
+
}
|
|
6427
|
+
var execFileAsync3 = promisify(execFile);
|
|
4620
6428
|
var XcrunIosDriver = class {
|
|
4621
6429
|
constructor(options, run) {
|
|
4622
6430
|
this.options = options;
|
|
4623
6431
|
const xcrun = options.xcrunPath ?? "xcrun";
|
|
4624
6432
|
this.run = run ?? (async (args, commandOptions = {}) => {
|
|
4625
6433
|
try {
|
|
4626
|
-
const { stdout } = await
|
|
6434
|
+
const { stdout } = await execFileAsync3(xcrun, [...args], {
|
|
4627
6435
|
encoding: "utf8",
|
|
4628
6436
|
env: commandOptions.env ?? process.env,
|
|
4629
6437
|
maxBuffer: 16 * 1024 * 1024
|
|
@@ -4686,7 +6494,7 @@ var XcrunIosDriver = class {
|
|
|
4686
6494
|
if (this.pid === void 0) return false;
|
|
4687
6495
|
try {
|
|
4688
6496
|
if (this.options.transport === "simulator") {
|
|
4689
|
-
|
|
6497
|
+
process.kill(Number(this.pid), 0);
|
|
4690
6498
|
} else {
|
|
4691
6499
|
const output = await this.run(["devicectl", "device", "info", "processes", "--device", this.device()]);
|
|
4692
6500
|
if (!new RegExp(`\\b${this.pid}\\b`, "u").test(output)) return false;
|
|
@@ -5087,7 +6895,15 @@ function recordToScenario(value, scenarioPath = "recording.json", oracleValue) {
|
|
|
5087
6895
|
// src/runner/cli.ts
|
|
5088
6896
|
function exitCodeForReport(report) {
|
|
5089
6897
|
if (report.pass) return 0;
|
|
5090
|
-
|
|
6898
|
+
if (report.diagnostics?.some(({ code }) => code === "TN_PLAYTEST_FRAMEBUFFER_WINDOW_NOT_REACHED")) return 2;
|
|
6899
|
+
if (report.assertionResults === void 0 || report.assertionResults.every(isUnobservedDiagnosticsAssertion)) return 2;
|
|
6900
|
+
return 1;
|
|
6901
|
+
}
|
|
6902
|
+
function isUnobservedDiagnosticsAssertion(value) {
|
|
6903
|
+
if (typeof value !== "object" || value === null) return false;
|
|
6904
|
+
const assertion = value;
|
|
6905
|
+
if (assertion.id !== "diagnostics" || typeof assertion.details !== "object" || assertion.details === null) return false;
|
|
6906
|
+
return assertion.details.reason === "not-evaluated";
|
|
5091
6907
|
}
|
|
5092
6908
|
function classifyRunnerError(error, options = {}) {
|
|
5093
6909
|
if (error instanceof PlaytestCliUsageError) {
|
|
@@ -5212,8 +7028,9 @@ function scenarioUnreadable(message, options) {
|
|
|
5212
7028
|
);
|
|
5213
7029
|
}
|
|
5214
7030
|
var entryPath = process.argv[1];
|
|
5215
|
-
if (entryPath !== void 0 && resolve(entryPath) === fileURLToPath(import.meta.url)) {
|
|
5216
|
-
await main();
|
|
7031
|
+
if (entryPath !== void 0 && existsSync(entryPath) && realpathSync(resolve(entryPath)) === realpathSync(fileURLToPath(import.meta.url))) {
|
|
7032
|
+
const code = await main();
|
|
7033
|
+
process.exit(code);
|
|
5217
7034
|
}
|
|
5218
7035
|
|
|
5219
7036
|
export { classifyRunnerError, exitCodeForReport, main };
|