@yasserkhanorg/e2e-agents 0.5.16 → 0.7.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 (113) hide show
  1. package/dist/agent/pipeline.d.ts +1 -1
  2. package/dist/agent/pipeline.d.ts.map +1 -1
  3. package/dist/agent/plan.d.ts +2 -13
  4. package/dist/agent/plan.d.ts.map +1 -1
  5. package/dist/agent/plan.js +0 -365
  6. package/dist/agent/types.d.ts +42 -0
  7. package/dist/agent/types.d.ts.map +1 -0
  8. package/dist/agent/types.js +4 -0
  9. package/dist/api.d.ts +14 -14
  10. package/dist/api.d.ts.map +1 -1
  11. package/dist/api.js +67 -59
  12. package/dist/cli.js +86 -176
  13. package/dist/engine/ai_enrichment.d.ts +43 -0
  14. package/dist/engine/ai_enrichment.d.ts.map +1 -0
  15. package/dist/engine/ai_enrichment.js +235 -0
  16. package/dist/engine/diff_loader.d.ts +11 -0
  17. package/dist/engine/diff_loader.d.ts.map +1 -0
  18. package/dist/engine/diff_loader.js +74 -0
  19. package/dist/engine/impact_engine.d.ts +36 -0
  20. package/dist/engine/impact_engine.d.ts.map +1 -0
  21. package/dist/engine/impact_engine.js +196 -0
  22. package/dist/engine/plan_builder.d.ts +10 -0
  23. package/dist/engine/plan_builder.d.ts.map +1 -0
  24. package/dist/engine/plan_builder.js +374 -0
  25. package/dist/esm/agent/plan.js +1 -360
  26. package/dist/esm/agent/types.js +3 -0
  27. package/dist/esm/api.js +62 -54
  28. package/dist/esm/cli.js +87 -177
  29. package/dist/esm/engine/ai_enrichment.js +232 -0
  30. package/dist/esm/engine/diff_loader.js +70 -0
  31. package/dist/esm/engine/impact_engine.js +191 -0
  32. package/dist/esm/engine/plan_builder.js +368 -0
  33. package/dist/esm/index.js +6 -3
  34. package/dist/esm/knowledge/route_families.js +59 -1
  35. package/dist/index.d.ts +9 -4
  36. package/dist/index.d.ts.map +1 -1
  37. package/dist/index.js +14 -5
  38. package/dist/knowledge/route_families.d.ts +19 -0
  39. package/dist/knowledge/route_families.d.ts.map +1 -1
  40. package/dist/knowledge/route_families.js +62 -1
  41. package/package.json +1 -1
  42. package/dist/agent/ai_flow_analysis.d.ts +0 -13
  43. package/dist/agent/ai_flow_analysis.d.ts.map +0 -1
  44. package/dist/agent/ai_flow_analysis.js +0 -334
  45. package/dist/agent/ai_mapping.d.ts +0 -14
  46. package/dist/agent/ai_mapping.d.ts.map +0 -1
  47. package/dist/agent/ai_mapping.js +0 -560
  48. package/dist/agent/analysis.d.ts +0 -64
  49. package/dist/agent/analysis.d.ts.map +0 -1
  50. package/dist/agent/analysis.js +0 -292
  51. package/dist/agent/blast_radius.d.ts +0 -4
  52. package/dist/agent/blast_radius.d.ts.map +0 -1
  53. package/dist/agent/blast_radius.js +0 -37
  54. package/dist/agent/dependency_graph.d.ts +0 -14
  55. package/dist/agent/dependency_graph.d.ts.map +0 -1
  56. package/dist/agent/dependency_graph.js +0 -227
  57. package/dist/agent/flags.d.ts +0 -23
  58. package/dist/agent/flags.d.ts.map +0 -1
  59. package/dist/agent/flags.js +0 -171
  60. package/dist/agent/flow_catalog.d.ts +0 -25
  61. package/dist/agent/flow_catalog.d.ts.map +0 -1
  62. package/dist/agent/flow_catalog.js +0 -115
  63. package/dist/agent/flow_mapping.d.ts +0 -10
  64. package/dist/agent/flow_mapping.d.ts.map +0 -1
  65. package/dist/agent/flow_mapping.js +0 -84
  66. package/dist/agent/framework.d.ts +0 -13
  67. package/dist/agent/framework.d.ts.map +0 -1
  68. package/dist/agent/framework.js +0 -149
  69. package/dist/agent/gap_suggestions.d.ts +0 -14
  70. package/dist/agent/gap_suggestions.d.ts.map +0 -1
  71. package/dist/agent/gap_suggestions.js +0 -101
  72. package/dist/agent/generator.d.ts +0 -10
  73. package/dist/agent/generator.d.ts.map +0 -1
  74. package/dist/agent/generator.js +0 -115
  75. package/dist/agent/operational_insights.d.ts +0 -41
  76. package/dist/agent/operational_insights.d.ts.map +0 -1
  77. package/dist/agent/operational_insights.js +0 -127
  78. package/dist/agent/report.d.ts +0 -97
  79. package/dist/agent/report.d.ts.map +0 -1
  80. package/dist/agent/report.js +0 -159
  81. package/dist/agent/runner.d.ts +0 -7
  82. package/dist/agent/runner.d.ts.map +0 -1
  83. package/dist/agent/runner.js +0 -898
  84. package/dist/agent/selectors.d.ts +0 -10
  85. package/dist/agent/selectors.d.ts.map +0 -1
  86. package/dist/agent/selectors.js +0 -75
  87. package/dist/agent/subsystem_risk.d.ts +0 -23
  88. package/dist/agent/subsystem_risk.d.ts.map +0 -1
  89. package/dist/agent/subsystem_risk.js +0 -207
  90. package/dist/agent/tests.d.ts +0 -19
  91. package/dist/agent/tests.d.ts.map +0 -1
  92. package/dist/agent/tests.js +0 -116
  93. package/dist/agent/traceability.d.ts +0 -22
  94. package/dist/agent/traceability.d.ts.map +0 -1
  95. package/dist/agent/traceability.js +0 -183
  96. package/dist/esm/agent/ai_flow_analysis.js +0 -331
  97. package/dist/esm/agent/ai_mapping.js +0 -557
  98. package/dist/esm/agent/analysis.js +0 -287
  99. package/dist/esm/agent/blast_radius.js +0 -34
  100. package/dist/esm/agent/dependency_graph.js +0 -224
  101. package/dist/esm/agent/flags.js +0 -160
  102. package/dist/esm/agent/flow_catalog.js +0 -112
  103. package/dist/esm/agent/flow_mapping.js +0 -81
  104. package/dist/esm/agent/framework.js +0 -145
  105. package/dist/esm/agent/gap_suggestions.js +0 -98
  106. package/dist/esm/agent/generator.js +0 -112
  107. package/dist/esm/agent/operational_insights.js +0 -124
  108. package/dist/esm/agent/report.js +0 -156
  109. package/dist/esm/agent/runner.js +0 -894
  110. package/dist/esm/agent/selectors.js +0 -71
  111. package/dist/esm/agent/subsystem_risk.js +0 -204
  112. package/dist/esm/agent/tests.js +0 -111
  113. package/dist/esm/agent/traceability.js +0 -180
