@skyramp/mcp 0.2.6 → 0.2.150-rc.mntnc

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 (233) hide show
  1. package/build/commands/commandLibrary.d.ts +12 -0
  2. package/build/commands/recommendTestsAndExecuteCommand.d.ts +2 -0
  3. package/build/commands/testThisEndpointCommand.d.ts +2 -0
  4. package/build/index.d.ts +2 -0
  5. package/build/index.js +6 -4
  6. package/build/playwright/PlaywrightTraceService.d.ts +32 -0
  7. package/build/playwright/index.d.ts +3 -0
  8. package/build/playwright/registerPlaywrightTools.d.ts +8 -0
  9. package/build/playwright/registerPlaywrightTools.js +12 -11
  10. package/build/playwright/traceRecordingPrompt.d.ts +13 -0
  11. package/build/playwright/traceRecordingPrompt.js +3 -11
  12. package/build/prompts/code-reuse.d.ts +1 -0
  13. package/build/prompts/enhance-assertions/contractProviderAssertionsPrompt.d.ts +2 -0
  14. package/build/prompts/enhance-assertions/integrationAssertionsPrompt.d.ts +2 -0
  15. package/build/prompts/enhance-assertions/sharedAssertionRules.d.ts +15 -0
  16. package/build/prompts/enhance-assertions/uiAssertionsPrompt.d.ts +2 -0
  17. package/build/prompts/enhance-assertions/uiAssertionsPrompt.js +24 -5
  18. package/build/prompts/fix-error-prompt.d.ts +1 -0
  19. package/build/prompts/initialize-workspace/initializeWorkspacePrompt.d.ts +1 -0
  20. package/build/prompts/modularization/integration-test-modularization.d.ts +1 -0
  21. package/build/prompts/modularization/ui-test-modularization.d.ts +1 -0
  22. package/build/prompts/personas.d.ts +21 -0
  23. package/build/prompts/pom-aware-code-reuse.d.ts +1 -0
  24. package/build/prompts/startTraceCollectionPrompts.d.ts +2 -0
  25. package/build/prompts/sut-setup/modes/adaptWorkflowPrompt.d.ts +2 -0
  26. package/build/prompts/sut-setup/modes/adaptWorkflowPrompt.js +114 -0
  27. package/build/prompts/sut-setup/modes/dockerComposePrompt.d.ts +2 -0
  28. package/build/prompts/sut-setup/modes/dockerComposePrompt.js +292 -0
  29. package/build/prompts/sut-setup/shared.d.ts +39 -0
  30. package/build/prompts/sut-setup/shared.js +132 -0
  31. package/build/prompts/test-maintenance/actionsInstructions.d.ts +35 -0
  32. package/build/prompts/test-maintenance/drift-analysis-prompt.d.ts +4 -0
  33. package/build/prompts/test-maintenance/driftAnalysisSections.d.ts +13 -0
  34. package/build/prompts/test-maintenance/driftAnalysisSections.js +9 -3
  35. package/build/prompts/test-recommendation/analysisOutputPrompt.d.ts +84 -0
  36. package/build/prompts/test-recommendation/analysisOutputPrompt.js +1 -1
  37. package/build/prompts/test-recommendation/analysisOutputPrompt.test.d.ts +1 -0
  38. package/build/prompts/test-recommendation/analysisOutputPrompt.test.js +1 -0
  39. package/build/prompts/test-recommendation/diffExecutionPlan.d.ts +17 -0
  40. package/build/prompts/test-recommendation/diffExecutionPlan.js +7 -16
  41. package/build/prompts/test-recommendation/fullRepoCatalog.d.ts +7 -0
  42. package/build/prompts/test-recommendation/mergeEnrichedScenarios.test.d.ts +1 -0
  43. package/build/prompts/test-recommendation/mergeEnrichedScenarios.test.js +1 -0
  44. package/build/prompts/test-recommendation/promptPlan.d.ts +203 -0
  45. package/build/prompts/test-recommendation/promptPlan.test.d.ts +1 -0
  46. package/build/prompts/test-recommendation/recommendationSections.d.ts +35 -0
  47. package/build/prompts/test-recommendation/recommendationShared.d.ts +31 -0
  48. package/build/prompts/test-recommendation/registerRecommendTestsPrompt.d.ts +7 -0
  49. package/build/prompts/test-recommendation/scopeAssessment.d.ts +55 -0
  50. package/build/prompts/test-recommendation/scopeAssessment.js +2 -2
  51. package/build/prompts/test-recommendation/scopeAssessment.test.d.ts +1 -0
  52. package/build/prompts/test-recommendation/scopeAssessment.test.js +1 -0
  53. package/build/prompts/test-recommendation/test-recommendation-prompt.d.ts +6 -0
  54. package/build/prompts/test-recommendation/test-recommendation-prompt.js +4 -4
  55. package/build/prompts/test-recommendation/test-recommendation-prompt.test.d.ts +1 -0
  56. package/build/prompts/test-recommendation/test-recommendation-prompt.test.js +6 -99
  57. package/build/prompts/testbot/testbot-prompts.d.ts +11 -0
  58. package/build/prompts/testbot/testbot-prompts.js +213 -42
  59. package/build/prompts/testbot/testbot-prompts.test.d.ts +1 -0
  60. package/build/prompts/testbot/testbot-prompts.test.js +15 -117
  61. package/build/resources/analysisResources.d.ts +17 -0
  62. package/build/resources/progressResource.d.ts +2 -0
  63. package/build/resources/sutSetupResource.d.ts +2 -0
  64. package/build/resources/sutSetupResource.js +45 -0
  65. package/build/resources/testbotResource.d.ts +2 -0
  66. package/build/resources/testbotResource.js +1 -1
  67. package/build/services/AnalyticsService.d.ts +13 -0
  68. package/build/services/AnalyticsService.test.d.ts +1 -0
  69. package/build/services/AnalyticsService.test.js +86 -0
  70. package/build/services/ModularizationService.d.ts +11 -0
  71. package/build/services/ScenarioGenerationService.d.ts +37 -0
  72. package/build/services/ScenarioGenerationService.integration.test.d.ts +1 -0
  73. package/build/services/ScenarioGenerationService.integration.test.js +4 -0
  74. package/build/services/ScenarioGenerationService.test.d.ts +1 -0
  75. package/build/services/TestDiscoveryService.d.ts +128 -0
  76. package/build/services/TestDiscoveryService.js +22 -12
  77. package/build/services/TestDiscoveryService.test.d.ts +1 -0
  78. package/build/services/TestDiscoveryService.test.js +4 -3
  79. package/build/services/TestExecutionService.d.ts +55 -0
  80. package/build/services/TestExecutionService.js +158 -26
  81. package/build/services/TestExecutionService.test.d.ts +1 -0
  82. package/build/services/TestExecutionService.test.js +339 -25
  83. package/build/services/TestGenerationService.d.ts +56 -0
  84. package/build/services/TestGenerationService.test.d.ts +1 -0
  85. package/build/services/TestGenerationService.test.js +10 -8
  86. package/build/services/containerEnv.d.ts +14 -0
  87. package/build/tool-phase-coverage.test.d.ts +1 -0
  88. package/build/tool-phase-coverage.test.js +2 -0
  89. package/build/tool-phases.d.ts +38 -0
  90. package/build/tools/auth/loginTool.d.ts +2 -0
  91. package/build/tools/auth/logoutTool.d.ts +2 -0
  92. package/build/tools/code-refactor/codeReuseTool.d.ts +2 -0
  93. package/build/tools/code-refactor/enhanceAssertionsTool.d.ts +2 -0
  94. package/build/tools/code-refactor/modularizationTool.d.ts +2 -0
  95. package/build/tools/executeSkyrampTestTool.d.ts +2 -0
  96. package/build/tools/executeSkyrampTestTool.js +17 -4
  97. package/build/tools/fixErrorTool.d.ts +2 -0
  98. package/build/tools/generate-tests/generateBatchScenarioRestTool.d.ts +45 -0
  99. package/build/tools/generate-tests/generateBatchScenarioRestTool.js +1 -1
  100. package/build/tools/generate-tests/generateBatchScenarioRestTool.test.d.ts +1 -0
  101. package/build/tools/generate-tests/generateBatchScenarioRestTool.test.js +11 -9
  102. package/build/tools/generate-tests/generateContractRestTool.d.ts +31 -0
  103. package/build/tools/generate-tests/generateE2ERestTool.d.ts +13 -0
  104. package/build/tools/generate-tests/generateFuzzRestTool.d.ts +10 -0
  105. package/build/tools/generate-tests/generateIntegrationRestTool.d.ts +16 -0
  106. package/build/tools/generate-tests/generateLoadRestTool.d.ts +18 -0
  107. package/build/tools/generate-tests/generateLoadRestTool.test.d.ts +1 -0
  108. package/build/tools/generate-tests/generateMockRestTool.d.ts +64 -0
  109. package/build/tools/generate-tests/generateSmokeRestTool.d.ts +8 -0
  110. package/build/tools/generate-tests/generateUIRestTool.d.ts +14 -0
  111. package/build/tools/generate-tests/generateUIRestTool.js +1 -1
  112. package/build/tools/generate-tests/loadTestSchema.d.ts +39 -0
  113. package/build/tools/one-click/oneClickTool.d.ts +11 -0
  114. package/build/tools/submitReportTool.d.ts +384 -0
  115. package/build/tools/submitReportTool.js +225 -37
  116. package/build/tools/submitReportTool.test.d.ts +1 -0
  117. package/build/tools/submitReportTool.test.js +479 -55
  118. package/build/tools/test-management/actionsTool.d.ts +10 -0
  119. package/build/tools/test-management/actionsTool.js +10 -0
  120. package/build/tools/test-management/analyzeChangesTool.d.ts +26 -0
  121. package/build/tools/test-management/analyzeChangesTool.js +128 -48
  122. package/build/tools/test-management/analyzeChangesTool.test.d.ts +1 -0
  123. package/build/tools/test-management/analyzeChangesTool.test.js +80 -73
  124. package/build/tools/test-management/analyzeTestHealthTool.d.ts +2 -0
  125. package/build/tools/test-management/analyzeTestHealthTool.js +6 -3
  126. package/build/tools/test-management/index.d.ts +3 -0
  127. package/build/tools/test-management/index.js +0 -1
  128. package/build/tools/trace/resolveSaveStoragePath.d.ts +7 -0
  129. package/build/tools/trace/resolveSaveStoragePath.test.d.ts +1 -0
  130. package/build/tools/trace/resolveSessionPaths.d.ts +40 -0
  131. package/build/tools/trace/resolveSessionPaths.test.d.ts +1 -0
  132. package/build/tools/trace/sessionState.d.ts +2 -0
  133. package/build/tools/trace/sessionState.test.d.ts +1 -0
  134. package/build/tools/trace/startTraceCollectionTool.d.ts +2 -0
  135. package/build/tools/trace/stopTraceCollectionTool.d.ts +2 -0
  136. package/build/tools/workspace/initScanWorkspaceTool.d.ts +4 -0
  137. package/build/tools/workspace/initializeWorkspaceTool.d.ts +2 -0
  138. package/build/tools/workspace/initializeWorkspaceTool.test.d.ts +1 -0
  139. package/build/tools/workspace/initializeWorkspaceTool.test.js +134 -0
  140. package/build/types/OneClickCommands.d.ts +68 -0
  141. package/build/types/RepositoryAnalysis.d.ts +3004 -0
  142. package/build/types/TestAnalysis.d.ts +97 -0
  143. package/build/types/TestExecution.d.ts +63 -0
  144. package/build/types/TestExecution.js +11 -1
  145. package/build/types/TestRecommendation.d.ts +12 -0
  146. package/build/types/TestTypes.d.ts +234 -0
  147. package/build/types/TestbotReport.d.ts +68 -0
  148. package/build/types/TestbotReport.js +1 -0
  149. package/build/types/index.d.ts +4 -0
  150. package/build/types/index.js +3 -0
  151. package/build/utils/AnalysisStateManager.d.ts +182 -0
  152. package/build/utils/AnalysisStateManager.js +10 -1
  153. package/build/utils/AnalysisStateManager.test.d.ts +1 -0
  154. package/build/utils/analyze-openapi.d.ts +1 -0
  155. package/build/utils/branchDiff.d.ts +18 -0
  156. package/build/utils/dartRouteExtractor.d.ts +45 -0
  157. package/build/utils/dartRouteExtractor.test.d.ts +1 -0
  158. package/build/utils/docker.d.ts +19 -0
  159. package/build/utils/docker.test.d.ts +1 -0
  160. package/build/utils/docker.test.js +10 -9
  161. package/build/utils/featureFlags.d.ts +37 -0
  162. package/build/utils/featureFlags.test.d.ts +1 -0
  163. package/build/utils/gitStaging.d.ts +24 -0
  164. package/build/utils/gitStaging.test.d.ts +1 -0
  165. package/build/utils/gitStaging.test.js +13 -7
  166. package/build/utils/httpDefaults.d.ts +10 -0
  167. package/build/utils/httpDefaults.test.d.ts +1 -0
  168. package/build/utils/initAgent.d.ts +36 -0
  169. package/build/utils/language-helper.d.ts +6 -0
  170. package/build/utils/logger.d.ts +11 -0
  171. package/build/utils/normalizeParams.d.ts +14 -0
  172. package/build/utils/normalizeSkyrampImports.d.ts +13 -0
  173. package/build/utils/pr-comment-parser.d.ts +31 -0
  174. package/build/utils/pr-comment-parser.test.d.ts +1 -0
  175. package/build/utils/pr-comment-parser.test.js +6 -5
  176. package/build/utils/projectMetadata.d.ts +15 -0
  177. package/build/utils/projectMetadata.test.d.ts +1 -0
  178. package/build/utils/proxy-terminal.d.ts +2 -0
  179. package/build/utils/repoScanner.d.ts +27 -0
  180. package/build/utils/repoScanner.test.d.ts +1 -0
  181. package/build/utils/routeParsers.d.ts +53 -0
  182. package/build/utils/routeParsers.js +31 -38
  183. package/build/utils/routeParsers.test.d.ts +1 -0
  184. package/build/utils/scenarioDrafting.d.ts +71 -0
  185. package/build/utils/scenarioDrafting.js +23 -1
  186. package/build/utils/scenarioDrafting.test.d.ts +1 -0
  187. package/build/utils/skyrampMdContent.d.ts +5 -0
  188. package/build/utils/sourceRouteExtractor.d.ts +48 -0
  189. package/build/utils/sourceRouteExtractor.test.d.ts +1 -0
  190. package/build/utils/telemetry.d.ts +32 -0
  191. package/build/utils/telemetry.test.d.ts +1 -0
  192. package/build/utils/trace-parser.d.ts +32 -0
  193. package/build/utils/trace-parser.test.d.ts +6 -0
  194. package/build/utils/uiPageEnumerator.d.ts +146 -0
  195. package/build/utils/uiPageEnumerator.js +58 -14
  196. package/build/utils/uiPageEnumerator.test.d.ts +1 -0
  197. package/build/utils/uiPageEnumerator.test.js +223 -43
  198. package/build/utils/utils.d.ts +45 -0
  199. package/build/utils/utils.js +10 -0
  200. package/build/utils/utils.test.d.ts +1 -0
  201. package/build/utils/versions.d.ts +3 -0
  202. package/build/utils/versions.js +1 -1
  203. package/build/utils/workspaceAuth.d.ts +127 -0
  204. package/build/utils/workspaceAuth.test.d.ts +1 -0
  205. package/build/utils/workspaceAuth.test.js +25 -25
  206. package/build/workspace/index.d.ts +1 -0
  207. package/build/workspace/workspace.d.ts +390 -0
  208. package/build/workspace/workspace.test.d.ts +1 -0
  209. package/node_modules/playwright/LICENSE +202 -0
  210. package/node_modules/playwright/NOTICE +5 -0
  211. package/node_modules/playwright/README.md +168 -0
  212. package/node_modules/playwright/lib/mcp/skyramp/traceRecordingBackend.js +13 -9
  213. package/node_modules/playwright/lib/mcp/test/skyRampExport.js +4 -3
  214. package/node_modules/playwright/node_modules/playwright-core/LICENSE +202 -0
  215. package/node_modules/playwright/node_modules/playwright-core/NOTICE +5 -0
  216. package/node_modules/playwright/node_modules/playwright-core/ThirdPartyNotices.txt +23 -126
  217. package/node_modules/playwright/node_modules/playwright-core/lib/vite/traceViewer/assets/{codeMirrorModule-B0JOjboO.js → codeMirrorModule-B5kqh2EV.js} +1 -1
  218. package/node_modules/playwright/node_modules/playwright-core/lib/vite/traceViewer/assets/{defaultSettingsView-1anWeyDf.js → defaultSettingsView-CZ9npQ3N.js} +79 -79
  219. package/node_modules/playwright/node_modules/playwright-core/lib/vite/traceViewer/{index.Cc5029a3.js → index.BCnxj-_b.js} +1 -1
  220. package/node_modules/playwright/node_modules/playwright-core/lib/vite/traceViewer/index.html +2 -2
  221. package/node_modules/playwright/node_modules/playwright-core/lib/vite/traceViewer/{uiMode.Wo5yvvVh.js → uiMode.1Ym0Ivn8.js} +1 -1
  222. package/node_modules/playwright/node_modules/playwright-core/lib/vite/traceViewer/uiMode.html +2 -2
  223. package/node_modules/playwright/node_modules/playwright-core/package.json +1 -1
  224. package/node_modules/playwright/package.json +1 -1
  225. package/package.json +16 -4
  226. package/build/tools/test-management/uiAnalyzeChangesTool.js +0 -155
  227. package/build/tools/test-management/uiAnalyzeChangesTool.test.js +0 -147
  228. package/node_modules/playwright/node_modules/playwright-core/.DS_Store +0 -0
  229. package/node_modules/playwright/node_modules/playwright-core/bundles/mcp/node_modules/.bin/node-which +0 -52
  230. package/node_modules/playwright/node_modules/playwright-core/bundles/utils/node_modules/.bin/is-docker +0 -5
  231. package/node_modules/playwright/node_modules/playwright-core/bundles/utils/node_modules/.bin/mime +0 -46
  232. package/node_modules/playwright/node_modules/playwright-core/bundles/utils/node_modules/.bin/yaml +0 -11
  233. package/node_modules/playwright/node_modules/playwright-core/lib/vite/traceViewer/index.CP3Y8Zsb.js +0 -2
