sniff-qa 0.3.0 → 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 (34) hide show
  1. package/README.md +41 -0
  2. package/dist/classifier-XEA6ZGE7.js +673 -0
  3. package/dist/classifier-XEA6ZGE7.js.map +1 -0
  4. package/dist/cli/index.js +80 -4
  5. package/dist/cli/index.js.map +1 -1
  6. package/dist/discover-BLUSO42Q.js +228 -0
  7. package/dist/discover-BLUSO42Q.js.map +1 -0
  8. package/dist/domain-UQ34YE4B.js +1817 -0
  9. package/dist/domain-UQ34YE4B.js.map +1 -0
  10. package/dist/edge-cases-ZADKDZHL.js +246 -0
  11. package/dist/edge-cases-ZADKDZHL.js.map +1 -0
  12. package/dist/flakiness-OLJAY7CS.js +53 -0
  13. package/dist/flakiness-OLJAY7CS.js.map +1 -0
  14. package/dist/llm-VJAI6H6G.js +126 -0
  15. package/dist/llm-VJAI6H6G.js.map +1 -0
  16. package/dist/mcp/server.js +89 -0
  17. package/dist/mcp/server.js.map +1 -1
  18. package/dist/persistence-KTCRIGHU.js +270 -0
  19. package/dist/persistence-KTCRIGHU.js.map +1 -0
  20. package/dist/{repo-analyzer-WK5WP7NT.js → repo-analyzer-4OURSITY.js} +1 -1
  21. package/dist/report-SDZWX25B.js +280 -0
  22. package/dist/report-SDZWX25B.js.map +1 -0
  23. package/dist/{report-WLDV72FM.js → report-STC6CAVJ.js} +1 -1
  24. package/dist/runner-OYTN2NFD.js +996 -0
  25. package/dist/runner-OYTN2NFD.js.map +1 -0
  26. package/dist/scenarios-25UAZY6F.js +982 -0
  27. package/dist/scenarios-25UAZY6F.js.map +1 -0
  28. package/dist/tiebreak-L5UFNKU2.js +60 -0
  29. package/dist/tiebreak-L5UFNKU2.js.map +1 -0
  30. package/dist/{unified-7RKNG3EI.js → unified-2PM442OY.js} +2 -2
  31. package/package.json +1 -1
  32. /package/dist/{repo-analyzer-WK5WP7NT.js.map → repo-analyzer-4OURSITY.js.map} +0 -0
  33. /package/dist/{report-WLDV72FM.js.map → report-STC6CAVJ.js.map} +0 -0
  34. /package/dist/{unified-7RKNG3EI.js.map → unified-2PM442OY.js.map} +0 -0
