@threenative/playtest 0.3.4 → 0.3.5
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/README.md +40 -2
- package/dist/capture.d.ts +23 -1
- package/dist/capture.js +92 -2
- package/dist/{diagnostics-BXhYI2sc.d.ts → diagnostics-BhS6v2n1.d.ts} +17 -748
- package/dist/index.d.ts +5 -3
- package/dist/index.js +1693 -108
- package/dist/protocol.d.ts +43 -2
- package/dist/protocol.js +10 -1
- package/dist/runner/cli.d.ts +4 -2
- package/dist/runner/cli.js +10971 -8510
- package/dist/runner/index.d.ts +101 -83
- package/dist/runner/index.js +11952 -9964
- package/dist/schema-base-B5mr_Yr9.d.ts +844 -0
- package/dist/{shared-CHIDDJpp.d.ts → shared-DK12BZyS.d.ts} +171 -3
- package/dist/three/index.d.ts +9 -1
- package/dist/three/index.js +94 -27
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -43,7 +43,9 @@ npx @threenative/playtest playtests/device-smoke.playtest.json \
|
|
|
43
43
|
|
|
44
44
|
The native host receives the mailbox root through `TN_PLAYTEST_MAILBOX_ROOT` and injects the
|
|
45
45
|
shared `TN_PLAYTEST_MAILBOX` global before evaluating the game entry, so the game source is
|
|
46
|
-
unchanged.
|
|
46
|
+
unchanged. `--live-clock` on the desktop target also passes `TN_PLAYTEST_CLOCK=wall-clock`, which
|
|
47
|
+
the host reads before that same entry. On Linux without a display, prefix the command with
|
|
48
|
+
`sh scripts/xvfb.sh`.
|
|
47
49
|
|
|
48
50
|
An iOS simulator run installs a built app, launches it with `simctl`, and
|
|
49
51
|
uses the app data-container mailbox:
|
|
@@ -55,7 +57,7 @@ npx @threenative/playtest playtests/device-smoke.playtest.json \
|
|
|
55
57
|
```
|
|
56
58
|
|
|
57
59
|
For a signed physical build, add `--ios-transport device --device <devicectl-id>`.
|
|
58
|
-
Network, DOM, and visual
|
|
60
|
+
Network, DOM, and `assert.visual` assertions are unsupported on device targets and fail
|
|
59
61
|
`TN_PLAYTEST_UNSUPPORTED_ON_TARGET` with exit code 2. Default CI does not run Android or
|
|
60
62
|
iOS device scenarios. `.github/workflows/native-platforms.yml` is an explicit opt-in
|
|
61
63
|
platform lane; an absent run is not a pass.
|
|
@@ -68,3 +70,39 @@ entity, an absent resource, an empty effect log, or a scenario with no
|
|
|
68
70
|
assertions at all is a failure, never a silent pass. Wrong-typed assertion
|
|
69
71
|
values are rejected when the scenario loads rather than dropped, so a scenario
|
|
70
72
|
cannot quietly run with fewer checks than its author wrote.
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
## Tone gates and offline inspection
|
|
76
|
+
|
|
77
|
+
`npx @threenative/playtest tone shot.png other.png` prints tab-separated rows for mean, p1, p50,
|
|
78
|
+
p99, clip%, black%, plus an unweighted frame-average row. No browser is started. Empty input,
|
|
79
|
+
unreadable PNGs and images without visible pixels exit 2 without a partial table.
|
|
80
|
+
|
|
81
|
+
```json
|
|
82
|
+
{ "assert": { "tone": [{ "atStep": "landed", "mean": { "min": 60, "max": 140 }, "p99": { "min": 150 }, "clipFraction": { "max": 0.005 } }] } }
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
`atStep` selects a named step; omission selects the final capture. Every metric takes inclusive
|
|
86
|
+
min/max bounds. Empty arrays, empty bounds, non-finite/out-of-range numbers, unknown keys and
|
|
87
|
+
reversed ranges fail at load. Missing capture evidence fails TN_PLAYTEST_TONE_UNOBSERVED.
|
|
88
|
+
Failed bounds name the measured and required values.
|
|
89
|
+
|
|
90
|
+
All six metrics use the capture guard's existing PNG decode without downsampling: rounded
|
|
91
|
+
Rec.709 display luminance fills 256 bins; mean averages bin values and percentiles use nearest
|
|
92
|
+
rank. Clip/black fractions count bins 255/0 and use 0..1 in assertions (percentages in the CLI).
|
|
93
|
+
Fully transparent pixels are excluded; other pixels retain stored RGB without compositing.
|
|
94
|
+
These numbers measure exposure, not aesthetic quality.
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
Browser, Android, desktop and iOS scenario captures now record TN_TONE under observations.tone,
|
|
98
|
+
even without tone assertions. Explicit tone requests force their captures despite disabled
|
|
99
|
+
convenience screenshots. A named step's existing screenshot is reused. This host-side support
|
|
100
|
+
is exercised with target-driver fixtures; it does not turn unit tests into native GPU proof.
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
Repository runtime proof: `pnpm test:tone` builds the isolated calibration fixture and captures
|
|
104
|
+
its real WebGPU output at exposure 0.25 and 1. The same assertions must fail then pass. PNGs,
|
|
105
|
+
observations, reports and adapter provenance are retained under `artifacts/tone-exposure`; the
|
|
106
|
+
summary names the exact source SHA. It also runs after `pnpm test:templates`. The maintained
|
|
107
|
+
`integration-tone` workflow permits software WebGPU for pixel correctness only, not native
|
|
108
|
+
execution, hardware performance or aesthetic qualification.
|
package/dist/capture.d.ts
CHANGED
|
@@ -1,15 +1,22 @@
|
|
|
1
|
+
import { I as IToneMetrics, a as IPlaytestToneAssertion, b as IPlaytestRegionalToneObservation } from './schema-base-B5mr_Yr9.js';
|
|
2
|
+
import './protocol.js';
|
|
3
|
+
|
|
1
4
|
declare const CAPTURE_GUARD_LIMITS: {
|
|
2
5
|
readonly brightLuminance: 0.05;
|
|
6
|
+
readonly contentLuminanceDelta: 0.1;
|
|
3
7
|
readonly darkFrameMinDistinctColors: 32;
|
|
4
8
|
readonly darkFrameMaxLuminance: 0.5;
|
|
5
9
|
readonly darkFrameMinLuminanceStdDev: 0.02;
|
|
10
|
+
readonly desktopMinContentRatio: 0.001;
|
|
6
11
|
readonly minBrightPixelRatio: 0.05;
|
|
7
12
|
readonly minDistinctColors: 8;
|
|
8
13
|
readonly minLuminanceStdDev: 0.01;
|
|
9
14
|
};
|
|
10
15
|
interface ICaptureFrameStats {
|
|
16
|
+
readonly tone?: IToneMetrics;
|
|
11
17
|
readonly distinctColors: number;
|
|
12
18
|
readonly brightPixelRatio: number;
|
|
19
|
+
readonly contentRatio: number;
|
|
13
20
|
readonly height: number;
|
|
14
21
|
readonly luminanceStdDev: number;
|
|
15
22
|
readonly maxLuminance: number;
|
|
@@ -43,6 +50,14 @@ declare function inspectFrame(png: Buffer): ICaptureFrameStats;
|
|
|
43
50
|
* @example assertCaptureNotBlank(png, "first frame");
|
|
44
51
|
*/
|
|
45
52
|
declare function assertCaptureNotBlank(png: Buffer, label: string): ICaptureFrameStats;
|
|
53
|
+
/**
|
|
54
|
+
* Fail closed when a desktop-host frame shows no rendered content.
|
|
55
|
+
* A native desktop frame has no HTML overlay, so the browser bright-pixel floor does not apply.
|
|
56
|
+
* @situation guard a native desktop capture of a 3D scene
|
|
57
|
+
* @constraint keeps the uniform-frame checks and replaces only the bright-pixel floor
|
|
58
|
+
* @example assertDesktopCaptureNotBlank(png, "panned-culled.png");
|
|
59
|
+
*/
|
|
60
|
+
declare function assertDesktopCaptureNotBlank(png: Buffer, label: string): ICaptureFrameStats;
|
|
46
61
|
/**
|
|
47
62
|
* Fail closed when a screenshot is blank or uniform.
|
|
48
63
|
* @situation guard a visual playtest against a blank frame
|
|
@@ -51,5 +66,12 @@ declare function assertCaptureNotBlank(png: Buffer, label: string): ICaptureFram
|
|
|
51
66
|
* @example assertFrameShowsSomething(png, "first frame");
|
|
52
67
|
*/
|
|
53
68
|
declare const assertFrameShowsSomething: typeof assertCaptureNotBlank;
|
|
69
|
+
/**
|
|
70
|
+
* Collect opt-in regional tone observations from the same acquired PNG.
|
|
71
|
+
* @situation measure a specified pixel crop in a captured playtest frame
|
|
72
|
+
* @constraint does not acquire another screenshot or alter frame timing
|
|
73
|
+
* @example collectRegionalTone(png, assertions, "character", "posed");
|
|
74
|
+
*/
|
|
75
|
+
declare function collectRegionalTone(png: Buffer, assertions: readonly IPlaytestToneAssertion[], label: string, atStep?: string): IPlaytestRegionalToneObservation[];
|
|
54
76
|
|
|
55
|
-
export { CAPTURE_GUARD_LIMITS, CaptureGuardError, type ICaptureFrameStats, assertCaptureNotBlank, assertFrameShowsSomething, inspectFrame };
|
|
77
|
+
export { CAPTURE_GUARD_LIMITS, CaptureGuardError, type ICaptureFrameStats, assertCaptureNotBlank, assertDesktopCaptureNotBlank, assertFrameShowsSomething, collectRegionalTone, inspectFrame };
|
package/dist/capture.js
CHANGED
|
@@ -3,9 +3,14 @@ import { PNG } from 'pngjs';
|
|
|
3
3
|
|
|
4
4
|
var CAPTURE_GUARD_LIMITS = {
|
|
5
5
|
brightLuminance: 0.05,
|
|
6
|
+
contentLuminanceDelta: 0.1,
|
|
7
|
+
// Count content at least 10% luminance away from the modal clear-color bin.
|
|
6
8
|
darkFrameMinDistinctColors: 32,
|
|
7
9
|
darkFrameMaxLuminance: 0.5,
|
|
8
10
|
darkFrameMinLuminanceStdDev: 0.02,
|
|
11
|
+
// Native content: before 0.073214, centered 0.068491, pan 0.004435, cull-off 0.007173, startup 0.015981–0.016013.
|
|
12
|
+
desktopMinContentRatio: 1e-3,
|
|
13
|
+
// Lowest native frame clears this floor by 4.43x; uniform content is 0.
|
|
9
14
|
minBrightPixelRatio: 0.05,
|
|
10
15
|
minDistinctColors: 8,
|
|
11
16
|
minLuminanceStdDev: 0.01
|
|
@@ -24,8 +29,12 @@ var CaptureGuardError = class extends Error {
|
|
|
24
29
|
code = "TN_CAPTURE_BLANK";
|
|
25
30
|
};
|
|
26
31
|
function inspectFrame(png) {
|
|
27
|
-
|
|
32
|
+
return inspectDecodedFrame(PNG.sync.read(png));
|
|
33
|
+
}
|
|
34
|
+
function inspectDecodedFrame(image) {
|
|
28
35
|
const colors = /* @__PURE__ */ new Set();
|
|
36
|
+
const histogram = new Uint32Array(256);
|
|
37
|
+
let toneTotal = 0;
|
|
29
38
|
let luminanceTotal = 0;
|
|
30
39
|
let luminanceSquaredTotal = 0;
|
|
31
40
|
let brightPixels = 0;
|
|
@@ -39,6 +48,9 @@ function inspectFrame(png) {
|
|
|
39
48
|
colors.add((red << 24 | green << 16 | blue << 8 | alpha) >>> 0);
|
|
40
49
|
if (alpha === 0) continue;
|
|
41
50
|
const luminance = (0.2126 * red + 0.7152 * green + 0.0722 * blue) / 255;
|
|
51
|
+
const bin = Math.round(luminance * 255);
|
|
52
|
+
histogram[bin] = (histogram[bin] ?? 0) + 1;
|
|
53
|
+
toneTotal += bin;
|
|
42
54
|
visiblePixels += 1;
|
|
43
55
|
maxLuminance = Math.max(maxLuminance, luminance);
|
|
44
56
|
if (luminance > CAPTURE_GUARD_LIMITS.brightLuminance) brightPixels += 1;
|
|
@@ -47,9 +59,37 @@ function inspectFrame(png) {
|
|
|
47
59
|
}
|
|
48
60
|
const mean = visiblePixels === 0 ? 0 : luminanceTotal / visiblePixels;
|
|
49
61
|
const variance = visiblePixels === 0 ? 0 : luminanceSquaredTotal / visiblePixels - mean * mean;
|
|
62
|
+
let modalBin = 0;
|
|
63
|
+
for (let bin = 1; bin < histogram.length; bin += 1) {
|
|
64
|
+
if ((histogram[bin] ?? 0) > (histogram[modalBin] ?? 0)) modalBin = bin;
|
|
65
|
+
}
|
|
66
|
+
let contentPixels = 0;
|
|
67
|
+
for (let bin = 0; bin < histogram.length; bin += 1) {
|
|
68
|
+
if (Math.abs(bin - modalBin) / 255 >= CAPTURE_GUARD_LIMITS.contentLuminanceDelta) {
|
|
69
|
+
contentPixels += histogram[bin] ?? 0;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
const percentile = (fraction) => {
|
|
73
|
+
const rank = Math.ceil(visiblePixels * fraction);
|
|
74
|
+
let count = 0;
|
|
75
|
+
for (let bin = 0; bin < histogram.length; bin += 1) {
|
|
76
|
+
count += histogram[bin] ?? 0;
|
|
77
|
+
if (count >= rank) return bin;
|
|
78
|
+
}
|
|
79
|
+
return 255;
|
|
80
|
+
};
|
|
50
81
|
return {
|
|
82
|
+
...visiblePixels === 0 ? {} : { tone: {
|
|
83
|
+
mean: toneTotal / visiblePixels,
|
|
84
|
+
p1: percentile(0.01),
|
|
85
|
+
p50: percentile(0.5),
|
|
86
|
+
p99: percentile(0.99),
|
|
87
|
+
clipFraction: (histogram[255] ?? 0) / visiblePixels,
|
|
88
|
+
blackFraction: (histogram[0] ?? 0) / visiblePixels
|
|
89
|
+
} },
|
|
51
90
|
distinctColors: colors.size,
|
|
52
91
|
brightPixelRatio: image.data.length === 0 ? 0 : brightPixels / (image.data.length / 4),
|
|
92
|
+
contentRatio: image.data.length === 0 ? 0 : contentPixels / (image.data.length / 4),
|
|
53
93
|
height: image.height,
|
|
54
94
|
luminanceStdDev: Math.sqrt(Math.max(0, variance)),
|
|
55
95
|
maxLuminance,
|
|
@@ -57,6 +97,12 @@ function inspectFrame(png) {
|
|
|
57
97
|
};
|
|
58
98
|
}
|
|
59
99
|
function assertCaptureNotBlank(png, label) {
|
|
100
|
+
return assertCaptureSurface(png, label, "browser");
|
|
101
|
+
}
|
|
102
|
+
function assertDesktopCaptureNotBlank(png, label) {
|
|
103
|
+
return assertCaptureSurface(png, label, "desktop");
|
|
104
|
+
}
|
|
105
|
+
function assertCaptureSurface(png, label, target) {
|
|
60
106
|
const stats = inspectFrame(png);
|
|
61
107
|
if (stats.distinctColors < CAPTURE_GUARD_LIMITS.minDistinctColors) {
|
|
62
108
|
throw new CaptureGuardError(
|
|
@@ -72,6 +118,16 @@ function assertCaptureNotBlank(png, label) {
|
|
|
72
118
|
stats
|
|
73
119
|
);
|
|
74
120
|
}
|
|
121
|
+
if (target === "desktop") {
|
|
122
|
+
if (!(stats.contentRatio >= CAPTURE_GUARD_LIMITS.desktopMinContentRatio)) {
|
|
123
|
+
throw new CaptureGuardError(
|
|
124
|
+
label,
|
|
125
|
+
`content ratio ${stats.contentRatio.toFixed(5)} is below ${CAPTURE_GUARD_LIMITS.desktopMinContentRatio}`,
|
|
126
|
+
stats
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
return stats;
|
|
130
|
+
}
|
|
75
131
|
const hasDarkFrameVariation = stats.distinctColors >= CAPTURE_GUARD_LIMITS.darkFrameMinDistinctColors && stats.luminanceStdDev >= CAPTURE_GUARD_LIMITS.darkFrameMinLuminanceStdDev && stats.maxLuminance <= CAPTURE_GUARD_LIMITS.darkFrameMaxLuminance;
|
|
76
132
|
if (stats.brightPixelRatio < CAPTURE_GUARD_LIMITS.minBrightPixelRatio && !hasDarkFrameVariation) {
|
|
77
133
|
throw new CaptureGuardError(
|
|
@@ -83,5 +139,39 @@ function assertCaptureNotBlank(png, label) {
|
|
|
83
139
|
return stats;
|
|
84
140
|
}
|
|
85
141
|
var assertFrameShowsSomething = assertCaptureNotBlank;
|
|
142
|
+
function collectRegionalTone(png, assertions, label, atStep) {
|
|
143
|
+
const selected = [];
|
|
144
|
+
for (const [assertionIndex, assertion] of assertions.entries())
|
|
145
|
+
if (assertion.region !== void 0 && assertion.atStep === atStep)
|
|
146
|
+
selected.push({ assertion, assertionIndex });
|
|
147
|
+
if (selected.length === 0) return [];
|
|
148
|
+
const image = PNG.sync.read(png);
|
|
149
|
+
const measure = (region) => {
|
|
150
|
+
if (![region.x, region.y, region.width, region.height].every(Number.isSafeInteger) || region.x < 0 || region.y < 0 || region.width <= 0 || region.height <= 0 || region.width > image.width - region.x || region.height > image.height - region.y)
|
|
151
|
+
return { error: "Tone region is outside decoded PNG bounds or invalid." };
|
|
152
|
+
const cropped = new PNG({ width: region.width, height: region.height });
|
|
153
|
+
for (let y = 0; y < region.height; y++) {
|
|
154
|
+
const offset = ((region.y + y) * image.width + region.x) * 4;
|
|
155
|
+
image.data.copy(cropped.data, y * region.width * 4, offset, offset + region.width * 4);
|
|
156
|
+
}
|
|
157
|
+
const metrics = inspectDecodedFrame(cropped).tone;
|
|
158
|
+
return metrics === void 0 ? { error: "Tone region contains no visible pixels." } : { metrics };
|
|
159
|
+
};
|
|
160
|
+
return selected.map(({ assertion, assertionIndex }) => {
|
|
161
|
+
const region = assertion.region;
|
|
162
|
+
const measured = measure(region);
|
|
163
|
+
const reference = assertion.compare === void 0 ? void 0 : { region: assertion.compare.region, ...measure(assertion.compare.region) };
|
|
164
|
+
return {
|
|
165
|
+
code: "TN_TONE",
|
|
166
|
+
label,
|
|
167
|
+
...atStep === void 0 ? {} : { atStep },
|
|
168
|
+
assertionIndex,
|
|
169
|
+
region,
|
|
170
|
+
...measured.metrics,
|
|
171
|
+
...measured.error === void 0 ? {} : { error: measured.error },
|
|
172
|
+
...reference === void 0 ? {} : { reference }
|
|
173
|
+
};
|
|
174
|
+
});
|
|
175
|
+
}
|
|
86
176
|
|
|
87
|
-
export { CAPTURE_GUARD_LIMITS, CaptureGuardError, assertCaptureNotBlank, assertFrameShowsSomething, inspectFrame };
|
|
177
|
+
export { CAPTURE_GUARD_LIMITS, CaptureGuardError, assertCaptureNotBlank, assertDesktopCaptureNotBlank, assertFrameShowsSomething, collectRegionalTone, inspectFrame };
|