sniff-qa 0.5.0 → 0.5.2

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 (87) hide show
  1. package/.claude-plugin/plugin.json +13 -0
  2. package/CHANGELOG.md +95 -0
  3. package/NOTICE +14 -0
  4. package/README.md +92 -32
  5. package/SECURITY.md +33 -0
  6. package/dist/{accessibility-UNJB57T6.js → accessibility-JXRMWF5Y.js} +10 -1
  7. package/dist/accessibility-JXRMWF5Y.js.map +1 -0
  8. package/dist/{anthropic-api-MRDZ7BJA.js → anthropic-api-ZR3UEB3Z.js} +5 -3
  9. package/dist/anthropic-api-ZR3UEB3Z.js.map +1 -0
  10. package/dist/{chunk-623BAIU2.js → chunk-CZKMOAXU.js} +10 -3
  11. package/dist/chunk-CZKMOAXU.js.map +1 -0
  12. package/dist/{chunk-CBDOJUXB.js → chunk-MYWWSM3V.js} +14 -6
  13. package/dist/chunk-MYWWSM3V.js.map +1 -0
  14. package/dist/{ci-2MVD2ISE.js → ci-ISCWZJD3.js} +3 -3
  15. package/dist/{ci-2MVD2ISE.js.map → ci-ISCWZJD3.js.map} +1 -1
  16. package/dist/{claude-code-F722EIIC.js → claude-code-ZFTBQXY4.js} +7 -3
  17. package/dist/claude-code-ZFTBQXY4.js.map +1 -0
  18. package/dist/cli/index.js +19 -14
  19. package/dist/cli/index.js.map +1 -1
  20. package/dist/{discover-JRU5E4FR.js → discover-ENPRVN5A.js} +3 -3
  21. package/dist/ensure-browsers-AYKMLUHV.js +86 -0
  22. package/dist/ensure-browsers-AYKMLUHV.js.map +1 -0
  23. package/dist/generator-HIFV67NI.js +7 -0
  24. package/dist/index.d.ts +43 -2
  25. package/dist/index.js +1 -1
  26. package/dist/{loader-QII5CZSX.js → loader-UG2XADG7.js} +25 -4
  27. package/dist/loader-UG2XADG7.js.map +1 -0
  28. package/dist/mcp/server.js +64 -48
  29. package/dist/mcp/server.js.map +1 -1
  30. package/dist/{model-2DTSAX7T.js → model-X5J2JR5U.js} +1 -1
  31. package/dist/{page-hooks-DOZWXF7Z.js → page-hooks-6RALVZB5.js} +2 -2
  32. package/dist/{performance-FBUGBRB3.js → performance-7HWKY5O2.js} +6 -3
  33. package/dist/performance-7HWKY5O2.js.map +1 -0
  34. package/dist/provider-BCKFVPTN.js +183 -0
  35. package/dist/provider-BCKFVPTN.js.map +1 -0
  36. package/dist/quality-run-6SXCN5CD.js +79 -0
  37. package/dist/quality-run-6SXCN5CD.js.map +1 -0
  38. package/dist/{registry-NB5CZB6W.js → registry-5XCXUAYJ.js} +14 -2
  39. package/dist/registry-5XCXUAYJ.js.map +1 -0
  40. package/dist/{report-IKRVVIW4.js → report-OAHSB56I.js} +2 -2
  41. package/dist/{runner-OYTN2NFD.js → runner-AXZXNWYH.js} +3 -3
  42. package/dist/runner-AXZXNWYH.js.map +1 -0
  43. package/dist/{runner-Z4I2YVVM.js → runner-HFJDHS2I.js} +3 -3
  44. package/dist/runner-HFJDHS2I.js.map +1 -0
  45. package/dist/runner-II7BPB63.js +201 -0
  46. package/dist/runner-II7BPB63.js.map +1 -0
  47. package/dist/{source-4DOO224X.js → source-5LS2B7TN.js} +38 -22
  48. package/dist/source-5LS2B7TN.js.map +1 -0
  49. package/dist/{unified-JCUBP6UO.js → unified-SKXQQX3Y.js} +25 -74
  50. package/dist/unified-SKXQQX3Y.js.map +1 -0
  51. package/dist/{update-baselines-MDTCFO2U.js → update-baselines-UCAW3SDN.js} +2 -2
  52. package/dist/{visual-ZSQPDE7A.js → visual-EUZG2STF.js} +8 -4
  53. package/dist/visual-EUZG2STF.js.map +1 -0
  54. package/dist/{workflow-template-3KFPCVIC.js → workflow-template-6DADGPHA.js} +5 -3
  55. package/dist/workflow-template-6DADGPHA.js.map +1 -0
  56. package/package.json +21 -7
  57. package/skills/sniff/SKILL.md +47 -0
  58. package/skills/sniff-fix/SKILL.md +44 -0
  59. package/skills/sniff-report/SKILL.md +40 -0
  60. package/smithery.yaml +10 -0
  61. package/dist/accessibility-UNJB57T6.js.map +0 -1
  62. package/dist/anthropic-api-MRDZ7BJA.js.map +0 -1
  63. package/dist/chunk-623BAIU2.js.map +0 -1
  64. package/dist/chunk-CBDOJUXB.js.map +0 -1
  65. package/dist/claude-code-F722EIIC.js.map +0 -1
  66. package/dist/ensure-browsers-ACHCEQCT.js +0 -60
  67. package/dist/ensure-browsers-ACHCEQCT.js.map +0 -1
  68. package/dist/generator-OZY3HMJW.js +0 -7
  69. package/dist/loader-QII5CZSX.js.map +0 -1
  70. package/dist/performance-FBUGBRB3.js.map +0 -1
  71. package/dist/provider-7IHXYR6V.js +0 -13
  72. package/dist/provider-7IHXYR6V.js.map +0 -1
  73. package/dist/registry-NB5CZB6W.js.map +0 -1
  74. package/dist/runner-MS2SNTMR.js +0 -153
  75. package/dist/runner-MS2SNTMR.js.map +0 -1
  76. package/dist/runner-OYTN2NFD.js.map +0 -1
  77. package/dist/runner-Z4I2YVVM.js.map +0 -1
  78. package/dist/source-4DOO224X.js.map +0 -1
  79. package/dist/unified-JCUBP6UO.js.map +0 -1
  80. package/dist/visual-ZSQPDE7A.js.map +0 -1
  81. package/dist/workflow-template-3KFPCVIC.js.map +0 -1
  82. /package/dist/{discover-JRU5E4FR.js.map → discover-ENPRVN5A.js.map} +0 -0
  83. /package/dist/{generator-OZY3HMJW.js.map → generator-HIFV67NI.js.map} +0 -0
  84. /package/dist/{model-2DTSAX7T.js.map → model-X5J2JR5U.js.map} +0 -0
  85. /package/dist/{page-hooks-DOZWXF7Z.js.map → page-hooks-6RALVZB5.js.map} +0 -0
  86. /package/dist/{report-IKRVVIW4.js.map → report-OAHSB56I.js.map} +0 -0
  87. /package/dist/{update-baselines-MDTCFO2U.js.map → update-baselines-UCAW3SDN.js.map} +0 -0