@@ -6,6 +6,9 @@ import { AnalyticsService } from "../services/AnalyticsService.js";
6
6
  import { TEST_CATEGORIES, externalCategory } from "../types/TestRecommendation.js";
7
7
  import { TestType, HttpMethod } from "../types/TestTypes.js";
8
8
  import { DriftAction } from "../types/TestAnalysis.js";
9
+ import { TestExecutionStatus } from "../types/TestExecution.js";
10
+ import { StateManager } from "../utils/AnalysisStateManager.js";
11
+ import { toolError } from "../utils/utils.js";
9
12
  // Drift actions that actually modify a test file. VERIFY and IGNORE are
10
13
  // no-ops (the test was assessed but left unchanged), so they must not count
11
14
  // toward "tests maintained" telemetry.
@@ -21,12 +24,37 @@ const testResultSchema = z.object({
21
24
  endpoint: z.string().describe("HTTP verb and path, e.g. 'GET /api/v1/products'"),
22
25
  status: z.enum(["Pass", "Fail", "Skipped"]).describe("Test execution result"),
23
26
  details: z.string().describe("One sentence — no embedded newlines, no markdown. e.g. '10.8s, products_contract_test.py' or 'failed: <one-line error summary>, products_contract_test.py'"),
27
+ videoPath: z.string().optional().describe("Path to video recording (UI/E2E tests only)"),
28
+ });
29
+ // Structured grounding for UI recommendations. Lifted verbatim from a
30
+ // `browser_blueprint` element captured during this run. Source of truth for
31
+ // codegen (prefers testId > stableId > role+name for locator selection),
32
+ // the verifier (cross-checks each field against captured blueprints), and
33
+ // any future tooling that wants reliable grounding data without prose
34
+ // parsing. `reasoning` is free-form prose constrained by the Blueprint
35
+ // Citation Invariant — every element cited must appear in `targetElements`.
36
+ // See testbot prompt step 4 for the full populate-and-render rules.
37
+ export const targetElementSchema = z.object({
38
+ role: z.string().describe("ARIA role (e.g. 'button', 'heading', 'textbox', 'link'). Lifted verbatim from the captured blueprint element's `role` field."),
39
+ accessibleName: z.string().describe("Computed accessible name (e.g. 'Save changes', 'Order Details'). Lifted verbatim from the captured blueprint element's `accessibleName` field. Must match the bolded name in `reasoning` character-for-character."),
40
+ testId: z.string().nullable().describe("data-testid attribute value (preferred locator handle), or null when the element has no data-testid. Lifted from the blueprint element's `testId`."),
41
+ stableId: z.string().nullable().describe("Unique HTML id attribute value (fallback locator when no testId), or null. Lifted from the blueprint element's `stableId`."),
42
+ contextText: z.array(z.string()).nullable().describe("Disambiguating row text for elements inside repeating sections (table rows, list items): the row's surrounding non-interactive text. Lifted from the blueprint repeatingElement's items[].contextText. null for non-repeating elements."),
43
+ mutability: z.enum(["mutable", "immutable", "unknown"]).optional().describe("Whether the element's content/state is expected to change between captures. 'mutable' elements are behavioral-test targets; 'immutable' are smoke-test targets. Copied from the blueprint element's `mutability`."),
44
+ widgetType: z.enum(["native", "custom", "unknown"]).optional().describe("'native' = HTML built-ins (button, input). 'custom' or 'unknown' = non-standard composites; fall back to snapshot-driven trial clicks for interaction. Copied from the blueprint element's `widgetType`."),
45
+ });
46
+ // Page metadata for a UI recommendation. Lifted from the BlueprintCapture
47
+ // the agent used to populate `targetElements`. Codegen reads `url` to drive
48
+ // page.goto(); the verifier uses `pageHash` to detect stale captures.
49
+ export const pageContextSchema = z.object({
50
+ url: z.string().describe("URL of the page where the test runs. Lifted from BlueprintCapture.url."),
51
+ pageHash: z.string().optional().describe("Opaque hash of the captured page state (BlueprintCapture.pageHash). Lets the verifier confirm the recommendation was grounded in a still-current capture."),
24
52
  });