@@ -1,359 +1,7 @@
1
1
  // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
2
2
  // See LICENSE.txt for license information.
3
3
  import { appendFileSync, existsSync, mkdirSync, readFileSync, writeFileSync } from 'fs';
4
- import { dirname, join } from 'path';
5
- import { minimatch } from 'minimatch';
6
- const DEFAULT_POLICY = {
7
- minConfidenceForTargeted: 60,
8
- safeMergeMinConfidence: 85,
9
- forceFullOnWarningsAtOrAbove: 2,
10
- forceFullOnP0WithGaps: true,
11
- forceFullOnRiskyFiles: true,
12
- riskyFilePatterns: [
13
- '**/auth/**',
14
- '**/login/**',
15
- '**/permissions/**',
16
- '**/admin/**',
17
- '**/security/**',
18
- '**/migrations/**',
19
- '**/schema/**',
20
- '**/*.sql',
21
- '**/webhook/**',
22
- ],
23
- enforcementMode: 'advisory',
24
- blockOnActions: ['must-add-tests'],
25
- };
26
- function countPriority(flows) {
27
- const counts = { p0: 0, p1: 0, p2: 0 };
28
- for (const flow of flows) {
29
- if (flow.priority === 'P0')
30
- counts.p0 += 1;
31
- else if (flow.priority === 'P1')
32
- counts.p1 += 1;
33
- else
34
- counts.p2 += 1;
35
- }
36
- return counts;
37
- }
38
- function computeConfidence(impact, p0, p1) {
39
- let confidence = 85;
40
- confidence -= Math.min(25, impact.warnings.length * 8);
41
- confidence -= Math.min(20, impact.gaps.length * 5);
42
- if (p0 > 0) {
43
- confidence -= Math.min(10, p0 * 3);
44
- }
45
- else if (p1 > 0) {
46
- confidence -= Math.min(6, p1 * 2);
47
- }
48
- if (impact.impactModel) {
49
- if (impact.impactModel.flowMapping === 'catalog') {
50
- confidence += 4;
51
- }
52
- else if (impact.impactModel.flowMapping === 'ai') {
53
- confidence += 4;
54
- }
55
- if (impact.impactModel.testMapping === 'catalog') {
56
- confidence += 4;
57
- }
58
- else if (impact.impactModel.testMapping === 'traceability') {
59
- confidence += 6;
60
- }
61
- else if (impact.impactModel.testMapping === 'ai') {
62
- confidence += 4;
63
- }
64
- if (impact.impactModel.confidenceClass === 'medium') {
65
- confidence -= 4;
66
- }
67
- else if (impact.impactModel.confidenceClass === 'low') {
68
- confidence -= 12;
69
- }
70
- if (impact.impactModel.traceability) {
71
- if (!impact.impactModel.traceability.manifestFound) {
72
- confidence -= 6;
73
- }
74
- else if (impact.impactModel.traceability.coverageRatio >= 0.8) {
75
- confidence += 2;
76
- }
77
- else if (impact.impactModel.traceability.coverageRatio < 0.5) {
78
- confidence -= 4;
79
- }
80
- }
81
- if (impact.impactModel.dependencyGraph?.truncated) {
82
- confidence -= 6;
83
- }
84
- if (impact.impactModel.dependencyGraph && impact.impactModel.dependencyGraph.expandedFiles > 0) {
85
- confidence += 2;
86
- }
87
- }
88
- return Math.max(0, Math.min(100, confidence));
89
- }
90
- function findRiskyFiles(changedFiles, patterns) {
91
- const risky = changedFiles.filter((file) => patterns.some((pattern) => minimatch(file, pattern, { matchBase: true })));
92
- return [...new Set(risky)];
93
- }
94
- function pickRunSet(impact, p0, confidence, policy) {
95
- const reasons = [];
96
- const triggeredRules = [];
97
- const riskyFiles = findRiskyFiles(impact.changedFiles, policy.riskyFilePatterns);
98
- if (impact.warnings.length > 0) {
99
- reasons.push('Impact analysis emitted warnings; broader safety coverage is recommended.');
100
- }
101
- if (impact.gaps.length > 0) {
102
- reasons.push('Uncovered P0/P1 flows were detected.');
103
- }
104
- if (p0 > 0) {
105
- reasons.push('P0 flows are impacted by this change set.');
106
- }
107
- if (policy.forceFullOnRiskyFiles && riskyFiles.length > 0) {
108
- triggeredRules.push('risky-files');
109
- reasons.push(`Risky file patterns matched: ${riskyFiles.join(', ')}`);
110
- }
111
- if (impact.impactModel?.confidenceClass === 'low') {
112
- triggeredRules.push('low-traceability');
113
- reasons.push('Impact mapping confidence is low.');
114
- }
115
- if (impact.impactModel?.traceability?.manifestFound && impact.impactModel.traceability.coverageRatio < 0.4) {
116
- triggeredRules.push('traceability-low-coverage');
117
- reasons.push('Traceability manifest coverage is low for impacted flows; broader safety run is recommended.');
118
- }
119
- if (impact.impactModel?.dependencyGraph?.truncated) {
120
- triggeredRules.push('dependency-graph-truncated');
121
- reasons.push('Dependency graph expansion was truncated; broader safety run is recommended.');
122
- }
123
- if (confidence < policy.minConfidenceForTargeted) {
124
- triggeredRules.push('low-confidence');
125
- }
126
- if (impact.warnings.length >= policy.forceFullOnWarningsAtOrAbove) {
127
- triggeredRules.push('warning-threshold');
128
- }
129
- if (policy.forceFullOnP0WithGaps && p0 > 0 && impact.gaps.length > 0) {
130
- triggeredRules.push('p0-with-gaps');
131
- }
132
- if (triggeredRules.length > 0) {
133
- return {
134
- runSet: 'full',
135
- reasons: reasons.length > 0 ? reasons : ['Low confidence in targeted recommendation.'],
136
- triggeredRules,
137
- riskyFiles,
138
- };
139
- }
140
- if (impact.recommendedTests && impact.recommendedTests.length > 0) {
141
- return {
142
- runSet: 'targeted',
143
- reasons: reasons.length > 0 ? reasons : ['Sufficient confidence for targeted run list.'],
144
- triggeredRules,
145
- riskyFiles,
146
- };
147
- }
148
- return {
149
- runSet: 'smoke',
150
- reasons: reasons.length > 0 ? reasons : ['No targeted tests were mapped from the impacted flows.'],
151
- triggeredRules,
152
- riskyFiles,
153
- };
154
- }
155
- function buildDecision(runSet, confidence, impact, policy) {
156
- if (impact.gaps.length > 0) {
157
- return {
158
- action: 'must-add-tests',
159
- title: 'Must add tests',
160
- summary: `Detected ${impact.gaps.length} uncovered P0/P1 flow(s). Add or update tests before merge.`,
161
- };
162
- }
163
- if (impact.changedFiles.length === 0 && impact.flows.length === 0) {
164
- return {
165
- action: 'safe-to-merge',
166
- title: 'Safe to merge',
167
- summary: 'No app file changes detected — no E2E coverage required for this change set.',
168
- };
169
- }
170
- if (runSet === 'smoke' && confidence >= policy.safeMergeMinConfidence && impact.warnings.length === 0) {
171
- return {
172
- action: 'safe-to-merge',
173
- title: 'Safe to merge',
174
- summary: 'No critical coverage gaps were detected and policy confidence is high.',
175
- };
176
- }
177
- const coveredCount = impact.coverage.filter((c) => c.coveredBy.length > 0).length;
178
- const coverageSuffix = coveredCount > 0
179
- ? ` All ${coveredCount} impacted flow(s) have test coverage.`
180
- : '';
181
- return {
182
- action: 'run-now',
183
- title: 'Run now',
184
- summary: `Impacted flows are covered by existing tests.${coverageSuffix} Verify with the E2E suite before merge.`,
185
- };
186
- }
187
- function evaluateEnforcement(decision, policy) {
188
- const blockOnActions = (policy.blockOnActions && policy.blockOnActions.length > 0)
189
- ? [...policy.blockOnActions]
190
- : ['must-add-tests'];
191
- const matchedAction = blockOnActions.includes(decision.action);
192
- if (policy.enforcementMode === 'block' && matchedAction) {
193
- return {
194
- mode: policy.enforcementMode,
195
- blockOnActions,
196
- matchedAction,
197
- shouldFail: true,
198
- summary: `Blocking mode active: decision "${decision.action}" is configured to fail CI.`,
199
- };
200
- }
201
- if (policy.enforcementMode === 'warn' && matchedAction) {
202
- return {
203
- mode: policy.enforcementMode,
204
- blockOnActions,
205
- matchedAction,
206
- shouldFail: false,
207
- summary: `Warning mode active: decision "${decision.action}" is advisory-only for CI.`,
208
- };
209
- }
210
- if (policy.enforcementMode === 'block') {
211
- return {
212
- mode: policy.enforcementMode,
213
- blockOnActions,
214
- matchedAction,
215
- shouldFail: false,
216
- summary: `Blocking mode active, but decision "${decision.action}" is not configured for CI failure.`,
217
- };
218
- }
219
- if (policy.enforcementMode === 'warn') {
220
- return {
221
- mode: policy.enforcementMode,
222
- blockOnActions,
223
- matchedAction,
224
- shouldFail: false,
225
- summary: `Warning mode active, but decision "${decision.action}" is not configured for warning.`,
226
- };
227
- }
228
- return {
229
- mode: policy.enforcementMode,
230
- blockOnActions,
231
- matchedAction,
232
- shouldFail: false,
233
- summary: 'Advisory mode active: recommendations do not fail CI by default.',
234
- };
235
- }
236
- export function refreshPlanEnforcement(plan) {
237
- return {
238
- ...plan,
239
- enforcement: evaluateEnforcement(plan.decision, plan.policy.applied),
240
- };
241
- }
242
- export function buildPlanFromImpactReport(impact, policyOverride) {
243
- if (impact.mode !== 'impact') {
244
- throw new Error(`Plan generation requires impact report data, received mode=${impact.mode}`);
245
- }
246
- const policy = { ...DEFAULT_POLICY, ...(policyOverride || {}) };
247
- const { p0, p1, p2 } = countPriority(impact.flows);
248
- const confidence = computeConfidence(impact, p0, p1);
249
- const runSet = pickRunSet(impact, p0, confidence, policy);
250
- const decision = buildDecision(runSet.runSet, confidence, impact, policy);
251
- const enforcement = evaluateEnforcement(decision, policy);
252
- const requiredNewTests = impact.gaps.map((flow) => `${flow.id}: ${flow.name}`);
253
- const gapDetails = impact.gaps.map((flow) => ({
254
- id: flow.id,
255
- name: flow.name,
256
- priority: flow.priority,
257
- reasons: (flow.reasons || []).slice(0, 5),
258
- files: (flow.files || []).slice(0, 6),
259
- existingTests: flow.existingTests && flow.existingTests.length > 0 ? flow.existingTests.slice(0, 3) : undefined,
260
- missingScenarios: flow.missingScenarios && flow.missingScenarios.length > 0 ? flow.missingScenarios.slice(0, 5) : undefined,
261
- }));
262
- const coveredFlowIds = new Set(impact.gaps.map((g) => g.id));
263
- const coveredFlows = impact.coverage
264
- .filter((c) => c.coveredBy.length > 0 && !coveredFlowIds.has(c.flowId))
265
- .map((c) => ({
266
- id: c.flowId,
267
- name: c.flowName,
268
- priority: c.priority,
269
- coveredBy: c.coveredBy.slice(0, 3),
270
- }));
271
- const sourceRunId = impact.runMetadata?.runId;
272
- const runId = `plan-${sourceRunId || Date.now().toString(36)}`;
273
- return {
274
- schemaVersion: '1.0.0',
275
- runId,
276
- sourceRunId,
277
- generatedAt: new Date().toISOString(),
278
- source: 'impact',
279
- runSet: runSet.runSet,
280
- confidence,
281
- reasons: runSet.reasons,
282
- recommendedTests: impact.recommendedTests || [],
283
- requiredNewTests,
284
- gapDetails,
285
- coveredFlows,
286
- policy: {
287
- riskyFiles: runSet.riskyFiles,
288
- triggeredRules: runSet.triggeredRules,
289
- applied: policy,
290
- },
291
- decision,
292
- enforcement,
293
- metrics: {
294
- changedFiles: impact.changedFiles.length,
295
- impactedFlows: impact.flows.length,
296
- p0Flows: p0,
297
- p1Flows: p1,
298
- p2Flows: p2,
299
- uncoveredP0P1Flows: impact.gaps.length,
300
- warnings: impact.warnings.length,
301
- },
302
- };
303
- }
304
- export function attachDeveloperActions(plan, context) {
305
- const safeSince = context.sinceRef ? ` --since "${context.sinceRef}"` : '';
306
- const generateBaseCommand = context.configPath
307
- ? `npx e2e-ai-agents approve-and-generate --config "${context.configPath}" --pipeline --pipeline-mcp --pipeline-mcp-only${safeSince}`
308
- : `npx e2e-ai-agents approve-and-generate --path "${context.appPath}" --tests-root "${context.testsRoot}" --pipeline --pipeline-mcp --pipeline-mcp-only${safeSince}`;
309
- const runRecommendedTests = plan.recommendedTests.length > 0
310
- ? `node -e "const fs=require('fs'); const p=JSON.parse(fs.readFileSync('${context.testsRoot}/.e2e-ai-agents/plan.json','utf8')); const tests=p.recommendedTests.map((t)=>t.replace(/ \\(flags:.*\\)$/,'')); console.log(tests.join(' '));" | xargs npx playwright test`
311
- : undefined;
312
- return {
313
- ...plan,
314
- nextActions: {
315
- requiresUserApprovalForGeneration: true,
316
- runRecommendedTests,
317
- runSmokeSuite: 'npx playwright test --grep @smoke --project=chrome',
318
- runFullSuite: 'npx playwright test --project=chrome',
319
- approveAndGenerate: generateBaseCommand,
320
- generateMissingTests: generateBaseCommand,
321
- healGeneratedTests: generateBaseCommand,
322
- commitGeneratedTests: `npx e2e-ai-agents finalize-generated-tests --path "${context.appPath}" --tests-root "${context.testsRoot}" --commit-message "test(e2e): add generated coverage and healed specs"`,
323
- openPullRequest: `npx e2e-ai-agents finalize-generated-tests --path "${context.appPath}" --tests-root "${context.testsRoot}" --create-pr`,
324
- },
325
- };
326
- }
327
- export function writePlanReport(appRoot, plan) {
328
- const baseDir = join(appRoot, '.e2e-ai-agents');
329
- mkdirSync(baseDir, { recursive: true });
330
- const planPath = join(baseDir, 'plan.json');
331
- writeFileSync(planPath, JSON.stringify(plan, null, 2), 'utf-8');
332
- return planPath;
333
- }
334
- export function renderCiSummaryMarkdown(plan) {
335
- const lines = [];
336
- const { p0Flows, p1Flows, uncoveredP0P1Flows, changedFiles, impactedFlows } = plan.metrics;
337
- const mustAddTests = plan.decision.action === 'must-add-tests';
338
- const statusEmoji = mustAddTests ? '🔴' : plan.decision.action === 'safe-to-merge' ? '🟢' : '🟡';
339
- lines.push(`## ${statusEmoji} E2E Coverage: ${plan.decision.title}`);
340
- lines.push('');
341
- lines.push(`${plan.decision.summary}`);
342
- lines.push('');
343
- lines.push(`**${changedFiles}** files changed → **${impactedFlows}** flows impacted` +
344
- (p0Flows > 0 || p1Flows > 0 ? ` (P0: ${p0Flows}, P1: ${p1Flows})` : ''));
345
- if (mustAddTests && plan.requiredNewTests.length > 0) {
346
- lines.push('');
347
- lines.push('### ⚠️ Add E2E tests for these uncovered P0/P1 flows');
348
- lines.push('');
349
- lines.push(`The following ${uncoveredP0P1Flows} flow(s) have no test coverage and must be covered before merge:`);
350
- lines.push('');
351
- for (const gap of plan.requiredNewTests) {
352
- lines.push(`- ${gap}`);
353
- }
354
- }
355
- return lines.join('\n');
356
- }
4
+ import { join } from 'path';
357
5
  const PLAN_METRICS_EVENTS_PATH = '.e2e-ai-agents/metrics.jsonl';
