sniff-qa 0.2.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 (92) hide show
  1. package/LICENSE +172 -0
  2. package/README.md +581 -0
  3. package/dist/accessibility-UNJB57T6.js +93 -0
  4. package/dist/accessibility-UNJB57T6.js.map +1 -0
  5. package/dist/anthropic-api-MRDZ7BJA.js +33 -0
  6. package/dist/anthropic-api-MRDZ7BJA.js.map +1 -0
  7. package/dist/chunk-623BAIU2.js +73 -0
  8. package/dist/chunk-623BAIU2.js.map +1 -0
  9. package/dist/chunk-CBDOJUXB.js +157 -0
  10. package/dist/chunk-CBDOJUXB.js.map +1 -0
  11. package/dist/chunk-IXDUD2UG.js +14 -0
  12. package/dist/chunk-IXDUD2UG.js.map +1 -0
  13. package/dist/chunk-MMISGY2Q.js +52 -0
  14. package/dist/chunk-MMISGY2Q.js.map +1 -0
  15. package/dist/chunk-ZM6MGWO4.js +49 -0
  16. package/dist/chunk-ZM6MGWO4.js.map +1 -0
  17. package/dist/ci-2MVD2ISE.js +52 -0
  18. package/dist/ci-2MVD2ISE.js.map +1 -0
  19. package/dist/claude-code-F722EIIC.js +42 -0
  20. package/dist/claude-code-F722EIIC.js.map +1 -0
  21. package/dist/claude-exploration-provider-QJH6IPYU.js +126 -0
  22. package/dist/claude-exploration-provider-QJH6IPYU.js.map +1 -0
  23. package/dist/cli/index.d.ts +1 -0
  24. package/dist/cli/index.js +72 -0
  25. package/dist/cli/index.js.map +1 -0
  26. package/dist/cross-reference-MHNPSLEN.js +218 -0
  27. package/dist/cross-reference-MHNPSLEN.js.map +1 -0
  28. package/dist/element-extractor-OZTFBVKZ.js +250 -0
  29. package/dist/element-extractor-OZTFBVKZ.js.map +1 -0
  30. package/dist/errors-RFEOR527.js +7 -0
  31. package/dist/errors-RFEOR527.js.map +1 -0
  32. package/dist/flakiness-OVC7KGN2.js +11 -0
  33. package/dist/flakiness-OVC7KGN2.js.map +1 -0
  34. package/dist/formatter-HC3LT3VH.js +146 -0
  35. package/dist/formatter-HC3LT3VH.js.map +1 -0
  36. package/dist/framework-detector-ISSM2Q2I.js +95 -0
  37. package/dist/framework-detector-ISSM2Q2I.js.map +1 -0
  38. package/dist/generator-OZY3HMJW.js +7 -0
  39. package/dist/generator-OZY3HMJW.js.map +1 -0
  40. package/dist/index.d.ts +212 -0
  41. package/dist/index.js +13 -0
  42. package/dist/index.js.map +1 -0
  43. package/dist/init-75MMIW4A.js +66 -0
  44. package/dist/init-75MMIW4A.js.map +1 -0
  45. package/dist/json-YDWEB33Q.js +8 -0
  46. package/dist/json-YDWEB33Q.js.map +1 -0
  47. package/dist/junit-GL44ATRR.js +52 -0
  48. package/dist/junit-GL44ATRR.js.map +1 -0
  49. package/dist/loader-QII5CZSX.js +161 -0
  50. package/dist/loader-QII5CZSX.js.map +1 -0
  51. package/dist/mcp/server.d.ts +3 -0
  52. package/dist/mcp/server.js +171 -0
  53. package/dist/mcp/server.js.map +1 -0
  54. package/dist/model-SRPWXU63.js +92 -0
  55. package/dist/model-SRPWXU63.js.map +1 -0
  56. package/dist/page-hooks-DOZWXF7Z.js +13 -0
  57. package/dist/page-hooks-DOZWXF7Z.js.map +1 -0
  58. package/dist/page-state-extractor-GYYLYRFR.js +75 -0
  59. package/dist/page-state-extractor-GYYLYRFR.js.map +1 -0
  60. package/dist/performance-FBUGBRB3.js +134 -0
  61. package/dist/performance-FBUGBRB3.js.map +1 -0
  62. package/dist/persistence-RHUFBQAY.js +86 -0
  63. package/dist/persistence-RHUFBQAY.js.map +1 -0
  64. package/dist/prompt-builder-D3FBH534.js +53 -0
  65. package/dist/prompt-builder-D3FBH534.js.map +1 -0
  66. package/dist/provider-7IHXYR6V.js +13 -0
  67. package/dist/provider-7IHXYR6V.js.map +1 -0
  68. package/dist/registry-NB5CZB6W.js +43 -0
  69. package/dist/registry-NB5CZB6W.js.map +1 -0
  70. package/dist/repo-analyzer-4OURSITY.js +49 -0
  71. package/dist/repo-analyzer-4OURSITY.js.map +1 -0
  72. package/dist/report-E2JZMQED.js +61 -0
  73. package/dist/report-E2JZMQED.js.map +1 -0
  74. package/dist/response-parser-PUGNWF7S.js +46 -0
  75. package/dist/response-parser-PUGNWF7S.js.map +1 -0
  76. package/dist/route-discoverer-QBZCRQLJ.js +304 -0
  77. package/dist/route-discoverer-QBZCRQLJ.js.map +1 -0
  78. package/dist/runner-MS2SNTMR.js +153 -0
  79. package/dist/runner-MS2SNTMR.js.map +1 -0
  80. package/dist/runner-Z4I2YVVM.js +237 -0
  81. package/dist/runner-Z4I2YVVM.js.map +1 -0
  82. package/dist/source-D5KLH46F.js +896 -0
  83. package/dist/source-D5KLH46F.js.map +1 -0
  84. package/dist/unified-CQU7PSNJ.js +275 -0
  85. package/dist/unified-CQU7PSNJ.js.map +1 -0
  86. package/dist/update-baselines-MDTCFO2U.js +71 -0
  87. package/dist/update-baselines-MDTCFO2U.js.map +1 -0
  88. package/dist/visual-ZSQPDE7A.js +125 -0
  89. package/dist/visual-ZSQPDE7A.js.map +1 -0
  90. package/dist/workflow-template-3KFPCVIC.js +119 -0
  91. package/dist/workflow-template-3KFPCVIC.js.map +1 -0
  92. package/package.json +95 -0
