@mizchi/vlmkit-capture 0.9.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/dist/capture-config.d.mts +5 -5
- package/dist/capture-config.mjs +31 -17
- package/dist/capturer.d.mts +1 -1
- package/dist/capturer.mjs +4 -3
- package/dist/crater-smoke.d.mts +9 -3
- package/dist/crater-smoke.mjs +22 -41
- package/dist/gates/crater.gate.d.mts +12 -0
- package/dist/gates/crater.gate.mjs +103 -0
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +2 -2
- package/dist/playwright-launch-error.d.mts +15 -1
- package/dist/playwright-launch-error.mjs +17 -1
- package/dist/route-capture.d.mts +87 -0
- package/dist/route-capture.mjs +198 -0
- package/package.json +6 -4
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Playwright / Crater capture infrastructure for VRT — viewport discovery,
|
|
4
4
|
multi-route capture, prescanner integration.
|
|
5
5
|
|
|
6
|
-
Part of the [`vlmkit`](https://github.com/mizchi/
|
|
6
|
+
Part of the [`vlmkit`](https://github.com/mizchi/vlmkit) monorepo.
|
|
7
7
|
|
|
8
8
|
## Install
|
|
9
9
|
|
|
@@ -24,7 +24,7 @@ const { viewports, breakpoints } = discoverViewports(html, {
|
|
|
24
24
|
|
|
25
25
|
const routeSet = resolveCaptureRoutes({
|
|
26
26
|
cwd: process.cwd(),
|
|
27
|
-
configPath: "
|
|
27
|
+
configPath: "vlmkit.config.json",
|
|
28
28
|
});
|
|
29
29
|
```
|
|
30
30
|
|
|
@@ -39,7 +39,7 @@ import { capturePage } from "@mizchi/vlmkit-capture/capturer.ts";
|
|
|
39
39
|
|
|
40
40
|
| Module | Purpose |
|
|
41
41
|
|---|---|
|
|
42
|
-
| `capture-config` | `
|
|
42
|
+
| `capture-config` | `vlmkit.config.json` resolution + route schema. |
|
|
43
43
|
| `viewport-discovery` | Parse CSS media queries to suggest test viewports. |
|
|
44
44
|
| `crater-client` | Bidi-protocol client for the Crater browser engine. |
|
|
45
45
|
| `playwright-analyzer` | Auto-detect Playwright config from project. |
|
|
@@ -18,10 +18,10 @@ declare const DEFAULT_CAPTURE_BASE_URL = "http://127.0.0.1:4174";
|
|
|
18
18
|
/**
|
|
19
19
|
* Built-in fallback used when no config or env override is provided.
|
|
20
20
|
* Kept for vlmkit's own development workflow; external projects should
|
|
21
|
-
* supply their own routes via `
|
|
21
|
+
* supply their own routes via `vlmkit.config.json`.
|
|
22
22
|
*/
|
|
23
23
|
declare const DEFAULT_CAPTURE_ROUTES: CaptureRoute[];
|
|
24
|
-
declare const DEFAULT_CAPTURE_CONFIG_FILE = "
|
|
24
|
+
declare const DEFAULT_CAPTURE_CONFIG_FILE = "vlmkit.config.json";
|
|
25
25
|
declare function parseCaptureConfig(raw: string): CaptureConfig;
|
|
26
26
|
declare function routeNameFromPath(path: string): string;
|
|
27
27
|
interface LoadCaptureConfigOptions {
|
|
@@ -35,9 +35,9 @@ interface LoadCaptureConfigOptions {
|
|
|
35
35
|
* Resolve the route set to use for a capture run.
|
|
36
36
|
*
|
|
37
37
|
* Precedence (highest first):
|
|
38
|
-
* 1. `
|
|
39
|
-
* 2. Explicit config path (CLI / `
|
|
40
|
-
* 3. `
|
|
38
|
+
* 1. `VLMKIT_CAPTURE_ROUTES` env var (JSON-encoded array)
|
|
39
|
+
* 2. Explicit config path (CLI / `VLMKIT_CONFIG_PATH`)
|
|
40
|
+
* 3. `vlmkit.config.json` discovered in `cwd`
|
|
41
41
|
* 4. Built-in defaults
|
|
42
42
|
*/
|
|
43
43
|
declare function resolveCaptureRoutes(options?: LoadCaptureConfigOptions): CaptureRouteSet;
|
package/dist/capture-config.mjs
CHANGED
|
@@ -4,15 +4,15 @@ import { dirname, isAbsolute, resolve } from "node:path";
|
|
|
4
4
|
/**
|
|
5
5
|
* Capture configuration loader for `vlmkit workflow init|capture`.
|
|
6
6
|
*
|
|
7
|
-
* Allows external projects to drive `e2e/
|
|
8
|
-
* editing the spec by sourcing routes from `
|
|
9
|
-
* file pointed at by `--config` / `
|
|
7
|
+
* Allows external projects to drive `e2e/vlmkit-capture.spec.ts` without
|
|
8
|
+
* editing the spec by sourcing routes from `vlmkit.config.json` (or any
|
|
9
|
+
* file pointed at by `--config` / `VLMKIT_CONFIG_PATH`).
|
|
10
10
|
*/
|
|
11
11
|
const DEFAULT_CAPTURE_BASE_URL = "http://127.0.0.1:4174";
|
|
12
12
|
/**
|
|
13
13
|
* Built-in fallback used when no config or env override is provided.
|
|
14
14
|
* Kept for vlmkit's own development workflow; external projects should
|
|
15
|
-
* supply their own routes via `
|
|
15
|
+
* supply their own routes via `vlmkit.config.json`.
|
|
16
16
|
*/
|
|
17
17
|
const DEFAULT_CAPTURE_ROUTES = [
|
|
18
18
|
{
|
|
@@ -41,7 +41,7 @@ const DEFAULT_CAPTURE_ROUTES = [
|
|
|
41
41
|
waitFor: "main"
|
|
42
42
|
}
|
|
43
43
|
];
|
|
44
|
-
const DEFAULT_CAPTURE_CONFIG_FILE = "
|
|
44
|
+
const DEFAULT_CAPTURE_CONFIG_FILE = "vlmkit.config.json";
|
|
45
45
|
function parseCaptureConfig(raw) {
|
|
46
46
|
let parsed;
|
|
47
47
|
try {
|
|
@@ -51,21 +51,35 @@ function parseCaptureConfig(raw) {
|
|
|
51
51
|
}
|
|
52
52
|
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) throw new Error("Capture config must be an object");
|
|
53
53
|
const record = parsed;
|
|
54
|
-
const baseUrl = record.baseUrl == null ? void 0 : parseNonEmptyString(record.baseUrl, "capture config baseUrl must be a non-empty string");
|
|
55
54
|
const captureSection = record.capture;
|
|
56
55
|
const routesSource = pickRoutesSource(captureSection, record.routes);
|
|
56
|
+
const routes = routesSource === void 0 ? void 0 : parseCaptureRoutes(routesSource);
|
|
57
|
+
const innerBaseUrl = pickCaptureKey(captureSection, "baseUrl");
|
|
58
|
+
const baseUrlSource = innerBaseUrl ? innerBaseUrl.value : record.baseUrl;
|
|
57
59
|
return {
|
|
58
|
-
baseUrl,
|
|
59
|
-
routes
|
|
60
|
+
baseUrl: baseUrlSource == null ? void 0 : parseNonEmptyString(baseUrlSource, "capture config baseUrl must be a non-empty string"),
|
|
61
|
+
routes
|
|
60
62
|
};
|
|
61
63
|
}
|
|
62
64
|
function pickRoutesSource(captureSection, topLevelRoutes) {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
65
|
+
const inner = pickCaptureKey(captureSection, "routes");
|
|
66
|
+
return inner ? inner.value : topLevelRoutes;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* One key out of the `capture` block, wrapped, or `undefined` when the block or the key is
|
|
70
|
+
* absent.
|
|
71
|
+
*
|
|
72
|
+
* Wrapped rather than returned bare so a present-but-`null` value stays distinguishable
|
|
73
|
+
* from an absent one: `"capture": { "routes": null }` must keep reaching
|
|
74
|
+
* `parseCaptureRoutes` and failing loudly, instead of falling through to the top level and
|
|
75
|
+
* being ignored.
|
|
76
|
+
*/
|
|
77
|
+
function pickCaptureKey(captureSection, key) {
|
|
78
|
+
if (captureSection === void 0 || captureSection === null) return void 0;
|
|
79
|
+
if (typeof captureSection !== "object" || Array.isArray(captureSection)) throw new Error("capture config `capture` must be an object");
|
|
80
|
+
const record = captureSection;
|
|
81
|
+
if (!(key in record) || record[key] === void 0) return void 0;
|
|
82
|
+
return { value: record[key] };
|
|
69
83
|
}
|
|
70
84
|
function parseCaptureRoutes(value) {
|
|
71
85
|
if (!Array.isArray(value)) throw new Error("capture config routes must be an array");
|
|
@@ -102,9 +116,9 @@ function routeNameFromPath(path) {
|
|
|
102
116
|
* Resolve the route set to use for a capture run.
|
|
103
117
|
*
|
|
104
118
|
* Precedence (highest first):
|
|
105
|
-
* 1. `
|
|
106
|
-
* 2. Explicit config path (CLI / `
|
|
107
|
-
* 3. `
|
|
119
|
+
* 1. `VLMKIT_CAPTURE_ROUTES` env var (JSON-encoded array)
|
|
120
|
+
* 2. Explicit config path (CLI / `VLMKIT_CONFIG_PATH`)
|
|
121
|
+
* 3. `vlmkit.config.json` discovered in `cwd`
|
|
108
122
|
* 4. Built-in defaults
|
|
109
123
|
*/
|
|
110
124
|
function resolveCaptureRoutes(options = {}) {
|
package/dist/capturer.d.mts
CHANGED
|
@@ -33,7 +33,7 @@ interface ResolvedCaptureBackend {
|
|
|
33
33
|
/**
|
|
34
34
|
* Resolution order:
|
|
35
35
|
* 1. Explicit `--backend` flag
|
|
36
|
-
* 2. `
|
|
36
|
+
* 2. `VLMKIT_CAPTURE_BACKEND` env var
|
|
37
37
|
* 3. Default local
|
|
38
38
|
*
|
|
39
39
|
* For the Cloudflare backend, credentials come from env (`CLOUDFLARE_ACCOUNT_ID`
|
package/dist/capturer.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { chromium } from "playwright";
|
|
2
|
+
import { launchBrowser } from "@mizchi/vlmkit-core/browser-launch.ts";
|
|
2
3
|
//#region src/capturer.ts
|
|
3
4
|
/**
|
|
4
5
|
* Browser launch abstraction.
|
|
@@ -22,7 +23,7 @@ function createLocalCapturer() {
|
|
|
22
23
|
kind: "local",
|
|
23
24
|
label: "local chromium",
|
|
24
25
|
async launch() {
|
|
25
|
-
return
|
|
26
|
+
return launchBrowser();
|
|
26
27
|
},
|
|
27
28
|
async close(browser) {
|
|
28
29
|
await browser.close();
|
|
@@ -51,7 +52,7 @@ function maskAccount(id) {
|
|
|
51
52
|
/**
|
|
52
53
|
* Resolution order:
|
|
53
54
|
* 1. Explicit `--backend` flag
|
|
54
|
-
* 2. `
|
|
55
|
+
* 2. `VLMKIT_CAPTURE_BACKEND` env var
|
|
55
56
|
* 3. Default local
|
|
56
57
|
*
|
|
57
58
|
* For the Cloudflare backend, credentials come from env (`CLOUDFLARE_ACCOUNT_ID`
|
|
@@ -61,7 +62,7 @@ function maskAccount(id) {
|
|
|
61
62
|
function resolveCaptureBackend(options = {}) {
|
|
62
63
|
const env = options.env ?? process.env;
|
|
63
64
|
const explicit = options.backendFlag?.trim().toLowerCase();
|
|
64
|
-
const envChoice = env.
|
|
65
|
+
const envChoice = env.VLMKIT_CAPTURE_BACKEND?.trim().toLowerCase();
|
|
65
66
|
const choice = explicit || envChoice || "local";
|
|
66
67
|
const source = explicit ? "flag" : envChoice ? "env" : "default";
|
|
67
68
|
switch (choice) {
|
package/dist/crater-smoke.d.mts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { RuleView } from "@mizchi/vlmkit-core/plugin/contract.ts";
|
|
2
|
+
|
|
1
3
|
//#region src/crater-smoke.d.ts
|
|
2
4
|
interface CraterSmokeClient {
|
|
3
5
|
connect(): Promise<void>;
|
|
@@ -87,12 +89,16 @@ interface CraterSmokeOptions {
|
|
|
87
89
|
createClient?: (url: string) => CraterSmokeClient;
|
|
88
90
|
}
|
|
89
91
|
declare function runCraterBidiSmoke(options?: CraterSmokeOptions): Promise<CraterSmokeReport>;
|
|
90
|
-
declare function formatCraterSmokeReport(report: CraterSmokeReport): string;
|
|
91
|
-
|
|
92
|
+
declare function formatCraterSmokeReport(report: CraterSmokeReport, rules?: RuleView): string;
|
|
93
|
+
/**
|
|
94
|
+
* Read this gate's own flags. `--help` and `--json` are no longer handled
|
|
95
|
+
* here: the core gate runner owns both, and a parser that called
|
|
96
|
+
* `process.exit(0)` for help could not be used by anything but a CLI.
|
|
97
|
+
*/
|
|
98
|
+
declare function parseCraterSmokeArgs(argv: readonly string[], env?: NodeJS.ProcessEnv | Partial<NodeJS.ProcessEnv>): {
|
|
92
99
|
url: string;
|
|
93
100
|
requireAvailable: boolean;
|
|
94
101
|
deep: boolean;
|
|
95
|
-
json: boolean;
|
|
96
102
|
};
|
|
97
103
|
//#endregion
|
|
98
104
|
export { CraterSmokeCheck, CraterSmokeClient, CraterSmokeOptions, CraterSmokeReport, CraterSmokeStatus, formatCraterSmokeReport, parseCraterSmokeArgs, runCraterBidiSmoke };
|
package/dist/crater-smoke.mjs
CHANGED
|
@@ -1,17 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { CraterClient, isCraterAvailable, resolveCraterBidiUrl } from "./crater-client.mjs";
|
|
3
|
-
import
|
|
4
|
-
import { fileURLToPath } from "node:url";
|
|
5
|
-
import { handleCliError } from "@mizchi/vlmkit-core/cli-error.ts";
|
|
3
|
+
import "node:path";
|
|
6
4
|
import { BOLD, CYAN, DIM, GREEN, RED, RESET, YELLOW } from "@mizchi/vlmkit-core/terminal-colors.ts";
|
|
5
|
+
import { ruleTier } from "@mizchi/vlmkit-core/plugin/rule-tier.ts";
|
|
7
6
|
//#region src/crater-smoke.ts
|
|
8
|
-
/**
|
|
9
|
-
* Crater BiDi smoke check.
|
|
10
|
-
*
|
|
11
|
-
* Verifies the minimum backend contract used by vlmkit:
|
|
12
|
-
* connection, viewport/content load, PNG capture, paint tree capture,
|
|
13
|
-
* computed-style capture, and responsive breakpoint discovery.
|
|
14
|
-
*/
|
|
15
7
|
const DEFAULT_HTML = `<!doctype html>
|
|
16
8
|
<html>
|
|
17
9
|
<head>
|
|
@@ -210,60 +202,49 @@ async function runCraterBidiSmoke(options = {}) {
|
|
|
210
202
|
elapsedMs: now() - start
|
|
211
203
|
};
|
|
212
204
|
}
|
|
213
|
-
function formatCraterSmokeReport(report) {
|
|
205
|
+
function formatCraterSmokeReport(report, rules) {
|
|
214
206
|
const lines = [];
|
|
215
|
-
const
|
|
207
|
+
const checkFailedOff = ruleTier(rules, "check-failed", "suspect") === "off";
|
|
208
|
+
const unavailableOff = ruleTier(rules, "unavailable", "info") === "off";
|
|
209
|
+
const failsShown = report.checks.some((c) => c.status === "fail") && !checkFailedOff;
|
|
210
|
+
const color = report.status === "pass" || !failsShown && report.status === "fail" ? GREEN : report.status === "skip" ? unavailableOff ? DIM : YELLOW : RED;
|
|
216
211
|
lines.push(`${BOLD}${CYAN}vlmkit check crater${RESET}`);
|
|
217
212
|
lines.push(`${DIM}url: ${report.url}${RESET}`);
|
|
218
213
|
lines.push("");
|
|
219
|
-
lines.push(`status: ${color}${report.status}${RESET}`);
|
|
214
|
+
lines.push(`status: ${color}${report.status}${RESET}` + (report.status === "fail" && !failsShown ? ` ${DIM}(check-failed off — the failures below are measured, not reported)${RESET}` : ""));
|
|
220
215
|
for (const check of report.checks) {
|
|
221
|
-
const icon = check.status === "pass" ? `${GREEN}PASS${RESET}` : check.status === "skip" ? `${YELLOW}SKIP${RESET}` : `${RED}FAIL${RESET}`;
|
|
216
|
+
const icon = check.status === "pass" ? `${GREEN}PASS${RESET}` : check.status === "skip" ? unavailableOff ? `${DIM}SKIP${RESET}` : `${YELLOW}SKIP${RESET}` : checkFailedOff ? `${DIM}FAIL${RESET}` : `${RED}FAIL${RESET}`;
|
|
222
217
|
lines.push(` ${icon} ${check.name.padEnd(22)} ${String(check.elapsedMs).padStart(5)}ms ${DIM}${check.message}${RESET}`);
|
|
223
218
|
}
|
|
224
219
|
lines.push(`${DIM}elapsed: ${report.elapsedMs}ms${RESET}`);
|
|
225
220
|
return lines.join("\n");
|
|
226
221
|
}
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
console.log(" --deep Exercise heavier v0.18.0 APIs (batchRender)");
|
|
233
|
-
console.log(" --json Print JSON report");
|
|
234
|
-
process.exit(exitCode);
|
|
235
|
-
}
|
|
222
|
+
/**
|
|
223
|
+
* Read this gate's own flags. `--help` and `--json` are no longer handled
|
|
224
|
+
* here: the core gate runner owns both, and a parser that called
|
|
225
|
+
* `process.exit(0)` for help could not be used by anything but a CLI.
|
|
226
|
+
*/
|
|
236
227
|
function parseCraterSmokeArgs(argv, env = process.env) {
|
|
237
228
|
let url = resolveCraterBidiUrl({ env });
|
|
238
229
|
let requireAvailable = false;
|
|
239
230
|
let deep = false;
|
|
240
|
-
let json = false;
|
|
241
231
|
for (let i = 0; i < argv.length; i++) {
|
|
242
232
|
const arg = argv[i];
|
|
243
|
-
if (arg === "--
|
|
244
|
-
else if (arg === "--url") url = argv[++i] ?? "ws://127.0.0.1:9222";
|
|
233
|
+
if (arg === "--url") url = argv[++i] ?? "ws://127.0.0.1:9222";
|
|
245
234
|
else if (arg === "--require") requireAvailable = true;
|
|
246
235
|
else if (arg === "--deep") deep = true;
|
|
247
|
-
else if (arg === "--json") json = true;
|
|
248
236
|
}
|
|
249
237
|
return {
|
|
250
238
|
url,
|
|
251
239
|
requireAvailable,
|
|
252
|
-
deep
|
|
253
|
-
json
|
|
240
|
+
deep
|
|
254
241
|
};
|
|
255
242
|
}
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
});
|
|
263
|
-
if (args.json) console.log(JSON.stringify(report, null, 2));
|
|
264
|
-
else console.log(formatCraterSmokeReport(report));
|
|
265
|
-
if (report.status === "fail" || args.requireAvailable && report.status === "skip") process.exit(1);
|
|
266
|
-
}
|
|
267
|
-
if (process.env.__VRT_DISPATCHER_LEAF__ === "crater-smoke" || (process.argv[1] ? resolve(process.argv[1]) === fileURLToPath(import.meta.url) : false)) main().catch(handleCliError);
|
|
243
|
+
/**
|
|
244
|
+
* CLI entry removed: this module is measurement code now, not a command.
|
|
245
|
+
* `check crater` is declared in `./gates/crater.gate.ts` and driven by the core runner
|
|
246
|
+
* (`@mizchi/vlmkit-core/plugin/runner.ts`), which owns argument parsing,
|
|
247
|
+
* `--json`, `--advisory`, the run ledger and the exit code.
|
|
248
|
+
*/
|
|
268
249
|
//#endregion
|
|
269
250
|
export { formatCraterSmokeReport, parseCraterSmokeArgs, runCraterBidiSmoke };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { CraterSmokeOptions, CraterSmokeReport } from "../crater-smoke.mjs";
|
|
2
|
+
import * as _$_mizchi_vlmkit_core_plugin_contract_ts0 from "@mizchi/vlmkit-core/plugin/contract.ts";
|
|
3
|
+
|
|
4
|
+
//#region src/gates/crater.gate.d.ts
|
|
5
|
+
/** The gate needs `requireAvailable` at verdict time, not just at run time. */
|
|
6
|
+
interface CraterGateOptions extends CraterSmokeOptions {
|
|
7
|
+
requireAvailable: boolean;
|
|
8
|
+
}
|
|
9
|
+
declare const craterGate: _$_mizchi_vlmkit_core_plugin_contract_ts0.GateDefinition<CraterSmokeReport, CraterGateOptions>;
|
|
10
|
+
declare const captureGatesPlugin: _$_mizchi_vlmkit_core_plugin_contract_ts0.VlmkitPlugin;
|
|
11
|
+
//#endregion
|
|
12
|
+
export { CraterGateOptions, captureGatesPlugin, captureGatesPlugin as default, craterGate };
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { formatCraterSmokeReport, parseCraterSmokeArgs, runCraterBidiSmoke } from "../crater-smoke.mjs";
|
|
2
|
+
import { defineGate, definePlugin } from "@mizchi/vlmkit-core/plugin/contract.ts";
|
|
3
|
+
//#region src/gates/crater.gate.ts
|
|
4
|
+
/**
|
|
5
|
+
* `check crater` as a gate definition, owned by the package that owns the
|
|
6
|
+
* Crater client.
|
|
7
|
+
*
|
|
8
|
+
* This is the second built-in plugin, and it exists to keep the composition
|
|
9
|
+
* story honest: gate definitions live next to their measurement code, not in
|
|
10
|
+
* one central catalog, so `vlmkit-capture` contributes its gate the same way a
|
|
11
|
+
* third party would. If the registry could only be fed from one package, the
|
|
12
|
+
* "core never imports a gate" rule would be decoration.
|
|
13
|
+
*
|
|
14
|
+
* `parseCraterSmokeArgs` is intentionally left in `../crater-smoke.ts`: it is
|
|
15
|
+
* covered by that module's tests and reads `resolveCraterBidiUrl` from the
|
|
16
|
+
* environment, which is behaviour worth keeping tested on its own.
|
|
17
|
+
*/
|
|
18
|
+
const craterGate = defineGate({
|
|
19
|
+
id: "check.crater",
|
|
20
|
+
command: ["check", "crater"],
|
|
21
|
+
title: "Crater BiDi backend smoke check",
|
|
22
|
+
summary: "Crater BiDi backend smoke check",
|
|
23
|
+
category: "infrastructure",
|
|
24
|
+
usage: `Exercises the Crater BiDi backend end to end: connect, navigate,
|
|
25
|
+
screenshot, and (with --deep) the heavier v0.18.0 APIs.
|
|
26
|
+
|
|
27
|
+
An unreachable Crater is reported as SKIP, not as a failure — the backend is
|
|
28
|
+
optional, so a machine without it must not fail the suite. Pass --require in
|
|
29
|
+
the CI job that is supposed to have Crater running.`,
|
|
30
|
+
rules: [{
|
|
31
|
+
id: "check-failed",
|
|
32
|
+
title: "A Crater smoke check failed",
|
|
33
|
+
severity: "suspect"
|
|
34
|
+
}, {
|
|
35
|
+
id: "unavailable",
|
|
36
|
+
title: "Crater is not reachable",
|
|
37
|
+
severity: "info",
|
|
38
|
+
docs: "Info by default because the backend is optional; --require promotes it to a failure."
|
|
39
|
+
}],
|
|
40
|
+
inputs: [
|
|
41
|
+
{
|
|
42
|
+
name: "url",
|
|
43
|
+
placeholder: "ws-url",
|
|
44
|
+
kind: "string",
|
|
45
|
+
description: "Crater BiDi URL",
|
|
46
|
+
defaultDescription: "ws://127.0.0.1:9222 or VLMKIT_CRATER_BIDI_URL"
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
name: "require",
|
|
50
|
+
kind: "boolean",
|
|
51
|
+
description: "Fail if Crater is unavailable"
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
name: "deep",
|
|
55
|
+
kind: "boolean",
|
|
56
|
+
description: "Exercise heavier v0.18.0 APIs (batchRender)"
|
|
57
|
+
}
|
|
58
|
+
],
|
|
59
|
+
parse: (argv) => {
|
|
60
|
+
const args = parseCraterSmokeArgs([...argv]);
|
|
61
|
+
return {
|
|
62
|
+
url: args.url,
|
|
63
|
+
requireAvailable: args.requireAvailable,
|
|
64
|
+
deep: args.deep
|
|
65
|
+
};
|
|
66
|
+
},
|
|
67
|
+
run: (options) => runCraterBidiSmoke(options),
|
|
68
|
+
findings: (report, options) => {
|
|
69
|
+
const findings = [];
|
|
70
|
+
for (const check of report.checks) {
|
|
71
|
+
if (check.status !== "fail") continue;
|
|
72
|
+
findings.push({
|
|
73
|
+
rule: "check-failed",
|
|
74
|
+
severity: "suspect",
|
|
75
|
+
message: `${check.name}: ${check.message}`,
|
|
76
|
+
evidence: { elapsedMs: check.elapsedMs }
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
if (report.status === "skip") findings.push({
|
|
80
|
+
rule: "unavailable",
|
|
81
|
+
severity: options.requireAvailable ? "suspect" : "info",
|
|
82
|
+
message: `Crater not reachable at ${report.url}` + (options.requireAvailable ? " (--require)" : " — checks were skipped.")
|
|
83
|
+
});
|
|
84
|
+
return findings;
|
|
85
|
+
},
|
|
86
|
+
format: formatCraterSmokeReport,
|
|
87
|
+
ledger: (report) => ({
|
|
88
|
+
tool: "check-crater",
|
|
89
|
+
source: report.url,
|
|
90
|
+
headline: {
|
|
91
|
+
status: report.status,
|
|
92
|
+
checks: report.checks.length,
|
|
93
|
+
failed: report.checks.filter((c) => c.status === "fail").length,
|
|
94
|
+
elapsedMs: report.elapsedMs
|
|
95
|
+
}
|
|
96
|
+
})
|
|
97
|
+
});
|
|
98
|
+
const captureGatesPlugin = definePlugin({
|
|
99
|
+
name: "@mizchi/vlmkit-capture",
|
|
100
|
+
gates: [craterGate]
|
|
101
|
+
});
|
|
102
|
+
//#endregion
|
|
103
|
+
export { captureGatesPlugin, captureGatesPlugin as default, craterGate };
|
package/dist/index.d.mts
CHANGED
|
@@ -6,7 +6,7 @@ import { CraterSmokeCheck, CraterSmokeClient, CraterSmokeReport, CraterSmokeStat
|
|
|
6
6
|
import { CRATER_WASM_MODULE_ENV, CraterBoxRect, CraterLayoutDiagnostics, CraterLayoutNode, CraterLayoutRootBox, CraterWasmLayoutBackend, CraterWasmModule, CraterWasmRenderRequest, CraterWasmRenderResult, CraterWasmViewport, LoadCraterWasmModuleOptions, createCraterWasmLayoutBackend, loadCraterWasmModule, normalizeCraterLayoutJson, summarizeCraterLayout } from "./crater-wasm.mjs";
|
|
7
7
|
import { ViewportDetectionResult } from "./detection-types.mjs";
|
|
8
8
|
import { Breakpoint, CraterViewportSource, DiscoveryResult, ResponsiveBreakpoint, ViewportOptions, ViewportSource, ViewportSpec, discoverViewports, discoverViewportsViaCrater, discoverViewportsWithBackend, extractBreakpoints, extractBreakpointsFromHtml, extractBreakpointsFromHtmlWithStylesheets, extractResponsiveBreakpointsFromHtml, extractResponsiveBreakpointsFromHtmlWithStylesheets, extractStylesheetHrefsFromHtml, generateViewports, mergeResponsiveBreakpoints, toResponsiveBreakpoints } from "./viewport-discovery.mjs";
|
|
9
|
-
import { formatPlaywrightLaunchError, isPlaywrightSandboxRestrictionError } from "./playwright-launch-error.mjs";
|
|
9
|
+
import { diagnoseSandboxLaunchFailure, formatPlaywrightLaunchError, isPlaywrightSandboxRestrictionError } from "./playwright-launch-error.mjs";
|
|
10
10
|
import { AnalyzedReport, FailedTest, ReportStats, analyzeReport, collectScreenshots, formatStats } from "./playwright-analyzer.mjs";
|
|
11
11
|
import { PrescannerResolvedBy, PrescannerTrialResolution, PrescannerTrialSummary, hasAnyDetectionSignal, hasCraterPrescanSignal, resolvePrescannerTrial, summarizePrescannerTrials } from "./prescanner.mjs";
|
|
12
|
-
export { type AnalyzedReport, type BatchPrescanOptions, type BatchPrescanRequest, type BatchPrescanResult, type Breakpoint, CRATER_BIDI_URL_ENV, CRATER_ROOT_ENV, CRATER_WASM_MODULE_ENV, type CaptureConfig, type CaptureRoute, type CaptureRouteSet, type CloudflareCrawlRecord, type CloudflareCrawlRecordStatus, type CloudflareCrawlRequest, type CloudflareCrawlResult, type CloudflareCrawlRoute, type CloudflareCrawlStartResult, type CloudflareQuickAction, type CloudflareQuickActionEndpointInput, type CloudflareQuickActionsConfig, type CloudflareQuickActionsEnv, type CloudflareScreenshotRequest, type CloudflareScreenshotResult, type CraterBatchRenderResult, type CraterBoxRect, type CraterBreakpointDiscoveryDiagnostics, type CraterBreakpointDiscoveryResult, CraterClient, type CraterComputedStyleWithState, type CraterCssMutation, type CraterCssMutationAction, type CraterLayoutDiagnostics, type CraterLayoutNode, type CraterLayoutRootBox, type CraterRenderVariant, type CraterResponsiveBreakpoint, type CraterRuleViewportMap, type CraterRuleViewportMapEntry, type CraterSmokeCheck, type CraterSmokeClient, type CraterSmokeReport, type CraterSmokeStatus, type CraterViewportSource, type CraterWasmLayoutBackend, type CraterWasmModule, type CraterWasmRenderRequest, type CraterWasmRenderResult, type CraterWasmViewport, DEFAULT_BIDI_URL, DEFAULT_CAPTURE_BASE_URL, DEFAULT_CAPTURE_CONFIG_FILE, DEFAULT_CAPTURE_ROUTES, type DiscoveryResult, type FailedTest, type LoadCaptureConfigOptions, type LoadCraterWasmModuleOptions, type PaintNode, type PaintProps, type PrescannerResolvedBy, type PrescannerTrialResolution, type PrescannerTrialSummary, type ReportStats, type ResponsiveBreakpoint, VLMKIT_CRATER_BIDI_URL_ENV, VLMKIT_CRATER_ROOT_ENV, ViewportDetectionResult, type ViewportOptions, type ViewportSource, type ViewportSpec, analyzeReport, buildCloudflareQuickActionEndpoint, captureConfigDir, collectScreenshots, createCloudflareQuickActionsClient, createCraterWasmLayoutBackend, diffPaintTrees, discoverViewports, discoverViewportsViaCrater, discoverViewportsWithBackend, extractBreakpoints, extractBreakpointsFromHtml, extractBreakpointsFromHtmlWithStylesheets, extractCloudflareCrawlRoutes, extractResponsiveBreakpointsFromHtml, extractResponsiveBreakpointsFromHtmlWithStylesheets, extractStylesheetHrefsFromHtml, formatCraterSmokeReport, formatPlaywrightLaunchError, formatStats, generateViewports, hasAnyBatchPrescanSignal, hasAnyDetectionSignal, hasCraterPrescanSignal, isCraterAvailable, isPlaywrightSandboxRestrictionError, loadCaptureConfigFromFile, loadCraterWasmModule, mergeResponsiveBreakpoints, mutationsForPropertyRemoval, mutationsForSelectorBlockRemoval, normalizeCraterLayoutJson, parseCaptureConfig, resolveCaptureRoutes, resolveCloudflareQuickActionsConfig, resolveCraterBidiUrl, resolvePrescannerTrial, routeNameFromPath, runBatchPrescan, runCraterBidiSmoke, summarizeCraterLayout, summarizePrescannerTrials, toResponsiveBreakpoints };
|
|
12
|
+
export { type AnalyzedReport, type BatchPrescanOptions, type BatchPrescanRequest, type BatchPrescanResult, type Breakpoint, CRATER_BIDI_URL_ENV, CRATER_ROOT_ENV, CRATER_WASM_MODULE_ENV, type CaptureConfig, type CaptureRoute, type CaptureRouteSet, type CloudflareCrawlRecord, type CloudflareCrawlRecordStatus, type CloudflareCrawlRequest, type CloudflareCrawlResult, type CloudflareCrawlRoute, type CloudflareCrawlStartResult, type CloudflareQuickAction, type CloudflareQuickActionEndpointInput, type CloudflareQuickActionsConfig, type CloudflareQuickActionsEnv, type CloudflareScreenshotRequest, type CloudflareScreenshotResult, type CraterBatchRenderResult, type CraterBoxRect, type CraterBreakpointDiscoveryDiagnostics, type CraterBreakpointDiscoveryResult, CraterClient, type CraterComputedStyleWithState, type CraterCssMutation, type CraterCssMutationAction, type CraterLayoutDiagnostics, type CraterLayoutNode, type CraterLayoutRootBox, type CraterRenderVariant, type CraterResponsiveBreakpoint, type CraterRuleViewportMap, type CraterRuleViewportMapEntry, type CraterSmokeCheck, type CraterSmokeClient, type CraterSmokeReport, type CraterSmokeStatus, type CraterViewportSource, type CraterWasmLayoutBackend, type CraterWasmModule, type CraterWasmRenderRequest, type CraterWasmRenderResult, type CraterWasmViewport, DEFAULT_BIDI_URL, DEFAULT_CAPTURE_BASE_URL, DEFAULT_CAPTURE_CONFIG_FILE, DEFAULT_CAPTURE_ROUTES, type DiscoveryResult, type FailedTest, type LoadCaptureConfigOptions, type LoadCraterWasmModuleOptions, type PaintNode, type PaintProps, type PrescannerResolvedBy, type PrescannerTrialResolution, type PrescannerTrialSummary, type ReportStats, type ResponsiveBreakpoint, VLMKIT_CRATER_BIDI_URL_ENV, VLMKIT_CRATER_ROOT_ENV, ViewportDetectionResult, type ViewportOptions, type ViewportSource, type ViewportSpec, analyzeReport, buildCloudflareQuickActionEndpoint, captureConfigDir, collectScreenshots, createCloudflareQuickActionsClient, createCraterWasmLayoutBackend, diagnoseSandboxLaunchFailure, diffPaintTrees, discoverViewports, discoverViewportsViaCrater, discoverViewportsWithBackend, extractBreakpoints, extractBreakpointsFromHtml, extractBreakpointsFromHtmlWithStylesheets, extractCloudflareCrawlRoutes, extractResponsiveBreakpointsFromHtml, extractResponsiveBreakpointsFromHtmlWithStylesheets, extractStylesheetHrefsFromHtml, formatCraterSmokeReport, formatPlaywrightLaunchError, formatStats, generateViewports, hasAnyBatchPrescanSignal, hasAnyDetectionSignal, hasCraterPrescanSignal, isCraterAvailable, isPlaywrightSandboxRestrictionError, loadCaptureConfigFromFile, loadCraterWasmModule, mergeResponsiveBreakpoints, mutationsForPropertyRemoval, mutationsForSelectorBlockRemoval, normalizeCraterLayoutJson, parseCaptureConfig, resolveCaptureRoutes, resolveCloudflareQuickActionsConfig, resolveCraterBidiUrl, resolvePrescannerTrial, routeNameFromPath, runBatchPrescan, runCraterBidiSmoke, summarizeCraterLayout, summarizePrescannerTrials, toResponsiveBreakpoints };
|
package/dist/index.mjs
CHANGED
|
@@ -5,7 +5,7 @@ import { buildCloudflareQuickActionEndpoint, createCloudflareQuickActionsClient,
|
|
|
5
5
|
import { formatCraterSmokeReport, runCraterBidiSmoke } from "./crater-smoke.mjs";
|
|
6
6
|
import { CRATER_WASM_MODULE_ENV, createCraterWasmLayoutBackend, loadCraterWasmModule, normalizeCraterLayoutJson, summarizeCraterLayout } from "./crater-wasm.mjs";
|
|
7
7
|
import { discoverViewports, discoverViewportsViaCrater, discoverViewportsWithBackend, extractBreakpoints, extractBreakpointsFromHtml, extractBreakpointsFromHtmlWithStylesheets, extractResponsiveBreakpointsFromHtml, extractResponsiveBreakpointsFromHtmlWithStylesheets, extractStylesheetHrefsFromHtml, generateViewports, mergeResponsiveBreakpoints, toResponsiveBreakpoints } from "./viewport-discovery.mjs";
|
|
8
|
-
import { formatPlaywrightLaunchError, isPlaywrightSandboxRestrictionError } from "./playwright-launch-error.mjs";
|
|
8
|
+
import { diagnoseSandboxLaunchFailure, formatPlaywrightLaunchError, isPlaywrightSandboxRestrictionError } from "./playwright-launch-error.mjs";
|
|
9
9
|
import { analyzeReport, collectScreenshots, formatStats } from "./playwright-analyzer.mjs";
|
|
10
10
|
import { hasAnyDetectionSignal, hasCraterPrescanSignal, resolvePrescannerTrial, summarizePrescannerTrials } from "./prescanner.mjs";
|
|
11
|
-
export { CRATER_BIDI_URL_ENV, CRATER_ROOT_ENV, CRATER_WASM_MODULE_ENV, CraterClient, DEFAULT_BIDI_URL, DEFAULT_CAPTURE_BASE_URL, DEFAULT_CAPTURE_CONFIG_FILE, DEFAULT_CAPTURE_ROUTES, VLMKIT_CRATER_BIDI_URL_ENV, VLMKIT_CRATER_ROOT_ENV, analyzeReport, buildCloudflareQuickActionEndpoint, captureConfigDir, collectScreenshots, createCloudflareQuickActionsClient, createCraterWasmLayoutBackend, diffPaintTrees, discoverViewports, discoverViewportsViaCrater, discoverViewportsWithBackend, extractBreakpoints, extractBreakpointsFromHtml, extractBreakpointsFromHtmlWithStylesheets, extractCloudflareCrawlRoutes, extractResponsiveBreakpointsFromHtml, extractResponsiveBreakpointsFromHtmlWithStylesheets, extractStylesheetHrefsFromHtml, formatCraterSmokeReport, formatPlaywrightLaunchError, formatStats, generateViewports, hasAnyBatchPrescanSignal, hasAnyDetectionSignal, hasCraterPrescanSignal, isCraterAvailable, isPlaywrightSandboxRestrictionError, loadCaptureConfigFromFile, loadCraterWasmModule, mergeResponsiveBreakpoints, mutationsForPropertyRemoval, mutationsForSelectorBlockRemoval, normalizeCraterLayoutJson, parseCaptureConfig, resolveCaptureRoutes, resolveCloudflareQuickActionsConfig, resolveCraterBidiUrl, resolvePrescannerTrial, routeNameFromPath, runBatchPrescan, runCraterBidiSmoke, summarizeCraterLayout, summarizePrescannerTrials, toResponsiveBreakpoints };
|
|
11
|
+
export { CRATER_BIDI_URL_ENV, CRATER_ROOT_ENV, CRATER_WASM_MODULE_ENV, CraterClient, DEFAULT_BIDI_URL, DEFAULT_CAPTURE_BASE_URL, DEFAULT_CAPTURE_CONFIG_FILE, DEFAULT_CAPTURE_ROUTES, VLMKIT_CRATER_BIDI_URL_ENV, VLMKIT_CRATER_ROOT_ENV, analyzeReport, buildCloudflareQuickActionEndpoint, captureConfigDir, collectScreenshots, createCloudflareQuickActionsClient, createCraterWasmLayoutBackend, diagnoseSandboxLaunchFailure, diffPaintTrees, discoverViewports, discoverViewportsViaCrater, discoverViewportsWithBackend, extractBreakpoints, extractBreakpointsFromHtml, extractBreakpointsFromHtmlWithStylesheets, extractCloudflareCrawlRoutes, extractResponsiveBreakpointsFromHtml, extractResponsiveBreakpointsFromHtmlWithStylesheets, extractStylesheetHrefsFromHtml, formatCraterSmokeReport, formatPlaywrightLaunchError, formatStats, generateViewports, hasAnyBatchPrescanSignal, hasAnyDetectionSignal, hasCraterPrescanSignal, isCraterAvailable, isPlaywrightSandboxRestrictionError, loadCaptureConfigFromFile, loadCraterWasmModule, mergeResponsiveBreakpoints, mutationsForPropertyRemoval, mutationsForSelectorBlockRemoval, normalizeCraterLayoutJson, parseCaptureConfig, resolveCaptureRoutes, resolveCloudflareQuickActionsConfig, resolveCraterBidiUrl, resolvePrescannerTrial, routeNameFromPath, runBatchPrescan, runCraterBidiSmoke, summarizeCraterLayout, summarizePrescannerTrials, toResponsiveBreakpoints };
|
|
@@ -1,7 +1,21 @@
|
|
|
1
1
|
//#region src/playwright-launch-error.d.ts
|
|
2
2
|
declare function isPlaywrightSandboxRestrictionError(error: unknown): boolean;
|
|
3
|
+
/**
|
|
4
|
+
* The `diagnose` hook for `launchBrowser` / `withBrowser`.
|
|
5
|
+
*
|
|
6
|
+
* Core owns the launch but cannot own this check: the sandbox signals live in
|
|
7
|
+
* `@mizchi/vlmkit-capture`, and capture depends on core, so the direction only
|
|
8
|
+
* works as a hook the caller passes in. Returns `null` — declining — for
|
|
9
|
+
* anything that is not the sandbox case, which leaves core's own missing-browser
|
|
10
|
+
* diagnosis and every existing `handleCliError` branch untouched.
|
|
11
|
+
*
|
|
12
|
+
* Replaces the identical 5-line `if (isPlaywrightSandboxRestrictionError(e))
|
|
13
|
+
* throw new Error(formatPlaywrightLaunchError(e, …))` block that had been copied
|
|
14
|
+
* to 4 launch sites (css-challenge x2, css-challenge-core, migration-compare).
|
|
15
|
+
*/
|
|
16
|
+
declare function diagnoseSandboxLaunchFailure(error: unknown): string | null;
|
|
3
17
|
declare function formatPlaywrightLaunchError(error: unknown, options?: {
|
|
4
18
|
commandHint?: string;
|
|
5
19
|
}): string;
|
|
6
20
|
//#endregion
|
|
7
|
-
export { formatPlaywrightLaunchError, isPlaywrightSandboxRestrictionError };
|
|
21
|
+
export { diagnoseSandboxLaunchFailure, formatPlaywrightLaunchError, isPlaywrightSandboxRestrictionError };
|
|
@@ -15,6 +15,22 @@ function isPlaywrightSandboxRestrictionError(error) {
|
|
|
15
15
|
const message = normalizeErrorMessage(error);
|
|
16
16
|
return message.includes(FORMATTED_SANDBOX_MARKER) || message.includes("browserType.launch:") && RAW_SANDBOX_SIGNAL_PATTERNS.some((pattern) => message.includes(pattern));
|
|
17
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* The `diagnose` hook for `launchBrowser` / `withBrowser`.
|
|
20
|
+
*
|
|
21
|
+
* Core owns the launch but cannot own this check: the sandbox signals live in
|
|
22
|
+
* `@mizchi/vlmkit-capture`, and capture depends on core, so the direction only
|
|
23
|
+
* works as a hook the caller passes in. Returns `null` — declining — for
|
|
24
|
+
* anything that is not the sandbox case, which leaves core's own missing-browser
|
|
25
|
+
* diagnosis and every existing `handleCliError` branch untouched.
|
|
26
|
+
*
|
|
27
|
+
* Replaces the identical 5-line `if (isPlaywrightSandboxRestrictionError(e))
|
|
28
|
+
* throw new Error(formatPlaywrightLaunchError(e, …))` block that had been copied
|
|
29
|
+
* to 4 launch sites (css-challenge x2, css-challenge-core, migration-compare).
|
|
30
|
+
*/
|
|
31
|
+
function diagnoseSandboxLaunchFailure(error) {
|
|
32
|
+
return isPlaywrightSandboxRestrictionError(error) ? formatPlaywrightLaunchError(error, { commandHint: "in your local terminal or in CI" }) : null;
|
|
33
|
+
}
|
|
18
34
|
function formatPlaywrightLaunchError(error, options = {}) {
|
|
19
35
|
const message = normalizeErrorMessage(error);
|
|
20
36
|
if (!isPlaywrightSandboxRestrictionError(error)) return message;
|
|
@@ -22,4 +38,4 @@ function formatPlaywrightLaunchError(error, options = {}) {
|
|
|
22
38
|
return `Playwright browser launch is blocked by a ${FORMATTED_SANDBOX_MARKER}. Chromium itself is likely fine.${` ${!options.commandHint ? "Re-run outside the Codex sandbox or in CI" : /re-?run outside the codex sandbox/i.test(options.commandHint) ? options.commandHint : `Re-run outside the Codex sandbox or ${options.commandHint}`}.`}\nOriginal error: ${message.split("\n").find((line) => line.trim().length > 0) ?? message}`;
|
|
23
39
|
}
|
|
24
40
|
//#endregion
|
|
25
|
-
export { formatPlaywrightLaunchError, isPlaywrightSandboxRestrictionError };
|
|
41
|
+
export { diagnoseSandboxLaunchFailure, formatPlaywrightLaunchError, isPlaywrightSandboxRestrictionError };
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { CaptureRoute } from "./capture-config.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/route-capture.d.ts
|
|
4
|
+
/** The viewport the old `vrt-desktop` project used, and vlmkit's default elsewhere. */
|
|
5
|
+
declare const DEFAULT_CAPTURE_VIEWPORT: {
|
|
6
|
+
readonly width: 1280;
|
|
7
|
+
readonly height: 720;
|
|
8
|
+
};
|
|
9
|
+
interface RouteCaptureOptions {
|
|
10
|
+
baseUrl: string;
|
|
11
|
+
routes: readonly CaptureRoute[];
|
|
12
|
+
/** Directory that receives `<name>.png` and `<name>.a11y.json`. */
|
|
13
|
+
outputDir: string;
|
|
14
|
+
viewport?: {
|
|
15
|
+
width: number;
|
|
16
|
+
height: number;
|
|
17
|
+
};
|
|
18
|
+
/** Settling delay after load, matching the spec's `waitForTimeout(500)`. */
|
|
19
|
+
settleMs?: number;
|
|
20
|
+
}
|
|
21
|
+
interface RouteCaptureEntry {
|
|
22
|
+
name: string;
|
|
23
|
+
url: string;
|
|
24
|
+
screenshotPath: string;
|
|
25
|
+
a11yPath: string;
|
|
26
|
+
/** How the a11y tree was obtained — CDP is the full tree; the rest are degraded. */
|
|
27
|
+
a11ySource: "cdp" | "aria-snapshot" | "empty";
|
|
28
|
+
/** `body` innerText length. 0 means the page rendered nothing, which the spec asserted on. */
|
|
29
|
+
textLength: number;
|
|
30
|
+
/**
|
|
31
|
+
* HTTP status of the main response, or null when Playwright reported none.
|
|
32
|
+
*
|
|
33
|
+
* Recorded because `page.goto` does NOT throw on 4xx/5xx: a route whose path is wrong captures
|
|
34
|
+
* the server's error page and that becomes the baseline. Measured while porting this — a route
|
|
35
|
+
* pointed at `/nope.html` produced a 404 screenshot, a 404 a11y tree, and an exit 0. The old
|
|
36
|
+
* spec had the same hole and no way to see it.
|
|
37
|
+
*/
|
|
38
|
+
status: number | null;
|
|
39
|
+
/** `waitFor` was given and never matched — the capture happened anyway, as before. */
|
|
40
|
+
waitForTimedOut?: boolean;
|
|
41
|
+
}
|
|
42
|
+
interface RouteCaptureFailure {
|
|
43
|
+
name: string;
|
|
44
|
+
url: string;
|
|
45
|
+
error: string;
|
|
46
|
+
}
|
|
47
|
+
interface RouteCaptureResult {
|
|
48
|
+
viewport: {
|
|
49
|
+
width: number;
|
|
50
|
+
height: number;
|
|
51
|
+
};
|
|
52
|
+
captured: RouteCaptureEntry[];
|
|
53
|
+
failures: RouteCaptureFailure[];
|
|
54
|
+
/** Captured, but the body had no text — a served-but-empty page. */
|
|
55
|
+
blank: RouteCaptureEntry[];
|
|
56
|
+
/** Captured, but the server did not return 2xx — an error page about to become a baseline. */
|
|
57
|
+
notOk: RouteCaptureEntry[];
|
|
58
|
+
}
|
|
59
|
+
declare function captureRoutes(options: RouteCaptureOptions): Promise<RouteCaptureResult>;
|
|
60
|
+
interface CdpAxNode {
|
|
61
|
+
nodeId: string;
|
|
62
|
+
parentId?: string;
|
|
63
|
+
role?: {
|
|
64
|
+
value: string;
|
|
65
|
+
};
|
|
66
|
+
name?: {
|
|
67
|
+
value: string;
|
|
68
|
+
};
|
|
69
|
+
properties?: {
|
|
70
|
+
name: string;
|
|
71
|
+
value: {
|
|
72
|
+
value: unknown;
|
|
73
|
+
};
|
|
74
|
+
}[];
|
|
75
|
+
childIds?: string[];
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* CDP returns a flat node list; the commands that diff these expect a tree.
|
|
79
|
+
*
|
|
80
|
+
* Ported unchanged from the spec, including which properties are carried
|
|
81
|
+
* (`checked` / `disabled` / `expanded` / `selected` / `level`) — the `.a11y.json` files on disk
|
|
82
|
+
* are compared against baselines captured by the old path, so changing the shape here would
|
|
83
|
+
* report every baseline as a semantic diff.
|
|
84
|
+
*/
|
|
85
|
+
declare function cdpNodesToTree(nodes: readonly CdpAxNode[]): unknown;
|
|
86
|
+
//#endregion
|
|
87
|
+
export { DEFAULT_CAPTURE_VIEWPORT, RouteCaptureEntry, RouteCaptureFailure, RouteCaptureOptions, RouteCaptureResult, captureRoutes, cdpNodesToTree };
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { join } from "node:path";
|
|
2
|
+
import { withBrowser } from "@mizchi/vlmkit-core/browser-launch.ts";
|
|
3
|
+
import { mkdir, writeFile } from "node:fs/promises";
|
|
4
|
+
//#region src/route-capture.ts
|
|
5
|
+
/**
|
|
6
|
+
* Route capture — screenshots + a11y trees for `vlmkit workflow init` / `workflow capture`,
|
|
7
|
+
* in this process.
|
|
8
|
+
*
|
|
9
|
+
* ## Why this file exists instead of `e2e/vlmkit-capture.spec.ts`
|
|
10
|
+
*
|
|
11
|
+
* That spec was 135 lines that did `goto` → `screenshot` → `Accessibility.getFullAXTree` →
|
|
12
|
+
* write two files. Nothing in it needed the Playwright TEST RUNNER: no fixtures, no
|
|
13
|
+
* `toHaveScreenshot`, no retries — one `expect` on body text, which is a measurement this
|
|
14
|
+
* returns instead. It was spawned with `npx playwright test`, and being a test file rather than
|
|
15
|
+
* a function cost four things:
|
|
16
|
+
*
|
|
17
|
+
* 1. **A packaging question with no good answer.** `package.json` publishes `dist/**` but
|
|
18
|
+
* excludes `dist/e2e/**`, and the `e2e/` sources are not published either, so an
|
|
19
|
+
* npm-installed vlmkit had no spec and no build could produce one. `workflow init` and
|
|
20
|
+
* `workflow capture` were source-checkout-only, and the open decision was "publish the spec
|
|
21
|
+
* or retire both commands". Retiring them was not as cheap as it looked: `verify`,
|
|
22
|
+
* `approve`, `report`, `introspect`, `spec-verify` and `expect` all read the `.a11y.json`
|
|
23
|
+
* sidecars this produces, and nothing else produces them — `vlmkit snapshot` writes
|
|
24
|
+
* multi-viewport PNGs and no a11y trees. Deleting two commands would have orphaned six.
|
|
25
|
+
* A function has no packaging question at all, which is how that decision is retired.
|
|
26
|
+
*
|
|
27
|
+
* 2. **A silent overwrite.** `playwright.config.ts` declares two projects — `vrt-desktop`
|
|
28
|
+
* (1280x720) and `vrt-mobile` (375x812) — and both ran this spec against the same
|
|
29
|
+
* `<name>.png` and `<name>.a11y.json`. Whichever finished last won, so a baseline was
|
|
30
|
+
* nondeterministically desktop or mobile. This takes ONE viewport, named in the result.
|
|
31
|
+
*
|
|
32
|
+
* 3. **Errors laundered through a subprocess.** A non-zero `playwright test` exit is a string,
|
|
33
|
+
* so the callers matched on captured-file counts and printed "(some tests had warnings, but
|
|
34
|
+
* captures completed)" — a blank page and a broken selector were the same sentence. Each
|
|
35
|
+
* route now reports its own outcome.
|
|
36
|
+
*
|
|
37
|
+
* 4. **`npx playwright test` startup** on every capture, plus `testDir`/filter fragility: a
|
|
38
|
+
* path outside `testDir` matches nothing and reports "No tests found", which is the
|
|
39
|
+
* obscure failure `resolveCaptureSpecPath` existed to work around.
|
|
40
|
+
*
|
|
41
|
+
* `withBrowser` is the same launcher all 27 gates use, so this shares their Chromium
|
|
42
|
+
* resolution, `--no-sandbox` handling and teardown.
|
|
43
|
+
*/
|
|
44
|
+
/** The viewport the old `vrt-desktop` project used, and vlmkit's default elsewhere. */
|
|
45
|
+
const DEFAULT_CAPTURE_VIEWPORT = {
|
|
46
|
+
width: 1280,
|
|
47
|
+
height: 720
|
|
48
|
+
};
|
|
49
|
+
async function captureRoutes(options) {
|
|
50
|
+
const viewport = options.viewport ?? { ...DEFAULT_CAPTURE_VIEWPORT };
|
|
51
|
+
const settleMs = options.settleMs ?? 500;
|
|
52
|
+
await mkdir(options.outputDir, { recursive: true });
|
|
53
|
+
const captured = [];
|
|
54
|
+
const failures = [];
|
|
55
|
+
await withBrowser(async (browser) => {
|
|
56
|
+
const context = await browser.newContext({ viewport });
|
|
57
|
+
try {
|
|
58
|
+
for (const route of options.routes) {
|
|
59
|
+
const url = `${options.baseUrl}${route.path}`;
|
|
60
|
+
const page = await context.newPage();
|
|
61
|
+
try {
|
|
62
|
+
const status = (await page.goto(url, { waitUntil: "networkidle" }))?.status() ?? null;
|
|
63
|
+
let waitForTimedOut = false;
|
|
64
|
+
if (route.waitFor) await page.waitForSelector(route.waitFor, { timeout: 1e4 }).catch(() => {
|
|
65
|
+
waitForTimedOut = true;
|
|
66
|
+
});
|
|
67
|
+
await page.waitForTimeout(settleMs);
|
|
68
|
+
const screenshotPath = join(options.outputDir, `${route.name}.png`);
|
|
69
|
+
await page.screenshot({
|
|
70
|
+
path: screenshotPath,
|
|
71
|
+
fullPage: true
|
|
72
|
+
});
|
|
73
|
+
const { tree, source } = await collectA11yTree(page, route.name);
|
|
74
|
+
const a11yPath = join(options.outputDir, `${route.name}.a11y.json`);
|
|
75
|
+
await writeFile(a11yPath, JSON.stringify(tree, null, 2));
|
|
76
|
+
const textLength = (await page.locator("body").innerText().catch(() => "")).length;
|
|
77
|
+
captured.push({
|
|
78
|
+
name: route.name,
|
|
79
|
+
url,
|
|
80
|
+
screenshotPath,
|
|
81
|
+
a11yPath,
|
|
82
|
+
a11ySource: source,
|
|
83
|
+
textLength,
|
|
84
|
+
status,
|
|
85
|
+
...waitForTimedOut ? { waitForTimedOut } : {}
|
|
86
|
+
});
|
|
87
|
+
} catch (err) {
|
|
88
|
+
failures.push({
|
|
89
|
+
name: route.name,
|
|
90
|
+
url,
|
|
91
|
+
error: err instanceof Error ? err.message : String(err)
|
|
92
|
+
});
|
|
93
|
+
} finally {
|
|
94
|
+
await page.close().catch(() => {});
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
} finally {
|
|
98
|
+
await context.close().catch(() => {});
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
return {
|
|
102
|
+
viewport,
|
|
103
|
+
captured,
|
|
104
|
+
failures,
|
|
105
|
+
blank: captured.filter((c) => c.textLength === 0),
|
|
106
|
+
notOk: captured.filter((c) => c.status !== null && (c.status < 200 || c.status >= 300))
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* The full CDP accessibility tree, with the spec's two fallbacks kept.
|
|
111
|
+
*
|
|
112
|
+
* `Accessibility.getFullAXTree` is Chromium-only, so the `ariaSnapshot` fallback is what makes
|
|
113
|
+
* this work at all on another engine. Which one produced the tree is now returned: an
|
|
114
|
+
* `ariaSnapshot` string and a real tree are not interchangeable to the commands that diff them,
|
|
115
|
+
* and silently degrading was invisible.
|
|
116
|
+
*/
|
|
117
|
+
async function collectA11yTree(page, name) {
|
|
118
|
+
try {
|
|
119
|
+
const client = await page.context().newCDPSession(page);
|
|
120
|
+
try {
|
|
121
|
+
return {
|
|
122
|
+
tree: cdpNodesToTree((await client.send("Accessibility.getFullAXTree")).nodes),
|
|
123
|
+
source: "cdp"
|
|
124
|
+
};
|
|
125
|
+
} finally {
|
|
126
|
+
await client.detach().catch(() => {});
|
|
127
|
+
}
|
|
128
|
+
} catch {
|
|
129
|
+
try {
|
|
130
|
+
return {
|
|
131
|
+
tree: {
|
|
132
|
+
role: "document",
|
|
133
|
+
name,
|
|
134
|
+
ariaSnapshot: await page.locator(":root").ariaSnapshot()
|
|
135
|
+
},
|
|
136
|
+
source: "aria-snapshot"
|
|
137
|
+
};
|
|
138
|
+
} catch {
|
|
139
|
+
return {
|
|
140
|
+
tree: {
|
|
141
|
+
role: "document",
|
|
142
|
+
name,
|
|
143
|
+
children: []
|
|
144
|
+
},
|
|
145
|
+
source: "empty"
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* CDP returns a flat node list; the commands that diff these expect a tree.
|
|
152
|
+
*
|
|
153
|
+
* Ported unchanged from the spec, including which properties are carried
|
|
154
|
+
* (`checked` / `disabled` / `expanded` / `selected` / `level`) — the `.a11y.json` files on disk
|
|
155
|
+
* are compared against baselines captured by the old path, so changing the shape here would
|
|
156
|
+
* report every baseline as a semantic diff.
|
|
157
|
+
*/
|
|
158
|
+
function cdpNodesToTree(nodes) {
|
|
159
|
+
if (!nodes || nodes.length === 0) return {
|
|
160
|
+
role: "document",
|
|
161
|
+
name: "",
|
|
162
|
+
children: []
|
|
163
|
+
};
|
|
164
|
+
const nodeMap = /* @__PURE__ */ new Map();
|
|
165
|
+
const childMap = /* @__PURE__ */ new Map();
|
|
166
|
+
for (const node of nodes) {
|
|
167
|
+
const props = {};
|
|
168
|
+
for (const p of node.properties ?? []) props[p.name] = p.value?.value;
|
|
169
|
+
const treeNode = {
|
|
170
|
+
role: node.role?.value ?? "none",
|
|
171
|
+
name: node.name?.value ?? ""
|
|
172
|
+
};
|
|
173
|
+
if (props.checked !== void 0) treeNode.checked = props.checked;
|
|
174
|
+
if (props.disabled !== void 0) treeNode.disabled = props.disabled;
|
|
175
|
+
if (props.expanded !== void 0) treeNode.expanded = props.expanded;
|
|
176
|
+
if (props.selected !== void 0) treeNode.selected = props.selected;
|
|
177
|
+
if (props.level !== void 0) treeNode.level = props.level;
|
|
178
|
+
nodeMap.set(node.nodeId, treeNode);
|
|
179
|
+
if (node.childIds) childMap.set(node.nodeId, node.childIds);
|
|
180
|
+
}
|
|
181
|
+
const seen = /* @__PURE__ */ new Set();
|
|
182
|
+
const buildTree = (nodeId) => {
|
|
183
|
+
if (seen.has(nodeId)) return null;
|
|
184
|
+
seen.add(nodeId);
|
|
185
|
+
const node = nodeMap.get(nodeId);
|
|
186
|
+
if (!node) return null;
|
|
187
|
+
const children = (childMap.get(nodeId) ?? []).map(buildTree).filter((c) => c !== null);
|
|
188
|
+
if (children.length > 0) node.children = children;
|
|
189
|
+
return node;
|
|
190
|
+
};
|
|
191
|
+
return buildTree(nodes[0].nodeId) ?? {
|
|
192
|
+
role: "document",
|
|
193
|
+
name: "",
|
|
194
|
+
children: []
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
//#endregion
|
|
198
|
+
export { DEFAULT_CAPTURE_VIEWPORT, captureRoutes, cdpNodesToTree };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mizchi/vlmkit-capture",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"description": "Playwright + Crater capture infrastructure for VRT — viewport discovery, multi-route capture, prescanner.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "mizchi",
|
|
@@ -36,13 +36,15 @@
|
|
|
36
36
|
}
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"playwright": "^1.61.1",
|
|
40
39
|
"pngjs": "^7.0.0",
|
|
41
40
|
"ws": "^8.20.0",
|
|
42
|
-
"@mizchi/vlmkit-core": "0.
|
|
41
|
+
"@mizchi/vlmkit-core": "0.11.0"
|
|
42
|
+
},
|
|
43
|
+
"peerDependencies": {
|
|
44
|
+
"playwright": ">=1.61 <2"
|
|
43
45
|
},
|
|
44
46
|
"scripts": {
|
|
45
47
|
"build": "pnpm --dir ../.. exec tsdown --config tsdown.packages.config.ts --filter @mizchi/vlmkit-capture",
|
|
46
|
-
"test": "
|
|
48
|
+
"test": "pnpm --dir ../.. exec vitest run packages/vlmkit-capture/src"
|
|
47
49
|
}
|
|
48
50
|
}
|