@playcraft/build 0.2.14 → 0.2.15-test-a
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/audio-source-files.d.ts +5 -0
- package/dist/audio-source-files.js +135 -0
- package/dist/base-builder.js +41 -2
- package/dist/delivery/agent-build-runner.d.ts +44 -0
- package/dist/delivery/agent-build-runner.js +365 -0
- package/dist/delivery/agent-build-source.d.ts +8 -0
- package/dist/delivery/agent-build-source.js +25 -0
- package/dist/delivery/artifact-descriptor.d.ts +31 -0
- package/dist/delivery/artifact-descriptor.js +237 -0
- package/dist/delivery/artifact-package.d.ts +43 -0
- package/dist/delivery/artifact-package.js +283 -0
- package/dist/delivery/build-plan.d.ts +4 -0
- package/dist/delivery/build-plan.js +189 -0
- package/dist/delivery/build-plan.types.d.ts +51 -0
- package/dist/delivery/build-plan.types.js +1 -0
- package/dist/delivery/command-isolation.d.ts +21 -0
- package/dist/delivery/command-isolation.js +327 -0
- package/dist/delivery/commands.d.ts +5 -0
- package/dist/delivery/commands.js +146 -0
- package/dist/delivery/files.d.ts +9 -0
- package/dist/delivery/files.js +144 -0
- package/dist/delivery/git-source-fingerprint.d.ts +2 -0
- package/dist/delivery/git-source-fingerprint.js +58 -0
- package/dist/delivery/isolated-source.d.ts +5 -0
- package/dist/delivery/isolated-source.js +131 -0
- package/dist/delivery/output-publication.d.ts +21 -0
- package/dist/delivery/output-publication.js +444 -0
- package/dist/delivery/project-delivery.d.ts +6 -0
- package/dist/delivery/project-delivery.js +287 -0
- package/dist/delivery/recipe-build-plan.d.ts +4 -0
- package/dist/delivery/recipe-build-plan.js +53 -0
- package/dist/delivery/recipe.d.ts +20 -0
- package/dist/delivery/recipe.js +211 -0
- package/dist/delivery/safe-path.d.ts +2 -0
- package/dist/delivery/safe-path.js +18 -0
- package/dist/delivery/types.d.ts +76 -0
- package/dist/delivery/types.js +1 -0
- package/dist/engines/engine-detector.js +4 -0
- package/dist/engines/generic-adapter.js +14 -19
- package/dist/engines/playable-scripts-adapter.js +2 -5
- package/dist/index.d.ts +21 -4
- package/dist/index.js +12 -2
- package/dist/platforms/adikteev.js +1 -0
- package/dist/platforms/applovin.js +1 -0
- package/dist/platforms/base.d.ts +4 -0
- package/dist/platforms/base.js +25 -6
- package/dist/platforms/bigo.js +1 -0
- package/dist/platforms/facebook.js +1 -0
- package/dist/platforms/google.js +1 -0
- package/dist/platforms/inmobi.js +1 -0
- package/dist/platforms/ironsource.js +1 -0
- package/dist/platforms/liftoff.js +1 -0
- package/dist/platforms/mintegral.js +1 -0
- package/dist/platforms/moloco.js +1 -0
- package/dist/platforms/playcraft.js +1 -0
- package/dist/platforms/remerge.js +1 -0
- package/dist/platforms/snapchat.js +1 -0
- package/dist/platforms/tiktok.js +1 -0
- package/dist/platforms/unity.js +1 -0
- package/dist/production-animation-presence.d.ts +2 -0
- package/dist/production-animation-presence.js +146 -0
- package/dist/production-inputs.d.ts +30 -0
- package/dist/production-inputs.js +262 -0
- package/dist/production-source-paths.d.ts +5 -0
- package/dist/production-source-paths.js +27 -0
- package/dist/redirect-policy.d.ts +23 -0
- package/dist/redirect-policy.js +25 -0
- package/dist/types.d.ts +10 -2
- package/dist/validation/artifact-qa.d.ts +36 -0
- package/dist/validation/artifact-qa.js +263 -0
- package/dist/validation/artifact-rules.d.ts +39 -0
- package/dist/validation/artifact-rules.js +451 -0
- package/dist/validation/artifact.d.ts +14 -0
- package/dist/validation/artifact.js +188 -0
- package/dist/validation/html-validator.d.ts +5 -0
- package/dist/validation/html-validator.js +19 -17
- package/dist/validation/index.d.ts +5 -0
- package/dist/validation/index.js +5 -0
- package/dist/validation/package-validator.d.ts +2 -0
- package/dist/validation/package-validator.js +25 -64
- package/dist/validation/playwright-driver.d.ts +37 -0
- package/dist/validation/playwright-driver.js +302 -0
- package/dist/validation/profiles.d.ts +13 -1
- package/dist/validation/profiles.js +27 -0
- package/dist/validation/runtime-cover.d.ts +32 -0
- package/dist/validation/runtime-cover.js +120 -0
- package/dist/validation/runtime-load.d.ts +141 -0
- package/dist/validation/runtime-load.js +812 -0
- package/dist/validation/source-scanner.d.ts +11 -0
- package/dist/validation/source-scanner.js +32 -2
- package/dist/validation/types.d.ts +201 -2
- package/dist/validation/types.js +1 -1
- package/dist/validation/validation-runner.d.ts +22 -2
- package/dist/validation/validation-runner.js +64 -3
- package/dist/validation/zip-reader.d.ts +7 -0
- package/dist/validation/zip-reader.js +159 -26
- package/dist/vite/config-builder-generic.d.ts +3 -1
- package/dist/vite/config-builder-generic.js +9 -7
- package/dist/vite/config-builder.js +1 -1
- package/dist/vite/plugin-platform.js +16 -30
- package/dist/vite/plugin-source-builder.d.ts +2 -14
- package/dist/vite/plugin-source-builder.js +61 -997
- package/dist/vite/source-builder-asset-paths.d.ts +25 -0
- package/dist/vite/source-builder-asset-paths.js +154 -0
- package/dist/vite/source-builder-esm.d.ts +7 -0
- package/dist/vite/source-builder-esm.js +877 -0
- package/dist/vite/source-builder-types.d.ts +14 -0
- package/dist/vite/source-builder-types.js +1 -0
- package/dist/vite/workspace.d.ts +6 -0
- package/dist/vite/workspace.js +41 -0
- package/dist/vite-builder.d.ts +4 -5
- package/dist/vite-builder.js +33 -34
- package/dist/workspace-css-imports.d.ts +2 -0
- package/dist/workspace-css-imports.js +139 -0
- package/dist/workspace-model-source.d.ts +14 -0
- package/dist/workspace-model-source.js +184 -0
- package/dist/workspace-public-imports.d.ts +11 -0
- package/dist/workspace-public-imports.js +232 -0
- package/dist/workspace-public-source.d.ts +15 -0
- package/dist/workspace-public-source.js +564 -0
- package/package.json +30 -4
- package/templates/patches/playcraft-redirect-policy.js +115 -0
|
@@ -3,31 +3,33 @@ import { getRulesForStage } from './profiles.js';
|
|
|
3
3
|
const RESOURCE_ATTR_RE = /\b(?:src|href|data)\s*=\s*["']([^"']+)["']/gi;
|
|
4
4
|
const CSS_URL_RE = /url\(\s*["']?([^"')]+)["']?\s*\)/gi;
|
|
5
5
|
export async function validateHtmlArtifact(context, profile) {
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
if (context.htmlContent !== undefined) {
|
|
7
|
+
return validateHtmlArtifactContent(context, context.htmlContent, context.htmlPath, profile);
|
|
8
|
+
}
|
|
8
9
|
if (!context.htmlPath) {
|
|
9
10
|
return [missingHtmlResult(context.channel)];
|
|
10
11
|
}
|
|
11
|
-
let artifact;
|
|
12
12
|
try {
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
fs.stat(context.htmlPath),
|
|
16
|
-
]);
|
|
17
|
-
artifact = {
|
|
18
|
-
path: context.htmlPath,
|
|
19
|
-
content,
|
|
20
|
-
size: stat.size,
|
|
21
|
-
};
|
|
13
|
+
const content = await fs.readFile(context.htmlPath);
|
|
14
|
+
return validateHtmlArtifactContent(context, content, context.htmlPath, profile);
|
|
22
15
|
}
|
|
23
16
|
catch (error) {
|
|
24
17
|
return [missingHtmlResult(context.channel, context.htmlPath, error)];
|
|
25
18
|
}
|
|
19
|
+
}
|
|
20
|
+
/** Validates the exact final bytes, including objects downloaded by Business. */
|
|
21
|
+
export function validateHtmlArtifactContent(context, content, displayPath = 'index.html', profile) {
|
|
22
|
+
const rules = profile?.rules.filter((rule) => rule.stage === 'html-artifact')
|
|
23
|
+
?? getRulesForStage(context.channel, 'html-artifact');
|
|
24
|
+
const artifact = {
|
|
25
|
+
path: displayPath,
|
|
26
|
+
content: typeof content === 'string' ? content : Buffer.from(content).toString('utf-8'),
|
|
27
|
+
size: typeof content === 'string' ? Buffer.byteLength(content) : content.byteLength,
|
|
28
|
+
};
|
|
26
29
|
const results = [];
|
|
27
30
|
for (const rule of rules) {
|
|
28
|
-
if (!rule.detectable || !rule.check)
|
|
31
|
+
if (!rule.detectable || !rule.check)
|
|
29
32
|
continue;
|
|
30
|
-
}
|
|
31
33
|
results.push(evaluateHtmlRule(rule, artifact));
|
|
32
34
|
}
|
|
33
35
|
return results;
|
|
@@ -87,10 +89,10 @@ function resultFromBoolean(rule, passed, file, evidence) {
|
|
|
87
89
|
confidence: rule.confidence,
|
|
88
90
|
};
|
|
89
91
|
}
|
|
90
|
-
function collectExternalResources(html) {
|
|
92
|
+
export function collectExternalResources(html) {
|
|
91
93
|
return collectUrls(html).filter((url) => /^https?:\/\//i.test(url) || /^\/\//.test(url));
|
|
92
94
|
}
|
|
93
|
-
function collectLocalResourceReferences(html) {
|
|
95
|
+
export function collectLocalResourceReferences(html) {
|
|
94
96
|
return collectUrls(html).filter((url) => {
|
|
95
97
|
if (isInlineOrSpecialUrl(url))
|
|
96
98
|
return false;
|
|
@@ -114,7 +116,7 @@ function collectUrls(html) {
|
|
|
114
116
|
function isInlineOrSpecialUrl(url) {
|
|
115
117
|
return /^(data:|blob:|javascript:|mailto:|tel:|about:)/i.test(url);
|
|
116
118
|
}
|
|
117
|
-
function isAllowedExternalResource(url, allowedPatterns) {
|
|
119
|
+
export function isAllowedExternalResource(url, allowedPatterns) {
|
|
118
120
|
if (!allowedPatterns || allowedPatterns.length === 0) {
|
|
119
121
|
return false;
|
|
120
122
|
}
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
export * from './types.js';
|
|
2
|
+
export * from './artifact.js';
|
|
3
|
+
export * from './artifact-rules.js';
|
|
4
|
+
export * from './artifact-qa.js';
|
|
5
|
+
export * from './runtime-load.js';
|
|
2
6
|
export * from './profiles.js';
|
|
3
7
|
export * from './html-validator.js';
|
|
4
8
|
export * from './package-validator.js';
|
|
@@ -6,3 +10,4 @@ export * from './reporter.js';
|
|
|
6
10
|
export * from './source-scanner.js';
|
|
7
11
|
export * from './validation-runner.js';
|
|
8
12
|
export * from './zip-reader.js';
|
|
13
|
+
export * from './runtime-cover.js';
|
package/dist/validation/index.js
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
export * from './types.js';
|
|
2
|
+
export * from './artifact.js';
|
|
3
|
+
export * from './artifact-rules.js';
|
|
4
|
+
export * from './artifact-qa.js';
|
|
5
|
+
export * from './runtime-load.js';
|
|
2
6
|
export * from './profiles.js';
|
|
3
7
|
export * from './html-validator.js';
|
|
4
8
|
export * from './package-validator.js';
|
|
@@ -6,3 +10,4 @@ export * from './reporter.js';
|
|
|
6
10
|
export * from './source-scanner.js';
|
|
7
11
|
export * from './validation-runner.js';
|
|
8
12
|
export * from './zip-reader.js';
|
|
13
|
+
export * from './runtime-cover.js';
|
|
@@ -1,2 +1,4 @@
|
|
|
1
|
+
import type { Platform } from '../types.js';
|
|
1
2
|
import type { ChannelRuleProfile, ValidationContext, ValidationResult } from './types.js';
|
|
2
3
|
export declare function validateDeliveryPackage(context: ValidationContext, profile?: ChannelRuleProfile): Promise<ValidationResult[]>;
|
|
4
|
+
export declare function validateSingleHtmlPackage(channel: Platform, bytes: Uint8Array, artifactName?: string): ValidationResult[];
|
|
@@ -2,10 +2,11 @@ import fs from 'fs/promises';
|
|
|
2
2
|
import fsSync from 'fs';
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import { getChannelRuleProfile } from './profiles.js';
|
|
5
|
+
import { directorySize, listDirectoryEntries } from './artifact.js';
|
|
5
6
|
import { SimpleZipReader } from './zip-reader.js';
|
|
6
7
|
const FIVE_MB = 5 * 1024 * 1024;
|
|
7
8
|
export async function validateDeliveryPackage(context, profile = getChannelRuleProfile(context.channel)) {
|
|
8
|
-
if (!context.packagePath) {
|
|
9
|
+
if (!context.packagePath && !context.packageBytes) {
|
|
9
10
|
return [{
|
|
10
11
|
ruleId: `${context.channel}.package.path.required`,
|
|
11
12
|
channel: context.channel,
|
|
@@ -18,9 +19,10 @@ export async function validateDeliveryPackage(context, profile = getChannelRuleP
|
|
|
18
19
|
confidence: 'high',
|
|
19
20
|
}];
|
|
20
21
|
}
|
|
22
|
+
const packagePath = context.packagePath ?? 'delivery.zip';
|
|
21
23
|
let inventory;
|
|
22
24
|
try {
|
|
23
|
-
inventory = await readPackageInventory(context.
|
|
25
|
+
inventory = await readPackageInventory(packagePath, context.packageBytes);
|
|
24
26
|
}
|
|
25
27
|
catch (error) {
|
|
26
28
|
return [{
|
|
@@ -29,9 +31,9 @@ export async function validateDeliveryPackage(context, profile = getChannelRuleP
|
|
|
29
31
|
stage: 'delivery-package',
|
|
30
32
|
severity: 'error',
|
|
31
33
|
status: 'fail',
|
|
32
|
-
message: `Delivery package is not readable: ${
|
|
34
|
+
message: `Delivery package is not readable: ${packagePath}`,
|
|
33
35
|
recommendation: 'Verify the generated ZIP or delivery directory exists and is readable.',
|
|
34
|
-
file:
|
|
36
|
+
file: packagePath,
|
|
35
37
|
evidence: error instanceof Error ? error.message : String(error),
|
|
36
38
|
owner: 'playcraft-delivery',
|
|
37
39
|
confidence: 'high',
|
|
@@ -62,18 +64,26 @@ export async function validateDeliveryPackage(context, profile = getChannelRuleP
|
|
|
62
64
|
}
|
|
63
65
|
return results;
|
|
64
66
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
67
|
+
export function validateSingleHtmlPackage(channel, bytes, artifactName = 'index.html') {
|
|
68
|
+
return [
|
|
69
|
+
boolResult(channel, 'package.size.max-5mb', bytes.byteLength <= FIVE_MB, 'Delivery HTML should be smaller than 5 MB.', 'Reduce artifact size or inline assets more aggressively.', artifactName, `actual=${bytes.byteLength}, limit=${FIVE_MB}`),
|
|
70
|
+
boolResult(channel, 'package.single-html.required', bytes.byteLength > 0 && artifactName.toLowerCase().endsWith('.html'), 'Delivery must be one nonempty HTML file.', 'Provide exactly one nonempty HTML artifact.', artifactName),
|
|
71
|
+
];
|
|
72
|
+
}
|
|
73
|
+
async function readPackageInventory(packagePath, packageBytes) {
|
|
74
|
+
if (packageBytes === undefined) {
|
|
75
|
+
const stat = await fs.stat(packagePath);
|
|
76
|
+
if (stat.isDirectory()) {
|
|
77
|
+
const entries = await listDirectoryEntries(packagePath);
|
|
78
|
+
return {
|
|
79
|
+
packagePath,
|
|
80
|
+
entries,
|
|
81
|
+
readText: (entryPath) => readTextFromDirectorySyncUnsupported(packagePath, entryPath),
|
|
82
|
+
size: await directorySize(packagePath),
|
|
83
|
+
};
|
|
84
|
+
}
|
|
75
85
|
}
|
|
76
|
-
const buffer = await fs.readFile(packagePath);
|
|
86
|
+
const buffer = packageBytes === undefined ? await fs.readFile(packagePath) : Buffer.from(packageBytes);
|
|
77
87
|
const zip = new SimpleZipReader(buffer);
|
|
78
88
|
return {
|
|
79
89
|
packagePath,
|
|
@@ -82,38 +92,6 @@ async function readPackageInventory(packagePath) {
|
|
|
82
92
|
size: buffer.length,
|
|
83
93
|
};
|
|
84
94
|
}
|
|
85
|
-
async function readDirectoryEntries(dir) {
|
|
86
|
-
const entries = [];
|
|
87
|
-
const walk = async (current) => {
|
|
88
|
-
const dirEntries = await fs.readdir(current, { withFileTypes: true });
|
|
89
|
-
for (const entry of dirEntries) {
|
|
90
|
-
const fullPath = path.join(current, entry.name);
|
|
91
|
-
const relative = path.relative(dir, fullPath).replace(/\\/g, '/');
|
|
92
|
-
if (entry.isDirectory()) {
|
|
93
|
-
entries.push({
|
|
94
|
-
path: `${relative}/`,
|
|
95
|
-
compressedSize: 0,
|
|
96
|
-
uncompressedSize: 0,
|
|
97
|
-
compressionMethod: 0,
|
|
98
|
-
isDirectory: true,
|
|
99
|
-
});
|
|
100
|
-
await walk(fullPath);
|
|
101
|
-
}
|
|
102
|
-
else {
|
|
103
|
-
const stat = await fs.stat(fullPath);
|
|
104
|
-
entries.push({
|
|
105
|
-
path: relative,
|
|
106
|
-
compressedSize: stat.size,
|
|
107
|
-
uncompressedSize: stat.size,
|
|
108
|
-
compressionMethod: 0,
|
|
109
|
-
isDirectory: false,
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
};
|
|
114
|
-
await walk(dir);
|
|
115
|
-
return entries;
|
|
116
|
-
}
|
|
117
95
|
function readTextFromDirectorySyncUnsupported(_packagePath, _entryPath) {
|
|
118
96
|
const filePath = path.join(_packagePath, _entryPath);
|
|
119
97
|
try {
|
|
@@ -123,23 +101,6 @@ function readTextFromDirectorySyncUnsupported(_packagePath, _entryPath) {
|
|
|
123
101
|
return null;
|
|
124
102
|
}
|
|
125
103
|
}
|
|
126
|
-
async function calculateDirectorySize(dir) {
|
|
127
|
-
let total = 0;
|
|
128
|
-
const walk = async (current) => {
|
|
129
|
-
const entries = await fs.readdir(current, { withFileTypes: true });
|
|
130
|
-
for (const entry of entries) {
|
|
131
|
-
const fullPath = path.join(current, entry.name);
|
|
132
|
-
if (entry.isDirectory()) {
|
|
133
|
-
await walk(fullPath);
|
|
134
|
-
}
|
|
135
|
-
else {
|
|
136
|
-
total += (await fs.stat(fullPath)).size;
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
};
|
|
140
|
-
await walk(dir);
|
|
141
|
-
return total;
|
|
142
|
-
}
|
|
143
104
|
function validateZipLikePackage(channel, inventory) {
|
|
144
105
|
const paths = new Set(inventory.entries.map((entry) => entry.path));
|
|
145
106
|
return [
|
|
@@ -0,0 +1,37 @@
|
|
|
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;
|
|
@@ -0,0 +1,302 @@
|
|
|
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,5 +1,17 @@
|
|
|
1
|
-
import type { Platform } from '../types.js';
|
|
1
|
+
import type { OutputFormat, Platform } from '../types.js';
|
|
2
2
|
import type { ChannelRuleProfile, ValidationRule, ValidationStage } from './types.js';
|
|
3
3
|
export declare const CHANNEL_RULE_PROFILES: Record<Platform, ChannelRuleProfile>;
|
|
4
4
|
export declare function getChannelRuleProfile(channel: Platform): ChannelRuleProfile;
|
|
5
5
|
export declare function getRulesForStage(channel: Platform, stage: ValidationStage): ValidationRule[];
|
|
6
|
+
export declare const CHANNEL_RULES_VERSION = "channel-rules-v1";
|
|
7
|
+
export type ChannelCapability = {
|
|
8
|
+
channel: Platform;
|
|
9
|
+
channelRulesVersion: typeof CHANNEL_RULES_VERSION;
|
|
10
|
+
supportedFormats: OutputFormat[];
|
|
11
|
+
packageStrategy: 'single-html' | 'normalized-zip' | 'format-dependent';
|
|
12
|
+
rootEntryRequired: boolean;
|
|
13
|
+
maxFiles?: number;
|
|
14
|
+
maxArtifactBytes?: number;
|
|
15
|
+
};
|
|
16
|
+
/** Versioned delivery facts shared by Runner packaging and Business revalidation. */
|
|
17
|
+
export declare function getChannelCapability(channel: Platform): ChannelCapability;
|
|
@@ -219,3 +219,30 @@ export function getChannelRuleProfile(channel) {
|
|
|
219
219
|
export function getRulesForStage(channel, stage) {
|
|
220
220
|
return getChannelRuleProfile(channel).rules.filter((rule) => rule.stage === stage);
|
|
221
221
|
}
|
|
222
|
+
export const CHANNEL_RULES_VERSION = 'channel-rules-v1';
|
|
223
|
+
/** Versioned delivery facts shared by Runner packaging and Business revalidation. */
|
|
224
|
+
export function getChannelCapability(channel) {
|
|
225
|
+
const profile = getChannelRuleProfile(channel);
|
|
226
|
+
const supportsZip = profile.deliveryMode === 'zip' ||
|
|
227
|
+
profile.deliveryMode === 'html-backed-zip' ||
|
|
228
|
+
profile.deliveryMode === 'mixed';
|
|
229
|
+
const supportsHtml = profile.deliveryMode === 'single-html' || profile.deliveryMode === 'mixed';
|
|
230
|
+
return {
|
|
231
|
+
channel,
|
|
232
|
+
channelRulesVersion: CHANNEL_RULES_VERSION,
|
|
233
|
+
supportedFormats: [
|
|
234
|
+
...(supportsHtml ? ['html'] : []),
|
|
235
|
+
...(supportsZip ? ['zip'] : []),
|
|
236
|
+
],
|
|
237
|
+
packageStrategy: profile.deliveryMode === 'mixed'
|
|
238
|
+
? 'format-dependent'
|
|
239
|
+
: profile.deliveryMode === 'single-html'
|
|
240
|
+
? 'single-html'
|
|
241
|
+
: 'normalized-zip',
|
|
242
|
+
rootEntryRequired: supportsZip,
|
|
243
|
+
...(channel === 'google' ? { maxFiles: 512 } : {}),
|
|
244
|
+
...(profile.rules.some((rule) => rule.check?.kind === 'max-size')
|
|
245
|
+
? { maxArtifactBytes: FIVE_MB }
|
|
246
|
+
: {}),
|
|
247
|
+
};
|
|
248
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
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>;
|