agentic-qe 3.8.5 → 3.8.7

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 (67) hide show
  1. package/.claude/skills/skills-manifest.json +1 -1
  2. package/CHANGELOG.md +26 -0
  3. package/assets/governance/constitution.md +1 -1
  4. package/assets/governance/shards/chaos-resilience.shard.md +1 -1
  5. package/assets/governance/shards/code-intelligence.shard.md +1 -1
  6. package/assets/governance/shards/contract-testing.shard.md +1 -1
  7. package/assets/governance/shards/coverage-analysis.shard.md +1 -1
  8. package/assets/governance/shards/defect-intelligence.shard.md +1 -1
  9. package/assets/governance/shards/learning-optimization.shard.md +1 -1
  10. package/assets/governance/shards/quality-assessment.shard.md +1 -1
  11. package/assets/governance/shards/requirements-validation.shard.md +1 -1
  12. package/assets/governance/shards/security-compliance.shard.md +1 -1
  13. package/assets/governance/shards/test-execution.shard.md +1 -1
  14. package/assets/governance/shards/test-generation.shard.md +1 -1
  15. package/assets/governance/shards/visual-accessibility.shard.md +1 -1
  16. package/dist/cli/bundle.js +715 -643
  17. package/dist/cli/command-registry.js +3 -1
  18. package/dist/cli/completions/index.d.ts +17 -0
  19. package/dist/cli/completions/index.js +49 -1
  20. package/dist/cli/handlers/hypergraph-handler.d.ts +27 -0
  21. package/dist/cli/handlers/hypergraph-handler.js +248 -0
  22. package/dist/cli/handlers/index.d.ts +1 -0
  23. package/dist/cli/handlers/index.js +1 -0
  24. package/dist/coordination/mincut/phase-executor.d.ts +27 -0
  25. package/dist/coordination/mincut/phase-executor.js +70 -0
  26. package/dist/coordination/mincut/time-crystal-analysis.d.ts +35 -0
  27. package/dist/coordination/mincut/time-crystal-analysis.js +237 -0
  28. package/dist/coordination/mincut/time-crystal-persistence.d.ts +35 -0
  29. package/dist/coordination/mincut/time-crystal-persistence.js +81 -0
  30. package/dist/coordination/mincut/time-crystal-scheduling.d.ts +34 -0
  31. package/dist/coordination/mincut/time-crystal-scheduling.js +213 -0
  32. package/dist/coordination/mincut/time-crystal-types.d.ts +278 -0
  33. package/dist/coordination/mincut/time-crystal-types.js +67 -0
  34. package/dist/coordination/mincut/time-crystal.d.ts +8 -438
  35. package/dist/coordination/mincut/time-crystal.js +87 -905
  36. package/dist/coordination/protocols/code-intelligence-index.js +2 -11
  37. package/dist/domains/code-intelligence/coordinator-hypergraph.js +1 -1
  38. package/dist/domains/code-intelligence/coordinator.d.ts +5 -0
  39. package/dist/domains/code-intelligence/coordinator.js +35 -3
  40. package/dist/init/phases/06-code-intelligence.d.ts +8 -3
  41. package/dist/init/phases/06-code-intelligence.js +70 -32
  42. package/dist/learning/agent-routing.d.ts +53 -0
  43. package/dist/learning/agent-routing.js +142 -0
  44. package/dist/learning/embedding-utils.d.ts +34 -0
  45. package/dist/learning/embedding-utils.js +95 -0
  46. package/dist/learning/pattern-promotion.d.ts +63 -0
  47. package/dist/learning/pattern-promotion.js +187 -0
  48. package/dist/learning/pretrained-patterns.d.ts +14 -0
  49. package/dist/learning/pretrained-patterns.js +726 -0
  50. package/dist/learning/qe-reasoning-bank-types.d.ts +174 -0
  51. package/dist/learning/qe-reasoning-bank-types.js +24 -0
  52. package/dist/learning/qe-reasoning-bank.d.ts +9 -192
  53. package/dist/learning/qe-reasoning-bank.js +48 -1093
  54. package/dist/mcp/bundle.js +1084 -1083
  55. package/dist/mcp/handlers/hypergraph-handler.d.ts +27 -0
  56. package/dist/mcp/handlers/hypergraph-handler.js +140 -0
  57. package/dist/mcp/handlers/index.d.ts +1 -0
  58. package/dist/mcp/handlers/index.js +2 -0
  59. package/dist/mcp/server.js +19 -0
  60. package/dist/mcp/tool-scoping.js +5 -0
  61. package/dist/shared/code-index-extractor.d.ts +23 -0
  62. package/dist/shared/code-index-extractor.js +101 -0
  63. package/dist/shared/security/command-validator.js +2 -2
  64. package/dist/shared/security/input-sanitizer.js +1 -1
  65. package/dist/shared/security/path-traversal-validator.js +1 -1
  66. package/dist/shared/security/regex-safety-validator.js +7 -7
  67. package/package.json +1 -1