@@ -0,0 +1,13 @@
1
+ {
2
+ "name": "sniff",
3
+ "version": "0.5.2",
4
+ "description": "Local QA automation via sniff-qa: source scans, browser audits, discovery, and reports with no API key required by default",
5
+ "author": {
6
+ "name": "Adam Boudj",
7
+ "url": "https://github.com/Aboudjem/sniff"
8
+ },
9
+ "homepage": "https://github.com/Aboudjem/sniff",
10
+ "repository": "https://github.com/Aboudjem/sniff",
11
+ "license": "Apache-2.0",
12
+ "keywords": ["testing", "qa", "playwright", "accessibility", "mcp", "sniff-qa"]
13
+ }
package/CHANGELOG.md ADDED
@@ -0,0 +1,95 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ## [0.5.2] - 2026-05-06
11
+
12
+ ### Fixed
13
+
14
+ - Added a `sniff-qa` npm binary alias while keeping the installed `sniff` binary, so `npx sniff-qa` resolves correctly from the npm registry.
15
+
16
+ ## [0.5.1] - 2026-05-06
17
+
18
+ ### Added
19
+
20
+ - Agent-agnostic AI provider selection with deterministic `ai.provider: "none"` as the default and optional `codex-cli`, `claude-code`, `anthropic-api`, `openai-api`, `gemini-cli`, and `ollama` providers.
21
+ - Multi-browser config via `browser.projects` with Chromium as the default and Firefox/WebKit opt-in.
22
+ - `sniff_install` MCP support for requested Playwright browser projects.
23
+ - Test typechecking through `tsconfig.test.json`.
24
+
25
+ ### Changed
26
+
27
+ - Browser runtime console/network hook findings now flow into normal results, reports, persistence, MCP responses, and exit codes.
28
+ - MCP `sniff({ mode: "run" })` now uses the shared source + browser path instead of a browser-only root route.
29
+ - Browser audits use the current repo analysis routes before falling back to `/`, avoiding stale `.sniff/last-results.json` route reuse.
30
+ - Scanner crashes now produce high-severity `scanner-error/*` findings instead of silent metadata-only errors.
31
+ - Dead-link scanning now ignores code files by default and requires `deadLinks.scanCode: true` for JSX/TSX/JS/TS extraction.
32
+ - `--explore` is now opt-in so default CLI scans remain deterministic and local.
33
+ - README assets now use absolute GitHub URLs so npm rendering works.
34
+
35
+ ### Fixed
36
+
37
+ - `BrowserRunner` now receives the target `rootDir`, so reports and visual baselines are written for the scanned project instead of the caller process.
38
+ - Accessibility, visual, performance, and e2e scanners now honor `config.scanners` and their enabled flags consistently.
39
+ - CI workflow generation now uploads `.sniff/reports/` and uses `npx sniff-qa --ci --format html,json,junit`.
40
+
41
+ ## [0.4.0] - 2026-04-17
42
+
43
+ ### Added
44
+
45
+ - **Autonomous E2E discovery** (`sniff discover`): scans source (Prisma, Drizzle, TypeORM, Zod, GraphQL, OpenAPI, TS types), classifies the app into one of 10 types, generates happy-path journeys with personas, enumerates edge variants (invalid email, XSS, payment declined, empty cart, offline, slow network, and more), drives them through Playwright, and writes HTML/JSON/JUnit reports
46
+ - **Scenario persistence** at `sniff-scenarios/_generated/<app-type>/<journey>.<variant>.scenario.md` with JSON frontmatter, hash-tracked to protect hand-edits; `custom/` directory for user-authored scenarios
47
+ - **Regenerate semantics**: `--regenerate`, `--regenerate-only`, `--force-regenerate` flags; non-interactive runs default to keeping hand-edits
48
+ - **Realism profiles** (`robot`, `careful-user`, `casual-user`, `frustrated-user`, `power-user`) with seeded RNG and `--seed <n>` for replay
49
+ - **Real-world variant caps** (3 per scenario, 40 per run, both configurable) surface the most informative edge variants first
50
+ - **Production-URL safety banner**: 5-second non-blocking countdown before running against a non-localhost URL
51
+ - **Flakiness quarantine** for discovery scenarios using the existing quarantine engine
52
+ - **LLM polish via Claude Code CLI**: optional tie-break for close-call app-type classifications, cached under `.sniff/discover/cache/`; falls back to deterministic classification if the CLI is unavailable or `--no-llm` is set
53
+ - **`sniff_discover` MCP tool**: returns compact summary (top app type, stats, failures) so AI editors can drive discovery
54
+ - **Doctor awareness** of `sniff-scenarios/` baselines
55
+
56
+ ### Changed
57
+
58
+ - `sniff doctor` now also reports on discovery baselines
59
+
60
+ ## [0.2.0] - 2026-04-16
61
+
62
+ ### Added
63
+
64
+ - **Dead link checker** validates internal file references, external URLs (HTTP HEAD with retry/timeout), and anchor links across .md, .html, .jsx, .tsx, .vue, .svelte, and .astro files
65
+ - **API endpoint discovery** auto-detects routes from Express, Fastify, Hono, Next.js (App + Pages Router), SvelteKit, tRPC, and GraphQL schema definitions
66
+ - **API endpoint issue detection** flags missing error handling, input validation, auth middleware, and hardcoded secrets in route handlers
67
+ - **Cross-reference engine** correlates source code findings with browser runtime evidence (5 strategies: broken imports to 404s, console.log to runtime output, hardcoded URLs to network requests, a11y issues to axe violations, placeholders to visible text)
68
+ - **Corroborated findings** with bumped severity and confidence tags when issues are confirmed in both source and browser layers
69
+ - **Pipeline SVG diagrams** (light/dark) showing the full 8-check pipeline
70
+ - **Architecture SVG diagrams** (light/dark) showing all system components
71
+ - **Report example SVG** (light/dark) showing styled terminal output
72
+ - **Dead link config** section in `sniff.config.ts` (checkExternal, timeout, retries, ignorePatterns, maxConcurrent)
73
+ - **API endpoints config** section in `sniff.config.ts` (checkErrorHandling, checkValidation, checkAuth, checkSecrets, frameworks filter)
74
+
75
+ ### Changed
76
+
77
+ - README updated to document all 8 checks with detailed examples, source rule reference table, cross-reference examples, and expanded config reference
78
+ - "Five checks" updated to "Eight checks" across all documentation
79
+ - Comparison table expanded with dead link checking, API endpoint discovery, and cross-reference engine rows
80
+
81
+ ## [0.1.0] - 2026-04-16
82
+
83
+ ### Added
84
+
85
+ - **Source scanner** with AST and regex rules for debugger statements, placeholder text, hardcoded URLs, broken imports, TODO/FIXME tags
86
+ - **Accessibility scanner** powered by axe-core for WCAG 2.x violations with fix guidance
87
+ - **Visual regression scanner** using pixelmatch for pixel level diffing with baseline tracking
88
+ - **Performance scanner** using Lighthouse for LCP, FCP, TTI budget enforcement
89
+ - **AI explorer** that roams your app, fills forms with adversarial inputs (XSS, SQL injection, Unicode), and reports crashes
90
+ - **Three modes**: quick scan (source only), full audit (all 5 checks), CI mode (deterministic)
91
+ - **MCP server** for native AI editor integration (Claude Code, Cursor, Windsurf, VS Code + Cline)
92
+ - **Flakiness quarantine** for stable CI pipelines
93
+ - **HTML, JSON, and JUnit report** generation
94
+ - **Zero config** operation with framework auto detection
95
+ - **CLI** with `npx sniff-qa` entry point
package/NOTICE ADDED
@@ -0,0 +1,14 @@
1
+ Sniff
2
+ Copyright 2025 Adam Boudj <adam@integralayer.com>
3
+
4
+ This product includes software developed by Adam Boudj.
5
+
6
+ If you use Sniff in your project, a mention or attribution is appreciated:
7
+ - In your README, docs, or project credits
8
+ - "QA powered by Sniff (https://github.com/adamboudj/sniff)"
9
+
10
+ Third-party licenses:
11
+ - Playwright (Apache-2.0) - https://playwright.dev
12
+ - axe-core (MPL-2.0) - https://www.deque.com/axe/
13
+ - Lighthouse (Apache-2.0) - https://developer.chrome.com/docs/lighthouse
14
+ - pixelmatch (ISC) - https://github.com/mapbox/pixelmatch
package/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  <picture>
2
- <source media="(prefers-color-scheme: dark)" srcset=".github/assets/logo-dark.svg">
3
- <source media="(prefers-color-scheme: light)" srcset=".github/assets/logo-light.svg">
4
- <img alt="Sniff" src=".github/assets/logo-light.svg" width="100%">
2
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/Aboudjem/sniff/main/.github/assets/logo-dark.svg">
3
+ <source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/Aboudjem/sniff/main/.github/assets/logo-light.svg">
4
+ <img alt="Sniff" src="https://raw.githubusercontent.com/Aboudjem/sniff/main/.github/assets/logo-light.svg" width="100%">
5
5
  </picture>