358
6
  const PLAN_METRICS_SUMMARY_PATH = '.e2e-ai-agents/metrics-summary.json';
359
7
  function parsePlanMetricLine(line) {
@@ -433,10 +81,3 @@ export function appendPlanMetrics(appRoot, plan) {
433
81
  writeFileSync(summaryPath, JSON.stringify(summary, null, 2), 'utf-8');
434
82
  return { eventsPath, summaryPath };
435
83
  }
436
- export function writeCiSummary(appRoot, markdown, relativePath = '.e2e-ai-agents/ci-summary.md') {
437
- const fullPath = join(appRoot, relativePath);
438
- const dir = dirname(fullPath);
439
- mkdirSync(dir, { recursive: true });
440
- writeFileSync(fullPath, markdown, 'utf-8');
441
- return fullPath;
442
- }
@@ -0,0 +1,3 @@
1
+ // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
2
+ // See LICENSE.txt for license information.
3
+ export {};
package/dist/esm/api.js CHANGED
@@ -1,21 +1,16 @@
1
1
  // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
2
2
  // See LICENSE.txt for license information.
3
- import { existsSync, readFileSync } from 'fs';
4
- import { join } from 'path';
5
3
  import { resolveConfig } from './agent/config.js';
6
- import { runGap, runImpact } from './agent/runner.js';
7
- import { appendPlanMetrics, attachDeveloperActions, buildPlanFromImpactReport, renderCiSummaryMarkdown, writeCiSummary, writePlanReport, } from './agent/plan.js';
8
- import { applyOperationalInsights } from './agent/operational_insights.js';
4
+ import { appendPlanMetrics, } from './agent/plan.js';
5
+ import { analyzeImpact as analyzeImpactV2 } from './engine/impact_engine.js';
6
+ import { buildPlanFromImpact, renderCiSummaryMarkdown, writeCiSummary, writePlanReport, } from './engine/plan_builder.js';
7
+ import { getChangedFiles } from './agent/git.js';
8
+ import { loadDiffs } from './engine/diff_loader.js';
9
+ import { enrichImpactWithAI } from './engine/ai_enrichment.js';
10
+ import { AnthropicProvider } from './anthropic_provider.js';
9
11
  import { finalizeGeneratedTests } from './agent/handoff.js';
10
12
  import { ingestTraceabilityInput, } from './agent/traceability_ingest.js';
11
13
  import { captureTraceabilityInput, } from './agent/traceability_capture.js';
12
- function readReportJson(reportPath) {
13
- if (!existsSync(reportPath)) {
14
- throw new Error(`Expected report not found: ${reportPath}`);
15
- }
16
- const raw = readFileSync(reportPath, 'utf-8');
17
- return JSON.parse(raw);
18
- }
19
14
  function resolveAgent(options, mode) {
20
15
  const cwd = options.cwd || process.cwd();
21
16
  const { config } = resolveConfig(cwd, options.configPath, {
@@ -27,63 +22,76 @@ function resolveAgent(options, mode) {
27
22
  }
28
23
  return config;
29
24
  }
30
- function reportPathFor(configPath, mode) {
31
- return join(configPath, '.e2e-ai-agents', mode === 'impact' ? 'impact.json' : 'gap.json');
25
+ export function handoffGeneratedTests(options) {
26
+ return finalizeGeneratedTests(options);
32
27
  }
33
- export async function analyzeImpact(options = {}) {
34
- const config = resolveAgent(options, 'impact');
35
- await runImpact(config, { apply: options.apply ?? false });
28
+ export function ingestTraceability(options) {
29
+ const cwd = options.cwd || process.cwd();
30
+ const { config } = resolveConfig(cwd, options.configPath, {
31
+ path: options.path,
32
+ testsRoot: options.testsRoot,
33
+ mode: 'impact',
34
+ });
36
35
  const reportRoot = config.testsRoot || config.path;
37
- const reportPath = reportPathFor(reportRoot, 'impact');
38
- const report = readReportJson(reportPath);
39
- return { report, reportPath };
36
+ return ingestTraceabilityInput(reportRoot, config.impact.traceability, options.payload, options.options);
40
37
  }
41
- export async function findGaps(options = {}) {
42
- const config = resolveAgent(options, 'gap');
43
- await runGap(config, { apply: options.apply ?? false });
38
+ export function analyzeImpactDeterministic(options = {}) {
39
+ const config = resolveAgent(options, 'impact');
44
40
  const reportRoot = config.testsRoot || config.path;
45
- const reportPath = reportPathFor(reportRoot, 'gap');
46
- const report = readReportJson(reportPath);
47
- return { report, reportPath };
41
+ const gitResult = getChangedFiles(config.path, config.git.since, { includeUncommitted: config.git.includeUncommitted });
42
+ return analyzeImpactV2(gitResult.files, {
43
+ testsRoot: reportRoot,
44
+ routeFamilies: config.routeFamilies,
45
+ });
48
46
  }
49
- export async function recommendTests(options = {}) {
47
+ export function recommendTestsDeterministic(options = {}) {
50
48
  const config = resolveAgent(options, 'impact');
51
- await runImpact(config, { apply: options.apply ?? false });
52
49
  const reportRoot = config.testsRoot || config.path;
53
- const impactPath = reportPathFor(reportRoot, 'impact');
54
- const report = readReportJson(impactPath);
55
- const basePlan = buildPlanFromImpactReport(report, config.policy);
56
- const withActions = attachDeveloperActions(basePlan, {
57
- appPath: config.path,
50
+ const gitResult = getChangedFiles(config.path, config.git.since, { includeUncommitted: config.git.includeUncommitted });
51
+ const impact = analyzeImpactV2(gitResult.files, {
58
52
  testsRoot: reportRoot,
59
- sinceRef: config.git.since,
53
+ routeFamilies: config.routeFamilies,
60
54
  });
61
- const plan = applyOperationalInsights(withActions, reportRoot);
55
+ const plan = buildPlanFromImpact(impact, config.policy);
62
56
  const planPath = writePlanReport(reportRoot, plan);
63
57
  const ciSummaryMarkdown = renderCiSummaryMarkdown(plan);
64
58
  const ciSummaryPath = writeCiSummary(reportRoot, ciSummaryMarkdown);
65
59
  appendPlanMetrics(reportRoot, plan);
66
- return {
67
- report,
68
- reportPath: impactPath,
69
- plan,
70
- planPath,
71
- ciSummaryMarkdown,
72
- ciSummaryPath,
73
- };
60
+ return { impact, plan, planPath, ciSummaryMarkdown, ciSummaryPath };
74
61
  }
75
- export function handoffGeneratedTests(options) {
76
- return finalizeGeneratedTests(options);
77
- }
78
- export function ingestTraceability(options) {
79
- const cwd = options.cwd || process.cwd();
80
- const { config } = resolveConfig(cwd, options.configPath, {
81
- path: options.path,
82
- testsRoot: options.testsRoot,
83
- mode: 'impact',
84
- });
62
+ export async function recommendTestsAI(options = {}) {
63
+ const config = resolveAgent(options, 'impact');
85
64
  const reportRoot = config.testsRoot || config.path;
86
- return ingestTraceabilityInput(reportRoot, config.impact.traceability, options.payload, options.options);
65
+ const gitResult = getChangedFiles(config.path, config.git.since, { includeUncommitted: config.git.includeUncommitted });
66
+ const impact = analyzeImpactV2(gitResult.files, {
67
+ testsRoot: reportRoot,
68
+ routeFamilies: config.routeFamilies,
69
+ });
70
+ const apiKey = process.env.ANTHROPIC_API_KEY;
71
+ let aiEnrichment;
72
+ if (apiKey) {
73
+ const diffs = loadDiffs(config.path, config.git.since, gitResult.files);
74
+ const provider = new AnthropicProvider({ apiKey });
75
+ // Collect all known spec paths from impacted features
76
+ const specSet = new Set();
77
+ for (const feature of impact.impactedFeatures) {
78
+ for (const s of feature.playwrightSpecs) {
79
+ specSet.add(s);
80
+ }
81
+ }
82
+ aiEnrichment = await enrichImpactWithAI({
83
+ deterministicImpact: impact,
84
+ diffs,
85
+ provider,
86
+ specList: [...specSet],
87
+ });
88
+ }
89
+ const plan = buildPlanFromImpact(impact, config.policy, aiEnrichment);
90
+ const planPath = writePlanReport(reportRoot, plan);
91
+ const ciSummaryMarkdown = renderCiSummaryMarkdown(plan);
92
+ const ciSummaryPath = writeCiSummary(reportRoot, ciSummaryMarkdown);
93
+ appendPlanMetrics(reportRoot, plan);
94
+ return { impact, plan, planPath, ciSummaryMarkdown, ciSummaryPath, aiEnrichment };
87
95
  }
88
96
  export function captureTraceability(options) {
89
97
  const cwd = options.cwd || process.cwd();