digital-ai-testing-mcp 1.2.8 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (191) hide show
  1. package/README.md +148 -46
  2. package/dist/api/browser-inspection.d.ts.map +1 -1
  3. package/dist/api/browser-inspection.js +14 -15
  4. package/dist/api/browser-inspection.js.map +1 -1
  5. package/dist/api/client.d.ts +7 -0
  6. package/dist/api/client.d.ts.map +1 -1
  7. package/dist/api/client.js +9 -0
  8. package/dist/api/client.js.map +1 -1
  9. package/dist/api/projects.d.ts +16 -3
  10. package/dist/api/projects.d.ts.map +1 -1
  11. package/dist/api/projects.js +60 -18
  12. package/dist/api/projects.js.map +1 -1
  13. package/dist/api/reporting.d.ts +91 -0
  14. package/dist/api/reporting.d.ts.map +1 -1
  15. package/dist/api/reporting.js +182 -8
  16. package/dist/api/reporting.js.map +1 -1
  17. package/dist/api/test-orchestrator.d.ts +59 -0
  18. package/dist/api/test-orchestrator.d.ts.map +1 -0
  19. package/dist/api/test-orchestrator.js +126 -0
  20. package/dist/api/test-orchestrator.js.map +1 -0
  21. package/dist/api/test-runs.d.ts +80 -0
  22. package/dist/api/test-runs.d.ts.map +1 -0
  23. package/dist/api/test-runs.js +209 -0
  24. package/dist/api/test-runs.js.map +1 -0
  25. package/dist/api/test-views.d.ts.map +1 -1
  26. package/dist/api/test-views.js +5 -1
  27. package/dist/api/test-views.js.map +1 -1
  28. package/dist/api/transactions.d.ts +6 -0
  29. package/dist/api/transactions.d.ts.map +1 -1
  30. package/dist/api/transactions.js +19 -3
  31. package/dist/api/transactions.js.map +1 -1
  32. package/dist/api/usage-reports.d.ts.map +1 -1
  33. package/dist/api/usage-reports.js +3 -3
  34. package/dist/api/usage-reports.js.map +1 -1
  35. package/dist/api/webdriver.d.ts +44 -1
  36. package/dist/api/webdriver.d.ts.map +1 -1
  37. package/dist/api/webdriver.js +194 -67
  38. package/dist/api/webdriver.js.map +1 -1
  39. package/dist/index.js +80 -32
  40. package/dist/index.js.map +1 -1
  41. package/dist/tools/agent-tools.js +2 -2
  42. package/dist/tools/agent-tools.js.map +1 -1
  43. package/dist/tools/application-tools.d.ts.map +1 -1
  44. package/dist/tools/application-tools.js +5 -4
  45. package/dist/tools/application-tools.js.map +1 -1
  46. package/dist/tools/boilerplate-tools.d.ts +3 -0
  47. package/dist/tools/boilerplate-tools.d.ts.map +1 -1
  48. package/dist/tools/boilerplate-tools.js +301 -20
  49. package/dist/tools/boilerplate-tools.js.map +1 -1
  50. package/dist/tools/browser-tools.d.ts.map +1 -1
  51. package/dist/tools/browser-tools.js +8 -5
  52. package/dist/tools/browser-tools.js.map +1 -1
  53. package/dist/tools/device-group-tools.js +5 -5
  54. package/dist/tools/device-group-tools.js.map +1 -1
  55. package/dist/tools/device-tools.d.ts.map +1 -1
  56. package/dist/tools/device-tools.js +5 -4
  57. package/dist/tools/device-tools.js.map +1 -1
  58. package/dist/tools/health-tools.d.ts.map +1 -1
  59. package/dist/tools/health-tools.js +5 -4
  60. package/dist/tools/health-tools.js.map +1 -1
  61. package/dist/tools/inspection-tools.d.ts.map +1 -1
  62. package/dist/tools/inspection-tools.js +112 -10
  63. package/dist/tools/inspection-tools.js.map +1 -1
  64. package/dist/tools/meta-tools.d.ts +4 -1
  65. package/dist/tools/meta-tools.d.ts.map +1 -1
  66. package/dist/tools/meta-tools.js +62 -36
  67. package/dist/tools/meta-tools.js.map +1 -1
  68. package/dist/tools/performance-tools.d.ts.map +1 -1
  69. package/dist/tools/performance-tools.js +1 -7
  70. package/dist/tools/performance-tools.js.map +1 -1
  71. package/dist/tools/project-tools.d.ts.map +1 -1
  72. package/dist/tools/project-tools.js +38 -19
  73. package/dist/tools/project-tools.js.map +1 -1
  74. package/dist/tools/provisioning-profile-tools.d.ts.map +1 -1
  75. package/dist/tools/provisioning-profile-tools.js +5 -4
  76. package/dist/tools/provisioning-profile-tools.js.map +1 -1
  77. package/dist/tools/remediation-tools.d.ts +7 -0
  78. package/dist/tools/remediation-tools.d.ts.map +1 -0
  79. package/dist/tools/remediation-tools.js +50 -0
  80. package/dist/tools/remediation-tools.js.map +1 -0
  81. package/dist/tools/reporting-tools.d.ts.map +1 -1
  82. package/dist/tools/reporting-tools.js +369 -136
  83. package/dist/tools/reporting-tools.js.map +1 -1
  84. package/dist/tools/repository-tools.d.ts.map +1 -1
  85. package/dist/tools/repository-tools.js +5 -4
  86. package/dist/tools/repository-tools.js.map +1 -1
  87. package/dist/tools/reservation-tools.js +2 -2
  88. package/dist/tools/reservation-tools.js.map +1 -1
  89. package/dist/tools/test-run-tools.d.ts +3 -0
  90. package/dist/tools/test-run-tools.d.ts.map +1 -0
  91. package/dist/tools/test-run-tools.js +284 -0
  92. package/dist/tools/test-run-tools.js.map +1 -0
  93. package/dist/tools/test-view-tools.d.ts.map +1 -1
  94. package/dist/tools/test-view-tools.js +11 -11
  95. package/dist/tools/test-view-tools.js.map +1 -1
  96. package/dist/tools/toolset-tools.d.ts +8 -0
  97. package/dist/tools/toolset-tools.d.ts.map +1 -0
  98. package/dist/tools/toolset-tools.js +40 -0
  99. package/dist/tools/toolset-tools.js.map +1 -0
  100. package/dist/tools/transaction-tools.d.ts.map +1 -1
  101. package/dist/tools/transaction-tools.js +17 -7
  102. package/dist/tools/transaction-tools.js.map +1 -1
  103. package/dist/tools/usage-report-tools.d.ts.map +1 -1
  104. package/dist/tools/usage-report-tools.js +43 -15
  105. package/dist/tools/usage-report-tools.js.map +1 -1
  106. package/dist/tools/user-tools.js +2 -2
  107. package/dist/tools/user-tools.js.map +1 -1
  108. package/dist/tools/web-inspection-tools.d.ts.map +1 -1
  109. package/dist/tools/web-inspection-tools.js +39 -26
  110. package/dist/tools/web-inspection-tools.js.map +1 -1
  111. package/dist/tools/workflow-tools.js +1 -1
  112. package/dist/types/digital-ai.d.ts +18 -3
  113. package/dist/types/digital-ai.d.ts.map +1 -1
  114. package/dist/utils/browser-name.d.ts +2 -0
  115. package/dist/utils/browser-name.d.ts.map +1 -0
  116. package/dist/utils/browser-name.js +19 -0
  117. package/dist/utils/browser-name.js.map +1 -0
  118. package/dist/utils/command-payload.d.ts +19 -0
  119. package/dist/utils/command-payload.d.ts.map +1 -0
  120. package/dist/utils/command-payload.js +13 -0
  121. package/dist/utils/command-payload.js.map +1 -0
  122. package/dist/utils/csv.d.ts +6 -0
  123. package/dist/utils/csv.d.ts.map +1 -1
  124. package/dist/utils/csv.js +28 -2
  125. package/dist/utils/csv.js.map +1 -1
  126. package/dist/utils/locality.d.ts +7 -0
  127. package/dist/utils/locality.d.ts.map +1 -1
  128. package/dist/utils/locality.js +19 -0
  129. package/dist/utils/locality.js.map +1 -1
  130. package/dist/utils/maestro-flow.d.ts +38 -0
  131. package/dist/utils/maestro-flow.d.ts.map +1 -0
  132. package/dist/utils/maestro-flow.js +114 -0
  133. package/dist/utils/maestro-flow.js.map +1 -0
  134. package/dist/utils/metric-semantics.d.ts +22 -0
  135. package/dist/utils/metric-semantics.d.ts.map +1 -0
  136. package/dist/utils/metric-semantics.js +24 -0
  137. package/dist/utils/metric-semantics.js.map +1 -0
  138. package/dist/utils/pagination.d.ts +11 -0
  139. package/dist/utils/pagination.d.ts.map +1 -1
  140. package/dist/utils/pagination.js +16 -0
  141. package/dist/utils/pagination.js.map +1 -1
  142. package/dist/utils/remediation.d.ts +130 -0
  143. package/dist/utils/remediation.d.ts.map +1 -0
  144. package/dist/utils/remediation.js +424 -0
  145. package/dist/utils/remediation.js.map +1 -0
  146. package/dist/utils/report-ref.d.ts +23 -0
  147. package/dist/utils/report-ref.d.ts.map +1 -0
  148. package/dist/utils/report-ref.js +31 -0
  149. package/dist/utils/report-ref.js.map +1 -0
  150. package/dist/utils/response-formatter.d.ts +2 -1
  151. package/dist/utils/response-formatter.d.ts.map +1 -1
  152. package/dist/utils/response-formatter.js +32 -21
  153. package/dist/utils/response-formatter.js.map +1 -1
  154. package/dist/utils/test-orchestrator.d.ts +102 -0
  155. package/dist/utils/test-orchestrator.d.ts.map +1 -0
  156. package/dist/utils/test-orchestrator.js +236 -0
  157. package/dist/utils/test-orchestrator.js.map +1 -0
  158. package/dist/utils/test-status.d.ts +48 -0
  159. package/dist/utils/test-status.d.ts.map +1 -0
  160. package/dist/utils/test-status.js +92 -0
  161. package/dist/utils/test-status.js.map +1 -0
  162. package/dist/utils/tool-catalog.d.ts +6 -0
  163. package/dist/utils/tool-catalog.d.ts.map +1 -0
  164. package/dist/utils/tool-catalog.js +15 -0
  165. package/dist/utils/tool-catalog.js.map +1 -0
  166. package/dist/utils/toolsets.d.ts +79 -0
  167. package/dist/utils/toolsets.d.ts.map +1 -0
  168. package/dist/utils/toolsets.js +156 -0
  169. package/dist/utils/toolsets.js.map +1 -0
  170. package/dist/utils/usage-report-guard.d.ts +7 -0
  171. package/dist/utils/usage-report-guard.d.ts.map +1 -1
  172. package/dist/utils/usage-report-guard.js +18 -1
  173. package/dist/utils/usage-report-guard.js.map +1 -1
  174. package/dist/utils/usage-report-summary.d.ts +12 -0
  175. package/dist/utils/usage-report-summary.d.ts.map +1 -1
  176. package/dist/utils/usage-report-summary.js +25 -6
  177. package/dist/utils/usage-report-summary.js.map +1 -1
  178. package/package.json +41 -4
  179. package/resources/boilerplate/Android-Native/Java JUnit5/gradle +6 -1
  180. package/resources/boilerplate/Android-Native/Java JUnit5/gradle-oss +6 -1
  181. package/resources/boilerplate/Android-Native/java TestNG/AndroidNative-oss.java +2 -2
  182. package/resources/boilerplate/Android-Native/java TestNG/AndroidNative.java +2 -2
  183. package/resources/boilerplate/Android-Native/java TestNG/gradle +1 -1
  184. package/resources/boilerplate/Android-Native/java TestNG/gradle-oss +1 -1
  185. package/resources/boilerplate/iOS-Native/java-JUnit5/gradle +6 -1
  186. package/resources/boilerplate/iOS-Native/java-JUnit5/gradle-oss +6 -1
  187. package/resources/boilerplate/iOS-Native/java-TestNG/gradle +1 -1
  188. package/resources/boilerplate/iOS-Native/java-TestNG/gradle-oss +1 -1
  189. package/resources/boilerplate/iOS-Native/java-TestNG/iOSNative-oss.java +2 -2
  190. package/resources/boilerplate/iOS-Native/java-TestNG/iOSNative.java +2 -2
  191. package/resources/test-orchestrator/agent.json +19 -0