6
6
 
7
7
  <p align="center">
@@ -12,7 +12,43 @@
12
12
  <a href="https://github.com/Aboudjem/sniff/stargazers"><img src="https://img.shields.io/github/stars/Aboudjem/sniff?style=flat-square&color=ef4444" alt="Stars"></a>
13
13
  </p>
14
14
 
15
- <p align="center">Scan your source code, your live site, or both. Finds bugs before your users do.</p>
15
+ <p align="center"><b>Scan your source code, your live site, or both. Finds bugs before your users do.</b></p>
16
+
17
+ <p align="center">
18
+ <a href="#get-started">Get started</a> ·
19
+ <a href="#what-it-finds">What it finds</a> ·
20
+ <a href="#commands">Commands</a> ·
21
+ <a href="#works-with-any-stack">Stacks</a> ·
22
+ <a href="docs/VIDEO-PLAN.md">Demo videos</a>
23
+ </p>
24
+
25
+ <picture>
26
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/Aboudjem/sniff/main/.github/assets/sniff-diagram.svg">
27
+ <img alt="Sniff flow: source -> radar scanner -> findings" src="https://raw.githubusercontent.com/Aboudjem/sniff/main/.github/assets/sniff-diagram.svg" width="100%">
28
+ </picture>
29
+
30
+ ---
31
+
32
+ ## The 30-second pitch
33
+
34
+ > You ship a feature. A user finds the bug before you do. Sniff is the opposite of that.
35
+
36
+ Sniff is a tiny CLI that reads your source, opens your app in a headless browser, and hunts down bugs across **eight dimensions** — functional, visual, accessibility, performance, dead links, API endpoints, broken imports, and optional AI-assisted exploration. No API key required. No manual Playwright setup. No config.
37
+
38
+ ```bash
39
+ npx sniff-qa
40
+ ```
41
+
42
+ That's the whole setup. The rest of this README is detail.
43
+
44
+ ### Why developers love it
45
+
46
+ - **One command.** `npx sniff-qa` auto-detects your framework, your dev server, your test scenarios. If `npm run dev` is running, sniff finds it.
47
+ - **Zero API keys by default.** Deterministic local QA is the default. Codex, Claude, Gemini, Ollama, Anthropic, and OpenAI providers are optional enhancements.
48
+ - **Eight checks, every time.** Accessibility + visual regression + performance + dead links + API contracts + source scanning + broken imports + browser runtime hooks — out of the box.
49
+ - **Talks to your editor.** Ships as an MCP server. Just say *"scan this project"* in Claude / Cursor / Copilot / Continue / Windsurf / Codex / Gemini.
50
+ - **CI-ready.** `sniff --ci` emits JUnit, tracks flakes, and fails on severity thresholds you set. `sniff ci` generates the GitHub Actions workflow.
51
+ - **Actually explains the fix.** Every finding cites the rule, the file, the line — and `/sniff-fix` generates the patch.
16
52
 
17
53
  ---
18
54
 
@@ -34,7 +70,7 @@ npx sniff-qa --url http://localhost:3000 # specific local URL
34
70
  npx sniff-qa --url https://myapp.com # production URL
35
71
  ```
36
72
 
37
- > **No API keys. No Playwright install. No config files.** Everything works out of the box. Browser checks auto-install Chromium on first run.
73
+ > **No API keys. No manual Playwright install. No config files.** Everything works out of the box. Browser checks auto-install the configured Playwright browser projects on first CLI run.
38
74
 
39
75
  ### Use from your AI editor
40
76
 
@@ -123,7 +159,7 @@ clawhub install sniff-qa
123
159
 
124
160
  Then ask: *"Scan this project for issues"* or *"Check accessibility on localhost:3000"* or *"Discover and run E2E tests"*
125
161
 
126
- **MCP tools:** `sniff({ mode: "scan" | "run" | "discover" | "report" })` — unified entry point. Plus `sniff_install` when Playwright's Chromium is missing. The legacy per-mode tools (`sniff_scan`, `sniff_run`, `sniff_discover`, `sniff_report`) remain available but are deprecated in v0.5 and will be removed in v0.7.
162
+ **MCP tools:** `sniff({ mode: "scan" | "run" | "discover" | "report" })` — unified entry point. Plus `sniff_install` when Playwright browser binaries are missing. MCP returns a structured `needsSetup` payload instead of doing a long install inside stdio; call `sniff_install` or run the shown `npx playwright install ...` command, then retry. The legacy per-mode tools (`sniff_scan`, `sniff_run`, `sniff_discover`, `sniff_report`) remain available but are deprecated in v0.5 and will be removed in v0.7.
127
163
 
128
164
  ### Install as a dev dependency
129
165
 
@@ -141,7 +177,7 @@ npm install -D sniff-qa
141
177
 
142
178
  That's all you need. Sniff auto-detects your dev server when it's running.
143
179
 
144
- Requires Node.js 22+. Playwright installs automatically on first browser scan.
180
+ Requires Node.js 22+. Playwright installs automatically on first CLI browser scan; MCP asks you to run `sniff_install` when setup is missing.
145
181
 
146
182
  ---
147
183
 
@@ -152,6 +188,7 @@ npx sniff-qa # scan source + auto-detect
152
188
  npx sniff-qa --url https://myapp.com # scan source + specific URL
153
189
  npx sniff-qa ./path/to/project # scan a specific directory
154
190
  npx sniff-qa --ci # CI mode (JUnit output, no AI explorer)
191
+ npx sniff-qa --url http://localhost:3000 --explore # opt-in AI exploration
155
192
  npx sniff-qa --verbose # show classifier top 3 + matched signals
156
193
  npx sniff-qa discover --dry-run # preview generated scenarios, no browser
157
194
  npx sniff-qa discover --force-app-type saas # skip classification, treat as SaaS
@@ -164,9 +201,9 @@ Sniff auto-detects your dev server by reading `package.json` scripts plus `vite.
164
201
  ## What it finds
165
202
 
166
203
  <picture>
167
- <source media="(prefers-color-scheme: dark)" srcset=".github/assets/features-dark.svg">
168
- <source media="(prefers-color-scheme: light)" srcset=".github/assets/features-light.svg">
169
- <img alt="Sniff checks: source bugs, dead links, API endpoints, broken imports, accessibility, visual regression, performance, AI explorer" src=".github/assets/features-light.svg" width="100%">
204
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/Aboudjem/sniff/main/.github/assets/features-dark.svg">
205
+ <source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/Aboudjem/sniff/main/.github/assets/features-light.svg">
206
+ <img alt="Sniff checks: source bugs, dead links, API endpoints, broken imports, accessibility, visual regression, performance, optional AI explorer" src="https://raw.githubusercontent.com/Aboudjem/sniff/main/.github/assets/features-light.svg" width="100%">
170
207
  </picture>
171
208
 
172
209
  **Source checks** run on every scan. **Browser checks** run automatically when sniff detects a running dev server, or when you pass `--url`.
