@playcraft/build 0.2.19-test-a → 0.2.20
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/base-builder.js +2 -42
- package/dist/engines/engine-detector.js +0 -4
- package/dist/engines/generic-adapter.js +19 -14
- package/dist/engines/playable-scripts-adapter.js +5 -2
- package/dist/index.d.ts +4 -21
- package/dist/index.js +2 -12
- package/dist/platforms/adikteev.js +0 -1
- package/dist/platforms/applovin.js +0 -1
- package/dist/platforms/base.d.ts +0 -4
- package/dist/platforms/base.js +6 -25
- package/dist/platforms/bigo.js +0 -1
- package/dist/platforms/facebook.js +0 -1
- package/dist/platforms/google.js +0 -1
- package/dist/platforms/inmobi.js +0 -1
- package/dist/platforms/ironsource.js +0 -1
- package/dist/platforms/liftoff.js +0 -1
- package/dist/platforms/mintegral.js +0 -1
- package/dist/platforms/moloco.js +0 -1
- package/dist/platforms/playcraft.js +0 -1
- package/dist/platforms/remerge.js +0 -1
- package/dist/platforms/snapchat.js +0 -1
- package/dist/platforms/tiktok.js +0 -1
- package/dist/platforms/unity.js +0 -1
- package/dist/types.d.ts +2 -12
- package/dist/validation/html-validator.d.ts +0 -5
- package/dist/validation/html-validator.js +17 -19
- package/dist/validation/index.d.ts +0 -5
- package/dist/validation/index.js +0 -5
- package/dist/validation/package-validator.d.ts +0 -2
- package/dist/validation/package-validator.js +64 -25
- package/dist/validation/profiles.d.ts +1 -13
- package/dist/validation/profiles.js +0 -27
- package/dist/validation/source-scanner.d.ts +0 -11
- package/dist/validation/source-scanner.js +2 -32
- package/dist/validation/types.d.ts +2 -201
- package/dist/validation/types.js +1 -1
- package/dist/validation/validation-runner.d.ts +2 -22
- package/dist/validation/validation-runner.js +3 -64
- package/dist/validation/zip-reader.d.ts +0 -7
- package/dist/validation/zip-reader.js +26 -159
- package/dist/vite/config-builder-generic.d.ts +1 -3
- package/dist/vite/config-builder-generic.js +7 -9
- package/dist/vite/config-builder.js +1 -1
- package/dist/vite/plugin-platform.js +30 -16
- package/dist/vite/plugin-source-builder.d.ts +14 -2
- package/dist/vite/plugin-source-builder.js +997 -61
- package/dist/vite-builder.d.ts +5 -4
- package/dist/vite-builder.js +34 -33
- package/package.json +4 -30
- package/templates/patches/one-page-mraid-resize-canvas.js +2 -0
- package/dist/audio-source-files.d.ts +0 -5
- package/dist/audio-source-files.js +0 -135
- package/dist/delivery/agent-build-runner.d.ts +0 -44
- package/dist/delivery/agent-build-runner.js +0 -365
- package/dist/delivery/agent-build-source.d.ts +0 -8
- package/dist/delivery/agent-build-source.js +0 -25
- package/dist/delivery/artifact-descriptor.d.ts +0 -31
- package/dist/delivery/artifact-descriptor.js +0 -237
- package/dist/delivery/artifact-package.d.ts +0 -43
- package/dist/delivery/artifact-package.js +0 -283
- package/dist/delivery/build-plan.d.ts +0 -4
- package/dist/delivery/build-plan.js +0 -189
- package/dist/delivery/build-plan.types.d.ts +0 -51
- package/dist/delivery/build-plan.types.js +0 -1
- package/dist/delivery/command-isolation.d.ts +0 -21
- package/dist/delivery/command-isolation.js +0 -327
- package/dist/delivery/commands.d.ts +0 -5
- package/dist/delivery/commands.js +0 -146
- package/dist/delivery/files.d.ts +0 -9
- package/dist/delivery/files.js +0 -144
- package/dist/delivery/git-source-fingerprint.d.ts +0 -2
- package/dist/delivery/git-source-fingerprint.js +0 -58
- package/dist/delivery/isolated-source.d.ts +0 -5
- package/dist/delivery/isolated-source.js +0 -148
- package/dist/delivery/output-publication.d.ts +0 -21
- package/dist/delivery/output-publication.js +0 -444
- package/dist/delivery/project-delivery.d.ts +0 -6
- package/dist/delivery/project-delivery.js +0 -287
- package/dist/delivery/recipe-build-plan.d.ts +0 -4
- package/dist/delivery/recipe-build-plan.js +0 -53
- package/dist/delivery/recipe.d.ts +0 -20
- package/dist/delivery/recipe.js +0 -211
- package/dist/delivery/safe-path.d.ts +0 -2
- package/dist/delivery/safe-path.js +0 -18
- package/dist/delivery/types.d.ts +0 -81
- package/dist/delivery/types.js +0 -1
- package/dist/production-animation-presence.d.ts +0 -2
- package/dist/production-animation-presence.js +0 -146
- package/dist/production-inputs.d.ts +0 -30
- package/dist/production-inputs.js +0 -262
- package/dist/production-source-paths.d.ts +0 -5
- package/dist/production-source-paths.js +0 -27
- package/dist/redirect-policy.d.ts +0 -23
- package/dist/redirect-policy.js +0 -25
- package/dist/validation/artifact-qa.d.ts +0 -36
- package/dist/validation/artifact-qa.js +0 -263
- package/dist/validation/artifact-rules.d.ts +0 -39
- package/dist/validation/artifact-rules.js +0 -451
- package/dist/validation/artifact.d.ts +0 -14
- package/dist/validation/artifact.js +0 -188
- package/dist/validation/playwright-driver.d.ts +0 -37
- package/dist/validation/playwright-driver.js +0 -302
- package/dist/validation/runtime-cover.d.ts +0 -32
- package/dist/validation/runtime-cover.js +0 -120
- package/dist/validation/runtime-load.d.ts +0 -141
- package/dist/validation/runtime-load.js +0 -812
- package/dist/vite/source-builder-asset-paths.d.ts +0 -25
- package/dist/vite/source-builder-asset-paths.js +0 -154
- package/dist/vite/source-builder-esm.d.ts +0 -7
- package/dist/vite/source-builder-esm.js +0 -877
- package/dist/vite/source-builder-types.d.ts +0 -14
- package/dist/vite/source-builder-types.js +0 -1
- package/dist/vite/workspace.d.ts +0 -6
- package/dist/vite/workspace.js +0 -41
- package/dist/workspace-css-imports.d.ts +0 -2
- package/dist/workspace-css-imports.js +0 -139
- package/dist/workspace-model-source.d.ts +0 -14
- package/dist/workspace-model-source.js +0 -184
- package/dist/workspace-public-imports.d.ts +0 -11
- package/dist/workspace-public-imports.js +0 -232
- package/dist/workspace-public-source.d.ts +0 -15
- package/dist/workspace-public-source.js +0 -564
- package/templates/patches/playcraft-redirect-policy.js +0 -115
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import type { BrowserType } from 'playwright-core';
|
|
2
|
-
import type { BrowserDriver } from './types.js';
|
|
3
|
-
/**
|
|
4
|
-
* The one headless browser driver for artifact QA, shared by `playcraft qa` in the workspace sandbox
|
|
5
|
-
* and by export validation in the build sandbox. `playwright-core` is loaded only when a driver is
|
|
6
|
-
* created, so importing this module never needs a browser.
|
|
7
|
-
*/
|
|
8
|
-
export declare class QaBrowserUnavailableError extends Error {
|
|
9
|
-
readonly browserPath: string;
|
|
10
|
-
constructor(browserPath: string, reason?: string);
|
|
11
|
-
}
|
|
12
|
-
export interface PlaywrightDriver extends BrowserDriver {
|
|
13
|
-
/** Browser version, recorded in reports. */
|
|
14
|
-
readonly version: string;
|
|
15
|
-
/** Set when no X display could be found or started; WebGL is then likely missing. */
|
|
16
|
-
readonly displayProblem?: string;
|
|
17
|
-
close(): Promise<void>;
|
|
18
|
-
}
|
|
19
|
-
export interface PlaywrightDriverOptions {
|
|
20
|
-
/** Chromium executable; default `PLAYCRAFT_CHROMIUM_PATH`, then `/usr/bin/chromium`. */
|
|
21
|
-
browserPath?: string;
|
|
22
|
-
/** Xvfb executable; default `PLAYCRAFT_XVFB_PATH`, then `/usr/bin/Xvfb`. */
|
|
23
|
-
xvfbPath?: string;
|
|
24
|
-
/** Browser launch timeout. Default 10000 ms. */
|
|
25
|
-
launchTimeoutMs?: number;
|
|
26
|
-
/**
|
|
27
|
-
* playwright-core's `chromium`, when the host resolves packages differently from this module, e.g.
|
|
28
|
-
* a CommonJS runner that finds playwright-core through NODE_PATH. Default: imported here.
|
|
29
|
-
*/
|
|
30
|
-
chromium?: BrowserType;
|
|
31
|
-
}
|
|
32
|
-
export declare function createPlaywrightDriver(options?: PlaywrightDriverOptions): Promise<PlaywrightDriver>;
|
|
33
|
-
/**
|
|
34
|
-
* The sandbox image sets DISPLAY=:99 globally, but only some sandbox start paths launch that Xvfb.
|
|
35
|
-
* Trust a local display only when its X socket exists; a remote host:display is trusted as given.
|
|
36
|
-
*/
|
|
37
|
-
export declare function liveDisplay(value: string | undefined): boolean;
|
|
@@ -1,302 +0,0 @@
|
|
|
1
|
-
import { spawn } from 'node:child_process';
|
|
2
|
-
import { existsSync } from 'node:fs';
|
|
3
|
-
import { access } from 'node:fs/promises';
|
|
4
|
-
import { isIP } from 'node:net';
|
|
5
|
-
import { isAbsolute } from 'node:path';
|
|
6
|
-
/**
|
|
7
|
-
* The one headless browser driver for artifact QA, shared by `playcraft qa` in the workspace sandbox
|
|
8
|
-
* and by export validation in the build sandbox. `playwright-core` is loaded only when a driver is
|
|
9
|
-
* created, so importing this module never needs a browser.
|
|
10
|
-
*/
|
|
11
|
-
export class QaBrowserUnavailableError extends Error {
|
|
12
|
-
constructor(browserPath, reason) {
|
|
13
|
-
super(`Headless Chromium is not available at ${browserPath}${reason ? ` (${reason})` : ''}; set PLAYCRAFT_CHROMIUM_PATH`);
|
|
14
|
-
this.browserPath = browserPath;
|
|
15
|
-
this.name = 'QaBrowserUnavailableError';
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
const VIRTUAL_DISPLAY_TIMEOUT_MS = 5000;
|
|
19
|
-
const MAX_EVENT_TEXT = 1000;
|
|
20
|
-
const MAX_STACK_TEXT = 8000;
|
|
21
|
-
/**
|
|
22
|
-
* Chrome logs these when a page tries to launch a host-app scheme (`bytedance://`, `nativeapp://`);
|
|
23
|
-
* they are bridge calls, not game errors.
|
|
24
|
-
*/
|
|
25
|
-
const BRIDGE_LAUNCH_LOG = /launch ['"][a-z][a-z0-9+.-]*:/i;
|
|
26
|
-
export async function createPlaywrightDriver(options = {}) {
|
|
27
|
-
const browserPath = options.browserPath || process.env.PLAYCRAFT_CHROMIUM_PATH || '/usr/bin/chromium';
|
|
28
|
-
if (!isAbsolute(browserPath))
|
|
29
|
-
throw new QaBrowserUnavailableError(browserPath);
|
|
30
|
-
await access(browserPath).catch(() => {
|
|
31
|
-
throw new QaBrowserUnavailableError(browserPath);
|
|
32
|
-
});
|
|
33
|
-
let displayProblem;
|
|
34
|
-
const display = await startVirtualDisplay(options.xvfbPath ?? (process.env.PLAYCRAFT_XVFB_PATH || '/usr/bin/Xvfb')).catch((error) => {
|
|
35
|
-
displayProblem = `virtual display for WebGL is unavailable: ${error instanceof Error ? error.message : String(error)}`;
|
|
36
|
-
return undefined;
|
|
37
|
-
});
|
|
38
|
-
if (!display && !liveDisplay(process.env.DISPLAY))
|
|
39
|
-
displayProblem ?? (displayProblem = 'no X display and no Xvfb; WebGL may be unavailable');
|
|
40
|
-
let server;
|
|
41
|
-
let browser;
|
|
42
|
-
try {
|
|
43
|
-
const chromium = options.chromium ?? (await import('playwright-core')).chromium;
|
|
44
|
-
// A browser server can be killed outright when a renderer hangs during close.
|
|
45
|
-
server = await chromium.launchServer({
|
|
46
|
-
...(display ? { env: { ...process.env, DISPLAY: display.display } } : {}),
|
|
47
|
-
host: '127.0.0.1',
|
|
48
|
-
executablePath: browserPath,
|
|
49
|
-
headless: true,
|
|
50
|
-
timeout: options.launchTimeoutMs ?? 10000,
|
|
51
|
-
handleSIGTERM: false,
|
|
52
|
-
handleSIGINT: false,
|
|
53
|
-
handleSIGHUP: false,
|
|
54
|
-
args: [
|
|
55
|
-
'--mute-audio',
|
|
56
|
-
'--disable-dev-shm-usage',
|
|
57
|
-
'--enable-unsafe-swiftshader',
|
|
58
|
-
'--use-gl=angle',
|
|
59
|
-
'--use-angle=swiftshader',
|
|
60
|
-
'--hide-scrollbars',
|
|
61
|
-
...(process.getuid?.() === 0 ? ['--no-sandbox'] : []),
|
|
62
|
-
],
|
|
63
|
-
});
|
|
64
|
-
browser = await chromium.connect(server.wsEndpoint(), {
|
|
65
|
-
timeout: options.launchTimeoutMs ?? 10000,
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
catch (error) {
|
|
69
|
-
await server?.close().catch(() => undefined);
|
|
70
|
-
display?.stop();
|
|
71
|
-
throw new QaBrowserUnavailableError(browserPath, error instanceof Error ? error.message.split('\n')[0] : String(error));
|
|
72
|
-
}
|
|
73
|
-
const owned = server;
|
|
74
|
-
return {
|
|
75
|
-
version: browser.version(),
|
|
76
|
-
...(displayProblem ? { displayProblem } : {}),
|
|
77
|
-
open: (pageOptions) => openPage(browser, pageOptions),
|
|
78
|
-
close: async () => {
|
|
79
|
-
const kill = setTimeout(() => owned.process()?.kill('SIGKILL'), 1500);
|
|
80
|
-
await owned.close().catch(() => undefined);
|
|
81
|
-
clearTimeout(kill);
|
|
82
|
-
display?.stop();
|
|
83
|
-
},
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
async function openPage(browser, options) {
|
|
87
|
-
const context = await browser.newContext({
|
|
88
|
-
viewport: { width: options.viewport.width, height: options.viewport.height },
|
|
89
|
-
deviceScaleFactor: options.viewport.deviceScaleFactor,
|
|
90
|
-
isMobile: options.viewport.isMobile,
|
|
91
|
-
hasTouch: options.viewport.hasTouch,
|
|
92
|
-
userAgent: options.userAgent,
|
|
93
|
-
...(options.locale ? { locale: options.locale } : {}),
|
|
94
|
-
serviceWorkers: 'block',
|
|
95
|
-
acceptDownloads: false,
|
|
96
|
-
});
|
|
97
|
-
if (options.initScript)
|
|
98
|
-
await context.addInitScript(options.initScript);
|
|
99
|
-
const page = await context.newPage();
|
|
100
|
-
// The probe records store-opening calls; a popup that still opens is closed, never followed.
|
|
101
|
-
context.on('page', (popup) => {
|
|
102
|
-
if (popup !== page)
|
|
103
|
-
void popup.close();
|
|
104
|
-
});
|
|
105
|
-
const origin = options.origin.replace(/\/+$/, '');
|
|
106
|
-
const entryUrl = `${origin}/${options.entryPath.split('/').map(encodeURIComponent).join('/')}`;
|
|
107
|
-
const events = {
|
|
108
|
-
consoleErrors: [],
|
|
109
|
-
pageErrors: [],
|
|
110
|
-
pageErrorDetails: [],
|
|
111
|
-
failedRequests: [],
|
|
112
|
-
blockedRequests: [],
|
|
113
|
-
navigationAttempts: [],
|
|
114
|
-
containerRequests: [],
|
|
115
|
-
crashed: false,
|
|
116
|
-
};
|
|
117
|
-
let entryServed = false;
|
|
118
|
-
await context.route('**/*', async (route) => {
|
|
119
|
-
const request = route.request();
|
|
120
|
-
const url = request.url();
|
|
121
|
-
const mainNavigation = request.isNavigationRequest() && request.frame() === page.mainFrame();
|
|
122
|
-
if (!url.startsWith(`${origin}/`) || (mainNavigation && entryServed && url !== entryUrl)) {
|
|
123
|
-
if (mainNavigation) {
|
|
124
|
-
// A 204 keeps the current document; aborting would replace it with an error page.
|
|
125
|
-
events.navigationAttempts.push(url);
|
|
126
|
-
return route.fulfill({ status: 204, body: '' });
|
|
127
|
-
}
|
|
128
|
-
// Ad SDK telemetry (for example Bigo's logger POST) never leaves the machine, but an aborted
|
|
129
|
-
// request surfaces as the SDK's own rejection. A channel container answers it locally.
|
|
130
|
-
if (options.containerTelemetry && !['GET', 'HEAD'].includes(request.method())) {
|
|
131
|
-
events.containerRequests.push(`${request.method()} ${url}`);
|
|
132
|
-
return route.fulfill({
|
|
133
|
-
status: 200,
|
|
134
|
-
contentType: 'application/json',
|
|
135
|
-
body: '{}',
|
|
136
|
-
headers: {
|
|
137
|
-
'access-control-allow-origin': origin,
|
|
138
|
-
'access-control-allow-credentials': 'true',
|
|
139
|
-
},
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
if (options.remoteReads && ['GET', 'HEAD'].includes(request.method()) && publicHttp(url))
|
|
143
|
-
return route.continue();
|
|
144
|
-
events.blockedRequests.push(url);
|
|
145
|
-
return route.abort('blockedbyclient');
|
|
146
|
-
}
|
|
147
|
-
if (mainNavigation)
|
|
148
|
-
entryServed = true;
|
|
149
|
-
let pathname;
|
|
150
|
-
try {
|
|
151
|
-
pathname = decodeURIComponent(new URL(url).pathname);
|
|
152
|
-
}
|
|
153
|
-
catch {
|
|
154
|
-
pathname = new URL(url).pathname;
|
|
155
|
-
}
|
|
156
|
-
const resource = await options.resolve(pathname);
|
|
157
|
-
if (!resource) {
|
|
158
|
-
events.failedRequests.push({ url, reason: 'not found in the artifact' });
|
|
159
|
-
return route.fulfill({ status: 404, body: '' });
|
|
160
|
-
}
|
|
161
|
-
const headers = { 'content-type': resource.contentType };
|
|
162
|
-
// Remote reads mirror a real container, so no policy narrows what the page may load.
|
|
163
|
-
if (resource.contentType.startsWith('text/html') &&
|
|
164
|
-
options.contentSecurityPolicy &&
|
|
165
|
-
!options.remoteReads)
|
|
166
|
-
headers['content-security-policy'] = options.contentSecurityPolicy;
|
|
167
|
-
return route.fulfill({ status: 200, body: resource.body, headers });
|
|
168
|
-
});
|
|
169
|
-
page.on('console', (message) => {
|
|
170
|
-
if (message.type() !== 'error')
|
|
171
|
-
return;
|
|
172
|
-
const text = message.text();
|
|
173
|
-
if (BRIDGE_LAUNCH_LOG.test(text))
|
|
174
|
-
return;
|
|
175
|
-
events.consoleErrors.push(text.slice(0, MAX_EVENT_TEXT));
|
|
176
|
-
});
|
|
177
|
-
page.on('pageerror', (error) => {
|
|
178
|
-
const message = `${error.name}: ${error.message}`.slice(0, MAX_EVENT_TEXT);
|
|
179
|
-
events.pageErrors.push(message);
|
|
180
|
-
events.pageErrorDetails.push({
|
|
181
|
-
message,
|
|
182
|
-
...(error.stack ? { stack: error.stack.slice(0, MAX_STACK_TEXT) } : {}),
|
|
183
|
-
});
|
|
184
|
-
});
|
|
185
|
-
page.on('crash', () => {
|
|
186
|
-
events.crashed = true;
|
|
187
|
-
events.pageErrors.push('Page crashed');
|
|
188
|
-
events.pageErrorDetails.push({ message: 'Page crashed' });
|
|
189
|
-
});
|
|
190
|
-
page.on('requestfailed', (request) => {
|
|
191
|
-
const url = request.url();
|
|
192
|
-
const reason = request.failure()?.errorText ?? 'request failed';
|
|
193
|
-
// Blocked requests and missing files are already recorded by the route.
|
|
194
|
-
if (!url.startsWith(`${origin}/`) || /ERR_BLOCKED_BY_CLIENT|ERR_ABORTED/i.test(reason))
|
|
195
|
-
return;
|
|
196
|
-
events.failedRequests.push({ url, reason });
|
|
197
|
-
});
|
|
198
|
-
let loaded = false;
|
|
199
|
-
let loadError;
|
|
200
|
-
try {
|
|
201
|
-
await page.goto(entryUrl, { waitUntil: 'load', timeout: options.timeoutMs });
|
|
202
|
-
loaded = true;
|
|
203
|
-
}
|
|
204
|
-
catch (error) {
|
|
205
|
-
loadError = error instanceof Error ? error.message.split('\n')[0] : String(error);
|
|
206
|
-
}
|
|
207
|
-
return {
|
|
208
|
-
loaded,
|
|
209
|
-
...(loadError ? { loadError } : {}),
|
|
210
|
-
events: () => ({
|
|
211
|
-
consoleErrors: [...events.consoleErrors],
|
|
212
|
-
pageErrors: [...events.pageErrors],
|
|
213
|
-
pageErrorDetails: [...events.pageErrorDetails],
|
|
214
|
-
failedRequests: [...events.failedRequests],
|
|
215
|
-
blockedRequests: [...events.blockedRequests],
|
|
216
|
-
navigationAttempts: [...events.navigationAttempts],
|
|
217
|
-
containerRequests: [...events.containerRequests],
|
|
218
|
-
crashed: events.crashed,
|
|
219
|
-
}),
|
|
220
|
-
evaluate: (expression) => page.evaluate(expression),
|
|
221
|
-
click: (x, y) => page.mouse.click(x, y),
|
|
222
|
-
tap: (x, y) => options.viewport.hasTouch ? page.touchscreen.tap(x, y) : page.mouse.click(x, y),
|
|
223
|
-
screenshot: () => page.screenshot({ type: 'png', timeout: 10000 }),
|
|
224
|
-
wait: (ms) => page.waitForTimeout(ms),
|
|
225
|
-
close: () => context.close(),
|
|
226
|
-
};
|
|
227
|
-
}
|
|
228
|
-
/** An http(s) address outside loopback, link-local and private ranges. */
|
|
229
|
-
function publicHttp(value) {
|
|
230
|
-
let url;
|
|
231
|
-
try {
|
|
232
|
-
url = new URL(value);
|
|
233
|
-
}
|
|
234
|
-
catch {
|
|
235
|
-
return false;
|
|
236
|
-
}
|
|
237
|
-
if (url.protocol !== 'http:' && url.protocol !== 'https:')
|
|
238
|
-
return false;
|
|
239
|
-
const host = url.hostname.replace(/^\[|\]$/g, '').toLowerCase();
|
|
240
|
-
if (host === 'localhost' || host.endsWith('.localhost') || host.endsWith('.internal'))
|
|
241
|
-
return false;
|
|
242
|
-
if (isIP(host) === 4) {
|
|
243
|
-
const [a = 0, b = 0] = host.split('.').map(Number);
|
|
244
|
-
return !(a === 0 ||
|
|
245
|
-
a === 10 ||
|
|
246
|
-
a === 127 ||
|
|
247
|
-
(a === 169 && b === 254) ||
|
|
248
|
-
(a === 100 && b >= 64 && b <= 127) ||
|
|
249
|
-
(a === 172 && b >= 16 && b <= 31) ||
|
|
250
|
-
(a === 192 && b === 168));
|
|
251
|
-
}
|
|
252
|
-
if (isIP(host) === 6)
|
|
253
|
-
return !(host === '::' || host === '::1' || /^f[cd]|^fe[89ab]|^::ffff:/.test(host));
|
|
254
|
-
return true;
|
|
255
|
-
}
|
|
256
|
-
/**
|
|
257
|
-
* The sandbox image sets DISPLAY=:99 globally, but only some sandbox start paths launch that Xvfb.
|
|
258
|
-
* Trust a local display only when its X socket exists; a remote host:display is trusted as given.
|
|
259
|
-
*/
|
|
260
|
-
export function liveDisplay(value) {
|
|
261
|
-
const match = /^([^:]*):(\d+)(?:\.\d+)?$/.exec(value || '');
|
|
262
|
-
if (!match)
|
|
263
|
-
return false;
|
|
264
|
-
return match[1] !== '' && match[1] !== 'unix'
|
|
265
|
-
? true
|
|
266
|
-
: existsSync(`/tmp/.X11-unix/X${match[2]}`);
|
|
267
|
-
}
|
|
268
|
-
/**
|
|
269
|
-
* Debian's Chromium presents SwiftShader only through X11, so a sandbox without a display server
|
|
270
|
-
* loses WebGL. Start a private Xvfb when one is installed; -displayfd picks a free display number.
|
|
271
|
-
*/
|
|
272
|
-
async function startVirtualDisplay(xvfbPath) {
|
|
273
|
-
if (liveDisplay(process.env.DISPLAY) || !xvfbPath || !existsSync(xvfbPath))
|
|
274
|
-
return undefined;
|
|
275
|
-
const child = spawn(xvfbPath, ['-displayfd', '3', '-screen', '0', '1280x1024x24', '-nolisten', 'tcp'], { stdio: ['ignore', 'ignore', 'ignore', 'pipe'] });
|
|
276
|
-
try {
|
|
277
|
-
const display = await new Promise((resolve, reject) => {
|
|
278
|
-
let output = '';
|
|
279
|
-
const timer = setTimeout(() => reject(new Error('Xvfb did not report a display')), VIRTUAL_DISPLAY_TIMEOUT_MS);
|
|
280
|
-
const fail = (error) => {
|
|
281
|
-
clearTimeout(timer);
|
|
282
|
-
reject(error);
|
|
283
|
-
};
|
|
284
|
-
child.once('error', fail);
|
|
285
|
-
child.once('exit', (code) => fail(new Error(`Xvfb exited with code ${code}`)));
|
|
286
|
-
child.stdio[3]?.on('data', (chunk) => {
|
|
287
|
-
output += chunk.toString();
|
|
288
|
-
const match = /^(\d+)\s/.exec(output);
|
|
289
|
-
if (!match)
|
|
290
|
-
return;
|
|
291
|
-
clearTimeout(timer);
|
|
292
|
-
resolve(`:${match[1]}`);
|
|
293
|
-
});
|
|
294
|
-
});
|
|
295
|
-
child.removeAllListeners('exit');
|
|
296
|
-
return { display, stop: () => child.kill('SIGTERM') };
|
|
297
|
-
}
|
|
298
|
-
catch (error) {
|
|
299
|
-
child.kill('SIGKILL');
|
|
300
|
-
throw error;
|
|
301
|
-
}
|
|
302
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import type { BrowserDriver, PlayableArtifact } from './types.js';
|
|
2
|
-
/**
|
|
3
|
-
* The game's first screen as a Remix cover, taken while QA has the artifact open. It follows the
|
|
4
|
-
* workspace cover capture (`playcraft workspace-runtime` cover route): phone viewport at device
|
|
5
|
-
* scale 1, English locale, a short minimum wait to skip most loading screens, then the first frame
|
|
6
|
-
* of a few consecutive frames that show real content. Saving a Remix can then reuse it instead of
|
|
7
|
-
* rendering the preview again.
|
|
8
|
-
*/
|
|
9
|
-
export interface CoverCaptureOptions {
|
|
10
|
-
driver: BrowserDriver;
|
|
11
|
-
/** Cover size in CSS pixels, e.g. the phone content viewport of the preview frame. */
|
|
12
|
-
width: number;
|
|
13
|
-
height: number;
|
|
14
|
-
/** Navigation timeout. Default 20000 ms. */
|
|
15
|
-
timeoutMs?: number;
|
|
16
|
-
/** Minimum wait after load. Default 3000 ms. */
|
|
17
|
-
minRenderMs?: number;
|
|
18
|
-
/** How long to wait for content after the minimum wait. Default 20000 ms. */
|
|
19
|
-
contentWaitMs?: number;
|
|
20
|
-
}
|
|
21
|
-
export interface CoverFrame {
|
|
22
|
-
png: Buffer;
|
|
23
|
-
width: number;
|
|
24
|
-
height: number;
|
|
25
|
-
/** A few consecutive frames showed real content; false when the wait ran out. */
|
|
26
|
-
contentReady: boolean;
|
|
27
|
-
waitedMs: number;
|
|
28
|
-
}
|
|
29
|
-
/** Returns the cover frame, or `undefined` when the page does not open. */
|
|
30
|
-
export declare function captureCoverFrame(artifact: PlayableArtifact, options: CoverCaptureOptions): Promise<CoverFrame | undefined>;
|
|
31
|
-
/** Not a flat, mostly white or mostly black frame, judged on a 48 px wide grey thumbnail. */
|
|
32
|
-
export declare function hasVisibleContent(frame: Buffer): Promise<boolean>;
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import sharp from 'sharp';
|
|
2
|
-
import { RUNTIME_ORIGIN } from './runtime-load.js';
|
|
3
|
-
const IPHONE_USER_AGENT = 'Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Mobile/15E148 Safari/604.1';
|
|
4
|
-
const POLL_INTERVAL_MS = 500;
|
|
5
|
-
const READY_STREAK = 3;
|
|
6
|
-
const SETTLE_MS = 500;
|
|
7
|
-
/** Cover content thresholds, the same as the workspace cover capture. */
|
|
8
|
-
const MIN_STDDEV = 15;
|
|
9
|
-
const MAX_FLAT_RATIO = 0.88;
|
|
10
|
-
const CONTENT_TYPES = {
|
|
11
|
-
html: 'text/html; charset=utf-8',
|
|
12
|
-
htm: 'text/html; charset=utf-8',
|
|
13
|
-
js: 'text/javascript; charset=utf-8',
|
|
14
|
-
mjs: 'text/javascript; charset=utf-8',
|
|
15
|
-
css: 'text/css; charset=utf-8',
|
|
16
|
-
json: 'application/json',
|
|
17
|
-
svg: 'image/svg+xml',
|
|
18
|
-
png: 'image/png',
|
|
19
|
-
jpg: 'image/jpeg',
|
|
20
|
-
jpeg: 'image/jpeg',
|
|
21
|
-
webp: 'image/webp',
|
|
22
|
-
gif: 'image/gif',
|
|
23
|
-
mp3: 'audio/mpeg',
|
|
24
|
-
ogg: 'audio/ogg',
|
|
25
|
-
wav: 'audio/wav',
|
|
26
|
-
woff: 'font/woff',
|
|
27
|
-
woff2: 'font/woff2',
|
|
28
|
-
ttf: 'font/ttf',
|
|
29
|
-
wasm: 'application/wasm',
|
|
30
|
-
};
|
|
31
|
-
/** Returns the cover frame, or `undefined` when the page does not open. */
|
|
32
|
-
export async function captureCoverFrame(artifact, options) {
|
|
33
|
-
const startedAt = Date.now();
|
|
34
|
-
const page = await options.driver.open({
|
|
35
|
-
origin: RUNTIME_ORIGIN,
|
|
36
|
-
entryPath: artifact.entry,
|
|
37
|
-
viewport: {
|
|
38
|
-
width: options.width,
|
|
39
|
-
height: options.height,
|
|
40
|
-
deviceScaleFactor: 1,
|
|
41
|
-
isMobile: true,
|
|
42
|
-
hasTouch: true,
|
|
43
|
-
},
|
|
44
|
-
userAgent: IPHONE_USER_AGENT,
|
|
45
|
-
locale: 'en-US',
|
|
46
|
-
// The cover shows the game as players see it: no probe and no extra policy on the page.
|
|
47
|
-
initScript: '',
|
|
48
|
-
contentSecurityPolicy: '',
|
|
49
|
-
timeoutMs: options.timeoutMs ?? 20000,
|
|
50
|
-
resolve: async (pathname) => {
|
|
51
|
-
const relativePath = pathname.replace(/^\/+/, '');
|
|
52
|
-
const body = await artifact.readBuffer(relativePath);
|
|
53
|
-
if (!body)
|
|
54
|
-
return null;
|
|
55
|
-
const extension = relativePath.split('.').pop()?.toLowerCase() ?? '';
|
|
56
|
-
return { body, contentType: CONTENT_TYPES[extension] ?? 'application/octet-stream' };
|
|
57
|
-
},
|
|
58
|
-
});
|
|
59
|
-
try {
|
|
60
|
-
if (!page.loaded)
|
|
61
|
-
return undefined;
|
|
62
|
-
await page.wait(options.minRenderMs ?? 3000);
|
|
63
|
-
let contentReady = false;
|
|
64
|
-
let streak = 0;
|
|
65
|
-
const deadline = Date.now() + (options.contentWaitMs ?? 20000);
|
|
66
|
-
while (Date.now() < deadline) {
|
|
67
|
-
const frame = await page.screenshot().catch(() => undefined);
|
|
68
|
-
streak = frame && (await hasVisibleContent(frame)) ? streak + 1 : 0;
|
|
69
|
-
if (streak >= READY_STREAK) {
|
|
70
|
-
contentReady = true;
|
|
71
|
-
break;
|
|
72
|
-
}
|
|
73
|
-
await page.wait(POLL_INTERVAL_MS);
|
|
74
|
-
}
|
|
75
|
-
await page.wait(SETTLE_MS);
|
|
76
|
-
const png = await page.screenshot();
|
|
77
|
-
return {
|
|
78
|
-
png,
|
|
79
|
-
width: options.width,
|
|
80
|
-
height: options.height,
|
|
81
|
-
contentReady,
|
|
82
|
-
waitedMs: Date.now() - startedAt,
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
finally {
|
|
86
|
-
await page.close();
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
/** Not a flat, mostly white or mostly black frame, judged on a 48 px wide grey thumbnail. */
|
|
90
|
-
export async function hasVisibleContent(frame) {
|
|
91
|
-
try {
|
|
92
|
-
const { data, info } = await sharp(frame)
|
|
93
|
-
.resize({ width: 48 })
|
|
94
|
-
.greyscale()
|
|
95
|
-
.raw()
|
|
96
|
-
.toBuffer({ resolveWithObject: true });
|
|
97
|
-
const count = info.width * info.height;
|
|
98
|
-
if (count === 0)
|
|
99
|
-
return false;
|
|
100
|
-
let sum = 0;
|
|
101
|
-
let squares = 0;
|
|
102
|
-
let white = 0;
|
|
103
|
-
let black = 0;
|
|
104
|
-
for (let index = 0; index < count; index++) {
|
|
105
|
-
const lum = data[index * info.channels];
|
|
106
|
-
sum += lum;
|
|
107
|
-
squares += lum * lum;
|
|
108
|
-
if (lum >= 245)
|
|
109
|
-
white++;
|
|
110
|
-
if (lum <= 10)
|
|
111
|
-
black++;
|
|
112
|
-
}
|
|
113
|
-
const mean = sum / count;
|
|
114
|
-
const stddev = Math.sqrt(Math.max(0, squares / count - mean * mean));
|
|
115
|
-
return stddev >= MIN_STDDEV && white / count < MAX_FLAT_RATIO && black / count < MAX_FLAT_RATIO;
|
|
116
|
-
}
|
|
117
|
-
catch {
|
|
118
|
-
return false;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
import type { Platform } from '../types.js';
|
|
2
|
-
import type { BrowserDriver, PlayableArtifact, RuntimeViewport, ValidationResult } from './types.js';
|
|
3
|
-
/**
|
|
4
|
-
* `runtime-load` rules: open the artifact in a headless browser without playing it. All network
|
|
5
|
-
* access outside the artifact is blocked, store-opening calls are recorded instead of followed,
|
|
6
|
-
* and the CTA chain is exercised through whichever CTA entry the artifact has: adsdk's
|
|
7
|
-
* `window.PlayableSDK`, or the platform-injected CTA adapter's `window.PlayCraftCTA`. Either is
|
|
8
|
-
* accepted; what matters is that the CTA reaches the channel's store API.
|
|
9
|
-
*/
|
|
10
|
-
export declare const RUNTIME_LOAD_RULE_IDS: {
|
|
11
|
-
readonly pageLoads: "common.runtime.page.loads";
|
|
12
|
-
readonly requests: "common.runtime.requests.resolved";
|
|
13
|
-
readonly csp: "common.runtime.csp.clean";
|
|
14
|
-
readonly errors: "common.runtime.errors.none";
|
|
15
|
-
readonly firstFrame: "common.runtime.first-frame.content";
|
|
16
|
-
readonly ctaEntry: "common.runtime.cta.entry";
|
|
17
|
-
readonly startSignal: "common.runtime.start-signal.sent";
|
|
18
|
-
readonly noAutoRedirect: "common.runtime.redirect.none-on-load";
|
|
19
|
-
readonly ctaRouted: "common.runtime.cta.routed";
|
|
20
|
-
readonly ctaStoreUrl: "common.runtime.cta.store-url";
|
|
21
|
-
readonly viewportCanvasFit: "common.runtime.viewport.canvas-fit";
|
|
22
|
-
readonly viewportOverflow: "common.runtime.viewport.no-overflow";
|
|
23
|
-
readonly viewportErrors: "common.runtime.viewport.errors";
|
|
24
|
-
readonly viewportContent: "common.runtime.viewport.content";
|
|
25
|
-
readonly firstTap: "common.runtime.interaction.first-tap";
|
|
26
|
-
readonly webgl: "common.runtime.environment.webgl";
|
|
27
|
-
};
|
|
28
|
-
export type RuntimeLoadRuleId = (typeof RUNTIME_LOAD_RULE_IDS)[keyof typeof RUNTIME_LOAD_RULE_IDS];
|
|
29
|
-
export interface RuntimeViewportPreset {
|
|
30
|
-
/** Shown in evidence, e.g. `iphone16 portrait`. */
|
|
31
|
-
name: string;
|
|
32
|
-
viewport: RuntimeViewport;
|
|
33
|
-
}
|
|
34
|
-
export interface RuntimeLoadOptions {
|
|
35
|
-
driver: BrowserDriver;
|
|
36
|
-
profile: Platform;
|
|
37
|
-
/**
|
|
38
|
-
* Viewports to open the artifact in. The first one also runs the CTA checks. Callers pass
|
|
39
|
-
* presets from `@playcraft/common/preview/preview-devices`; default is one phone portrait.
|
|
40
|
-
*/
|
|
41
|
-
viewports?: RuntimeViewportPreset[];
|
|
42
|
-
/** Wait after the load event before inspecting the page. Default 1500 ms. */
|
|
43
|
-
settleMs?: number;
|
|
44
|
-
/** Navigation timeout. Default 15000 ms. */
|
|
45
|
-
timeoutMs?: number;
|
|
46
|
-
/**
|
|
47
|
-
* Receives what the main viewport recorded, with page exceptions kept apart from other errors,
|
|
48
|
-
* so a caller such as export validation can apply its own policy and keep the evidence.
|
|
49
|
-
*/
|
|
50
|
-
onDiagnostics?: (diagnostics: RuntimeLoadDiagnostics) => void;
|
|
51
|
-
}
|
|
52
|
-
/** Raw observations of the main viewport, for callers that keep their own report. */
|
|
53
|
-
export interface RuntimeLoadDiagnostics {
|
|
54
|
-
viewport: RuntimeViewport;
|
|
55
|
-
loaded: boolean;
|
|
56
|
-
loadError?: string;
|
|
57
|
-
pageErrors: Array<{
|
|
58
|
-
message: string;
|
|
59
|
-
stack?: string;
|
|
60
|
-
}>;
|
|
61
|
-
rejections: Array<{
|
|
62
|
-
message: string;
|
|
63
|
-
stack?: string;
|
|
64
|
-
}>;
|
|
65
|
-
consoleErrors: string[];
|
|
66
|
-
failedRequests: Array<{
|
|
67
|
-
url: string;
|
|
68
|
-
reason: string;
|
|
69
|
-
}>;
|
|
70
|
-
blockedRequests: string[];
|
|
71
|
-
containerRequests: string[];
|
|
72
|
-
crashed: boolean;
|
|
73
|
-
/** `false` when the browser offered no WebGL context. */
|
|
74
|
-
webgl?: boolean;
|
|
75
|
-
/** Whether the first-tap check ran. */
|
|
76
|
-
tapped: boolean;
|
|
77
|
-
/** Errors raised after the first tap. */
|
|
78
|
-
afterTapErrors: string[];
|
|
79
|
-
screenshot?: Buffer;
|
|
80
|
-
}
|
|
81
|
-
export declare const RUNTIME_ORIGIN = "http://artifact.playcraft-qa.test";
|
|
82
|
-
/** Same-origin artifact files and inline data only; no network, workers or frames. */
|
|
83
|
-
export declare const RUNTIME_CSP: string;
|
|
84
|
-
/**
|
|
85
|
-
* A channel container lets the ad SDK report to its servers, so writes may connect out; the driver
|
|
86
|
-
* answers them locally (`containerTelemetry`), and remote reads are still blocked and reported.
|
|
87
|
-
*/
|
|
88
|
-
export declare const RUNTIME_CONTAINER_CSP: string;
|
|
89
|
-
export declare function channelGlobalsFor(profile: Platform): string[];
|
|
90
|
-
/** Names of the viewports `runRuntimeLoadChecks` opens, for reports. */
|
|
91
|
-
export declare function runtimeViewportNames(viewports?: RuntimeViewportPreset[]): string[];
|
|
92
|
-
/**
|
|
93
|
-
* Opens the artifact in a headless browser and returns every `runtime-load` result. When the page
|
|
94
|
-
* does not load, only the page-load result is returned.
|
|
95
|
-
*/
|
|
96
|
-
export declare function runRuntimeLoadChecks(artifact: PlayableArtifact, options: RuntimeLoadOptions): Promise<ValidationResult[]>;
|
|
97
|
-
/**
|
|
98
|
-
* Script injected before any page script during runtime QA. It records, without side effects:
|
|
99
|
-
* store-opening calls (channel SDK APIs, `window.open`, `postMessage('download')`), adsdk events
|
|
100
|
-
* (via `window.PlayableSDK.on`), and CSP violations. Results live on `window.__PLAYCRAFT_QA__`.
|
|
101
|
-
*
|
|
102
|
-
* adsdk picks the channel from build-time constants (`AD_NETWORK`, `AD_PROTOCOL`) and only checks
|
|
103
|
-
* that the channel's global exists. The platform CTA adapter instead picks the channel by which
|
|
104
|
-
* global exists, so only the profile's own channel globals are stubbed (`channelGlobalsFor`).
|
|
105
|
-
* Stubs are defined only when the page has none, matching the platform fallbacks in
|
|
106
|
-
* `packages/build/src/platforms/*.ts`.
|
|
107
|
-
*/
|
|
108
|
-
/** adsdk events the probe subscribes to. */
|
|
109
|
-
export declare const ADSDK_PROBE_EVENTS: readonly ["playcraftInit", "playcraftReady", "playcraftStart", "playcraftInteractive", "playcraftFinish", "playcraftInstall"];
|
|
110
|
-
export interface RuntimeProbeOptions {
|
|
111
|
-
/** Channel SDK globals to install recording stubs for; see `channelGlobalsFor`. */
|
|
112
|
-
channelGlobals: string[];
|
|
113
|
-
}
|
|
114
|
-
export interface RuntimeProbeCall {
|
|
115
|
-
api: string;
|
|
116
|
-
url?: string;
|
|
117
|
-
at: number;
|
|
118
|
-
}
|
|
119
|
-
export interface RuntimeProbeState {
|
|
120
|
-
calls: RuntimeProbeCall[];
|
|
121
|
-
events: Array<{
|
|
122
|
-
name: string;
|
|
123
|
-
at: number;
|
|
124
|
-
}>;
|
|
125
|
-
csp: Array<{
|
|
126
|
-
blockedURI: string;
|
|
127
|
-
violatedDirective: string;
|
|
128
|
-
}>;
|
|
129
|
-
sdk: boolean;
|
|
130
|
-
/** The platform CTA adapter (`window.PlayCraftCTA.jump`) is present. */
|
|
131
|
-
adapter: boolean;
|
|
132
|
-
/** The export wrote store links for the CTA adapter (`window.__PLAYCRAFT_STORE_URLS__`). */
|
|
133
|
-
storeUrls: boolean;
|
|
134
|
-
/** Messages of unhandled Promise rejections. */
|
|
135
|
-
rejections?: string[];
|
|
136
|
-
/** Stacks of those rejections, in the same order; empty when the reason was not an Error. */
|
|
137
|
-
rejectionStacks?: string[];
|
|
138
|
-
/** Host-app bridge addresses (`bytedance://`, `nativeapp://`) a frame tried to open; stopped. */
|
|
139
|
-
bridge?: string[];
|
|
140
|
-
}
|
|
141
|
-
export declare function buildRuntimeProbeScript(options: RuntimeProbeOptions): string;
|