@@ -1,5 +1,6 @@
1
1
  import { z } from 'zod';
2
- import { getTestById, getTestByReportApiId, listTests, listTestsSortedDesc, getGroupedTests, getDistinctKeyValues, deleteTests, downloadTestAttachments, extractAttachmentLog, summarizeTestFailures, } from '../api/reporting.js';
2
+ import { getTestById, getTestByUuid, shareTestReport, getRootCauseAnalysis, RCA_MAX_ATTEMPTS, getTestByReportApiId, listTests, listTestsSortedDesc, getGroupedTests, getDistinctKeyValues, deleteTests, downloadTestAttachments, downloadTestVideo, getTestVideoInfo, extractAttachmentLog, summarizeTestFailures, } from '../api/reporting.js';
3
+ import { normaliseDeviceOs } from '../api/transactions.js';
3
4
  import { serverFsDownloadNotice, serverFsOutputParam, commandGeneratorNotice, localPlatformParamNotice } from '../utils/locality.js';
4
5
  import { checkDeleteAllowed, serverSortAvailable } from '../api/access-level.js';
5
6
  import { checkDestructiveGuard } from '../utils/destructive-guard.js';
@@ -7,53 +8,156 @@ import { validateOutputPath } from '../utils/path-guard.js';
7
8
  import { buildDownloadCommand } from '../utils/download-command.js';
8
9
  import { formatTestReport, formatTestReportList, formatFailureSummary, formatTestAttachments, formatGroupedTestReports, formatProjectTestSummary, } from '../utils/response-formatter.js';
9
10
  import { outputFormatParam, respond } from '../utils/output-format.js';
