vibecode-anything 0.0.0-stage → 0.4.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.
Files changed (180) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +407 -2
  3. package/dist/cli.d.ts +2 -0
  4. package/dist/cli.js +2519 -0
  5. package/dist/core/adapters.d.ts +31 -0
  6. package/dist/core/adapters.js +478 -0
  7. package/dist/core/agent-adapter.d.ts +67 -0
  8. package/dist/core/agent-adapter.js +312 -0
  9. package/dist/core/anti-cheat.d.ts +6 -0
  10. package/dist/core/anti-cheat.js +372 -0
  11. package/dist/core/badge.d.ts +18 -0
  12. package/dist/core/badge.js +360 -0
  13. package/dist/core/cache.d.ts +47 -0
  14. package/dist/core/cache.js +403 -0
  15. package/dist/core/ci-export.d.ts +35 -0
  16. package/dist/core/ci-export.js +796 -0
  17. package/dist/core/ci-formats.d.ts +21 -0
  18. package/dist/core/ci-formats.js +388 -0
  19. package/dist/core/client-codegen.d.ts +36 -0
  20. package/dist/core/client-codegen.js +2538 -0
  21. package/dist/core/compose.d.ts +71 -0
  22. package/dist/core/compose.js +1088 -0
  23. package/dist/core/diff.d.ts +10 -0
  24. package/dist/core/diff.js +207 -0
  25. package/dist/core/docs-export.d.ts +37 -0
  26. package/dist/core/docs-export.js +2706 -0
  27. package/dist/core/doctor.d.ts +70 -0
  28. package/dist/core/doctor.js +525 -0
  29. package/dist/core/errors.d.ts +32 -0
  30. package/dist/core/errors.js +81 -0
  31. package/dist/core/exec.d.ts +38 -0
  32. package/dist/core/exec.js +336 -0
  33. package/dist/core/fixtures.d.ts +153 -0
  34. package/dist/core/fixtures.js +2245 -0
  35. package/dist/core/format.d.ts +77 -0
  36. package/dist/core/format.js +632 -0
  37. package/dist/core/fs-snapshot.d.ts +37 -0
  38. package/dist/core/fs-snapshot.js +216 -0
  39. package/dist/core/graphql-export.d.ts +34 -0
  40. package/dist/core/graphql-export.js +2482 -0
  41. package/dist/core/har-export.d.ts +29 -0
  42. package/dist/core/har-export.js +988 -0
  43. package/dist/core/html-report.d.ts +27 -0
  44. package/dist/core/html-report.js +1535 -0
  45. package/dist/core/http-export.d.ts +31 -0
  46. package/dist/core/http-export.js +726 -0
  47. package/dist/core/impact.d.ts +80 -0
  48. package/dist/core/impact.js +1412 -0
  49. package/dist/core/lint.d.ts +38 -0
  50. package/dist/core/lint.js +1111 -0
  51. package/dist/core/load-export.d.ts +37 -0
  52. package/dist/core/load-export.js +1813 -0
  53. package/dist/core/mcp-export.d.ts +35 -0
  54. package/dist/core/mcp-export.js +1736 -0
  55. package/dist/core/mock-server.d.ts +47 -0
  56. package/dist/core/mock-server.js +1722 -0
  57. package/dist/core/openapi-export.d.ts +44 -0
  58. package/dist/core/openapi-export.js +1074 -0
  59. package/dist/core/parity.d.ts +14 -0
  60. package/dist/core/parity.js +173 -0
  61. package/dist/core/playwright-exporter.d.ts +23 -0
  62. package/dist/core/playwright-exporter.js +1343 -0
  63. package/dist/core/png.d.ts +7 -0
  64. package/dist/core/png.js +339 -0
  65. package/dist/core/regression.d.ts +54 -0
  66. package/dist/core/regression.js +529 -0
  67. package/dist/core/responsive.d.ts +86 -0
  68. package/dist/core/responsive.js +606 -0
  69. package/dist/core/run.d.ts +74 -0
  70. package/dist/core/run.js +696 -0
  71. package/dist/core/scheduler.d.ts +24 -0
  72. package/dist/core/scheduler.js +162 -0
  73. package/dist/core/schema-export.d.ts +29 -0
  74. package/dist/core/schema-export.js +2215 -0
  75. package/dist/core/schema.d.ts +18 -0
  76. package/dist/core/schema.js +1057 -0
  77. package/dist/core/security.d.ts +233 -0
  78. package/dist/core/security.js +1839 -0
  79. package/dist/core/server-export.d.ts +38 -0
  80. package/dist/core/server-export.js +3198 -0
  81. package/dist/core/slices.d.ts +24 -0
  82. package/dist/core/slices.js +294 -0
  83. package/dist/core/spec-writer.d.ts +9 -0
  84. package/dist/core/spec-writer.js +1202 -0
  85. package/dist/core/store.d.ts +26 -0
  86. package/dist/core/store.js +217 -0
  87. package/dist/core/target-map.d.ts +34 -0
  88. package/dist/core/target-map.js +262 -0
  89. package/dist/core/test-exporter.d.ts +25 -0
  90. package/dist/core/test-exporter.js +1918 -0
  91. package/dist/core/types.d.ts +919 -0
  92. package/dist/core/types.js +4 -0
  93. package/dist/core/visual-semantic.d.ts +67 -0
  94. package/dist/core/visual-semantic.js +673 -0
  95. package/dist/core/visual.d.ts +34 -0
  96. package/dist/core/visual.js +508 -0
  97. package/dist/core/watch.d.ts +78 -0
  98. package/dist/core/watch.js +495 -0
  99. package/dist/core/yaml.d.ts +5 -0
  100. package/dist/core/yaml.js +1009 -0
  101. package/dist/diagnostics/diagnose.d.ts +53 -0
  102. package/dist/diagnostics/diagnose.js +1083 -0
  103. package/dist/diagnostics/flake.d.ts +71 -0
  104. package/dist/diagnostics/flake.js +608 -0
  105. package/dist/diagnostics/mutation-audit.d.ts +69 -0
  106. package/dist/diagnostics/mutation-audit.js +769 -0
  107. package/dist/diagnostics/spatial.d.ts +42 -0
  108. package/dist/diagnostics/spatial.js +346 -0
  109. package/dist/diagnostics/trends.d.ts +122 -0
  110. package/dist/diagnostics/trends.js +1190 -0
  111. package/dist/discovery/discover.d.ts +111 -0
  112. package/dist/discovery/discover.js +2017 -0
  113. package/dist/discovery/lock.d.ts +116 -0
  114. package/dist/discovery/lock.js +1505 -0
  115. package/dist/discovery/routes.d.ts +36 -0
  116. package/dist/discovery/routes.js +1494 -0
  117. package/dist/discovery/test-importer.d.ts +92 -0
  118. package/dist/discovery/test-importer.js +4952 -0
  119. package/dist/index.d.ts +123 -0
  120. package/dist/index.js +99 -0
  121. package/dist/ingestors/api-collections.d.ts +28 -0
  122. package/dist/ingestors/api-collections.js +2335 -0
  123. package/dist/ingestors/api-repo.d.ts +6 -0
  124. package/dist/ingestors/api-repo.js +1120 -0
  125. package/dist/ingestors/asyncapi.d.ts +26 -0
  126. package/dist/ingestors/asyncapi.js +2105 -0
  127. package/dist/ingestors/bridges.d.ts +5 -0
  128. package/dist/ingestors/bridges.js +1264 -0
  129. package/dist/ingestors/cli.d.ts +10 -0
  130. package/dist/ingestors/cli.js +454 -0
  131. package/dist/ingestors/curl.d.ts +14 -0
  132. package/dist/ingestors/curl.js +1024 -0
  133. package/dist/ingestors/graphql.d.ts +56 -0
  134. package/dist/ingestors/graphql.js +1852 -0
  135. package/dist/ingestors/http-file.d.ts +20 -0
  136. package/dist/ingestors/http-file.js +923 -0
  137. package/dist/ingestors/image.d.ts +2 -0
  138. package/dist/ingestors/image.js +147 -0
  139. package/dist/ingestors/index.d.ts +5 -0
  140. package/dist/ingestors/index.js +577 -0
  141. package/dist/ingestors/openrpc.d.ts +29 -0
  142. package/dist/ingestors/openrpc.js +1807 -0
  143. package/dist/ingestors/proto.d.ts +47 -0
  144. package/dist/ingestors/proto.js +2690 -0
  145. package/dist/ingestors/trace.d.ts +10 -0
  146. package/dist/ingestors/trace.js +599 -0
  147. package/dist/ingestors/video.d.ts +50 -0
  148. package/dist/ingestors/video.js +655 -0
  149. package/dist/ingestors/web.d.ts +40 -0
  150. package/dist/ingestors/web.js +839 -0
  151. package/dist/mcp/server.d.ts +2 -0
  152. package/dist/mcp/server.js +3969 -0
  153. package/dist/oracles/api-repo.d.ts +2 -0
  154. package/dist/oracles/api-repo.js +286 -0
  155. package/dist/oracles/cli.d.ts +2 -0
  156. package/dist/oracles/cli.js +205 -0
  157. package/dist/oracles/http-workflow.d.ts +68 -0
  158. package/dist/oracles/http-workflow.js +828 -0
  159. package/dist/oracles/image.d.ts +2 -0
  160. package/dist/oracles/image.js +429 -0
  161. package/dist/oracles/index.d.ts +6 -0
  162. package/dist/oracles/index.js +320 -0
  163. package/dist/oracles/perf-budget.d.ts +90 -0
  164. package/dist/oracles/perf-budget.js +1329 -0
  165. package/dist/oracles/stream.d.ts +94 -0
  166. package/dist/oracles/stream.js +1268 -0
  167. package/dist/oracles/ui-states.d.ts +49 -0
  168. package/dist/oracles/ui-states.js +894 -0
  169. package/dist/oracles/video.d.ts +21 -0
  170. package/dist/oracles/video.js +627 -0
  171. package/dist/oracles/web.d.ts +2 -0
  172. package/dist/oracles/web.js +871 -0
  173. package/dist/plugins/builtins.d.ts +12 -0
  174. package/dist/plugins/builtins.js +1052 -0
  175. package/dist/plugins/registry.d.ts +86 -0
  176. package/dist/plugins/registry.js +554 -0
  177. package/dist/setup/index.d.ts +7 -0
  178. package/dist/setup/index.js +298 -0
  179. package/package.json +54 -4
  180. package/skills/vibecode-anything/SKILL.md +75 -0
