sniff-qa 0.4.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/plugin.json +13 -0
- package/CHANGELOG.md +89 -0
- package/NOTICE +14 -0
- package/README.md +127 -38
- package/SECURITY.md +33 -0
- package/dist/{accessibility-UNJB57T6.js → accessibility-JXRMWF5Y.js} +10 -1
- package/dist/accessibility-JXRMWF5Y.js.map +1 -0
- package/dist/{anthropic-api-MRDZ7BJA.js → anthropic-api-ZR3UEB3Z.js} +5 -3
- package/dist/anthropic-api-ZR3UEB3Z.js.map +1 -0
- package/dist/{chunk-623BAIU2.js → chunk-CZKMOAXU.js} +10 -3
- package/dist/chunk-CZKMOAXU.js.map +1 -0
- package/dist/{chunk-CBDOJUXB.js → chunk-MYWWSM3V.js} +14 -6
- package/dist/chunk-MYWWSM3V.js.map +1 -0
- package/dist/{ci-2MVD2ISE.js → ci-ISCWZJD3.js} +3 -3
- package/dist/{ci-2MVD2ISE.js.map → ci-ISCWZJD3.js.map} +1 -1
- package/dist/classifier-MWQMQ727.js +1701 -0
- package/dist/classifier-MWQMQ727.js.map +1 -0
- package/dist/{claude-code-F722EIIC.js → claude-code-ZFTBQXY4.js} +7 -3
- package/dist/claude-code-ZFTBQXY4.js.map +1 -0
- package/dist/cli/index.js +38 -44
- package/dist/cli/index.js.map +1 -1
- package/dist/dev-server-detector-XQ5AYPDT.js +319 -0
- package/dist/dev-server-detector-XQ5AYPDT.js.map +1 -0
- package/dist/{discover-BLUSO42Q.js → discover-ENPRVN5A.js} +114 -15
- package/dist/discover-ENPRVN5A.js.map +1 -0
- package/dist/ensure-browsers-AYKMLUHV.js +86 -0
- package/dist/ensure-browsers-AYKMLUHV.js.map +1 -0
- package/dist/generator-HIFV67NI.js +7 -0
- package/dist/index.d.ts +43 -2
- package/dist/index.js +1 -1
- package/dist/init-IQKT4ANC.js +148 -0
- package/dist/init-IQKT4ANC.js.map +1 -0
- package/dist/{loader-QII5CZSX.js → loader-UG2XADG7.js} +25 -4
- package/dist/loader-UG2XADG7.js.map +1 -0
- package/dist/mcp/server.js +186 -41
- package/dist/mcp/server.js.map +1 -1
- package/dist/{model-2DTSAX7T.js → model-X5J2JR5U.js} +1 -1
- package/dist/{page-hooks-DOZWXF7Z.js → page-hooks-6RALVZB5.js} +2 -2
- package/dist/{performance-FBUGBRB3.js → performance-7HWKY5O2.js} +6 -3
- package/dist/performance-7HWKY5O2.js.map +1 -0
- package/dist/provider-BCKFVPTN.js +183 -0
- package/dist/provider-BCKFVPTN.js.map +1 -0
- package/dist/quality-run-6SXCN5CD.js +79 -0
- package/dist/quality-run-6SXCN5CD.js.map +1 -0
- package/dist/{registry-NB5CZB6W.js → registry-5XCXUAYJ.js} +14 -2
- package/dist/registry-5XCXUAYJ.js.map +1 -0
- package/dist/{report-STC6CAVJ.js → report-OAHSB56I.js} +2 -2
- package/dist/{runner-OYTN2NFD.js → runner-AXZXNWYH.js} +3 -3
- package/dist/runner-AXZXNWYH.js.map +1 -0
- package/dist/{runner-Z4I2YVVM.js → runner-HFJDHS2I.js} +3 -3
- package/dist/runner-HFJDHS2I.js.map +1 -0
- package/dist/runner-II7BPB63.js +201 -0
- package/dist/runner-II7BPB63.js.map +1 -0
- package/dist/{scenarios-25UAZY6F.js → scenarios-I7YYVTD2.js} +11 -6
- package/dist/{scenarios-25UAZY6F.js.map → scenarios-I7YYVTD2.js.map} +1 -1
- package/dist/{source-4DOO224X.js → source-5LS2B7TN.js} +38 -22
- package/dist/source-5LS2B7TN.js.map +1 -0
- package/dist/{unified-2PM442OY.js → unified-SKXQQX3Y.js} +25 -74
- package/dist/unified-SKXQQX3Y.js.map +1 -0
- package/dist/{update-baselines-MDTCFO2U.js → update-baselines-UCAW3SDN.js} +2 -2
- package/dist/{visual-ZSQPDE7A.js → visual-EUZG2STF.js} +8 -4
- package/dist/visual-EUZG2STF.js.map +1 -0
- package/dist/{workflow-template-3KFPCVIC.js → workflow-template-6DADGPHA.js} +5 -3
- package/dist/workflow-template-6DADGPHA.js.map +1 -0
- package/package.json +21 -8
- package/skills/sniff/SKILL.md +47 -0
- package/skills/sniff-fix/SKILL.md +44 -0
- package/skills/sniff-report/SKILL.md +40 -0
- package/smithery.yaml +10 -0
- package/dist/accessibility-UNJB57T6.js.map +0 -1
- package/dist/anthropic-api-MRDZ7BJA.js.map +0 -1
- package/dist/chunk-623BAIU2.js.map +0 -1
- package/dist/chunk-CBDOJUXB.js.map +0 -1
- package/dist/classifier-XEA6ZGE7.js +0 -673
- package/dist/classifier-XEA6ZGE7.js.map +0 -1
- package/dist/claude-code-F722EIIC.js.map +0 -1
- package/dist/dev-server-detector-NJ5RN4IC.js +0 -150
- package/dist/dev-server-detector-NJ5RN4IC.js.map +0 -1
- package/dist/discover-BLUSO42Q.js.map +0 -1
- package/dist/generator-OZY3HMJW.js +0 -7
- package/dist/init-75MMIW4A.js +0 -66
- package/dist/init-75MMIW4A.js.map +0 -1
- package/dist/loader-QII5CZSX.js.map +0 -1
- package/dist/performance-FBUGBRB3.js.map +0 -1
- package/dist/provider-7IHXYR6V.js +0 -13
- package/dist/provider-7IHXYR6V.js.map +0 -1
- package/dist/registry-NB5CZB6W.js.map +0 -1
- package/dist/runner-MS2SNTMR.js +0 -153
- package/dist/runner-MS2SNTMR.js.map +0 -1
- package/dist/runner-OYTN2NFD.js.map +0 -1
- package/dist/runner-Z4I2YVVM.js.map +0 -1
- package/dist/source-4DOO224X.js.map +0 -1
- package/dist/unified-2PM442OY.js.map +0 -1
- package/dist/visual-ZSQPDE7A.js.map +0 -1
- package/dist/workflow-template-3KFPCVIC.js.map +0 -1
- /package/dist/{generator-OZY3HMJW.js.map → generator-HIFV67NI.js.map} +0 -0
- /package/dist/{model-2DTSAX7T.js.map → model-X5J2JR5U.js.map} +0 -0
- /package/dist/{page-hooks-DOZWXF7Z.js.map → page-hooks-6RALVZB5.js.map} +0 -0
- /package/dist/{report-STC6CAVJ.js.map → report-OAHSB56I.js.map} +0 -0
- /package/dist/{update-baselines-MDTCFO2U.js.map → update-baselines-UCAW3SDN.js.map} +0 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: sniff-fix
|
|
3
|
+
description: Scan the project and auto-fix safe issues (remove debugger statements, console.log calls, and other auto-fixable problems).
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# /sniff-fix - Scan and fix issues
|
|
7
|
+
|
|
8
|
+
Scan the project, then automatically fix safe issues.
|
|
9
|
+
|
|
10
|
+
## What to do
|
|
11
|
+
|
|
12
|
+
1. Use the unified `sniff` MCP tool with `mode: "scan"` and the project's `rootDir` to get all findings. If the unified tool is not available, use legacy `sniff_scan`.
|
|
13
|
+
|
|
14
|
+
2. For each finding, fix it if safe:
|
|
15
|
+
- `debug-debugger`: Remove the `debugger;` line
|
|
16
|
+
- `debug-console-log`: Remove `console.log/debug/info` lines
|
|
17
|
+
- `placeholder-lorem`: Flag to user (needs manual replacement)
|
|
18
|
+
- `hardcoded-localhost`: Suggest environment variable
|
|
19
|
+
- `api-hardcoded-secret`: Remove the secret and suggest env var
|
|
20
|
+
|
|
21
|
+
3. Do NOT auto-fix without telling the user what you're changing
|
|
22
|
+
|
|
23
|
+
4. After fixing, re-run unified `sniff` with `mode: "scan"` to verify issues are resolved
|
|
24
|
+
|
|
25
|
+
## Example
|
|
26
|
+
|
|
27
|
+
```
|
|
28
|
+
User: /sniff-fix
|
|
29
|
+
You: I'll scan and fix what I can.
|
|
30
|
+
|
|
31
|
+
Found 8 issues. Auto-fixing 4:
|
|
32
|
+
|
|
33
|
+
- Removed `debugger` from src/handler.ts:42
|
|
34
|
+
- Removed `console.log` from src/api.ts:8
|
|
35
|
+
- Removed `console.log` from src/api.ts:15
|
|
36
|
+
- Removed `console.debug` from src/utils.ts:3
|
|
37
|
+
|
|
38
|
+
4 issues need manual attention:
|
|
39
|
+
- src/config.ts:8 - Hardcoded localhost URL (replace with env var)
|
|
40
|
+
- README.md:28 - Broken link to ./missing-guide.md
|
|
41
|
+
- ...
|
|
42
|
+
|
|
43
|
+
Re-scanning... 4 issues remaining (down from 8).
|
|
44
|
+
```
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: sniff-report
|
|
3
|
+
description: Show the results from the last sniff scan.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# /sniff-report - Show last scan results
|
|
7
|
+
|
|
8
|
+
Display findings from the most recent scan.
|
|
9
|
+
|
|
10
|
+
## What to do
|
|
11
|
+
|
|
12
|
+
1. Use the unified `sniff` MCP tool with:
|
|
13
|
+
- `mode`: `"report"`
|
|
14
|
+
- `rootDir`: the current project's absolute path
|
|
15
|
+
- `format`: 'summary' for readable output, 'json' for raw data
|
|
16
|
+
|
|
17
|
+
2. If the unified `sniff` tool is not available, use legacy `sniff_report` with the same rootDir and format.
|
|
18
|
+
|
|
19
|
+
3. Present the summary to the user:
|
|
20
|
+
- Total findings by severity
|
|
21
|
+
- Top issues with file locations
|
|
22
|
+
- Any corroborated findings (confirmed in source + browser)
|
|
23
|
+
|
|
24
|
+
## Example
|
|
25
|
+
|
|
26
|
+
```
|
|
27
|
+
User: /sniff-report
|
|
28
|
+
You: Here are the results from your last scan:
|
|
29
|
+
|
|
30
|
+
**Summary:** 12 findings (1 critical, 3 high, 6 medium, 2 low)
|
|
31
|
+
|
|
32
|
+
**Top issues:**
|
|
33
|
+
1. `src/routes.ts:14` - CRITICAL: Hardcoded API key
|
|
34
|
+
2. `src/handler.ts:42` - HIGH: debugger statement
|
|
35
|
+
3. `README.md:28` - HIGH: Broken internal link
|
|
36
|
+
|
|
37
|
+
Reports saved to:
|
|
38
|
+
- .sniff/reports/report.html
|
|
39
|
+
- .sniff/reports/report.json
|
|
40
|
+
```
|
package/smithery.yaml
ADDED
|
@@ -1 +0,0 @@
|
|
|
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 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 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;AAAA,EAC1D,OAAO;AAAA,EAEP,MAAM,KAAK,KAA8C;AACvD,UAAM,QAAQ,YAAY,IAAI;AAE9B,UAAM,EAAE,WAAW,IAAI,MAAM,OAAO,sBAAsB;AAE1D,UAAM,aAAa,IAAI,OAAO;AAE9B,UAAM,WAAW,YAAY,YAAY;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
@@ -1 +0,0 @@
|
|
|
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';\n private apiKey: string;\n\n constructor(apiKey: string) {\n this.apiKey = apiKey;\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: 'claude-sonnet-4-5-20250514',\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,EAER,YAAY,QAAgB;AAC1B,SAAK,SAAS;AAAA,EAChB;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;AAAA,QACP,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":[]}
|
|
@@ -1 +0,0 @@
|
|
|
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 { GeneratedTest, RouteTestContext } from './types.js';\n\nexport interface GenerateOptions {\n outputDir: string; // default 'sniff-tests'\n maxConcurrency: number; // default 5\n rootDir: string;\n}\n\nexport async function generateTests(\n analysis: AnalysisResult,\n options: GenerateOptions,\n): Promise<GeneratedTest[]> {\n const { resolveProvider } = await import('./provider.js');\n const provider = await resolveProvider();\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;AAUrB,eAAsB,cACpB,UACA,SAC0B;AAC1B,QAAM,EAAE,gBAAgB,IAAI,MAAM,OAAO,wBAAe;AACxD,QAAM,WAAW,M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AAO,aAAa,OAAO;AAEtE,eAAO;AAAA,MACT,CAAC;AAAA,IACH;AAEA,eAAW,CAAC,KAAK,MAAM,KAAK,aAAa,QAAQ,GAAG;AAClD,UAAI,OAAO,WAAW,aAAa;AACjC,gBAAQ,KAAK,OAAO,KAAK;AAAA,MAC3B,OAAO;AACL,eAAO,KAAK;AAAA,UACV,OAAO,MAAM,GAAG,EAAE;AAAA,UAClB,OAAO,OAAO,kBAAkB,QAAQ,OAAO,OAAO,UAAU,OAAO,OAAO,MAAM;AAAA,QACtF,CAAC;AAAA,MACH;AAAA,IACF;AAAA,EACF;AAEA,MAAI,OAAO,SAAS,GAAG;AACrB,YAAQ,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":[]}
|
|
@@ -1 +0,0 @@
|
|
|
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 { join } from 'node:path';\n\nexport interface PageHook {\n name: string;\n setup(page: Page, viewport: string): 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\n setup(page: Page, viewport: string): void {\n this.currentViewport = viewport;\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 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 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\n setup(page: Page, viewport: string): void {\n this.currentViewport = viewport;\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 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 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): 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): void {\n for (const hook of this.hooks) {\n try {\n hook.setup(page, viewport);\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"],"mappings":";AAEA,SAAS,YAAY;AASd,IAAM,mBAAN,MAA2C;AAAA,EACvC,OAAO;AAAA,EACR,WAA6B,CAAC;AAAA,EAC9B,kBAAkB;AAAA,EAE1B,MAAM,MAAY,UAAwB;AACxC,SAAK,kBAAkB;AAEvB,SAAK,GAAG,WAAW,CAAC,QAAwB;AAC1C,UAAI,IAAI,KAAK,MAAM,SAAS;AAC1B,aAAK,SAAS,KAAK;AAAA,UACjB,QAAQ;AAAA,UACR,UAAU;AAAA,UACV,SAAS,kBAAkB,IAAI,KAAK,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