@@ -176,9 +213,9 @@ Sniff auto-detects your dev server by reading `package.json` scripts plus `vite.
176
213
  ## Example output
177
214
 
178
215
  <picture>
179
- <source media="(prefers-color-scheme: dark)" srcset=".github/assets/report-dark.svg">
180
- <source media="(prefers-color-scheme: light)" srcset=".github/assets/report-light.svg">
181
- <img alt="Sniff terminal output" src=".github/assets/report-light.svg" width="100%">
216
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/Aboudjem/sniff/main/.github/assets/report-dark.svg">
217
+ <source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/Aboudjem/sniff/main/.github/assets/report-light.svg">
218
+ <img alt="Sniff terminal output" src="https://raw.githubusercontent.com/Aboudjem/sniff/main/.github/assets/report-light.svg" width="100%">
182
219
  </picture>
183
220
 
184
221
  ---
@@ -220,7 +257,8 @@ sniff --version Show version
220
257
  |:-----|:-------------|
221
258
  | `--url <url>` | Enable browser checks (accessibility, visual, performance, AI) |
222
259
  | `--ci` | CI mode: skip AI explorer, add JUnit output, track flaky tests |
223
- | `--no-explore` | Browser checks without AI explorer |
260
+ | `--explore` | Opt into AI-assisted exploration after browser checks |
261
+ | `--no-explore` | Compatibility flag; exploration is off by default |
224
262
  | `--no-browser` | Source only even if `--url` is set |
225
263
  | `--max-steps <n>` | Limit AI explorer steps (default: 50) |
226
264
  | `--no-headless` | Show the browser window |
@@ -276,7 +314,10 @@ import { defineConfig } from 'sniff-qa';
276
314
 
277
315
  export default defineConfig({
278
316
  // Save your URL so you can just run `sniff`
279
- browser: { baseUrl: 'http://localhost:3000' },
317
+ browser: {
318
+ baseUrl: 'http://localhost:3000',
319
+ projects: ['chromium'], // also supports 'firefox' and 'webkit'
320
+ },
280
321
 
281
322
  // Viewports to test
282
323
  viewports: [
@@ -284,17 +325,26 @@ export default defineConfig({
284
325
  { name: 'desktop', width: 1280, height: 720 },
285
326
  ],
286
327
 
287
- // Performance budgets (ms)
288
- performance: { budgets: { lcp: 2500, fcp: 1800, tti: 3800 } },
289
-
290
- // Visual regression threshold (0-1)
291
- visual: { threshold: 0.1 },
328
+ // Toggle scanner groups
329
+ scanners: ['source', 'repo-analyzer', 'e2e', 'accessibility', 'visual', 'performance'],
330
+ accessibility: { enabled: true, standard: 'wcag21aa' },
331
+ visual: { enabled: true, threshold: 0.1 },
332
+ performance: { enabled: true, budgets: { lcp: 2500, fcp: 1800, tti: 3800 } },
333
+
334
+ // Optional AI providers. Default is deterministic local QA with provider: 'none'.
335
+ ai: {
336
+ provider: 'none', // codex-cli, claude-code, anthropic-api, openai-api, gemini-cli, ollama
337
+ model: undefined,
338
+ command: undefined,
339
+ baseUrl: undefined,
340
+ },
292
341
 
293
- // AI explorer
294
- exploration: { maxSteps: 50 },
342
+ // Optional AI explorer, run only with --explore
343
+ exploration: { enabled: true, maxSteps: 50 },
295
344
 
296
345
  // Dead link checker
297
346
  deadLinks: {
347
+ scanCode: false, // docs/HTML by default; opt into JSX/TSX/JS/TS to reduce noise
298
348
  checkExternal: true,
299
349
  timeout: 5000,
300
350
  retries: 2,
@@ -318,6 +368,8 @@ export default defineConfig({
318
368
  });
319
369
  ```
320
370
 
371
+ Provider selection can also come from environment: `SNIFF_AI_PROVIDER`, `SNIFF_AI_MODEL`, `SNIFF_AI_COMMAND`, and `SNIFF_AI_BASE_URL`. API-backed providers use their normal keys: `ANTHROPIC_API_KEY` or `OPENAI_API_KEY`. If the selected provider is missing, Sniff skips AI generation and keeps the deterministic QA run moving.
372
+
321
373
  </details>
322
374
 
323
375
  <details>
@@ -350,11 +402,19 @@ Set any to `'off'` to disable.
350
402
 
351
403
  ## CI integration
352
404
 
405
+ Run Sniff directly in CI:
406
+
407
+ ```bash
408
+ npx sniff-qa --ci --format html,json,junit
409
+ ```
410
+
411
+ Generate a GitHub Actions workflow:
412
+
353
413
  ```bash
354
414
  npx sniff-qa ci
355
415
  ```
356
416
 
357
- Generates `.github/workflows/sniff.yml` with Playwright caching, JUnit output, and report artifacts.
417
+ This writes `.github/workflows/sniff.yml` with Playwright caching, JUnit output, and report artifacts.
358
418
 
359
419
  **Flakiness quarantine:** Tests that fail 3 of 5 runs get quarantined. They still run, still report, but won't block your pipeline.
360
420
 
@@ -403,25 +463,25 @@ Pass `--verbose` to see the top-3 candidates and every matched signal — useful
403
463
 
404
464
  **Production-URL safety:** when the target is not a local address, sniff prints a 5-second countdown banner before running. Hit Ctrl+C to cancel. No `--allow-destructive` flag.
405
465
 
406
- **LLM polish (optional):** if the `claude` CLI is available, sniff uses it to break close-call app-type classifications. Responses are cached under `.sniff/discover/cache/`. Pass `--no-llm` to skip.
466
+ **LLM polish (optional):** discovery can use the `claude` CLI to break close-call app-type classifications. Responses are cached under `.sniff/discover/cache/`. Pass `--no-llm` to skip.
407
467
 
408
468
  ---
409
469
 
410
470
  ## How it works
411
471
 
412
472
  <picture>
413
- <source media="(prefers-color-scheme: dark)" srcset=".github/assets/pipeline-dark.svg">
414
- <source media="(prefers-color-scheme: light)" srcset=".github/assets/pipeline-light.svg">
415
- <img alt="Sniff pipeline" src=".github/assets/pipeline-light.svg" width="100%">
473
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/Aboudjem/sniff/main/.github/assets/pipeline-dark.svg">
474
+ <source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/Aboudjem/sniff/main/.github/assets/pipeline-light.svg">
475
+ <img alt="Sniff pipeline" src="https://raw.githubusercontent.com/Aboudjem/sniff/main/.github/assets/pipeline-light.svg" width="100%">
416
476
  </picture>
417
477
 
418
478
  <details>
419
479
  <summary><b>Architecture</b></summary>
420
480
 
421
481
  <picture>
422
- <source media="(prefers-color-scheme: dark)" srcset=".github/assets/architecture-dark.svg">
423
- <source media="(prefers-color-scheme: light)" srcset=".github/assets/architecture-light.svg">
424
- <img alt="Sniff architecture" src=".github/assets/architecture-light.svg" width="100%">
482
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/Aboudjem/sniff/main/.github/assets/architecture-dark.svg">
483
+ <source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/Aboudjem/sniff/main/.github/assets/architecture-light.svg">
484
+ <img alt="Sniff architecture" src="https://raw.githubusercontent.com/Aboudjem/sniff/main/.github/assets/architecture-light.svg" width="100%">
425
485
  </picture>
426
486
 
427
487
  </details>
@@ -430,10 +490,10 @@ Pass `--verbose` to see the top-3 candidates and every matched signal — useful
430
490
 
431
491
  ## Privacy