@@ -0,0 +1,871 @@
1
+ import crypto from "node:crypto";
2
+ import { VibecodeError, errorMessage } from "../core/errors.js";
3
+ import { loadPlaywright, launchBrowser } from "../core/adapters.js";
4
+ import { isRecordSafe, redactSensitiveText, resolveSafeTargetUrl } from "../core/security.js";
5
+ import { compareRegionsIoU } from "../core/visual.js";
6
+ import { auditResponsiveViewports, extractResponsiveSnapshotFromHtml } from "../core/responsive.js";
7
+ import { extractTitle, extractAllLandmarks, stripTags, openBrowserPage, gotoWithSpaFallback, extractInteractiveLandmarks } from "../ingestors/web.js";
8
+ import { filterRuntimeHeaders, mergeHeaders } from "../ingestors/trace.js";
9
+ const PLAYWRIGHT_INSTALL_HINT = "npm install -D playwright && npx playwright install chromium";
10
+ function resolvePlaywright(candidate) {
11
+ if (!candidate || typeof candidate !== "object")
12
+ return null;
13
+ const mod = candidate;
14
+ if (mod.chromium && typeof mod.chromium.launch === "function") {
15
+ return mod;
16
+ }
17
+ if (mod.default?.chromium && typeof mod.default.chromium.launch === "function") {
18
+ return mod.default;
19
+ }
20
+ return null;
21
+ }
22
+ async function getPlaywright(deps, cwd) {
23
+ const explicit = Object.prototype.hasOwnProperty.call(deps, "playwright") ? deps.playwright : undefined;
24
+ if (explicit === null)
25
+ return null;
26
+ const loaded = explicit !== undefined ? explicit : await loadPlaywright(cwd ? { ...deps, cwd } : deps);
27
+ return resolvePlaywright(loaded);
28
+ }
29
+ const isObject = isRecordSafe;
30
+ function expectsStatusGe500(expectedStatus) {
31
+ if (typeof expectedStatus === "number")
32
+ return expectedStatus >= 500;
33
+ if (Array.isArray(expectedStatus))
34
+ return expectedStatus.some((s) => typeof s === "number" && s >= 500);
35
+ return false;
36
+ }
37
+ function computeCandidateOutputHash(title, bodyText) {
38
+ const normalized = `${title}\n${bodyText}`.replace(/\s+/g, " ").trim();
39
+ if (!normalized)
40
+ return undefined;
41
+ return crypto.createHash("sha256").update(normalized, "utf8").digest("hex");
42
+ }
43
+ function checkInteractiveLandmarks(expected, actual) {
44
+ const failures = [];
45
+ const list = actual || [];
46
+ for (const exp of expected || []) {
47
+ if (!exp || (!exp.role && !exp.tag))
48
+ continue;
49
+ const expRole = exp.role ? String(exp.role).toLowerCase() : "";
50
+ const expTag = exp.tag ? String(exp.tag).toLowerCase() : "";
51
+ const expName = exp.name ? String(exp.name).trim().toLowerCase() : "";
52
+ const matched = list.some((act) => {
53
+ const actRole = String(act.role || "").toLowerCase();
54
+ const actTag = String(act.tag || "").toLowerCase();
55
+ const actName = String(act.name || "").trim().toLowerCase();
56
+ if (expRole && actRole !== expRole)
57
+ return false;
58
+ if (expTag && actTag !== expTag)
59
+ return false;
60
+ if (expName && !actName.includes(expName))
61
+ return false;
62
+ return true;
63
+ });
64
+ if (!matched) {
65
+ failures.push(`missing interactive landmark ${exp.role || "*"} <${exp.tag || "*"}>${exp.name ? ` (${JSON.stringify(exp.name)})` : ""}`);
66
+ }
67
+ }
68
+ return failures;
69
+ }
70
+ function buildUrl(base, routePath) {
71
+ return resolveSafeTargetUrl(routePath || "/", base).toString();
72
+ }
73
+ async function fetchRoute(url, timeoutMs = 15000, headers) {
74
+ const ctrl = new AbortController();
75
+ const t = setTimeout(() => ctrl.abort(), timeoutMs);
76
+ const cleanHeaders = filterRuntimeHeaders(headers);
77
+ try {
78
+ const res = await fetch(url, {
79
+ signal: ctrl.signal,
80
+ redirect: "follow",
81
+ ...(Object.keys(cleanHeaders).length > 0 ? { headers: cleanHeaders } : {})
82
+ });
83
+ const html = await res.text();
84
+ return { status: res.status, title: extractTitle(html), landmarks: extractAllLandmarks(html), html };
85
+ }
86
+ finally {
87
+ clearTimeout(t);
88
+ }
89
+ }
90
+ function checkLandmarks(expected, actualList) {
91
+ const failures = [];
92
+ const list = actualList || [];
93
+ const have = new Set(list.map((l) => String(l.tag).toLowerCase()));
94
+ for (const lm of expected || []) {
95
+ if (!lm || !lm.tag || lm.required === false)
96
+ continue;
97
+ const tag = String(lm.tag).toLowerCase();
98
+ if (!have.has(tag)) {
99
+ failures.push(`missing landmark <${lm.tag}>`);
100
+ continue;
101
+ }
102
+ if (lm.textContains) {
103
+ const ok = list.some((f) => String(f.tag).toLowerCase() === tag && String(f.text || "").includes(lm.textContains));
104
+ if (!ok)
105
+ failures.push(`landmark <${lm.tag}> missing text ${JSON.stringify(lm.textContains)}`);
106
+ }
107
+ }
108
+ return failures;
109
+ }
110
+ function checkStatus(expectedStatus, actualStatus) {
111
+ if (typeof expectedStatus === "number") {
112
+ return actualStatus === expectedStatus ? null : `status expected ${expectedStatus}, got ${actualStatus}`;
113
+ }
114
+ if (Array.isArray(expectedStatus) && expectedStatus.length > 0) {
115
+ return expectedStatus.includes(actualStatus)
116
+ ? null
117
+ : `status expected ${JSON.stringify(expectedStatus)}, got ${actualStatus}`;
118
+ }
119
+ return null;
120
+ }
121
+ function normalizeResponsiveViewports(raw) {
122
+ if (!Array.isArray(raw))
123
+ return [];
124
+ const out = [];
125
+ for (const vp of raw) {
126
+ if (vp &&
127
+ typeof vp === "object" &&
128
+ typeof vp.name === "string" &&
129
+ vp.name.trim().length > 0 &&
130
+ typeof vp.width === "number" &&
131
+ Number.isFinite(vp.width) &&
132
+ vp.width > 0 &&
133
+ typeof vp.height === "number" &&
134
+ Number.isFinite(vp.height) &&
135
+ vp.height > 0) {
136
+ out.push({ name: vp.name.trim(), width: vp.width, height: vp.height });
137
+ }
138
+ }
139
+ return out;
140
+ }
141
+ function applyResponsiveReport(responsive, failures, metrics, diff) {
142
+ metrics.responsive = {
143
+ passed: responsive.passed,
144
+ score: responsive.score,
145
+ viewportsChecked: responsive.viewportsChecked,
146
+ failedViewports: responsive.failedViewports,
147
+ totalErrors: responsive.totalErrors,
148
+ totalWarnings: responsive.totalWarnings,
149
+ viewports: responsive.viewports.map((v) => ({
150
+ name: v.viewport.name,
151
+ width: v.viewport.width,
152
+ height: v.viewport.height,
153
+ passed: v.passed,
154
+ errorCount: v.errorCount,
155
+ warningCount: v.warningCount,
156
+ scrollWidth: v.scrollWidth
157
+ }))
158
+ };
159
+ if (!responsive.passed) {
160
+ const errorIssues = responsive.issues.filter((i) => i.severity === "error");
161
+ const toReport = errorIssues.length > 0 ? errorIssues : responsive.issues;
162
+ for (const issue of toReport.slice(0, 15)) {
163
+ failures.push(`responsive [${issue.viewport}] ${issue.kind}: ${issue.message}`);
164
+ }
165
+ if (toReport.length > 15) {
166
+ failures.push(`responsive: ${toReport.length - 15} more responsive layout issues`);
167
+ }
168
+ diff.responsiveIssues = responsive.issues;
169
+ }
170
+ }
171
+ async function readPageHtmlFallback(page) {
172
+ if (typeof page.content === "function") {
173
+ try {
174
+ const html = await page.content();
175
+ if (typeof html === "string")
176
+ return html;
177
+ }
178
+ catch {
179
+ // fall through
180
+ }
181
+ }
182
+ try {
183
+ const html = await page.evaluate(() => {
184
+ if (typeof document === "undefined")
185
+ return "";
186
+ if (document.documentElement && typeof document.documentElement.outerHTML === "string") {
187
+ return document.documentElement.outerHTML;
188
+ }
189
+ if (document.body && typeof document.body.innerHTML === "string") {
190
+ return document.body.innerHTML;
191
+ }
192
+ return "";
193
+ });
194
+ return typeof html === "string" ? html : "";
195
+ }
196
+ catch {
197
+ return "";
198
+ }
199
+ }
200
+ async function capturePlaywrightResponsiveSnapshots(page, viewports, originalViewport) {
201
+ let cachedFallbackHtml = null;
202
+ const getFallbackHtml = async () => {
203
+ if (cachedFallbackHtml === null)
204
+ cachedFallbackHtml = await readPageHtmlFallback(page);
205
+ return cachedFallbackHtml;
206
+ };
207
+ if (typeof page.setViewportSize !== "function") {
208
+ const html = await getFallbackHtml();
209
+ return viewports.map((vp) => extractResponsiveSnapshotFromHtml(html, vp));
210
+ }
211
+ const snapshots = [];
212
+ try {
213
+ for (const vp of viewports) {
214
+ await page.setViewportSize({ width: vp.width, height: vp.height });
215
+ let evaluated = null;
216
+ try {
217
+ evaluated = await page.evaluate(() => {
218
+ if (typeof document === "undefined" || !document.documentElement)
219
+ return null;
220
+ const docEl = document.documentElement;
221
+ const body = document.body;
222
+ const scrollWidth = Math.max(Number(docEl.scrollWidth || 0), Number(body?.scrollWidth || 0));
223
+ const scrollHeight = Math.max(Number(docEl.scrollHeight || 0), Number(body?.scrollHeight || 0));
224
+ let hasViewportMeta;
225
+ if (typeof document.querySelectorAll === "function") {
226
+ const metas = document.querySelectorAll("meta");
227
+ hasViewportMeta = false;
228
+ for (let m = 0; m < metas.length; m++) {
229
+ const nameAttr = metas[m]?.getAttribute?.("name");
230
+ if (typeof nameAttr === "string" && nameAttr.trim().toLowerCase() === "viewport") {
231
+ hasViewportMeta = true;
232
+ break;
233
+ }
234
+ }
235
+ }
236
+ const elements = [];
237
+ if (typeof document.querySelectorAll === "function") {
238
+ const nodes = document.querySelectorAll("header,nav,main,footer,section,article,aside,form,table,h1,h2,h3,p,a,button,input,select,textarea,[role='button'],[role='link'],[data-testid]");
239
+ const interactiveSet = new Set(["a", "button", "input", "select", "textarea"]);
240
+ const limit = Math.min(nodes.length, 500);
241
+ for (let i = 0; i < limit; i++) {
242
+ const el = nodes[i];
243
+ if (!el || typeof el.getBoundingClientRect !== "function")
244
+ continue;
245
+ if (typeof window !== "undefined" && typeof window.getComputedStyle === "function") {
246
+ const cs = window.getComputedStyle(el);
247
+ if (cs && (cs.display === "none" || cs.visibility === "hidden" || cs.opacity === "0"))
248
+ continue;
249
+ }
250
+ const r = el.getBoundingClientRect();
251
+ const tag = String(el.tagName || "").toLowerCase();
252
+ const role = typeof el.getAttribute === "function" ? (el.getAttribute("role") || undefined) : undefined;
253
+ const interactive = interactiveSet.has(tag) || role === "button" || role === "link";
254
+ const idAttr = typeof el.getAttribute === "function" ? el.getAttribute("id") : el.id;
255
+ const testId = typeof el.getAttribute === "function" ? el.getAttribute("data-testid") : null;
256
+ const id = (idAttr && idAttr.trim()) || (testId && testId.trim()) || `${tag || "el"}-${i + 1}`;
257
+ elements.push({
258
+ id,
259
+ ...(tag ? { tag } : {}),
260
+ ...(role ? { role } : {}),
261
+ interactive,
262
+ visible: true,
263
+ bbox: { x: r.x, y: r.y, w: r.width, h: r.height }
264
+ });
265
+ }
266
+ }
267
+ return { scrollWidth, scrollHeight, hasViewportMeta, elements };
268
+ });
269
+ }
270
+ catch {
271
+ evaluated = null;
272
+ }
273
+ if (evaluated &&
274
+ typeof evaluated === "object" &&
275
+ typeof evaluated.scrollWidth === "number" &&
276
+ Number.isFinite(evaluated.scrollWidth) &&
277
+ Array.isArray(evaluated.elements)) {
278
+ snapshots.push({
279
+ viewport: vp,
280
+ scrollWidth: evaluated.scrollWidth,
281
+ scrollHeight: typeof evaluated.scrollHeight === "number" && Number.isFinite(evaluated.scrollHeight)
282
+ ? evaluated.scrollHeight
283
+ : vp.height,
284
+ elements: evaluated.elements,
285
+ ...(typeof evaluated.hasViewportMeta === "boolean" ? { hasViewportMeta: evaluated.hasViewportMeta } : {})
286
+ });
287
+ }
288
+ else {
289
+ const html = await getFallbackHtml();
290
+ snapshots.push(extractResponsiveSnapshotFromHtml(html, vp));
291
+ }
292
+ }
293
+ }
294
+ finally {
295
+ try {
296
+ await page.setViewportSize(originalViewport);
297
+ }
298
+ catch {
299
+ // ignore viewport restore errors
300
+ }
301
+ }
302
+ return snapshots;
303
+ }
304
+ async function verifyRouteWithFetch(invariant, ctx, deps) {
305
+ const input = invariant.input || {};
306
+ const expected = invariant.expected || {};
307
+ let url;
308
+ try {
309
+ url = buildUrl(ctx.target, input.path || "/");
310
+ }
311
+ catch (err) {
312
+ return {
313
+ status: "fail",
314
+ score: 0,
315
+ failures: [redactSensitiveText(`invalid URL: ${errorMessage(err)}`)],
316
+ metrics: { backend: "fetch", url: redactSensitiveText(String(input.path || ctx.target)) }
317
+ };
318
+ }
319
+ const safeUrl = redactSensitiveText(url);
320
+ const mergedHeaders = mergeHeaders(isObject(input.headers) ? input.headers : undefined, ctx.headers);
321
+ let obs;
322
+ try {
323
+ const timeout = input.timeoutMs || 15000;
324
+ obs =
325
+ Object.keys(mergedHeaders).length > 0
326
+ ? await (deps.fetchRoute || fetchRoute)(url, timeout, mergedHeaders)
327
+ : await (deps.fetchRoute || fetchRoute)(url, timeout);
328
+ }
329
+ catch (err) {
330
+ return {
331
+ status: "fail",
332
+ score: 0,
333
+ failures: [redactSensitiveText(`request failed: ${errorMessage(err)}`)],
334
+ metrics: { backend: "fetch", url: safeUrl }
335
+ };
336
+ }
337
+ const failures = [];
338
+ const statusErr = checkStatus(expected.status, obs.status);
339
+ if (statusErr)
340
+ failures.push(statusErr);
341
+ const enforceNoServerErrors = !expectsStatusGe500(expected.status) &&
342
+ (expected.noServerErrors === true || (expected.noServerErrors !== false && invariant.severity === "hard"));
343
+ if (obs.status >= 500 && enforceNoServerErrors) {
344
+ failures.push(`server error response: HTTP ${obs.status}`);
345
+ }
346
+ if (expected.titleContains && !String(obs.title).includes(expected.titleContains)) {
347
+ failures.push(`title missing ${JSON.stringify(expected.titleContains)} (got ${JSON.stringify(obs.title)})`);
348
+ }
349
+ failures.push(...checkLandmarks(expected.landmarks, obs.landmarks));
350
+ const candidateOutputHash = computeCandidateOutputHash(obs.title || "", stripTags(obs.html || ""));
351
+ const metrics = {
352
+ backend: "fetch",
353
+ status: obs.status,
354
+ title: obs.title,
355
+ landmarkCount: obs.landmarks.length,
356
+ ...(candidateOutputHash ? { candidateOutputHash } : {})
357
+ };
358
+ const diff = {};
359
+ const responsiveViewports = normalizeResponsiveViewports(expected.responsiveViewports);
360
+ let responsiveReport = null;
361
+ if (responsiveViewports.length > 0) {
362
+ const snapshots = responsiveViewports.map((vp) => extractResponsiveSnapshotFromHtml(obs.html || "", vp));
363
+ responsiveReport = auditResponsiveViewports(snapshots);
364
+ applyResponsiveReport(responsiveReport, failures, metrics, diff);
365
+ }
366
+ const hasDiff = Object.keys(diff).length > 0;
367
+ const score = failures.length === 0
368
+ ? 1
369
+ : invariant.severity === "soft" && responsiveReport
370
+ ? responsiveReport.score
371
+ : 0;
372
+ return {
373
+ status: failures.length ? "fail" : "pass",
374
+ score,
375
+ failures,
376
+ metrics,
377
+ ...(hasDiff ? { diff } : {})
378
+ };
379
+ }
380
+ function dedupeBoxes(boxes) {
381
+ const seen = new Set();
382
+ const out = [];
383
+ for (const b of boxes || []) {
384
+ const key = b.selector || b.id;
385
+ if (!key || seen.has(key))
386
+ continue;
387
+ seen.add(key);
388
+ out.push({ id: key, bbox: b.bbox });
389
+ }
390
+ return out;
391
+ }
392
+ async function verifyRouteWithPlaywright(invariant, ctx, _deps, pw) {
393
+ const input = invariant.input || {};
394
+ const expected = invariant.expected || {};
395
+ let url;
396
+ try {
397
+ url = buildUrl(ctx.target, input.path || "/");
398
+ }
399
+ catch (err) {
400
+ return {
401
+ status: "fail",
402
+ score: 0,
403
+ failures: [redactSensitiveText(`invalid URL: ${errorMessage(err)}`)],
404
+ metrics: { backend: "playwright" }
405
+ };
406
+ }
407
+ const viewport = input.viewport || { width: 1280, height: 720 };
408
+ const mergedHeaders = mergeHeaders(isObject(input.headers) ? input.headers : undefined, ctx.headers);
409
+ const storageState = ctx.storageState || input.storageState;
410
+ const browser = await launchBrowser(pw, { headless: true, featureName: "web_route verification" });
411
+ try {
412
+ const pageHandle = await openBrowserPage(browser, { viewport, headers: mergedHeaders, storageState });
413
+ const { page } = pageHandle;
414
+ try {
415
+ const telemetry = await attachTelemetry(page);
416
+ let response = null;
417
+ try {
418
+ response = await gotoWithSpaFallback(page, url, input.waitUntil || "networkidle", input.timeoutMs || 15000);
419
+ }
420
+ catch (err) {
421
+ return { status: "fail", score: 0, failures: [redactSensitiveText(`navigation failed: ${errorMessage(err)}`)], metrics: { backend: "playwright" } };
422
+ }
423
+ const failures = [];
424
+ const status = response?.status?.() ?? 200;
425
+ const statusErr = checkStatus(expected.status, status);
426
+ if (statusErr)
427
+ failures.push(statusErr);
428
+ const title = await page.title();
429
+ if (expected.titleContains && !String(title).includes(expected.titleContains)) {
430
+ failures.push(`title missing ${JSON.stringify(expected.titleContains)} (got ${JSON.stringify(title)})`);
431
+ }
432
+ const wantsParagraph = (expected.landmarks || []).some((l) => String(l.tag).toLowerCase() === "p");
433
+ const selector = wantsParagraph
434
+ ? "header,nav,main,footer,h1,h2,form,table,ul,p"
435
+ : "header,nav,main,footer,h1,h2,form,table,ul";
436
+ const found = await page.$$eval(selector, (nodes) => nodes.map((n) => ({ tag: n.tagName.toLowerCase(), text: (n.textContent || "").trim().slice(0, 120) }))).catch(() => []);
437
+ failures.push(...checkLandmarks(expected.landmarks, found));
438
+ const metrics = { backend: "playwright", status, title, landmarkCount: found.length };
439
+ const diff = {};
440
+ if (Array.isArray(expected.interactiveLandmarks) && expected.interactiveLandmarks.length > 0) {
441
+ const foundInteractive = await extractInteractiveLandmarks(page);
442
+ metrics.interactiveLandmarkCount = foundInteractive.length;
443
+ failures.push(...checkInteractiveLandmarks(expected.interactiveLandmarks, foundInteractive));
444
+ }
445
+ if (Array.isArray(expected.boundingBoxes) && expected.boundingBoxes.length) {
446
+ const actualBoxes = [];
447
+ for (const item of expected.boundingBoxes) {
448
+ const sel = item.selector;
449
+ if (!sel)
450
+ continue;
451
+ const box = await page.$eval(sel, (el) => {
452
+ const r = el.getBoundingClientRect();
453
+ return { x: r.x / (window.innerWidth || 1), y: r.y / (window.innerHeight || 1), w: r.width / (window.innerWidth || 1), h: r.height / (window.innerHeight || 1) };
454
+ }).catch(() => null);
455
+ if (box &&
456
+ Number.isFinite(box.x) &&
457
+ Number.isFinite(box.y) &&
458
+ Number.isFinite(box.w) &&
459
+ Number.isFinite(box.h) &&
460
+ box.w > 0 &&
461
+ box.h > 0) {
462
+ actualBoxes.push({ selector: sel, bbox: box });
463
+ }
464
+ }
465
+ const cmp = compareRegionsIoU(dedupeBoxes(expected.boundingBoxes), dedupeBoxes(actualBoxes));
466
+ metrics.layoutIoU = cmp.meanIoU;
467
+ const minIoU = invariant.tolerance?.minLayoutIoU ?? 0.75;
468
+ if (cmp.meanIoU < minIoU)
469
+ failures.push(`layoutIoU ${cmp.meanIoU.toFixed(3)} < ${minIoU}`);
470
+ }
471
+ const responsiveViewports = normalizeResponsiveViewports(expected.responsiveViewports);
472
+ let responsiveReport = null;
473
+ if (responsiveViewports.length > 0) {
474
+ const snapshots = await capturePlaywrightResponsiveSnapshots(page, responsiveViewports, viewport);
475
+ responsiveReport = auditResponsiveViewports(snapshots);
476
+ applyResponsiveReport(responsiveReport, failures, metrics, diff);
477
+ }
478
+ const telemetryNow = telemetry.collect();
479
+ const enforceNoPageErrors = expected.noPageErrors === true || (expected.noPageErrors !== false && invariant.severity === "hard");
480
+ if (enforceNoPageErrors) {
481
+ for (const err of telemetryNow.pageErrors) {
482
+ failures.push(`uncaught page error: ${err}`);
483
+ }
484
+ }
485
+ const serverErrorResponses = telemetryNow.network.filter((c) => c.status >= 500);
486
+ if (status >= 500 && !serverErrorResponses.some((c) => c.status === status)) {
487
+ let reqPath = "/";
488
+ try {
489
+ reqPath = new URL(url).pathname;
490
+ }
491
+ catch { /* keep "/" */ }
492
+ serverErrorResponses.push({ method: "GET", pathPattern: reqPath, status });
493
+ }
494
+ const enforceNoServerErrors = !expectsStatusGe500(expected.status) &&
495
+ (expected.noServerErrors === true || (expected.noServerErrors !== false && invariant.severity === "hard"));
496
+ if (enforceNoServerErrors) {
497
+ for (const errRes of serverErrorResponses) {
498
+ failures.push(`server error response: ${errRes.method} ${errRes.pathPattern} returned HTTP ${errRes.status}`);
499
+ }
500
+ }
501
+ let bodyText = "";
502
+ try {
503
+ bodyText = await page.evaluate(() => typeof document !== "undefined" && document.body ? (document.body.innerText || document.body.textContent || "") : "");
504
+ }
505
+ catch { /* ignore */ }
506
+ const candidateOutputHash = computeCandidateOutputHash(title || "", bodyText || "");
507
+ if (candidateOutputHash) {
508
+ metrics.candidateOutputHash = candidateOutputHash;
509
+ }
510
+ metrics.pageErrors = telemetryNow.pageErrors.length;
511
+ metrics.serverErrors = serverErrorResponses.length;
512
+ const hasDiff = Object.keys(diff).length > 0;
513
+ const score = invariant.severity === "soft" && typeof metrics.layoutIoU === "number"
514
+ ? (responsiveReport ? Math.min(metrics.layoutIoU, responsiveReport.score) : metrics.layoutIoU)
515
+ : invariant.severity === "soft" && responsiveReport
516
+ ? (failures.length ? responsiveReport.score : 1)
517
+ : (failures.length ? 0 : 1);
518
+ return { status: failures.length ? "fail" : "pass", score, failures, metrics, ...(hasDiff ? { diff } : {}) };
519
+ }
520
+ finally {
521
+ await pageHandle.close();
522
+ }
523
+ }
524
+ finally {
525
+ try {
526
+ await browser.close();
527
+ }
528
+ catch { /* ignore */ }
529
+ }
530
+ }
531
+ async function verifyRoute(invariant, ctx, deps) {
532
+ if (!ctx.target)
533
+ throw new VibecodeError("TARGET_MISSING", "Missing --target <url> for web verification.");
534
+ const pw = await getPlaywright(deps, ctx.cwd);
535
+ if (pw) {
536
+ try {
537
+ return await verifyRouteWithPlaywright(invariant, ctx, deps, pw);
538
+ }
539
+ catch (err) {
540
+ if (err instanceof VibecodeError && err.code !== "ADAPTER_MISSING")
541
+ throw err;
542
+ if (Array.isArray(invariant.expected?.boundingBoxes) && invariant.expected.boundingBoxes.length > 0) {
543
+ if (err instanceof VibecodeError)
544
+ throw err;
545
+ }
546
+ // fall through to fetch fallback
547
+ }
548
+ }
549
+ if (Array.isArray(invariant.expected?.boundingBoxes) && invariant.expected.boundingBoxes.length > 0) {
550
+ throw new VibecodeError("ADAPTER_MISSING", "web_route boundingBoxes verification requires Playwright", {
551
+ adapter: "playwright",
552
+ installHint: PLAYWRIGHT_INSTALL_HINT
553
+ });
554
+ }
555
+ return verifyRouteWithFetch(invariant, ctx, deps);
556
+ }
557
+ async function attachTelemetry(page) {
558
+ const network = [];
559
+ const consoleErrors = [];
560
+ const pageErrors = [];
561
+ if (typeof page.on === "function") {
562
+ page.on("response", (res) => {
563
+ try {
564
+ const resRec = res;
565
+ const rawUrl = typeof resRec.url === "function" ? resRec.url() : String(resRec.url ?? "");
566
+ const parsed = new URL(rawUrl);
567
+ const reqObj = typeof resRec.request === "function" ? resRec.request() : undefined;
568
+ const method = reqObj && typeof reqObj.method === "function"
569
+ ? reqObj.method()
570
+ : String(reqObj?.method ?? "GET");
571
+ const status = typeof resRec.status === "function" ? resRec.status() : Number(resRec.status ?? 200);
572
+ const headersObj = typeof resRec.headers === "function" ? resRec.headers() : resRec.headers;
573
+ network.push({ method, pathPattern: parsed.pathname, status, contentType: headersObj?.["content-type"] });
574
+ }
575
+ catch { /* ignore */ }
576
+ });
577
+ page.on("console", (msg) => { if (msg.type?.() === "error")
578
+ consoleErrors.push(msg.text?.() ?? String(msg)); });
579
+ page.on("pageerror", (err) => pageErrors.push(err?.message || String(err)));
580
+ }
581
+ return {
582
+ collect() {
583
+ return {
584
+ network: network.length > 0 ? network : (Array.isArray(page.__networkCalls) ? page.__networkCalls : network),
585
+ consoleErrors: consoleErrors.length > 0 ? consoleErrors : (Array.isArray(page.__consoleErrors) ? page.__consoleErrors : consoleErrors),
586
+ pageErrors: pageErrors.length > 0 ? pageErrors : (Array.isArray(page.__pageErrors) ? page.__pageErrors : pageErrors)
587
+ };
588
+ }
589
+ };
590
+ }
591
+ async function verifyFlow(invariant, ctx, deps) {
592
+ if (!ctx.target)
593
+ throw new VibecodeError("TARGET_MISSING", "Missing --target <url> for web flow verification.");
594
+ const pw = await getPlaywright(deps, ctx.cwd);
595
+ if (!pw) {
596
+ throw new VibecodeError("ADAPTER_MISSING", "web_flow verification requires Playwright", {
597
+ adapter: "playwright",
598
+ installHint: PLAYWRIGHT_INSTALL_HINT
599
+ });
600
+ }
601
+ const input = invariant.input || {};
602
+ const expected = invariant.expected || {};
603
+ let startUrl;
604
+ try {
605
+ startUrl = buildUrl(ctx.target, input.startPath || "/");
606
+ }
607
+ catch (err) {
608
+ return {
609
+ status: "fail",
610
+ score: 0,
611
+ failures: [redactSensitiveText(`invalid startPath URL: ${errorMessage(err)}`)],
612
+ metrics: { backend: "playwright" }
613
+ };
614
+ }
615
+ const viewport = input.viewport || { width: 1280, height: 720 };
616
+ const mergedHeaders = mergeHeaders(isObject(input.headers) ? input.headers : undefined, ctx.headers);
617
+ const storageState = ctx.storageState || input.storageState;
618
+ const browser = await launchBrowser(pw, { headless: true, featureName: "web_flow verification" });
619
+ try {
620
+ const pageHandle = await openBrowserPage(browser, { viewport, headers: mergedHeaders, storageState });
621
+ const { page } = pageHandle;
622
+ try {
623
+ const actionPage = page;
624
+ const telemetry = await attachTelemetry(page);
625
+ const failures = [];
626
+ const navTimeoutMs = input.timeoutMs || 15000;
627
+ try {
628
+ await gotoWithSpaFallback(page, startUrl, input.waitUntil || "networkidle", navTimeoutMs);
629
+ }
630
+ catch (err) {
631
+ return {
632
+ status: "fail",
633
+ score: 0,
634
+ failures: [redactSensitiveText(`navigation failed: ${errorMessage(err)}`)],
635
+ metrics: { backend: "playwright" }
636
+ };
637
+ }
638
+ for (const step of input.steps || []) {
639
+ try {
640
+ const selector = step.selector ?? "";
641
+ const stepTimeoutMs = step.timeoutMs || input.timeoutMs || 5000;
642
+ if (step.action === "fill")
643
+ await actionPage.fill(selector, String(step.value ?? ""), { timeout: stepTimeoutMs });
644
+ else if (step.action === "click")
645
+ await actionPage.click(selector, { timeout: stepTimeoutMs });
646
+ else if (step.action === "press")
647
+ await actionPage.press(selector, step.key || "Enter", { timeout: stepTimeoutMs });
648
+ else if (step.action === "goto") {
649
+ await gotoWithSpaFallback(page, buildUrl(ctx.target, step.url || step.path || "/"), step.waitUntil || "networkidle", step.timeoutMs || input.timeoutMs || 15000);
650
+ }
651
+ else if (step.action === "select") {
652
+ await actionPage.selectOption(selector, String(step.value ?? ""), { timeout: stepTimeoutMs });
653
+ }
654
+ else if (step.action === "waitFor") {
655
+ const timeout = step.timeoutMs || input.timeoutMs || 3000;
656
+ if (typeof page.waitForFunction === "function") {
657
+ await page.waitForFunction((txt) => Boolean(document.body && document.body.innerText.includes(txt)), String(step.text ?? step.value ?? ""), { timeout });
658
+ }
659
+ else if (typeof page.waitForTimeout === "function") {
660
+ await page.waitForTimeout(Math.min(timeout, 50));
661
+ }
662
+ }
663
+ else if (step.action === "waitForSelector") {
664
+ await page.waitForSelector(selector, { timeout: step.timeoutMs || input.timeoutMs || 3000 });
665
+ }
666
+ else {
667
+ failures.push(`unsupported flow step action: ${step.action}`);
668
+ }
669
+ }
670
+ catch (err) {
671
+ failures.push(redactSensitiveText(`step ${step.action} failed: ${errorMessage(err)}`));
672
+ }
673
+ }
674
+ const rawFinalUrl = typeof page.url === "function" ? page.url() : startUrl;
675
+ const finalUrl = redactSensitiveText(String(rawFinalUrl));
676
+ if (expected.finalUrlIncludes && !String(rawFinalUrl).includes(expected.finalUrlIncludes)) {
677
+ failures.push(`finalUrl ${finalUrl} does not include ${expected.finalUrlIncludes}`);
678
+ }
679
+ let bodyText = "";
680
+ try {
681
+ bodyText = await page.evaluate(() => typeof document !== "undefined" && document.body ? (document.body.innerText || document.body.textContent || "") : "");
682
+ }
683
+ catch { /* ignore */ }
684
+ for (const text of expected.visibleText || []) {
685
+ if (!bodyText.includes(text))
686
+ failures.push(`visibleText missing ${JSON.stringify(text)}`);
687
+ }
688
+ for (const text of expected.hiddenText || []) {
689
+ if (bodyText.includes(text))
690
+ failures.push(`hiddenText present ${JSON.stringify(text)}`);
691
+ }
692
+ const domCounts = {};
693
+ for (const assertion of expected.domAssertions || []) {
694
+ const count = await page.$$eval(assertion.selector, (els) => els.length).catch(() => 0);
695
+ domCounts[assertion.selector] = count;
696
+ if (typeof assertion.count === "number" && count !== assertion.count) {
697
+ failures.push(`domAssertion ${assertion.selector}: expected count ${assertion.count}, found ${count}`);
698
+ }
699
+ else if (count < (assertion.minCount || 1)) {
700
+ failures.push(`domAssertion ${assertion.selector}: found ${count} < ${assertion.minCount || 1}`);
701
+ }
702
+ }
703
+ const telemetryNow = telemetry.collect();
704
+ const networkCalls = telemetryNow.network || [];
705
+ for (const expectedCall of expected.networkCalls || []) {
706
+ const method = String(expectedCall.method || "GET").toUpperCase();
707
+ let re = null;
708
+ if (expectedCall.pathPattern) {
709
+ try {
710
+ re = new RegExp(expectedCall.pathPattern);
711
+ }
712
+ catch {
713
+ failures.push(`invalid pathPattern ${expectedCall.pathPattern}`);
714
+ continue;
715
+ }
716
+ }
717
+ const match = networkCalls.find((c) => String(c.method).toUpperCase() === method && (!re || re.test(c.pathPattern)) && (expectedCall.status === undefined || c.status === expectedCall.status));
718
+ if (!match)
719
+ failures.push(`missing network call ${method} ${expectedCall.pathPattern || ""}${expectedCall.status !== undefined ? " " + expectedCall.status : ""}`);
720
+ }
721
+ if (expected.noConsoleErrors) {
722
+ for (const err of telemetryNow.consoleErrors)
723
+ failures.push(`console error: ${err}`);
724
+ }
725
+ const enforceNoPageErrors = Boolean(expected.noUncaughtExceptions) ||
726
+ expected.noPageErrors === true ||
727
+ (expected.noPageErrors !== false && invariant.severity === "hard");
728
+ if (enforceNoPageErrors) {
729
+ for (const err of telemetryNow.pageErrors)
730
+ failures.push(`uncaught exception: ${err}`);
731
+ }
732
+ const expected500Matchers = (expected.networkCalls || []).filter((c) => typeof c.status === "number" && c.status >= 500);
733
+ const serverErrorResponses = networkCalls.filter((c) => {
734
+ if (c.status < 500)
735
+ return false;
736
+ return !expected500Matchers.some((exp) => {
737
+ const methodOk = !exp.method || String(exp.method).toUpperCase() === String(c.method).toUpperCase();
738
+ if (!methodOk || exp.status !== c.status)
739
+ return false;
740
+ if (!exp.pathPattern)
741
+ return true;
742
+ try {
743
+ return new RegExp(exp.pathPattern).test(c.pathPattern);
744
+ }
745
+ catch {
746
+ return false;
747
+ }
748
+ });
749
+ });
750
+ const enforceNoServerErrors = !expectsStatusGe500(expected.status) &&
751
+ (expected.noServerErrors === true || (expected.noServerErrors !== false && invariant.severity === "hard"));
752
+ if (enforceNoServerErrors) {
753
+ for (const errRes of serverErrorResponses) {
754
+ failures.push(`server error response: ${errRes.method} ${errRes.pathPattern} returned HTTP ${errRes.status}`);
755
+ }
756
+ }
757
+ const metrics = {
758
+ backend: "playwright",
759
+ finalUrl,
760
+ visibleTextLength: bodyText.length,
761
+ domCounts,
762
+ networkCalls: networkCalls.length,
763
+ consoleErrors: telemetryNow.consoleErrors.length,
764
+ pageErrors: telemetryNow.pageErrors.length,
765
+ serverErrors: serverErrorResponses.length
766
+ };
767
+ return { status: failures.length ? "fail" : "pass", score: failures.length ? 0 : 1, failures, metrics };
768
+ }
769
+ finally {
770
+ await pageHandle.close();
771
+ }
772
+ }
773
+ finally {
774
+ try {
775
+ await browser.close();
776
+ }
777
+ catch { /* ignore */ }
778
+ }
779
+ }
780
+ async function verifyNetwork(invariant, ctx, deps) {
781
+ if (!ctx.target)
782
+ throw new VibecodeError("TARGET_MISSING", "Missing --target <url> for web network verification.");
783
+ const pw = await getPlaywright(deps, ctx.cwd);
784
+ if (!pw) {
785
+ throw new VibecodeError("ADAPTER_MISSING", "web_network verification requires Playwright", {
786
+ adapter: "playwright",
787
+ installHint: PLAYWRIGHT_INSTALL_HINT
788
+ });
789
+ }
790
+ const input = invariant.input || {};
791
+ const expected = invariant.expected || {};
792
+ let url;
793
+ try {
794
+ url = buildUrl(ctx.target, input.triggerPath || input.path || "/");
795
+ }
796
+ catch (err) {
797
+ return {
798
+ status: "fail",
799
+ score: 0,
800
+ failures: [redactSensitiveText(`invalid URL: ${errorMessage(err)}`)],
801
+ metrics: { backend: "playwright" }
802
+ };
803
+ }
804
+ const mergedHeaders = mergeHeaders(isObject(input.headers) ? input.headers : undefined, ctx.headers);
805
+ const storageState = ctx.storageState || input.storageState;
806
+ const browser = await launchBrowser(pw, { headless: true, featureName: "web_network verification" });
807
+ try {
808
+ const pageHandle = await openBrowserPage(browser, {
809
+ viewport: input.viewport || { width: 1280, height: 720 },
810
+ headers: mergedHeaders,
811
+ storageState
812
+ });
813
+ const { page } = pageHandle;
814
+ try {
815
+ const telemetry = await attachTelemetry(page);
816
+ try {
817
+ await gotoWithSpaFallback(page, url, input.waitUntil || "networkidle", input.timeoutMs || 15000);
818
+ }
819
+ catch (err) {
820
+ return {
821
+ status: "fail",
822
+ score: 0,
823
+ failures: [redactSensitiveText(`navigation failed: ${errorMessage(err)}`)],
824
+ metrics: { backend: "playwright" }
825
+ };
826
+ }
827
+ const collected = telemetry.collect().network;
828
+ const failures = [];
829
+ for (const expectedCall of expected.networkCalls || []) {
830
+ const method = String(expectedCall.method || "GET").toUpperCase();
831
+ let re = null;
832
+ if (expectedCall.pathPattern) {
833
+ try {
834
+ re = new RegExp(expectedCall.pathPattern);
835
+ }
836
+ catch {
837
+ failures.push(`invalid pathPattern ${expectedCall.pathPattern}`);
838
+ continue;
839
+ }
840
+ }
841
+ const match = collected.find((c) => String(c.method).toUpperCase() === method && (!re || re.test(c.pathPattern)) && (expectedCall.status === undefined || c.status === expectedCall.status));
842
+ if (!match)
843
+ failures.push(`missing network call ${method} ${expectedCall.pathPattern || ""}${expectedCall.status !== undefined ? " " + expectedCall.status : ""}`);
844
+ }
845
+ return {
846
+ status: failures.length ? "fail" : "pass",
847
+ score: failures.length ? 0 : 1,
848
+ failures,
849
+ metrics: { backend: "playwright", networkCalls: collected.length }
850
+ };
851
+ }
852
+ finally {
853
+ await pageHandle.close();
854
+ }
855
+ }
856
+ finally {
857
+ try {
858
+ await browser.close();
859
+ }
860
+ catch { /* ignore */ }
861
+ }
862
+ }
863
+ export async function verifyInvariant(invariant, ctx, deps = {}) {
864
+ if (invariant.type === "web_route")
865
+ return verifyRoute(invariant, ctx, deps);
866
+ if (invariant.type === "web_flow")
867
+ return verifyFlow(invariant, ctx, deps);
868
+ if (invariant.type === "web_network")
869
+ return verifyNetwork(invariant, ctx, deps);
870
+ throw new VibecodeError("UNSUPPORTED_FORMAT", `Unsupported web invariant type: ${invariant.type}`);
871
+ }