@@ -0,0 +1,726 @@
1
+ /**
2
+ * Agentic QE v3 - Pretrained Patterns
3
+ * ADR-021: QE ReasoningBank for Pattern Learning
4
+ *
5
+ * Static pretrained pattern definitions that seed the QE ReasoningBank
6
+ * on first initialization when no existing patterns are found.
7
+ */
8
+ // ============================================================================
9
+ // Pretrained Foundational Patterns
10
+ // ============================================================================
11
+ /**
12
+ * Foundational QE patterns loaded on first initialization.
13
+ * These cover all 8+ QE domains with seed patterns.
14
+ */
15
+ export const PRETRAINED_PATTERNS = [
16
+ {
17
+ patternType: 'test-template',
18
+ name: 'AAA Unit Test',
19
+ description: 'Arrange-Act-Assert pattern for clear, maintainable unit tests',
20
+ template: {
21
+ type: 'code',
22
+ content: `describe('{{className}}', () => {
23
+ describe('{{methodName}}', () => {
24
+ it('should {{expectedBehavior}}', {{async}} () => {
25
+ // Arrange
26
+ {{arrangeCode}}
27
+
28
+ // Act
29
+ {{actCode}}
30
+
31
+ // Assert
32
+ {{assertCode}}
33
+ });
34
+ });
35
+ });`,
36
+ variables: [
37
+ { name: 'className', type: 'string', required: true, description: 'Class under test' },
38
+ { name: 'methodName', type: 'string', required: true, description: 'Method under test' },
39
+ { name: 'expectedBehavior', type: 'string', required: true, description: 'Expected behavior in plain English' },
40
+ { name: 'async', type: 'string', required: false, defaultValue: '', description: 'async keyword if needed' },
41
+ { name: 'arrangeCode', type: 'code', required: true, description: 'Setup code' },
42
+ { name: 'actCode', type: 'code', required: true, description: 'Action code' },
43
+ { name: 'assertCode', type: 'code', required: true, description: 'Assertion code' },
44
+ ],
45
+ },
46
+ context: {
47
+ testType: 'unit',
48
+ tags: ['unit-test', 'aaa', 'arrange-act-assert', 'best-practice'],
49
+ },
50
+ },
51
+ {
52
+ patternType: 'mock-pattern',
53
+ name: 'Dependency Mock',
54
+ description: 'Pattern for mocking external dependencies in tests',
55
+ template: {
56
+ type: 'code',
57
+ content: `const mock{{DependencyName}} = {
58
+ {{mockMethods}}
59
+ };
60
+
61
+ vi.mock('{{modulePath}}', () => ({
62
+ {{DependencyName}}: vi.fn(() => mock{{DependencyName}}),
63
+ }));`,
64
+ variables: [
65
+ { name: 'DependencyName', type: 'string', required: true, description: 'Name of dependency to mock' },
66
+ { name: 'modulePath', type: 'string', required: true, description: 'Module path to mock' },
67
+ { name: 'mockMethods', type: 'code', required: true, description: 'Mock method implementations' },
68
+ ],
69
+ },
70
+ context: {
71
+ framework: 'vitest',
72
+ testType: 'unit',
73
+ tags: ['mock', 'vitest', 'dependency-injection'],
74
+ },
75
+ },
76
+ {
77
+ patternType: 'coverage-strategy',
78
+ name: 'Risk-Based Coverage',
79
+ description: 'Prioritize coverage by code risk and complexity',
80
+ template: {
81
+ type: 'prompt',
82
+ content: `Analyze coverage gaps for {{targetPath}} with focus on:
83
+ 1. Critical business logic paths
84
+ 2. Error handling branches
85
+ 3. Edge cases and boundary conditions
86
+ 4. High-complexity functions (cyclomatic complexity > 10)
87
+
88
+ Risk scoring:
89
+ - Critical: Business logic, auth, payments
90
+ - High: Data validation, external integrations
91
+ - Medium: Internal utilities, helpers
92
+ - Low: Config, constants`,
93
+ variables: [
94
+ { name: 'targetPath', type: 'string', required: true, description: 'Path to analyze' },
95
+ ],
96
+ },
97
+ context: {
98
+ tags: ['coverage', 'risk-based', 'prioritization'],
99
+ },
100
+ },
101
+ {
102
+ patternType: 'flaky-fix',
103
+ name: 'Timing-Based Flakiness',
104
+ description: 'Fix flaky tests caused by timing issues',
105
+ template: {
106
+ type: 'prompt',
107
+ content: `The test {{testName}} is flaky due to timing issues.
108
+
109
+ Common fixes:
110
+ 1. Replace setTimeout with explicit waits
111
+ 2. Use waitFor or waitForCondition
112
+ 3. Mock time-dependent functions
113
+ 4. Increase timeouts for async operations
114
+ 5. Add retry logic with exponential backoff
115
+
116
+ Check for:
117
+ - Race conditions in async code
118
+ - Missing await keywords
119
+ - Shared state between tests
120
+ - External service dependencies`,
121
+ variables: [
122
+ { name: 'testName', type: 'string', required: true, description: 'Name of flaky test' },
123
+ ],
124
+ },
125
+ context: {
126
+ tags: ['flaky', 'timing', 'async', 'stability'],
127
+ },
128
+ },
129
+ // ================================================================
130
+ // quality-assessment domain seeds
131
+ // ================================================================
132
+ {
133
+ patternType: 'assertion-pattern',
134
+ qeDomain: 'quality-assessment',
135
+ name: 'Quality Gate Checklist',
136
+ description: 'Evaluate deployment readiness against quality gate criteria',
137
+ template: {
138
+ type: 'prompt',
139
+ content: `Quality gate evaluation for {{targetModule}}:
140
+
141
+ 1. Test coverage >= {{coverageThreshold}}%
142
+ 2. No critical/high severity bugs open
143
+ 3. All P1 tests passing
144
+ 4. Performance benchmarks within SLA (p95 < {{latencyThresholdMs}}ms)
145
+ 5. Security scan clean (no critical CVEs)
146
+ 6. Code review approved
147
+
148
+ Fail the gate if ANY criterion is unmet. Report which criteria passed/failed.`,
149
+ variables: [
150
+ { name: 'targetModule', type: 'string', required: true, description: 'Module or service to evaluate' },
151
+ { name: 'coverageThreshold', type: 'number', required: false, defaultValue: 80, description: 'Minimum coverage %' },
152
+ { name: 'latencyThresholdMs', type: 'number', required: false, defaultValue: 500, description: 'P95 latency limit in ms' },
153
+ ],
154
+ },
155
+ context: {
156
+ tags: ['quality-gate', 'deployment', 'readiness', 'sla'],
157
+ },
158
+ confidence: 0.6,
159
+ },
160
+ {
161
+ patternType: 'assertion-pattern',
162
+ qeDomain: 'quality-assessment',
163
+ name: 'Metric Threshold Validator',
164
+ description: 'Validate quality metrics against configurable thresholds',
165
+ template: {
166
+ type: 'code',
167
+ content: `function validateMetrics(metrics: Record<string, number>, thresholds: Record<string, { min?: number; max?: number }>) {
168
+ const violations: string[] = [];
169
+ for (const [metric, value] of Object.entries(metrics)) {
170
+ const threshold = thresholds[metric];
171
+ if (!threshold) continue;
172
+ if (threshold.min !== undefined && value < threshold.min) {
173
+ violations.push(\`\${metric}: \${value} < min \${threshold.min}\`);
174
+ }
175
+ if (threshold.max !== undefined && value > threshold.max) {
176
+ violations.push(\`\${metric}: \${value} > max \${threshold.max}\`);
177
+ }
178
+ }
179
+ return { pass: violations.length === 0, violations };
180
+ }`,
181
+ variables: [],
182
+ },
183
+ context: {
184
+ tags: ['metrics', 'threshold', 'validation', 'scoring'],
185
+ },
186
+ confidence: 0.6,
187
+ },
188
+ // ================================================================
189
+ // defect-intelligence domain seeds
190
+ // ================================================================
191
+ {
192
+ patternType: 'error-handling',
193
+ qeDomain: 'defect-intelligence',
194
+ name: 'Root Cause Analysis Workflow',
195
+ description: 'Systematic root cause analysis for test failures and production incidents',
196
+ template: {
197
+ type: 'prompt',
198
+ content: `Root cause analysis for: {{incidentDescription}}
199
+
200
+ 1. **Reproduce**: Confirm the failure is deterministic
201
+ 2. **Isolate**: Narrow down to the smallest failing component
202
+ 3. **Timeline**: When did it last pass? What changed since?
203
+ 4. **Categorize**: Is it a code bug, config issue, data issue, or environment?
204
+ 5. **Five Whys**: Ask why at least 5 times to reach the root cause
205
+ 6. **Fix**: Propose fix with test to prevent regression
206
+ 7. **Verify**: Run the fix and confirm the original failure is resolved`,
207
+ variables: [
208
+ { name: 'incidentDescription', type: 'string', required: true, description: 'Description of the failure or incident' },
209
+ ],
210
+ },
211
+ context: {
212
+ tags: ['root-cause', 'rca', 'debugging', 'incident'],
213
+ },
214
+ confidence: 0.6,
215
+ },
216
+ {
217
+ patternType: 'error-handling',
218
+ qeDomain: 'defect-intelligence',
219
+ name: 'Regression Risk Scorer',
220
+ description: 'Score change risk for regression based on code complexity and history',
221
+ template: {
222
+ type: 'prompt',
223
+ content: `Regression risk assessment for {{changePath}}:
224
+
225
+ Risk factors (score each 0-3):
226
+ - Lines changed: {{linesChanged}} → complexity risk
227
+ - Files affected: {{filesAffected}} → blast radius
228
+ - Previous bugs in area: historical defect density
229
+ - Test coverage of changed code: gap risk
230
+ - Dependency depth: cascade risk
231
+
232
+ Total risk = sum / 15 → Low (<0.3), Medium (0.3-0.6), High (>0.6)`,
233
+ variables: [
234
+ { name: 'changePath', type: 'string', required: true, description: 'File or module changed' },
235
+ { name: 'linesChanged', type: 'number', required: true, description: 'Number of lines changed' },
236
+ { name: 'filesAffected', type: 'number', required: true, description: 'Number of files affected' },
237
+ ],
238
+ },
239
+ context: {
240
+ tags: ['regression', 'risk', 'prediction', 'change-analysis'],
241
+ },
242
+ confidence: 0.6,
243
+ },
244
+ // ================================================================
245
+ // requirements-validation domain seeds
246
+ // ================================================================
247
+ {
248
+ patternType: 'test-template',
249
+ qeDomain: 'requirements-validation',
250
+ name: 'Gherkin BDD Scenario',
251
+ description: 'Behavior-driven development scenario in Given/When/Then format',
252
+ template: {
253
+ type: 'code',
254
+ content: `Feature: {{featureName}}
255
+
256
+ Scenario: {{scenarioDescription}}
257
+ Given {{precondition}}
258
+ When {{action}}
259
+ Then {{expectedOutcome}}
260
+
261
+ Scenario: {{scenarioDescription}} - error case
262
+ Given {{precondition}}
263
+ When {{errorAction}}
264
+ Then {{errorOutcome}}`,
265
+ variables: [
266
+ { name: 'featureName', type: 'string', required: true, description: 'Feature under test' },
267
+ { name: 'scenarioDescription', type: 'string', required: true, description: 'What the scenario validates' },
268
+ { name: 'precondition', type: 'string', required: true, description: 'Given precondition' },
269
+ { name: 'action', type: 'string', required: true, description: 'When action' },
270
+ { name: 'expectedOutcome', type: 'string', required: true, description: 'Then expected result' },
271
+ { name: 'errorAction', type: 'string', required: true, description: 'When error action' },
272
+ { name: 'errorOutcome', type: 'string', required: true, description: 'Then error result' },
273
+ ],
274
+ },
275
+ context: {
276
+ tags: ['bdd', 'gherkin', 'requirements', 'acceptance'],
277
+ },
278
+ confidence: 0.6,
279
+ },
280
+ {
281
+ patternType: 'test-template',
282
+ qeDomain: 'requirements-validation',
283
+ name: 'Acceptance Criteria Testability Check',
284
+ description: 'Evaluate whether acceptance criteria are testable and complete',
285
+ template: {
286
+ type: 'prompt',
287
+ content: `Testability assessment for: {{requirementId}} - {{requirementTitle}}
288
+
289
+ Acceptance criteria:
290
+ {{acceptanceCriteria}}
291
+
292
+ Evaluate each criterion:
293
+ 1. **Observable**: Can we verify the outcome without internal knowledge?
294
+ 2. **Measurable**: Is there a quantifiable threshold or clear pass/fail?
295
+ 3. **Atomic**: Does each criterion test exactly one thing?
296
+ 4. **Achievable**: Can this be tested with available tools?
297
+ 5. **Complete**: Are edge cases and error paths covered?
298
+
299
+ Flag any untestable or ambiguous criteria with suggested rewrites.`,
300
+ variables: [
301
+ { name: 'requirementId', type: 'string', required: true, description: 'Requirement identifier' },
302
+ { name: 'requirementTitle', type: 'string', required: true, description: 'Requirement title' },
303
+ { name: 'acceptanceCriteria', type: 'string', required: true, description: 'The acceptance criteria text' },
304
+ ],
305
+ },
306
+ context: {
307
+ tags: ['requirements', 'testability', 'acceptance-criteria', 'validation'],
308
+ },
309
+ confidence: 0.6,
310
+ },
311
+ // ================================================================
312
+ // code-intelligence domain seeds
313
+ // ================================================================
314
+ {
315
+ patternType: 'refactor-safe',
316
+ name: 'Safe Refactoring Checklist',
317
+ description: 'Ensure refactoring preserves behavior with systematic safety checks',
318
+ template: {
319
+ type: 'prompt',
320
+ content: `Safe refactoring checklist for {{targetPath}}:
321
+
322
+ Before refactoring:
323
+ 1. Run existing tests — capture baseline results
324
+ 2. Check coverage of code being refactored
325
+ 3. Identify all callers and dependents via references
326
+
327
+ During refactoring:
328
+ 4. Make one semantic change at a time
329
+ 5. Keep public API signatures stable (or update all callers)
330
+ 6. Preserve error handling contracts
331
+
332
+ After refactoring:
333
+ 7. Run full test suite — compare to baseline
334
+ 8. Check for any new uncovered paths
335
+ 9. Verify no unused imports or dead code introduced`,
336
+ variables: [
337
+ { name: 'targetPath', type: 'string', required: true, description: 'Path to refactor' },
338
+ ],
339
+ },
340
+ context: {
341
+ tags: ['refactor', 'safety', 'code-change', 'impact'],
342
+ },
343
+ confidence: 0.6,
344
+ },
345
+ {
346
+ patternType: 'refactor-safe',
347
+ name: 'Dependency Impact Analysis',
348
+ description: 'Analyze the blast radius of a code change through the dependency graph',
349
+ template: {
350
+ type: 'prompt',
351
+ content: `Impact analysis for changes in {{changedFile}}:
352
+
353
+ 1. Direct dependents: files that import/require {{changedFile}}
354
+ 2. Transitive dependents: files that depend on direct dependents
355
+ 3. Test coverage: which tests exercise the changed code?
356
+ 4. Integration points: does this affect API contracts or events?
357
+ 5. Risk tier: Critical (auth/payments) > High (business logic) > Medium (utils)
358
+
359
+ Output: sorted list of affected files with risk scores.`,
360
+ variables: [
361
+ { name: 'changedFile', type: 'string', required: true, description: 'File being changed' },
362
+ ],
363
+ },
364
+ context: {
365
+ tags: ['impact', 'dependency', 'blast-radius', 'analysis'],
366
+ },
367
+ confidence: 0.6,
368
+ },
369
+ // ================================================================
370
+ // security-compliance domain seeds
371
+ // ================================================================
372
+ {
373
+ patternType: 'assertion-pattern',
374
+ qeDomain: 'security-compliance',
375
+ name: 'OWASP Top 10 Security Audit',
376
+ description: 'Check code against OWASP Top 10 vulnerability categories',
377
+ template: {
378
+ type: 'prompt',
379
+ content: `Security audit for {{targetPath}} against OWASP Top 10:
380
+
381
+ 1. **A01 Broken Access Control**: Check authorization on every endpoint
382
+ 2. **A02 Cryptographic Failures**: No plaintext secrets, proper hashing
383
+ 3. **A03 Injection**: Parameterized queries, input sanitization
384
+ 4. **A04 Insecure Design**: Threat modeling, least privilege
385
+ 5. **A05 Security Misconfiguration**: Default creds, verbose errors
386
+ 6. **A06 Vulnerable Components**: Check dependencies for CVEs
387
+ 7. **A07 Auth Failures**: Brute force protection, session management
388
+ 8. **A08 Data Integrity Failures**: Verify signatures, safe deserialization
389
+ 9. **A09 Logging Failures**: Audit trail, no sensitive data in logs
390
+ 10. **A10 SSRF**: Validate/allowlist outbound URLs
391
+
392
+ Flag findings as Critical/High/Medium/Low with remediation guidance.`,
393
+ variables: [
394
+ { name: 'targetPath', type: 'string', required: true, description: 'Code path to audit' },
395
+ ],
396
+ },
397
+ context: {
398
+ tags: ['owasp', 'security', 'audit', 'vulnerability'],
399
+ },
400
+ confidence: 0.6,
401
+ },
402
+ {
403
+ patternType: 'assertion-pattern',
404
+ qeDomain: 'security-compliance',
405
+ name: 'Input Sanitization Pattern',
406
+ description: 'Validate and sanitize inputs at system boundaries to prevent injection',
407
+ template: {
408
+ type: 'code',
409
+ content: `// Input validation at system boundary
410
+ function validateInput(input: unknown, schema: {
411
+ type: 'string' | 'number' | 'boolean';
412
+ maxLength?: number;
413
+ pattern?: RegExp;
414
+ allowedValues?: unknown[];
415
+ }): { valid: boolean; sanitized: unknown; errors: string[] } {
416
+ const errors: string[] = [];
417
+ if (typeof input !== schema.type) {
418
+ errors.push(\`Expected \${schema.type}, got \${typeof input}\`);
419
+ return { valid: false, sanitized: null, errors };
420
+ }
421
+ if (schema.type === 'string') {
422
+ let str = input as string;
423
+ if (schema.maxLength && str.length > schema.maxLength) {
424
+ str = str.slice(0, schema.maxLength);
425
+ errors.push('Input truncated to max length');
426
+ }
427
+ if (schema.pattern && !schema.pattern.test(str)) {
428
+ errors.push('Input does not match expected pattern');
429
+ return { valid: false, sanitized: null, errors };
430
+ }
431
+ return { valid: errors.length === 0, sanitized: str, errors };
432
+ }
433
+ return { valid: true, sanitized: input, errors };
434
+ }`,
435
+ variables: [],
436
+ },
437
+ context: {
438
+ tags: ['security', 'validation', 'sanitization', 'injection-prevention'],
439
+ },
440
+ confidence: 0.6,
441
+ },
442
+ // ================================================================
443
+ // contract-testing domain seeds
444
+ // ================================================================
445
+ {
446
+ patternType: 'api-contract',
447
+ name: 'OpenAPI Contract Validator',
448
+ description: 'Validate API responses against OpenAPI/Swagger schema',
449
+ template: {
450
+ type: 'code',
451
+ content: `describe('{{apiEndpoint}} contract', () => {
452
+ it('should match the OpenAPI schema for {{operationId}}', async () => {
453
+ const response = await request(app).{{httpMethod}}('{{apiEndpoint}}');
454
+ expect(response.status).toBe({{expectedStatus}});
455
+ expect(response.body).toMatchSchema(openApiSpec.paths['{{apiEndpoint}}'].{{httpMethod}}.responses['{{expectedStatus}}'].content['application/json'].schema);
456
+ });
457
+
458
+ it('should return proper error for invalid input', async () => {
459
+ const response = await request(app).{{httpMethod}}('{{apiEndpoint}}').send({{invalidPayload}});
460
+ expect(response.status).toBe(400);
461
+ expect(response.body).toHaveProperty('errors');
462
+ });
463
+ });`,
464
+ variables: [
465
+ { name: 'apiEndpoint', type: 'string', required: true, description: 'API endpoint path' },
466
+ { name: 'operationId', type: 'string', required: true, description: 'OpenAPI operation ID' },
467
+ { name: 'httpMethod', type: 'string', required: true, description: 'HTTP method (get/post/put/delete)' },
468
+ { name: 'expectedStatus', type: 'number', required: true, description: 'Expected HTTP status code' },
469
+ { name: 'invalidPayload', type: 'object', required: true, description: 'Invalid request body for error case' },
470
+ ],
471
+ },
472
+ context: {
473
+ tags: ['api', 'contract', 'openapi', 'schema-validation'],
474
+ },
475
+ confidence: 0.6,
476
+ },
477
+ {
478
+ patternType: 'api-contract',
479
+ name: 'Consumer-Driven Contract Test',
480
+ description: 'Pact-style consumer-driven contract testing between services',
481
+ template: {
482
+ type: 'code',
483
+ content: `// Consumer side contract
484
+ const pact = new Pact({
485
+ consumer: '{{consumerName}}',
486
+ provider: '{{providerName}}',
487
+ });
488
+
489
+ describe('{{consumerName}} -> {{providerName}} contract', () => {
490
+ beforeAll(() => pact.setup());
491
+ afterAll(() => pact.finalize());
492
+
493
+ it('should receive {{expectedResource}}', async () => {
494
+ await pact.addInteraction({
495
+ state: '{{providerState}}',
496
+ uponReceiving: '{{interactionDescription}}',
497
+ withRequest: { method: '{{httpMethod}}', path: '{{requestPath}}' },
498
+ willRespondWith: {
499
+ status: 200,
500
+ body: like({{expectedShape}}),
501
+ },
502
+ });
503
+
504
+ const result = await client.{{clientMethod}}();
505
+ expect(result).toBeDefined();
506
+ });
507
+ });`,
508
+ variables: [
509
+ { name: 'consumerName', type: 'string', required: true, description: 'Consumer service name' },
510
+ { name: 'providerName', type: 'string', required: true, description: 'Provider service name' },
511
+ { name: 'expectedResource', type: 'string', required: true, description: 'Resource being consumed' },
512
+ { name: 'providerState', type: 'string', required: true, description: 'Provider state precondition' },
513
+ { name: 'interactionDescription', type: 'string', required: true, description: 'Interaction description' },
514
+ { name: 'httpMethod', type: 'string', required: true, description: 'HTTP method' },
515
+ { name: 'requestPath', type: 'string', required: true, description: 'Request path' },
516
+ { name: 'expectedShape', type: 'object', required: true, description: 'Expected response shape' },
517
+ { name: 'clientMethod', type: 'string', required: true, description: 'Client method to call' },
518
+ ],
519
+ },
520
+ context: {
521
+ tags: ['contract', 'pact', 'consumer-driven', 'microservice'],
522
+ },
523
+ confidence: 0.6,
524
+ },
525
+ // ================================================================
526
+ // visual-accessibility domain seeds
527
+ // ================================================================
528
+ {
529
+ patternType: 'a11y-check',
530
+ name: 'WCAG Contrast and ARIA Check',
531
+ description: 'Validate WCAG 2.2 color contrast ratios and ARIA attribute correctness',
532
+ template: {
533
+ type: 'prompt',
534
+ content: `Accessibility audit for {{componentName}}:
535
+
536
+ WCAG 2.2 AA Compliance:
537
+ 1. **Color Contrast**: Text contrast ratio >= 4.5:1 (normal), >= 3:1 (large)
538
+ 2. **ARIA Roles**: All interactive elements have correct role attributes
539
+ 3. **ARIA Labels**: Forms and buttons have aria-label or aria-labelledby
540
+ 4. **Focus Management**: Tab order is logical, focus visible on all interactive elements
541
+ 5. **Screen Reader**: Content is meaningful when linearized
542
+ 6. **Keyboard**: All functionality accessible via keyboard alone
543
+
544
+ Test with: axe-core, pa11y, or lighthouse --accessibility`,
545
+ variables: [
546
+ { name: 'componentName', type: 'string', required: true, description: 'UI component to audit' },
547
+ ],
548
+ },
549
+ context: {
550
+ tags: ['wcag', 'accessibility', 'aria', 'contrast', 'a11y'],
551
+ },
552
+ confidence: 0.6,
553
+ },
554
+ {
555
+ patternType: 'visual-baseline',
556
+ name: 'Visual Regression Baseline',
557
+ description: 'Capture and compare screenshots for visual regression detection',
558
+ template: {
559
+ type: 'code',
560
+ content: `describe('{{pageName}} visual regression', () => {
561
+ it('should match baseline screenshot', async () => {
562
+ await page.goto('{{pageUrl}}');
563
+ await page.waitForLoadState('networkidle');
564
+
565
+ const screenshot = await page.screenshot({ fullPage: {{fullPage}} });
566
+ expect(screenshot).toMatchSnapshot('{{pageName}}-baseline.png', {
567
+ maxDiffPixelRatio: {{maxDiffRatio}},
568
+ });
569
+ });
570
+
571
+ it('should match baseline at mobile viewport', async () => {
572
+ await page.setViewportSize({ width: 375, height: 812 });
573
+ await page.goto('{{pageUrl}}');
574
+ const screenshot = await page.screenshot({ fullPage: {{fullPage}} });
575
+ expect(screenshot).toMatchSnapshot('{{pageName}}-mobile-baseline.png', {
576
+ maxDiffPixelRatio: {{maxDiffRatio}},
577
+ });
578
+ });
579
+ });`,
580
+ variables: [
581
+ { name: 'pageName', type: 'string', required: true, description: 'Page name for snapshot naming' },
582
+ { name: 'pageUrl', type: 'string', required: true, description: 'Page URL to capture' },
583
+ { name: 'fullPage', type: 'boolean', required: false, defaultValue: true, description: 'Capture full page' },
584
+ { name: 'maxDiffRatio', type: 'number', required: false, defaultValue: 0.01, description: 'Max pixel diff ratio' },
585
+ ],
586
+ },
587
+ context: {
588
+ tags: ['visual', 'screenshot', 'regression', 'baseline', 'playwright'],
589
+ },
590
+ confidence: 0.6,
591
+ },
592
+ // ================================================================
593
+ // chaos-resilience domain seeds
594
+ // ================================================================
595
+ {
596
+ patternType: 'perf-benchmark',
597
+ name: 'Load Test Scenario',
598
+ description: 'k6-style load test with ramp-up stages and SLA assertions',
599
+ template: {
600
+ type: 'code',
601
+ content: `import http from 'k6/http';
602
+ import { check, sleep } from 'k6';
603
+
604
+ export const options = {
605
+ stages: [
606
+ { duration: '{{rampUpDuration}}', target: {{peakUsers}} },
607
+ { duration: '{{steadyDuration}}', target: {{peakUsers}} },
608
+ { duration: '{{rampDownDuration}}', target: 0 },
609
+ ],
610
+ thresholds: {
611
+ http_req_duration: ['p(95)<{{p95ThresholdMs}}'],
612
+ http_req_failed: ['rate<{{errorRateThreshold}}'],
613
+ },
614
+ };
615
+
616
+ export default function () {
617
+ const res = http.get('{{targetUrl}}');
618
+ check(res, {
619
+ 'status is 200': (r) => r.status === 200,
620
+ 'response time < {{p95ThresholdMs}}ms': (r) => r.timings.duration < {{p95ThresholdMs}},
621
+ });
622
+ sleep(1);
623
+ }`,
624
+ variables: [
625
+ { name: 'targetUrl', type: 'string', required: true, description: 'Target URL to load test' },
626
+ { name: 'peakUsers', type: 'number', required: true, description: 'Peak concurrent users' },
627
+ { name: 'rampUpDuration', type: 'string', required: false, defaultValue: '2m', description: 'Ramp-up duration' },
628
+ { name: 'steadyDuration', type: 'string', required: false, defaultValue: '5m', description: 'Steady state duration' },
629
+ { name: 'rampDownDuration', type: 'string', required: false, defaultValue: '1m', description: 'Ramp-down duration' },
630
+ { name: 'p95ThresholdMs', type: 'number', required: false, defaultValue: 500, description: 'P95 latency threshold in ms' },
631
+ { name: 'errorRateThreshold', type: 'number', required: false, defaultValue: 0.01, description: 'Max error rate (0-1)' },
632
+ ],
633
+ },
634
+ context: {
635
+ tags: ['load-test', 'k6', 'performance', 'sla'],
636
+ },
637
+ confidence: 0.6,
638
+ },
639
+ {
640
+ patternType: 'perf-benchmark',
641
+ name: 'Circuit Breaker Resilience Test',
642
+ description: 'Test circuit breaker behavior under fault injection',
643
+ template: {
644
+ type: 'prompt',
645
+ content: `Resilience test for {{serviceName}} circuit breaker:
646
+
647
+ 1. **Closed state**: Verify normal requests pass through
648
+ 2. **Fault injection**: Inject {{faultType}} faults at {{faultRate}}% rate
649
+ 3. **Trip threshold**: Verify breaker opens after {{failureThreshold}} consecutive failures
650
+ 4. **Open state**: Verify requests fail fast (no upstream calls)
651
+ 5. **Half-open probe**: After {{cooldownMs}}ms, verify single probe request
652
+ 6. **Recovery**: On probe success, verify breaker closes and traffic resumes
653
+ 7. **Metrics**: Verify circuit state changes are logged and observable`,
654
+ variables: [
655
+ { name: 'serviceName', type: 'string', required: true, description: 'Service with circuit breaker' },
656
+ { name: 'faultType', type: 'string', required: false, defaultValue: 'latency', description: 'Type of fault (latency/error/timeout)' },
657
+ { name: 'faultRate', type: 'number', required: false, defaultValue: 50, description: 'Fault injection rate %' },
658
+ { name: 'failureThreshold', type: 'number', required: false, defaultValue: 5, description: 'Failures to trip breaker' },
659
+ { name: 'cooldownMs', type: 'number', required: false, defaultValue: 30000, description: 'Cooldown before half-open' },
660
+ ],
661
+ },
662
+ context: {
663
+ tags: ['chaos', 'circuit-breaker', 'resilience', 'fault-injection'],
664
+ },
665
+ confidence: 0.6,
666
+ },
667
+ // ================================================================
668
+ // learning-optimization domain seeds
669
+ // ================================================================
670
+ {
671
+ patternType: 'coverage-strategy',
672
+ qeDomain: 'learning-optimization',
673
+ name: 'Cross-Domain Pattern Transfer',
674
+ description: 'Strategy for transferring useful patterns from one QE domain to related domains',
675
+ template: {
676
+ type: 'prompt',
677
+ content: `Pattern transfer from {{sourceDomain}} to {{targetDomain}}:
678
+
679
+ 1. Identify generalizable patterns in source domain (success rate > 70%)
680
+ 2. Check domain compatibility (related domains get 80% relevance, unrelated 50%)
681
+ 3. Adapt pattern context: replace domain-specific terms with target equivalents
682
+ 4. Set transferred pattern confidence to source * compatibility factor
683
+ 5. Store in target domain with provenance metadata
684
+ 6. Track transfer outcomes to learn which transfers are valuable`,
685
+ variables: [
686
+ { name: 'sourceDomain', type: 'string', required: true, description: 'Source QE domain' },
687
+ { name: 'targetDomain', type: 'string', required: true, description: 'Target QE domain' },
688
+ ],
689
+ },
690
+ context: {
691
+ tags: ['transfer', 'cross-domain', 'learning', 'pattern-reuse'],
692
+ },
693
+ confidence: 0.6,
694
+ },
695
+ {
696
+ patternType: 'coverage-strategy',
697
+ qeDomain: 'learning-optimization',
698
+ name: 'Pattern Quality Promotion Pipeline',
699
+ description: 'Pipeline for promoting short-term patterns to long-term based on success evidence',
700
+ template: {
701
+ type: 'prompt',
702
+ content: `Pattern promotion evaluation for {{patternName}}:
703
+
704
+ Criteria (all must pass):
705
+ 1. Usage count >= 3 successful applications
706
+ 2. Success rate >= 70%
707
+ 3. Confidence score >= 0.6
708
+ 4. Coherence check: no contradiction with existing long-term patterns
709
+ 5. Age: pattern has existed for at least 24 hours (not rushed)
710
+
711
+ On promotion:
712
+ - Move from short-term to long-term tier
713
+ - Boost confidence by 10%
714
+ - Enable for cross-domain transfer to related domains
715
+ - Mark as reusable for token savings optimization`,
716
+ variables: [
717
+ { name: 'patternName', type: 'string', required: true, description: 'Pattern to evaluate for promotion' },
718
+ ],
719
+ },
720
+ context: {
721
+ tags: ['promotion', 'learning', 'quality', 'pipeline'],
722
+ },
723
+ confidence: 0.6,
724
+ },
725
+ ];
726
+ //# sourceMappingURL=pretrained-patterns.js.map