432
492
 
433
- No telemetry. No signup. No data collection. No API keys. Your code stays on your machine.
493
+ No telemetry. No signup. No data collection. No API keys required. Your code stays on your machine unless you explicitly configure an API-backed AI provider.
434
494
 
435
495
  > [!NOTE]
436
- > All 8 checks work without any API key. The AI explorer uses Claude Code as the AI provider when run through MCP, so no separate Anthropic key is needed. Dead link checking validates external URLs but never sends your code.
496
+ > All deterministic checks work without any API key. Optional AI providers are off by default and must be selected through config or environment. Dead link checking validates external URLs but never sends your code.
437
497
 
438
498
  ---
439
499
 
package/SECURITY.md ADDED
@@ -0,0 +1,33 @@
1
+ # Security Policy
2
+
3
+ ## Reporting a Vulnerability
4
+
5
+ If you discover a security vulnerability in Sniff, please report it responsibly.
6
+
7
+ **Do NOT open a public GitHub issue for security vulnerabilities.**
8
+
9
+ Instead, email **adam@integralayer.com** with:
10
+
11
+ 1. Description of the vulnerability
12
+ 2. Steps to reproduce
13
+ 3. Potential impact
14
+ 4. Suggested fix (if any)
15
+
16
+ You will receive a response within 48 hours. We will work with you to understand
17
+ and address the issue before any public disclosure.
18
+
19
+ ## Scope
20
+
21
+ Sniff runs locally on your machine. Security concerns include:
22
+
23
+ - **Path traversal** in CLI arguments or config
24
+ - **Code injection** via malformed config files
25
+ - **Unsafe browser operations** in the exploration module
26
+ - **Dependency vulnerabilities** in the supply chain
27
+
28
+ ## Supported Versions
29
+
30
+ | Version | Supported |
31
+ |---------|-----------|
32
+ | 0.5.x | Yes |
33
+ | <0.5 | No |
@@ -34,6 +34,14 @@ var AccessibilityScanner = class {
34
34
  name = "accessibility";
35
35
  async scan(ctx) {
36
36
  const start = performance.now();
37
+ if (ctx.config.accessibility?.enabled === false) {
38
+ return {
39
+ scanner: this.name,
40
+ findings: [],
41
+ duration: performance.now() - start,
42
+ metadata: { skipped: true }
43
+ };
44
+ }
37
45
  const { AxeBuilder } = await import("@axe-core/playwright");
38
46
  const a11yConfig = ctx.config.accessibility;
39
47
  const standard = a11yConfig?.standard ?? "wcag21aa";
@@ -76,6 +84,7 @@ var AccessibilityScanner = class {
76
84
  snippet: node.html,
77
85
  url: ctx.page.url(),
78
86
  viewport: ctx.viewport.name,
87
+ browser: ctx.browser,
79
88
  fixSuggestion: buildFixSuggestion(violation, node)
80
89
  });
81
90
  }
