@threenative/playtest 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 João Paulo Furtado
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -23,10 +23,29 @@ npx @threenative/playtest playtests/movement.playtest.json \
23
23
  --browser-arg --enable-features=Vulkan
24
24
  ```
25
25
 
26
- ## Device targets
26
+ ## Doctor
27
27
 
28
- The same scenario format runs through `--target browser`, `--target android`, or
29
- `--target ios`. An iOS simulator run installs a built app, launches it with `simctl`, and
28
+ ```sh
29
+ npx @threenative/playtest doctor --text # can this machine run a playtest?
30
+ npx @threenative/playtest doctor --url <url> --text # and what is in the game running there
31
+ ```
32
+
33
+ ## Native targets
34
+
35
+ The same scenario format runs through `--target browser`, `--target android`, `--target desktop`,
36
+ or `--target ios`. A desktop run launches a caller-supplied packaged native game executable,
37
+ creates a temporary local mailbox, and removes it with the child process when the run ends:
38
+
39
+ ```bash
40
+ npx @threenative/playtest playtests/device-smoke.playtest.json \
41
+ --target desktop --executable .threenative/build/ThreeNative
42
+ ```
43
+
44
+ The native host receives the mailbox root through `TN_PLAYTEST_MAILBOX_ROOT` and injects the
45
+ shared `TN_PLAYTEST_MAILBOX` global before evaluating the game entry, so the game source is
46
+ unchanged. On Linux without a display, prefix the command with `sh scripts/xvfb.sh`.
47
+
48
+ An iOS simulator run installs a built app, launches it with `simctl`, and
30
49
  uses the app data-container mailbox:
31
50
 
32
51
  ```bash