11
+ import { commandPayload } from '../utils/command-payload.js';
12
+ import { parseReportRef } from '../utils/report-ref.js';
13
+ import { countsFromPivotRow, tallyStatuses, passRate, statusOutcome, unknownStatusCount, PASS_RATE_BASIS } from '../utils/test-status.js';
10
14
  export function registerReportingTools(server) {
11
15
  // ─── get_test_report ───────────────────────────────────────────────────────
12
- server.tool('get_test_report', 'Retrieve a full test execution report by its numeric test ID or by the report URL printed in tearDown (digitalai:reportUrl capability). ' +
13
- 'Provide either testId OR reportUrl — reportUrl is parsed to extract the numeric test ID automatically. ' +
14
- 'The test ID (test_id field) is also returned by list_test_reports and find_latest_test_for_name. ' +
15
- 'NOTE: Step-level detail is not available via numeric test ID — the backend API does not support it on this endpoint. ' +
16
+ server.tool('get_test_report', 'Retrieve a full test execution report by UUID, numeric test ID, or the report URL printed in tearDown (digitalai:reportUrl — e.g. .../reporter/video-report/<uuid>). ' +
17
+ 'Provide ONE of uuid, testId or reportUrl. PREFER uuid (or the report URL): UUIDs are global, while numeric test IDs are only unique per project and can resolve to a different test in another project. ' +
18
+ 'uuid and test_id are both returned by list_test_reports and find_latest_test_for_name. ' +
19
+ 'The single report has projectName but no status_code/project_id (those exist only on list records); its attachment_count ' +
20
+ 'counts the attachment files (as list_test_attachments does), which can be higher than the list record\'s figure. ' +
21
+ 'NOTE: Step-level detail is not available on this endpoint — the backend API does not support it here. ' +
16
22
  'To get steps, use get_test_by_report_id with the report_api_id from a live session. ' +
17
23
  'For failure diagnosis use the cause/errorCategory/errorDetail fields in this response, or get_test_log for the full Appium log.', {
18
- testId: z.number().int().optional().describe('The numeric test ID (test_id field from list results, e.g. 377918). Provide this OR reportUrl.'),
19
- reportUrl: z.string().optional().describe('The report URL printed by tearDown (digitalai:reportUrl capability value). The numeric test ID is extracted automatically.'),
24
+ uuid: z.string().optional().describe('The test execution UUID (uuid field from list results). Preferred — globally unique.'),
25
+ testId: z.number().int().optional().describe('The numeric test ID (test_id field from list results, e.g. 377918). Unique only within a project — prefer uuid.'),
26
+ reportUrl: z.string().optional().describe('The report URL printed by tearDown (digitalai:reportUrl), e.g. .../reporter/video-report/<uuid> or an older ...?test_id=<n> link. The identifier is extracted automatically.'),
20
27
  outputFormat: outputFormatParam,
21
- }, async ({ testId, reportUrl, outputFormat }) => {
22
- let resolvedId = testId;
23
- if (!resolvedId && reportUrl) {
24
- const UUID_RE = /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/i;
25
- const numericMatch = reportUrl.match(/\/(\d+)\/?(?:\?.*)?$/);
26
- if (numericMatch) {
27
- resolvedId = parseInt(numericMatch[1], 10);
28
- }
29
- else if (UUID_RE.test(reportUrl)) {
28
+ }, async ({ uuid, testId, reportUrl, outputFormat }) => {
29
+ const given = [uuid, testId, reportUrl].filter((v) => v != null && v !== '').length;
30
+ if (given === 0) {
31
+ return { content: [{ type: 'text', text: 'Provide one of uuid, testId or reportUrl.' }], isError: true };
32
+ }
33
+ if (given > 1) {
34
+ return { content: [{ type: 'text', text: 'Provide only ONE of uuid, testId or reportUrl — they could point at different reports.' }], isError: true };
35
+ }
36
+ const ref = parseReportRef(uuid ?? reportUrl ?? testId);
37
+ if (!ref) {
38
+ return {
39
+ content: [{ type: 'text', text: `Could not find a report UUID or numeric test ID in: ${uuid ?? reportUrl}. Use list_test_reports or find_latest_test_for_name to look the test up.` }],
40
+ isError: true,
41
+ };
42
+ }
43
+ try {
44
+ const report = ref.kind === 'uuid' ? await getTestByUuid(ref.uuid) : await getTestById(ref.testId);
45
+ return respond(outputFormat, report, formatTestReport(report));
46
+ }
47
+ catch (e) {
48
+ return { content: [{ type: 'text', text: `Error: ${e.message}` }], isError: true };
49
+ }
50
+ });
51
+ // ─── share_test_report ─────────────────────────────────────────────────────
52
+ server.tool('share_test_report', 'Create a PUBLIC link to a test report that anyone can open WITHOUT logging in — the report page, its data (including ' +
53
+ 'key-value pairs/capabilities) and its video. Links expire 14 days after first creation; sharing the same report again ' +
54
+ 'returns the same link and does NOT extend it. There is no revoke: the only way to disable a link early is to delete the ' +
55
+ 'report (delete_test_reports). Requires confirmPublicShare: true — without it, this returns a preview of what would be ' +
56
+ 'exposed and shares nothing. Only share when the user explicitly asked for a public/shareable link. ' +
57
+ 'Fails if public sharing is disabled for the report\'s project.', {
58
+ uuid: z.string().optional().describe('Test execution UUID (uuid field from list_test_reports / get_test_report).'),
59
+ reportUrl: z.string().optional().describe('The report URL (e.g. .../reporter/video-report/<uuid>). Must contain the UUID.'),
60
+ confirmPublicShare: z
61
+ .boolean()
62
+ .optional()
63
+ .describe('Must be true to create the public link. Omit to preview what would be shared.'),
64
+ outputFormat: outputFormatParam,
65
+ }, async ({ uuid, reportUrl, confirmPublicShare, outputFormat }) => {
66
+ if ((uuid ? 1 : 0) + (reportUrl ? 1 : 0) !== 1) {
67
+ return { content: [{ type: 'text', text: 'Provide exactly one of uuid or reportUrl.' }], isError: true };
68
+ }
69
+ const ref = parseReportRef(uuid ?? reportUrl);
70
+ if (ref?.kind !== 'uuid') {
71
+ return {
72
+ content: [{ type: 'text', text: 'Sharing needs the report UUID (numeric test IDs are not accepted). Get it from list_test_reports or get_test_report (uuid field), or pass the .../video-report/<uuid> URL.' }],
73
+ isError: true,
74
+ };
75
+ }
76
+ try {
77
+ // Fetch first: confirms the report exists and is visible to this credential, and shows what would be exposed.
78
+ const report = await getTestByUuid(ref.uuid);
79
+ const what = `"${report.name}" (${report.status}, ${report.start_time}${report.projectName ? `, project ${report.projectName}` : ''})`;
80
+ if (report.sharingEnabled === false) {
30
81
  return {
31
- content: [{
32
- type: 'text',
33
- text: `The report URL contains a UUID, not a numeric test ID. The Digital.ai reporter API does not support UUID-based lookup.\n\n` +
34
- `Use the numeric test ID from the "Report Test ID" line printed in tearDown (digitalai:reportTestId capability):\n` +
35
- ` get_test_report(testId: <the number from "Report Test ID">)\n\n` +
36
- `Or find it via: list_test_reports or find_latest_test_for_name.`,
37
- }],
82
+ content: [{ type: 'text', text: `Public sharing is disabled for ${what}'s project. A project admin must enable report sharing in the Reporter project settings first.` }],
38
83
  isError: true,
39
84
  };
40
85
  }
41
- else {
86
+ if (confirmPublicShare !== true) {
42
87
  return {
43
- content: [{ type: 'text', text: `Could not extract a numeric test ID from the report URL: ${reportUrl}. Provide testId directly instead.` }],
44
- isError: true,
88
+ content: [{
89
+ type: 'text',
90
+ text: `⚠️ Preview — nothing has been shared.\n\n` +
91
+ `This would create a PUBLIC link to ${what}. Anyone with the link can, without logging in:\n` +
92
+ ` • open the report page and its video\n` +
93
+ ` • read the report data, including all key-value pairs / capabilities\n` +
94
+ `The link lasts 14 days and cannot be revoked except by deleting the report.\n\n` +
95
+ `To proceed, call share_test_report again with confirmPublicShare: true.`,
96
+ }],
45
97
  };
46
98
  }
99
+ const share = await shareTestReport(ref.uuid);
100
+ const structured = { uuid: ref.uuid, testId: report.test_id, name: report.name, publicUrl: share.publicUrl, expires: share.expires };
101
+ const human = `🔗 Public link for ${what}:\n${share.publicUrl}\n\n` +
102
+ `Expires: ${share.expires} (14 days after it was first shared — re-sharing does not extend it).\n` +
103
+ `Anyone with this link can view the report, its data and its video without logging in. ` +
104
+ `To disable it early, delete the report (delete_test_reports).`;
105
+ return respond(outputFormat, structured, human);
47
106
  }
48
- if (!resolvedId) {
49
- return {
50
- content: [{ type: 'text', text: 'Provide either testId or reportUrl.' }],
51
- isError: true,
52
- };
107
+ catch (e) {
108
+ return { content: [{ type: 'text', text: `Error: ${e.message}` }], isError: true };
109
+ }
110
+ });
111
+ // ─── get_root_cause_analysis ───────────────────────────────────────────────
112
+ server.tool('get_root_cause_analysis', 'Read the platform\'s AI Root Cause Analysis for a failed test report: the hypothesis, the supporting evidence ' +
113
+ '(log lines with source, time and findings), the analysis status and attempts used, plus the reporter\'s own error ' +
114
+ 'classification (errorCategory / errorClassification / cause). Read-only — it never starts an analysis. ' +
115
+ 'Analyses are started from the video report in the Reporter UI; they cover Appium Server tests only and allow ' +
116
+ '3 failed attempts per test. ineligibleReason explains when an analysis cannot be run. ' +
117
+ 'To find analysed reports: list_test_reports with filter rca.status = COMPLETED.', {
118
+ uuid: z.string().optional().describe('Test execution UUID. Preferred.'),
119
+ reportUrl: z.string().optional().describe('Report URL (e.g. .../reporter/video-report/<uuid>).'),
120
+ testId: z.number().int().optional().describe('Numeric test id — unique only within a project; prefer uuid.'),
121
+ outputFormat: outputFormatParam,
122
+ }, async ({ uuid, reportUrl, testId, outputFormat }) => {
123
+ if ([uuid, reportUrl, testId].filter((v) => v != null && v !== '').length !== 1) {
124
+ return { content: [{ type: 'text', text: 'Provide exactly one of uuid, reportUrl or testId.' }], isError: true };
53
125
  }
54
126
  try {
55
- const report = await getTestById(resolvedId);
56
- return respond(outputFormat, report, formatTestReport(report));
127
+ const ref = parseReportRef(uuid ?? reportUrl ?? testId);
128
+ if (!ref)
129
+ return { content: [{ type: 'text', text: `Could not find a report UUID or test id in: ${uuid ?? reportUrl}.` }], isError: true };
130
+ const a = await getRootCauseAnalysis(ref);
131
+ const lines = [
132
+ `🔎 Root Cause Analysis — "${a.name}" (${a.testStatus}${a.framework ? `, ${a.framework}` : ''}${a.projectName ? `, project ${a.projectName}` : ''})`,
133
+ ` Status: ${a.status}` +
134
+ (a.attemptCount != null ? ` · attempts used ${a.attemptCount}/${RCA_MAX_ATTEMPTS}` : '') +
135
+ (a.serviceEnabled === false ? ' · RCA disabled on this cloud' : ''),
136
+ ];
137
+ if (a.hypothesis)
138
+ lines.push('', ` Hypothesis: ${a.hypothesis}`);
139
+ if (a.evidence.length) {
140
+ lines.push('', ' Evidence:');
141
+ for (const e of a.evidence) {
142
+ lines.push(` • ${[e.source, e.time].filter(Boolean).join(' @ ')}`);
143
+ if (e.log)
144
+ lines.push(` log: ${e.log}`);
145
+ if (e.findings)
146
+ lines.push(` → ${e.findings}`);
147
+ }
148
+ }
149
+ if (!a.hypothesis && a.status !== 'completed') {
150
+ lines.push('', a.status === 'none'
151
+ ? ' No analysis has been run for this report.'
152
+ : ` No result: the last analysis attempt ended "${a.status}".`);
153
+ }
154
+ const c = a.classification;
155
+ if (c.errorCategory || c.errorClassification || c.cause) {
156
+ lines.push('', ` Reporter classification: ${[c.errorCategory, c.errorClassification].filter(Boolean).join(' / ')}${c.cause ? ` — ${c.cause}` : ''}`);
157
+ }
158
+ if (a.ineligibleReason)
159
+ lines.push('', ` ℹ️ ${a.ineligibleReason}`);
160
+ return respond(outputFormat, a, lines.join('\n'));
57
161
  }
58
162
  catch (e) {
59
163
  return { content: [{ type: 'text', text: `Error: ${e.message}` }], isError: true };
@@ -80,7 +184,7 @@ export function registerReportingTools(server) {
80
184
  }
81
185
  if (UUID_RE.test(reportApiId)) {
82
186
  return {
83
- content: [{ type: 'text', text: `Error: "${reportApiId}" is a test UUID, not a report_api_id. There is no API endpoint to look up a test by UUID — use get_test_report(testId: <numeric_id>) instead. Find the numeric test_id via list_test_reports or find_latest_test_for_name. The report_api_id is a different identifier returned only when starting a manual or web-control session.` }],
187
+ content: [{ type: 'text', text: `Error: "${reportApiId}" is a test UUID, not a report_api_id. Use get_test_report(uuid: "${reportApiId}") instead. The report_api_id is a different identifier returned only when starting a manual or web-control session.` }],
84
188
  isError: true,
85
189
  };
86
190
  }
@@ -133,6 +237,7 @@ export function registerReportingTools(server) {
133
237
  '"user" (email, exact match — for "my reports" use the email from get_my_account_info), ' +
134
238
  '"has_attachment" ("Y"/"N"), ' +
135
239
  '"success" (boolean true/false), ' +
240
+ '"accessibility_report" (JSON boolean true/false, NOT the string "true" — that 400s; true = runs with an Axe accessibility scan), ' +
136
241
  '"test_id" (number), ' +
137
242
  '"project_id" (number), ' +
138
243
  '"device.os" ("Android"/"iOS" — case-sensitive), ' +
@@ -144,7 +249,7 @@ export function registerReportingTools(server) {
144
249
  operator: z.string().describe('Comparison operator. Supported: "=" (equality), ">" ">=" "<" "<=" (numeric/date), "contains" (substring for name). ' +
145
250
  'CSRF-blocked operators: "!=", "like", "startsWith", "in". ' +
146
251
  'Note: "success" must use boolean value with "="; string "true" is CSRF-blocked.'),
147
- value: z.union([z.string(), z.number(), z.boolean()]).describe('Filter value. Use boolean true/false for "success", numbers for numeric fields, strings for text fields.'),
252
+ value: z.union([z.string(), z.number(), z.boolean()]).describe('Filter value. Use boolean true/false for "success" and "accessibility_report", numbers for numeric fields, strings for text fields.'),
148
253
  }))
149
254
  .optional()
150
255
  .describe('Server-side filters. Multiple filters are ANDed. ' +
@@ -285,6 +390,7 @@ export function registerReportingTools(server) {
285
390
  'Use groupBy to specify which fields to group on — e.g. ["device.os"] returns one row per OS. ' +
286
391
  'Use pivotBy to add per-status columns (passedCount, failedCount, etc.) instead of separate rows. ' +
287
392
  'Useful for dashboards: pass/fail by OS, by test name, by environment, etc. ' +
393
+ 'Shared vs dedicated devices: groupBy ["device.pool.actual"] with pivotBy ["status"] (platform 26.7+; null = not recorded, e.g. browser tests or older runs). ' +
288
394
  'Note: null OS values represent browser/Selenium sessions. ' +
289
395
  'When groupBy includes "device.os", the MCP normalises case variants ("ANDROID"/"IOS") to ' +
290
396
  '"Android"/"iOS" and merges their counts, so you always receive at most 3 rows: Android, iOS, null.', {
@@ -329,20 +435,25 @@ export function registerReportingTools(server) {
329
435
  for (const row of result.data) {
330
436
  const rawOs = row['device.os'];
331
437
  const normOs = rawOs == null ? null : (OS_NORM[(String(rawOs)).toLowerCase()] ?? String(rawOs));
332
- const key = normOs ?? '__null__';
438
+ // Key on EVERY group-by field (OS normalised). Keying on the OS alone collapsed multi-field groupings —
439
+ // ["device.os","status"] merged Passed and Failed into one row per OS.
440
+ const key = JSON.stringify(groupBy.map((f) => (f === 'device.os' ? normOs : row[f] ?? null)));
333
441
  if (!merged[key]) {
334
442
  merged[key] = { ...row, 'device.os': normOs };
335
443
  }
336
444
  else {
337
- // Sum all numeric count fields
445
+ // Sum all numeric count fields (group-by fields are never summed)
338
446
  for (const [k, v] of Object.entries(row)) {
339
- if (typeof v === 'number' && k !== 'device.os') {
447
+ if (typeof v === 'number' && !groupBy.includes(k)) {
340
448
  merged[key][k] = (merged[key][k] ?? 0) + v;
341
449
  }
342
450
  }
343
451
  }
344
452
  }
345
- result = { ...result, data: Object.values(merged) };
453
+ const rows = Object.values(merged);
454
+ // `count` is the number of groups — after merging it must describe the rows actually returned (UAT 2026-10-09:
455
+ // count 5 with 3 rows).
456
+ result = { ...result, data: rows, ...(result.count != null ? { count: rows.length } : {}) };
346
457
  }
347
458
  return respond(outputFormat, result, formatGroupedTestReports(result));
348
459
  }
@@ -361,9 +472,21 @@ export function registerReportingTools(server) {
361
472
  outputFormat: outputFormatParam,
362
473
  }, async ({ keys, projectId, projectName, outputFormat }) => {
363
474
  try {
364
- const result = await getDistinctKeyValues(keys, projectId, projectName);
475
+ const raw = await getDistinctKeyValues(keys, projectId, projectName);
476
+ // device.os comes back as ANDROID/Android/IOS/iOS; fold the case variants the same way get_grouped_test_reports
477
+ // does, so the two tools agree (UAT 2026-10-10). The platform's own spellings are kept under rawValues.
478
+ const result = { ...raw };
479
+ const rawOs = raw['device.os'];
480
+ if (Array.isArray(rawOs)) {
481
+ const folded = [...new Set(rawOs.map((v) => (v == null ? v : normaliseDeviceOs(String(v)))))];
482
+ if (folded.length !== rawOs.length) {
483
+ result['device.os'] = folded;
484
+ result.rawValues = { 'device.os': rawOs };
485
+ }
486
+ }
365
487
  const lines = [];
366
- for (const [key, rawValues] of Object.entries(result)) {
488
+ for (const key of Object.keys(raw)) {
489
+ const rawValues = result[key];
367
490
  lines.push(`${key}:`);
368
491
  const values = Array.isArray(rawValues)
369
492
  ? rawValues
@@ -392,7 +515,7 @@ export function registerReportingTools(server) {
392
515
  }
393
516
  });
394
517
  // ─── delete_test_reports ───────────────────────────────────────────────────
395
- server.tool('delete_test_reports', 'Permanently delete one or more test execution records by their numeric IDs. This cannot be undone. Requires confirmDeletion: true. Cloud Admin only (project keys CSRF-blocked on reporter delete). PREFERRED cleanup method whenever the IDs are already known (e.g. from a filtered list_test_reports call) — more precise than name or date matching.', {
518
+ server.tool('delete_test_reports', 'Permanently delete one or more test execution records by their numeric IDs. This cannot be undone. Requires confirmDeletion: true. Cloud Admin can always delete; a project-level key only when its project\x27s allowUsersDeleteTests setting is on (otherwise the tool refuses up front and explains how to get it enabled). PREFERRED cleanup method whenever the IDs are already known (e.g. from a filtered list_test_reports call) — more precise than name or date matching.', {
396
519
  ids: z
397
520
  .array(z.number().int())
398
521
  .min(1)
@@ -455,7 +578,7 @@ export function registerReportingTools(server) {
455
578
  }
456
579
  });
457
580
  // ─── delete_test_reports_by_name ──────────────────────────────────────────
458
- server.tool('delete_test_reports_by_name', 'Find and permanently delete test execution records matching a name. Accepts exact match (name) or substring match (nameContains). Searches across all pages. Show a preview first via confirmDeletion: false, then re-call with confirmDeletion: true to execute. If you already have the numeric IDs (e.g. from a filtered list_test_reports call), use delete_test_reports instead — no name-matching ambiguity. Cloud Admin only — project-level keys (Project Admin and Project User) are CSRF-blocked on the reporter delete endpoint. IMPORTANT: always pass projectName (exact project name from list_projects) when using Cloud Admin access — without it the search spans the default reporter scope and tests from separate project reporter instances will not appear. The numeric projectId param is CSRF-blocked on reporter endpoints and is silently ignored.', {
581
+ server.tool('delete_test_reports_by_name', 'Find and permanently delete test execution records matching a name. Accepts exact match (name) or substring match (nameContains). Searches across all pages. Show a preview first via confirmDeletion: false, then re-call with confirmDeletion: true to execute. If you already have the numeric IDs (e.g. from a filtered list_test_reports call), use delete_test_reports instead — no name-matching ambiguity. Cloud Admin can always delete; a project-level key only when its project\x27s allowUsersDeleteTests setting is on (otherwise the tool refuses up front and explains how to get it enabled). IMPORTANT: always pass projectName (exact project name from list_projects) when using Cloud Admin access — without it the search spans the default reporter scope and tests from separate project reporter instances will not appear. The numeric projectId param is CSRF-blocked on reporter endpoints and is silently ignored.', {
459
582
  name: z
460
583
  .string()
461
584
  .optional()
@@ -557,23 +680,78 @@ export function registerReportingTools(server) {
557
680
  return { content: [{ type: 'text', text: `Error: ${e.message}` }], isError: true };
558
681
  }
559
682
  });
683
+ // ─── download_test_video ───────────────────────────────────────────────────
684
+ server.tool('download_test_video', 'Download only the session video (.mp4) of a test execution — no ZIP, no logs — or just one byte range of it. ' +
685
+ 'infoOnly: true returns the size without downloading. Byte ranges let you fetch a large recording in pieces, resume ' +
686
+ 'a cut-off download, or grab the start/end of a long session. Use download_test_attachments when you also need the logs.' +
687
+ serverFsDownloadNotice(), {
688
+ report: z.string().describe('Report UUID (preferred — numeric ids collide across projects), numeric test id, or the report URL (e.g. .../reporter/video-report/<uuid>).'),
689
+ localPath: z.string().optional().describe('Where to write the .mp4 (required unless infoOnly). ' + serverFsOutputParam()),
690
+ infoOnly: z.boolean().optional().describe('Return the video size and type without downloading it.'),
691
+ startByte: z.number().int().min(0).optional().describe('First byte of a partial download (0-based). With endByte for a fixed range; alone for "from here to the end" (e.g. resuming).'),
692
+ endByte: z.number().int().min(0).optional().describe('Last byte of a partial download, inclusive. Needs startByte.'),
693
+ lastBytes: z.number().int().min(1).optional().describe('Download only the final N bytes. Do not combine with startByte/endByte.'),
694
+ outputFormat: outputFormatParam,
695
+ }, async ({ report, localPath, infoOnly, startByte, endByte, lastBytes, outputFormat }) => {
696
+ const ref = parseReportRef(report);
697
+ if (!ref)
698
+ return { content: [{ type: 'text', text: `Error: "${report}" is not a report UUID, numeric test id or report URL.` }], isError: true };
699
+ const fail = (msg) => ({ content: [{ type: 'text', text: `Error: ${msg}` }], isError: true });
700
+ if (lastBytes != null && (startByte != null || endByte != null))
701
+ return fail('use either lastBytes or startByte/endByte, not both.');
702
+ if (endByte != null && startByte == null)
703
+ return fail('endByte needs startByte.');
704
+ if (startByte != null && endByte != null && endByte < startByte)
705
+ return fail('endByte must not be before startByte.');
706
+ const range = lastBytes != null ? `bytes=-${lastBytes}` : startByte != null ? `bytes=${startByte}-${endByte ?? ''}` : undefined;
707
+ const idNote = ref.kind === 'testId' ? ' Numeric ids are only unique per project — prefer the UUID.' : '';
708
+ try {
709
+ if (infoOnly) {
710
+ const info = await getTestVideoInfo(ref);
711
+ const mb = info.totalBytes != null ? `${(info.totalBytes / (1024 * 1024)).toFixed(1)} MB` : 'unknown size';
712
+ return respond(outputFormat, { ...info, rangeRequests: true }, `🎬 Video: ${mb} (${info.totalBytes ?? '?'} bytes, ${info.contentType ?? 'unknown type'}). Byte ranges are supported.${idNote}`);
713
+ }
714
+ if (!localPath)
715
+ return fail('localPath is required unless infoOnly is true.');
716
+ const pathErr = validateOutputPath(localPath);
717
+ if (pathErr)
718
+ return fail(pathErr);
719
+ const r = await downloadTestVideo(ref, localPath, range);
720
+ const what = r.partial ? `bytes ${r.contentRange?.replace(/^bytes\s*/, '') ?? range}` : 'full video';
721
+ return respond(outputFormat, { ...r, localPath }, `✅ ${what} (${r.bytesWritten} bytes${r.totalBytes != null ? ` of ${r.totalBytes}` : ''}) written to: ${localPath}` +
722
+ (r.partial ? '\nA partial file is a fragment, not a playable video on its own unless it starts at byte 0 and the player tolerates truncation.' : '') +
723
+ idNote);
724
+ }
725
+ catch (e) {
726
+ const msg = e.message;
727
+ if (/\[416\]/.test(msg))
728
+ return fail(`the requested range is outside the video. Call with infoOnly: true to get its size. (${msg})`);
729
+ return fail(msg);
730
+ }
731
+ });
560
732
  // ─── get_test_attachments_download_command ─────────────────────────────────
561
733
  server.tool('get_test_attachments_download_command', 'Generates a ready-to-run curl or PowerShell command for downloading a test execution\'s full attachment ZIP (session video .mp4, Appium/device logs) directly to the user\'s local machine. ' +
562
734
  commandGeneratorNotice('download_test_attachments', 'download') + ' ' +
563
735
  'For text logs only, get_test_log is simpler (returns log text inline, no command). This is the path for the BINARY artifacts (video).\n\n' +
564
736
  'WARNING: The generated command embeds the active access key in plaintext. Instruct the user to run it immediately and not save or share the output.', {
565
737
  uuid: z.string().describe('Test execution UUID (uuid field from get_test_report or list_test_reports).'),
566
- localPath: z.string().optional().default('test-attachments.zip').describe('Path on the user\'s local machine to save the ZIP. Default: "test-attachments.zip" in the current directory.'),
738
+ localPath: z.string().optional().describe('Path on the user\'s local machine to save the file. Default: "test-attachments.zip" (or "test-video.mp4" for artifact "video") in the current directory.'),
739
+ artifact: z
740
+ .enum(['zip', 'video'])
741
+ .optional()
742
+ .default('zip')
743
+ .describe('"zip" (default): the full attachment ZIP (video + logs). "video": only the session .mp4 — smaller, no unzip.'),
567
744
  localPlatform: z.enum(['windows', 'macos', 'linux']).describe('Platform of the machine that will run the command. ' + localPlatformParamNotice()),
568
745
  outputFormat: outputFormatParam,
569
- }, async ({ uuid, localPath, localPlatform, outputFormat }) => {
746
+ }, async ({ uuid, localPath, artifact, localPlatform, outputFormat }) => {
747
+ const video = artifact === 'video';
570
748
  const result = buildDownloadCommand({
571
- path: `/reporter/api/reports/${uuid}/attachments`,
572
- localPath: localPath ?? 'test-attachments.zip',
749
+ path: `/reporter/api/reports/${uuid}/${video ? 'video' : 'attachments'}`,
750
+ localPath: localPath ?? (video ? 'test-video.mp4' : 'test-attachments.zip'),
573
751
  localPlatform,
574
- notes: ['The downloaded file is a ZIP — unzip it to access the .mp4 video and the appium/device/ws logs.'],
752
+ notes: [video ? 'The downloaded file is the session video (.mp4).' : 'The downloaded file is a ZIP — unzip it to access the .mp4 video and the appium/device/ws logs.'],
575
753
  });
576
- return respond(outputFormat, { endpoint: result.endpoint, curlCommand: result.curlCommand, psCommand: result.psCommand }, result.humanText);
754
+ return respond(outputFormat, commandPayload(result), result.humanText);
577
755
  });
578
756
  // ─── get_test_log ──────────────────────────────────────────────────────────
579
757
  server.tool('get_test_log', 'Retrieve log content from a test execution directly as text — no file download required. ' +
@@ -636,12 +814,16 @@ export function registerReportingTools(server) {
636
814
  }
637
815
  });
638
816
  // ─── list_test_attachments ─────────────────────────────────────────────────
639
- server.tool('list_test_attachments', 'Show attachment metadata (file names, types, sizes) for a test execution. Takes the numeric testId (integer), NOT the uuid string. Call this before download_test_attachments to confirm attachments exist — download_test_attachments then takes the uuid shown in the output.', {
640
- testId: z.number().int().describe('Numeric test ID (the test_id integer from list_test_reports or find_latest_test_for_name — NOT the uuid string).'),
817
+ server.tool('list_test_attachments', 'Show attachment metadata (file names, types, sizes) for a test execution. Takes the uuid (preferred — globally unique) or the numeric testId. Call this before download_test_attachments to confirm attachments exist — download_test_attachments then takes the uuid shown in the output.', {
818
+ uuid: z.string().optional().describe('Test execution UUID (uuid field from list_test_reports). Preferred.'),
819
+ testId: z.number().int().optional().describe('Numeric test ID (test_id from list_test_reports). Unique only within a project — prefer uuid.'),
641
820
  outputFormat: outputFormatParam,
642
- }, async ({ testId, outputFormat }) => {
821
+ }, async ({ uuid, testId, outputFormat }) => {
822
+ if ((uuid ? 1 : 0) + (testId != null ? 1 : 0) !== 1) {
823
+ return { content: [{ type: 'text', text: 'Provide exactly one of uuid or testId.' }], isError: true };
824
+ }
643
825
  try {
644
- const report = await getTestById(testId);
826
+ const report = uuid ? await getTestByUuid(uuid) : await getTestById(testId);
645
827
  const structured = {
646
828
  testId: report.test_id,
647
829
  uuid: report.uuid,
@@ -678,7 +860,7 @@ export function registerReportingTools(server) {
678
860
  }
679
861
  });
680
862
  // ─── get_project_test_summary ──────────────────────────────────────────────
681
- server.tool('get_project_test_summary', 'Return a human-readable pass/fail summary for a project. Overall status counts (Passed/Failed/Incomplete) are all-time totals — the reporter API does not support date-range filtering for aggregate counts. Top failing test names are filtered to the requested time window client-side from the most recent 200 failures.', {
863
+ server.tool('get_project_test_summary', 'Return a pass/fail summary for a project. Status counts cover all six reporter statuses (Passed, Failed, Error, Incomplete, Skipped, Healed) and are all-time totals — the reporter API does not support date-range filtering for aggregate counts. Error = the test ended abnormally (crash, infrastructure, session ended early — since platform 26.9 these are no longer Incomplete). Pass rate = (Passed+Healed)/(Passed+Healed+Failed+Error). Top failing and top erroring test names are filtered to the requested time window client-side from the most recent 200 of each.', {
682
864
  startDate: z
683
865
  .string()
684
866
  .optional()
@@ -694,58 +876,70 @@ export function registerReportingTools(server) {
694
876
  try {
695
877
  const defaultStart = new Date(Date.now() - 48 * 60 * 60 * 1000).toISOString();
696
878
  const resolvedStart = startDate ?? defaultStart;
697
- // Fetch per-status counts + recent failures in parallel.
698
- // The grouped endpoint returns empty data[] without grouping keys, so we
699
- // use per-status listTests calls with returnTotalCount which reliably works.
700
- const [passedResult, failedResult, incompleteResult] = await Promise.all([
701
- listTests({ limit: 1, page: 1, returnTotalCount: true, filter: [{ property: 'status', operator: '=', value: 'Passed' }] }, projectId, projectName),
702
- listTestsSortedDesc({ limit: 200, page: 1, returnTotalCount: true, filter: [{ property: 'status', operator: '=', value: 'Failed' }] }, projectId, projectName),
703
- listTests({ limit: 1, page: 1, returnTotalCount: true, filter: [{ property: 'status', operator: '=', value: 'Incomplete' }] }, projectId, projectName),
879
+ // All six status counts in ONE call: grouped with pivotBy ["status"] and no groupBy returns a single row
880
+ // { passedCount, failedCount, errorCount, incompleteCount, skippedCount, healedCount, _count_ } (verified live
881
+ // 2026-10-09). The previous per-status listTests calls only asked for Passed/Failed/Incomplete, so Error,
882
+ // Skipped and Healed never reached the total — and since 26.9 every crash/infrastructure abort is Error.
883
+ // Recent Failed and Error records are fetched alongside for the windowed top-N names.
884
+ const recent = (status) => listTestsSortedDesc({ limit: 200, page: 1, returnTotalCount: false, filter: [{ property: 'status', operator: '=', value: status }] }, projectId, projectName);
885
+ const [grouped, failedResult, errorResult, byPool] = await Promise.all([
886
+ getGroupedTests({ pivotBy: ['status'] }, projectId, projectName),
887
+ recent('Failed'),
888
+ recent('Error'),
889
+ // device.pool.actual (platform 26.7+): which pool each mobile automation test actually ran on. Shared-device
890
+ // flakiness is a common question; one grouped call answers it. Best-effort — the summary stands without it.
891
+ getGroupedTests({ groupBy: ['device.pool.actual'], pivotBy: ['status'] }, projectId, projectName).catch(() => null),
704
892
  ]);
705
- const passed = passedResult.count ?? 0;
706
- const failed = failedResult.count ?? 0;
707
- const incomplete = incompleteResult.count ?? 0;
708
- const total = passed + failed + incomplete;
709
- // Apply date window client-side on the most recent 200 failures
893
+ const counts = countsFromPivotRow(grouped?.data?.[0]);
894
+ const devicePools = (byPool?.data ?? [])
895
+ .filter((r) => r['device.pool.actual'] != null) // null = not recorded (non-mobile tests, or before 26.7)
896
+ .map((r) => { const c = countsFromPivotRow(r); return { pool: String(r['device.pool.actual']), total: c.total, failed: c.failed, error: c.error, passRate: passRate(c) }; })
897
+ .sort((a, b) => b.total - a.total);
898
+ // Apply the date window client-side on the most recent 200 of each
710
899
  // (start_time filter via API key triggers CSRF — filter locally instead).
711
900
  const endTs = endDate ? new Date(endDate).getTime() : Date.now();
712
901
  const startTs = new Date(resolvedStart).getTime();
713
- const windowedFailures = (failedResult.data ?? []).filter((r) => {
714
- const t = new Date(r.start_time).getTime();
715
- return t >= startTs && t <= endTs;
716
- });
717
- const nameCounts = {};
718
- for (const r of windowedFailures) {
719
- nameCounts[r.name] = (nameCounts[r.name] ?? 0) + 1;
720
- }
721
- const topFailures = Object.entries(nameCounts)
722
- .sort((a, b) => b[1] - a[1])
723
- .slice(0, 5)
724
- .map(([name, count]) => `${name} (${count}x)`);
725
- const statusCounts = { Passed: passed, Failed: failed, Incomplete: incomplete };
902
+ const topNames = (records) => {
903
+ const nameCounts = {};
904
+ for (const r of records) {
905
+ const t = new Date(r.start_time).getTime();
906
+ if (t >= startTs && t <= endTs)
907
+ nameCounts[r.name] = (nameCounts[r.name] ?? 0) + 1;
908
+ }
909
+ return Object.entries(nameCounts)
910
+ .sort((a, b) => b[1] - a[1])
911
+ .slice(0, 5)
912
+ .map(([name, count]) => `${name} (${count}x)`);
913
+ };
914
+ const topFailures = topNames(failedResult.data ?? []);
915
+ const topErrors = topNames(errorResult.data ?? []);
726
916
  const windowLabel = endDate
727
917
  ? `${resolvedStart} → ${endDate}`
728
918
  : startDate
729
919
  ? `${resolvedStart} → now`
730
920
  : `last 48 hours`;
731
- const passRate = total > 0 ? ((passed / total) * 100).toFixed(1) : '0.0';
921
+ const unknown = unknownStatusCount(counts);
732
922
  const structured = {
733
- total,
734
- passed,
735
- failed,
736
- incomplete,
737
- passRate: parseFloat(passRate),
923
+ ...counts,
924
+ ...(unknown > 0 ? { otherStatus: unknown } : {}),
925
+ passRate: passRate(counts),
926
+ passRateBasis: PASS_RATE_BASIS,
738
927
  topFailures,
928
+ topErrors,
739
929
  window: windowLabel,
930
+ ...(devicePools.length ? { byDevicePool: devicePools } : {}),
740
931
  };
741
- return respond(outputFormat, structured, formatProjectTestSummary(statusCounts, total, windowLabel, topFailures));
932
+ const poolLines = devicePools.length
933
+ ? ['', ' By device pool (mobile automation, platform 26.7+):', ...devicePools.map((p) => ` ${p.pool.padEnd(10)} ${String(p.total).padStart(8)} tests · pass rate ${p.passRate == null ? 'n/a' : `${p.passRate}%`} · ${p.failed} failed · ${p.error} error`)]
934
+ : [];
935
+ return respond(outputFormat, structured, formatProjectTestSummary(counts, windowLabel, topFailures, topErrors) + poolLines.join('\n'));
742
936
  }
743
937
  catch (e) {
744
938
  return { content: [{ type: 'text', text: `Error: ${e.message}` }], isError: true };
745
939
  }
746
940
  });
747
941
  // ─── delete_test_reports_before_date ──────────────────────────────────────
748
- server.tool('delete_test_reports_before_date', 'Permanently delete all test execution records started before a given date. Fetches matching IDs automatically then deletes them. Requires confirmDeletion: true. This cannot be undone. Cloud Admin only (project keys CSRF-blocked on reporter delete).', {
942
+ server.tool('delete_test_reports_before_date', 'Permanently delete all test execution records started before a given date. Fetches matching IDs automatically then deletes them. Requires confirmDeletion: true. This cannot be undone. Cloud Admin can always delete; a project-level key only when its project\x27s allowUsersDeleteTests setting is on (otherwise the tool refuses up front and explains how to get it enabled).', {
749
943
  beforeDate: z
750
944
  .string()
751
945
  .describe('ISO 8601 cutoff date. All tests with start_time before this date will be deleted, e.g. "2024-01-01T00:00:00Z".'),
@@ -804,10 +998,17 @@ export function registerReportingTools(server) {
804
998
  .optional()
805
999
  .default(50)
806
1000
  .describe('Maximum number of active executions to return (default: 50).'),
1001
+ maxAgeHours: z
1002
+ .number()
1003
+ .min(1)
1004
+ .max(168)
1005
+ .optional()
1006
+ .default(12)
1007
+ .describe('Ignore Incomplete records that started longer ago than this — they are abandoned or never-finalised runs, not running ones (default 12; test runs time out after 4 h by default).'),
807
1008
  projectId: z.number().int().optional().describe('Scope to this project ID.'),
808
1009
  projectName: z.string().optional().describe('Scope to this project name.'),
809
1010
  outputFormat: outputFormatParam,
810
- }, async ({ limit, projectId, projectName, outputFormat }) => {
1011
+ }, async ({ limit, maxAgeHours, projectId, projectName, outputFormat }) => {
811
1012
  try {
812
1013
  // Active executions are Incomplete records with null duration.
813
1014
  // We fetch more than needed since not all Incomplete records are still running.
@@ -817,11 +1018,22 @@ export function registerReportingTools(server) {
817
1018
  returnTotalCount: false,
818
1019
  filter: [{ property: 'status', operator: '=', value: 'Incomplete' }],
819
1020
  }, projectId, projectName);
820
- const active = (result.data ?? []).filter(r => r.duration === null).slice(0, limit ?? 50);
1021
+ // Incomplete + null duration also matches runs that were abandoned or never finalised — the UAT (2026-10-09)
1022
+ // found every "active" execution was 3+ days old. Anything older than maxAgeHours is not running now.
1023
+ const ageCutoff = Date.now() - (maxAgeHours ?? 12) * 3600_000;
1024
+ const unfinished = (result.data ?? []).filter(r => r.duration === null);
1025
+ const recent = unfinished.filter(r => new Date(r.start_time).getTime() >= ageCutoff);
1026
+ const staleExcluded = unfinished.length - recent.length;
1027
+ const active = recent.slice(0, limit ?? 50);
1028
+ const staleNote = staleExcluded > 0
1029
+ ? ` ${staleExcluded} older Incomplete record(s) were ignored as stale (started more than ${maxAgeHours ?? 12} h ago — abandoned or never finalised).`
1030
+ : '';
821
1031
  if (active.length === 0) {
822
- return respond(outputFormat, { count: 0, executions: [] }, 'No active test executions found. All Incomplete records have finished reporting.');
1032
+ return respond(outputFormat, { count: 0, executions: [], staleExcluded, maxAgeHours: maxAgeHours ?? 12 }, `No active test executions found.${staleNote}`);
823
1033
  }
824
1034
  const structured = {
1035
+ staleExcluded,
1036
+ maxAgeHours: maxAgeHours ?? 12,
825
1037
  count: active.length,
826
1038
  executions: active.map(r => ({
827
1039
  testId: r.test_id,
@@ -839,7 +1051,7 @@ export function registerReportingTools(server) {
839
1051
  const elapsedSec = Math.floor((elapsedMs % 60000) / 1000);
840
1052
  lines.push(` • ${r.name}`, ` Test ID: ${r.test_id} UUID: ${r.uuid}`, ` Started: ${r.start_time} Elapsed: ${elapsedMin}m ${elapsedSec}s`, ` Project: ${r.project_id}`, '');
841
1053
  }
842
- lines.push('Note: "active" is inferred from Incomplete status + null duration. A test that finished very recently may appear here until the reporter updates.');
1054
+ lines.push(`Note: "active" is inferred from Incomplete status + null duration within the last ${maxAgeHours ?? 12} h. A test that finished very recently may appear here until the reporter updates.${staleNote}`);
843
1055
  return respond(outputFormat, structured, lines.join('\n'));
844
1056
  }
845
1057
  catch (e) {
@@ -886,18 +1098,16 @@ export function registerReportingTools(server) {
886
1098
  if (runs.length === 0) {
887
1099
  return respond(outputFormat, { found: false }, `No executions found for test name containing "${testName}".`);
888
1100
  }
889
- const passed = runs.filter(r => r.status === 'Passed' || r.success).length;
890
- const failed = runs.filter(r => r.status === 'Failed').length;
891
- const other = runs.length - passed - failed;
892
- const passRate = runs.length > 0 ? ((passed / runs.length) * 100).toFixed(1) : '0.0';
893
- // Sparkline: ✅ = Passed, ❌ = Failed, ⚠️ = other — newest last
894
- const spark = [...runs].reverse().map(r => {
895
- if (r.status === 'Passed' || r.success)
896
- return '✅';
897
- if (r.status === 'Failed')
898
- return '❌';
899
- return '⚠️';
900
- }).join(' ');
1101
+ // Classify by status, not `success` — success is false for Healed (verified live), true only for Passed.
1102
+ const c = tallyStatuses(runs);
1103
+ const passed = c.passed + c.healed;
1104
+ const failed = c.failed;
1105
+ const error = c.error;
1106
+ const other = runs.length - passed - failed - error;
1107
+ const rate = passRate(c);
1108
+ // Sparkline: ✅ = Passed/Healed, ❌ = Failed, 💥 = Error, ⚠️ = other — newest last
1109
+ const icon = (s) => (s === 'Error' ? '💥' : { pass: '✅', fail: '❌', other: '⚠️' }[statusOutcome(s)]);
1110
+ const spark = [...runs].reverse().map(r => icon(r.status)).join(' ');
901
1111
  // Consecutive streak from the most recent run
902
1112
  const latestStatus = runs[0].status;
903
1113
  let streak = 0;
@@ -911,8 +1121,9 @@ export function registerReportingTools(server) {
911
1121
  const structured = {
912
1122
  testName: runs[0].name,
913
1123
  runs: runs.length,
914
- passed, failed, other,
915
- passRate: parseFloat(passRate),
1124
+ passed, failed, error, other,
1125
+ passRate: rate,
1126
+ passRateBasis: PASS_RATE_BASIS,
916
1127
  latestStatus: runs[0].status,
917
1128
  latestRun: runs[0].start_time,
918
1129
  streak,
@@ -925,8 +1136,8 @@ export function registerReportingTools(server) {
925
1136
  };
926
1137
  const lines = [
927
1138
  `📋 Stability report: "${runs[0].name}"`,
928
- ` Runs examined: ${runs.length} | Pass rate: ${passRate}% | Latest: ${runs[0].status}${streakLabel}`,
929
- ` ${passed} passed · ${failed} failed · ${other} other`,
1139
+ ` Runs examined: ${runs.length} | Pass rate: ${rate == null ? 'n/a' : `${rate}%`} | Latest: ${runs[0].status}${streakLabel}`,
1140
+ ` ${passed} passed · ${failed} failed · ${error} error · ${other} other`,
930
1141
  ``,
931
1142
  ` Trend (oldest → newest):`,
932
1143
  ` ${spark}`,
@@ -934,8 +1145,7 @@ export function registerReportingTools(server) {
934
1145
  ` Most recent ${Math.min(5, runs.length)} runs:`,
935
1146
  ...runs.slice(0, 5).map(r => {
936
1147
  const dur = r.duration != null ? `${(r.duration / 1000).toFixed(1)}s` : 'n/a';
937
- const icon = r.status === 'Passed' ? '✅' : r.status === 'Failed' ? '❌' : '⚠️';
938
- return ` ${icon} ${r.status} — ${r.start_time} (${dur})`;
1148
+ return ` ${icon(r.status)} ${r.status} — ${r.start_time} (${dur})`;
939
1149
  }),
940
1150
  ];
941
1151
  return respond(outputFormat, structured, lines.join('\n'));
@@ -966,11 +1176,10 @@ export function registerReportingTools(server) {
966
1176
  const os = String(row['device.os'] ?? '');
967
1177
  if (!name || (os !== 'Android' && os !== 'iOS'))
968
1178
  continue;
969
- const passed = Number(row['passedCount'] ?? 0);
970
- const total = Number(row['_count_'] ?? (Number(row['passedCount'] ?? 0) + Number(row['failedCount'] ?? 0) + Number(row['incompleteCount'] ?? 0) + Number(row['errorCount'] ?? 0)));
1179
+ const c = countsFromPivotRow(row);
971
1180
  if (!map[name])
972
1181
  map[name] = {};
973
- map[name][os] = { passed, total };
1182
+ map[name][os] = { rate: passRate(c) ?? 0, total: c.total };
974
1183
  }
975
1184
  // Find divergent tests
976
1185
  const divergent = Object.entries(map)
@@ -982,8 +1191,8 @@ export function registerReportingTools(server) {
982
1191
  .map(([name, platforms]) => {
983
1192
  const a = platforms.Android;
984
1193
  const i = platforms.iOS;
985
- const androidPct = a.total > 0 ? (a.passed / a.total) * 100 : 0;
986
- const iosPct = i.total > 0 ? (i.passed / i.total) * 100 : 0;
1194
+ const androidPct = a.rate;
1195
+ const iosPct = i.rate;
987
1196
  return {
988
1197
  name,
989
1198
  androidPassRate: parseFloat(androidPct.toFixed(1)),
@@ -1063,7 +1272,10 @@ export function registerReportingTools(server) {
1063
1272
  continue;
1064
1273
  }
1065
1274
  records.push({ status: r.status, start_time: r.start_time });
1275
+ // The record cap ended the scan before the cutoff was reached: older days in the window were never read.
1276
+ // (UAT 2026-10-09: a 14-day trend stopped at 5,000 records on day 6 and reported scanCapped: false.)
1066
1277
  if (records.length >= maxRecords) {
1278
+ scanCapped = true;
1067
1279
  done = true;
1068
1280
  break;
1069
1281
  }
@@ -1093,50 +1305,71 @@ export function registerReportingTools(server) {
1093
1305
  }
1094
1306
  return d.toISOString().slice(0, 10);
1095
1307
  };
1308
+ const grouped = {};
1309
+ for (const r of records)
1310
+ (grouped[bucketKey(r.start_time)] ??= []).push(r);
1311
+ // passed = Passed + Healed; Error (abnormal end — crash/infrastructure, 26.9+) is its own column, not "other".
1096
1312
  const buckets = {};
1097
- for (const r of records) {
1098
- const key = bucketKey(r.start_time);
1099
- if (!buckets[key])
1100
- buckets[key] = { total: 0, passed: 0, failed: 0, other: 0 };
1101
- buckets[key].total++;
1102
- if (r.status === 'Passed')
1103
- buckets[key].passed++;
1104
- else if (r.status === 'Failed')
1105
- buckets[key].failed++;
1106
- else
1107
- buckets[key].other++;
1313
+ for (const [key, rs] of Object.entries(grouped)) {
1314
+ const c = tallyStatuses(rs);
1315
+ const passed = c.passed + c.healed;
1316
+ buckets[key] = { total: c.total, passed, failed: c.failed, error: c.error, other: c.total - passed - c.failed - c.error, passRate: passRate(c) };
1108
1317
  }
1109
1318
  const sorted = Object.entries(buckets).sort(([a], [b]) => a.localeCompare(b));
1319
+ // Earliest record actually read — when the scan was capped, days before this are missing, not empty.
1320
+ const coveredFrom = records.reduce((min, r) => (r.start_time < min ? r.start_time : min), records[0].start_time);
1321
+ // When capped, extrapolate from the observed rate so the caller gets a concrete next step (UAT 2026-10-10: a
1322
+ // 14-day request covered 6 days and the agent had to guess what to change).
1323
+ const MAX_RECORDS = 25_000;
1324
+ const coveredDays = Math.max((Date.now() - new Date(coveredFrom).getTime()) / 86_400_000, 1 / 24);
1325
+ const estimatedNeeded = Math.ceil((records.length / coveredDays) * lookbackDays * 1.1 / 500) * 500;
1326
+ const suggestedMaxRecords = scanCapped ? Math.min(estimatedNeeded, MAX_RECORDS) : null;
1327
+ const fittingLookbackDays = scanCapped && estimatedNeeded > MAX_RECORDS
1328
+ ? Math.max(1, Math.floor((MAX_RECORDS / (records.length / coveredDays)) / 1.1))
1329
+ : null;
1110
1330
  const structured = {
1111
1331
  bucketBy,
1112
1332
  lookbackDays,
1113
1333
  recordsScanned: records.length,
1114
1334
  cappedAt: records.length >= maxRecords ? maxRecords : null,
1115
- // true when the platform refused sort and the unsorted scan hit maxRecords before covering the window
1335
+ // true whenever maxRecords ended the scan before the lookback window was fully covered
1116
1336
  scanCapped,
1337
+ windowComplete: !scanCapped,
1338
+ coveredFrom: scanCapped ? coveredFrom : new Date(cutoffTs).toISOString(),
1339
+ ...(scanCapped
1340
+ ? {
1341
+ missingRange: { from: new Date(cutoffTs).toISOString(), to: coveredFrom },
1342
+ suggestedMaxRecords,
1343
+ ...(fittingLookbackDays != null ? { fittingLookbackDays } : {}),
1344
+ }
1345
+ : {}),
1117
1346
  buckets: sorted.map(([date, b]) => ({
1118
1347
  date,
1119
1348
  total: b.total,
1120
1349
  passed: b.passed,
1121
1350
  failed: b.failed,
1351
+ error: b.error,
1122
1352
  other: b.other,
1123
- passRate: b.total > 0 ? parseFloat(((b.passed / b.total) * 100).toFixed(1)) : null,
1353
+ passRate: b.passRate,
1124
1354
  })),
1355
+ passRateBasis: PASS_RATE_BASIS,
1125
1356
  };
1126
1357
  const lines = [
1127
1358
  `📅 Test execution trend (${bucketBy === 'week' ? 'weekly' : 'daily'}, last ${lookbackDays} days — ${records.length} records scanned)\n`,
1128
- ` ${'Date'.padEnd(12)} ${'Total'.padStart(6)} ${'Passed'.padStart(7)} ${'Failed'.padStart(7)} ${'Pass%'.padStart(7)}`,
1129
- ` ${'─'.repeat(44)}`,
1359
+ ` ${'Date'.padEnd(12)} ${'Total'.padStart(6)} ${'Passed'.padStart(7)} ${'Failed'.padStart(7)} ${'Error'.padStart(7)} ${'Pass%'.padStart(7)}`,
1360
+ ` ${'─'.repeat(52)}`,
1130
1361
  ...sorted.map(([date, b]) => {
1131
- const pct = b.total > 0 ? ((b.passed / b.total) * 100).toFixed(1) : '—';
1132
- return ` ${date.padEnd(12)} ${String(b.total).padStart(6)} ${String(b.passed).padStart(7)} ${String(b.failed).padStart(7)} ${pct.padStart(7)}`;
1362
+ const pct = b.passRate == null ? '—' : b.passRate.toFixed(1);
1363
+ return ` ${date.padEnd(12)} ${String(b.total).padStart(6)} ${String(b.passed).padStart(7)} ${String(b.failed).padStart(7)} ${String(b.error).padStart(7)} ${pct.padStart(7)}`;
1133
1364
  }),
1365
+ `\n Passed includes Healed. Pass% = (Passed+Healed)/(Passed+Healed+Failed+Error).`,
1134
1366
  ];
1135
- if (records.length >= maxRecords) {
1136
- lines.push(`\n ⚠️ Capped at ${maxRecords} records — increase maxRecords or reduce lookbackDays for a complete picture.`);
1137
- }
1138
- else if (scanCapped) {
1139
- lines.push(`\n ⚠️ Incomplete: the platform refused server-side sort for this credential, so records were scanned unsorted and the scan stopped at maxRecords (${maxRecords}) before the full ${lookbackDays}-day window was covered. Increase maxRecords for a complete picture.`);
1367
+ if (scanCapped) {
1368
+ lines.push(`\n ⚠️ INCOMPLETE WINDOW: the scan stopped at maxRecords (${maxRecords}) and only covers ${coveredFrom.slice(0, 10)} onward — ` +
1369
+ `days before that are MISSING from this trend, not days with zero executions. ` +
1370
+ (fittingLookbackDays != null
1371
+ ? `At this project's rate even the 25,000 maximum won't cover ${lookbackDays} days — use lookbackDays: ${fittingLookbackDays} with maxRecords: 25000, or bucketBy "week" over several shorter calls.`
1372
+ : `Re-run with maxRecords: ${suggestedMaxRecords} to cover the full ${lookbackDays}-day window (estimated from the rate observed so far).`));
1140
1373
  }
1141
1374
  return respond(outputFormat, structured, lines.join('\n'));
1142
1375
  }