@@ -0,0 +1,996 @@
1
+ // src/discovery/runner.ts
2
+ import { performance } from "perf_hooks";
3
+
4
+ // src/discovery/scenarios/personas.ts
5
+ var anonymous = {
6
+ name: "anonymous",
7
+ values: {
8
+ "email": "alex.taylor@example.test",
9
+ "firstName": "Alex",
10
+ "lastName": "Taylor",
11
+ "fullName": "Alex Taylor",
12
+ "phone": "+15555550100",
13
+ "query": "sample search"
14
+ }
15
+ };
16
+ var newCustomer = {
17
+ name: "new-customer",
18
+ values: {
19
+ "email": "morgan.quinn@example.test",
20
+ "password": "Correct-Horse-Battery-Staple-1",
21
+ "firstName": "Morgan",
22
+ "lastName": "Quinn",
23
+ "fullName": "Morgan Quinn",
24
+ "phone": "+15555550110",
25
+ "shipping.address": "123 Market Street",
26
+ "shipping.city": "San Francisco",
27
+ "shipping.state": "CA",
28
+ "shipping.zip": "94103",
29
+ "shipping.country": "US",
30
+ "card.number": "4242 4242 4242 4242",
31
+ "card.exp": "12/34",
32
+ "card.cvv": "123",
33
+ "card.nameOnCard": "Morgan Quinn"
34
+ }
35
+ };
36
+ var returningUser = {
37
+ name: "returning-user",
38
+ values: {
39
+ "email": "sam.rivera@example.test",
40
+ "password": "Correct-Horse-Battery-Staple-2",
41
+ "firstName": "Sam",
42
+ "lastName": "Rivera",
43
+ "fullName": "Sam Rivera",
44
+ "phone": "+15555550120"
45
+ }
46
+ };
47
+ var PERSONAS = {
48
+ anonymous,
49
+ "new-customer": newCustomer,
50
+ "returning-user": returningUser
51
+ };
52
+
53
+ // src/discovery/selectors.ts
54
+ var VISIBILITY_TIMEOUT_MS = 1500;
55
+ async function tryLocator(locator) {
56
+ try {
57
+ await locator.first().waitFor({ state: "visible", timeout: VISIBILITY_TIMEOUT_MS });
58
+ return true;
59
+ } catch {
60
+ return false;
61
+ }
62
+ }
63
+ function splitAlternatives(value) {
64
+ return value.split("|").map((s) => s.trim()).filter(Boolean);
65
+ }
66
+ async function resolveTarget(page, target) {
67
+ for (const hint of target.selectorHints) {
68
+ const locator = page.locator(hint);
69
+ if (await tryLocator(locator)) {
70
+ return { selector: hint, locator };
71
+ }
72
+ }
73
+ if (target.fallbackRoleText) {
74
+ const { role, name } = target.fallbackRoleText;
75
+ const alternatives = name ? splitAlternatives(name) : [""];
76
+ for (const altName of alternatives) {
77
+ const locator = altName ? page.getByRole(role, { name: new RegExp(altName, "i") }) : page.getByRole(role);
78
+ if (await tryLocator(locator)) {
79
+ return {
80
+ selector: altName ? `role=${role}[name=/${altName}/i]` : `role=${role}`,
81
+ locator
82
+ };
83
+ }
84
+ }
85
+ }
86
+ return null;
87
+ }
88
+
89
+ // src/discovery/validators/index.ts
90
+ async function validateConsoleClean(ctx) {
91
+ const errors = ctx.hookFindings.filter((f) => f.ruleId === "e2e/console-error");
92
+ return {
93
+ kind: "console-clean",
94
+ name: "no new console errors",
95
+ passed: errors.length === 0,
96
+ ...errors.length > 0 ? { detail: `${errors.length} console error(s) on step ${ctx.step.n}` } : {}
97
+ };
98
+ }
99
+ async function validateNetworkClean(ctx) {
100
+ const failures = ctx.hookFindings.filter((f) => f.ruleId === "e2e/network-failure");
101
+ return {
102
+ kind: "network-clean",
103
+ name: "no 4xx/5xx network failures",
104
+ passed: failures.length === 0,
105
+ ...failures.length > 0 ? { detail: `${failures.length} network failure(s)` } : {}
106
+ };
107
+ }
108
+ async function validateResponseTime(ctx, budgetMs) {
109
+ if (ctx.responseTimeMs === void 0) {
110
+ return { kind: "response-time", name: `response under ${budgetMs}ms`, passed: true };
111
+ }
112
+ const passed = ctx.responseTimeMs <= budgetMs;
113
+ return {
114
+ kind: "response-time",
115
+ name: `response under ${budgetMs}ms`,
116
+ passed,
117
+ ...passed ? {} : { detail: `took ${Math.round(ctx.responseTimeMs)}ms (budget ${budgetMs}ms)` }
118
+ };
119
+ }
120
+ async function validateVisibleTarget(ctx, resolvedSelector) {
121
+ if (!resolvedSelector) {
122
+ return { kind: "visible-target", name: "target is visible", passed: true };
123
+ }
124
+ try {
125
+ const visible = await ctx.page.locator(resolvedSelector).first().isVisible();
126
+ return {
127
+ kind: "visible-target",
128
+ name: "target is visible",
129
+ passed: visible,
130
+ ...visible ? {} : { detail: `selector ${resolvedSelector} is not visible` }
131
+ };
132
+ } catch (err) {
133
+ return {
134
+ kind: "visible-target",
135
+ name: "target is visible",
136
+ passed: false,
137
+ detail: err instanceof Error ? err.message : String(err)
138
+ };
139
+ }
140
+ }
141
+ async function validateLabelPresent(ctx, resolvedSelector) {
142
+ if (!resolvedSelector) {
143
+ return { kind: "label-present", name: "interactive target has a label", passed: true };
144
+ }
145
+ try {
146
+ const el = ctx.page.locator(resolvedSelector).first();
147
+ const tag = await el.evaluate((node) => node.tagName.toLowerCase());
148
+ if (tag !== "input" && tag !== "select" && tag !== "textarea") {
149
+ return { kind: "label-present", name: "interactive target has a label", passed: true };
150
+ }
151
+ const hasLabel = await el.evaluate((node) => {
152
+ const e = node;
153
+ if (e.getAttribute("aria-label")) return true;
154
+ if (e.getAttribute("aria-labelledby")) return true;
155
+ if (e.id) {
156
+ const byFor = document.querySelector(`label[for="${e.id}"]`);
157
+ if (byFor) return true;
158
+ }
159
+ const parentLabel = e.closest("label");
160
+ if (parentLabel) return true;
161
+ if (e.getAttribute("placeholder")) return true;
162
+ return false;
163
+ });
164
+ return {
165
+ kind: "label-present",
166
+ name: "interactive target has a label",
167
+ passed: hasLabel,
168
+ ...hasLabel ? {} : { detail: `${resolvedSelector} has no accessible label` }
169
+ };
170
+ } catch (err) {
171
+ return {
172
+ kind: "label-present",
173
+ name: "interactive target has a label",
174
+ passed: false,
175
+ detail: err instanceof Error ? err.message : String(err)
176
+ };
177
+ }
178
+ }
179
+ async function evaluateExpectation(ctx, expectation) {
180
+ switch (expectation.kind) {
181
+ case "url-matches": {
182
+ const url = ctx.page.url();
183
+ const passed = new RegExp(expectation.value).test(url);
184
+ return {
185
+ kind: "expect",
186
+ name: `url matches /${expectation.value}/`,
187
+ passed,
188
+ ...passed ? {} : { detail: `url was ${url}` }
189
+ };
190
+ }
191
+ case "text-visible": {
192
+ try {
193
+ const locator = ctx.page.getByText(new RegExp(expectation.value, "i"));
194
+ const count = await locator.count();
195
+ const passed = count > 0 && await locator.first().isVisible();
196
+ return {
197
+ kind: "expect",
198
+ name: `text visible: ${expectation.value}`,
199
+ passed,
200
+ ...passed ? {} : { detail: `no visible text matching /${expectation.value}/i` }
201
+ };
202
+ } catch (err) {
203
+ return {
204
+ kind: "expect",
205
+ name: `text visible: ${expectation.value}`,
206
+ passed: false,
207
+ detail: err instanceof Error ? err.message : String(err)
208
+ };
209
+ }
210
+ }
211
+ case "selector-visible": {
212
+ try {
213
+ const locator = ctx.page.locator(expectation.value).first();
214
+ const passed = await locator.isVisible();
215
+ return {
216
+ kind: "expect",
217
+ name: `selector visible: ${expectation.value}`,
218
+ passed,
219
+ ...passed ? {} : { detail: `${expectation.value} is not visible` }
220
+ };
221
+ } catch (err) {
222
+ return {
223
+ kind: "expect",
224
+ name: `selector visible: ${expectation.value}`,
225
+ passed: false,
226
+ detail: err instanceof Error ? err.message : String(err)
227
+ };
228
+ }
229
+ }
230
+ case "network-status":
231
+ return { kind: "expect", name: "network status", passed: true };
232
+ case "console-clean":
233
+ return validateConsoleClean(ctx);
234
+ }
235
+ }
236
+
237
+ // src/discovery/validators/scoped-a11y.ts
238
+ var CONTRAST_RULES = /* @__PURE__ */ new Set(["color-contrast", "color-contrast-enhanced"]);
239
+ var LABEL_RULES = /* @__PURE__ */ new Set([
240
+ "label",
241
+ "label-title-only",
242
+ "form-field-multiple-labels",
243
+ "aria-required-attr",
244
+ "button-name",
245
+ "link-name",
246
+ "input-button-name",
247
+ "select-name"
248
+ ]);
249
+ function mapImpact(impact) {
250
+ switch (impact) {
251
+ case "critical":
252
+ return "critical";
253
+ case "serious":
254
+ return "high";
255
+ case "moderate":
256
+ return "medium";
257
+ case "minor":
258
+ return "low";
259
+ default:
260
+ return "medium";
261
+ }
262
+ }
263
+ var defaultAxeRunner = async (page, opts) => {
264
+ const { AxeBuilder } = await import("@axe-core/playwright");
265
+ let builder = new AxeBuilder({ page }).withTags(["wcag2a", "wcag2aa", "wcag21aa"]);
266
+ if (opts.selector) {
267
+ builder = builder.include(opts.selector);
268
+ }
269
+ if (opts.includeRules && opts.includeRules.length > 0) {
270
+ builder = builder.withRules(opts.includeRules);
271
+ }
272
+ const results = await builder.analyze();
273
+ return { violations: results.violations };
274
+ };
275
+ function buildFinding(violation, node, opts) {
276
+ const contrastNode = node.any?.find((c) => c.id === "color-contrast");
277
+ let fixSuggestion;
278
+ if (contrastNode?.data) {
279
+ const expected = contrastNode.data["expected"];
280
+ const actual = contrastNode.data["contrastRatio"];
281
+ if (expected && actual !== void 0) {
282
+ fixSuggestion = `Expected contrast ratio of at least ${expected}:1, actual ${actual}:1. Increase foreground/background difference.`;
283
+ }
284
+ }
285
+ if (!fixSuggestion && node.failureSummary) {
286
+ fixSuggestion = node.failureSummary;
287
+ }
288
+ if (!fixSuggestion) {
289
+ fixSuggestion = `See ${violation.helpUrl} for remediation.`;
290
+ }
291
+ return {
292
+ ruleId: `a11y/${violation.id}`,
293
+ severity: mapImpact(violation.impact),
294
+ message: `${violation.help}. ${violation.description}`,
295
+ filePath: opts.url,
296
+ line: 0,
297
+ column: 0,
298
+ snippet: node.html,
299
+ url: opts.url,
300
+ viewport: opts.viewportName,
301
+ fixSuggestion
302
+ };
303
+ }
304
+ function filterViolations(violations, wanted) {
305
+ return violations.filter((v) => wanted.has(v.id));
306
+ }
307
+ async function runScopedAxe(page, opts, filter, axeRunner) {
308
+ const result = await axeRunner(page, opts);
309
+ return { violations: filterViolations(result.violations, filter), allCount: result.violations.length };
310
+ }
311
+ async function validateContrast(page, resolvedSelector, viewportName, axeRunner = defaultAxeRunner) {
312
+ const opts = {
313
+ selector: resolvedSelector,
314
+ includeRules: ["color-contrast"],
315
+ viewportName,
316
+ url: page.url()
317
+ };
318
+ const { violations } = await runScopedAxe(page, opts, CONTRAST_RULES, axeRunner);
319
+ const findings = violations.flatMap((v) => v.nodes.map((n) => buildFinding(v, n, opts)));
320
+ const passed = findings.length === 0;
321
+ return {
322
+ kind: "contrast-wcag-aa",
323
+ name: "target meets WCAG AA contrast",
324
+ passed,
325
+ ...passed ? {} : { detail: `${findings.length} contrast violation(s) in region ${resolvedSelector ?? "page"}` },
326
+ findings
327
+ };
328
+ }
329
+ async function validateScopedLabels(page, resolvedSelector, viewportName, axeRunner = defaultAxeRunner) {
330
+ const opts = {
331
+ selector: resolvedSelector,
332
+ viewportName,
333
+ url: page.url()
334
+ };
335
+ const { violations } = await runScopedAxe(page, opts, LABEL_RULES, axeRunner);
336
+ const findings = violations.flatMap((v) => v.nodes.map((n) => buildFinding(v, n, opts)));
337
+ const passed = findings.length === 0;
338
+ return {
339
+ kind: "label-present",
340
+ name: "interactive target has an accessible name",
341
+ passed,
342
+ ...passed ? {} : { detail: `${findings.length} label violation(s) in region ${resolvedSelector ?? "page"}` },
343
+ findings
344
+ };
345
+ }
346
+ async function validateFullPageAxe(page, viewportName, axeRunner = defaultAxeRunner) {
347
+ const opts = {
348
+ selector: null,
349
+ viewportName,
350
+ url: page.url()
351
+ };
352
+ const result = await axeRunner(page, opts);
353
+ const findings = result.violations.flatMap((v) => v.nodes.map((n) => buildFinding(v, n, opts)));
354
+ const passed = findings.length === 0;
355
+ return {
356
+ kind: "full-page-axe",
357
+ name: "full-page accessibility audit",
358
+ passed,
359
+ ...passed ? {} : { detail: `${findings.length} violation(s) on ${page.url()}` },
360
+ findings
361
+ };
362
+ }
363
+
364
+ // src/discovery/validators/focus-ring.ts
365
+ function parseOutlinePx(value) {
366
+ const match = /(\d+(?:\.\d+)?)px/.exec(value);
367
+ return match ? parseFloat(match[1]) : 0;
368
+ }
369
+ function hasVisibleFocusIndicator(probe) {
370
+ const widthPx = parseOutlinePx(probe.focusedOutlineWidth);
371
+ const outlineVisible = widthPx > 0 && probe.focusedOutlineStyle !== "none";
372
+ const shadowChanged = probe.focusedBoxShadow !== probe.blurredBoxShadow && probe.focusedBoxShadow !== "none";
373
+ return outlineVisible || shadowChanged;
374
+ }
375
+ async function validateFocusRing(page, resolvedSelector) {
376
+ if (!resolvedSelector) {
377
+ return { kind: "focus-ring", name: "target has a visible focus indicator", passed: true };
378
+ }
379
+ try {
380
+ const probe = await page.locator(resolvedSelector).first().evaluate((node) => {
381
+ const el = node;
382
+ const focusable = el.tagName === "BUTTON" || el.tagName === "A" || el.tagName === "INPUT" || el.tagName === "SELECT" || el.tagName === "TEXTAREA" || el.hasAttribute("tabindex");
383
+ if (!focusable) {
384
+ return {
385
+ focusable: false,
386
+ blurredOutlineWidth: "",
387
+ blurredOutlineStyle: "",
388
+ blurredBoxShadow: "",
389
+ focusedOutlineWidth: "",
390
+ focusedOutlineStyle: "",
391
+ focusedBoxShadow: ""
392
+ };
393
+ }
394
+ el.blur();
395
+ const blurred = getComputedStyle(el);
396
+ const blurredOutlineWidth = blurred.outlineWidth;
397
+ const blurredOutlineStyle = blurred.outlineStyle;
398
+ const blurredBoxShadow = blurred.boxShadow;
399
+ el.focus();
400
+ const focused = getComputedStyle(el);
401
+ return {
402
+ focusable: true,
403
+ blurredOutlineWidth,
404
+ blurredOutlineStyle,
405
+ blurredBoxShadow,
406
+ focusedOutlineWidth: focused.outlineWidth,
407
+ focusedOutlineStyle: focused.outlineStyle,
408
+ focusedBoxShadow: focused.boxShadow
409
+ };
410
+ });
411
+ if (!probe.focusable) {
412
+ return { kind: "focus-ring", name: "target has a visible focus indicator", passed: true };
413
+ }
414
+ const passed = hasVisibleFocusIndicator(probe);
415
+ return {
416
+ kind: "focus-ring",
417
+ name: "target has a visible focus indicator",
418
+ passed,
419
+ ...passed ? {} : { detail: `${resolvedSelector} has no visible focus state (outline ${probe.focusedOutlineStyle} ${probe.focusedOutlineWidth}, box-shadow ${probe.focusedBoxShadow})` }
420
+ };
421
+ } catch (err) {
422
+ return {
423
+ kind: "focus-ring",
424
+ name: "target has a visible focus indicator",
425
+ passed: false,
426
+ detail: err instanceof Error ? err.message : String(err)
427
+ };
428
+ }
429
+ }
430
+
431
+ // src/discovery/validators/layout-stability.ts
432
+ var DEFAULT_OPTIONS = {
433
+ threshold: 0.1,
434
+ maxPixelRatio: 0.05
435
+ };
436
+ async function captureRegionSnapshot(page, selector) {
437
+ if (!selector) return null;
438
+ try {
439
+ const locator = page.locator(selector).first();
440
+ const box = await locator.boundingBox();
441
+ if (!box) return null;
442
+ const padding = 16;
443
+ const clip = {
444
+ x: Math.max(0, Math.floor(box.x - padding)),
445
+ y: Math.max(0, Math.floor(box.y - padding)),
446
+ width: Math.max(1, Math.ceil(box.width + padding * 2)),
447
+ height: Math.max(1, Math.ceil(box.height + padding * 2))
448
+ };
449
+ const buffer = await page.screenshot({ clip });
450
+ return { ...clip, buffer };
451
+ } catch {
452
+ return null;
453
+ }
454
+ }
455
+ function compareSnapshots(before, after, options = {}) {
456
+ const opts = { ...DEFAULT_OPTIONS, ...options };
457
+ if (!before || !after) {
458
+ return { passed: true, ratio: 0 };
459
+ }
460
+ if (before.width !== after.width || before.height !== after.height) {
461
+ return {
462
+ passed: false,
463
+ ratio: 1,
464
+ detail: `region size changed from ${before.width}x${before.height} to ${after.width}x${after.height}`
465
+ };
466
+ }
467
+ if (before.buffer.length !== after.buffer.length) {
468
+ return {
469
+ passed: false,
470
+ ratio: 1,
471
+ detail: `buffer size changed from ${before.buffer.length} to ${after.buffer.length} bytes`
472
+ };
473
+ }
474
+ let diffBytes = 0;
475
+ for (let i = 0; i < before.buffer.length; i++) {
476
+ if (before.buffer[i] !== after.buffer[i]) diffBytes++;
477
+ }
478
+ const ratio = diffBytes / Math.max(1, before.buffer.length);
479
+ const passed = ratio <= opts.maxPixelRatio;
480
+ return {
481
+ passed,
482
+ ratio,
483
+ ...passed ? {} : { detail: `region pixels differ by ${(ratio * 100).toFixed(2)}% (max ${(opts.maxPixelRatio * 100).toFixed(2)}%)` }
484
+ };
485
+ }
486
+ async function validateLayoutStability(before, after, options = {}) {
487
+ const { passed, detail } = compareSnapshots(before, after, options);
488
+ return {
489
+ kind: "layout-stability",
490
+ name: "interaction region stayed stable",
491
+ passed,
492
+ ...detail ? { detail } : {}
493
+ };
494
+ }
495
+
496
+ // src/discovery/fill-form.ts
497
+ async function getFieldMetadata(locator) {
498
+ return await locator.evaluate((node) => {
499
+ const e = node;
500
+ return {
501
+ name: e.getAttribute("name") ?? "",
502
+ type: e.getAttribute("type") ?? e.tagName.toLowerCase(),
503
+ placeholder: e.getAttribute("placeholder") ?? "",
504
+ ariaLabel: e.getAttribute("aria-label") ?? "",
505
+ tag: e.tagName.toLowerCase(),
506
+ required: e.hasAttribute("required") || e.getAttribute("aria-required") === "true"
507
+ };
508
+ });
509
+ }
510
+ function pickValueForField(meta, persona, overrides) {
511
+ const hay = `${meta.name} ${meta.type} ${meta.placeholder} ${meta.ariaLabel}`.toLowerCase();
512
+ const val = (k) => persona.values[k];
513
+ const isCardField = /card ?number|cardnumber|ccnum|cc.?num/.test(hay);
514
+ if (meta.type === "email" || /email/.test(hay)) {
515
+ const v = overrides?.emailValue ?? val("email");
516
+ if (v !== void 0) return { value: v, kind: "email" };
517
+ }
518
+ if (meta.type === "password" || /password/.test(hay)) {
519
+ const v = val("password");
520
+ if (v) return { value: v, kind: "password" };
521
+ }
522
+ if (meta.type === "tel" || /phone|tel\b/.test(hay)) {
523
+ const v = val("phone");
524
+ if (v) return { value: v, kind: "phone" };
525
+ }
526
+ if (isCardField) {
527
+ const v = overrides?.cardNumber ?? val("card.number");
528
+ if (v) return { value: v, kind: "cardNumber" };
529
+ }
530
+ if (meta.type === "number" || /quantity|amount|count/.test(hay)) {
531
+ const v = overrides?.numericValue;
532
+ if (v !== void 0) return { value: v, kind: "numeric" };
533
+ }
534
+ if (/full ?name|your name|fullname/.test(hay) || meta.name.toLowerCase() === "name") {
535
+ const v = val("fullName");
536
+ if (v) return { value: v, kind: "fullName" };
537
+ }
538
+ if (/first ?name|firstname|given/.test(hay)) {
539
+ const v = val("firstName");
540
+ if (v) return { value: v, kind: "firstName" };
541
+ }
542
+ if (/last ?name|lastname|surname|family/.test(hay)) {
543
+ const v = val("lastName");
544
+ if (v) return { value: v, kind: "lastName" };
545
+ }
546
+ if (/address|street/.test(hay)) {
547
+ const v = val("shipping.address");
548
+ if (v) return { value: v, kind: "address" };
549
+ }
550
+ if (/city/.test(hay)) {
551
+ const v = val("shipping.city");
552
+ if (v) return { value: v, kind: "city" };
553
+ }
554
+ if (/state|region|province/.test(hay)) {
555
+ const v = val("shipping.state");
556
+ if (v) return { value: v, kind: "state" };
557
+ }
558
+ if (/zip|postal|postcode/.test(hay)) {
559
+ const v = val("shipping.zip");
560
+ if (v) return { value: v, kind: "zip" };
561
+ }
562
+ if (/country/.test(hay)) {
563
+ const v = val("shipping.country");
564
+ if (v) return { value: v, kind: "country" };
565
+ }
566
+ if (/cvv|cvc|security code/.test(hay)) {
567
+ const v = val("card.cvv");
568
+ if (v) return { value: v, kind: "cvv" };
569
+ }
570
+ if (/expiry|expir|exp.?month|exp.?year|mm.?yy/.test(hay)) {
571
+ const v = val("card.exp");
572
+ if (v) return { value: v, kind: "expiry" };
573
+ }
574
+ if (/search|query|keywords?/.test(hay)) {
575
+ const v = val("query");
576
+ if (v) return { value: v, kind: "query" };
577
+ }
578
+ if (overrides?.textValue !== void 0 && (meta.tag === "input" || meta.tag === "textarea")) {
579
+ return { value: overrides.textValue, kind: "text-override" };
580
+ }
581
+ return null;
582
+ }
583
+ function shouldSkipField(meta, overrides) {
584
+ if (!overrides) return false;
585
+ if (overrides.skipRequired && meta.required) return true;
586
+ if (overrides.skipField && overrides.skipField === meta.name) return true;
587
+ return false;
588
+ }
589
+ async function fillFormWithPersona(page, persona, overrides) {
590
+ const filled = [];
591
+ if (overrides?.emptyAll) {
592
+ return filled;
593
+ }
594
+ const inputs = page.locator('input:not([type="submit"]):not([type="hidden"]):not([type="button"]), textarea');
595
+ const count = await inputs.count();
596
+ for (let i = 0; i < count; i++) {
597
+ const locator = inputs.nth(i);
598
+ try {
599
+ const visible = await locator.isVisible();
600
+ if (!visible) continue;
601
+ const meta = await getFieldMetadata(locator);
602
+ if (shouldSkipField(meta, overrides)) continue;
603
+ const pick = pickValueForField(meta, persona, overrides);
604
+ if (!pick) continue;
605
+ await locator.fill(pick.value, { timeout: 3e3 });
606
+ filled.push({
607
+ selector: meta.name ? `[name="${meta.name}"]` : `input:nth(${i})`,
608
+ value: pick.value,
609
+ kind: pick.kind
610
+ });
611
+ } catch {
612
+ continue;
613
+ }
614
+ }
615
+ return filled;
616
+ }
617
+
618
+ // src/discovery/runner.ts
619
+ function hasValidation(specs, kind) {
620
+ return specs.find((s) => s.kind === kind);
621
+ }
622
+ async function applyStartupPreconditions(context, page, scenario) {
623
+ const preconditions = scenario.preconditions ?? [];
624
+ for (const action of preconditions) {
625
+ try {
626
+ switch (action.kind) {
627
+ case "clear-cookies":
628
+ await context.clearCookies();
629
+ break;
630
+ case "route-abort":
631
+ await page.route(action.urlPattern, (route) => route.abort());
632
+ break;
633
+ case "slow-network": {
634
+ const pattern = action.urlPattern ?? "**/*";
635
+ const delay = action.delayMs;
636
+ await page.route(pattern, async (route) => {
637
+ await new Promise((r) => setTimeout(r, delay));
638
+ await route.continue();
639
+ });
640
+ break;
641
+ }
642
+ case "set-offline":
643
+ break;
644
+ }
645
+ } catch {
646
+ }
647
+ }
648
+ }
649
+ async function maybeToggleOffline(context, scenario, stepN) {
650
+ const preconditions = scenario.preconditions ?? [];
651
+ for (const action of preconditions) {
652
+ if (action.kind !== "set-offline") continue;
653
+ if (action.beforeStep !== stepN) continue;
654
+ try {
655
+ await context.setOffline(true);
656
+ } catch {
657
+ }
658
+ }
659
+ }
660
+ function stepStatusFrom(validations) {
661
+ return validations.every((v) => v.passed) ? "pass" : "fail";
662
+ }
663
+ function failureReasonFrom(validations) {
664
+ const failed = validations.find((v) => !v.passed);
665
+ if (!failed) return void 0;
666
+ return `${failed.name}${failed.detail ? `: ${failed.detail}` : ""}`;
667
+ }
668
+ async function executeAction(page, step, scenario, context, resolvedSelector) {
669
+ const start = performance.now();
670
+ const personaName = scenario.persona;
671
+ const overrides = scenario.edgeOverrides;
672
+ try {
673
+ switch (step.action) {
674
+ case "navigate": {
675
+ const target = step.url ?? "";
676
+ const absolute = target.startsWith("http") ? target : `${context.baseUrl.replace(/\/$/, "")}${target.startsWith("/") ? "" : "/"}${target}`;
677
+ await page.goto(absolute, { waitUntil: "networkidle", timeout: context.stepTimeoutMs });
678
+ break;
679
+ }
680
+ case "click": {
681
+ if (!resolvedSelector) return { error: "target not found" };
682
+ await page.locator(resolvedSelector).first().click({ timeout: context.stepTimeoutMs });
683
+ break;
684
+ }
685
+ case "fill": {
686
+ if (!resolvedSelector) return { error: "target not found" };
687
+ const value = step.payload?.kind === "literal" ? step.payload.value : step.payload?.kind === "persona" && personaName ? PERSONAS[personaName]?.values[step.payload.value] ?? "" : "";
688
+ await page.locator(resolvedSelector).first().fill(value, { timeout: context.stepTimeoutMs });
689
+ break;
690
+ }
691
+ case "fill-form": {
692
+ const effectivePersona = step.payload?.kind === "persona" && typeof step.payload.value === "string" ? step.payload.value : personaName;
693
+ if (!effectivePersona) return { error: "no persona for fill-form" };
694
+ const persona = PERSONAS[effectivePersona];
695
+ if (!persona) return { error: `unknown persona: ${effectivePersona}` };
696
+ await fillFormWithPersona(page, persona, overrides);
697
+ break;
698
+ }
699
+ case "select": {
700
+ if (!resolvedSelector) return { error: "target not found" };
701
+ const value = step.payload?.kind === "literal" ? step.payload.value : "";
702
+ await page.locator(resolvedSelector).first().selectOption(value, { timeout: context.stepTimeoutMs });
703
+ break;
704
+ }
705
+ case "wait": {
706
+ await page.waitForTimeout(500);
707
+ break;
708
+ }
709
+ case "assert-url":
710
+ case "assert-text":
711
+ case "custom":
712
+ break;
713
+ }
714
+ } catch (err) {
715
+ return { error: err instanceof Error ? err.message : String(err) };
716
+ }
717
+ return { responseTimeMs: performance.now() - start };
718
+ }
719
+ async function runStep(page, step, scenario, context, hookCtrl, axeRunner, viewportName) {
720
+ const started = performance.now();
721
+ const urlBefore = page.url();
722
+ hookCtrl.reset();
723
+ let resolvedSelector = null;
724
+ if (step.target) {
725
+ const resolved = await resolveTarget(page, step.target);
726
+ resolvedSelector = resolved?.selector ?? null;
727
+ }
728
+ if (!resolvedSelector && step.target && !step.optional && step.action !== "navigate") {
729
+ const durationMs = performance.now() - started;
730
+ return {
731
+ n: step.n,
732
+ intent: step.intent,
733
+ action: step.action,
734
+ urlBefore,
735
+ urlAfter: urlBefore,
736
+ durationMs,
737
+ observation: { consoleErrors: 0, networkFailures: 0 },
738
+ validations: [
739
+ {
740
+ kind: "expect",
741
+ name: "target resolved",
742
+ passed: false,
743
+ detail: `no selector matched: ${step.target.selectorHints.join(", ")}`
744
+ }
745
+ ],
746
+ status: "fail",
747
+ failureReason: "target not found"
748
+ };
749
+ }
750
+ let layoutBefore = null;
751
+ if (hasValidation(scenario.validations.perStep, "layout-stability") && resolvedSelector) {
752
+ layoutBefore = await captureRegionSnapshot(page, resolvedSelector);
753
+ }
754
+ const actionResult = await executeAction(page, step, scenario, context, resolvedSelector);
755
+ await page.waitForTimeout(200);
756
+ const urlAfter = page.url();
757
+ const hookFindings = hookCtrl.collect();
758
+ const consoleErrors = hookFindings.filter((f) => f.ruleId === "e2e/console-error").length;
759
+ const networkFailures = hookFindings.filter((f) => f.ruleId === "e2e/network-failure").length;
760
+ const validations = [];
761
+ const ctx = { page, step, hookFindings, responseTimeMs: actionResult.responseTimeMs };
762
+ if (hasValidation(scenario.validations.perStep, "console-clean")) {
763
+ validations.push(await validateConsoleClean(ctx));
764
+ }
765
+ if (hasValidation(scenario.validations.perStep, "network-clean")) {
766
+ validations.push(await validateNetworkClean(ctx));
767
+ }
768
+ const respSpec = hasValidation(scenario.validations.perStep, "response-time");
769
+ if (respSpec?.budgetMs) {
770
+ validations.push(await validateResponseTime(ctx, respSpec.budgetMs));
771
+ }
772
+ if (hasValidation(scenario.validations.perStep, "visible-target")) {
773
+ validations.push(await validateVisibleTarget(ctx, resolvedSelector));
774
+ }
775
+ if (hasValidation(scenario.validations.perStep, "label-present")) {
776
+ validations.push(await validateLabelPresent(ctx, resolvedSelector));
777
+ validations.push(await validateScopedLabels(page, resolvedSelector, viewportName, axeRunner));
778
+ }
779
+ if (hasValidation(scenario.validations.perStep, "contrast-wcag-aa")) {
780
+ validations.push(await validateContrast(page, resolvedSelector, viewportName, axeRunner));
781
+ }
782
+ if (hasValidation(scenario.validations.perStep, "focus-ring")) {
783
+ validations.push(await validateFocusRing(page, resolvedSelector));
784
+ }
785
+ if (hasValidation(scenario.validations.perStep, "layout-stability")) {
786
+ const layoutAfter = resolvedSelector ? await captureRegionSnapshot(page, resolvedSelector) : null;
787
+ validations.push(await validateLayoutStability(layoutBefore, layoutAfter));
788
+ }
789
+ if (step.expect) {
790
+ for (const expectation of step.expect) {
791
+ validations.push(await evaluateExpectation(ctx, expectation));
792
+ }
793
+ }
794
+ if (actionResult.error) {
795
+ validations.push({
796
+ kind: "expect",
797
+ name: "action succeeded",
798
+ passed: false,
799
+ detail: actionResult.error
800
+ });
801
+ }
802
+ let screenshotPath;
803
+ const status = stepStatusFrom(validations);
804
+ if (status === "fail") {
805
+ const safeName = `${scenario.id}-step-${step.n}`;
806
+ screenshotPath = await hookCtrl.screenshot(page, safeName, context.reportDir);
807
+ }
808
+ return {
809
+ n: step.n,
810
+ intent: step.intent,
811
+ action: step.action,
812
+ ...resolvedSelector ? { resolvedSelector } : {},
813
+ urlBefore,
814
+ urlAfter,
815
+ durationMs: performance.now() - started,
816
+ observation: {
817
+ consoleErrors,
818
+ networkFailures,
819
+ ...actionResult.responseTimeMs !== void 0 ? { responseTimeMs: actionResult.responseTimeMs } : {},
820
+ ...screenshotPath ? { screenshotPath } : {}
821
+ },
822
+ validations,
823
+ status,
824
+ ...status === "fail" ? { failureReason: failureReasonFrom(validations) } : {}
825
+ };
826
+ }
827
+ async function runScenario(browser, scenario, context, setupHooks, axeRunner, seed) {
828
+ const start = performance.now();
829
+ const steps = [];
830
+ const findings = [];
831
+ let lastPage;
832
+ let lastViewportName = "";
833
+ let browserContext;
834
+ try {
835
+ browserContext = await browser.newContext({
836
+ viewport: { width: context.viewport.width, height: context.viewport.height }
837
+ });
838
+ const page = await browserContext.newPage();
839
+ const viewportName = `${context.viewport.width}x${context.viewport.height}`;
840
+ const hookCtrl = await setupHooks(page, viewportName);
841
+ lastPage = page;
842
+ lastViewportName = viewportName;
843
+ await applyStartupPreconditions(browserContext, page, scenario);
844
+ try {
845
+ await page.goto(context.baseUrl, {
846
+ waitUntil: "networkidle",
847
+ timeout: context.stepTimeoutMs
848
+ });
849
+ } catch {
850
+ return {
851
+ scenario,
852
+ status: "skip",
853
+ steps: [],
854
+ findings: [],
855
+ durationMs: performance.now() - start,
856
+ seed,
857
+ skippedReason: `could not reach baseUrl ${context.baseUrl}`
858
+ };
859
+ }
860
+ const scenarioDeadline = start + (scenario.expectedDurationMs ?? context.scenarioTimeoutMs);
861
+ for (const step of scenario.steps) {
862
+ if (performance.now() > scenarioDeadline) {
863
+ steps.push({
864
+ n: step.n,
865
+ intent: step.intent,
866
+ action: step.action,
867
+ urlBefore: page.url(),
868
+ urlAfter: page.url(),
869
+ durationMs: 0,
870
+ observation: { consoleErrors: 0, networkFailures: 0 },
871
+ validations: [{ kind: "expect", name: "scenario within budget", passed: false, detail: "scenario timeout" }],
872
+ status: "fail",
873
+ failureReason: "scenario timeout"
874
+ });
875
+ break;
876
+ }
877
+ await maybeToggleOffline(browserContext, scenario, step.n);
878
+ const record = await runStep(page, step, scenario, context, hookCtrl, axeRunner, viewportName);
879
+ steps.push(record);
880
+ findings.push(...hookCtrl.collect());
881
+ for (const v of record.validations) {
882
+ if (v.findings) findings.push(...v.findings);
883
+ }
884
+ if (record.status === "fail") break;
885
+ }
886
+ } finally {
887
+ if (browserContext) {
888
+ try {
889
+ await browserContext.close();
890
+ } catch {
891
+ }
892
+ }
893
+ }
894
+ const allStepsPassed = steps.length === scenario.steps.length && steps.every((s) => s.status === "pass");
895
+ const perScenarioOutcomes = [];
896
+ if (allStepsPassed && lastPage) {
897
+ for (const spec of scenario.validations.perScenario) {
898
+ if (spec.kind === "full-page-axe") {
899
+ try {
900
+ const outcome = await validateFullPageAxe(lastPage, lastViewportName, axeRunner);
901
+ perScenarioOutcomes.push(outcome);
902
+ if (outcome.findings) findings.push(...outcome.findings);
903
+ } catch {
904
+ }
905
+ }
906
+ }
907
+ }
908
+ const perScenarioPassed = perScenarioOutcomes.every((o) => o.passed);
909
+ const status = allStepsPassed && perScenarioPassed ? "pass" : "fail";
910
+ return {
911
+ scenario,
912
+ status,
913
+ steps,
914
+ findings,
915
+ durationMs: performance.now() - start,
916
+ seed
917
+ };
918
+ }
919
+ function seedFromString(s) {
920
+ let h = 2166136261;
921
+ for (let i = 0; i < s.length; i++) {
922
+ h ^= s.charCodeAt(i);
923
+ h = Math.imul(h, 16777619);
924
+ }
925
+ return h >>> 0;
926
+ }
927
+ async function runScenarios(scenarios, guesses, context, config, deps) {
928
+ const start = performance.now();
929
+ const runAt = (/* @__PURE__ */ new Date()).toISOString();
930
+ const launchBrowser = deps?.launchBrowser ?? (async () => {
931
+ const { chromium } = await import("playwright");
932
+ return chromium.launch({ headless: context.headless });
933
+ });
934
+ const defaultSetupHooks = async (page, viewportName) => {
935
+ const {
936
+ PageHookPipeline,
937
+ ConsoleErrorHook,
938
+ NetworkFailureHook,
939
+ ScreenshotHook
940
+ } = await import("./page-hooks-DOZWXF7Z.js");
941
+ const pipeline = new PageHookPipeline();
942
+ pipeline.register(new ConsoleErrorHook());
943
+ pipeline.register(new NetworkFailureHook());
944
+ pipeline.register(new ScreenshotHook());
945
+ pipeline.setupAll(page, viewportName);
946
+ return {
947
+ collect: () => pipeline.collectAll(),
948
+ reset: () => pipeline.resetAll(),
949
+ screenshot: (p, name, dir) => pipeline.captureScreenshot(p, name, dir)
950
+ };
951
+ };
952
+ const setupHooks = deps?.setupHooks ?? defaultSetupHooks;
953
+ const axeRunner = deps?.axeRunner ?? defaultAxeRunner;
954
+ const baseSeed = context.seed ?? seedFromString(runAt);
955
+ const results = [];
956
+ if (scenarios.length === 0) {
957
+ void config;
958
+ return {
959
+ appTypeGuesses: guesses,
960
+ scenarios: [],
961
+ stats: { total: 0, passed: 0, failed: 0, skipped: 0, quarantined: 0, durationMs: 0 },
962
+ runAt
963
+ };
964
+ }
965
+ const browser = await launchBrowser();
966
+ try {
967
+ for (const scenario of scenarios) {
968
+ const seed = seedFromString(`${baseSeed}::${scenario.id}`);
969
+ const result = await runScenario(browser, scenario, context, setupHooks, axeRunner, seed);
970
+ results.push(result);
971
+ }
972
+ } finally {
973
+ try {
974
+ await browser.close();
975
+ } catch {
976
+ }
977
+ }
978
+ const stats = {
979
+ total: results.length,
980
+ passed: results.filter((r) => r.status === "pass").length,
981
+ failed: results.filter((r) => r.status === "fail").length,
982
+ skipped: results.filter((r) => r.status === "skip").length,
983
+ quarantined: results.filter((r) => r.quarantined === true).length,
984
+ durationMs: performance.now() - start
985
+ };
986
+ return {
987
+ appTypeGuesses: guesses,
988
+ scenarios: results,
989
+ stats,
990
+ runAt
991
+ };
992
+ }
993
+ export {
994
+ runScenarios
995
+ };
996
+ //# sourceMappingURL=runner-OYTN2NFD.js.map