digital-ai-testing-mcp 2.3.0 → 2.3.2
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.
- package/dist/api/access-level.d.ts +3 -2
- package/dist/api/access-level.d.ts.map +1 -1
- package/dist/api/access-level.js +3 -2
- package/dist/api/access-level.js.map +1 -1
- package/dist/api/browser-events.d.ts +25 -1
- package/dist/api/browser-events.d.ts.map +1 -1
- package/dist/api/browser-events.js +72 -3
- package/dist/api/browser-events.js.map +1 -1
- package/dist/api/browser-inspection.d.ts +2 -0
- package/dist/api/browser-inspection.d.ts.map +1 -1
- package/dist/api/browser-inspection.js +15 -0
- package/dist/api/browser-inspection.js.map +1 -1
- package/dist/api/reporter-projects.d.ts +12 -0
- package/dist/api/reporter-projects.d.ts.map +1 -1
- package/dist/api/reporter-projects.js +56 -1
- package/dist/api/reporter-projects.js.map +1 -1
- package/dist/api/reporting.d.ts +6 -0
- package/dist/api/reporting.d.ts.map +1 -1
- package/dist/api/reporting.js +21 -4
- package/dist/api/reporting.js.map +1 -1
- package/dist/api/test-requests.d.ts +4 -0
- package/dist/api/test-requests.d.ts.map +1 -1
- package/dist/api/test-requests.js +2 -0
- package/dist/api/test-requests.js.map +1 -1
- package/dist/api/virtual-devices.d.ts +12 -0
- package/dist/api/virtual-devices.d.ts.map +1 -1
- package/dist/api/virtual-devices.js +38 -1
- package/dist/api/virtual-devices.js.map +1 -1
- package/dist/api/webdriver.d.ts +2 -0
- package/dist/api/webdriver.d.ts.map +1 -1
- package/dist/api/webdriver.js +87 -3
- package/dist/api/webdriver.js.map +1 -1
- package/dist/tools/boilerplate-tools.d.ts.map +1 -1
- package/dist/tools/boilerplate-tools.js +47 -7
- package/dist/tools/boilerplate-tools.js.map +1 -1
- package/dist/tools/coverage-tools.d.ts.map +1 -1
- package/dist/tools/coverage-tools.js +2 -1
- package/dist/tools/coverage-tools.js.map +1 -1
- package/dist/tools/device-health-tool.d.ts.map +1 -1
- package/dist/tools/device-health-tool.js +4 -2
- package/dist/tools/device-health-tool.js.map +1 -1
- package/dist/tools/device-tools.d.ts.map +1 -1
- package/dist/tools/device-tools.js +63 -10
- package/dist/tools/device-tools.js.map +1 -1
- package/dist/tools/inspection-tools.d.ts +8 -0
- package/dist/tools/inspection-tools.d.ts.map +1 -1
- package/dist/tools/inspection-tools.js +102 -2
- package/dist/tools/inspection-tools.js.map +1 -1
- package/dist/tools/reporting-tools.d.ts +18 -0
- package/dist/tools/reporting-tools.d.ts.map +1 -1
- package/dist/tools/reporting-tools.js +138 -34
- package/dist/tools/reporting-tools.js.map +1 -1
- package/dist/tools/web-inspection-tools.d.ts.map +1 -1
- package/dist/tools/web-inspection-tools.js +2 -1
- package/dist/tools/web-inspection-tools.js.map +1 -1
- package/dist/types/digital-ai.d.ts +1 -0
- package/dist/types/digital-ai.d.ts.map +1 -1
- package/dist/utils/device-health.d.ts +2 -0
- package/dist/utils/device-health.d.ts.map +1 -1
- package/dist/utils/device-health.js +5 -0
- package/dist/utils/device-health.js.map +1 -1
- package/dist/utils/device-resolver.d.ts +2 -0
- package/dist/utils/device-resolver.d.ts.map +1 -1
- package/dist/utils/device-resolver.js +3 -3
- package/dist/utils/device-resolver.js.map +1 -1
- package/dist/utils/remediation.d.ts.map +1 -1
- package/dist/utils/remediation.js +10 -4
- package/dist/utils/remediation.js.map +1 -1
- package/dist/utils/response-formatter.d.ts.map +1 -1
- package/dist/utils/response-formatter.js +8 -2
- package/dist/utils/response-formatter.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import { getTestById, getTestByUuid, shareTestReport, getRootCauseAnalysis, RCA_MAX_ATTEMPTS, getTestByReportApiId, listTests, listTestsSortedDesc, getGroupedTests, getDistinctKeyValues, deleteTests, downloadTestAttachments, downloadTestVideo, getTestVideoInfo, extractAttachmentLog, summarizeTestFailures, } from '../api/reporting.js';
|
|
2
|
+
import { getTestById, getScopedTest, getTestByUuid, shareTestReport, getRootCauseAnalysis, RCA_MAX_ATTEMPTS, getTestByReportApiId, listTests, listTestsSortedDesc, getGroupedTests, getDistinctKeyValues, deleteTests, downloadTestAttachments, downloadTestVideo, getTestVideoInfo, extractAttachmentLog, summarizeTestFailures, } from '../api/reporting.js';
|
|
3
3
|
import { normaliseDeviceOs } from '../api/transactions.js';
|
|
4
|
+
import { REPORTER_PROJECT_ID_DESC, resolveReporterProjectName } from '../api/reporter-projects.js';
|
|
4
5
|
import { serverFsDownloadNotice, serverFsOutputParam, commandGeneratorNotice, localPlatformParamNotice } from '../utils/locality.js';
|
|
5
6
|
import { checkDeleteAllowed, serverSortAvailable } from '../api/access-level.js';
|
|
6
7
|
import { checkDestructiveGuard } from '../utils/destructive-guard.js';
|
|
@@ -12,7 +13,56 @@ import { commandPayload } from '../utils/command-payload.js';
|
|
|
12
13
|
import { parseReportRef } from '../utils/report-ref.js';
|
|
13
14
|
import { selectLogLines, DEFAULT_LOG_CONTEXT, DEFAULT_LOG_MAX_CHARS } from '../utils/log-view.js';
|
|
14
15
|
import { getRunningTestRequests } from '../api/test-requests.js';
|
|
16
|
+
import { getAllProjects } from '../api/projects.js';
|
|
15
17
|
import { countsFromPivotRow, tallyStatuses, passRate, statusOutcome, unknownStatusCount, PASS_RATE_BASIS } from '../utils/test-status.js';
|
|
18
|
+
/**
|
|
19
|
+
* Where does the lookback cutoff fall in the newest-first record order? Probes single records (limit 1, page = index+1)
|
|
20
|
+
* instead of extrapolating a rate. Returns neededRecords (rounded up, 5% headroom) when the window fits under maxCap,
|
|
21
|
+
* else fittingLookbackDays read from the record AT maxCap. About 10 tiny requests. Throws if the platform stops sorting.
|
|
22
|
+
*/
|
|
23
|
+
export async function measureTrendWindow(cutoffTs, scannedUpTo, maxCap, projectId, projectName) {
|
|
24
|
+
const at = async (index) => {
|
|
25
|
+
const b = await listTests({ limit: 1, page: index + 1, returnTotalCount: false, sort: [{ property: 'start_time', descending: true }] }, projectId, projectName);
|
|
26
|
+
if (b.sortApplied !== true)
|
|
27
|
+
throw new Error('sort not applied');
|
|
28
|
+
const r = b.data?.[0];
|
|
29
|
+
return r ? new Date(r.start_time).getTime() : null;
|
|
30
|
+
};
|
|
31
|
+
const atCap = await at(maxCap - 1);
|
|
32
|
+
if (atCap !== null && atCap >= cutoffTs) {
|
|
33
|
+
return { fittingLookbackDays: Math.max(1, Math.floor((Date.now() - atCap) / 86_400_000)) };
|
|
34
|
+
}
|
|
35
|
+
// Records [0, scannedUpTo) are in the window; the record at hi is out of it (or past the end).
|
|
36
|
+
let lo = scannedUpTo;
|
|
37
|
+
let hi = maxCap - 1;
|
|
38
|
+
while (hi - lo > 50) {
|
|
39
|
+
const mid = Math.floor((lo + hi) / 2);
|
|
40
|
+
const t = await at(mid);
|
|
41
|
+
if (t !== null && t >= cutoffTs)
|
|
42
|
+
lo = mid + 1;
|
|
43
|
+
else
|
|
44
|
+
hi = mid;
|
|
45
|
+
}
|
|
46
|
+
return { neededRecords: Math.min(maxCap, Math.ceil((hi * 1.05) / 500) * 500) };
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Names the project a delete runs in. A reporter projectId is resolved to a name before the delete, and reporter IDs
|
|
50
|
+
* differ from the cloud IDs list_projects shows — the preview must say which project the id landed on, so a mixed-up
|
|
51
|
+
* id is visible BEFORE confirmDeletion.
|
|
52
|
+
*/
|
|
53
|
+
const deleteScopeLabel = (projectName) => (projectName ? ` in project "${projectName}"` : '');
|
|
54
|
+
/**
|
|
55
|
+
* A reporter project_id FILTER only matches inside the project the call is scoped to: for another project's id the
|
|
56
|
+
* platform answers 0 records with no reason (verified live 2026-11-13 — project_id = 89 from the Default scope gave 0,
|
|
57
|
+
* the same project by name 3.1M). An empty result with that filter therefore gets a note pointing at the parameters
|
|
58
|
+
* that do scope the call (intake 2026-11-14: the projectId PARAMETER was fixed, the filter still answered silently).
|
|
59
|
+
*/
|
|
60
|
+
export function projectIdFilterNote(filter, resultCount) {
|
|
61
|
+
if (resultCount > 0 || !filter?.some((f) => f.property === 'project_id'))
|
|
62
|
+
return undefined;
|
|
63
|
+
return 'Note: a project_id filter only matches inside the project this call is scoped to — for another project it ' +
|
|
64
|
+
'returns nothing, as here. To query another project, drop the filter and pass projectId (the reporter project id) or projectName.';
|
|
65
|
+
}
|
|
16
66
|
export function registerReportingTools(server) {
|
|
17
67
|
// ─── get_test_report ───────────────────────────────────────────────────────
|
|
18
68
|
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>). ' +
|
|
@@ -252,7 +302,8 @@ export function registerReportingTools(server) {
|
|
|
252
302
|
'"success" (boolean true/false), ' +
|
|
253
303
|
'"accessibility_report" (JSON boolean true/false, NOT the string "true" — that 400s; true = runs with an Axe accessibility scan), ' +
|
|
254
304
|
'"test_id" (number), ' +
|
|
255
|
-
'"project_id" (number
|
|
305
|
+
'"project_id" (number — matches only INSIDE the project the call is scoped to; for another project it ' +
|
|
306
|
+
'returns 0 records, so pass the projectId or projectName parameter instead), ' +
|
|
256
307
|
'"device.os" ("Android"/"iOS" — case-sensitive), ' +
|
|
257
308
|
'"test.framework" (exact, case-sensitive: "Appium Server", "Appium Grid", "Selenium", "Espresso", "XCUITest", ' +
|
|
258
309
|
'"Maestro", "Playwright", "Cypress", "Mobile Studio Manual", … — get_distinct_test_key_values(["test.framework"]) ' +
|
|
@@ -295,7 +346,7 @@ export function registerReportingTools(server) {
|
|
|
295
346
|
.string()
|
|
296
347
|
.optional()
|
|
297
348
|
.describe('ISO 8601 end of date range, e.g. "2025-06-01T00:00:00Z". Defaults to now when startDate is provided.'),
|
|
298
|
-
projectId: z.number().int().optional().describe(
|
|
349
|
+
projectId: z.number().int().optional().describe(REPORTER_PROJECT_ID_DESC),
|
|
299
350
|
projectName: z.string().optional().describe('Scope results to this project name.'),
|
|
300
351
|
outputFormat: outputFormatParam,
|
|
301
352
|
}, async ({ fields, limit, page, searchValue, filter, sort, keys, returnTotalCount, startDate, endDate, projectId, projectName, outputFormat }) => {
|
|
@@ -377,10 +428,12 @@ export function registerReportingTools(server) {
|
|
|
377
428
|
const header = matched.length === 0
|
|
378
429
|
? `${totalLine}No tests found in range ${rangeLabel} (date filter applied client-side).`
|
|
379
430
|
: `${totalLine}${matched.length} test(s) shown for range ${rangeLabel} (date filter applied client-side):\n`;
|
|
431
|
+
const rangeNote = projectIdFilterNote(filter, matched.length);
|
|
380
432
|
return respond(outputFormat, {
|
|
381
433
|
reports: shape(matched),
|
|
382
434
|
...(wantTotal && { total: matchedCount, totalCapped: countCapped }),
|
|
383
|
-
|
|
435
|
+
...(rangeNote && { note: rangeNote }),
|
|
436
|
+
}, header + (matched.length > 0 ? '\n' + render(matched) : '') + (rangeNote ? `\n\n${rangeNote}` : ''));
|
|
384
437
|
}
|
|
385
438
|
const request = {
|
|
386
439
|
limit: targetLimit,
|
|
@@ -400,7 +453,8 @@ export function registerReportingTools(server) {
|
|
|
400
453
|
? 'The platform refused server-side sort for this credential — these results are in platform order, NOT the order requested. ' +
|
|
401
454
|
'For newest-first results use find_latest_test_for_name / list_active_test_executions, or pass startDate/endDate (scanned and ordered client-side).'
|
|
402
455
|
: undefined;
|
|
403
|
-
|
|
456
|
+
const emptyNote = projectIdFilterNote(filter, reports.length);
|
|
457
|
+
return respond(outputFormat, { reports: shape(reports), total: result.count, ...(sortRefused && { sortApplied: false, warning: sortWarning }), ...(emptyNote && { note: emptyNote }) }, (sortWarning ? `⚠️ ${sortWarning}\n\n` : '') + countLine + render(reports) + (emptyNote ? `\n\n${emptyNote}` : ''));
|
|
404
458
|
}
|
|
405
459
|
catch (e) {
|
|
406
460
|
return { content: [{ type: 'text', text: `Error: ${e.message}` }], isError: true };
|
|
@@ -436,7 +490,7 @@ export function registerReportingTools(server) {
|
|
|
436
490
|
.boolean()
|
|
437
491
|
.optional()
|
|
438
492
|
.describe('If true, adds totalRecords — the number of test records across all groups (the response\x27s count is the number of groups).'),
|
|
439
|
-
projectId: z.number().int().optional().describe(
|
|
493
|
+
projectId: z.number().int().optional().describe(REPORTER_PROJECT_ID_DESC),
|
|
440
494
|
projectName: z.string().optional().describe('Scope to this project name.'),
|
|
441
495
|
outputFormat: outputFormatParam,
|
|
442
496
|
}, async ({ groupBy, pivotBy, filter, returnTotalCount, projectId, projectName, outputFormat }) => {
|
|
@@ -495,7 +549,7 @@ export function registerReportingTools(server) {
|
|
|
495
549
|
.array(z.string())
|
|
496
550
|
.min(1)
|
|
497
551
|
.describe('One or more key names, e.g. ["device.os", "browser", "environment"].'),
|
|
498
|
-
projectId: z.number().int().optional().describe(
|
|
552
|
+
projectId: z.number().int().optional().describe(REPORTER_PROJECT_ID_DESC),
|
|
499
553
|
projectName: z.string().optional().describe('Scope to this project name.'),
|
|
500
554
|
outputFormat: outputFormatParam,
|
|
501
555
|
}, async ({ keys, projectId, projectName, outputFormat }) => {
|
|
@@ -552,9 +606,17 @@ export function registerReportingTools(server) {
|
|
|
552
606
|
.boolean()
|
|
553
607
|
.optional()
|
|
554
608
|
.describe('Must be true to confirm the permanent deletion.'),
|
|
555
|
-
projectId: z.number().int().optional().describe(
|
|
609
|
+
projectId: z.number().int().optional().describe(REPORTER_PROJECT_ID_DESC),
|
|
556
610
|
projectName: z.string().optional().describe('Exact project name (from list_projects) to scope the delete to a specific reporter instance.'),
|
|
557
611
|
}, async ({ ids, confirmDeletion, projectId, projectName }) => {
|
|
612
|
+
// Resolve a reporter projectId to its name FIRST: the gate (and the delete) must look at the project the
|
|
613
|
+
// records are in, not the default scope.
|
|
614
|
+
try {
|
|
615
|
+
projectName = await resolveReporterProjectName(projectId, projectName);
|
|
616
|
+
}
|
|
617
|
+
catch (e) {
|
|
618
|
+
return { content: [{ type: 'text', text: `Error: ${e.message}` }], isError: true };
|
|
619
|
+
}
|
|
558
620
|
const denied = await checkDeleteAllowed(projectName);
|
|
559
621
|
if (denied) {
|
|
560
622
|
return { content: [{ type: 'text', text: denied }], isError: true };
|
|
@@ -564,7 +626,10 @@ export function registerReportingTools(server) {
|
|
|
564
626
|
// Fetch details for all IDs so the guard shows a human-readable preview.
|
|
565
627
|
// If any ID cannot be resolved, block the deletion entirely rather than
|
|
566
628
|
// silently deleting records the caller cannot verify.
|
|
567
|
-
|
|
629
|
+
// GET /tests/{id} always answers from the default reporter scope, so with a project the preview reads the
|
|
630
|
+
// records through the project-scoped list — the same scope the delete runs in. Otherwise the preview could
|
|
631
|
+
// show the Default project's report N while the confirmed delete removes the other project's report N.
|
|
632
|
+
const results = await Promise.allSettled(ids.map(id => projectName ? getScopedTest(id, projectName) : getTestById(id)));
|
|
568
633
|
const failedIndices = results.reduce((acc, r, i) => (r.status === 'rejected' ? [...acc, i] : acc), []);
|
|
569
634
|
if (failedIndices.length > 0) {
|
|
570
635
|
const failedIds = failedIndices.map(i => ids[i]).join(', ');
|
|
@@ -572,7 +637,7 @@ export function registerReportingTools(server) {
|
|
|
572
637
|
content: [{
|
|
573
638
|
type: 'text',
|
|
574
639
|
text: `⛔ Cannot preview deletion: ${failedIndices.length} of the requested ID(s) could not be resolved ` +
|
|
575
|
-
`in the current reporter scope: [${failedIds}].\n\n` +
|
|
640
|
+
`in ${projectName ? `project "${projectName}"` : 'the current reporter scope'}: [${failedIds}].\n\n` +
|
|
576
641
|
`Verify these IDs exist and are accessible with the active credentials. ` +
|
|
577
642
|
`If they belong to a different project, switch to that project's profile ` +
|
|
578
643
|
`with switch_environment() and retry.\n\nNo changes were made.`,
|
|
@@ -588,17 +653,17 @@ export function registerReportingTools(server) {
|
|
|
588
653
|
const header = ` ${'ID'.padEnd(10)} ${'Status'.padEnd(12)} ${'Start (UTC)'.padEnd(20)} Name`;
|
|
589
654
|
const sep = ` ${'-'.repeat(9)} ${'-'.repeat(11)} ${'-'.repeat(19)} ${'-'.repeat(30)}`;
|
|
590
655
|
const table = [header, sep, ...rows].join('\n');
|
|
591
|
-
const guard = checkDestructiveGuard(confirmDeletion, `Delete ${ids.length} test report(s)`);
|
|
656
|
+
const guard = checkDestructiveGuard(confirmDeletion, `Delete ${ids.length} test report(s)${deleteScopeLabel(projectName)}`);
|
|
592
657
|
return { content: [{ type: 'text', text: `${guard}\n\nRecords that would be deleted:\n${table}` }] };
|
|
593
658
|
}
|
|
594
659
|
// >50 IDs — skip detail fetch, return guard with ID list
|
|
595
|
-
const guard = checkDestructiveGuard(confirmDeletion, `Delete ${ids.length} test report(s): [${ids.join(', ')}]`);
|
|
660
|
+
const guard = checkDestructiveGuard(confirmDeletion, `Delete ${ids.length} test report(s)${deleteScopeLabel(projectName)}: [${ids.join(', ')}]`);
|
|
596
661
|
return { content: [{ type: 'text', text: guard }] };
|
|
597
662
|
}
|
|
598
663
|
try {
|
|
599
664
|
await deleteTests(ids, projectId, projectName);
|
|
600
665
|
return {
|
|
601
|
-
content: [{ type: 'text', text: `✅ Successfully deleted ${ids.length} test report(s).` }],
|
|
666
|
+
content: [{ type: 'text', text: `✅ Successfully deleted ${ids.length} test report(s)${deleteScopeLabel(projectName)}.` }],
|
|
602
667
|
};
|
|
603
668
|
}
|
|
604
669
|
catch (e) {
|
|
@@ -606,7 +671,7 @@ export function registerReportingTools(server) {
|
|
|
606
671
|
}
|
|
607
672
|
});
|
|
608
673
|
// ─── delete_test_reports_by_name ──────────────────────────────────────────
|
|
609
|
-
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.
|
|
674
|
+
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. A reporter projectId is resolved to its project name.', {
|
|
610
675
|
name: z
|
|
611
676
|
.string()
|
|
612
677
|
.optional()
|
|
@@ -624,9 +689,17 @@ export function registerReportingTools(server) {
|
|
|
624
689
|
.int()
|
|
625
690
|
.optional()
|
|
626
691
|
.describe('Maximum records to show in preview (confirmDeletion: false). Defaults to 50. The deletion itself (confirmDeletion: true) always processes all matching records regardless of this limit.'),
|
|
627
|
-
projectId: z.number().int().optional().describe(
|
|
692
|
+
projectId: z.number().int().optional().describe(REPORTER_PROJECT_ID_DESC),
|
|
628
693
|
projectName: z.string().optional().describe('Exact project name (from list_projects) to scope the search. Required when the target project has its own reporter instance separate from the default scope.'),
|
|
629
694
|
}, async ({ name, nameContains, confirmDeletion, maxPreviewResults, projectId, projectName }) => {
|
|
695
|
+
// Resolve a reporter projectId to its name FIRST: the gate (and the delete) must look at the project the
|
|
696
|
+
// records are in, not the default scope.
|
|
697
|
+
try {
|
|
698
|
+
projectName = await resolveReporterProjectName(projectId, projectName);
|
|
699
|
+
}
|
|
700
|
+
catch (e) {
|
|
701
|
+
return { content: [{ type: 'text', text: `Error: ${e.message}` }], isError: true };
|
|
702
|
+
}
|
|
630
703
|
const denied = await checkDeleteAllowed(projectName);
|
|
631
704
|
if (denied) {
|
|
632
705
|
return { content: [{ type: 'text', text: denied }], isError: true };
|
|
@@ -653,7 +726,7 @@ export function registerReportingTools(server) {
|
|
|
653
726
|
return { content: [{ type: 'text', text: `No test reports found matching ${criterion}.` }] };
|
|
654
727
|
}
|
|
655
728
|
const total = typeof newest.count === 'number' && newest.count >= rows.length ? newest.count : rows.length;
|
|
656
|
-
const guard = checkDestructiveGuard(false, `Delete ${total} test report(s) matching "${name ?? nameContains}"`);
|
|
729
|
+
const guard = checkDestructiveGuard(false, `Delete ${total} test report(s) matching "${name ?? nameContains}"${deleteScopeLabel(projectName)}`);
|
|
657
730
|
const lines = rows.map((r) => ` ${r.test_id}: ${r.name} (${r.start_time?.slice(0, 10) ?? '?'})`);
|
|
658
731
|
const more = total > rows.length
|
|
659
732
|
? `\n\n⚠️ Showing the newest ${rows.length} of ${total} matches. confirmDeletion: true deletes all ${total}; narrow nameContains to delete fewer.`
|
|
@@ -686,7 +759,7 @@ export function registerReportingTools(server) {
|
|
|
686
759
|
return { content: [{ type: 'text', text: `No test reports found matching ${criterion}.` }] };
|
|
687
760
|
}
|
|
688
761
|
const countDesc = truncated ? `${previewCap}+ (preview capped at ${previewCap})` : `${allIds.length}`;
|
|
689
|
-
const guard = checkDestructiveGuard(confirmDeletion, `Delete ${countDesc} test report(s) matching "${name ?? nameContains}"`);
|
|
762
|
+
const guard = checkDestructiveGuard(confirmDeletion, `Delete ${countDesc} test report(s) matching "${name ?? nameContains}"${deleteScopeLabel(projectName)}`);
|
|
690
763
|
if (guard) {
|
|
691
764
|
const truncationNote = truncated
|
|
692
765
|
? `\n\n⚠️ Showing first ${previewCap} of ${previewCap}+ matches. Re-run with confirmDeletion: true to delete all matches, or use a more specific nameContains value to narrow the search.`
|
|
@@ -700,7 +773,7 @@ export function registerReportingTools(server) {
|
|
|
700
773
|
}
|
|
701
774
|
await deleteTests(allIds, projectId, projectName);
|
|
702
775
|
return {
|
|
703
|
-
content: [{ type: 'text', text: `✅ Deleted ${allIds.length} test report(s) matching "${name ?? nameContains}".` }],
|
|
776
|
+
content: [{ type: 'text', text: `✅ Deleted ${allIds.length} test report(s) matching "${name ?? nameContains}"${deleteScopeLabel(projectName)}.` }],
|
|
704
777
|
};
|
|
705
778
|
}
|
|
706
779
|
catch (e) {
|
|
@@ -872,7 +945,7 @@ export function registerReportingTools(server) {
|
|
|
872
945
|
.describe("Dimension to bucket by: 'errorClassification' (default, e.g. element_not_found), 'errorCategory' (e.g. assertion, device, network), or 'name'."),
|
|
873
946
|
nameFilter: z.string().optional().describe('Only include failures whose test name contains this substring (e.g. "Login").'),
|
|
874
947
|
maxReports: z.number().int().min(1).max(1000).optional().default(200).describe('Cap on failures analyzed (fan-out bound). Default 200. capped:true in the result means more failures exist beyond this.'),
|
|
875
|
-
projectId: z.number().int().optional().describe(
|
|
948
|
+
projectId: z.number().int().optional().describe(REPORTER_PROJECT_ID_DESC),
|
|
876
949
|
projectName: z.string().optional().describe('Scope to a project by name.'),
|
|
877
950
|
outputFormat: outputFormatParam,
|
|
878
951
|
}, async ({ startDate, endDate, groupBy, nameFilter, maxReports, projectId, projectName, outputFormat }) => {
|
|
@@ -914,7 +987,7 @@ export function registerReportingTools(server) {
|
|
|
914
987
|
// ─── find_latest_test_for_name ─────────────────────────────────────────────
|
|
915
988
|
server.tool('find_latest_test_for_name', 'Return the most recent execution record for a test by name. Answers "did the last run of X pass?" without requiring a full list_test_reports query.', {
|
|
916
989
|
name: z.string().describe('Exact or partial test name to search for.'),
|
|
917
|
-
projectId: z.number().int().optional().describe(
|
|
990
|
+
projectId: z.number().int().optional().describe(REPORTER_PROJECT_ID_DESC),
|
|
918
991
|
projectName: z.string().optional().describe('Scope to this project name.'),
|
|
919
992
|
outputFormat: outputFormatParam,
|
|
920
993
|
}, async ({ name, projectId, projectName, outputFormat }) => {
|
|
@@ -942,7 +1015,7 @@ export function registerReportingTools(server) {
|
|
|
942
1015
|
.string()
|
|
943
1016
|
.optional()
|
|
944
1017
|
.describe('ISO 8601 end of the window. Defaults to now if omitted.'),
|
|
945
|
-
projectId: z.number().int().optional().describe(
|
|
1018
|
+
projectId: z.number().int().optional().describe(REPORTER_PROJECT_ID_DESC),
|
|
946
1019
|
projectName: z.string().optional().describe('Scope to this project name.'),
|
|
947
1020
|
outputFormat: outputFormatParam,
|
|
948
1021
|
}, async ({ startDate, endDate, projectId, projectName, outputFormat }) => {
|
|
@@ -1020,9 +1093,17 @@ export function registerReportingTools(server) {
|
|
|
1020
1093
|
.boolean()
|
|
1021
1094
|
.optional()
|
|
1022
1095
|
.describe('Must be true to confirm the permanent deletion. Omit or set false to preview what would be deleted.'),
|
|
1023
|
-
projectId: z.number().int().optional().describe(
|
|
1096
|
+
projectId: z.number().int().optional().describe(REPORTER_PROJECT_ID_DESC),
|
|
1024
1097
|
projectName: z.string().optional().describe('Scope to this project name.'),
|
|
1025
1098
|
}, async ({ beforeDate, confirmDeletion, projectId, projectName }) => {
|
|
1099
|
+
// Resolve a reporter projectId to its name FIRST: the gate (and the delete) must look at the project the
|
|
1100
|
+
// records are in, not the default scope.
|
|
1101
|
+
try {
|
|
1102
|
+
projectName = await resolveReporterProjectName(projectId, projectName);
|
|
1103
|
+
}
|
|
1104
|
+
catch (e) {
|
|
1105
|
+
return { content: [{ type: 'text', text: `Error: ${e.message}` }], isError: true };
|
|
1106
|
+
}
|
|
1026
1107
|
const denied = await checkDeleteAllowed(projectName);
|
|
1027
1108
|
if (denied) {
|
|
1028
1109
|
return { content: [{ type: 'text', text: denied }], isError: true };
|
|
@@ -1046,7 +1127,7 @@ export function registerReportingTools(server) {
|
|
|
1046
1127
|
if (allIds.length === 0) {
|
|
1047
1128
|
return { content: [{ type: 'text', text: `No test reports found before ${beforeDate}.` }] };
|
|
1048
1129
|
}
|
|
1049
|
-
const guard = checkDestructiveGuard(confirmDeletion, `Delete ${allIds.length} test report(s) started before ${beforeDate}`);
|
|
1130
|
+
const guard = checkDestructiveGuard(confirmDeletion, `Delete ${allIds.length} test report(s) started before ${beforeDate}${deleteScopeLabel(projectName)}`);
|
|
1050
1131
|
if (guard) {
|
|
1051
1132
|
return {
|
|
1052
1133
|
content: [{ type: 'text', text: `${guard}\n\nPreview: ${allIds.length} record(s) would be deleted (IDs ${allIds[0]}…${allIds[allIds.length - 1]}).` }],
|
|
@@ -1054,7 +1135,7 @@ export function registerReportingTools(server) {
|
|
|
1054
1135
|
}
|
|
1055
1136
|
await deleteTests(allIds, projectId, projectName);
|
|
1056
1137
|
return {
|
|
1057
|
-
content: [{ type: 'text', text: `✅ Deleted ${allIds.length} test report(s) started before ${beforeDate}.` }],
|
|
1138
|
+
content: [{ type: 'text', text: `✅ Deleted ${allIds.length} test report(s) started before ${beforeDate}${deleteScopeLabel(projectName)}.` }],
|
|
1058
1139
|
};
|
|
1059
1140
|
}
|
|
1060
1141
|
catch (e) {
|
|
@@ -1081,7 +1162,8 @@ export function registerReportingTools(server) {
|
|
|
1081
1162
|
.optional()
|
|
1082
1163
|
.default(12)
|
|
1083
1164
|
.describe('Fallback (reporter heuristic) only: 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).'),
|
|
1084
|
-
projectId: z.number().int().optional().describe('
|
|
1165
|
+
projectId: z.number().int().optional().describe('CLOUD project ID (as get_server_info / list_projects show) — matched against the platform\'s live list. ' +
|
|
1166
|
+
'The reporter fallback (whose IDs differ) is scoped by the matching project name instead.'),
|
|
1085
1167
|
projectName: z.string().optional().describe('Scope to this project name.'),
|
|
1086
1168
|
outputFormat: outputFormatParam,
|
|
1087
1169
|
}, async ({ limit, maxAgeHours, projectId, projectName, outputFormat }) => {
|
|
@@ -1095,6 +1177,7 @@ export function registerReportingTools(server) {
|
|
|
1095
1177
|
liveError = e.message;
|
|
1096
1178
|
}
|
|
1097
1179
|
if (live) {
|
|
1180
|
+
// Here projectId is the CLOUD project id — the live list carries that one.
|
|
1098
1181
|
const scoped = live.filter((r) => (projectName === undefined || (r.projectName ?? '').toLowerCase() === projectName.toLowerCase()) &&
|
|
1099
1182
|
(projectId === undefined || r.projectId === projectId));
|
|
1100
1183
|
const shown = scoped.slice(0, limit ?? 50);
|
|
@@ -1112,6 +1195,16 @@ export function registerReportingTools(server) {
|
|
|
1112
1195
|
return respond(outputFormat, structured, lines.join('\n'));
|
|
1113
1196
|
}
|
|
1114
1197
|
try {
|
|
1198
|
+
// The reporter cannot scope by the CLOUD projectId (its ids differ) — map it to the project name, which both
|
|
1199
|
+
// sides share, so a projectId-only call is not silently answered for every project.
|
|
1200
|
+
let fallbackProjectName = projectName;
|
|
1201
|
+
if (!fallbackProjectName && projectId !== undefined) {
|
|
1202
|
+
const project = (await getAllProjects()).find((p) => Number(p.id) === projectId);
|
|
1203
|
+
if (!project) {
|
|
1204
|
+
return { content: [{ type: 'text', text: `Error: cloud project ID ${projectId} was not found in list_projects — pass projectName instead.` }], isError: true };
|
|
1205
|
+
}
|
|
1206
|
+
fallbackProjectName = project.name;
|
|
1207
|
+
}
|
|
1115
1208
|
// Fallback: active executions are Incomplete records with null duration.
|
|
1116
1209
|
// We fetch more than needed since not all Incomplete records are still running.
|
|
1117
1210
|
const result = await listTestsSortedDesc({
|
|
@@ -1119,7 +1212,8 @@ export function registerReportingTools(server) {
|
|
|
1119
1212
|
page: 1,
|
|
1120
1213
|
returnTotalCount: false,
|
|
1121
1214
|
filter: [{ property: 'status', operator: '=', value: 'Incomplete' }],
|
|
1122
|
-
},
|
|
1215
|
+
}, undefined, // projectId here is the cloud id — the reporter's ids differ; scoped by name instead
|
|
1216
|
+
fallbackProjectName);
|
|
1123
1217
|
// Incomplete + null duration also matches runs that were abandoned or never finalised — the UAT (2026-10-09)
|
|
1124
1218
|
// found every "active" execution was 3+ days old. Anything older than maxAgeHours is not running now.
|
|
1125
1219
|
const ageCutoff = Date.now() - (maxAgeHours ?? 12) * 3600_000;
|
|
@@ -1168,7 +1262,7 @@ export function registerReportingTools(server) {
|
|
|
1168
1262
|
.string()
|
|
1169
1263
|
.default('appVersion')
|
|
1170
1264
|
.describe('The test report metadata key that holds the app version, e.g. "appVersion" or "buildNumber".'),
|
|
1171
|
-
projectId: z.number().int().optional().describe(
|
|
1265
|
+
projectId: z.number().int().optional().describe(REPORTER_PROJECT_ID_DESC),
|
|
1172
1266
|
projectName: z.string().optional().describe('Scope to this project name.'),
|
|
1173
1267
|
outputFormat: outputFormatParam,
|
|
1174
1268
|
}, async ({ versionKey, projectId, projectName, outputFormat }) => {
|
|
@@ -1187,7 +1281,7 @@ export function registerReportingTools(server) {
|
|
|
1187
1281
|
testName: z.string().describe('Exact or partial test name to look up.'),
|
|
1188
1282
|
maxRuns: z.number().int().min(1).max(200).optional().default(20)
|
|
1189
1283
|
.describe('Number of most-recent runs to retrieve (default: 20, max: 200).'),
|
|
1190
|
-
projectId: z.number().int().optional().describe(
|
|
1284
|
+
projectId: z.number().int().optional().describe(REPORTER_PROJECT_ID_DESC),
|
|
1191
1285
|
projectName: z.string().optional().describe('Scope to this project name.'),
|
|
1192
1286
|
outputFormat: outputFormatParam,
|
|
1193
1287
|
}, async ({ testName, maxRuns, projectId, projectName, outputFormat }) => {
|
|
@@ -1267,7 +1361,7 @@ export function registerReportingTools(server) {
|
|
|
1267
1361
|
.describe('Minimum runs on each platform to include a test in the comparison (default: 3). Filters out tests barely run on one OS.'),
|
|
1268
1362
|
minDivergencePct: z.number().min(0).max(100).optional().default(20)
|
|
1269
1363
|
.describe('Minimum pass-rate gap (percentage points) to flag as divergent (default: 20).'),
|
|
1270
|
-
projectId: z.number().int().optional().describe(
|
|
1364
|
+
projectId: z.number().int().optional().describe(REPORTER_PROJECT_ID_DESC),
|
|
1271
1365
|
projectName: z.string().optional().describe('Scope to this project name.'),
|
|
1272
1366
|
outputFormat: outputFormatParam,
|
|
1273
1367
|
}, async ({ minRunsPerPlatform, minDivergencePct, projectId, projectName, outputFormat }) => {
|
|
@@ -1338,7 +1432,7 @@ export function registerReportingTools(server) {
|
|
|
1338
1432
|
.describe('Hard cap on records fetched to protect against very large datasets (default: 5 000, max: 25 000). Increase if your project runs >165 tests/day and lookbackDays > 30.'),
|
|
1339
1433
|
bucketBy: z.enum(['day', 'week']).optional().default('day')
|
|
1340
1434
|
.describe('"day" (default) or "week". Weekly buckets are cleaner for 90-day views.'),
|
|
1341
|
-
projectId: z.number().int().optional().describe(
|
|
1435
|
+
projectId: z.number().int().optional().describe(REPORTER_PROJECT_ID_DESC),
|
|
1342
1436
|
projectName: z.string().optional().describe('Scope to this project name.'),
|
|
1343
1437
|
outputFormat: outputFormatParam,
|
|
1344
1438
|
}, async ({ lookbackDays, maxRecords, bucketBy, projectId, projectName, outputFormat }) => {
|
|
@@ -1349,6 +1443,7 @@ export function registerReportingTools(server) {
|
|
|
1349
1443
|
let scanned = 0;
|
|
1350
1444
|
let scanCapped = false;
|
|
1351
1445
|
let done = false;
|
|
1446
|
+
let lastSorted = false;
|
|
1352
1447
|
while (!done && records.length < maxRecords) {
|
|
1353
1448
|
const wantSort = serverSortAvailable();
|
|
1354
1449
|
const batch = await listTests({ limit: 500, page: fetchPage, returnTotalCount: false,
|
|
@@ -1365,6 +1460,7 @@ export function registerReportingTools(server) {
|
|
|
1365
1460
|
break;
|
|
1366
1461
|
scanned += rows.length;
|
|
1367
1462
|
const isSorted = batch.sortApplied === true;
|
|
1463
|
+
lastSorted = isSorted;
|
|
1368
1464
|
for (const r of rows) {
|
|
1369
1465
|
const ts = new Date(r.start_time).getTime();
|
|
1370
1466
|
// Early-exit is only valid on server-sorted data; otherwise skip out-of-window rows and keep scanning.
|
|
@@ -1427,10 +1523,17 @@ export function registerReportingTools(server) {
|
|
|
1427
1523
|
const MAX_RECORDS = 25_000;
|
|
1428
1524
|
const coveredDays = Math.max((Date.now() - new Date(coveredFrom).getTime()) / 86_400_000, 1 / 24);
|
|
1429
1525
|
const estimatedNeeded = Math.ceil((records.length / coveredDays) * lookbackDays * 1.1 / 500) * 500;
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1526
|
+
// On sorted data, MEASURE where the cutoff falls instead of extrapolating: a rate taken from the newest days
|
|
1527
|
+
// missed a burst (UAT 2026-11-13 run 2 — the suggested 15,500 fell short because one older day had ~10k runs).
|
|
1528
|
+
const measured = scanCapped && lastSorted
|
|
1529
|
+
? await measureTrendWindow(cutoffTs, maxRecords, MAX_RECORDS, projectId, projectName).catch(() => null)
|
|
1433
1530
|
: null;
|
|
1531
|
+
const suggestedMaxRecords = !scanCapped ? null
|
|
1532
|
+
: measured?.neededRecords ?? (measured?.fittingLookbackDays != null ? MAX_RECORDS : Math.min(estimatedNeeded, MAX_RECORDS));
|
|
1533
|
+
const fittingLookbackDays = !scanCapped ? null
|
|
1534
|
+
: measured ? (measured.fittingLookbackDays ?? null)
|
|
1535
|
+
: estimatedNeeded > MAX_RECORDS ? Math.max(1, Math.floor((MAX_RECORDS / (records.length / coveredDays)) / 1.1)) : null;
|
|
1536
|
+
const suggestionBasis = measured ? 'measured' : 'estimated from the rate observed so far';
|
|
1434
1537
|
const structured = {
|
|
1435
1538
|
bucketBy,
|
|
1436
1539
|
lookbackDays,
|
|
@@ -1444,6 +1547,7 @@ export function registerReportingTools(server) {
|
|
|
1444
1547
|
? {
|
|
1445
1548
|
missingRange: { from: new Date(cutoffTs).toISOString(), to: coveredFrom },
|
|
1446
1549
|
suggestedMaxRecords,
|
|
1550
|
+
suggestionBasis,
|
|
1447
1551
|
...(fittingLookbackDays != null ? { fittingLookbackDays } : {}),
|
|
1448
1552
|
}
|
|
1449
1553
|
: {}),
|
|
@@ -1473,7 +1577,7 @@ export function registerReportingTools(server) {
|
|
|
1473
1577
|
`days before that are MISSING from this trend, not days with zero executions. ` +
|
|
1474
1578
|
(fittingLookbackDays != null
|
|
1475
1579
|
? `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.`
|
|
1476
|
-
: `Re-run with maxRecords: ${suggestedMaxRecords} to cover the full ${lookbackDays}-day window (
|
|
1580
|
+
: `Re-run with maxRecords: ${suggestedMaxRecords} to cover the full ${lookbackDays}-day window (${suggestionBasis}).`));
|
|
1477
1581
|
}
|
|
1478
1582
|
return respond(outputFormat, structured, lines.join('\n'));
|
|
1479
1583
|
}
|