@@ -0,0 +1,33 @@
1
+ // src/ai/anthropic-api.ts
2
+ var AnthropicAPIProvider = class {
3
+ name = "anthropic-api";
4
+ apiKey;
5
+ constructor(apiKey) {
6
+ this.apiKey = apiKey;
7
+ }
8
+ async generateTests(context) {
9
+ const { buildSystemPrompt, buildUserPrompt } = await import("./prompt-builder-D3FBH534.js");
10
+ const { parseGeneratedTest } = await import("./response-parser-PUGNWF7S.js");
11
+ const { default: Anthropic } = await import("@anthropic-ai/sdk");
12
+ const client = new Anthropic({ apiKey: this.apiKey });
13
+ const systemPrompt = buildSystemPrompt();
14
+ const userPrompt = buildUserPrompt(context);
15
+ try {
16
+ const message = await client.messages.create({
17
+ model: "claude-sonnet-4-5-20250514",
18
+ max_tokens: 4096,
19
+ system: systemPrompt,
20
+ messages: [{ role: "user", content: userPrompt }]
21
+ });
22
+ const rawContent = message.content.filter((block) => block.type === "text").map((block) => block.text).join("\n");
23
+ return parseGeneratedTest(rawContent, context.route.path);
24
+ } catch (err) {
25
+ const { SniffError } = await import("./errors-RFEOR527.js");
26
+ throw new SniffError("ANTHROPIC_API_ERROR", `Anthropic API failed: ${err instanceof Error ? err.message : String(err)}`);
27
+ }
28
+ }
29
+ };
30
+ export {
31
+ AnthropicAPIProvider
32
+ };
33
+ //# sourceMappingURL=anthropic-api-MRDZ7BJA.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';\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":[]}
@@ -0,0 +1,73 @@
1
+ // src/ai/generator.ts
2
+ import { mkdir, writeFile, readFile } from "fs/promises";
3
+ import { join } from "path";
4
+ async function generateTests(analysis, options) {
5
+ const { resolveProvider } = await import("./provider-7IHXYR6V.js");
6
+ const provider = await resolveProvider();
7
+ const outputDir = join(options.rootDir, options.outputDir);
8
+ await mkdir(outputDir, { recursive: true });
9
+ const results = [];
10
+ const errors = [];
11
+ const routes = analysis.routes;
12
+ const totalRoutes = routes.length;
13
+ console.log(`Generating tests for ${totalRoutes} route(s) using ${provider.name}...`);
14
+ for (let i = 0; i < routes.length; i += options.maxConcurrency) {
15
+ const batch = routes.slice(i, i + options.maxConcurrency);
16
+ const batchEnd = Math.min(i + options.maxConcurrency, totalRoutes);
17
+ console.log(` Generating tests: ${batchEnd}/${totalRoutes} routes...`);
18
+ const batchResults = await Promise.allSettled(
19
+ batch.map(async (route) => {
20
+ const routeElements = analysis.elements.filter(
21
+ (el) => el.filePath === route.filePath
22
+ );
23
+ const routeComponents = analysis.components.filter(
24
+ (comp) => comp.filePath === route.filePath || comp.routes.includes(route.path)
25
+ );
26
+ const framework = analysis.project.frameworks[0] ?? { name: "unknown", configFiles: [] };
27
+ let sourceContent;
28
+ try {
29
+ sourceContent = await readFile(join(options.rootDir, route.filePath), "utf-8");
30
+ } catch {
31
+ }
32
+ const context = {
33
+ route,
34
+ elements: routeElements,
35
+ components: routeComponents,
36
+ framework,
37
+ sourceContent
38
+ };
39
+ const result = await provider.generateTests(context);
40
+ const fileName = routePathToFileName(route.path);
41
+ await writeFile(join(outputDir, fileName), result.specContent, "utf-8");
42
+ return result;
43
+ })
44
+ );
45
+ for (const [idx, result] of batchResults.entries()) {
46
+ if (result.status === "fulfilled") {
47
+ results.push(result.value);
48
+ } else {
49
+ errors.push({
50
+ route: batch[idx].path,
51
+ error: result.reason instanceof Error ? result.reason.message : String(result.reason)
52
+ });
53
+ }
54
+ }
55
+ }
56
+ if (errors.length > 0) {
57
+ console.warn(`Warning: ${errors.length} route(s) failed AI generation:`);
58
+ for (const err of errors) {
59
+ console.warn(` - ${err.route}: ${err.error}`);
60
+ }
61
+ }
62
+ console.log(`Generated ${results.length} test file(s) in ${options.outputDir}/`);
63
+ return results;
64
+ }
65
+ function routePathToFileName(routePath) {
66
+ if (routePath === "/") return "home.spec.ts";
67
+ return routePath.replace(/^\//, "").replace(/\//g, "-").replace(/\[([^\]]+)\]/g, "$1").replace(/[^a-zA-Z0-9-]/g, "") + ".spec.ts";
68
+ }
69
+
70
+ export {
71
+ generateTests
72
+ };
73
+ //# sourceMappingURL=chunk-623BAIU2.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 { 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,MAAM,gBAAgB;AAEvC,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,WAAW,KAAK,IAAI,IAAI,QAAQ,gBAAgB,WAAW;AACjE,YAAQ,IAAI,uBAAuB,QAAQ,IAAI,WAAW,YAAY;AAEtE,UAAM,eAAe,MAAM,QAAQ;AAAA,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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":[]}
@@ -0,0 +1,157 @@
1
+ // src/browser/page-hooks.ts
2
+ import { join } from "path";
3
+ var ConsoleErrorHook = class {
4
+ name = "console-error";
5
+ findings = [];
6
+ currentViewport = "";
7
+ setup(page, viewport) {
8
+ this.currentViewport = viewport;
9
+ page.on("console", (msg) => {
10
+ if (msg.type() === "error") {
11
+ this.findings.push({
12
+ ruleId: "e2e/console-error",
13
+ severity: "high",
14
+ message: `Console error: ${msg.text()}`,
15
+ filePath: "",
16
+ line: 0,
17
+ column: 0,
18
+ snippet: msg.text(),
19
+ url: msg.location().url || page.url(),
20
+ viewport: this.currentViewport,
21
+ fixSuggestion: "Check browser console for stack trace details."
22
+ });
23
+ }
24
+ });
25
+ page.on("pageerror", (err) => {
26
+ this.findings.push({
27
+ ruleId: "e2e/console-error",
28
+ severity: "high",
29
+ message: `Uncaught exception: ${err.message}`,
30
+ filePath: "",
31
+ line: 0,
32
+ column: 0,
33
+ snippet: err.stack ?? err.message,
34
+ url: page.url(),
35
+ viewport: this.currentViewport,
36
+ fixSuggestion: "Check browser console for stack trace details."
37
+ });
38
+ });
39
+ }
40
+ collect() {
41
+ return [...this.findings];
42
+ }
43
+ reset() {
44
+ this.findings = [];
45
+ }
46
+ };
47
+ var NetworkFailureHook = class {
48
+ name = "network-failure";
49
+ findings = [];
50
+ currentViewport = "";
51
+ setup(page, viewport) {
52
+ this.currentViewport = viewport;
53
+ page.on("response", (res) => {
54
+ const status = res.status();
55
+ if (status >= 400) {
56
+ const severity = status >= 500 ? "high" : "medium";
57
+ this.findings.push({
58
+ ruleId: "e2e/network-failure",
59
+ severity,
60
+ message: `HTTP ${status} for ${res.url()}`,
61
+ filePath: "",
62
+ line: 0,
63
+ column: 0,
64
+ snippet: `${res.request().method()} ${res.url()} -> ${status}`,
65
+ url: res.url(),
66
+ viewport: this.currentViewport,
67
+ fixSuggestion: "Verify the resource URL is correct and the server is responding."
68
+ });
69
+ }
70
+ });
71
+ page.on("requestfailed", (req) => {
72
+ this.findings.push({
73
+ ruleId: "e2e/network-failure",
74
+ severity: "critical",
75
+ message: `Request failed: ${req.url()} (${req.failure()?.errorText ?? "unknown error"})`,
76
+ filePath: "",
77
+ line: 0,
78
+ column: 0,
79
+ snippet: `${req.method()} ${req.url()} -> FAILED: ${req.failure()?.errorText ?? "unknown"}`,
80
+ url: req.url(),
81
+ viewport: this.currentViewport,
82
+ fixSuggestion: "Verify the resource URL is correct and the server is responding."
83
+ });
84
+ });
85
+ }
86
+ collect() {
87
+ return [...this.findings];
88
+ }
89
+ reset() {
90
+ this.findings = [];
91
+ }
92
+ };
93
+ var ScreenshotHook = class {
94
+ name = "screenshot";
95
+ setup(_page, _viewport) {
96
+ }
97
+ collect() {
98
+ return [];
99
+ }
100
+ reset() {
101
+ }
102
+ async captureFailure(page, name, outputDir) {
103
+ const screenshotPath = join(outputDir, `${name}.png`);
104
+ await page.screenshot({ path: screenshotPath, fullPage: false });
105
+ return screenshotPath;
106
+ }
107
+ };
108
+ var PageHookPipeline = class {
109
+ hooks = [];
110
+ screenshotHook = null;
111
+ register(hook) {
112
+ this.hooks.push(hook);
113
+ if (hook instanceof ScreenshotHook) {
114
+ this.screenshotHook = hook;
115
+ }
116
+ }
117
+ setupAll(page, viewport) {
118
+ for (const hook of this.hooks) {
119
+ try {
120
+ hook.setup(page, viewport);
121
+ } catch {
122
+ }
123
+ }
124
+ }
125
+ collectAll() {
126
+ const findings = [];
127
+ for (const hook of this.hooks) {
128
+ try {
129
+ findings.push(...hook.collect());
130
+ } catch {
131
+ }
132
+ }
133
+ return findings;
134
+ }
135
+ resetAll() {
136
+ for (const hook of this.hooks) {
137
+ try {
138
+ hook.reset();
139
+ } catch {
140
+ }
141
+ }
142
+ }
143
+ async captureScreenshot(page, name, outputDir) {
144
+ if (this.screenshotHook) {
145
+ return this.screenshotHook.captureFailure(page, name, outputDir);
146
+ }
147
+ return void 0;
148
+ }
149
+ };
150
+
151
+ export {
152
+ ConsoleErrorHook,
153
+ NetworkFailureHook,
154
+ ScreenshotHook,
155
+ PageHookPipeline
156
+ };
157
+ //# sourceMappingURL=chunk-CBDOJUXB.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 { 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,CAAC;AAAA,UACrC,UAAU;AAAA,UACV,MAAM;AAAA,UACN,QAAQ;AAAA,UACR,SAAS,IAAI,KAAK;AAAA,UAClB,KAAK,IAAI,SAAS,EAAE,OAAO,KAAK,IAAI;AAAA,UACpC,UAAU,KAAK;AAAA,UACf,eAAe;AAAA,QACjB,CAAC;AAAA,MACH;AAAA,IACF,CAAC;AAED,SAAK,GAAG,aAAa,CAAC,QAAe;AACnC,WAAK,SAAS,KAAK;AAAA,QACjB,QAAQ;AAAA,QACR,UAAU;AAAA,QACV,SAAS,uBAAuB,IAAI,OAAO;AAAA,QAC3C,UAAU;AAAA,QACV,MAAM;AAAA,QACN,QAAQ;AAAA,QACR,SAAS,IAAI,SAAS,IAAI;AAAA,QAC1B,KAAK,KAAK,IAAI;AAAA,QACd,UA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EACF;AAAA,EAEA,MAAM,kBAAkB,MAAY,MAAc,WAAgD;AAChG,QAAI,KAAK,gBAAgB;AACvB,aAAO,KAAK,eAAe,eAAe,MAAM,MAAM,SAAS;AAAA,IACjE;AACA,WAAO;AAAA,EACT;AACF;","names":[]}
@@ -0,0 +1,14 @@
1
+ // src/core/errors.ts
2
+ var SniffError = class extends Error {
3
+ code;
4
+ constructor(code, message) {
5
+ super(message);
6
+ this.name = "SniffError";
7
+ this.code = code;
8
+ }
9
+ };
10
+
11
+ export {
12
+ SniffError
13
+ };
14
+ //# sourceMappingURL=chunk-IXDUD2UG.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/core/errors.ts"],"sourcesContent":["export class SniffError extends Error {\n readonly code: string;\n\n constructor(code: string, message: string) {\n super(message);\n this.name = 'SniffError';\n this.code = code;\n }\n}\n"],"mappings":";AAAO,IAAM,aAAN,cAAyB,MAAM;AAAA,EAC3B;AAAA,EAET,YAAY,MAAc,SAAiB;AACzC,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,OAAO;AAAA,EACd;AACF;","names":[]}
@@ -0,0 +1,52 @@
1
+ // src/exploration/edge-cases.ts
2
+ var EDGE_CASE_PAYLOADS = {
3
+ xss: [
4
+ "<script>alert(1)</script>",
5
+ '"><img src=x onerror=alert(1)>',
6
+ "javascript:alert(1)",
7
+ "<svg/onload=alert(1)>",
8
+ "<img src=x onerror=prompt(1)>"
9
+ ],
10
+ sqli: [
11
+ "' OR '1'='1",
12
+ "1; DROP TABLE users--",
13
+ "' UNION SELECT NULL--",
14
+ '" OR 1=1--'
15
+ ],
16
+ unicode: [
17
+ "\0",
18
+ "\uFFFD",
19
+ "\u{1F4A9}",
20
+ "\u202E",
21
+ "\u200B"
22
+ ],
23
+ boundary: [
24
+ "",
25
+ " ",
26
+ "a".repeat(1e4),
27
+ "-1",
28
+ "0",
29
+ "999999999999999",
30
+ "1.7976931348623157e+308"
31
+ ],
32
+ specialChars: [
33
+ "../../../etc/passwd",
34
+ "%00",
35
+ "\r\n",
36
+ "${7*7}",
37
+ "{{7*7}}"
38
+ ]
39
+ };
40
+ function selectPayload(inputType, stepIndex) {
41
+ const categories = Object.keys(EDGE_CASE_PAYLOADS);
42
+ const categoryIndex = stepIndex % categories.length;
43
+ const category = categories[categoryIndex];
44
+ const payloads = EDGE_CASE_PAYLOADS[category];
45
+ const payloadIndex = Math.floor(stepIndex / categories.length) % payloads.length;
46
+ return { value: payloads[payloadIndex], category };
47
+ }
48
+
49
+ export {
50
+ selectPayload
51
+ };
52
+ //# sourceMappingURL=chunk-MMISGY2Q.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/exploration/edge-cases.ts"],"sourcesContent":["export const EDGE_CASE_PAYLOADS = {\n xss: [\n '<script>alert(1)</script>',\n '\"><img src=x onerror=alert(1)>',\n 'javascript:alert(1)',\n '<svg/onload=alert(1)>',\n '<img src=x onerror=prompt(1)>',\n ],\n sqli: [\n \"' OR '1'='1\",\n '1; DROP TABLE users--',\n \"' UNION SELECT NULL--\",\n '\" OR 1=1--',\n ],\n unicode: [\n '\\u0000',\n '\\uFFFD',\n '\\u{1F4A9}',\n '\\u202E',\n '\\u200B',\n ],\n boundary: [\n '',\n ' ',\n 'a'.repeat(10000),\n '-1',\n '0',\n '999999999999999',\n '1.7976931348623157e+308',\n ],\n specialChars: [\n '../../../etc/passwd',\n '%00',\n '\\r\\n',\n '${7*7}',\n '{{7*7}}',\n ],\n} as const;\n\nexport type PayloadCategory = keyof typeof EDGE_CASE_PAYLOADS;\n\n/** Select a payload for a given input type. Uses category rotation for coverage. */\nexport function selectPayload(inputType: string, stepIndex: number): { value: string; category: PayloadCategory } {\n const categories = Object.keys(EDGE_CASE_PAYLOADS) as PayloadCategory[];\n // Rotate through categories based on step index for breadth\n const categoryIndex = stepIndex % categories.length;\n const category = categories[categoryIndex];\n const payloads = EDGE_CASE_PAYLOADS[category];\n const payloadIndex = Math.floor(stepIndex / categories.length) % payloads.length;\n return { value: payloads[payloadIndex], category };\n}\n"],"mappings":";AAAO,IAAM,qBAAqB;AAAA,EAChC,KAAK;AAAA,IACH;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAAA,EACA,MAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAAA,EACA,SAAS;AAAA,IACP;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAAA,EACA,UAAU;AAAA,IACR;AAAA,IACA;AAAA,IACA,IAAI,OAAO,GAAK;AAAA,IAChB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAAA,EACA,cAAc;AAAA,IACZ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;AAKO,SAAS,cAAc,WAAmB,WAAiE;AAChH,QAAM,aAAa,OAAO,KAAK,kBAAkB;AAEjD,QAAM,gBAAgB,YAAY,WAAW;AAC7C,QAAM,WAAW,WAAW,aAAa;AACzC,QAAM,WAAW,mBAAmB,QAAQ;AAC5C,QAAM,eAAe,KAAK,MAAM,YAAY,WAAW,MAAM,IAAI,SAAS;AAC1E,SAAO,EAAE,OAAO,SAAS,YAAY,GAAG,SAAS;AACnD;","names":[]}
@@ -0,0 +1,49 @@
1
+ // src/core/flakiness.ts
2
+ function buildTestId(scanner, finding) {
3
+ const isBrowser = "url" in finding && typeof finding.url === "string";
4
+ const location = isBrowser ? finding.url : finding.filePath;
5
+ return `${scanner}::${finding.ruleId}::${location}`;
6
+ }
7
+ function buildTestRunRecords(results, runId) {
8
+ const timestamp = (/* @__PURE__ */ new Date()).toISOString();
9
+ const records = [];
10
+ for (const result of results) {
11
+ for (const finding of result.findings) {
12
+ const testId = buildTestId(result.scanner, finding);
13
+ const isBrowser = "url" in finding && typeof finding.url === "string";
14
+ const record = {
15
+ runId,
16
+ timestamp,
17
+ testId,
18
+ passed: false,
19
+ duration: result.duration
20
+ };
21
+ if (isBrowser && "viewport" in finding) {
22
+ record.viewport = finding.viewport;
23
+ }
24
+ records.push(record);
25
+ }
26
+ }
27
+ return records;
28
+ }
29
+ function computeFlakeStatus(history, testId, windowSize = 5, threshold = 3) {
30
+ const testRuns = history.runs.filter((r) => r.testId === testId);
31
+ const window = testRuns.slice(-windowSize);
32
+ const runCount = window.length;
33
+ if (runCount < windowSize) {
34
+ return { isFlaky: false, failureCount: 0, runCount };
35
+ }
36
+ const failureCount = window.filter((r) => !r.passed).length;
37
+ return {
38
+ isFlaky: failureCount >= threshold,
39
+ failureCount,
40
+ runCount
41
+ };
42
+ }
43
+
44
+ export {
45
+ buildTestId,
46
+ buildTestRunRecords,
47
+ computeFlakeStatus
48
+ };
49
+ //# sourceMappingURL=chunk-ZM6MGWO4.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/core/flakiness.ts"],"sourcesContent":["import type { Finding, BrowserFinding, FlakinessHistory, TestRunRecord } from './types.js';\nimport type { ScanResult } from '../scanners/types.js';\n\n/**\n * Build a deterministic test ID from a scanner name and finding.\n * Format: \"${scanner}::${ruleId}::${url}\" for browser findings,\n * \"${scanner}::${ruleId}::${filePath}\" for source findings.\n *\n * Including scanner ensures two different scanners with the same ruleId\n * on the same file do not share a history ID.\n * Does NOT use finding.message (too variable across runs).\n */\nexport function buildTestId(scanner: string, finding: Finding | BrowserFinding): string {\n const isBrowser = 'url' in finding && typeof (finding as BrowserFinding).url === 'string';\n const location = isBrowser ? (finding as BrowserFinding).url : finding.filePath;\n return `${scanner}::${finding.ruleId}::${location}`;\n}\n\n/**\n * Convert scan results into TestRunRecord entries.\n * Each finding becomes a record with passed=false (findings represent failures).\n *\n * Limitation: We have no positive signal for passing tests in the current\n * architecture -- only failures (findings) are recorded. A test that stops\n * appearing in findings is assumed to have passed, but we cannot create\n * explicit pass records without a test manifest.\n */\nexport function buildTestRunRecords(results: ScanResult[], runId: string): TestRunRecord[] {\n const timestamp = new Date().toISOString();\n const records: TestRunRecord[] = [];\n\n for (const result of results) {\n for (const finding of result.findings) {\n const testId = buildTestId(result.scanner, finding);\n const isBrowser = 'url' in finding && typeof (finding as BrowserFinding).url === 'string';\n const record: TestRunRecord = {\n runId,\n timestamp,\n testId,\n passed: false,\n duration: result.duration,\n };\n if (isBrowser && 'viewport' in finding) {\n record.viewport = (finding as BrowserFinding).viewport;\n }\n records.push(record);\n }\n }\n\n return records;\n}\n\n/**\n * Compute whether a test is flaky based on its recent history.\n *\n * Defaults: windowSize=5 (look at last 5 runs), threshold=3 (3+ failures = flaky).\n * If fewer than windowSize records exist, returns isFlaky: false (not enough data).\n * This ensures newly-failing tests always block until sufficient history accumulates (T-04-04).\n */\nexport function computeFlakeStatus(\n history: FlakinessHistory,\n testId: string,\n windowSize = 5,\n threshold = 3,\n): { isFlaky: boolean; failureCount: number; runCount: number } {\n const testRuns = history.runs.filter((r) => r.testId === testId);\n const window = testRuns.slice(-windowSize);\n const runCount = window.length;\n\n if (runCount < windowSize) {\n return { isFlaky: false, failureCount: 0, runCount };\n }\n\n const failureCount = window.filter((r) => !r.passed).length;\n return {\n isFlaky: failureCount >= threshold,\n failureCount,\n runCount,\n };\n}\n"],"mappings":";AAYO,SAAS,YAAY,SAAiB,SAA2C;AACtF,QAAM,YAAY,SAAS,WAAW,OAAQ,QAA2B,QAAQ;AACjF,QAAM,WAAW,YAAa,QAA2B,MAAM,QAAQ;AACvE,SAAO,GAAG,OAAO,KAAK,QAAQ,MAAM,KAAK,QAAQ;AACnD;AAWO,SAAS,oBAAoB,SAAuB,OAAgC;AACzF,QAAM,aAAY,oBAAI,KAAK,GAAE,YAAY;AACzC,QAAM,UAA2B,CAAC;AAElC,aAAW,UAAU,SAAS;AAC5B,eAAW,WAAW,OAAO,UAAU;AACrC,YAAM,SAAS,YAAY,OAAO,SAAS,OAAO;AAClD,YAAM,YAAY,SAAS,WAAW,OAAQ,QAA2B,QAAQ;AACjF,YAAM,SAAwB;AAAA,QAC5B;AAAA,QACA;AAAA,QACA;AAAA,QACA,QAAQ;AAAA,QACR,UAAU,OAAO;AAAA,MACnB;AACA,UAAI,aAAa,cAAc,SAAS;AACtC,eAAO,WAAY,QAA2B;AAAA,MAChD;AACA,cAAQ,KAAK,MAAM;AAAA,IACrB;AAAA,EACF;AAEA,SAAO;AACT;AASO,SAAS,mBACd,SACA,QACA,aAAa,GACb,YAAY,GACkD;AAC9D,QAAM,WAAW,QAAQ,KAAK,OAAO,CAAC,MAAM,EAAE,WAAW,MAAM;AAC/D,QAAM,SAAS,SAAS,MAAM,CAAC,UAAU;AACzC,QAAM,WAAW,OAAO;AAExB,MAAI,WAAW,YAAY;AACzB,WAAO,EAAE,SAAS,OAAO,cAAc,GAAG,SAAS;AAAA,EACrD;AAEA,QAAM,eAAe,OAAO,OAAO,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE;AACrD,SAAO;AAAA,IACL,SAAS,gBAAgB;AAAA,IACzB;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
@@ -0,0 +1,52 @@
1
+ // src/cli/commands/ci.ts
2
+ async function ciCommand(options) {
3
+ const pc = (await import("picocolors")).default;
4
+ const { existsSync } = await import("fs");
5
+ const { mkdir, writeFile } = await import("fs/promises");
6
+ const { join, dirname } = await import("path");
7
+ const { generateGitHubActionsWorkflow, detectPackageManager } = await import("./workflow-template-3KFPCVIC.js");
8
+ const outputPath = options.output ?? ".github/workflows/sniff.yml";
9
+ if (!outputPath.endsWith(".yml") && !outputPath.endsWith(".yaml")) {
10
+ console.error(pc.red("Output path must end with .yml or .yaml"));
11
+ process.exit(1);
12
+ }
13
+ const fullPath = join(process.cwd(), outputPath);
14
+ if (!fullPath.startsWith(process.cwd() + "/") && fullPath !== process.cwd()) {
15
+ console.error(pc.red("Output path must be within the project directory"));
16
+ process.exit(1);
17
+ }
18
+ if (existsSync(fullPath) && !options.force) {
19
+ console.error(pc.yellow(`Workflow already exists at ${outputPath}. Use --force to overwrite.`));
20
+ process.exit(1);
21
+ }
22
+ const packageManager = await detectPackageManager(process.cwd());
23
+ const packageName = options.packageName ?? "sniff-qa";
24
+ const yaml = generateGitHubActionsWorkflow({
25
+ packageName,
26
+ nodeVersion: "22",
27
+ branches: ["main", "master"],
28
+ timeoutMinutes: 15,
29
+ retentionDays: 30,
30
+ packageManager
31
+ });
32
+ await mkdir(dirname(fullPath), { recursive: true });
33
+ await writeFile(fullPath, yaml, "utf-8");
34
+ console.log(`
35
+ ${pc.green("Created")} ${outputPath}
36
+ `);
37
+ console.log(` Package manager: ${packageManager}`);
38
+ console.log(` Package name: ${packageName}`);
39
+ console.log(` Triggers: push + PR to main/master`);
40
+ console.log(` Caches: Playwright browsers + node_modules`);
41
+ console.log(`
42
+ ${pc.dim("The workflow runs")} ${pc.bold("npx " + packageName + " run --ci")} ${pc.dim("which enables:")}`);
43
+ console.log(` ${pc.dim("- Headless browser mode")}`);
44
+ console.log(` ${pc.dim("- JUnit XML output")}`);
45
+ console.log(` ${pc.dim("- Flakiness tracking + quarantine")}`);
46
+ console.log(` ${pc.dim("- Non-zero exit on failure")}
47
+ `);
48
+ }
49
+ export {
50
+ ciCommand
51
+ };
52
+ //# sourceMappingURL=ci-2MVD2ISE.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/cli/commands/ci.ts"],"sourcesContent":["export async function ciCommand(options: {\n output?: string;\n force?: boolean;\n packageName?: string;\n}): Promise<void> {\n const pc = (await import('picocolors')).default;\n const { existsSync } = await import('node:fs');\n const { mkdir, writeFile } = await import('node:fs/promises');\n const { join, dirname } = await import('node:path');\n const { generateGitHubActionsWorkflow, detectPackageManager } = await import('../../ci/workflow-template.js');\n\n const outputPath = options.output ?? '.github/workflows/sniff.yml';\n\n // Validate output path ends with .yml or .yaml (T-04-10 mitigation)\n if (!outputPath.endsWith('.yml') && !outputPath.endsWith('.yaml')) {\n console.error(pc.red('Output path must end with .yml or .yaml'));\n process.exit(1);\n }\n\n // Prevent path traversal outside project directory (T-04-10 mitigation)\n const fullPath = join(process.cwd(), outputPath);\n if (!fullPath.startsWith(process.cwd() + '/') && fullPath !== process.cwd()) {\n console.error(pc.red('Output path must be within the project directory'));\n process.exit(1);\n }\n\n // Check for existing file\n if (existsSync(fullPath) && !options.force) {\n console.error(pc.yellow(`Workflow already exists at ${outputPath}. Use --force to overwrite.`));\n process.exit(1);\n }\n\n const packageManager = await detectPackageManager(process.cwd());\n const packageName = options.packageName ?? 'sniff-qa';\n\n const yaml = generateGitHubActionsWorkflow({\n packageName,\n nodeVersion: '22',\n branches: ['main', 'master'],\n timeoutMinutes: 15,\n retentionDays: 30,\n packageManager,\n });\n\n await mkdir(dirname(fullPath), { recursive: true });\n await writeFile(fullPath, yaml, 'utf-8');\n\n console.log(`\\n${pc.green('Created')} ${outputPath}\\n`);\n console.log(` Package manager: ${packageManager}`);\n console.log(` Package name: ${packageName}`);\n console.log(` Triggers: push + PR to main/master`);\n console.log(` Caches: Playwright browsers + node_modules`);\n console.log(`\\n${pc.dim('The workflow runs')} ${pc.bold('npx ' + packageName + ' run --ci')} ${pc.dim('which enables:')}`);\n console.log(` ${pc.dim('- Headless browser mode')}`);\n console.log(` ${pc.dim('- JUnit XML output')}`);\n console.log(` ${pc.dim('- Flakiness tracking + quarantine')}`);\n console.log(` ${pc.dim('- Non-zero exit on failure')}\\n`);\n}\n"],"mappings":";AAAA,eAAsB,UAAU,SAId;AAChB,QAAM,MAAM,MAAM,OAAO,YAAY,GAAG;AACxC,QAAM,EAAE,WAAW,IAAI,MAAM,OAAO,IAAS;AAC7C,QAAM,EAAE,OAAO,UAAU,IAAI,MAAM,OAAO,aAAkB;AAC5D,QAAM,EAAE,MAAM,QAAQ,IAAI,MAAM,OAAO,MAAW;AAClD,QAAM,EAAE,+BAA+B,qBAAqB,IAAI,MAAM,OAAO,iCAA+B;AAE5G,QAAM,aAAa,QAAQ,UAAU;AAGrC,MAAI,CAAC,WAAW,SAAS,MAAM,KAAK,CAAC,WAAW,SAAS,OAAO,GAAG;AACjE,YAAQ,MAAM,GAAG,IAAI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AAC,EAAE;AAC/C,UAAQ,IAAI,KAAK,GAAG,IAAI,mCAAmC,CAAC,EAAE;AAC9D,UAAQ,IAAI,KAAK,GAAG,IAAI,4BAA4B,CAAC;AAAA,CAAI;AAC3D;","names":[]}
@@ -0,0 +1,42 @@
1
+ // src/ai/claude-code.ts
2
+ import { execFile as execFileCb } from "child_process";
3
+ import { promisify } from "util";
4
+ var execFile = promisify(execFileCb);
5
+ var ClaudeCodeProvider = class {
6
+ name = "claude-code";
7
+ async generateTests(context) {
8
+ const { buildSystemPrompt, buildUserPrompt } = await import("./prompt-builder-D3FBH534.js");
9
+ const { parseGeneratedTest } = await import("./response-parser-PUGNWF7S.js");
10
+ const systemPrompt = buildSystemPrompt();
11
+ const userPrompt = buildUserPrompt(context);
12
+ try {
13
+ const { stdout } = await execFile("claude", [
14
+ "--print",
15
+ "--output-format",
16
+ "json",
17
+ "--system-prompt",
18
+ systemPrompt,
19
+ userPrompt
20
+ ], {
21
+ timeout: 12e4,
22
+ // 2 minute timeout per route
23
+ maxBuffer: 1024 * 1024 * 5
24
+ // 5MB buffer
25
+ });
26
+ const response = JSON.parse(stdout);
27
+ const rawContent = response.result ?? stdout;
28
+ return parseGeneratedTest(rawContent, context.route.path);
29
+ } catch (err) {
30
+ if (err instanceof Error && "code" in err && err.code === "ENOENT") {
31
+ const { SniffError: SniffError2 } = await import("./errors-RFEOR527.js");
32
+ throw new SniffError2("CLAUDE_CLI_NOT_FOUND", "Claude Code CLI not found. Install it from https://claude.ai/download or set ANTHROPIC_API_KEY for API mode.");
33
+ }
34
+ const { SniffError } = await import("./errors-RFEOR527.js");
35
+ throw new SniffError("CLAUDE_CLI_ERROR", `Claude Code CLI failed: ${err instanceof Error ? err.message : String(err)}`);
36
+ }
37
+ }
38
+ };
39
+ export {
40
+ ClaudeCodeProvider
41
+ };
42
+ //# sourceMappingURL=claude-code-F722EIIC.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/ai/claude-code.ts"],"sourcesContent":["import { execFile as execFileCb } from 'node:child_process';\nimport { promisify } from 'node:util';\nimport type { AIProvider, RouteTestContext, GeneratedTest } from './types.js';\n\nconst execFile = promisify(execFileCb);\n\nexport class ClaudeCodeProvider implements AIProvider {\n name = 'claude-code';\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\n const systemPrompt = buildSystemPrompt();\n const userPrompt = buildUserPrompt(context);\n\n try {\n const { stdout } = await execFile('claude', [\n '--print',\n '--output-format', 'json',\n '--system-prompt', systemPrompt,\n userPrompt,\n ], {\n timeout: 120_000, // 2 minute timeout per route\n maxBuffer: 1024 * 1024 * 5, // 5MB buffer\n });\n\n // Parse Claude Code JSON response: {\"type\":\"result\",\"subtype\":\"success\",\"result\":\"...\"}\n const response = JSON.parse(stdout);\n const rawContent = response.result ?? stdout;\n\n return parseGeneratedTest(rawContent, context.route.path);\n } catch (err) {\n if (err instanceof Error && 'code' in err && (err as NodeJS.ErrnoException).code === 'ENOENT') {\n const { SniffError } = await import('../core/errors.js');\n throw new SniffError('CLAUDE_CLI_NOT_FOUND', 'Claude Code CLI not found. Install it from https://claude.ai/download or set ANTHROPIC_API_KEY for API mode.');\n }\n const { SniffError } = await import('../core/errors.js');\n throw new SniffError('CLAUDE_CLI_ERROR', `Claude Code CLI failed: ${err instanceof Error ? err.message : String(err)}`);\n }\n }\n}\n"],"mappings":";AAAA,SAAS,YAAY,kBAAkB;AACvC,SAAS,iBAAiB;AAG1B,IAAM,WAAW,UAAU,UAAU;AAE9B,IAAM,qBAAN,MAA+C;AAAA,EACpD,OAAO;AAAA,EAEP,MAAM,cAAc,SAAmD;AACrE,UAAM,EAAE,mBAAmB,gBAAgB,IAAI,MAAM,OAAO,8BAAqB;AACjF,UAAM,EAAE,mBAAmB,IAAI,MAAM,OAAO,+BAAsB;AAElE,UAAM,eAAe,kBAAkB;AACvC,UAAM,aAAa,gBAAgB,OAAO;AAE1C,QAAI;AACF,YAAM,EAAE,OAAO,IAAI,MAAM,SAAS,UAAU;AAAA,QAC1C;AAAA,QACA;AAAA,QAAmB;AAAA,QACnB;AAAA,QAAmB;AAAA,QACnB;AAAA,MACF,GAAG;AAAA,QACD,SAAS;AAAA;AAAA,QACT,WAAW,OAAO,OAAO;AAAA;AAAA,MAC3B,CAAC;AAGD,YAAM,WAAW,KAAK,MAAM,MAAM;AAClC,YAAM,aAAa,SAAS,UAAU;AAEtC,aAAO,mBAAmB,YAAY,QAAQ,MAAM,IAAI;AAAA,IAC1D,SAAS,KAAK;AACZ,UAAI,eAAe,SAAS,UAAU,OAAQ,IAA8B,SAAS,UAAU;AAC7F,cAAM,EAAE,YAAAA,YAAW,IAAI,MAAM,OAAO,sBAAmB;AACvD,cAAM,IAAIA,YAAW,wBAAwB,8GAA8G;AAAA,MAC7J;AACA,YAAM,EAAE,WAAW,IAAI,MAAM,OAAO,sBAAmB;AACvD,YAAM,IAAI,WAAW,oBAAoB,2BAA2B,eAAe,QAAQ,IAAI,UAAU,OAAO,GAAG,CAAC,EAAE;AAAA,IACxH;AAAA,EACF;AACF;","names":["SniffError"]}