@threenative/runtime-native 0.3.2 → 0.3.4
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 +236 -1
- package/android/app/build.gradle.kts +37 -2
- package/android/app/src/main/java/com/mystral/engine/MystralActivity.java +97 -1
- package/android/app/src/main/java/com/mystral/engine/TnUiOverlay.java +170 -8
- package/android/build.gradle.kts +1 -1
- package/android/gradle/wrapper/gradle-wrapper.properties +2 -2
- package/package.json +17 -4
- package/scripts/asset-manifest.mjs +209 -0
- package/scripts/asset-preflight.mjs +137 -6
- package/scripts/bundle.mjs +25 -5
- package/scripts/check-android-16kb-alignment.mjs +413 -0
- package/scripts/desktop-distribution.mjs +1084 -0
- package/scripts/inspect-container-brand.mjs +748 -0
- package/scripts/inspect-macos-icon.mjs +169 -0
- package/scripts/install-prebuilt.mjs +6 -3
- package/scripts/package-android.mjs +478 -32
- package/scripts/package-desktop.mjs +191 -15
- package/scripts/package-ios.mjs +83 -41
- package/scripts/physical-device-evidence.mjs +135 -1
- package/scripts/production-evidence.mjs +43 -12
- package/scripts/profile-production.mjs +735 -159
- package/scripts/qualify-physical-mobile.mjs +286 -69
- package/scripts/verify-starter-consumer.mjs +782 -0
- package/scripts/verify-starter-desktop-base.mjs +458 -0
- package/scripts/verify-starter-desktop.mjs +27 -220
- package/scripts/verify-windows-installer.mjs +63 -0
- package/scripts/windows-installer.mjs +181 -0
- package/scripts/windows-installer.nsi +114 -0
- package/scripts/xvfb.sh +48 -1
|
@@ -0,0 +1,458 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { spawnSync } from 'node:child_process';
|
|
4
|
+
import { createHash } from 'node:crypto';
|
|
5
|
+
import { existsSync, mkdirSync, readFileSync, realpathSync, writeFileSync } from 'node:fs';
|
|
6
|
+
import { basename, dirname, join, resolve } from 'node:path';
|
|
7
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
8
|
+
import { PNG } from 'pngjs';
|
|
9
|
+
|
|
10
|
+
import { parseLinkedLibraries, resolveContainer } from './desktop-distribution.mjs';
|
|
11
|
+
import { inspectContainerBrand } from './inspect-container-brand.mjs';
|
|
12
|
+
import { inspectMacosIcon } from './inspect-macos-icon.mjs';
|
|
13
|
+
|
|
14
|
+
const READY_MARKER = 'TN_NATIVE_SMOKE_READY:webgpu';
|
|
15
|
+
const ASSET_MARKER = 'TN_NATIVE_STARTER_ASSETS_LOADED:texture,glb';
|
|
16
|
+
// Measured: a drawn starter frame has ~17,000 distinct colours, a lost capture had 5.
|
|
17
|
+
const UNRENDERED_FRAME_COLOR_FLOOR = 64;
|
|
18
|
+
// 64x64. Below this the frame is a fixture, not a capture.
|
|
19
|
+
const UNRENDERED_FRAME_MIN_PIXELS = 4096;
|
|
20
|
+
const ASSET_PIXEL_FLOOR = 100;
|
|
21
|
+
// The packaged proof is a cyan/magenta checkerboard pennant, and it is identified by CHANNEL
|
|
22
|
+
// MARGIN rather than by distance to the authored texture colour. The gate reads a lit, tonemapped
|
|
23
|
+
// render, and the authored cyan never reaches the screen: measured on the CI capture of run
|
|
24
|
+
// 34076016432, the pennant's cyan renders as rgb(86,180,189) — 103 away from the authored
|
|
25
|
+
// [18,220,255] — while the ocean behind it sits at 149 and the sky at 140. Any absolute-distance
|
|
26
|
+
// threshold wide enough to admit the asset also admits the sea, which is how a frame showing the
|
|
27
|
+
// pennant plainly was rejected with 798,464 of 921,600 pixels classified as proof.
|
|
28
|
+
//
|
|
29
|
+
// Magenta is the discriminator, because an ocean world contains none: 521 magenta pixels on the
|
|
30
|
+
// pennant, against 0 in the same frame with the pennant cropped away.
|
|
31
|
+
const PROOF_MAGENTA_MIN_MARGIN = 40;
|
|
32
|
+
// Corroborating cyan, counted only inside the magenta bounds so the background cannot supply it.
|
|
33
|
+
const PROOF_CYAN_MIN_MARGIN = 70;
|
|
34
|
+
const PROOF_CYAN_IN_BOUNDS_FLOOR = 50;
|
|
35
|
+
// A proof region may occupy up to a quarter of a rendered frame; a wash that reaches almost every
|
|
36
|
+
// part of the frame must not count as localized evidence.
|
|
37
|
+
const MAX_ASSET_BOUNDS_FRACTION = 0.25;
|
|
38
|
+
// Bounds alone cannot separate a small asset from magenta scattered thinly across the frame, since
|
|
39
|
+
// scattered pixels share almost the same bounding box as a solid one. Density does: the pennant
|
|
40
|
+
// fills 0.236 of its own bounds, scattered noise fills 0.04.
|
|
41
|
+
const MIN_ASSET_BOUNDS_DENSITY = 0.1;
|
|
42
|
+
|
|
43
|
+
function isProofMagenta(data, offset) {
|
|
44
|
+
return (
|
|
45
|
+
data[offset + 3] > 0 &&
|
|
46
|
+
data[offset] > data[offset + 1] + PROOF_MAGENTA_MIN_MARGIN &&
|
|
47
|
+
data[offset + 2] > data[offset + 1] + PROOF_MAGENTA_MIN_MARGIN
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function isProofCyan(data, offset) {
|
|
52
|
+
return (
|
|
53
|
+
data[offset + 3] > 0 &&
|
|
54
|
+
data[offset + 1] - data[offset] > PROOF_CYAN_MIN_MARGIN &&
|
|
55
|
+
data[offset + 2] - data[offset] > PROOF_CYAN_MIN_MARGIN
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function countProofCyanInBounds(png, bounds) {
|
|
60
|
+
let cyan = 0;
|
|
61
|
+
for (let y = bounds.minY; y <= bounds.maxY; y += 1) {
|
|
62
|
+
for (let x = bounds.minX; x <= bounds.maxX; x += 1) {
|
|
63
|
+
if (isProofCyan(png.data, (y * png.width + x) * 4)) cyan += 1;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return cyan;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Localization is a question about a capture, not about a texture, so only a capture-sized frame
|
|
70
|
+
// reaches this. The distribution test feeds the packaged 16x16 proof itself, where the asset
|
|
71
|
+
// legitimately fills the whole frame and asking where it sits has no meaning.
|
|
72
|
+
function assertProofIsLocalized(png, bounds, magentaAssetPixels) {
|
|
73
|
+
const boundsArea = (bounds.maxX - bounds.minX + 1) * (bounds.maxY - bounds.minY + 1);
|
|
74
|
+
const boundsFraction = boundsArea / (png.width * png.height);
|
|
75
|
+
if (boundsFraction > MAX_ASSET_BOUNDS_FRACTION) {
|
|
76
|
+
throw new Error(
|
|
77
|
+
`TN_NATIVE_STARTER_ASSET_NOT_LOCALIZED: magenta spans ${(boundsFraction * 100).toFixed(1)}% of the frame, which is a wash, not the proof asset.`,
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
const density = magentaAssetPixels / boundsArea;
|
|
81
|
+
if (density < MIN_ASSET_BOUNDS_DENSITY) {
|
|
82
|
+
throw new Error(
|
|
83
|
+
`TN_NATIVE_STARTER_ASSET_NOT_LOCALIZED: magenta fills only ${(density * 100).toFixed(1)}% of its own bounds, which is scatter, not the proof asset.`,
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// One pass over the frame: the colour census the unrendered-frame floor reads, and the magenta
|
|
89
|
+
// pixel count with the bounds it occupies.
|
|
90
|
+
function scanProofMagenta(png) {
|
|
91
|
+
const colors = new Set();
|
|
92
|
+
const bounds = { maxX: -1, maxY: -1, minX: png.width, minY: png.height };
|
|
93
|
+
let magentaAssetPixels = 0;
|
|
94
|
+
for (let index = 0; index < png.data.length; index += 4) {
|
|
95
|
+
colors.add(
|
|
96
|
+
`${png.data[index]},${png.data[index + 1]},${png.data[index + 2]},${png.data[index + 3]}`,
|
|
97
|
+
);
|
|
98
|
+
if (!isProofMagenta(png.data, index)) continue;
|
|
99
|
+
magentaAssetPixels += 1;
|
|
100
|
+
const pixel = index / 4;
|
|
101
|
+
const x = pixel % png.width;
|
|
102
|
+
const y = Math.floor(pixel / png.width);
|
|
103
|
+
if (x < bounds.minX) bounds.minX = x;
|
|
104
|
+
if (x > bounds.maxX) bounds.maxX = x;
|
|
105
|
+
if (y < bounds.minY) bounds.minY = y;
|
|
106
|
+
if (y > bounds.maxY) bounds.maxY = y;
|
|
107
|
+
}
|
|
108
|
+
return { bounds, colors, magentaAssetPixels };
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export function inspectStarterScreenshot(path) {
|
|
112
|
+
if (!existsSync(path)) throw new Error(`TN_NATIVE_STARTER_SCREENSHOT_MISSING: ${path}`);
|
|
113
|
+
const png = PNG.sync.read(readFileSync(path));
|
|
114
|
+
const { bounds, colors, magentaAssetPixels } = scanProofMagenta(png);
|
|
115
|
+
if (colors.size < 2) throw new Error('TN_NATIVE_STARTER_SCREENSHOT_BLANK: one-color frame.');
|
|
116
|
+
// A one-colour guard is too weak to catch the capture this gate actually loses. A rendered
|
|
117
|
+
// starter frame carries roughly 17k distinct colours; an intermittent CI failure captured five —
|
|
118
|
+
// flat background, two flat shapes, thirteen pixels of the GLB — while the run log still showed
|
|
119
|
+
// TN_NATIVE_STARTER_ASSETS_LOADED and "Rendered 300 frames". That frame was never drawn, and
|
|
120
|
+
// reporting it as a missing asset sends the reader hunting for a texture that loaded fine.
|
|
121
|
+
// Only meaningful at capture resolution. A 16x16 synthetic fixture — what the installed-verifier
|
|
122
|
+
// distribution test feeds this function — is legitimately two colours, and judging it by the
|
|
123
|
+
// diversity a 1280x720 render carries would reject a frame that is exactly what it claims to be.
|
|
124
|
+
const rendered = png.width * png.height >= UNRENDERED_FRAME_MIN_PIXELS;
|
|
125
|
+
if (rendered && colors.size < UNRENDERED_FRAME_COLOR_FLOOR) {
|
|
126
|
+
throw new Error(
|
|
127
|
+
`TN_NATIVE_STARTER_FRAME_NOT_RENDERED: only ${colors.size} distinct colours in ${png.width}x${png.height}. The run log may still show every marker: this is the capture, not the scene.`,
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
if (magentaAssetPixels < ASSET_PIXEL_FLOOR) {
|
|
131
|
+
throw new Error(
|
|
132
|
+
`TN_NATIVE_STARTER_ASSET_NOT_VISIBLE: found ${magentaAssetPixels} magenta proof pixels in a frame of ${colors.size} colours.`,
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
if (rendered) assertProofIsLocalized(png, bounds, magentaAssetPixels);
|
|
136
|
+
const cyanAssetPixels = countProofCyanInBounds(png, bounds);
|
|
137
|
+
if (cyanAssetPixels < PROOF_CYAN_IN_BOUNDS_FLOOR) {
|
|
138
|
+
throw new Error(
|
|
139
|
+
`TN_NATIVE_STARTER_ASSET_NOT_VISIBLE: magenta found but only ${cyanAssetPixels} cyan proof pixels inside its bounds; the checkerboard needs both colours.`,
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
return {
|
|
143
|
+
colors: colors.size,
|
|
144
|
+
cyanAssetPixels,
|
|
145
|
+
height: png.height,
|
|
146
|
+
magentaAssetPixels,
|
|
147
|
+
width: png.width,
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export function analyzeStarterLog(log, frames = 300) {
|
|
152
|
+
const failures = [];
|
|
153
|
+
for (const marker of [READY_MARKER, ASSET_MARKER, `TN_NATIVE_SMOKE_${frames}_FRAMES:${frames}`]) {
|
|
154
|
+
if (!log.includes(marker)) failures.push(`missing ${marker}`);
|
|
155
|
+
}
|
|
156
|
+
if (!new RegExp(`Rendered ${frames} frames in \\d+ms`, 'u').test(log)) {
|
|
157
|
+
failures.push(`missing exact ${frames}-frame completion`);
|
|
158
|
+
}
|
|
159
|
+
for (const pattern of [/TN_NATIVE_START_FAILED/u, /validation error/iu, /TypeError:/u]) {
|
|
160
|
+
if (pattern.test(log)) failures.push(`runtime log matched ${pattern}`);
|
|
161
|
+
}
|
|
162
|
+
// The capture is only evidence if the world was on screen when it was taken. The host holds the
|
|
163
|
+
// screenshot until the startup gate opens and says so; a 0 here means it captured the loading
|
|
164
|
+
// state after waiting out its budget, which is the difference between a 17,000-colour frame and
|
|
165
|
+
// a five-colour one.
|
|
166
|
+
if (log.includes('TN_STARTUP_CAPTURE_READY:0')) {
|
|
167
|
+
failures.push('startup gate never opened before capture (TN_STARTUP_CAPTURE_READY:0)');
|
|
168
|
+
}
|
|
169
|
+
return failures;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* The install step for a system library the container records as a player prerequisite.
|
|
174
|
+
*
|
|
175
|
+
* The container deliberately ships none of these, so a missing one is a player-machine gap. The
|
|
176
|
+
* verifier names the concrete library and its OS install command rather than leaking the dynamic
|
|
177
|
+
* loader's bare `not found`, which reads like a broken artifact.
|
|
178
|
+
*/
|
|
179
|
+
export function playerPrerequisiteHint(name, platform = process.platform, recorded = true) {
|
|
180
|
+
if (recorded && /libwebkit2gtk-/u.test(name)) {
|
|
181
|
+
return 'install the WebKitGTK 4.1 runtime (Debian/Ubuntu: sudo apt-get install -y libwebkit2gtk-4.1-0; Fedora: sudo dnf install webkit2gtk4.1; Arch: sudo pacman -S webkit2gtk-4.1).';
|
|
182
|
+
}
|
|
183
|
+
if (recorded && (/webview2/iu.test(name) || /^WebView2Loader\.dll$/iu.test(name))) {
|
|
184
|
+
return 'install the Microsoft Edge WebView2 Evergreen Runtime (https://developer.microsoft.com/microsoft-edge/webview2/).';
|
|
185
|
+
}
|
|
186
|
+
return `install ${name} with this OS's package manager; the container records system libraries as player prerequisites and does not ship them.`;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function defaultExec(command, args) {
|
|
190
|
+
const result = spawnSync(command, args, { encoding: 'utf8' });
|
|
191
|
+
return {
|
|
192
|
+
error: result.error,
|
|
193
|
+
status: result.status,
|
|
194
|
+
stderr: result.stderr ?? '',
|
|
195
|
+
stdout: result.stdout ?? '',
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/** Shared libraries the player machine must provide that this host cannot resolve. */
|
|
200
|
+
export function missingPlayerLibraries(executable, { platform = process.platform, run = defaultExec } = {}) {
|
|
201
|
+
if (platform !== 'linux') return [];
|
|
202
|
+
const result = run('ldd', [executable]);
|
|
203
|
+
if (result.error) {
|
|
204
|
+
throw new Error(
|
|
205
|
+
`TN_STARTER_PREREQUISITE_TOOL_MISSING: 'ldd' is required to resolve player prerequisites (${result.error.message}).`,
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
if (result.status !== 0) {
|
|
209
|
+
throw new Error(
|
|
210
|
+
`TN_STARTER_PREREQUISITE_RESOLUTION_FAILED: 'ldd' exited ${result.status ?? 'unknown'} for ${executable}.\n${result.stderr}`,
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
return parseLinkedLibraries(result.stdout, 'linux')
|
|
214
|
+
.filter((library) => library.missing)
|
|
215
|
+
.map((library) => library.name);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/** Fail with the concrete prerequisite and its install step, not a loader error. */
|
|
219
|
+
export function assertPlayerPrerequisites(manifest, executable, { platform = process.platform, run = defaultExec } = {}) {
|
|
220
|
+
const missing = missingPlayerLibraries(executable, { platform, run });
|
|
221
|
+
if (missing.length === 0) return [];
|
|
222
|
+
const recorded = new Set((manifest?.prerequisites ?? []).map((prerequisite) => prerequisite?.name));
|
|
223
|
+
const details = missing
|
|
224
|
+
.map((name) => ` - ${name}: ${playerPrerequisiteHint(name, platform, recorded.has(name))}`)
|
|
225
|
+
.join('\n');
|
|
226
|
+
throw new Error(
|
|
227
|
+
`TN_NATIVE_STARTER_PREREQUISITE_MISSING: ${executable} needs ${missing.length} system prerequisite(s) this player machine does not provide:\n${details}`,
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
function launchStarterExecutable(executable, { env = process.env, frames, logPath, project, screenshot }) {
|
|
232
|
+
// Windowed at the configured size, not the starter's `display.fullscreen: true` default: a
|
|
233
|
+
// headless Windows runner has no interactive desktop for a fullscreen swap and the process was
|
|
234
|
+
// seen to hang in it, and a fixed window keeps the capture size the render gates already assert.
|
|
235
|
+
const runtimeArgs = ['--windowed', '--screenshot', screenshot, '--frames', String(frames)];
|
|
236
|
+
// See verify-desktop-core.mjs: `xvfb-run` hands back its own failing cleanup kill's status.
|
|
237
|
+
const displayHelper = join(dirname(fileURLToPath(import.meta.url)), 'xvfb.sh');
|
|
238
|
+
if (process.platform === 'linux' && !existsSync(displayHelper)) {
|
|
239
|
+
throw new Error(`TN_NATIVE_STARTER_DISPLAY_SUPPORT_MISSING: ${displayHelper}`);
|
|
240
|
+
}
|
|
241
|
+
const command = process.platform === 'linux' ? 'sh' : executable;
|
|
242
|
+
const args = process.platform === 'linux' ? [displayHelper, executable, ...runtimeArgs] : runtimeArgs;
|
|
243
|
+
// A hosted Windows runner renders 300 frames on a software adapter with the WebView2 overlay
|
|
244
|
+
// compositing alongside, which is slower than the Linux and macOS lanes; the override keeps a
|
|
245
|
+
// genuinely hung run bounded at the caller's number instead of ours.
|
|
246
|
+
const timeoutMs = Number(process.env.TN_STARTER_TIMEOUT_MS ?? 300_000);
|
|
247
|
+
const result = spawnSync(command, args, {
|
|
248
|
+
cwd: project,
|
|
249
|
+
encoding: 'utf8',
|
|
250
|
+
env: process.platform === 'linux' ? { ...env, SDL_VIDEODRIVER: 'x11' } : env,
|
|
251
|
+
timeout: timeoutMs,
|
|
252
|
+
});
|
|
253
|
+
// Write the captured output before judging it. On a timeout `spawnSync` sets `error` and the old
|
|
254
|
+
// code threw before the log existed, so a Windows run that hung reported only ETIMEDOUT and no
|
|
255
|
+
// clue where it stopped; the log is the diagnosis.
|
|
256
|
+
const log = `${result.stdout ?? ''}\n${result.stderr ?? ''}`;
|
|
257
|
+
writeFileSync(logPath, log);
|
|
258
|
+
if (result.error) {
|
|
259
|
+
throw new Error(`TN_NATIVE_STARTER_SPAWN_FAILED: ${result.error.message}\n${log}`);
|
|
260
|
+
}
|
|
261
|
+
if (result.status !== 0) throw new Error(`TN_NATIVE_STARTER_EXIT_${result.status}:\n${log}`);
|
|
262
|
+
return log;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
// The raw debug artifact and the installed release container are judged by the same markers.
|
|
266
|
+
function judgeStarterRun({ artifact, brand, frames, log, logPath, reportPath, screenshot }) {
|
|
267
|
+
const failures = analyzeStarterLog(log, frames);
|
|
268
|
+
if (failures.length > 0) throw new Error(`TN_NATIVE_STARTER_LOG_FAILED:\n${failures.join('\n')}`);
|
|
269
|
+
// Windows (DWM) and macOS (Quartz) always composite, so the default starter's WebView HUD must
|
|
270
|
+
// attach there. Linux CI runs a bare Xvfb with no compositor and the overlay correctly refuses,
|
|
271
|
+
// so this is asserted only where the desktop compositor is part of the OS.
|
|
272
|
+
const overlayAttached = log.includes('"attached":true');
|
|
273
|
+
if ((process.platform === 'win32' || process.platform === 'darwin') && !overlayAttached) {
|
|
274
|
+
throw new Error(
|
|
275
|
+
'TN_NATIVE_STARTER_UI_OVERLAY_MISSING: the starter WebView HUD did not attach on this always-composited desktop host.',
|
|
276
|
+
);
|
|
277
|
+
}
|
|
278
|
+
const image = inspectStarterScreenshot(screenshot);
|
|
279
|
+
const report = {
|
|
280
|
+
artifact,
|
|
281
|
+
brand,
|
|
282
|
+
completedAt: new Date().toISOString(),
|
|
283
|
+
frames,
|
|
284
|
+
image,
|
|
285
|
+
log: logPath,
|
|
286
|
+
overlayAttached,
|
|
287
|
+
pass: true,
|
|
288
|
+
screenshot,
|
|
289
|
+
screenshotSha256: createHash('sha256').update(readFileSync(screenshot)).digest('hex'),
|
|
290
|
+
};
|
|
291
|
+
writeFileSync(reportPath, `${JSON.stringify(report, null, 2)}\n`);
|
|
292
|
+
return report;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
export function verifyStarterDesktop({ frames = 300, project = process.cwd() } = {}) {
|
|
296
|
+
const projectRoot = resolve(project);
|
|
297
|
+
const manifest = JSON.parse(readFileSync(join(projectRoot, 'package.json'), 'utf8'));
|
|
298
|
+
const projectName = basename(String(manifest.name ?? 'starter').replace(/^@[^/]+\//u, ''));
|
|
299
|
+
const executableName = process.platform === 'win32' ? `${projectName}.exe` : projectName;
|
|
300
|
+
const artifact = join(projectRoot, 'dist-native', executableName);
|
|
301
|
+
if (!existsSync(artifact)) {
|
|
302
|
+
throw new Error(`TN_NATIVE_STARTER_ARTIFACT_MISSING: run pnpm build:desktop first (${artifact}).`);
|
|
303
|
+
}
|
|
304
|
+
const artifactDirectory = join(projectRoot, 'artifacts', 'native');
|
|
305
|
+
const screenshot = join(artifactDirectory, 'starter-desktop.png');
|
|
306
|
+
const logPath = join(artifactDirectory, 'starter-desktop.log');
|
|
307
|
+
const reportPath = join(artifactDirectory, 'starter-desktop-report.json');
|
|
308
|
+
mkdirSync(artifactDirectory, { recursive: true });
|
|
309
|
+
const log = launchStarterExecutable(artifact, { frames, logPath, project: projectRoot, screenshot });
|
|
310
|
+
return judgeStarterRun({ artifact, frames, log, logPath, reportPath, screenshot });
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* Verify an installed release container from wherever the player unpacked it.
|
|
315
|
+
*
|
|
316
|
+
* The same markers and capture are judged, but a missing system prerequisite is caught before the
|
|
317
|
+
* launch and reported with its install step, and the container's own integrity records are
|
|
318
|
+
* resolved first, so a tampered or incomplete payload never reaches the launch.
|
|
319
|
+
*/
|
|
320
|
+
/**
|
|
321
|
+
* Resolve the container and inspect its brand without launching the game.
|
|
322
|
+
*
|
|
323
|
+
* Brand is judged before anything launches: a container that carries the wrong identity must not
|
|
324
|
+
* be rescued by a green frame, and its failure names the surface, not the launch.
|
|
325
|
+
*/
|
|
326
|
+
function inspectContainer(containerRoot, config, projectRoot) {
|
|
327
|
+
const manifest = resolveContainer(containerRoot);
|
|
328
|
+
const brand =
|
|
329
|
+
config === undefined
|
|
330
|
+
? null
|
|
331
|
+
: inspectContainerBrand(containerRoot, config, { project: projectRoot });
|
|
332
|
+
// inspectContainerBrand owns metadata/provenance. A release-verifier pass additionally needs
|
|
333
|
+
// the final macOS payload decoded: a matching source hash cannot prove an ICNS conversion.
|
|
334
|
+
if (brand?.icon !== undefined && manifest.platform.startsWith('darwin-')) {
|
|
335
|
+
brand.icon.macos = inspectMacosIcon(
|
|
336
|
+
join(containerRoot, brand.icon.path),
|
|
337
|
+
resolve(projectRoot, config.app.icon),
|
|
338
|
+
);
|
|
339
|
+
}
|
|
340
|
+
return { brand, manifest };
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* Inspect a distributed container's brand on a host that cannot launch it.
|
|
345
|
+
*
|
|
346
|
+
* The Windows CI leg packages a real `.exe` with real PE resources but has no interactive desktop
|
|
347
|
+
* to run it on. macOS icon-content inspection needs macOS iconutil/sips, but no GUI session.
|
|
348
|
+
* Integrity records are resolved
|
|
349
|
+
* first either way, so this is not a weaker check than the launching path — only a shorter one.
|
|
350
|
+
*/
|
|
351
|
+
export function verifyContainerBrand({ root, config, project = process.cwd() } = {}) {
|
|
352
|
+
if (!root) {
|
|
353
|
+
throw new Error('TN_NATIVE_STARTER_CONTAINER_MISSING: pass --container <unpacked directory>.');
|
|
354
|
+
}
|
|
355
|
+
if (config === undefined) {
|
|
356
|
+
throw new Error(
|
|
357
|
+
'TN_NATIVE_STARTER_CLI_INVALID: --brand-only needs --config <resolved config json>.',
|
|
358
|
+
);
|
|
359
|
+
}
|
|
360
|
+
return inspectContainer(resolve(root), config, resolve(project)).brand;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
export function verifyStarterContainer({ root, config, frames = 300, project = process.cwd(), env, run } = {}) {
|
|
364
|
+
if (!root) {
|
|
365
|
+
throw new Error('TN_NATIVE_STARTER_CONTAINER_MISSING: pass --container <unpacked directory>.');
|
|
366
|
+
}
|
|
367
|
+
const projectRoot = resolve(project);
|
|
368
|
+
const containerRoot = resolve(root);
|
|
369
|
+
const { brand, manifest } = inspectContainer(containerRoot, config, projectRoot);
|
|
370
|
+
const executable = join(containerRoot, manifest.executable);
|
|
371
|
+
assertPlayerPrerequisites(manifest, executable, { run });
|
|
372
|
+
const artifactDirectory = join(projectRoot, 'artifacts', 'native');
|
|
373
|
+
const screenshot = join(artifactDirectory, 'starter-container.png');
|
|
374
|
+
const logPath = join(artifactDirectory, 'starter-container.log');
|
|
375
|
+
const reportPath = join(artifactDirectory, 'starter-container-report.json');
|
|
376
|
+
mkdirSync(artifactDirectory, { recursive: true });
|
|
377
|
+
const log = launchStarterExecutable(executable, { env, frames, logPath, project: projectRoot, screenshot });
|
|
378
|
+
return judgeStarterRun({ artifact: executable, brand, frames, log, logPath, reportPath, screenshot });
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
/** The consumer config the container is judged against, read as the resolved JSON the packager takes. */
|
|
382
|
+
function readBrandConfig(path) {
|
|
383
|
+
try {
|
|
384
|
+
return JSON.parse(readFileSync(path, 'utf8'));
|
|
385
|
+
} catch (error) {
|
|
386
|
+
throw new Error(
|
|
387
|
+
`TN_NATIVE_STARTER_BRAND_CONFIG_INVALID: ${path} is not readable JSON (${error instanceof Error ? error.message : String(error)}).`,
|
|
388
|
+
);
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
const CLI_VALUE_FLAGS = ['--container', '--config', '--frames', '--project'];
|
|
393
|
+
const CLI_BOOLEAN_FLAGS = ['--brand-only'];
|
|
394
|
+
|
|
395
|
+
function frameCount(value) {
|
|
396
|
+
const frames = Number(value);
|
|
397
|
+
if (!Number.isInteger(frames) || frames <= 0) {
|
|
398
|
+
throw new Error(
|
|
399
|
+
`TN_NATIVE_STARTER_CLI_INVALID: --frames needs a positive whole number, not '${value}'.`,
|
|
400
|
+
);
|
|
401
|
+
}
|
|
402
|
+
return frames;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
/**
|
|
406
|
+
* Every flag is recognized and every value is present, or the run stops.
|
|
407
|
+
*
|
|
408
|
+
* A flag that silently does nothing turns a check off without saying so: `--config $EMPTY` drops
|
|
409
|
+
* brand inspection, `--container $EMPTY` quietly runs the developer-artifact path against a
|
|
410
|
+
* different binary than the one under test, and a mistyped flag does either without a word.
|
|
411
|
+
*/
|
|
412
|
+
function parseCliFlags(argv) {
|
|
413
|
+
const options = {};
|
|
414
|
+
for (let index = 0; index < argv.length; ) {
|
|
415
|
+
const flag = argv[index];
|
|
416
|
+
if (CLI_BOOLEAN_FLAGS.includes(flag)) {
|
|
417
|
+
options.brandOnly = true;
|
|
418
|
+
index += 1;
|
|
419
|
+
continue;
|
|
420
|
+
}
|
|
421
|
+
if (!CLI_VALUE_FLAGS.includes(flag)) {
|
|
422
|
+
throw new Error(
|
|
423
|
+
`TN_NATIVE_STARTER_CLI_INVALID: unknown flag '${flag}'. Supported: ${[...CLI_VALUE_FLAGS, ...CLI_BOOLEAN_FLAGS].join(', ')}.`,
|
|
424
|
+
);
|
|
425
|
+
}
|
|
426
|
+
const value = argv[index + 1];
|
|
427
|
+
if (typeof value !== 'string' || value.trim().length === 0) {
|
|
428
|
+
throw new Error(`TN_NATIVE_STARTER_CLI_INVALID: ${flag} needs a value.`);
|
|
429
|
+
}
|
|
430
|
+
if (flag === '--container') options.root = resolve(value);
|
|
431
|
+
else if (flag === '--config') options.config = readBrandConfig(resolve(value));
|
|
432
|
+
else if (flag === '--frames') options.frames = frameCount(value);
|
|
433
|
+
else options.project = resolve(value);
|
|
434
|
+
index += 2;
|
|
435
|
+
}
|
|
436
|
+
return options;
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
if (process.argv[1] && import.meta.url === pathToFileURL(realpathSync(process.argv[1])).href) {
|
|
440
|
+
try {
|
|
441
|
+
const options = parseCliFlags(process.argv.slice(2));
|
|
442
|
+
if (options.brandOnly) {
|
|
443
|
+
const brand = verifyContainerBrand(options);
|
|
444
|
+
console.log(
|
|
445
|
+
`container brand verified: ${brand.name?.name ?? '(no configured name)'}\n${JSON.stringify(brand, null, 2)}`,
|
|
446
|
+
);
|
|
447
|
+
process.exit(0);
|
|
448
|
+
}
|
|
449
|
+
const report = options.root ? verifyStarterContainer(options) : verifyStarterDesktop(options);
|
|
450
|
+
const brand = report.brand === undefined || report.brand === null
|
|
451
|
+
? 'brand NOT inspected (pass --config <resolved config json>)'
|
|
452
|
+
: `brand ${report.brand.name?.name ?? 'unnamed'} verified`;
|
|
453
|
+
console.log(`starter desktop gate passed: ${report.frames} frames, ${report.image.colors} colors, ${report.image.cyanAssetPixels} asset pixels, ${brand}`);
|
|
454
|
+
} catch (error) {
|
|
455
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
456
|
+
process.exitCode = 1;
|
|
457
|
+
}
|
|
458
|
+
}
|