25
53
  // TODO: Unify newTestSchema and additionalRecommendationSchema into a single
26
54
  // interface that adds an `implemented: boolean` field. Both describe the same
27
55
  // concept (a test recommendation) — the only difference is whether it was
28
56
  // generated in this run or left for later. Tracked per Archit's review comment.
29
- const newTestSchema = z.object({
57
+ export const newTestSchema = z.object({
30
58
  testId: z.string().describe("Human-readable kebab-case identifier, e.g. 'contract-get-products' or 'integration-users-orders-workflow'. Format: '<testType>-<method>-<resource>' for single-endpoint tests or '<testType>-<scenario-slug>' for multi-step tests. Must be unique within the report."),
31
59
  testType: z.nativeEnum(TestType).describe("Type of test created. Do not include priority or other metadata in this field."),
32
60
  category: z.preprocess((val) => externalCategory(val), z.enum(TEST_CATEGORIES)).describe("Test category — critical categories (security_boundary, business_rule, data_integrity, breaking_change) get generation priority over workflow"),
@@ -37,6 +65,71 @@ const newTestSchema = z.object({
37
65
  traceFile: z.string().optional().describe("Path to the backend trace file if used or created"),
38
66
  frontendTrace: z.string().optional().describe("Path to the Playwright/UI trace file if used or created"),
39
67
  reasoning: z.string().describe("Why this test was created: what production risk it mitigates, what code pattern it targets, or what coverage gap it fills"),
68
+ targetElements: z.array(targetElementSchema).min(1).nullable().optional().describe("UI tests only: structured grounding for one or more elements the test targets. Most tests target a single element (array length 1); render-state and multi-step UI tests target several (array length 2+). Each entry must be lifted verbatim from a captured blueprint element. Set to null when blueprint capture failed (also requires '[no-blueprint-data]' marker in BOTH description and reasoning). See Blueprint Citation Invariant in testbot prompt."),
69
+ pageContext: pageContextSchema.optional().describe("UI tests only: page metadata for the test. Lifted from the BlueprintCapture used during grounding."),
70
+ }).superRefine((rec, ctx) => {
71
+ // targetElements / pageContext are UI-only.
72
+ if (rec.testType !== TestType.UI) {
73
+ for (const field of ["targetElements", "pageContext"]) {
74
+ if (rec[field] !== undefined) {
75
+ ctx.addIssue({
76
+ code: z.ZodIssueCode.custom,
77
+ path: [field],
78
+ message: `${field} is only valid for testType: 'ui'`,
79
+ });
80
+ }
81
+ }
82
+ }
83
+ else {
84
+ // description is required for UI tests (walkthrough of steps/assertions).
85
+ if (!rec.description) {
86
+ ctx.addIssue({
87
+ code: z.ZodIssueCode.custom,
88
+ path: ["description"],
89
+ message: "description is required for testType: 'ui'.",
90
+ });
91
+ }
92
+ // targetElements must be present (array or null — not omitted entirely).
93
+ if (rec.targetElements === undefined) {
94
+ ctx.addIssue({
95
+ code: z.ZodIssueCode.custom,
96
+ path: ["targetElements"],
97
+ message: "targetElements is required for testType: 'ui'. Use null when blueprint capture failed (and add '[no-blueprint-data]' to both description and reasoning).",
98
+ });
99
+ }
100
+ // pageContext is required when targetElements is an array (grounded), forbidden when null.
101
+ if (Array.isArray(rec.targetElements) && rec.pageContext === undefined) {
102
+ ctx.addIssue({
103
+ code: z.ZodIssueCode.custom,
104
+ path: ["pageContext"],
105
+ message: "pageContext is required for testType: 'ui' when targetElements is an array.",
106
+ });
107
+ }
108
+ if (rec.targetElements === null && rec.pageContext !== undefined) {
109
+ ctx.addIssue({
110
+ code: z.ZodIssueCode.custom,
111
+ path: ["pageContext"],
112
+ message: "pageContext must be omitted when targetElements is null (no blueprint data).",
113
+ });
114
+ }
115
+ // When targetElements is null, both description and reasoning must carry the '[no-blueprint-data]' marker.
116
+ if (rec.targetElements === null) {
117
+ if (!rec.reasoning.includes("[no-blueprint-data]")) {
118
+ ctx.addIssue({
119
+ code: z.ZodIssueCode.custom,
120
+ path: ["reasoning"],
121
+ message: "reasoning must contain '[no-blueprint-data]' when targetElements is null.",
122
+ });
123
+ }
124
+ if (rec.description && !rec.description.includes("[no-blueprint-data]")) {
125
+ ctx.addIssue({
126
+ code: z.ZodIssueCode.custom,
127
+ path: ["description"],
128
+ message: "description must contain '[no-blueprint-data]' when targetElements is null.",
129
+ });
130
+ }
131
+ }
132
+ }
40
133
  });
41
134
  const descriptionSchema = z.object({
42
135
  description: z.string().describe("One-line description. Do NOT prefix with the severity level — severity is a separate field. Include code logic bugs from the diff, test generation/execution failures, and environment misconfiguration."),
@@ -63,12 +156,14 @@ export const additionalRecommendationSchema = z.object({
63
156
  scenarioName: z.string().optional().describe("Proposed scenario name for future generation, e.g. 'products-orders-workflow'. No file exists yet — this is a suggestion only. Omit if not applicable."),
64
157
  // TODO: replace text with max(3) and check for regression
65
158
  steps: z.array(scenarioStepSchema).describe("Ordered sequence of API/UI steps in this test scenario (at most 3). Each step must include method and path so the endpoints are explicit. Omit requestBody and responseBody from steps."),
66
- description: z.string().describe("What this test does and why it is valuable. For multi-step scenarios, list the endpoints involved (e.g. 'POST /api/v1/products POST /api/v1/orders → PATCH /api/v1/orders/{id}') so the recommendation is actionable without primaryEndpoint."),
159
+ description: z.string().describe("Walkthrough of what the test does the steps and assertions. For multi-step scenarios, list the endpoints involved. The 'why it is valuable' belongs in reasoning."),
67
160
  priority: z.preprocess((val) => (typeof val === "string" ? val.toLowerCase() : val), z.enum(["high", "medium", "low"])).describe("Priority level: high, medium, or low. First check diff relevance — does the test target an endpoint changed in this PR? HIGH: diff-relevant security/auth/error tests, cross-resource isolation for diff endpoints, CRUD lifecycle for NEW endpoints in the diff. MEDIUM: diff-relevant business-rule happy paths, multi-resource workflows involving diff endpoints, security/error tests for NON-diff endpoints. LOW: tests targeting only unchanged endpoints, trivially discoverable happy paths duplicating generated tests."),
68
161
  openApiSpec: z.string().optional().describe("Path to OpenAPI/Swagger spec file if available, e.g. 'openapi.yaml'"),
69
162
  backendTrace: z.string().optional().describe("Path to backend trace file if available, e.g. 'tests/skyramp-traces.json'. Used by integration and E2E tests."),
70
163
  frontendTrace: z.string().optional().describe("Path to Playwright/UI trace file if available, e.g. 'tests/skyramp-playwright.zip'. UI tests need this; E2E tests need both frontend and backend traces."),
71
164
  reasoning: z.string().describe("Why this test is recommended: the specific production risk, business rule, or security boundary it would validate"),
165
+ targetElements: z.array(targetElementSchema).min(1).nullable().optional().describe("UI tests only: structured grounding for one or more elements the test targets. Most tests target a single element (array length 1); render-state and multi-step UI tests target several (array length 2+). Each entry must be lifted verbatim from a captured blueprint element. Set to null when blueprint capture failed (also requires '[no-blueprint-data]' marker in BOTH description and reasoning). See Blueprint Citation Invariant in testbot prompt."),
166
+ pageContext: pageContextSchema.optional().describe("UI tests only: page metadata for the test. Lifted from the BlueprintCapture used during grounding."),
72
167
  }).superRefine((rec, ctx) => {
73
168
  if (rec.testType === TestType.CONTRACT && !rec.primaryEndpoint) {
74
169
  ctx.addIssue({
@@ -77,6 +172,57 @@ export const additionalRecommendationSchema = z.object({
77
172
  message: "primaryEndpoint is required for contract tests — provide the HTTP verb and path, e.g. 'PATCH /api/v1/orders/{order_id}'.",
78
173
  });
79
174
  }
175
+ // targetElements / pageContext are UI-only.
176
+ if (rec.testType !== TestType.UI) {
177
+ for (const field of ["targetElements", "pageContext"]) {
178
+ if (rec[field] !== undefined) {
179
+ ctx.addIssue({
180
+ code: z.ZodIssueCode.custom,
181
+ path: [field],
182
+ message: `${field} is only valid for testType: 'ui'`,
183
+ });
184
+ }
185
+ }
186
+ }
187
+ else {
188
+ if (rec.targetElements === undefined) {
189
+ ctx.addIssue({
190
+ code: z.ZodIssueCode.custom,
191
+ path: ["targetElements"],
192
+ message: "targetElements is required for testType: 'ui'. Use null when blueprint capture failed (and add '[no-blueprint-data]' to both description and reasoning).",
193
+ });
194
+ }
195
+ if (Array.isArray(rec.targetElements) && rec.pageContext === undefined) {
196
+ ctx.addIssue({
197
+ code: z.ZodIssueCode.custom,
198
+ path: ["pageContext"],
199
+ message: "pageContext is required for testType: 'ui' when targetElements is an array.",
200
+ });
201
+ }
202
+ if (rec.targetElements === null && rec.pageContext !== undefined) {
203
+ ctx.addIssue({
204
+ code: z.ZodIssueCode.custom,
205
+ path: ["pageContext"],
206
+ message: "pageContext must be omitted when targetElements is null (no blueprint data).",
207
+ });
208
+ }
209
+ if (rec.targetElements === null) {
210
+ if (!rec.reasoning.includes("[no-blueprint-data]")) {
211
+ ctx.addIssue({
212
+ code: z.ZodIssueCode.custom,
213
+ path: ["reasoning"],
214
+ message: "reasoning must contain '[no-blueprint-data]' when targetElements is null.",
215
+ });
216
+ }
217
+ if (!rec.description.includes("[no-blueprint-data]")) {
218
+ ctx.addIssue({
219
+ code: z.ZodIssueCode.custom,
220
+ path: ["description"],
221
+ message: "description must contain '[no-blueprint-data]' when targetElements is null.",
222
+ });
223
+ }
224
+ }
225
+ }
80
226
  });
81
227
  const testMaintenanceSchema = z.object({
82
228
  testType: z.nativeEnum(TestType).describe("Type of test."),
@@ -84,13 +230,25 @@ const testMaintenanceSchema = z.object({
84
230
  fileName: z.string().describe("Test file that was maintained, e.g. 'products_smoke_test.py'"),
85
231
  action: z.nativeEnum(DriftAction).describe("The drift action assigned to this test during maintenance triage."),
86
232
  description: z.string().describe("What was changed and why"),
87
- beforeStatus: z.enum(["Pass", "Fail", "Error"]).describe("Test result BEFORE modification"),
88
- beforeDetails: z.string().describe("Execution output/timing before modification, or 'baseline from CI workflow <name>' if a parallel workflow provided the baseline"),
89
- afterStatus: z.enum(["Pass", "Fail", "Error", "Skipped"]).describe("Test result AFTER modification"),
90
- afterDetails: z.string().describe("Execution output/timing after modification"),
91
- })
92
- .refine(m => ![DriftAction.Verify, DriftAction.Ignore].includes(m.action) || m.afterStatus === "Skipped", { message: "VERIFY and IGNORE entries must have afterStatus: 'Skipped' these actions do not modify the test file" })
93
- .refine(m => ![DriftAction.Update, DriftAction.Regenerate, DriftAction.Delete].includes(m.action) || m.afterStatus !== "Skipped", { message: "UPDATE, REGENERATE, and DELETE entries must have a real afterStatus (not Skipped) — these actions modify the test file and must be executed" });
233
+ beforeDetails: z.string().describe("One line only — no embedded newlines, no raw HTTP headers or JSON blobs. " +
234
+ "For passing runs: count and timing, e.g. '4 passed in 15.09s'. " +
235
+ "For failing runs: failure name and one-line root cause, e.g. " +
236
+ "'FAILED test_foo assert 403 got 200, auth middleware not enforced'. " +
237
+ "Empty string for VERIFY/IGNORE entries where no before-execution was run."),
238
+ afterDetails: z.string().describe("One line only no embedded newlines, no raw HTTP headers or JSON blobs. " +
239
+ "For passing runs: count and timing, e.g. '5 passed in 10.96s'. " +
240
+ "For failing runs: failure name and one-line root cause, e.g. " +
241
+ "'FAILED test_foo — check_schema fails, order_id=1 has discount from prior PATCH test'. " +
242
+ "Empty string for VERIFY/IGNORE/DELETE entries where no after-execution was run."),
243
+ // Server-populated from stateFile execution records — never supplied by the LLM.
244
+ beforeStatus: z.nativeEnum(TestExecutionStatus),
245
+ afterStatus: z.nativeEnum(TestExecutionStatus),
246
+ });
247
+ // LLM input contract: status fields are server-populated from stateFile.
248
+ const testMaintenanceLLMSchema = testMaintenanceSchema.omit({
249
+ beforeStatus: true,
250
+ afterStatus: true,
251
+ });
94
252
  /**
95
253
  * Derive per-run analytics counts from a submitted report. These power the
96
254
  * alpha-launch dashboards (tests generated/maintained, suite growth, bugs vs
@@ -114,7 +272,7 @@ function computeReportMetrics(params) {
114
272
  const recommendations = params.additionalRecommendations ?? [];
115
273
  const countBy = (items, pred) => items.filter(pred).length;
116
274
  const changedMaintenance = (params.testMaintenance ?? []).filter(isMaintenanceChange);
117
- const maintenanceRecovered = countBy(changedMaintenance, (m) => m.beforeStatus !== "Pass" && m.afterStatus === "Pass");
275
+ const maintenanceRecovered = countBy(changedMaintenance, (m) => (m.beforeStatus === TestExecutionStatus.Fail || m.beforeStatus === TestExecutionStatus.Error) && m.afterStatus === TestExecutionStatus.Pass);
118
276
  return {
119
277
  testsGenerated: String(params.newTestsCreated.length),
120
278
  testsMaintained: String(changedMaintenance.length),
@@ -130,6 +288,23 @@ function computeReportMetrics(params) {
130
288
  issuesLow: String(countBy(params.issuesFound, (i) => i.severity === "low")),
131
289
  };
132
290
  }
291
+ function deduplicateById(items) {
292
+ const seen = new Set();
293
+ const result = [];
294
+ for (const item of items) {
295
+ let id = item.testId;
296
+ if (seen.has(id)) {
297
+ let suffix = 2;
298
+ while (seen.has(`${id}-${suffix}`))
299
+ suffix++;
300
+ id = `${id}-${suffix}`;
301
+ item.testId = id;
302
+ }
303
+ seen.add(id);
304
+ result.push(item);
305
+ }
306
+ return result;
307
+ }
133
308
  export function registerSubmitReportTool(server) {
134
309
  server.registerTool(TOOL_NAME, {
135
310
  description: "Submit the final testbot report. Call this tool once after completing all test analysis, generation, and execution. " +
@@ -150,9 +325,9 @@ export function registerSubmitReportTool(server) {
150
325
  .default([])
151
326
  .describe("Recommended tests that were not generated (lower priority). Only include recommendations that add distinct coverage beyond generated tests — do not pad with variants testing the same endpoint and flow."),
152
327
  testMaintenance: z
153
- .array(testMaintenanceSchema)
328
+ .array(testMaintenanceLLMSchema)
154
329
  .optional()
155
- .describe("One entry per test assessed in the drift analysis step. Omit this field when no existing tests were found."),
330
+ .describe("One entry per test assessed in the drift analysis step, including IGNORE and VERIFY entries — these provide triage transparency even when no edits were needed. Omit this field entirely when no existing tests were found."),
156
331
  testResults: z
157
332
  .array(testResultSchema)
158
333
  .describe("List of ALL test execution results. One entry per test executed."),
@@ -175,6 +350,12 @@ export function registerSubmitReportTool(server) {
175
350
  .describe("Succinct commit message (if possible, under 72 chars) summarizing what Testbot did, " +
176
351
  "e.g. 'add contract tests for /products endpoint' or 'update smoke tests for order API changes'. " +
177
352
  "Used as both the git commit subject and the side PR title — the consumer applies truncation as needed."),
353
+ stateFile: z
354
+ .string()
355
+ .describe("Path to the state file returned by skyramp_analyze_changes. Required — " +
356
+ "contains execution results for maintenance scoring (existingTests), " +
357
+ "discovered endpoints for coverage validation (newEndpoints), and " +
358
+ "UI page context for frontend test grounding (uiContext)."),
178
359
  },
179
360
  _meta: {
180
361
  keywords: ["report", "summary", "testbot", "submit"],
@@ -182,40 +363,50 @@ export function registerSubmitReportTool(server) {
182
363
  }, async (params) => {
183
364
  const startTime = Date.now();
184
365
  let errorResult;
185
- const deduplicateById = (items) => {
186
- const seen = new Set();
187
- const result = [];
188
- for (const item of items) {
189
- let id = item.testId;
190
- if (seen.has(id)) {
191
- let suffix = 2;
192
- while (seen.has(`${id}-${suffix}`))
193
- suffix++;
194
- id = `${id}-${suffix}`;
195
- item.testId = id;
196
- }
197
- seen.add(id);
198
- result.push(item);
199
- }
200
- return result;
201
- };
202
366
  const dedupedNewTests = deduplicateById([...params.newTestsCreated]);
203
367
  const dedupedRecommendations = deduplicateById([...(params.additionalRecommendations ?? [])]);
368
+ let testMaintenance;
369
+ if (params.testMaintenance) {
370
+ try {
371
+ const stateData = await StateManager.fromStatePath(params.stateFile).readData();
372
+ if (!stateData) {
373
+ errorResult = toolError(`stateFile not found or empty: ${params.stateFile}`);
374
+ return errorResult;
375
+ }
376
+ // Status fields are stateFile-authoritative. Details are LLM-supplied when present
377
+ // (single-line, with root-cause context) and fall back to server-side extraction.
378
+ testMaintenance = params.testMaintenance.map((m) => {
379
+ const recorded = stateData.existingTests?.find((t) => t.testFile.endsWith(m.fileName) || path.basename(t.testFile) === path.basename(m.fileName));
380
+ const defaultBeforeStatus = MAINTENANCE_CHANGE_ACTIONS.has(m.action) ? TestExecutionStatus.Unknown : TestExecutionStatus.Skipped;
381
+ const defaultAfterStatus = m.action === DriftAction.Delete ? TestExecutionStatus.Skipped
382
+ : MAINTENANCE_CHANGE_ACTIONS.has(m.action) ? TestExecutionStatus.Unknown : TestExecutionStatus.Skipped;
383
+ const beforeStatus = recorded?.executionBefore?.status ?? defaultBeforeStatus;
384
+ const afterStatus = recorded?.executionAfter?.status ?? defaultAfterStatus;
385
+ logger.info(`${m.fileName}: before=${beforeStatus} after=${afterStatus}`);
386
+ return { ...m, beforeStatus, afterStatus };
387
+ });
388
+ }
389
+ catch (err) {
390
+ errorResult = toolError(`Failed to load stateFile for maintenance enrichment: ${err.message}`);
391
+ return errorResult;
392
+ }
393
+ }
204
394
  // Strip generation-artifact fields from newTestsCreated before writing.
205
395
  // scenarioFile, traceFile, frontendTrace are internal paths used during
206
396
  // generation — downstream scoring scripts don't expect them and fail if
207
397
  // they encounter these string fields while traversing the object.
208
398
  const sanitizedNewTests = dedupedNewTests.map(({ scenarioFile: _sf, traceFile: _tf, frontendTrace: _ft, ...rest }) => rest);
209
- const reportJson = JSON.stringify({
399
+ const report = {
210
400
  businessCaseAnalysis: params.businessCaseAnalysis,
211
401
  newTestsCreated: sanitizedNewTests,
212
402
  additionalRecommendations: dedupedRecommendations,
213
- testMaintenance: params.testMaintenance,
403
+ testMaintenance,
214
404
  testResults: params.testResults,
215
405
  issuesFound: params.issuesFound,
216
406
  nextSteps: params.nextSteps ?? [],
217
407
  commitMessage: (params.commitMessage ?? "").replace(/[\r\n]+/g, " ").trim() || DEFAULT_COMMIT_MESSAGE,
218
- }, null, 2);
408
+ };
409
+ const reportJson = JSON.stringify(report, null, 2);
219
410
  logger.info("Submitting testbot report", {
220
411
  outputFile: params.summaryOutputFile,
221
412
  payloadBytes: reportJson.length,
@@ -242,10 +433,7 @@ export function registerSubmitReportTool(server) {
242
433
  const elapsed = Date.now() - startTime;
243
434
  const errorMessage = `Failed to write report: ${error.message}`;
244
435
  logger.error(errorMessage, { error, elapsedMs: elapsed });
245
- errorResult = {
246
- content: [{ type: "text", text: errorMessage }],
247
- isError: true,
248
- };
436
+ errorResult = toolError(errorMessage);
249
437
  return errorResult;
250
438
  }
251
439
  finally {
@@ -253,7 +441,7 @@ export function registerSubmitReportTool(server) {
253
441
  summary_output_file: params.summaryOutputFile,
254
442
  testResultCount: String(params.testResults.length),
255
443
  payloadBytes: String(reportJson.length),
256
- ...computeReportMetrics(params),
444
+ ...computeReportMetrics({ ...params, testMaintenance }),
257
445
  }).catch(() => { });
258
446
  }
259
447
  });
@@ -0,0 +1 @@
1
+ export {};