@@ -0,0 +1,48 @@
1
+ declare const CAPTURE_GUARD_LIMITS: {
2
+ readonly brightLuminance: 0.05;
3
+ readonly darkFrameMinDistinctColors: 32;
4
+ readonly darkFrameMaxLuminance: 0.5;
5
+ readonly darkFrameMinLuminanceStdDev: 0.02;
6
+ readonly minBrightPixelRatio: 0.05;
7
+ readonly minDistinctColors: 8;
8
+ readonly minLuminanceStdDev: 0.01;
9
+ };
10
+ interface ICaptureFrameStats {
11
+ readonly distinctColors: number;
12
+ readonly brightPixelRatio: number;
13
+ readonly height: number;
14
+ readonly luminanceStdDev: number;
15
+ readonly maxLuminance: number;
16
+ readonly width: number;
17
+ }
18
+ /**
19
+ * Explain why a captured frame failed the non-blank guard.
20
+ * @situation fail a visual test when the rendered frame is blank
21
+ * @situation include capture statistics in a playtest error
22
+ * @example throw new CaptureGuardError("menu", "no bright pixels");
23
+ */
24
+ declare class CaptureGuardError extends Error {
25
+ readonly label: string;
26
+ readonly reason: string;
27
+ readonly stats?: ICaptureFrameStats | undefined;
28
+ readonly code = "TN_CAPTURE_BLANK";
29
+ constructor(label: string, reason: string, stats?: ICaptureFrameStats | undefined);
30
+ }
31
+ /**
32
+ * Inspect a PNG frame for visible pixels and luminance variation.
33
+ * @situation measure whether a screenshot contains a rendered game
34
+ * @situation diagnose a uniform or blank capture
35
+ * @example const stats = inspectFrame(png);
36
+ */
37
+ declare function inspectFrame(png: Buffer): ICaptureFrameStats;
38
+ /**
39
+ * Fail closed when a screenshot is blank or uniform.
40
+ * @situation guard a visual playtest against a blank frame
41
+ * @situation prove a screenshot contains more than a loading surface
42
+ * @constraint the assertion throws instead of returning a false pass
43
+ * @example assertCaptureNotBlank(png, "first frame");
44
+ */
45
+ declare function assertCaptureNotBlank(png: Buffer, label: string): ICaptureFrameStats;
46
+ declare const assertFrameShowsSomething: typeof assertCaptureNotBlank;
47
+
48
+ export { CAPTURE_GUARD_LIMITS, CaptureGuardError, type ICaptureFrameStats, assertCaptureNotBlank, assertFrameShowsSomething, inspectFrame };
@@ -0,0 +1,87 @@
1
+ #!/usr/bin/env node
2
+ import { PNG } from 'pngjs';
3
+
4
+ var CAPTURE_GUARD_LIMITS = {
5
+ brightLuminance: 0.05,
6
+ darkFrameMinDistinctColors: 32,
7
+ darkFrameMaxLuminance: 0.5,
8
+ darkFrameMinLuminanceStdDev: 0.02,
9
+ minBrightPixelRatio: 0.05,
10
+ minDistinctColors: 8,
11
+ minLuminanceStdDev: 0.01
12
+ };
13
+ var CaptureGuardError = class extends Error {
14
+ constructor(label, reason, stats) {
15
+ super(`TN_CAPTURE_BLANK: ${label}: ${reason}`);
16
+ this.label = label;
17
+ this.reason = reason;
18
+ this.stats = stats;
19
+ this.name = "CaptureGuardError";
20
+ }
21
+ label;
22
+ reason;
23
+ stats;
24
+ code = "TN_CAPTURE_BLANK";
25
+ };
26
+ function inspectFrame(png) {
27
+ const image = PNG.sync.read(png);
28
+ const colors = /* @__PURE__ */ new Set();
29
+ let luminanceTotal = 0;
30
+ let luminanceSquaredTotal = 0;
31
+ let brightPixels = 0;
32
+ let visiblePixels = 0;
33
+ let maxLuminance = 0;
34
+ for (let offset = 0; offset < image.data.length; offset += 4) {
35
+ const red = image.data[offset] ?? 0;
36
+ const green = image.data[offset + 1] ?? 0;
37
+ const blue = image.data[offset + 2] ?? 0;
38
+ const alpha = image.data[offset + 3] ?? 0;
39
+ colors.add((red << 24 | green << 16 | blue << 8 | alpha) >>> 0);
40
+ if (alpha === 0) continue;
41
+ const luminance = (0.2126 * red + 0.7152 * green + 0.0722 * blue) / 255;
42
+ visiblePixels += 1;
43
+ maxLuminance = Math.max(maxLuminance, luminance);
44
+ if (luminance > CAPTURE_GUARD_LIMITS.brightLuminance) brightPixels += 1;
45
+ luminanceTotal += luminance;
46
+ luminanceSquaredTotal += luminance * luminance;
47
+ }
48
+ const mean = visiblePixels === 0 ? 0 : luminanceTotal / visiblePixels;
49
+ const variance = visiblePixels === 0 ? 0 : luminanceSquaredTotal / visiblePixels - mean * mean;
50
+ return {
51
+ distinctColors: colors.size,
52
+ brightPixelRatio: image.data.length === 0 ? 0 : brightPixels / (image.data.length / 4),
53
+ height: image.height,
54
+ luminanceStdDev: Math.sqrt(Math.max(0, variance)),
55
+ maxLuminance,
56
+ width: image.width
57
+ };
58
+ }
59
+ function assertCaptureNotBlank(png, label) {
60
+ const stats = inspectFrame(png);
61
+ if (stats.distinctColors < CAPTURE_GUARD_LIMITS.minDistinctColors) {
62
+ throw new CaptureGuardError(
63
+ label,
64
+ `only ${stats.distinctColors} distinct color(s); capture is likely uniform or blank`,
65
+ stats
66
+ );
67
+ }
68
+ if (stats.luminanceStdDev < CAPTURE_GUARD_LIMITS.minLuminanceStdDev) {
69
+ throw new CaptureGuardError(
70
+ label,
71
+ `luminance standard deviation ${stats.luminanceStdDev.toFixed(5)} is below ${CAPTURE_GUARD_LIMITS.minLuminanceStdDev}`,
72
+ stats
73
+ );
74
+ }
75
+ const hasDarkFrameVariation = stats.distinctColors >= CAPTURE_GUARD_LIMITS.darkFrameMinDistinctColors && stats.luminanceStdDev >= CAPTURE_GUARD_LIMITS.darkFrameMinLuminanceStdDev && stats.maxLuminance <= CAPTURE_GUARD_LIMITS.darkFrameMaxLuminance;
76
+ if (stats.brightPixelRatio < CAPTURE_GUARD_LIMITS.minBrightPixelRatio && !hasDarkFrameVariation) {
77
+ throw new CaptureGuardError(
78
+ label,
79
+ `bright pixel ratio ${stats.brightPixelRatio.toFixed(5)} is below ${CAPTURE_GUARD_LIMITS.minBrightPixelRatio}`,
80
+ stats
81
+ );
82
+ }
83
+ return stats;
84
+ }
85
+ var assertFrameShowsSomething = assertCaptureNotBlank;
86
+
87
+ export { CAPTURE_GUARD_LIMITS, CaptureGuardError, assertCaptureNotBlank, assertFrameShowsSomething, inspectFrame };