@@ -90,4 +99,4 @@ var AccessibilityScanner = class {
90
99
  export {
91
100
  AccessibilityScanner
92
101
  };
93
- //# sourceMappingURL=accessibility-UNJB57T6.js.map
102
+ //# sourceMappingURL=accessibility-JXRMWF5Y.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/scanners/accessibility/index.ts"],"sourcesContent":["import { performance } from 'node:perf_hooks';\n\nimport type { BrowserScanner, BrowserScanContext, ScanResult } from '../types.js';\nimport type { BrowserFinding } from '../../core/types.js';\nimport type { Severity } from '../../core/types.js';\n\nfunction mapAxeImpact(impact: string | null | undefined): Severity {\n switch (impact) {\n case 'critical': return 'critical';\n case 'serious': return 'high';\n case 'moderate': return 'medium';\n case 'minor': return 'low';\n default: return 'medium';\n }\n}\n\nfunction buildFixSuggestion(\n violation: { id: string; helpUrl: string },\n node: { failureSummary?: string; any?: Array<{ id: string; data?: Record<string, unknown> }> },\n): string {\n if (violation.id === 'color-contrast') {\n const contrastData = node.any?.find((check) => check.id === 'color-contrast');\n if (contrastData?.data) {\n const expected = contrastData.data['expected'] as string | undefined;\n const actual = contrastData.data['contrastRatio'] as number | undefined;\n if (expected && actual !== undefined) {\n return `Expected contrast ratio of at least ${expected}:1, but found ${actual}:1. Increase the color difference between foreground and background.`;\n }\n }\n }\n\n if (node.failureSummary) {\n return node.failureSummary;\n }\n\n return `See ${violation.helpUrl} for remediation guidance.`;\n}\n\nexport class AccessibilityScanner implements BrowserScanner {\n name = 'accessibility';\n\n async scan(ctx: BrowserScanContext): Promise<ScanResult> {\n const start = performance.now();\n\n if (ctx.config.accessibility?.enabled === false) {\n return {\n scanner: this.name,\n findings: [],\n duration: performance.now() - start,\n metadata: { skipped: true },\n };\n }\n\n const { AxeBuilder } = await import('@axe-core/playwright');\n\n const a11yConfig = ctx.config.accessibility;\n\n const standard = a11yConfig?.standard ?? 'wcag21aa';\n let tags: string[];\n switch (standard) {\n case 'wcag2a':\n tags = ['wcag2a'];\n break;\n case 'wcag2aa':\n tags = ['wcag2a', 'wcag2aa'];\n break;\n case 'wcag21aa':\n default:\n tags = ['wcag2a', 'wcag2aa', 'wcag21aa'];\n break;\n }\n\n let builder = new AxeBuilder({ page: ctx.page }).withTags(tags);\n\n // Apply custom rule overrides\n if (a11yConfig?.rules) {\n for (const [ruleId, enabled] of Object.entries(a11yConfig.rules)) {\n if (enabled === false) {\n builder = builder.disableRules([ruleId]);\n }\n }\n }\n\n // Enable touch target-size rule on mobile viewports (A11Y-02)\n if (ctx.viewport.name === 'mobile') {\n builder = builder.withRules(['target-size']);\n }\n\n const results = await builder.analyze();\n\n const findings: BrowserFinding[] = [];\n for (const violation of results.violations) {\n const severity = mapAxeImpact(violation.impact);\n for (const node of violation.nodes) {\n findings.push({\n ruleId: `a11y/${violation.id}`,\n severity,\n message: `${violation.help}. ${violation.description}`,\n filePath: ctx.page.url(),\n line: 0,\n column: 0,\n snippet: node.html,\n url: ctx.page.url(),\n viewport: ctx.viewport.name,\n browser: ctx.browser,\n fixSuggestion: buildFixSuggestion(violation, node),\n });\n }\n }\n\n return {\n scanner: this.name,\n findings,\n duration: performance.now() - start,\n };\n }\n}\n"],"mappings":";AAAA,SAAS,mBAAmB;AAM5B,SAAS,aAAa,QAA6C;AACjE,UAAQ,QAAQ;AAAA,IACd,KAAK;AAAY,aAAO;AAAA,IACxB,KAAK;AAAW,aAAO;AAAA,IACvB,KAAK;AAAY,aAAO;AAAA,IACxB,KAAK;AAAS,aAAO;AAAA,IACrB;AAAS,aAAO;AAAA,EAClB;AACF;AAEA,SAAS,mBACP,WACA,MACQ;AACR,MAAI,UAAU,OAAO,kBAAkB;AACrC,UAAM,eAAe,KAAK,KAAK,KAAK,CAAC,UAAU,MAAM,OAAO,gBAAgB;AAC5E,QAAI,cAAc,MAAM;AACtB,YAAM,WAAW,aAAa,KAAK,UAAU;AAC7C,YAAM,SAAS,aAAa,KAAK,eAAe;AAChD,UAAI,YAAY,WAAW,QAAW;AACpC,eAAO,uCAAuC,QAAQ,iBAAiB,MAAM;AAAA,MAC/E;AAAA,IACF;AAAA,EACF;AAEA,MAAI,KAAK,gBAAgB;AACvB,WAAO,KAAK;AAAA,EACd;AAEA,SAAO,OAAO,UAAU,OAAO;AACjC;AAEO,IAAM,uBAAN,MAAqD;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AAG,UAAU,IAAI,KAAK,UAAU,WAAW;AAAA,UACpD,UAAU,IAAI,KAAK,IAAI;AAAA,UACvB,MAAM;AAAA,UACN,QAAQ;AAAA,UACR,SAAS,KAAK;AAAA,UACd,KAAK,IAAI,KAAK,IAAI;AAAA,UAClB,UAAU,IAAI,SAAS;AAAA,UACvB,SAAS,IAAI;AAAA,UACb,eAAe,mBAAmB,WAAW,IAAI;AAAA,QACnD,CAAC;AAAA,MACH;AAAA,IACF;AAEA,WAAO;AAAA,MACL,SAAS,KAAK;AAAA,MACd;AAAA,MACA,UAAU,YAAY,IAAI,IAAI;AAAA,IAChC;AAAA,EACF;AACF;","names":[]}
@@ -2,8 +2,10 @@
2
2
  var AnthropicAPIProvider = class {
3
3
  name = "anthropic-api";
4
4
  apiKey;
5
- constructor(apiKey) {
5
+ model;
6
+ constructor(apiKey, model = "claude-sonnet-4-5-20250514") {
6
7
  this.apiKey = apiKey;
8
+ this.model = model;
7
9
  }
8
10
  async generateTests(context) {
9
11
  const { buildSystemPrompt, buildUserPrompt } = await import("./prompt-builder-D3FBH534.js");
@@ -14,7 +16,7 @@ var AnthropicAPIProvider = class {
14
16
  const userPrompt = buildUserPrompt(context);
15
17
  try {
16
18
  const message = await client.messages.create({
17
- model: "claude-sonnet-4-5-20250514",
19
+ model: this.model,
18
20
  max_tokens: 4096,
19
21
  system: systemPrompt,
20
22
  messages: [{ role: "user", content: userPrompt }]
@@ -30,4 +32,4 @@ var AnthropicAPIProvider = class {
30
32
  export {
31
33
  AnthropicAPIProvider
32
34
  };
33
- //# sourceMappingURL=anthropic-api-MRDZ7BJA.js.map
35
+ //# sourceMappingURL=anthropic-api-ZR3UEB3Z.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/ai/anthropic-api.ts"],"sourcesContent":["import type { AIProvider, RouteTestContext, GeneratedTest } from './types.js';\nimport type { TextBlock } from '@anthropic-ai/sdk/resources/messages/messages.js';\n\nexport class AnthropicAPIProvider implements AIProvider {\n name = 'anthropic-api' as const;\n private apiKey: string;\n private model: string;\n\n constructor(apiKey: string, model = 'claude-sonnet-4-5-20250514') {\n this.apiKey = apiKey;\n this.model = model;\n }\n\n async generateTests(context: RouteTestContext): Promise<GeneratedTest> {\n const { buildSystemPrompt, buildUserPrompt } = await import('./prompt-builder.js');\n const { parseGeneratedTest } = await import('./response-parser.js');\n const { default: Anthropic } = await import('@anthropic-ai/sdk');\n\n const client = new Anthropic({ apiKey: this.apiKey });\n const systemPrompt = buildSystemPrompt();\n const userPrompt = buildUserPrompt(context);\n\n try {\n const message = await client.messages.create({\n model: this.model,\n max_tokens: 4096,\n system: systemPrompt,\n messages: [{ role: 'user', content: userPrompt }],\n });\n\n const rawContent = message.content\n .filter((block): block is TextBlock => block.type === 'text')\n .map((block) => block.text)\n .join('\\n');\n\n return parseGeneratedTest(rawContent, context.route.path);\n } catch (err) {\n const { SniffError } = await import('../core/errors.js');\n throw new SniffError('ANTHROPIC_API_ERROR', `Anthropic API failed: ${err instanceof Error ? err.message : String(err)}`);\n }\n }\n}\n"],"mappings":";AAGO,IAAM,uBAAN,MAAiD;AAAA,EACtD,OAAO;AAAA,EACC;AAAA,EACA;AAAA,EAER,YAAY,QAAgB,QAAQ,8BAA8B;AAChE,SAAK,SAAS;AACd,SAAK,QAAQ;AAAA,EACf;AAAA,EAEA,MAAM,cAAc,SAAmD;AACrE,UAAM,EAAE,mBAAmB,gBAAgB,IAAI,MAAM,OAAO,8BAAqB;AACjF,UAAM,EAAE,mBAAmB,IAAI,MAAM,OAAO,+BAAsB;AAClE,UAAM,EAAE,SAAS,UAAU,IAAI,MAAM,OAAO,mBAAmB;AAE/D,UAAM,SAAS,IAAI,UAAU,EAAE,QAAQ,KAAK,OAAO,CAAC;AACpD,UAAM,eAAe,kBAAkB;AACvC,UAAM,aAAa,gBAAgB,OAAO;AAE1C,QAAI;AACF,YAAM,UAAU,MAAM,OAAO,SAAS,OAAO;AAAA,QAC3C,OAAO,KAAK;AAAA,QACZ,YAAY;AAAA,QACZ,QAAQ;AAAA,QACR,UAAU,CAAC,EAAE,MAAM,QAAQ,SAAS,WAAW,CAAC;AAAA,MAClD,CAAC;AAED,YAAM,aAAa,QAAQ,QACxB,OAAO,CAAC,UAA8B,MAAM,SAAS,MAAM,EAC3D,IAAI,CAAC,UAAU,MAAM,IAAI,EACzB,KAAK,IAAI;AAEZ,aAAO,mBAAmB,YAAY,QAAQ,MAAM,IAAI;AAAA,IAC1D,SAAS,KAAK;AACZ,YAAM,EAAE,WAAW,IAAI,MAAM,OAAO,sBAAmB;AACvD,YAAM,IAAI,WAAW,uBAAuB,yBAAyB,eAAe,QAAQ,IAAI,UAAU,OAAO,GAAG,CAAC,EAAE;AAAA,IACzH;AAAA,EACF;AACF;","names":[]}
@@ -2,8 +2,15 @@
2
2
  import { mkdir, writeFile, readFile } from "fs/promises";
3
3
  import { join } from "path";
4
4
  async function generateTests(analysis, options) {
5
- const { resolveProvider } = await import("./provider-7IHXYR6V.js");
6
- const provider = await resolveProvider();
5
+ const { resolveProvider } = await import("./provider-BCKFVPTN.js");
6
+ const resolution = await resolveProvider(options.ai);
7
+ const provider = resolution.provider;
8
+ if (!provider) {
9
+ if (resolution.name !== "none") {
10
+ console.warn(`Skipping AI test generation (${resolution.name}): ${resolution.reason ?? "provider unavailable"}`);
11
+ }
12
+ return [];
13
+ }
7
14
  const outputDir = join(options.rootDir, options.outputDir);
8
15
  await mkdir(outputDir, { recursive: true });
9
16
  const results = [];
@@ -70,4 +77,4 @@ function routePathToFileName(routePath) {
70
77
  export {
71
78
  generateTests
72
79
  };
73
- //# sourceMappingURL=chunk-623BAIU2.js.map
80
+ //# sourceMappingURL=chunk-CZKMOAXU.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/ai/generator.ts"],"sourcesContent":["import { mkdir, writeFile, readFile } from 'node:fs/promises';\nimport { join } from 'node:path';\nimport type { AnalysisResult } from '../analyzers/types.js';\nimport type { AIConfig } from '../config/schema.js';\nimport type { GeneratedTest, RouteTestContext } from './types.js';\n\nexport interface GenerateOptions {\n outputDir: string; // default 'sniff-tests'\n maxConcurrency: number; // default 5\n rootDir: string;\n ai?: AIConfig;\n}\n\nexport async function generateTests(\n analysis: AnalysisResult,\n options: GenerateOptions,\n): Promise<GeneratedTest[]> {\n const { resolveProvider } = await import('./provider.js');\n const resolution = await resolveProvider(options.ai);\n const provider = resolution.provider;\n\n if (!provider) {\n if (resolution.name !== 'none') {\n console.warn(`Skipping AI test generation (${resolution.name}): ${resolution.reason ?? 'provider unavailable'}`);\n }\n return [];\n }\n\n const outputDir = join(options.rootDir, options.outputDir);\n await mkdir(outputDir, { recursive: true });\n\n const results: GeneratedTest[] = [];\n const errors: Array<{ route: string; error: string }> = [];\n\n // Process routes with concurrency limit\n const routes = analysis.routes;\n const totalRoutes = routes.length;\n console.log(`Generating tests for ${totalRoutes} route(s) using ${provider.name}...`);\n\n for (let i = 0; i < routes.length; i += options.maxConcurrency) {\n const batch = routes.slice(i, i + options.maxConcurrency);\n const batchEnd = Math.min(i + options.maxConcurrency, totalRoutes);\n console.log(` Generating tests: ${batchEnd}/${totalRoutes} routes...`);\n\n const batchResults = await Promise.allSettled(\n batch.map(async (route) => {\n // Build context for this route\n const routeElements = analysis.elements.filter(\n (el) => el.filePath === route.filePath,\n );\n const routeComponents = analysis.components.filter(\n (comp) => comp.filePath === route.filePath || comp.routes.includes(route.path),\n );\n const framework = analysis.project.frameworks[0] ?? { name: 'unknown' as const, configFiles: [] };\n\n // Read source content for context\n let sourceContent: string | undefined;\n try {\n sourceContent = await readFile(join(options.rootDir, route.filePath), 'utf-8');\n } catch { /* file might not be readable */ }\n\n const context: RouteTestContext = {\n route,\n elements: routeElements,\n components: routeComponents,\n framework,\n sourceContent,\n };\n\n const result = await provider.generateTests(context);\n\n // Write .spec.ts file\n const fileName = routePathToFileName(route.path);\n await writeFile(join(outputDir, fileName), result.specContent, 'utf-8');\n\n return result;\n }),\n );\n\n for (const [idx, result] of batchResults.entries()) {\n if (result.status === 'fulfilled') {\n results.push(result.value);\n } else {\n errors.push({\n route: batch[idx].path,\n error: result.reason instanceof Error ? result.reason.message : String(result.reason),\n });\n }\n }\n }\n\n if (errors.length > 0) {\n console.warn(`Warning: ${errors.length} route(s) failed AI generation:`);\n for (const err of errors) {\n console.warn(` - ${err.route}: ${err.error}`);\n }\n }\n\n console.log(`Generated ${results.length} test file(s) in ${options.outputDir}/`);\n return results;\n}\n\nfunction routePathToFileName(routePath: string): string {\n if (routePath === '/') return 'home.spec.ts';\n return routePath\n .replace(/^\\//, '')\n .replace(/\\//g, '-')\n .replace(/\\[([^\\]]+)\\]/g, '$1')\n .replace(/[^a-zA-Z0-9-]/g, '')\n + '.spec.ts';\n}\n"],"mappings":";AAAA,SAAS,OAAO,WAAW,gBAAgB;AAC3C,SAAS,YAAY;AAYrB,eAAsB,cACpB,UACA,SAC0B;AAC1B,QAAM,EAAE,gBAAgB,IAAI,MAAM,OAAO,wBAAe;AACxD,QAAM,aAAa,MAAM,gBAAgB,QAAQ,EAAE;AACnD,QAAM,WAAW,WAAW;AAE5B,MAAI,CAAC,UAAU;AACb,QAAI,WAAW,SAAS,QAAQ;AAC9B,cAAQ,KAAK,gCAAgC,WAAW,IAAI,MAAM,WAAW,UAAU,sBAAsB,EAAE;AAAA,IACjH;AACA,WAAO,CAAC;AAAA,EACV;AAEA,QAAM,YAAY,KAAK,QAAQ,SAAS,QAAQ,SAAS;AACzD,QAAM,MAAM,WAAW,EAAE,WAAW,KAAK,CAAC;AAE1C,QAAM,UAA2B,CAAC;AAClC,QAAM,SAAkD,CAAC;AAGzD,QAAM,SAAS,SAAS;AACxB,QAAM,cAAc,OAAO;AAC3B,UAAQ,IAAI,wBAAwB,WAAW,mBAAmB,SAAS,IAAI,KAAK;AAEpF,WAAS,IAAI,GAAG,IAAI,OAAO,QAAQ,KAAK,QAAQ,gBAAgB;AAC9D,UAAM,QAAQ,OAAO,MAAM,GAAG,IAAI,QAAQ,cAAc;AACxD,UAAM,WA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,KAAK,YAAY,OAAO,MAAM,iCAAiC;AACvE,eAAW,OAAO,QAAQ;AACxB,cAAQ,KAAK,OAAO,IAAI,KAAK,KAAK,IAAI,KAAK,EAAE;AAAA,IAC/C;AAAA,EACF;AAEA,UAAQ,IAAI,aAAa,QAAQ,MAAM,oBAAoB,QAAQ,SAAS,GAAG;AAC/E,SAAO;AACT;AAEA,SAAS,oBAAoB,WAA2B;AACtD,MAAI,cAAc,IAAK,QAAO;AAC9B,SAAO,UACJ,QAAQ,OAAO,EAAE,EACjB,QAAQ,OAAO,GAAG,EAClB,QAAQ,iBAAiB,IAAI,EAC7B,QAAQ,kBAAkB,EAAE,IAC3B;AACN;","names":[]}
@@ -4,8 +4,10 @@ var ConsoleErrorHook = class {
4
4
  name = "console-error";
5
5
  findings = [];
6
6
  currentViewport = "";
7
- setup(page, viewport) {
7
+ currentBrowser = "chromium";
8
+ setup(page, viewport, browser) {
8
9
  this.currentViewport = viewport;
10
+ this.currentBrowser = browser;
9
11
  page.on("console", (msg) => {
10
12
  if (msg.type() === "error") {
11
13
  this.findings.push({
@@ -18,6 +20,7 @@ var ConsoleErrorHook = class {
18
20
  snippet: msg.text(),
19
21
  url: msg.location().url || page.url(),
20
22
  viewport: this.currentViewport,
23
+ browser: this.currentBrowser,
21
24
  fixSuggestion: "Check browser console for stack trace details."
22
25
  });
23
26
  }
@@ -33,6 +36,7 @@ var ConsoleErrorHook = class {
33
36
  snippet: err.stack ?? err.message,
34
37
  url: page.url(),
35
38
  viewport: this.currentViewport,
39
+ browser: this.currentBrowser,
36
40
  fixSuggestion: "Check browser console for stack trace details."
37
41
  });
38
42
  });
@@ -48,8 +52,10 @@ var NetworkFailureHook = class {
48
52
  name = "network-failure";
49
53
  findings = [];
50
54
  currentViewport = "";
51
- setup(page, viewport) {
55
+ currentBrowser = "chromium";
56
+ setup(page, viewport, browser) {
52
57
  this.currentViewport = viewport;
58
+ this.currentBrowser = browser;
53
59
  page.on("response", (res) => {
54
60
  const status = res.status();
55
61
  if (status >= 400) {
@@ -64,6 +70,7 @@ var NetworkFailureHook = class {
64
70
  snippet: `${res.request().method()} ${res.url()} -> ${status}`,
65
71
  url: res.url(),
66
72
  viewport: this.currentViewport,
73
+ browser: this.currentBrowser,
67
74
  fixSuggestion: "Verify the resource URL is correct and the server is responding."
68
75
  });
69
76
  }
@@ -79,6 +86,7 @@ var NetworkFailureHook = class {
79
86
  snippet: `${req.method()} ${req.url()} -> FAILED: ${req.failure()?.errorText ?? "unknown"}`,
80
87
  url: req.url(),
81
88
  viewport: this.currentViewport,
89
+ browser: this.currentBrowser,
82
90
  fixSuggestion: "Verify the resource URL is correct and the server is responding."
83
91
  });
84
92
  });
@@ -92,7 +100,7 @@ var NetworkFailureHook = class {
92
100
  };
93
101
  var ScreenshotHook = class {
94
102
  name = "screenshot";
95
- setup(_page, _viewport) {
103
+ setup(_page, _viewport, _browser) {
96
104
  }
97
105
  collect() {
98
106
  return [];
@@ -114,10 +122,10 @@ var PageHookPipeline = class {
114
122
  this.screenshotHook = hook;
115
123
  }
116
124
  }
117
- setupAll(page, viewport) {
125
+ setupAll(page, viewport, browser) {
118
126
  for (const hook of this.hooks) {
119
127
  try {
120
- hook.setup(page, viewport);
128
+ hook.setup(page, viewport, browser);
121
129
  } catch {
122
130
  }
123
131
  }
@@ -154,4 +162,4 @@ export {
154
162
  ScreenshotHook,
155
163
  PageHookPipeline
156
164
  };
157
- //# sourceMappingURL=chunk-CBDOJUXB.js.map
165
+ //# sourceMappingURL=chunk-MYWWSM3V.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/browser/page-hooks.ts"],"sourcesContent":["import type { Page, ConsoleMessage, Response, Request } from 'playwright';\nimport type { BrowserFinding } from '../core/types.js';\nimport type { BrowserProject } from '../config/schema.js';\nimport { join } from 'node:path';\n\nexport interface PageHook {\n name: string;\n setup(page: Page, viewport: string, browser: BrowserProject): void;\n collect(): BrowserFinding[];\n reset(): void;\n}\n\nexport class ConsoleErrorHook implements PageHook {\n readonly name = 'console-error';\n private findings: BrowserFinding[] = [];\n private currentViewport = '';\n private currentBrowser: BrowserProject = 'chromium';\n\n setup(page: Page, viewport: string, browser: BrowserProject): void {\n this.currentViewport = viewport;\n this.currentBrowser = browser;\n\n page.on('console', (msg: ConsoleMessage) => {\n if (msg.type() === 'error') {\n this.findings.push({\n ruleId: 'e2e/console-error',\n severity: 'high',\n message: `Console error: ${msg.text()}`,\n filePath: '',\n line: 0,\n column: 0,\n snippet: msg.text(),\n url: msg.location().url || page.url(),\n viewport: this.currentViewport,\n browser: this.currentBrowser,\n fixSuggestion: 'Check browser console for stack trace details.',\n });\n }\n });\n\n page.on('pageerror', (err: Error) => {\n this.findings.push({\n ruleId: 'e2e/console-error',\n severity: 'high',\n message: `Uncaught exception: ${err.message}`,\n filePath: '',\n line: 0,\n column: 0,\n snippet: err.stack ?? err.message,\n url: page.url(),\n viewport: this.currentViewport,\n browser: this.currentBrowser,\n fixSuggestion: 'Check browser console for stack trace details.',\n });\n });\n }\n\n collect(): BrowserFinding[] {\n return [...this.findings];\n }\n\n reset(): void {\n this.findings = [];\n }\n}\n\nexport class NetworkFailureHook implements PageHook {\n readonly name = 'network-failure';\n private findings: BrowserFinding[] = [];\n private currentViewport = '';\n private currentBrowser: BrowserProject = 'chromium';\n\n setup(page: Page, viewport: string, browser: BrowserProject): void {\n this.currentViewport = viewport;\n this.currentBrowser = browser;\n\n page.on('response', (res: Response) => {\n const status = res.status();\n if (status >= 400) {\n const severity = status >= 500 ? 'high' as const : 'medium' as const;\n this.findings.push({\n ruleId: 'e2e/network-failure',\n severity,\n message: `HTTP ${status} for ${res.url()}`,\n filePath: '',\n line: 0,\n column: 0,\n snippet: `${res.request().method()} ${res.url()} -> ${status}`,\n url: res.url(),\n viewport: this.currentViewport,\n browser: this.currentBrowser,\n fixSuggestion: 'Verify the resource URL is correct and the server is responding.',\n });\n }\n });\n\n page.on('requestfailed', (req: Request) => {\n this.findings.push({\n ruleId: 'e2e/network-failure',\n severity: 'critical',\n message: `Request failed: ${req.url()} (${req.failure()?.errorText ?? 'unknown error'})`,\n filePath: '',\n line: 0,\n column: 0,\n snippet: `${req.method()} ${req.url()} -> FAILED: ${req.failure()?.errorText ?? 'unknown'}`,\n url: req.url(),\n viewport: this.currentViewport,\n browser: this.currentBrowser,\n fixSuggestion: 'Verify the resource URL is correct and the server is responding.',\n });\n });\n }\n\n collect(): BrowserFinding[] {\n return [...this.findings];\n }\n\n reset(): void {\n this.findings = [];\n }\n}\n\nexport class ScreenshotHook implements PageHook {\n readonly name = 'screenshot';\n\n setup(_page: Page, _viewport: string, _browser: BrowserProject): void {\n // ScreenshotHook does not listen to events; it is called on demand.\n }\n\n collect(): BrowserFinding[] {\n return [];\n }\n\n reset(): void {\n // No state to reset.\n }\n\n async captureFailure(page: Page, name: string, outputDir: string): Promise<string> {\n const screenshotPath = join(outputDir, `${name}.png`);\n await page.screenshot({ path: screenshotPath, fullPage: false });\n return screenshotPath;\n }\n}\n\nexport class PageHookPipeline {\n private hooks: PageHook[] = [];\n private screenshotHook: ScreenshotHook | null = null;\n\n register(hook: PageHook): void {\n this.hooks.push(hook);\n if (hook instanceof ScreenshotHook) {\n this.screenshotHook = hook;\n }\n }\n\n setupAll(page: Page, viewport: string, browser: BrowserProject): void {\n for (const hook of this.hooks) {\n try {\n hook.setup(page, viewport, browser);\n } catch {\n // Error isolation: if one hook fails setup, others still run.\n }\n }\n }\n\n collectAll(): BrowserFinding[] {\n const findings: BrowserFinding[] = [];\n for (const hook of this.hooks) {\n try {\n findings.push(...hook.collect());\n } catch {\n // Error isolation: if one hook fails collection, others still run.\n }\n }\n return findings;\n }\n\n resetAll(): void {\n for (const hook of this.hooks) {\n try {\n hook.reset();\n } catch {\n // Error isolation: if one hook fails reset, others still run.\n }\n }\n }\n\n async captureScreenshot(page: Page, name: string, outputDir: string): Promise<string | undefined> {\n if (this.screenshotHook) {\n return this.screenshotHook.captureFailure(page, name, outputDir);\n }\n return undefined;\n }\n}\n"],"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