@mizchi/vlmkit-capture 0.8.0 → 0.8.1
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/batch-prescan.d.mts +51 -0
- package/dist/batch-prescan.mjs +66 -0
- package/dist/capture-config.d.mts +50 -0
- package/dist/capture-config.mjs +164 -0
- package/dist/capturer.d.mts +45 -0
- package/dist/capturer.mjs +94 -0
- package/dist/cloudflare-quick-actions.d.mts +114 -0
- package/dist/cloudflare-quick-actions.mjs +142 -0
- package/dist/crater-client.d.mts +159 -0
- package/dist/crater-client.mjs +362 -0
- package/dist/crater-smoke.d.mts +98 -0
- package/dist/crater-smoke.mjs +269 -0
- package/dist/crater-wasm.d.mts +65 -0
- package/dist/crater-wasm.mjs +132 -0
- package/{src/detection-types.ts → dist/detection-types.d.mts} +4 -2
- package/dist/detection-types.mjs +1 -0
- package/dist/index.d.mts +12 -0
- package/dist/index.mjs +11 -0
- package/dist/playwright-analyzer.d.mts +38 -0
- package/dist/playwright-analyzer.mjs +117 -0
- package/dist/playwright-launch-error.d.mts +7 -0
- package/dist/playwright-launch-error.mjs +25 -0
- package/dist/prescanner.d.mts +39 -0
- package/dist/prescanner.mjs +61 -0
- package/dist/viewport-discovery.d.mts +114 -0
- package/dist/viewport-discovery.mjs +294 -0
- package/package.json +18 -6
- package/src/batch-prescan.ts +0 -115
- package/src/capture-config.ts +0 -219
- package/src/capturer.ts +0 -138
- package/src/cloudflare-quick-actions.ts +0 -304
- package/src/crater-client.ts +0 -537
- package/src/crater-smoke.ts +0 -336
- package/src/crater-wasm.ts +0 -260
- package/src/index.ts +0 -157
- package/src/playwright-analyzer.ts +0 -180
- package/src/playwright-launch-error.ts +0 -41
- package/src/prescanner.ts +0 -123
- package/src/viewport-discovery.ts +0 -455
package/src/index.ts
DELETED
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @mizchi/vlmkit-capture — Playwright + Crater capture infrastructure
|
|
3
|
-
*
|
|
4
|
-
* The barrel re-exports the lightweight modules. `capturer.ts`
|
|
5
|
-
* (Playwright bootstrap) imports Playwright at module top-level and is
|
|
6
|
-
* intentionally NOT in the barrel — deep-import when you need it.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
// ---- Capture config (vrt.config.json + route resolution) ----
|
|
10
|
-
export {
|
|
11
|
-
parseCaptureConfig,
|
|
12
|
-
resolveCaptureRoutes,
|
|
13
|
-
loadCaptureConfigFromFile,
|
|
14
|
-
captureConfigDir,
|
|
15
|
-
routeNameFromPath,
|
|
16
|
-
DEFAULT_CAPTURE_BASE_URL,
|
|
17
|
-
DEFAULT_CAPTURE_ROUTES,
|
|
18
|
-
DEFAULT_CAPTURE_CONFIG_FILE,
|
|
19
|
-
type CaptureRoute,
|
|
20
|
-
type CaptureConfig,
|
|
21
|
-
type CaptureRouteSet,
|
|
22
|
-
type LoadCaptureConfigOptions,
|
|
23
|
-
} from "./capture-config.ts";
|
|
24
|
-
|
|
25
|
-
// ---- Viewport / breakpoint discovery ----
|
|
26
|
-
export {
|
|
27
|
-
discoverViewports,
|
|
28
|
-
discoverViewportsViaCrater,
|
|
29
|
-
discoverViewportsWithBackend,
|
|
30
|
-
generateViewports,
|
|
31
|
-
extractBreakpoints,
|
|
32
|
-
extractBreakpointsFromHtml,
|
|
33
|
-
extractBreakpointsFromHtmlWithStylesheets,
|
|
34
|
-
extractResponsiveBreakpointsFromHtml,
|
|
35
|
-
extractResponsiveBreakpointsFromHtmlWithStylesheets,
|
|
36
|
-
extractStylesheetHrefsFromHtml,
|
|
37
|
-
toResponsiveBreakpoints,
|
|
38
|
-
mergeResponsiveBreakpoints,
|
|
39
|
-
type Breakpoint,
|
|
40
|
-
type CraterViewportSource,
|
|
41
|
-
type ResponsiveBreakpoint,
|
|
42
|
-
type ViewportSource,
|
|
43
|
-
type ViewportSpec,
|
|
44
|
-
type ViewportOptions,
|
|
45
|
-
type DiscoveryResult,
|
|
46
|
-
} from "./viewport-discovery.ts";
|
|
47
|
-
|
|
48
|
-
// ---- Playwright launch diagnostics ----
|
|
49
|
-
export {
|
|
50
|
-
isPlaywrightSandboxRestrictionError,
|
|
51
|
-
formatPlaywrightLaunchError,
|
|
52
|
-
} from "./playwright-launch-error.ts";
|
|
53
|
-
|
|
54
|
-
// ---- Cloudflare Browser Run Quick Actions ----
|
|
55
|
-
export {
|
|
56
|
-
buildCloudflareQuickActionEndpoint,
|
|
57
|
-
createCloudflareQuickActionsClient,
|
|
58
|
-
extractCloudflareCrawlRoutes,
|
|
59
|
-
resolveCloudflareQuickActionsConfig,
|
|
60
|
-
type CloudflareCrawlRecord,
|
|
61
|
-
type CloudflareCrawlRecordStatus,
|
|
62
|
-
type CloudflareCrawlRequest,
|
|
63
|
-
type CloudflareCrawlResult,
|
|
64
|
-
type CloudflareCrawlRoute,
|
|
65
|
-
type CloudflareCrawlStartResult,
|
|
66
|
-
type CloudflareQuickAction,
|
|
67
|
-
type CloudflareQuickActionEndpointInput,
|
|
68
|
-
type CloudflareQuickActionsConfig,
|
|
69
|
-
type CloudflareQuickActionsEnv,
|
|
70
|
-
type CloudflareScreenshotRequest,
|
|
71
|
-
type CloudflareScreenshotResult,
|
|
72
|
-
} from "./cloudflare-quick-actions.ts";
|
|
73
|
-
|
|
74
|
-
// ---- Playwright report analyzer ----
|
|
75
|
-
export {
|
|
76
|
-
analyzeReport,
|
|
77
|
-
collectScreenshots,
|
|
78
|
-
formatStats,
|
|
79
|
-
type AnalyzedReport,
|
|
80
|
-
type FailedTest,
|
|
81
|
-
type ReportStats,
|
|
82
|
-
} from "./playwright-analyzer.ts";
|
|
83
|
-
|
|
84
|
-
// ---- Prescanner (signal aggregator) ----
|
|
85
|
-
export {
|
|
86
|
-
hasAnyDetectionSignal,
|
|
87
|
-
hasCraterPrescanSignal,
|
|
88
|
-
resolvePrescannerTrial,
|
|
89
|
-
summarizePrescannerTrials,
|
|
90
|
-
type PrescannerResolvedBy,
|
|
91
|
-
type PrescannerTrialResolution,
|
|
92
|
-
type PrescannerTrialSummary,
|
|
93
|
-
} from "./prescanner.ts";
|
|
94
|
-
|
|
95
|
-
// ---- Crater client (Bidi protocol) ----
|
|
96
|
-
export {
|
|
97
|
-
CraterClient,
|
|
98
|
-
CRATER_BIDI_URL_ENV,
|
|
99
|
-
CRATER_ROOT_ENV,
|
|
100
|
-
DEFAULT_BIDI_URL,
|
|
101
|
-
VLMKIT_CRATER_BIDI_URL_ENV,
|
|
102
|
-
VLMKIT_CRATER_ROOT_ENV,
|
|
103
|
-
resolveCraterBidiUrl,
|
|
104
|
-
type CraterResponsiveBreakpoint,
|
|
105
|
-
type CraterBreakpointDiscoveryDiagnostics,
|
|
106
|
-
type CraterRuleViewportMapEntry,
|
|
107
|
-
type CraterRuleViewportMap,
|
|
108
|
-
type CraterComputedStyleWithState,
|
|
109
|
-
type CraterCssMutation,
|
|
110
|
-
type CraterCssMutationAction,
|
|
111
|
-
type CraterRenderVariant,
|
|
112
|
-
type CraterBatchRenderResult,
|
|
113
|
-
type CraterBreakpointDiscoveryResult,
|
|
114
|
-
type PaintNode,
|
|
115
|
-
type PaintProps,
|
|
116
|
-
} from "./crater-client.ts";
|
|
117
|
-
export { isCraterAvailable } from "./crater-client.ts";
|
|
118
|
-
export {
|
|
119
|
-
CRATER_WASM_MODULE_ENV,
|
|
120
|
-
createCraterWasmLayoutBackend,
|
|
121
|
-
loadCraterWasmModule,
|
|
122
|
-
normalizeCraterLayoutJson,
|
|
123
|
-
summarizeCraterLayout,
|
|
124
|
-
type CraterBoxRect,
|
|
125
|
-
type CraterLayoutDiagnostics,
|
|
126
|
-
type CraterLayoutNode,
|
|
127
|
-
type CraterLayoutRootBox,
|
|
128
|
-
type CraterWasmLayoutBackend,
|
|
129
|
-
type CraterWasmModule,
|
|
130
|
-
type CraterWasmRenderRequest,
|
|
131
|
-
type CraterWasmRenderResult,
|
|
132
|
-
type CraterWasmViewport,
|
|
133
|
-
type LoadCraterWasmModuleOptions,
|
|
134
|
-
} from "./crater-wasm.ts";
|
|
135
|
-
export {
|
|
136
|
-
runCraterBidiSmoke,
|
|
137
|
-
formatCraterSmokeReport,
|
|
138
|
-
type CraterSmokeCheck,
|
|
139
|
-
type CraterSmokeClient,
|
|
140
|
-
type CraterSmokeReport,
|
|
141
|
-
type CraterSmokeStatus,
|
|
142
|
-
} from "./crater-smoke.ts";
|
|
143
|
-
|
|
144
|
-
// ---- Detection / paint-tree types ----
|
|
145
|
-
export * from "./detection-types.ts";
|
|
146
|
-
export { diffPaintTrees } from "./crater-client.ts";
|
|
147
|
-
|
|
148
|
-
// ---- Batch prescan (Crater v0.18.0 batchRender driver) ----
|
|
149
|
-
export {
|
|
150
|
-
hasAnyBatchPrescanSignal,
|
|
151
|
-
mutationsForPropertyRemoval,
|
|
152
|
-
mutationsForSelectorBlockRemoval,
|
|
153
|
-
runBatchPrescan,
|
|
154
|
-
type BatchPrescanOptions,
|
|
155
|
-
type BatchPrescanRequest,
|
|
156
|
-
type BatchPrescanResult,
|
|
157
|
-
} from "./batch-prescan.ts";
|
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
import { readFile, readdir, stat } from "node:fs/promises";
|
|
2
|
-
import { join, relative, basename } from "node:path";
|
|
3
|
-
import type {
|
|
4
|
-
PlaywrightReport,
|
|
5
|
-
TestSuite,
|
|
6
|
-
TestSpec,
|
|
7
|
-
VrtSnapshot,
|
|
8
|
-
Attachment,
|
|
9
|
-
} from "@mizchi/vlmkit-core/types.ts";
|
|
10
|
-
|
|
11
|
-
export interface AnalyzedReport {
|
|
12
|
-
snapshots: VrtSnapshot[];
|
|
13
|
-
failedTests: FailedTest[];
|
|
14
|
-
stats: ReportStats;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export interface FailedTest {
|
|
18
|
-
testId: string;
|
|
19
|
-
title: string;
|
|
20
|
-
project: string;
|
|
21
|
-
errors: string[];
|
|
22
|
-
attachments: Attachment[];
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export interface ReportStats {
|
|
26
|
-
total: number;
|
|
27
|
-
passed: number;
|
|
28
|
-
failed: number;
|
|
29
|
-
skipped: number;
|
|
30
|
-
flaky: number;
|
|
31
|
-
duration: number;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Playwright JSON レポートを読み込み、構造化された VRT データに変換する
|
|
36
|
-
*/
|
|
37
|
-
export async function analyzeReport(
|
|
38
|
-
reportPath: string
|
|
39
|
-
): Promise<AnalyzedReport> {
|
|
40
|
-
const raw = await readFile(reportPath, "utf-8");
|
|
41
|
-
const report: PlaywrightReport = JSON.parse(raw);
|
|
42
|
-
|
|
43
|
-
const snapshots: VrtSnapshot[] = [];
|
|
44
|
-
const failedTests: FailedTest[] = [];
|
|
45
|
-
const stats: ReportStats = {
|
|
46
|
-
total: 0,
|
|
47
|
-
passed: 0,
|
|
48
|
-
failed: 0,
|
|
49
|
-
skipped: 0,
|
|
50
|
-
flaky: 0,
|
|
51
|
-
duration: 0,
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
function walkSuites(suites: TestSuite[], prefix: string = "") {
|
|
55
|
-
for (const suite of suites) {
|
|
56
|
-
const suitePath = prefix ? `${prefix} > ${suite.title}` : suite.title;
|
|
57
|
-
|
|
58
|
-
for (const spec of suite.specs) {
|
|
59
|
-
processSpec(spec, suitePath);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
if (suite.suites) {
|
|
63
|
-
walkSuites(suite.suites, suitePath);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
function processSpec(spec: TestSpec, suitePath: string) {
|
|
69
|
-
for (const test of spec.tests) {
|
|
70
|
-
stats.total++;
|
|
71
|
-
stats.duration += test.duration;
|
|
72
|
-
|
|
73
|
-
const testId = `${suitePath} > ${spec.title}[${test.projectName}]`;
|
|
74
|
-
|
|
75
|
-
if (test.status === "skipped") {
|
|
76
|
-
stats.skipped++;
|
|
77
|
-
continue;
|
|
78
|
-
}
|
|
79
|
-
if (test.status === "flaky") stats.flaky++;
|
|
80
|
-
if (test.status === "expected") stats.passed++;
|
|
81
|
-
if (test.status === "unexpected") stats.failed++;
|
|
82
|
-
|
|
83
|
-
// 各 attempt からスクリーンショットを抽出
|
|
84
|
-
for (const attempt of test.results) {
|
|
85
|
-
const screenshots = attempt.attachments.filter(
|
|
86
|
-
(a) =>
|
|
87
|
-
a.contentType === "image/png" && a.path && !a.name.includes("trace")
|
|
88
|
-
);
|
|
89
|
-
|
|
90
|
-
for (const screenshot of screenshots) {
|
|
91
|
-
snapshots.push({
|
|
92
|
-
testId,
|
|
93
|
-
testTitle: spec.title,
|
|
94
|
-
projectName: test.projectName,
|
|
95
|
-
screenshotPath: screenshot.path!,
|
|
96
|
-
status: test.status === "expected" ? "unchanged" : "changed",
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
if (attempt.errors.length > 0) {
|
|
101
|
-
failedTests.push({
|
|
102
|
-
testId,
|
|
103
|
-
title: spec.title,
|
|
104
|
-
project: test.projectName,
|
|
105
|
-
errors: attempt.errors.map((e) => e.message),
|
|
106
|
-
attachments: attempt.attachments,
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
walkSuites(report.suites);
|
|
114
|
-
|
|
115
|
-
return { snapshots, failedTests, stats };
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* test-results ディレクトリからスクリーンショットファイルを収集し、
|
|
120
|
-
* ベースラインとの対応関係を構築する
|
|
121
|
-
*/
|
|
122
|
-
export async function collectScreenshots(
|
|
123
|
-
resultsDir: string,
|
|
124
|
-
baselineDir: string
|
|
125
|
-
): Promise<VrtSnapshot[]> {
|
|
126
|
-
const snapshots: VrtSnapshot[] = [];
|
|
127
|
-
|
|
128
|
-
async function walk(dir: string) {
|
|
129
|
-
let entries;
|
|
130
|
-
try {
|
|
131
|
-
entries = await readdir(dir, { withFileTypes: true });
|
|
132
|
-
} catch {
|
|
133
|
-
return;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
for (const entry of entries) {
|
|
137
|
-
const fullPath = join(dir, entry.name);
|
|
138
|
-
if (entry.isDirectory()) {
|
|
139
|
-
await walk(fullPath);
|
|
140
|
-
} else if (entry.name.endsWith(".png") && !entry.name.includes("diff")) {
|
|
141
|
-
const relPath = relative(resultsDir, fullPath);
|
|
142
|
-
const baselinePath = join(baselineDir, relPath);
|
|
143
|
-
let baselineExists = false;
|
|
144
|
-
try {
|
|
145
|
-
await stat(baselinePath);
|
|
146
|
-
baselineExists = true;
|
|
147
|
-
} catch {
|
|
148
|
-
// baseline doesn't exist
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
snapshots.push({
|
|
152
|
-
testId: relPath.replace(/\.png$/, ""),
|
|
153
|
-
testTitle: basename(relPath, ".png"),
|
|
154
|
-
projectName: relPath.split("/")[0] || "default",
|
|
155
|
-
screenshotPath: fullPath,
|
|
156
|
-
baselinePath: baselineExists ? baselinePath : undefined,
|
|
157
|
-
status: baselineExists ? "unchanged" : "new",
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
await walk(resultsDir);
|
|
164
|
-
return snapshots;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* レポートの統計サマリを人間可読な文字列にする
|
|
169
|
-
*/
|
|
170
|
-
export function formatStats(stats: ReportStats): string {
|
|
171
|
-
const lines = [
|
|
172
|
-
`Total: ${stats.total} tests`,
|
|
173
|
-
`Passed: ${stats.passed}`,
|
|
174
|
-
`Failed: ${stats.failed}`,
|
|
175
|
-
`Skipped: ${stats.skipped}`,
|
|
176
|
-
`Flaky: ${stats.flaky}`,
|
|
177
|
-
`Duration: ${(stats.duration / 1000).toFixed(1)}s`,
|
|
178
|
-
];
|
|
179
|
-
return lines.join("\n");
|
|
180
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
const FORMATTED_SANDBOX_MARKER = "Codex/macOS sandbox restriction";
|
|
2
|
-
const RAW_SANDBOX_SIGNAL_PATTERNS = [
|
|
3
|
-
"Operation not permitted",
|
|
4
|
-
"Permission denied",
|
|
5
|
-
"MachPortRendezvousServer",
|
|
6
|
-
"bootstrap_check_in",
|
|
7
|
-
"mach_port_rendezvous_mac.cc",
|
|
8
|
-
] as const;
|
|
9
|
-
|
|
10
|
-
function normalizeErrorMessage(error: unknown): string {
|
|
11
|
-
if (error instanceof Error) return error.message;
|
|
12
|
-
return String(error).replace(/^Error:\s*/, "");
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function isPlaywrightSandboxRestrictionError(error: unknown): boolean {
|
|
16
|
-
const message = normalizeErrorMessage(error);
|
|
17
|
-
return message.includes(FORMATTED_SANDBOX_MARKER)
|
|
18
|
-
|| (
|
|
19
|
-
message.includes("browserType.launch:")
|
|
20
|
-
&& RAW_SANDBOX_SIGNAL_PATTERNS.some((pattern) => message.includes(pattern))
|
|
21
|
-
);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export function formatPlaywrightLaunchError(
|
|
25
|
-
error: unknown,
|
|
26
|
-
options: { commandHint?: string } = {},
|
|
27
|
-
): string {
|
|
28
|
-
const message = normalizeErrorMessage(error);
|
|
29
|
-
if (!isPlaywrightSandboxRestrictionError(error)) return message;
|
|
30
|
-
if (message.includes(FORMATTED_SANDBOX_MARKER)) return message;
|
|
31
|
-
|
|
32
|
-
const hintBody = !options.commandHint
|
|
33
|
-
? "Re-run outside the Codex sandbox or in CI"
|
|
34
|
-
: /re-?run outside the codex sandbox/i.test(options.commandHint)
|
|
35
|
-
? options.commandHint
|
|
36
|
-
: `Re-run outside the Codex sandbox or ${options.commandHint}`;
|
|
37
|
-
const hint = ` ${hintBody}.`;
|
|
38
|
-
|
|
39
|
-
const originalLine = message.split("\n").find((line) => line.trim().length > 0) ?? message;
|
|
40
|
-
return `Playwright browser launch is blocked by a ${FORMATTED_SANDBOX_MARKER}. Chromium itself is likely fine.${hint}\nOriginal error: ${originalLine}`;
|
|
41
|
-
}
|
package/src/prescanner.ts
DELETED
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
import type { ViewportDetectionResult } from "./detection-types.ts";
|
|
2
|
-
|
|
3
|
-
export type PrescannerResolvedBy = "crater" | "chromium" | "none";
|
|
4
|
-
|
|
5
|
-
/** Which Crater metadata signal first fired for a trial resolved by crater. */
|
|
6
|
-
export type PrescannerCraterSignal =
|
|
7
|
-
| "paint-tree"
|
|
8
|
-
| "computed-style"
|
|
9
|
-
| "forced-state"
|
|
10
|
-
| "visual"
|
|
11
|
-
| "none";
|
|
12
|
-
|
|
13
|
-
export interface PrescannerTrialResolution {
|
|
14
|
-
craterDetected: boolean;
|
|
15
|
-
fallbackUsed: boolean;
|
|
16
|
-
finalDetected: boolean;
|
|
17
|
-
resolvedBy: PrescannerResolvedBy;
|
|
18
|
-
/** Whether the crater path skipped PNG capture entirely (metadata-only). */
|
|
19
|
-
metadataOnly: boolean;
|
|
20
|
-
/** First crater signal type that fired (paint-tree wins over computed-style → forced-state → visual). */
|
|
21
|
-
craterSignal: PrescannerCraterSignal;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export interface PrescannerTrialSummary {
|
|
25
|
-
total: number;
|
|
26
|
-
detected: number;
|
|
27
|
-
craterResolved: number;
|
|
28
|
-
chromiumFallbacks: number;
|
|
29
|
-
chromiumDetected: number;
|
|
30
|
-
passedAfterFallback: number;
|
|
31
|
-
/** Trials resolved by crater that never captured a PNG (metadata-only detection). */
|
|
32
|
-
metadataOnly: number;
|
|
33
|
-
/** Per-signal breakdown of crater-resolved trials. */
|
|
34
|
-
craterBySignal: {
|
|
35
|
-
paintTree: number;
|
|
36
|
-
computedStyle: number;
|
|
37
|
-
forcedState: number;
|
|
38
|
-
visual: number;
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export function hasCraterPrescanSignal(viewports: ViewportDetectionResult[]): boolean {
|
|
43
|
-
return viewports.some((viewport) =>
|
|
44
|
-
viewport.visualDiffDetected ||
|
|
45
|
-
viewport.computedStyleDiffCount > 0 ||
|
|
46
|
-
viewport.hoverDiffDetected ||
|
|
47
|
-
viewport.paintTreeDiffCount > 0
|
|
48
|
-
);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export function hasAnyDetectionSignal(viewports: ViewportDetectionResult[]): boolean {
|
|
52
|
-
return viewports.some((viewport) =>
|
|
53
|
-
viewport.visualDiffDetected ||
|
|
54
|
-
viewport.a11yDiffDetected ||
|
|
55
|
-
viewport.computedStyleDiffCount > 0 ||
|
|
56
|
-
viewport.hoverDiffDetected ||
|
|
57
|
-
viewport.paintTreeDiffCount > 0,
|
|
58
|
-
);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/** Classify the first crater signal that fired. */
|
|
62
|
-
function classifyCraterSignal(viewports: ViewportDetectionResult[]): PrescannerCraterSignal {
|
|
63
|
-
if (viewports.some((v) => v.paintTreeDiffCount > 0)) return "paint-tree";
|
|
64
|
-
if (viewports.some((v) => v.computedStyleDiffCount > 0)) return "computed-style";
|
|
65
|
-
if (viewports.some((v) => v.hoverDiffDetected)) return "forced-state";
|
|
66
|
-
if (viewports.some((v) => v.visualDiffDetected)) return "visual";
|
|
67
|
-
return "none";
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/** True when every viewport in the crater capture skipped its PNG. */
|
|
71
|
-
function isMetadataOnly(viewports: ViewportDetectionResult[]): boolean {
|
|
72
|
-
if (viewports.length === 0) return false;
|
|
73
|
-
return viewports.every((v) => v.visualCaptureSkipped === true);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export function resolvePrescannerTrial(
|
|
77
|
-
craterViewports: ViewportDetectionResult[],
|
|
78
|
-
chromiumViewports: ViewportDetectionResult[] = [],
|
|
79
|
-
): PrescannerTrialResolution {
|
|
80
|
-
const craterDetected = hasCraterPrescanSignal(craterViewports);
|
|
81
|
-
const metadataOnly = isMetadataOnly(craterViewports);
|
|
82
|
-
if (craterDetected) {
|
|
83
|
-
return {
|
|
84
|
-
craterDetected: true,
|
|
85
|
-
fallbackUsed: false,
|
|
86
|
-
finalDetected: true,
|
|
87
|
-
resolvedBy: "crater",
|
|
88
|
-
metadataOnly,
|
|
89
|
-
craterSignal: classifyCraterSignal(craterViewports),
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
const chromiumDetected = hasAnyDetectionSignal(chromiumViewports);
|
|
94
|
-
return {
|
|
95
|
-
craterDetected: false,
|
|
96
|
-
fallbackUsed: true,
|
|
97
|
-
finalDetected: chromiumDetected,
|
|
98
|
-
resolvedBy: chromiumDetected ? "chromium" : "none",
|
|
99
|
-
metadataOnly,
|
|
100
|
-
craterSignal: "none",
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
export function summarizePrescannerTrials(
|
|
105
|
-
resolutions: PrescannerTrialResolution[],
|
|
106
|
-
): PrescannerTrialSummary {
|
|
107
|
-
const craterResolved = resolutions.filter((r) => r.resolvedBy === "crater");
|
|
108
|
-
return {
|
|
109
|
-
total: resolutions.length,
|
|
110
|
-
detected: resolutions.filter((resolution) => resolution.finalDetected).length,
|
|
111
|
-
craterResolved: craterResolved.length,
|
|
112
|
-
chromiumFallbacks: resolutions.filter((resolution) => resolution.fallbackUsed).length,
|
|
113
|
-
chromiumDetected: resolutions.filter((resolution) => resolution.resolvedBy === "chromium").length,
|
|
114
|
-
passedAfterFallback: resolutions.filter((resolution) => resolution.resolvedBy === "none").length,
|
|
115
|
-
metadataOnly: craterResolved.filter((r) => r.metadataOnly).length,
|
|
116
|
-
craterBySignal: {
|
|
117
|
-
paintTree: craterResolved.filter((r) => r.craterSignal === "paint-tree").length,
|
|
118
|
-
computedStyle: craterResolved.filter((r) => r.craterSignal === "computed-style").length,
|
|
119
|
-
forcedState: craterResolved.filter((r) => r.craterSignal === "forced-state").length,
|
|
120
|
-
visual: craterResolved.filter((r) => r.craterSignal === "visual").length,
|
|
121
|
-
},
|
|
122
|
-
};
|
|
123
|
-
}
|