simplify3x-connect 0.0.0-stage → 0.28.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.
- package/LICENSE +21 -0
- package/README.md +117 -3
- package/dist/acText.d.ts +12 -0
- package/dist/acText.d.ts.map +1 -0
- package/dist/acText.js +44 -0
- package/dist/acText.js.map +1 -0
- package/dist/adapters/factory.d.ts +25 -0
- package/dist/adapters/factory.d.ts.map +1 -0
- package/dist/adapters/factory.js +55 -0
- package/dist/adapters/factory.js.map +1 -0
- package/dist/adapters/http.d.ts +62 -0
- package/dist/adapters/http.d.ts.map +1 -0
- package/dist/adapters/http.js +138 -0
- package/dist/adapters/http.js.map +1 -0
- package/dist/adapters/remoteMcp/adapter.d.ts +112 -0
- package/dist/adapters/remoteMcp/adapter.d.ts.map +1 -0
- package/dist/adapters/remoteMcp/adapter.js +259 -0
- package/dist/adapters/remoteMcp/adapter.js.map +1 -0
- package/dist/adapters/simplifyqa/adapter.d.ts +1390 -0
- package/dist/adapters/simplifyqa/adapter.d.ts.map +1 -0
- package/dist/adapters/simplifyqa/adapter.js +9126 -0
- package/dist/adapters/simplifyqa/adapter.js.map +1 -0
- package/dist/adapters/simplifyqa/apiFailureReason.d.ts +11 -0
- package/dist/adapters/simplifyqa/apiFailureReason.d.ts.map +1 -0
- package/dist/adapters/simplifyqa/apiFailureReason.js +35 -0
- package/dist/adapters/simplifyqa/apiFailureReason.js.map +1 -0
- package/dist/adapters/simplifyqa/desktopConditions.d.ts +50 -0
- package/dist/adapters/simplifyqa/desktopConditions.d.ts.map +1 -0
- package/dist/adapters/simplifyqa/desktopConditions.js +95 -0
- package/dist/adapters/simplifyqa/desktopConditions.js.map +1 -0
- package/dist/adapters/simplifyqa/executionFailures.d.ts +59 -0
- package/dist/adapters/simplifyqa/executionFailures.d.ts.map +1 -0
- package/dist/adapters/simplifyqa/executionFailures.js +641 -0
- package/dist/adapters/simplifyqa/executionFailures.js.map +1 -0
- package/dist/adapters/simplifyqa/failureCategory.d.ts +26 -0
- package/dist/adapters/simplifyqa/failureCategory.d.ts.map +1 -0
- package/dist/adapters/simplifyqa/failureCategory.js +208 -0
- package/dist/adapters/simplifyqa/failureCategory.js.map +1 -0
- package/dist/adapters/simplifyqa/failureReport.d.ts +50 -0
- package/dist/adapters/simplifyqa/failureReport.d.ts.map +1 -0
- package/dist/adapters/simplifyqa/failureReport.js +383 -0
- package/dist/adapters/simplifyqa/failureReport.js.map +1 -0
- package/dist/adapters/simplifyqa/failureTypes.d.ts +193 -0
- package/dist/adapters/simplifyqa/failureTypes.d.ts.map +1 -0
- package/dist/adapters/simplifyqa/failureTypes.js +8 -0
- package/dist/adapters/simplifyqa/failureTypes.js.map +1 -0
- package/dist/adapters/simplifyqa/flow.d.ts +58 -0
- package/dist/adapters/simplifyqa/flow.d.ts.map +1 -0
- package/dist/adapters/simplifyqa/flow.js +335 -0
- package/dist/adapters/simplifyqa/flow.js.map +1 -0
- package/dist/adapters/simplifyqa/functionMatch.d.ts +53 -0
- package/dist/adapters/simplifyqa/functionMatch.d.ts.map +1 -0
- package/dist/adapters/simplifyqa/functionMatch.js +110 -0
- package/dist/adapters/simplifyqa/functionMatch.js.map +1 -0
- package/dist/adapters/simplifyqa/heal/apply.d.ts +59 -0
- package/dist/adapters/simplifyqa/heal/apply.d.ts.map +1 -0
- package/dist/adapters/simplifyqa/heal/apply.js +213 -0
- package/dist/adapters/simplifyqa/heal/apply.js.map +1 -0
- package/dist/adapters/simplifyqa/heal/diagnose.d.ts +24 -0
- package/dist/adapters/simplifyqa/heal/diagnose.d.ts.map +1 -0
- package/dist/adapters/simplifyqa/heal/diagnose.js +211 -0
- package/dist/adapters/simplifyqa/heal/diagnose.js.map +1 -0
- package/dist/adapters/simplifyqa/heal/index.d.ts +37 -0
- package/dist/adapters/simplifyqa/heal/index.d.ts.map +1 -0
- package/dist/adapters/simplifyqa/heal/index.js +83 -0
- package/dist/adapters/simplifyqa/heal/index.js.map +1 -0
- package/dist/adapters/simplifyqa/heal/plan.d.ts +67 -0
- package/dist/adapters/simplifyqa/heal/plan.d.ts.map +1 -0
- package/dist/adapters/simplifyqa/heal/plan.js +338 -0
- package/dist/adapters/simplifyqa/heal/plan.js.map +1 -0
- package/dist/adapters/simplifyqa/heal/store.d.ts +10 -0
- package/dist/adapters/simplifyqa/heal/store.d.ts.map +1 -0
- package/dist/adapters/simplifyqa/heal/store.js +40 -0
- package/dist/adapters/simplifyqa/heal/store.js.map +1 -0
- package/dist/adapters/simplifyqa/mapLimit.d.ts +3 -0
- package/dist/adapters/simplifyqa/mapLimit.d.ts.map +1 -0
- package/dist/adapters/simplifyqa/mapLimit.js +14 -0
- package/dist/adapters/simplifyqa/mapLimit.js.map +1 -0
- package/dist/adapters/simplifyqa/mapper.d.ts +159 -0
- package/dist/adapters/simplifyqa/mapper.d.ts.map +1 -0
- package/dist/adapters/simplifyqa/mapper.js +1767 -0
- package/dist/adapters/simplifyqa/mapper.js.map +1 -0
- package/dist/adapters/simplifyqa/planTree.d.ts +31 -0
- package/dist/adapters/simplifyqa/planTree.d.ts.map +1 -0
- package/dist/adapters/simplifyqa/planTree.js +110 -0
- package/dist/adapters/simplifyqa/planTree.js.map +1 -0
- package/dist/adapters/simplifyqa/searchEngine.d.ts +254 -0
- package/dist/adapters/simplifyqa/searchEngine.d.ts.map +1 -0
- package/dist/adapters/simplifyqa/searchEngine.js +1248 -0
- package/dist/adapters/simplifyqa/searchEngine.js.map +1 -0
- package/dist/adapters/simplifyqa/searchRegistry.d.ts +117 -0
- package/dist/adapters/simplifyqa/searchRegistry.d.ts.map +1 -0
- package/dist/adapters/simplifyqa/searchRegistry.js +1664 -0
- package/dist/adapters/simplifyqa/searchRegistry.js.map +1 -0
- package/dist/adapters/simplifyqa/searchResolve.d.ts +84 -0
- package/dist/adapters/simplifyqa/searchResolve.d.ts.map +1 -0
- package/dist/adapters/simplifyqa/searchResolve.js +319 -0
- package/dist/adapters/simplifyqa/searchResolve.js.map +1 -0
- package/dist/adapters/simplifyqa/stepDiagnostics.d.ts +25 -0
- package/dist/adapters/simplifyqa/stepDiagnostics.d.ts.map +1 -0
- package/dist/adapters/simplifyqa/stepDiagnostics.js +89 -0
- package/dist/adapters/simplifyqa/stepDiagnostics.js.map +1 -0
- package/dist/adapters/simplifyqa/stepRules.d.ts +91 -0
- package/dist/adapters/simplifyqa/stepRules.d.ts.map +1 -0
- package/dist/adapters/simplifyqa/stepRules.js +228 -0
- package/dist/adapters/simplifyqa/stepRules.js.map +1 -0
- package/dist/adapters/types.d.ts +514 -0
- package/dist/adapters/types.d.ts.map +1 -0
- package/dist/adapters/types.js +2 -0
- package/dist/adapters/types.js.map +1 -0
- package/dist/adapters/walnut/actionTypes.d.ts +16 -0
- package/dist/adapters/walnut/actionTypes.d.ts.map +1 -0
- package/dist/adapters/walnut/actionTypes.js +178 -0
- package/dist/adapters/walnut/actionTypes.js.map +1 -0
- package/dist/adapters/walnut/adapter.d.ts +235 -0
- package/dist/adapters/walnut/adapter.d.ts.map +1 -0
- package/dist/adapters/walnut/adapter.js +1120 -0
- package/dist/adapters/walnut/adapter.js.map +1 -0
- package/dist/adapters/walnut/mapper.d.ts +55 -0
- package/dist/adapters/walnut/mapper.d.ts.map +1 -0
- package/dist/adapters/walnut/mapper.js +364 -0
- package/dist/adapters/walnut/mapper.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +38 -0
- package/dist/cli.js.map +1 -0
- package/dist/config.d.ts +109 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +272 -0
- package/dist/config.js.map +1 -0
- package/dist/connection.d.ts +105 -0
- package/dist/connection.d.ts.map +1 -0
- package/dist/connection.js +255 -0
- package/dist/connection.js.map +1 -0
- package/dist/domain/heal.d.ts +163 -0
- package/dist/domain/heal.d.ts.map +1 -0
- package/dist/domain/heal.js +55 -0
- package/dist/domain/heal.js.map +1 -0
- package/dist/domain/types.d.ts +1328 -0
- package/dist/domain/types.d.ts.map +1 -0
- package/dist/domain/types.js +8 -0
- package/dist/domain/types.js.map +1 -0
- package/dist/domain/validate.d.ts +3 -0
- package/dist/domain/validate.d.ts.map +1 -0
- package/dist/domain/validate.js +67 -0
- package/dist/domain/validate.js.map +1 -0
- package/dist/drafts/apiPatch.d.ts +9 -0
- package/dist/drafts/apiPatch.d.ts.map +1 -0
- package/dist/drafts/apiPatch.js +27 -0
- package/dist/drafts/apiPatch.js.map +1 -0
- package/dist/drafts/bulk.d.ts +24 -0
- package/dist/drafts/bulk.d.ts.map +1 -0
- package/dist/drafts/bulk.js +44 -0
- package/dist/drafts/bulk.js.map +1 -0
- package/dist/drafts/duplicate.d.ts +12 -0
- package/dist/drafts/duplicate.d.ts.map +1 -0
- package/dist/drafts/duplicate.js +59 -0
- package/dist/drafts/duplicate.js.map +1 -0
- package/dist/drafts/store.d.ts +91 -0
- package/dist/drafts/store.d.ts.map +1 -0
- package/dist/drafts/store.js +244 -0
- package/dist/drafts/store.js.map +1 -0
- package/dist/gateway.d.ts +37 -0
- package/dist/gateway.d.ts.map +1 -0
- package/dist/gateway.js +71 -0
- package/dist/gateway.js.map +1 -0
- package/dist/httpMain.d.ts +3 -0
- package/dist/httpMain.d.ts.map +1 -0
- package/dist/httpMain.js +20 -0
- package/dist/httpMain.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +46 -0
- package/dist/index.js.map +1 -0
- package/dist/initAgents.d.ts +2 -0
- package/dist/initAgents.d.ts.map +1 -0
- package/dist/initAgents.js +508 -0
- package/dist/initAgents.js.map +1 -0
- package/dist/log.d.ts +17 -0
- package/dist/log.d.ts.map +1 -0
- package/dist/log.js +49 -0
- package/dist/log.js.map +1 -0
- package/dist/mcpResult.d.ts +39 -0
- package/dist/mcpResult.d.ts.map +1 -0
- package/dist/mcpResult.js +19 -0
- package/dist/mcpResult.js.map +1 -0
- package/dist/mount.d.ts +33 -0
- package/dist/mount.d.ts.map +1 -0
- package/dist/mount.js +213 -0
- package/dist/mount.js.map +1 -0
- package/dist/paramTokens.d.ts +18 -0
- package/dist/paramTokens.d.ts.map +1 -0
- package/dist/paramTokens.js +50 -0
- package/dist/paramTokens.js.map +1 -0
- package/dist/projectStore.d.ts +5 -0
- package/dist/projectStore.d.ts.map +1 -0
- package/dist/projectStore.js +60 -0
- package/dist/projectStore.js.map +1 -0
- package/dist/requestConnection.d.ts +22 -0
- package/dist/requestConnection.d.ts.map +1 -0
- package/dist/requestConnection.js +50 -0
- package/dist/requestConnection.js.map +1 -0
- package/dist/serve.d.ts +10 -0
- package/dist/serve.d.ts.map +1 -0
- package/dist/serve.js +37 -0
- package/dist/serve.js.map +1 -0
- package/dist/server.d.ts +41 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +370 -0
- package/dist/server.js.map +1 -0
- package/dist/tools/actionCatalog.d.ts +24 -0
- package/dist/tools/actionCatalog.d.ts.map +1 -0
- package/dist/tools/actionCatalog.js +56 -0
- package/dist/tools/actionCatalog.js.map +1 -0
- package/dist/tools/attachment.tools.d.ts +15 -0
- package/dist/tools/attachment.tools.d.ts.map +1 -0
- package/dist/tools/attachment.tools.js +104 -0
- package/dist/tools/attachment.tools.js.map +1 -0
- package/dist/tools/backlog.tools.d.ts +13 -0
- package/dist/tools/backlog.tools.d.ts.map +1 -0
- package/dist/tools/backlog.tools.js +690 -0
- package/dist/tools/backlog.tools.js.map +1 -0
- package/dist/tools/connection.tools.d.ts +16 -0
- package/dist/tools/connection.tools.d.ts.map +1 -0
- package/dist/tools/connection.tools.js +120 -0
- package/dist/tools/connection.tools.js.map +1 -0
- package/dist/tools/defects.tools.d.ts +7 -0
- package/dist/tools/defects.tools.d.ts.map +1 -0
- package/dist/tools/defects.tools.js +108 -0
- package/dist/tools/defects.tools.js.map +1 -0
- package/dist/tools/discovery.tools.d.ts +23 -0
- package/dist/tools/discovery.tools.d.ts.map +1 -0
- package/dist/tools/discovery.tools.js +1746 -0
- package/dist/tools/discovery.tools.js.map +1 -0
- package/dist/tools/executionPlan.tools.d.ts +14 -0
- package/dist/tools/executionPlan.tools.d.ts.map +1 -0
- package/dist/tools/executionPlan.tools.js +184 -0
- package/dist/tools/executionPlan.tools.js.map +1 -0
- package/dist/tools/failure.tools.d.ts +14 -0
- package/dist/tools/failure.tools.d.ts.map +1 -0
- package/dist/tools/failure.tools.js +65 -0
- package/dist/tools/failure.tools.js.map +1 -0
- package/dist/tools/formulas.tools.d.ts +7 -0
- package/dist/tools/formulas.tools.d.ts.map +1 -0
- package/dist/tools/formulas.tools.js +84 -0
- package/dist/tools/formulas.tools.js.map +1 -0
- package/dist/tools/functionReuse.d.ts +77 -0
- package/dist/tools/functionReuse.d.ts.map +1 -0
- package/dist/tools/functionReuse.js +384 -0
- package/dist/tools/functionReuse.js.map +1 -0
- package/dist/tools/gapAnalysis.tools.d.ts +31 -0
- package/dist/tools/gapAnalysis.tools.d.ts.map +1 -0
- package/dist/tools/gapAnalysis.tools.js +287 -0
- package/dist/tools/gapAnalysis.tools.js.map +1 -0
- package/dist/tools/heal.tools.d.ts +20 -0
- package/dist/tools/heal.tools.d.ts.map +1 -0
- package/dist/tools/heal.tools.js +268 -0
- package/dist/tools/heal.tools.js.map +1 -0
- package/dist/tools/impactAnalysis.tools.d.ts +17 -0
- package/dist/tools/impactAnalysis.tools.d.ts.map +1 -0
- package/dist/tools/impactAnalysis.tools.js +352 -0
- package/dist/tools/impactAnalysis.tools.js.map +1 -0
- package/dist/tools/markdown.d.ts +13 -0
- package/dist/tools/markdown.d.ts.map +1 -0
- package/dist/tools/markdown.js +145 -0
- package/dist/tools/markdown.js.map +1 -0
- package/dist/tools/objects.tools.d.ts +7 -0
- package/dist/tools/objects.tools.d.ts.map +1 -0
- package/dist/tools/objects.tools.js +458 -0
- package/dist/tools/objects.tools.js.map +1 -0
- package/dist/tools/pipeline.tools.d.ts +11 -0
- package/dist/tools/pipeline.tools.d.ts.map +1 -0
- package/dist/tools/pipeline.tools.js +100 -0
- package/dist/tools/pipeline.tools.js.map +1 -0
- package/dist/tools/preference.tools.d.ts +15 -0
- package/dist/tools/preference.tools.d.ts.map +1 -0
- package/dist/tools/preference.tools.js +114 -0
- package/dist/tools/preference.tools.js.map +1 -0
- package/dist/tools/privileges.tools.d.ts +65 -0
- package/dist/tools/privileges.tools.d.ts.map +1 -0
- package/dist/tools/privileges.tools.js +186 -0
- package/dist/tools/privileges.tools.js.map +1 -0
- package/dist/tools/project.tools.d.ts +13 -0
- package/dist/tools/project.tools.d.ts.map +1 -0
- package/dist/tools/project.tools.js +199 -0
- package/dist/tools/project.tools.js.map +1 -0
- package/dist/tools/query.tools.d.ts +23 -0
- package/dist/tools/query.tools.d.ts.map +1 -0
- package/dist/tools/query.tools.js +368 -0
- package/dist/tools/query.tools.js.map +1 -0
- package/dist/tools/recording.tools.d.ts +58 -0
- package/dist/tools/recording.tools.d.ts.map +1 -0
- package/dist/tools/recording.tools.js +1050 -0
- package/dist/tools/recording.tools.js.map +1 -0
- package/dist/tools/recordingNames.d.ts +3 -0
- package/dist/tools/recordingNames.d.ts.map +1 -0
- package/dist/tools/recordingNames.js +16 -0
- package/dist/tools/recordingNames.js.map +1 -0
- package/dist/tools/report.tools.d.ts +12 -0
- package/dist/tools/report.tools.d.ts.map +1 -0
- package/dist/tools/report.tools.js +104 -0
- package/dist/tools/report.tools.js.map +1 -0
- package/dist/tools/run.tools.d.ts +25 -0
- package/dist/tools/run.tools.d.ts.map +1 -0
- package/dist/tools/run.tools.js +1295 -0
- package/dist/tools/run.tools.js.map +1 -0
- package/dist/tools/schemas.d.ts +860 -0
- package/dist/tools/schemas.d.ts.map +1 -0
- package/dist/tools/schemas.js +220 -0
- package/dist/tools/schemas.js.map +1 -0
- package/dist/tools/storySync.tools.d.ts +167 -0
- package/dist/tools/storySync.tools.d.ts.map +1 -0
- package/dist/tools/storySync.tools.js +678 -0
- package/dist/tools/storySync.tools.js.map +1 -0
- package/dist/tools/suiteManage.tools.d.ts +14 -0
- package/dist/tools/suiteManage.tools.d.ts.map +1 -0
- package/dist/tools/suiteManage.tools.js +112 -0
- package/dist/tools/suiteManage.tools.js.map +1 -0
- package/dist/tools/tasks.tools.d.ts +7 -0
- package/dist/tools/tasks.tools.d.ts.map +1 -0
- package/dist/tools/tasks.tools.js +101 -0
- package/dist/tools/tasks.tools.js.map +1 -0
- package/dist/tools/tcEditPublisher.d.ts +29 -0
- package/dist/tools/tcEditPublisher.d.ts.map +1 -0
- package/dist/tools/tcEditPublisher.js +61 -0
- package/dist/tools/tcEditPublisher.js.map +1 -0
- package/dist/tools/testCaseLint.d.ts +5 -0
- package/dist/tools/testCaseLint.d.ts.map +1 -0
- package/dist/tools/testCaseLint.js +112 -0
- package/dist/tools/testCaseLint.js.map +1 -0
- package/dist/tools/testPlan.tools.d.ts +12 -0
- package/dist/tools/testPlan.tools.d.ts.map +1 -0
- package/dist/tools/testPlan.tools.js +104 -0
- package/dist/tools/testPlan.tools.js.map +1 -0
- package/dist/tools/testcase.tools.d.ts +86 -0
- package/dist/tools/testcase.tools.d.ts.map +1 -0
- package/dist/tools/testcase.tools.js +1591 -0
- package/dist/tools/testcase.tools.js.map +1 -0
- package/dist/tools/testdata.tools.d.ts +7 -0
- package/dist/tools/testdata.tools.d.ts.map +1 -0
- package/dist/tools/testdata.tools.js +636 -0
- package/dist/tools/testdata.tools.js.map +1 -0
- package/dist/tools/xlsx.d.ts +8 -0
- package/dist/tools/xlsx.d.ts.map +1 -0
- package/dist/tools/xlsx.js +113 -0
- package/dist/tools/xlsx.js.map +1 -0
- package/dist/vendor/actionSignatures.d.ts +117 -0
- package/dist/vendor/actionSignatures.d.ts.map +1 -0
- package/dist/vendor/actionSignatures.js +420 -0
- package/dist/vendor/actionSignatures.js.map +1 -0
- package/dist/vendor/logger.d.ts +43 -0
- package/dist/vendor/logger.d.ts.map +1 -0
- package/dist/vendor/logger.js +184 -0
- package/dist/vendor/logger.js.map +1 -0
- package/dist/version.d.ts +10 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +10 -0
- package/dist/version.js.map +1 -0
- package/dist/versionName.d.ts +21 -0
- package/dist/versionName.d.ts.map +1 -0
- package/dist/versionName.js +48 -0
- package/dist/versionName.js.map +1 -0
- package/package.json +62 -4
|
@@ -0,0 +1,1746 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { nextVersionName } from '../versionName.js';
|
|
3
|
+
import { ok, err } from '../mcpResult.js';
|
|
4
|
+
import { zJournalOp, zRawFilter } from './schemas.js';
|
|
5
|
+
import { stepsMarkdown } from './markdown.js';
|
|
6
|
+
import { mkdir, writeFile } from 'node:fs/promises';
|
|
7
|
+
import { join } from 'node:path';
|
|
8
|
+
import { buildXlsx } from './xlsx.js';
|
|
9
|
+
const NOT_CONNECTED = 'Not connected to a product. Use qa_connect({ url, token, projectId }) first — listing and ' +
|
|
10
|
+
'reading existing test cases needs a live backend connection (the offline path only authors drafts).';
|
|
11
|
+
function describeError(e) {
|
|
12
|
+
return e instanceof Error ? e.message : String(e);
|
|
13
|
+
}
|
|
14
|
+
/** Markdown table cells: escape pipes and flatten newlines (mirrors markdown.ts). */
|
|
15
|
+
function escCell(v) {
|
|
16
|
+
return String(v ?? '').replace(/\|/g, '\\|').replace(/\r?\n/g, ' ');
|
|
17
|
+
}
|
|
18
|
+
/** SQA adapter attaches `totalCount` as a side-band prop on the returned array (via
|
|
19
|
+
* mapper.withTotal). The provider interface declares plain `T[]`, so read it via a widening cast. */
|
|
20
|
+
function totalOf(rows) {
|
|
21
|
+
const t = rows.totalCount;
|
|
22
|
+
return typeof t === 'number' ? t : undefined;
|
|
23
|
+
}
|
|
24
|
+
/** Render a `ModuleSaved` (single node or subtree) as human-readable text so the model sees the
|
|
25
|
+
* full tree shape it just created — id, code, isRoot flag, parent, and nested children indented.
|
|
26
|
+
* `failedAt` (if set on root) is surfaced at the bottom so a partial-success is never hidden. */
|
|
27
|
+
function formatModuleSaved(saved, indent = 0) {
|
|
28
|
+
const pad = ' '.repeat(indent);
|
|
29
|
+
const code = saved.code ? ` [${saved.code}]` : '';
|
|
30
|
+
const parent = saved.parentId ? `, parent=${saved.parentId}` : '';
|
|
31
|
+
const root = saved.isRoot ? ', isRoot=true' : '';
|
|
32
|
+
const head = `${pad}- ${saved.name}${code} (id ${saved.id}${root}${parent})`;
|
|
33
|
+
const linkWarningLine = saved.linkWarning ? `${pad} ⚠ ${saved.linkWarning}` : undefined;
|
|
34
|
+
const childLines = (saved.children ?? []).map((c) => formatModuleSaved(c, indent + 1));
|
|
35
|
+
const parts = [head, ...(linkWarningLine ? [linkWarningLine] : []), ...childLines];
|
|
36
|
+
if (indent === 0 && saved.failedAt) {
|
|
37
|
+
parts.push(`\n⚠ Subtree create stopped at "${saved.failedAt.path}": ${saved.failedAt.error}`);
|
|
38
|
+
parts.push(' Nodes listed above ARE persisted. Fix the error, then create the remaining nodes.');
|
|
39
|
+
}
|
|
40
|
+
if (indent === 0) {
|
|
41
|
+
const created = countCreated(saved);
|
|
42
|
+
parts.unshift(`Created ${created} module${created === 1 ? '' : 's'}:`);
|
|
43
|
+
}
|
|
44
|
+
return parts.join('\n');
|
|
45
|
+
}
|
|
46
|
+
function countCreated(saved) {
|
|
47
|
+
return 1 + (saved.children ?? []).reduce((n, c) => n + countCreated(c), 0);
|
|
48
|
+
}
|
|
49
|
+
/** Header line for a list tool: "Showing 100 of 350 test cases" when the backend returned a
|
|
50
|
+
* totalCount larger than the page, else "N test cases". Pluralises via `plural` (defaults to `s`
|
|
51
|
+
* suffix — pass explicit forms for "stor y/ies", etc). */
|
|
52
|
+
function countHeader(rows, singular, plural = singular + 's') {
|
|
53
|
+
const shown = rows.length;
|
|
54
|
+
const total = totalOf(rows) ?? shown;
|
|
55
|
+
const word = total === 1 ? singular : plural;
|
|
56
|
+
return total > shown ? `Showing ${shown} of ${total} ${word}` : `${total} ${word}`;
|
|
57
|
+
}
|
|
58
|
+
/** One-line human summary of a single version's dependency row from `delete_version`'s dry-run.
|
|
59
|
+
* Shape branches on `parentType`: TC has 7 ref maps (defects, suites, execplans, scenarios,
|
|
60
|
+
* schedulers, pipelines, workflows), FN has 3 (tcs, fns, workflows). Each map is {projectId → ids}. */
|
|
61
|
+
function renderVersionDepRow(dep) {
|
|
62
|
+
const totalIn = (m) => Object.values(m).reduce((n, arr) => n + arr.length, 0);
|
|
63
|
+
const parts = [];
|
|
64
|
+
if ('defectArr' in dep) {
|
|
65
|
+
const d = dep;
|
|
66
|
+
const bits = [
|
|
67
|
+
['defect', totalIn(d.defectArr)], ['suite', totalIn(d.suiteArr)],
|
|
68
|
+
['exec-plan', totalIn(d.epArr)], ['scenario', totalIn(d.scenarioArr)],
|
|
69
|
+
['schedule', totalIn(d.schedulerArr)], ['pipeline', totalIn(d.pipelineArr)],
|
|
70
|
+
['workflow', totalIn(d.workflowArr)],
|
|
71
|
+
];
|
|
72
|
+
for (const [label, n] of bits)
|
|
73
|
+
if (n)
|
|
74
|
+
parts.push(`${n} ${label}${n === 1 ? '' : 's'}`);
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
const d = dep;
|
|
78
|
+
const bits = [
|
|
79
|
+
['test case', totalIn(d.tcArr)], ['function', totalIn(d.fnArr)], ['workflow', totalIn(d.wfArr)],
|
|
80
|
+
];
|
|
81
|
+
for (const [label, n] of bits)
|
|
82
|
+
if (n)
|
|
83
|
+
parts.push(`${n} ${label}${n === 1 ? '' : 's'}`);
|
|
84
|
+
}
|
|
85
|
+
return parts.length ? `- ${parts.join(', ')}` : '- (no references)';
|
|
86
|
+
}
|
|
87
|
+
/** Pick the source version for save-as-new-TC/FN and save-as-new-version. A multi-version source is
|
|
88
|
+
* NEVER silently defaulted: with no selection it lists the versions by name and asks; a name/number the
|
|
89
|
+
* user gave ("v2", "2", "v2.0", or an id) is resolved here, and an unresolvable one lists the options.
|
|
90
|
+
* Single-version sources proceed and the caller states which version was used. */
|
|
91
|
+
async function pickSourceVersion(adapter, kind, id, requested) {
|
|
92
|
+
let versions = [];
|
|
93
|
+
try {
|
|
94
|
+
const src = kind === 'TC' ? await adapter.getTestCase(id) : await adapter.getFunction(id);
|
|
95
|
+
versions = (src.versions ?? []).map((v) => ({ id: v.id, name: v.name, isCurrent: v.isCurrent }));
|
|
96
|
+
}
|
|
97
|
+
catch {
|
|
98
|
+
// Version list unavailable — fall back to the adapter's own default rather than block.
|
|
99
|
+
return requested ? { version: { id: requested, name: requested } } : {};
|
|
100
|
+
}
|
|
101
|
+
const listing = versions.map((v) => `- **${v.name}**${v.isCurrent ? ' (currently open)' : ''}`).join('\n');
|
|
102
|
+
if (requested) {
|
|
103
|
+
const r = requested.trim().toLowerCase();
|
|
104
|
+
const num = r.replace(/^v/, '').replace(/\.0+$/, '');
|
|
105
|
+
const hit = versions.find((v) => v.id === requested)
|
|
106
|
+
?? versions.find((v) => v.name.trim().toLowerCase() === r)
|
|
107
|
+
?? versions.find((v) => v.name.trim().toLowerCase().replace(/^v/, '').replace(/\.0+$/, '') === num);
|
|
108
|
+
if (hit)
|
|
109
|
+
return { version: { id: hit.id, name: hit.name } };
|
|
110
|
+
return { message: `Version "${requested}" of ${id} was not found. Available versions:
|
|
111
|
+
${listing}
|
|
112
|
+
|
|
113
|
+
**Ask the user** which one to use, then call again with \`sourceVersionName\`.` };
|
|
114
|
+
}
|
|
115
|
+
if (versions.length > 1) {
|
|
116
|
+
return { message: `${id} has ${versions.length} versions:
|
|
117
|
+
${listing}
|
|
118
|
+
|
|
119
|
+
**Ask the user** which version to use (do NOT default to the latest or v1), then call again with \`sourceVersionName\`. Nothing was created.` };
|
|
120
|
+
}
|
|
121
|
+
return versions[0] ? { version: { id: versions[0].id, name: versions[0].name } } : {};
|
|
122
|
+
}
|
|
123
|
+
/** Inline-display ceiling for tc_list: above this many matches the tool asks how to proceed instead of
|
|
124
|
+
* rendering everything into the chat. */
|
|
125
|
+
const TC_INLINE_LIMIT = 100;
|
|
126
|
+
const TC_EXPORT_PAGE = 100;
|
|
127
|
+
/** Hard stop on an export so a runaway project can't turn one call into unbounded requests. */
|
|
128
|
+
const TC_EXPORT_CAP = 20000;
|
|
129
|
+
/** Human-readable list of the filters a tc_list call applied — echoed in every response. */
|
|
130
|
+
function describeTcFilters(a) {
|
|
131
|
+
const parts = [];
|
|
132
|
+
const add = (label, v) => { if (v !== undefined && v !== '')
|
|
133
|
+
parts.push(`${label}: ${String(v)}`); };
|
|
134
|
+
add('search', a['search']);
|
|
135
|
+
add('status', a['status']);
|
|
136
|
+
add('createdBy', a['createdBy']);
|
|
137
|
+
add('updatedBy', a['updatedBy']);
|
|
138
|
+
add('story', a['storyId']);
|
|
139
|
+
add('module', a['moduleId']);
|
|
140
|
+
if (typeof a['obsolete'] === 'boolean')
|
|
141
|
+
parts.push(`obsolete: ${a['obsolete']}`);
|
|
142
|
+
const f = a['filters'];
|
|
143
|
+
if (Array.isArray(f))
|
|
144
|
+
for (const x of f)
|
|
145
|
+
parts.push(`${x.column}: ${String(x.value)}`);
|
|
146
|
+
return parts.length ? parts.join(' · ') : 'none (all test cases in the active project)';
|
|
147
|
+
}
|
|
148
|
+
export function registerDiscoveryTools(server, deps) {
|
|
149
|
+
server.registerTool('list_projects', {
|
|
150
|
+
title: 'List projects (resolve a project name to its id)',
|
|
151
|
+
description: 'List the projects visible to the current connection — id, name and counts. Use this to ' +
|
|
152
|
+
'resolve a project NAME to its id (e.g. before qa_switch_project when the user names a ' +
|
|
153
|
+
'project). Requires a live connection.',
|
|
154
|
+
inputSchema: {},
|
|
155
|
+
annotations: { readOnlyHint: true },
|
|
156
|
+
}, async () => {
|
|
157
|
+
const adapter = deps.getAdapter();
|
|
158
|
+
if (!adapter)
|
|
159
|
+
return err(NOT_CONNECTED);
|
|
160
|
+
try {
|
|
161
|
+
const rows = await adapter.listProjects();
|
|
162
|
+
if (!rows.length)
|
|
163
|
+
return ok('No projects found.', { projects: [], totalCount: totalOf(rows) ?? 0 });
|
|
164
|
+
const view = rows.map(({ id: _id, ...rest }) => rest);
|
|
165
|
+
const text = `${countHeader(rows, 'project')}:\n\n` +
|
|
166
|
+
'| key | name | test cases |\n|---|---|---|\n' +
|
|
167
|
+
rows.map((p) => `| ${escCell(p.code)} | ${escCell(p.name)} | ${p.counts?.['testCases'] ?? '-'} |`).join('\n');
|
|
168
|
+
return ok(text, { projects: view, totalCount: totalOf(rows) ?? rows.length });
|
|
169
|
+
}
|
|
170
|
+
catch (e) {
|
|
171
|
+
return err(describeError(e));
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
server.registerTool('tc_list', {
|
|
175
|
+
title: 'List / search existing test cases (NOT reusable functions)',
|
|
176
|
+
description: 'List or search EXISTING TEST CASES (TC_* ids) in the connected product. NOT for reusable ' +
|
|
177
|
+
'functions: if the user asks for functions, FN_*, the function library, or reusable steps, ' +
|
|
178
|
+
'use `list_functions` instead. Trigger words for THIS tool: "test case", "TC", "TC_", ' +
|
|
179
|
+
'"scenario", "script". Requires a live connection (qa_connect). Returns a summary list — id, ' +
|
|
180
|
+
'title, technology, execution type, step count. Use `tc_get` to read one in full. ' +
|
|
181
|
+
'Read-only, product-neutral. When presenting this as a table, label the columns "ID" and ' +
|
|
182
|
+
'"Name" — the underlying fields are literally named `code`/`title`, but that\'s internal ' +
|
|
183
|
+
'wire terminology, not what to show the user.',
|
|
184
|
+
inputSchema: {
|
|
185
|
+
search: z.string().optional().describe('Free-text search over title / id.'),
|
|
186
|
+
status: z.string().optional().describe('Filter by status. Walnut only — SimplifyQA test cases have no status field (use `reviewApproveStatus` or a custom field via sqa_query).'),
|
|
187
|
+
limit: z.number().int().positive().optional().describe('Max results (paging).'),
|
|
188
|
+
offset: z.number().int().nonnegative().optional().describe('Result offset (paging).'),
|
|
189
|
+
createdBy: z.string().optional().describe('Numeric userId of the creator. Pass "me" to filter by the current caller (needs QA_MCP_USER_ID for API-key auth). Resolve names to ids via list_users first.'),
|
|
190
|
+
updatedBy: z.string().optional().describe('Numeric userId of the last updater. Pass "me" for the current caller. Resolve names via list_users first.'),
|
|
191
|
+
storyId: z.string().optional().describe('Only test cases tagged to this user story (id or business key, e.g. US_123).'),
|
|
192
|
+
moduleId: z.string().optional().describe('Only test cases filed under this module (id or business key, e.g. MO_12). SimplifyQA only — ignored elsewhere.'),
|
|
193
|
+
obsolete: z.boolean().optional().describe('True → only obsolete TCs; false → only non-obsolete. Omit to include both. The response summary always reports how many of the returned rows are obsolete.'),
|
|
194
|
+
filters: z.array(zRawFilter).optional().describe('Extra raw column filters for project-configured columns with no dedicated parameter above (e.g. custom fields) — use the field\'s backend key as `column`. SimplifyQA test cases have no priority/status/stepCount columns.'),
|
|
195
|
+
output: z.enum(['xlsx', 'first100']).optional().describe("How to return a LARGE result. Omit it: when more than 100 test cases match, the tool returns ONLY the total count + the options and you must ASK the user. 'xlsx' = write ALL matches to an .xlsx file (use directly when the user asked for Excel / a download — no need to ask). 'first100' = show exactly the first 100 inline. At 100 or fewer matches results are shown inline either way. Ignored when `limit`/`offset` is passed (an explicit page)."),
|
|
196
|
+
outDir: z.string().optional().describe('Folder for the .xlsx export. Default: ./qa-reports'),
|
|
197
|
+
},
|
|
198
|
+
annotations: { readOnlyHint: false },
|
|
199
|
+
}, async ({ search, status, limit, offset, createdBy, updatedBy, storyId, moduleId, obsolete, filters, output, outDir }) => {
|
|
200
|
+
const adapter = deps.getAdapter();
|
|
201
|
+
if (!adapter)
|
|
202
|
+
return err(NOT_CONNECTED);
|
|
203
|
+
try {
|
|
204
|
+
const q = {
|
|
205
|
+
...(search !== undefined ? { search } : {}),
|
|
206
|
+
...(status !== undefined ? { status } : {}),
|
|
207
|
+
...(limit !== undefined ? { limit } : {}),
|
|
208
|
+
...(offset !== undefined ? { offset } : {}),
|
|
209
|
+
...(createdBy !== undefined ? { createdBy } : {}),
|
|
210
|
+
...(updatedBy !== undefined ? { updatedBy } : {}),
|
|
211
|
+
...(storyId !== undefined ? { storyId } : {}),
|
|
212
|
+
...(moduleId !== undefined ? { moduleId } : {}),
|
|
213
|
+
...(obsolete !== undefined ? { obsolete } : {}),
|
|
214
|
+
...(filters?.length ? { filters } : {}),
|
|
215
|
+
};
|
|
216
|
+
const appliedFilters = describeTcFilters({ search, status, createdBy, updatedBy, storyId, moduleId, obsolete, filters });
|
|
217
|
+
const paged = limit !== undefined || offset !== undefined;
|
|
218
|
+
// ---- Excel export: ALL matches, regardless of count, no questions asked.
|
|
219
|
+
if (output === 'xlsx' && !paged) {
|
|
220
|
+
const all = [];
|
|
221
|
+
for (let off = 0;; off += TC_EXPORT_PAGE) {
|
|
222
|
+
const page = await adapter.listTestCases({ ...q, limit: TC_EXPORT_PAGE, offset: off });
|
|
223
|
+
all.push(...page);
|
|
224
|
+
const total = totalOf(page);
|
|
225
|
+
if (page.length < TC_EXPORT_PAGE || (total !== undefined && all.length >= total))
|
|
226
|
+
break;
|
|
227
|
+
if (all.length >= TC_EXPORT_CAP) {
|
|
228
|
+
return err(`Export stopped: more than ${TC_EXPORT_CAP} test cases match. Nothing was written — narrow the query (module, status, story, search) and try again.`);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
if (!all.length)
|
|
232
|
+
return ok(`No test cases match (filters: ${appliedFilters}) — no file was written.`, { testCases: [], totalCount: 0 });
|
|
233
|
+
// Priority/status are absent on SimplifyQA test cases; only include the columns the
|
|
234
|
+
// connected product actually returned.
|
|
235
|
+
const hasStatus = all.some((r) => r.status !== undefined);
|
|
236
|
+
const hasPriority = all.some((r) => r.priority !== undefined);
|
|
237
|
+
const hasSteps = all.some((r) => r.stepCount !== undefined);
|
|
238
|
+
const headers = [
|
|
239
|
+
'ID', 'Name', 'Technology', 'Execution type',
|
|
240
|
+
...(hasStatus ? ['Status'] : []),
|
|
241
|
+
...(hasPriority ? ['Priority'] : []),
|
|
242
|
+
...(hasSteps ? ['Steps'] : []),
|
|
243
|
+
'Obsolete',
|
|
244
|
+
];
|
|
245
|
+
const data = all.map((r) => [
|
|
246
|
+
r.code ?? r.id, r.title, r.technologyType ?? '', r.executionType ?? '',
|
|
247
|
+
...(hasStatus ? [r.status ?? ''] : []),
|
|
248
|
+
...(hasPriority ? [r.priority ?? ''] : []),
|
|
249
|
+
...(hasSteps ? [r.stepCount ?? ''] : []),
|
|
250
|
+
r.obsolete === true ? 'yes' : '',
|
|
251
|
+
]);
|
|
252
|
+
const dir = outDir ?? join(process.cwd(), 'qa-reports');
|
|
253
|
+
await mkdir(dir, { recursive: true });
|
|
254
|
+
const stamp = new Date().toISOString().replace(/[:T]/g, '-').slice(0, 19);
|
|
255
|
+
const file = join(dir, `test-cases_${stamp}.xlsx`);
|
|
256
|
+
await writeFile(file, buildXlsx('Test cases', headers, data));
|
|
257
|
+
return ok(`Exported **${all.length}** test case${all.length === 1 ? '' : 's'} to \`${file}\`.\n` +
|
|
258
|
+
`Columns: ${headers.join(', ')}.\nFilters applied: ${appliedFilters}.\n` +
|
|
259
|
+
'The list carries no parameter values, so nothing protected is included.', { file, count: all.length, filters: appliedFilters });
|
|
260
|
+
}
|
|
261
|
+
let rows = await adapter.listTestCases(q);
|
|
262
|
+
if (!rows.length)
|
|
263
|
+
return ok(`No test cases found (filters: ${appliedFilters}).`, { testCases: [], totalCount: totalOf(rows) ?? 0 });
|
|
264
|
+
// ---- Large result: state the count and ASK, instead of dumping everything inline.
|
|
265
|
+
let shownNote = '';
|
|
266
|
+
if (!paged) {
|
|
267
|
+
let total = totalOf(rows);
|
|
268
|
+
if (total === undefined && rows.length >= TC_INLINE_LIMIT) {
|
|
269
|
+
// Backend gave no total: probe one row past the page to know whether more exist.
|
|
270
|
+
const probe = await adapter.listTestCases({ ...q, limit: 1, offset: TC_INLINE_LIMIT });
|
|
271
|
+
total = probe.length ? (totalOf(probe) ?? TC_INLINE_LIMIT + 1) : rows.length;
|
|
272
|
+
}
|
|
273
|
+
const count = total ?? rows.length;
|
|
274
|
+
if (count > TC_INLINE_LIMIT) {
|
|
275
|
+
if (output === 'first100') {
|
|
276
|
+
rows = Object.assign(rows.slice(0, TC_INLINE_LIMIT), { totalCount: count });
|
|
277
|
+
shownNote = `\n\nShowing the first ${TC_INLINE_LIMIT} of ${count} — ${count - TC_INLINE_LIMIT} not displayed.`;
|
|
278
|
+
}
|
|
279
|
+
else {
|
|
280
|
+
return ok(`**${count} test cases** match (filters: ${appliedFilters}) — too many to show in the chat.\n\n` +
|
|
281
|
+
'**Ask the user how to proceed**, then call `tc_list` again:\n' +
|
|
282
|
+
"- Download all as Excel → `output: 'xlsx'`\n" +
|
|
283
|
+
"- Show the first 100 here → `output: 'first100'`\n" +
|
|
284
|
+
'- Refine the query (module, status, story, search text…) and list again', { needs: 'output', totalCount: count, options: ['xlsx', 'first100', 'refine'], filters: appliedFilters });
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
const view = rows.map(({ id: _id, priority: _p, ...rest }) => rest);
|
|
289
|
+
const obsoleteCount = rows.filter((r) => r.obsolete === true).length;
|
|
290
|
+
const obsoleteNote = obsoleteCount ? ` · ${obsoleteCount} obsolete` : '';
|
|
291
|
+
// Status and steps are provider-specific; do not print empty columns for SimplifyQA.
|
|
292
|
+
const hasStatus = rows.some((r) => r.status !== undefined);
|
|
293
|
+
const hasSteps = rows.some((r) => r.stepCount !== undefined);
|
|
294
|
+
const header = `| ID | Name | technology | execution |${hasStatus ? ' status |' : ''}${hasSteps ? ' steps |' : ''} obsolete |`;
|
|
295
|
+
const separator = `|---|---|---|---|${hasStatus ? '---|' : ''}${hasSteps ? '---|' : ''}---|`;
|
|
296
|
+
const text = `${countHeader(rows, 'test case')}${obsoleteNote} (filters: ${appliedFilters}):\n\n` +
|
|
297
|
+
`${header}\n${separator}\n` +
|
|
298
|
+
rows
|
|
299
|
+
.map((r) => `| ${escCell(r.code)} | ${escCell(r.title)} | ${r.technologyType ?? '-'} | ${r.executionType ?? '-'} |${hasStatus ? ` ${r.status ?? '-'} |` : ''}${hasSteps ? ` ${r.stepCount ?? '-'} |` : ''} ${r.obsolete === true ? 'yes' : ''} |`)
|
|
300
|
+
.join('\n') + shownNote;
|
|
301
|
+
return ok(text, { testCases: view, totalCount: totalOf(rows) ?? rows.length, obsoleteOnPage: obsoleteCount });
|
|
302
|
+
}
|
|
303
|
+
catch (e) {
|
|
304
|
+
return err(describeError(e));
|
|
305
|
+
}
|
|
306
|
+
});
|
|
307
|
+
server.registerTool('tc_get', {
|
|
308
|
+
title: 'Read one test case (with steps)',
|
|
309
|
+
description: 'Read a single EXISTING test case in full — metadata plus its steps as a readable table — ' +
|
|
310
|
+
'from the connected product. Requires a live connection (qa_connect). `id` accepts the ' +
|
|
311
|
+
"product's id or business key. Product-neutral: same shape on any connected product.\n\n" +
|
|
312
|
+
'VERSIONS: SimplifyQA TCs can have multiple versions, each with its own steps. When the TC ' +
|
|
313
|
+
"has more than one version and `versionId` is omitted, this tool REFUSES and lists the " +
|
|
314
|
+
"available versions — ASK the user which one to read, then call again with `versionId`. " +
|
|
315
|
+
"Pass `versionId: ''` (empty string) to accept the TC's currently-selected version. Single- " +
|
|
316
|
+
'version TCs are read directly. Providers without versioning (Walnut) ignore `versionId`.',
|
|
317
|
+
inputSchema: {
|
|
318
|
+
id: z.string().describe('The test case id (or business key) to read.'),
|
|
319
|
+
versionId: z.string().optional().describe("Version to read (an id from the TC's `versions[]`). Omit to trigger the ASK-user " +
|
|
320
|
+
"prompt when the TC has multiple versions. Pass '' (empty string) to accept the TC's " +
|
|
321
|
+
'currently-selected version without prompting.'),
|
|
322
|
+
},
|
|
323
|
+
annotations: { readOnlyHint: true },
|
|
324
|
+
}, async ({ id, versionId }) => {
|
|
325
|
+
const adapter = deps.getAdapter();
|
|
326
|
+
if (!adapter)
|
|
327
|
+
return err(NOT_CONNECTED);
|
|
328
|
+
try {
|
|
329
|
+
// Cheap pre-flight: read the TC without steps so we can inspect versions before deciding
|
|
330
|
+
// whether to prompt. Adapter's getTestCase(id) with no versionId is the natural way, and
|
|
331
|
+
// for SQA the version list is on the TC doc itself so this is one HTTP round-trip that
|
|
332
|
+
// we're going to do anyway.
|
|
333
|
+
const preview = await adapter.getTestCase(id);
|
|
334
|
+
const versions = preview.versions ?? [];
|
|
335
|
+
if (versions.length > 1 && versionId === undefined) {
|
|
336
|
+
const listing = versions
|
|
337
|
+
.map((v) => ` • \`${v.id}\` — **${v.name}**${v.isCurrent ? ' (current)' : ''}${v.reviewApproveStatus ? ` · ${v.reviewApproveStatus}` : ''}`)
|
|
338
|
+
.join('\n');
|
|
339
|
+
return err(`Test case ${preview.id ?? id} has ${versions.length} versions — ASK the user which ` +
|
|
340
|
+
`one to read, then call \`tc_get\` again with { id, versionId }. ` +
|
|
341
|
+
`Pass \`versionId: ''\` to accept the current version.\n\n${listing}`);
|
|
342
|
+
}
|
|
343
|
+
// versionId === '' means "explicit current" — pass undefined to the adapter (its default).
|
|
344
|
+
// Otherwise pass through.
|
|
345
|
+
const chosen = versionId === undefined || versionId === '' ? undefined : versionId;
|
|
346
|
+
const tc = chosen ? await adapter.getTestCase(id, chosen) : preview;
|
|
347
|
+
const stepCount = tc.steps.length;
|
|
348
|
+
const versionLine = tc.versions?.length
|
|
349
|
+
? (() => {
|
|
350
|
+
const current = tc.versions.find((v) => v.isCurrent) ?? tc.versions[tc.versions.length - 1];
|
|
351
|
+
return ` · version: ${current.name}${tc.versions.length > 1 ? ` (${tc.versions.length} total)` : ''}`;
|
|
352
|
+
})()
|
|
353
|
+
: '';
|
|
354
|
+
const meta = [
|
|
355
|
+
tc.priority ? `priority: ${tc.priority}` : '',
|
|
356
|
+
tc.status ? `status: ${tc.status}` : '',
|
|
357
|
+
`category: ${tc.category}`,
|
|
358
|
+
`${stepCount} step${stepCount === 1 ? '' : 's'}`,
|
|
359
|
+
].filter(Boolean).join(' · ');
|
|
360
|
+
const header = `**${tc.title}**${tc.id ? ` · ${tc.id}` : ''}\n` +
|
|
361
|
+
`${meta}${versionLine}`;
|
|
362
|
+
return ok(`${header}\n\n${stepsMarkdown(tc)}`, { tc });
|
|
363
|
+
}
|
|
364
|
+
catch (e) {
|
|
365
|
+
return err(describeError(e));
|
|
366
|
+
}
|
|
367
|
+
});
|
|
368
|
+
server.registerTool('tc_delete', {
|
|
369
|
+
title: 'Delete a test case (two-step confirm)',
|
|
370
|
+
description: 'Soft-delete an existing test case in the connected product. TWO-STEP CONFIRM: call once ' +
|
|
371
|
+
'with just `tcId` to preview the target (title + step count) and get a warning; then call ' +
|
|
372
|
+
'again with `{ tcId, confirm: true }` to actually delete. Refuses to delete without ' +
|
|
373
|
+
"`confirm:true`. `tcId` accepts the product's id or business key. Requires a live " +
|
|
374
|
+
'connection (qa_connect). Product-neutral.',
|
|
375
|
+
inputSchema: {
|
|
376
|
+
tcId: z.string().describe('The test case id (or business key) to delete.'),
|
|
377
|
+
confirm: z.boolean().optional().describe('Set to true on the SECOND call to actually delete.'),
|
|
378
|
+
},
|
|
379
|
+
annotations: { readOnlyHint: false, destructiveHint: true },
|
|
380
|
+
}, async ({ tcId, confirm }) => {
|
|
381
|
+
const adapter = deps.getAdapter();
|
|
382
|
+
if (!adapter)
|
|
383
|
+
return err(NOT_CONNECTED);
|
|
384
|
+
if (!confirm) {
|
|
385
|
+
try {
|
|
386
|
+
// Delete preview: read the current version — no step-collapse hint anymore since
|
|
387
|
+
// the adapter's getTestCase signature dropped that arg in favor of a versionId param.
|
|
388
|
+
const tc = await adapter.getTestCase(tcId);
|
|
389
|
+
const steps = tc.steps.length;
|
|
390
|
+
return ok(`⚠️ About to delete test case **${tc.title}**` +
|
|
391
|
+
`${tc.id ? ` (${tc.id})` : ''} — ${steps} step${steps === 1 ? '' : 's'}. ` +
|
|
392
|
+
`To proceed, call again with { tcId: "${tcId}", confirm: true }.`, { preview: true, tc });
|
|
393
|
+
}
|
|
394
|
+
catch (e) {
|
|
395
|
+
return err(describeError(e));
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
try {
|
|
399
|
+
await adapter.deleteTestCase(tcId);
|
|
400
|
+
return ok(`Deleted ${tcId}.`);
|
|
401
|
+
}
|
|
402
|
+
catch (e) {
|
|
403
|
+
return err(describeError(e));
|
|
404
|
+
}
|
|
405
|
+
});
|
|
406
|
+
server.registerTool('tc_clone', {
|
|
407
|
+
title: 'Save a test case as a new test case (same project + module)',
|
|
408
|
+
description: 'FOR TEST CASES ONLY. NOT for reusable functions: if the user names an `FN_*` key or asks to ' +
|
|
409
|
+
'clone a function, use `fn_clone` instead. Trigger words for THIS tool: "test case", "TC", ' +
|
|
410
|
+
'"TC_", "scenario", "script".\n\n' +
|
|
411
|
+
'Save an existing test case as a NEW test case (new TC id) in the SAME project + module. ' +
|
|
412
|
+
'Mirrors the FE in-editor "Save as new TC" dialog (operation: SAVEASNEWTC). Clones ONE ' +
|
|
413
|
+
'source version — pass `sourceVersionId` to pick which; defaults to the TC\'s currently ' +
|
|
414
|
+
'selected version. `tcId` accepts the numeric id or business key (`TC_*`).\n\n' +
|
|
415
|
+
'`newName` is REQUIRED — backend rejects an empty name on SAVEASNEWTC.\n\n' +
|
|
416
|
+
'TESTDATA — TWO-STEP: call once WITHOUT `tdCopy` to get the "Copy Test Data" prompt and ' +
|
|
417
|
+
'confirm with the user; then call again with `tdCopy` set. Mirrors the FE\'s "COPY TEST ' +
|
|
418
|
+
'DATA" modal (Cancel = false, Confirm = true). The tool REFUSES to clone until `tdCopy` ' +
|
|
419
|
+
'is passed — the prompt step is not skippable.\n\n' +
|
|
420
|
+
'`tdCopy:true` clones the source version\'s testdata iterations across every environment. ' +
|
|
421
|
+
'`tdCopy:false` copies only the column STRUCTURE — one empty iteration (`ITR-1`) per ' +
|
|
422
|
+
'environment; cells fall back to each parameter\'s project-level `defaultValue` if any.\n\n' +
|
|
423
|
+
'Requires a live connection.',
|
|
424
|
+
inputSchema: {
|
|
425
|
+
tcId: z.string().describe('The source test case id or business key (e.g. TC_123).'),
|
|
426
|
+
newName: z.string().min(1).describe('Name for the new test case (required by backend).'),
|
|
427
|
+
tdCopy: z.boolean().optional().describe('REQUIRED to actually clone. Whether to clone the source version\'s testdata iterations. Omit on the first call to get the confirmation prompt; ask the user, then call again with the chosen value.'),
|
|
428
|
+
sourceVersionId: z.string().optional().describe('Which version of the source TC to clone; defaults to the TC\'s current version.'),
|
|
429
|
+
sourceVersionName: z.string().optional().describe('Version to use, by NAME/number as the user says it (e.g. "v2", "2"). Preferred over sourceVersionId — the user should never need an id. If the source has several versions and this is omitted, the tool lists them and asks.'),
|
|
430
|
+
},
|
|
431
|
+
annotations: { readOnlyHint: false },
|
|
432
|
+
}, async ({ tcId, newName, tdCopy, sourceVersionId, sourceVersionName }) => {
|
|
433
|
+
const adapter = deps.getAdapter();
|
|
434
|
+
if (!adapter)
|
|
435
|
+
return err(NOT_CONNECTED);
|
|
436
|
+
if (!adapter.cloneTestCase)
|
|
437
|
+
return err('This product does not support save-as-new-testcase.');
|
|
438
|
+
const picked = await pickSourceVersion(adapter, 'TC', tcId, sourceVersionName ?? sourceVersionId);
|
|
439
|
+
if (picked.message)
|
|
440
|
+
return ok(picked.message, { needs: 'sourceVersionName' });
|
|
441
|
+
if (picked.version)
|
|
442
|
+
sourceVersionId = picked.version.id;
|
|
443
|
+
const srcNote = picked.version ? ` Source version: **${picked.version.name}**.` : '';
|
|
444
|
+
// Prompt step: no `tdCopy` → hand back the "Copy Test Data" question.
|
|
445
|
+
if (tdCopy === undefined) {
|
|
446
|
+
return ok(`**COPY TEST DATA** — Do you want to copy test data to new test case **${newName}** (from ${tcId})?\n\n` +
|
|
447
|
+
`If you do not want to copy the test data, only the column structure will be carried over (one empty ITR-1 per environment).\n\n` +
|
|
448
|
+
`**Ask the user**, then call \`tc_clone\` again:\n` +
|
|
449
|
+
`- \`tdCopy: true\` → copy iterations across all environments (Confirm)\n` +
|
|
450
|
+
`- \`tdCopy: false\` → structure only, empty values (Cancel)`, { preview: true, needs: 'tdCopy' });
|
|
451
|
+
}
|
|
452
|
+
try {
|
|
453
|
+
const ref = await adapter.cloneTestCase(tcId, newName, {
|
|
454
|
+
tdCopy,
|
|
455
|
+
...(sourceVersionId !== undefined ? { sourceVersionId } : {}),
|
|
456
|
+
});
|
|
457
|
+
const tdNote = tdCopy
|
|
458
|
+
? ' Testdata iterations were copied across environments.'
|
|
459
|
+
: ' Testdata structure was carried over but values are empty (tdCopy:false).';
|
|
460
|
+
return ok(`Cloned ${tcId} → **${newName}**. New id: **${ref.id}**` +
|
|
461
|
+
srcNote +
|
|
462
|
+
(ref.productUrl ? ` · ${ref.productUrl}` : '') +
|
|
463
|
+
`.${tdNote}`, { savedRef: ref });
|
|
464
|
+
}
|
|
465
|
+
catch (e) {
|
|
466
|
+
return err(describeError(e));
|
|
467
|
+
}
|
|
468
|
+
});
|
|
469
|
+
server.registerTool('tc_save_as_new_version', {
|
|
470
|
+
title: 'Snapshot a test case as a new version',
|
|
471
|
+
description: 'FOR TEST CASES ONLY. NOT for reusable functions: if the user names an `FN_*` key or asks to ' +
|
|
472
|
+
'snapshot / create a new version of a function, use `fn_save_as_new_version` instead. ' +
|
|
473
|
+
'Trigger words for THIS tool: "test case", "TC", "TC_", "scenario", "script".\n\n' +
|
|
474
|
+
'Freeze the CURRENT server state of a test case under a NEW version name — same TC id, a ' +
|
|
475
|
+
'new version row with cloned steps. Mirrors the SimplifyQA UI "Save as new version" dialog ' +
|
|
476
|
+
'(operation: SAVENEWVERSION). `tcId` accepts the numeric id or business key (`TC_*`).\n\n' +
|
|
477
|
+
'`versionName` must be unique for this TC — the backend rejects duplicates.\n\n' +
|
|
478
|
+
'TESTDATA — TWO-STEP: call once WITHOUT `tdCopy` to get the "Copy Test Data" prompt and ' +
|
|
479
|
+
'confirm with the user; then call again with `tdCopy` set. Mirrors the FE\'s "COPY TEST ' +
|
|
480
|
+
'DATA" modal (Cancel = false, Confirm = true). The tool REFUSES to snapshot until `tdCopy` ' +
|
|
481
|
+
'is passed — the prompt step is not skippable.\n\n' +
|
|
482
|
+
'`tdCopy:true` clones the source version\'s testdata iterations across every environment. ' +
|
|
483
|
+
'`tdCopy:false` copies only the column STRUCTURE — one empty iteration (`ITR-1`) per ' +
|
|
484
|
+
'environment; cells fall back to each parameter\'s project-level `defaultValue` if any.\n\n' +
|
|
485
|
+
'`sourceVersionId` picks which version to snapshot; omit to snapshot the TC\'s currently ' +
|
|
486
|
+
'selected version. Requires a live connection.',
|
|
487
|
+
inputSchema: {
|
|
488
|
+
tcId: z.string().describe('The test case id or business key (e.g. TC_123).'),
|
|
489
|
+
versionName: z.string().min(1).optional().describe('Name for the new version. OMIT to auto-increment (v1.0 → v2.0 → v3.0 …) from the versions ' +
|
|
490
|
+
'already on the TC — the normal path for an update. If given it must be unique for this TC.'),
|
|
491
|
+
tdCopy: z.boolean().optional().describe('REQUIRED to actually snapshot. Clone testdata iterations from the source version. Omit on the first call to get the confirmation prompt; ask the user, then call again with the chosen value.'),
|
|
492
|
+
sourceVersionId: z.string().optional().describe('Version to snapshot; defaults to the TC\'s current version.'),
|
|
493
|
+
fromDraftId: z.string().optional().describe('Freeze THIS edited draft as the new version instead of the stored state — the "update + save ' +
|
|
494
|
+
'as new version" path. Load it first with tc_draft_from_tc({tcId}) (+ tc_draft_update), then ' +
|
|
495
|
+
'pass its draftId here. Without it the tool clones the CURRENT server state (pure snapshot).'),
|
|
496
|
+
sourceVersionName: z.string().optional().describe('Version to use, by NAME/number as the user says it (e.g. "v2", "2"). Preferred over sourceVersionId — the user should never need an id. If the source has several versions and this is omitted, the tool lists them and asks.'),
|
|
497
|
+
},
|
|
498
|
+
annotations: { readOnlyHint: false },
|
|
499
|
+
}, async ({ tcId, versionName, tdCopy, sourceVersionId, sourceVersionName, fromDraftId }) => {
|
|
500
|
+
const adapter = deps.getAdapter();
|
|
501
|
+
if (!adapter)
|
|
502
|
+
return err(NOT_CONNECTED);
|
|
503
|
+
if (!adapter.saveAsNewVersion)
|
|
504
|
+
return err('This product does not support save-as-new-version.');
|
|
505
|
+
// Resolve the edited draft FIRST: the version name auto-increment and the "copy test data"
|
|
506
|
+
// prompt are both phrased against the content that is about to be frozen.
|
|
507
|
+
let draftTc;
|
|
508
|
+
if (fromDraftId) {
|
|
509
|
+
const draft = deps.getDraft?.(fromDraftId);
|
|
510
|
+
if (!draft)
|
|
511
|
+
return err(`Draft "${fromDraftId}" not found — load it with tc_draft_from_tc({ tcId }) first.`);
|
|
512
|
+
draftTc = draft.tc;
|
|
513
|
+
// The draft must be THIS test case, else the "new version" would carry another TC's steps.
|
|
514
|
+
if (draftTc.id && draftTc.id !== tcId) {
|
|
515
|
+
return err(`Draft "${fromDraftId}" is for ${draftTc.id}, not ${tcId}. Re-open it with tc_draft_from_tc({ tcId: "${tcId}" }).`);
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
// Auto-increment v1.0 → v2.0 → v3.0 unless the caller named the version.
|
|
519
|
+
if (!versionName) {
|
|
520
|
+
try {
|
|
521
|
+
const tcForVersions = draftTc ?? (await adapter.getTestCase(tcId));
|
|
522
|
+
versionName = nextVersionName(tcForVersions);
|
|
523
|
+
}
|
|
524
|
+
catch (e) {
|
|
525
|
+
return err(`Could not read ${tcId} to choose the next version name: ${describeError(e)}. Pass versionName explicitly.`);
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
const picked = await pickSourceVersion(adapter, 'TC', tcId, sourceVersionName ?? sourceVersionId);
|
|
529
|
+
if (picked.message)
|
|
530
|
+
return ok(picked.message, { needs: 'sourceVersionName' });
|
|
531
|
+
if (picked.version)
|
|
532
|
+
sourceVersionId = picked.version.id;
|
|
533
|
+
const srcNote = picked.version ? ` Source version: **${picked.version.name}**.` : '';
|
|
534
|
+
// Prompt step: no `tdCopy` → hand back the "Copy Test Data" question so the caller can
|
|
535
|
+
// confirm with the user before writing. Mirrors the FE's COPY TEST DATA modal.
|
|
536
|
+
if (tdCopy === undefined) {
|
|
537
|
+
return ok(`**COPY TEST DATA** — Do you want to copy test data to new version **${versionName}** of ${tcId}?\n\n` +
|
|
538
|
+
`If you do not want to copy the test data, only the column structure will be carried over (one empty ITR-1 per environment).\n\n` +
|
|
539
|
+
`**Ask the user**, then call \`tc_save_as_new_version\` again:\n` +
|
|
540
|
+
`- \`tdCopy: true\` → copy iterations across all environments (Confirm)\n` +
|
|
541
|
+
`- \`tdCopy: false\` → structure only, empty values (Cancel)`, { preview: true, needs: 'tdCopy' });
|
|
542
|
+
}
|
|
543
|
+
try {
|
|
544
|
+
const ref = await adapter.saveAsNewVersion(tcId, {
|
|
545
|
+
versionName: versionName,
|
|
546
|
+
tdCopy,
|
|
547
|
+
// A draft loaded from the TC remembers which version it came from — pin it so tdCopy clones
|
|
548
|
+
// THAT version's iterations instead of the adapter having to re-resolve (or finding none).
|
|
549
|
+
...(sourceVersionId !== undefined
|
|
550
|
+
? { sourceVersionId }
|
|
551
|
+
: draftTc?.currentVersionId
|
|
552
|
+
? { sourceVersionId: draftTc.currentVersionId }
|
|
553
|
+
: {}),
|
|
554
|
+
...(draftTc ? { tc: draftTc } : {}),
|
|
555
|
+
});
|
|
556
|
+
const tdNote = tdCopy
|
|
557
|
+
? ' Testdata iterations were copied across environments.'
|
|
558
|
+
: ' Testdata structure was carried over but values are empty (tdCopy:false).';
|
|
559
|
+
return ok(`Snapshotted ${tcId} as new version **${versionName}**` +
|
|
560
|
+
srcNote +
|
|
561
|
+
(ref.productUrl ? ` · ${ref.productUrl}` : '') +
|
|
562
|
+
`.${tdNote}`, { savedRef: ref });
|
|
563
|
+
}
|
|
564
|
+
catch (e) {
|
|
565
|
+
return err(describeError(e));
|
|
566
|
+
}
|
|
567
|
+
});
|
|
568
|
+
server.registerTool('tc_steps_to_function', {
|
|
569
|
+
title: 'Extract selected steps of a test case into a new reusable function',
|
|
570
|
+
description: 'Take a subset of the steps on an EXISTING test case and save them as a new reusable ' +
|
|
571
|
+
'function (SimplifyQA STEPSTOFN operation). Mirrors the FE "Save as function" modal. ' +
|
|
572
|
+
'Steps are picked by their current `seq`, resequenced 1..N in the new function, and filed ' +
|
|
573
|
+
'under `moduleId`. `tcId` accepts the numeric id or business key (TC_123). Requires a live ' +
|
|
574
|
+
'connection (qa_connect).\n\n' +
|
|
575
|
+
'CALL THIS when the user says things like "save these steps as a function", "convert the ' +
|
|
576
|
+
'first N steps to a function", "extract these steps into a function". Show the steps of the ' +
|
|
577
|
+
'TC first (via tc_get) so the user can confirm which `seq`s to extract, and ASK the user ' +
|
|
578
|
+
'which module to file the new function under — call `list_modules` if the module id is not ' +
|
|
579
|
+
'known.\n\n' +
|
|
580
|
+
'VERSIONS: SimplifyQA TCs can have multiple versions with DIFFERENT step counts/content. ' +
|
|
581
|
+
"When the TC has more than one version and `versionId` is omitted, this tool REFUSES and " +
|
|
582
|
+
"lists the available versions — ASK the user which version's steps to convert, read that " +
|
|
583
|
+
"version's steps with tc_get({ id, versionId }) to confirm the `seq`s, then call this tool " +
|
|
584
|
+
"again with the SAME `versionId`. Pass `versionId: ''` to accept the TC's currently-selected " +
|
|
585
|
+
'version without prompting. Single-version TCs are used directly.\n\n' +
|
|
586
|
+
'`executionType` forces every picked step into the AUTOMATION or MANUAL bucket; omit to ' +
|
|
587
|
+
'split by each step\'s own executionType (function will be DUO if both are present).\n\n' +
|
|
588
|
+
'TESTDATA: iterations from the source TC version are copied to the new function by default. ' +
|
|
589
|
+
'The backend prunes them to only the parameters the extracted steps reference (via key-based ' +
|
|
590
|
+
'matching in tcfn.service.js `compareDatas` `isStepsToFn` mode), across every environment ' +
|
|
591
|
+
'the source version has. Pass `copyTestData: false` if you explicitly want a bare function.\n\n' +
|
|
592
|
+
'REPLACE-IN-SOURCE: pass `replaceInSource: true` to also splice a FUNCTION + FUNCTION_END ' +
|
|
593
|
+
'pair back into the source TC in place of the extracted steps (mirrors the FE "Save & Replace" ' +
|
|
594
|
+
'button). The extracted rows are soft-deleted; the backend automatically drops any testdata ' +
|
|
595
|
+
'columns those steps owned and injects an FN cell (with the FN\'s per-env default iteration) ' +
|
|
596
|
+
'into every TC iteration row. Requires a contiguous `stepSeqs` range and refuses picks that ' +
|
|
597
|
+
'cross control-flow (IF/WHILE/FOR/DO) or nested FUNCTION brackets, and DUO/SYNCON TCs — those ' +
|
|
598
|
+
'are v2 cases.\n\n' +
|
|
599
|
+
'FAILURE MODE with replaceInSource: if the FN is created but the follow-up PUT fails, the ' +
|
|
600
|
+
'error surfaces the new fn id + version id so you can retry or delete the phantom function.',
|
|
601
|
+
inputSchema: {
|
|
602
|
+
tcId: z.string().describe('The source test case id or business key (e.g. TC_123).'),
|
|
603
|
+
stepSeqs: z.array(z.number().int().positive()).min(1)
|
|
604
|
+
.describe('Current `seq` numbers of the steps to extract (e.g. [1,2,3,4] for the first four). Must be contiguous when replaceInSource is true.'),
|
|
605
|
+
name: z.string().min(1).describe('Name for the new function.'),
|
|
606
|
+
moduleId: z.number().int().positive()
|
|
607
|
+
.describe('Module id to file the new function under. Resolve via list_modules if unknown.'),
|
|
608
|
+
executionType: z.enum(['AUTOMATION', 'MANUAL']).optional()
|
|
609
|
+
.describe('Force all picked steps into this bucket; omit to split by each step\'s own executionType.'),
|
|
610
|
+
copyTestData: z.boolean().optional()
|
|
611
|
+
.describe('Copy the source version\'s testdata iterations to the new function (backend prunes to only the params the extracted steps use). Default: true.'),
|
|
612
|
+
replaceInSource: z.boolean().optional()
|
|
613
|
+
.describe('Replace the extracted steps on the source TC with a FUNCTION + FUNCTION_END call to the new function. Default: false (create-only). Requires contiguous stepSeqs and refuses DUO/SYNCON/control-flow spans.'),
|
|
614
|
+
versionId: z.string().optional().describe("Version to extract steps FROM — an id from the TC's `versions[]`, from a real tc_get " +
|
|
615
|
+
'read the user directed. REQUIRED whenever the TC has more than one version (this tool ' +
|
|
616
|
+
"refuses when it's omitted OR empty in that case) — there is no shortcut for \"current\" " +
|
|
617
|
+
'on a multi-version TC; the user must name a version. Omit only for a genuinely single-' +
|
|
618
|
+
'version TC.'),
|
|
619
|
+
},
|
|
620
|
+
annotations: { readOnlyHint: false },
|
|
621
|
+
}, async ({ tcId, stepSeqs, name, moduleId, executionType, copyTestData, replaceInSource, versionId }) => {
|
|
622
|
+
const adapter = deps.getAdapter();
|
|
623
|
+
if (!adapter)
|
|
624
|
+
return err(NOT_CONNECTED);
|
|
625
|
+
if (!adapter.saveStepsAsFunction) {
|
|
626
|
+
return err('This product does not support extracting steps to a function.');
|
|
627
|
+
}
|
|
628
|
+
// Same ASK-when-ambiguous rule as tc_get, but STRICTER: unlike tc_get's read-only ''-means-
|
|
629
|
+
// "accept current" shortcut, this is a WRITE action, so an empty versionId is treated the
|
|
630
|
+
// SAME as omitted — there is no silent "current version" default here. This closes a real
|
|
631
|
+
// loophole where a model satisfied the "versionId required" check by passing '' instead of
|
|
632
|
+
// actually asking the user, then fabricated a justification for skipping the question.
|
|
633
|
+
if ((versionId === undefined || versionId === '') && adapter.getTestCase) {
|
|
634
|
+
try {
|
|
635
|
+
const preview = await adapter.getTestCase(tcId);
|
|
636
|
+
const versions = preview.versions ?? [];
|
|
637
|
+
if (versions.length > 1) {
|
|
638
|
+
const listing = versions
|
|
639
|
+
.map((v) => ` • \`${v.id}\` — **${v.name}**${v.isCurrent ? ' (current)' : ''}`)
|
|
640
|
+
.join('\n');
|
|
641
|
+
return err(`Test case ${preview.id ?? tcId} has ${versions.length} versions — STOP. Do NOT pick ` +
|
|
642
|
+
`one yourself (not "current", not the one you last read with tc_get, not a "sensible ` +
|
|
643
|
+
`default") — ASK the user which version's steps to convert and WAIT for their ` +
|
|
644
|
+
`explicit reply, even if you already showed them this version list earlier in the ` +
|
|
645
|
+
`conversation. There is no '' / "current" shortcut for this tool — a real version id ` +
|
|
646
|
+
`named by the user is required. Once they answer, read that version's steps with ` +
|
|
647
|
+
`tc_get({ id: "${tcId}", versionId }) to confirm the seqs, then call ` +
|
|
648
|
+
`tc_steps_to_function again with that SAME versionId.\n\n${listing}`);
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
catch (e) {
|
|
652
|
+
return err(describeError(e));
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
const chosenVersionId = versionId === undefined || versionId === '' ? undefined : versionId;
|
|
656
|
+
const tdCopy = copyTestData ?? true;
|
|
657
|
+
const tdNote = tdCopy
|
|
658
|
+
? ' Testdata iterations were copied (pruned to the extracted steps\' parameters).'
|
|
659
|
+
: ' No testdata was copied.';
|
|
660
|
+
if (replaceInSource) {
|
|
661
|
+
if (!adapter.extractStepsAsFunctionAndReplace) {
|
|
662
|
+
return err('This product does not support replace-in-source for step-to-function extraction.');
|
|
663
|
+
}
|
|
664
|
+
try {
|
|
665
|
+
const ref = await adapter.extractStepsAsFunctionAndReplace(tcId, {
|
|
666
|
+
stepSeqs, name, moduleId, copyTestData: tdCopy,
|
|
667
|
+
...(executionType !== undefined ? { executionType } : {}),
|
|
668
|
+
...(chosenVersionId !== undefined ? { versionId: chosenVersionId } : {}),
|
|
669
|
+
});
|
|
670
|
+
return ok(`Created function **${name}** (id: ${ref.fnId}, version: ${ref.fnVersionId}) and replaced ` +
|
|
671
|
+
`steps [${stepSeqs.join(', ')}] on ${tcId} with a FUNCTION call.${tdNote}`, { savedRef: ref });
|
|
672
|
+
}
|
|
673
|
+
catch (e) {
|
|
674
|
+
return err(describeError(e));
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
try {
|
|
678
|
+
const ref = await adapter.saveStepsAsFunction(tcId, {
|
|
679
|
+
stepSeqs, name, moduleId, copyTestData: tdCopy,
|
|
680
|
+
...(executionType !== undefined ? { executionType } : {}),
|
|
681
|
+
...(chosenVersionId !== undefined ? { versionId: chosenVersionId } : {}),
|
|
682
|
+
});
|
|
683
|
+
return ok(`Created function **${name}** (id: ${ref.id}) from ${tcId} steps [${stepSeqs.join(', ')}].${tdNote}`, { savedRef: ref });
|
|
684
|
+
}
|
|
685
|
+
catch (e) {
|
|
686
|
+
return err(describeError(e));
|
|
687
|
+
}
|
|
688
|
+
});
|
|
689
|
+
server.registerTool('story_list', {
|
|
690
|
+
title: 'List / search user stories',
|
|
691
|
+
description: 'Pull up USER STORIES in the connected project — id, key (US_…), title, status. Give `search` to ' +
|
|
692
|
+
'find stories by keyword (matches key / title / description / acceptance criteria). Use story_get ' +
|
|
693
|
+
'to read one with its acceptance criteria, then draft manual test cases for it. Requires a live ' +
|
|
694
|
+
'connection (qa_connect). Read-only and product-neutral.',
|
|
695
|
+
inputSchema: {
|
|
696
|
+
search: z.string().optional().describe('Keyword to find stories (key / title / description / AC).'),
|
|
697
|
+
status: z.string().optional(),
|
|
698
|
+
limit: z.number().int().positive().optional(),
|
|
699
|
+
offset: z.number().int().nonnegative().optional(),
|
|
700
|
+
sprintId: z.string().optional().describe('Only stories that belong to this sprint (from list_sprints).'),
|
|
701
|
+
releaseId: z.string().optional().describe('Only stories that belong to this release (from list_releases).'),
|
|
702
|
+
createdBy: z.string().optional().describe('Numeric userId of the creator. Pass "me" to filter by the current caller (needs QA_MCP_USER_ID for API-key auth). Resolve names to ids via list_users first.'),
|
|
703
|
+
updatedBy: z.string().optional().describe('Numeric userId of the last updater. Pass "me" for the current caller. Resolve names via list_users first.'),
|
|
704
|
+
ownerId: z.string().optional().describe('Numeric userId of the story OWNER (assignee). Pass "me" for the current caller. Resolve names via list_users first.'),
|
|
705
|
+
filters: z.array(zRawFilter).optional().describe('Extra raw column filters for project-configured columns with no dedicated parameter above (Feature/Epic/Priority/custom fields) — use the field\'s backend key as `column`.'),
|
|
706
|
+
},
|
|
707
|
+
annotations: { readOnlyHint: true },
|
|
708
|
+
}, async ({ search, status, limit, offset, sprintId, releaseId, createdBy, updatedBy, ownerId, filters }) => {
|
|
709
|
+
const adapter = deps.getAdapter();
|
|
710
|
+
if (!adapter)
|
|
711
|
+
return err(NOT_CONNECTED);
|
|
712
|
+
if (!adapter.listStories)
|
|
713
|
+
return err('This product does not expose a user-story backlog.');
|
|
714
|
+
try {
|
|
715
|
+
const rows = await adapter.listStories({
|
|
716
|
+
...(search ? { search } : {}),
|
|
717
|
+
...(status ? { status } : {}),
|
|
718
|
+
...(limit != null ? { limit } : {}),
|
|
719
|
+
...(offset != null ? { offset } : {}),
|
|
720
|
+
...(sprintId ? { sprintId } : {}),
|
|
721
|
+
...(releaseId ? { releaseId } : {}),
|
|
722
|
+
...(createdBy ? { createdBy } : {}),
|
|
723
|
+
...(updatedBy ? { updatedBy } : {}),
|
|
724
|
+
...(ownerId ? { ownerId } : {}),
|
|
725
|
+
...(filters?.length ? { filters } : {}),
|
|
726
|
+
});
|
|
727
|
+
if (!rows.length)
|
|
728
|
+
return ok('No user stories found.', { stories: [], totalCount: totalOf(rows) ?? 0 });
|
|
729
|
+
const view = rows.map(({ id: _id, ...rest }) => rest);
|
|
730
|
+
const text = `${countHeader(rows, 'story', 'stories')}:\n\n` +
|
|
731
|
+
'| key | title | status |\n|---|---|---|\n' +
|
|
732
|
+
rows.map((s) => `| ${escCell(s.key ?? s.id)} | ${escCell(s.title)} | ${escCell(s.status ?? '-')} |`).join('\n');
|
|
733
|
+
return ok(text, { stories: view, totalCount: totalOf(rows) ?? rows.length });
|
|
734
|
+
}
|
|
735
|
+
catch (e) {
|
|
736
|
+
return err(describeError(e));
|
|
737
|
+
}
|
|
738
|
+
});
|
|
739
|
+
server.registerTool('story_get', {
|
|
740
|
+
title: 'Read one user story (with acceptance criteria)',
|
|
741
|
+
description: 'Read a single user story — title, description, and ACCEPTANCE CRITERIA — from the connected ' +
|
|
742
|
+
'product. `id` accepts the story id or its business key (US_123). Read this before drafting manual ' +
|
|
743
|
+
'test cases so they cover the acceptance criteria. Requires a live connection.',
|
|
744
|
+
inputSchema: { id: z.string().describe('Story id or business key (US_123).') },
|
|
745
|
+
annotations: { readOnlyHint: true },
|
|
746
|
+
}, async ({ id }) => {
|
|
747
|
+
const adapter = deps.getAdapter();
|
|
748
|
+
if (!adapter)
|
|
749
|
+
return err(NOT_CONNECTED);
|
|
750
|
+
if (!adapter.getStory)
|
|
751
|
+
return err('This product does not expose a user-story backlog.');
|
|
752
|
+
try {
|
|
753
|
+
const story = await adapter.getStory(id);
|
|
754
|
+
const ac = story.acceptanceCriteria ?? [];
|
|
755
|
+
const header = `**${story.title}**${story.key ? ` · ${story.key}` : ''}${story.status ? ` · ${story.status}` : ''}`;
|
|
756
|
+
const desc = story.description ? `\n\n${story.description}` : '';
|
|
757
|
+
const acBlock = ac.length
|
|
758
|
+
? `\n\n**Acceptance criteria (${ac.length}):**\n` + ac.map((c, i) => `${i + 1}. ${c}`).join('\n')
|
|
759
|
+
: '\n\n_No acceptance criteria on this story._';
|
|
760
|
+
return ok(`${header}${desc}${acBlock}`, { story });
|
|
761
|
+
}
|
|
762
|
+
catch (e) {
|
|
763
|
+
return err(describeError(e));
|
|
764
|
+
}
|
|
765
|
+
});
|
|
766
|
+
server.registerTool('list_releases', {
|
|
767
|
+
title: 'List releases (project-scoped or all)',
|
|
768
|
+
description: 'List RELEASES in SimplifyQA — id, name, state, planned dates. `scope` is required: ' +
|
|
769
|
+
'"project" = releases attached to the currently connected project, "all" = every release the ' +
|
|
770
|
+
'token can see. ASK the user which scope before calling — do not guess. Requires a live ' +
|
|
771
|
+
'connection (qa_connect). Read-only.',
|
|
772
|
+
inputSchema: {
|
|
773
|
+
scope: z.enum(['project', 'all']).describe('ASK the user first: "project" = current project only, "all" = every release visible to the token.'),
|
|
774
|
+
},
|
|
775
|
+
annotations: { readOnlyHint: true },
|
|
776
|
+
}, async ({ scope }) => {
|
|
777
|
+
const adapter = deps.getAdapter();
|
|
778
|
+
if (!adapter)
|
|
779
|
+
return err(NOT_CONNECTED);
|
|
780
|
+
if (!adapter.listReleases)
|
|
781
|
+
return err('This product has no release/sprint model.');
|
|
782
|
+
try {
|
|
783
|
+
const rows = await adapter.listReleases({ scope });
|
|
784
|
+
if (!rows.length)
|
|
785
|
+
return ok(`No releases found (scope: ${scope}).`, { releases: [], totalCount: totalOf(rows) ?? 0 });
|
|
786
|
+
const text = `${countHeader(rows, 'release')} (scope: ${scope}):\n\n` +
|
|
787
|
+
'| id | name | state | planned start | planned end |\n|---|---|---|---|---|\n' +
|
|
788
|
+
rows
|
|
789
|
+
.map((r) => `| ${escCell(r.id)} | ${escCell(r.name)} | ${escCell(r.state ?? '-')} | ${escCell(r.plannedStartDate ?? '-')} | ${escCell(r.plannedEndDate ?? '-')} |`)
|
|
790
|
+
.join('\n');
|
|
791
|
+
return ok(text, { releases: rows, totalCount: totalOf(rows) ?? rows.length });
|
|
792
|
+
}
|
|
793
|
+
catch (e) {
|
|
794
|
+
return err(describeError(e));
|
|
795
|
+
}
|
|
796
|
+
});
|
|
797
|
+
server.registerTool('list_sprints', {
|
|
798
|
+
title: 'List sprints (optionally within a release)',
|
|
799
|
+
description: 'List SPRINTS in SimplifyQA — id, name, parent release, state, planned dates. Pass ' +
|
|
800
|
+
'`releaseId` (from list_releases) to see sprints of one release; omit to see every sprint the ' +
|
|
801
|
+
'token can see. To answer "how many stories in this sprint", follow up with ' +
|
|
802
|
+
'story_list({ sprintId }). Requires a live connection. Read-only.',
|
|
803
|
+
inputSchema: {
|
|
804
|
+
releaseId: z.string().optional().describe('Only sprints belonging to this release (from list_releases).'),
|
|
805
|
+
},
|
|
806
|
+
annotations: { readOnlyHint: true },
|
|
807
|
+
}, async ({ releaseId }) => {
|
|
808
|
+
const adapter = deps.getAdapter();
|
|
809
|
+
if (!adapter)
|
|
810
|
+
return err(NOT_CONNECTED);
|
|
811
|
+
if (!adapter.listSprints)
|
|
812
|
+
return err('This product has no release/sprint model.');
|
|
813
|
+
try {
|
|
814
|
+
const rows = await adapter.listSprints(releaseId !== undefined ? { releaseId } : {});
|
|
815
|
+
if (!rows.length)
|
|
816
|
+
return ok('No sprints found.', { sprints: [], totalCount: totalOf(rows) ?? 0 });
|
|
817
|
+
const text = `${countHeader(rows, 'sprint')}${releaseId ? ` (release ${releaseId})` : ''}:\n\n` +
|
|
818
|
+
'| id | name | release | state | planned start | planned end |\n|---|---|---|---|---|---|\n' +
|
|
819
|
+
rows
|
|
820
|
+
.map((s) => `| ${escCell(s.id)} | ${escCell(s.name)} | ${escCell(s.releaseId ?? '-')} | ${escCell(s.state ?? '-')} | ${escCell(s.plannedStartDate ?? '-')} | ${escCell(s.plannedEndDate ?? '-')} |`)
|
|
821
|
+
.join('\n');
|
|
822
|
+
return ok(text, { sprints: rows, totalCount: totalOf(rows) ?? rows.length });
|
|
823
|
+
}
|
|
824
|
+
catch (e) {
|
|
825
|
+
return err(describeError(e));
|
|
826
|
+
}
|
|
827
|
+
});
|
|
828
|
+
server.registerTool('list_functions', {
|
|
829
|
+
title: 'List / search reusable functions (NOT test cases)',
|
|
830
|
+
description: 'List reusable FUNCTIONS in the connected project — the FN_* library of building blocks that ' +
|
|
831
|
+
'test cases call as nested steps. NOT test cases: if the user asks for test cases, TCs, ' +
|
|
832
|
+
'scenarios, or scripts, use `tc_list` instead. Trigger words for THIS tool: "functions", ' +
|
|
833
|
+
'"reusable functions", "function library", "FN_", "shared steps", "building blocks". Returns ' +
|
|
834
|
+
'id, key (FN_*), name, description, technology (WEB/API/ANDROID/IOS), execution type ' +
|
|
835
|
+
'(MANUAL/AUTOMATION), review status, step count. Use `get_function` to read one in full ' +
|
|
836
|
+
'(with its steps) and `delete_function` to soft-delete. SimplifyQA-only. Requires a live ' +
|
|
837
|
+
'connection (qa_connect). Read-only.',
|
|
838
|
+
inputSchema: {
|
|
839
|
+
search: z.string().optional().describe('Free-text search over the function name.'),
|
|
840
|
+
fnType: z.string().optional().describe('Filter by technology (WEB / API / ANDROID / IOS).'),
|
|
841
|
+
executionType: z.string().optional().describe('Filter by execution type (MANUAL / AUTOMATION).'),
|
|
842
|
+
moduleId: z.string().optional().describe('Only functions filed under this module (id or business key, e.g. MO_12).'),
|
|
843
|
+
createdBy: z.string().optional().describe('Numeric userId of the creator. Pass "me" to filter by the current caller (needs QA_MCP_USER_ID for API-key auth). Resolve names to ids via list_users first.'),
|
|
844
|
+
updatedBy: z.string().optional().describe('Numeric userId of the last updater. Pass "me" for the current caller. Resolve names via list_users first.'),
|
|
845
|
+
limit: z.number().int().positive().optional().describe('Max results (paging).'),
|
|
846
|
+
offset: z.number().int().nonnegative().optional().describe('Result offset (paging).'),
|
|
847
|
+
},
|
|
848
|
+
annotations: { readOnlyHint: true },
|
|
849
|
+
}, async ({ search, fnType, executionType, moduleId, createdBy, updatedBy, limit, offset }) => {
|
|
850
|
+
const adapter = deps.getAdapter();
|
|
851
|
+
if (!adapter)
|
|
852
|
+
return err(NOT_CONNECTED);
|
|
853
|
+
if (!adapter.listFunctions)
|
|
854
|
+
return err('This product has no reusable-function library.');
|
|
855
|
+
try {
|
|
856
|
+
const rows = await adapter.listFunctions({
|
|
857
|
+
...(search !== undefined ? { search } : {}),
|
|
858
|
+
...(fnType !== undefined ? { fnType } : {}),
|
|
859
|
+
...(executionType !== undefined ? { executionType } : {}),
|
|
860
|
+
...(moduleId !== undefined ? { moduleId } : {}),
|
|
861
|
+
...(createdBy !== undefined ? { createdBy } : {}),
|
|
862
|
+
...(updatedBy !== undefined ? { updatedBy } : {}),
|
|
863
|
+
...(limit !== undefined ? { limit } : {}),
|
|
864
|
+
...(offset !== undefined ? { offset } : {}),
|
|
865
|
+
});
|
|
866
|
+
if (!rows.length)
|
|
867
|
+
return ok('No functions found.', { functions: [], totalCount: totalOf(rows) ?? 0 });
|
|
868
|
+
const view = rows.map(({ id: _id, ...rest }) => rest);
|
|
869
|
+
const text = `${countHeader(rows, 'function')}:\n\n` +
|
|
870
|
+
'| key | name | technology | execution | status | steps |\n|---|---|---|---|---|---|\n' +
|
|
871
|
+
rows
|
|
872
|
+
.map((f) => `| ${escCell(f.code)} | ${escCell(f.name)} | ${f.fnType ?? '-'} | ${f.executionType ?? '-'} | ${f.status ?? '-'} | ${f.stepCount ?? '-'} |`)
|
|
873
|
+
.join('\n');
|
|
874
|
+
return ok(text, { functions: view, totalCount: totalOf(rows) ?? rows.length });
|
|
875
|
+
}
|
|
876
|
+
catch (e) {
|
|
877
|
+
return err(describeError(e));
|
|
878
|
+
}
|
|
879
|
+
});
|
|
880
|
+
server.registerTool('get_function', {
|
|
881
|
+
title: 'Read / explain one reusable function (NOT a test case)',
|
|
882
|
+
description: 'Read a single reusable FUNCTION in full — metadata, description, and steps as a readable ' +
|
|
883
|
+
"table — from the connected product. `id` accepts the function's numeric id or its business key " +
|
|
884
|
+
'(e.g. FN_123). NOT for test cases: if the user asks to read / explain a TC or TC_* id, use ' +
|
|
885
|
+
'`tc_get` instead. Trigger words for THIS tool: "function", "FN_", "reusable function", ' +
|
|
886
|
+
'"explain this function". Use this to explain what a function does before calling it from a ' +
|
|
887
|
+
'test case or before deleting it. Requires a live connection (qa_connect).',
|
|
888
|
+
inputSchema: {
|
|
889
|
+
id: z.string().describe('The function id (or business key like FN_123) to read.'),
|
|
890
|
+
},
|
|
891
|
+
annotations: { readOnlyHint: true },
|
|
892
|
+
}, async ({ id }) => {
|
|
893
|
+
const adapter = deps.getAdapter();
|
|
894
|
+
if (!adapter)
|
|
895
|
+
return err(NOT_CONNECTED);
|
|
896
|
+
if (!adapter.getFunction)
|
|
897
|
+
return err('This product has no reusable-function library.');
|
|
898
|
+
try {
|
|
899
|
+
const fn = await adapter.getFunction(id);
|
|
900
|
+
const steps = fn.steps.length;
|
|
901
|
+
const versionCount = fn.versions?.length ?? 0;
|
|
902
|
+
const header = `**${fn.name}**${fn.code ? ` · ${fn.code}` : fn.id ? ` · ${fn.id}` : ''}\n` +
|
|
903
|
+
`technology: ${fn.fnType ?? '-'} · execution: ${fn.executionType ?? '-'}` +
|
|
904
|
+
`${fn.status ? ` · status: ${fn.status}` : ''} · ${steps} step${steps === 1 ? '' : 's'}` +
|
|
905
|
+
`${versionCount ? ` · ${versionCount} version${versionCount === 1 ? '' : 's'}: ${fn.versions.map((v) => v.name).join(', ')}` : ''}` +
|
|
906
|
+
`${fn.description ? `\n\n${fn.description}` : ''}`;
|
|
907
|
+
const body = steps
|
|
908
|
+
? '\n\n| # | type | description |\n|---|---|---|\n' +
|
|
909
|
+
fn.steps
|
|
910
|
+
.map((s) => `| ${s.n} | ${escCell(s.stepType)}${s.controlFlow ? `/${s.controlFlow.kind}` : ''} | ${escCell(s.description)} |`)
|
|
911
|
+
.join('\n')
|
|
912
|
+
: '\n\n_(no steps)_';
|
|
913
|
+
const versionsBlock = versionCount
|
|
914
|
+
? '\n\n**Versions** (newest first):\n\n| name | id | current | execution | review |\n|---|---|---|---|---|\n' +
|
|
915
|
+
fn.versions
|
|
916
|
+
.map((v) => `| ${escCell(v.name)} | \`${v.id}\` | ${v.isCurrent ? '✓' : ''} | ${v.executionType ?? '-'} | ${v.reviewApproveStatus ?? '-'} |`)
|
|
917
|
+
.join('\n')
|
|
918
|
+
: '';
|
|
919
|
+
return ok(`${header}${body}${versionsBlock}`, { function: fn });
|
|
920
|
+
}
|
|
921
|
+
catch (e) {
|
|
922
|
+
return err(describeError(e));
|
|
923
|
+
}
|
|
924
|
+
});
|
|
925
|
+
server.registerTool('delete_function', {
|
|
926
|
+
title: 'Delete a reusable function (NOT a test case; two-step confirm)',
|
|
927
|
+
description: 'Soft-delete a reusable FUNCTION in the connected product. NOT for test cases: if the user ' +
|
|
928
|
+
'asks to delete a TC or TC_* id, use `tc_delete` instead. Trigger words for THIS tool: ' +
|
|
929
|
+
'"function", "FN_", "reusable function". TWO-STEP CONFIRM: call once with just `id` to preview ' +
|
|
930
|
+
'the target (name + step count) and get a warning; then call again with `{ id, confirm: true }` ' +
|
|
931
|
+
"to actually delete. Refuses to delete without `confirm:true`. `id` accepts the function's " +
|
|
932
|
+
'numeric id or business key. The backend refuses to delete a function that is still referenced ' +
|
|
933
|
+
'by a test case, another function, or a workflow — this tool surfaces those references so the ' +
|
|
934
|
+
'user can remove them first.',
|
|
935
|
+
inputSchema: {
|
|
936
|
+
id: z.string().describe('The function id (or business key like FN_123) to delete.'),
|
|
937
|
+
confirm: z.boolean().optional().describe('Set to true on the SECOND call to actually delete.'),
|
|
938
|
+
},
|
|
939
|
+
annotations: { readOnlyHint: false, destructiveHint: true },
|
|
940
|
+
}, async ({ id, confirm }) => {
|
|
941
|
+
const adapter = deps.getAdapter();
|
|
942
|
+
if (!adapter)
|
|
943
|
+
return err(NOT_CONNECTED);
|
|
944
|
+
if (!adapter.getFunction || !adapter.deleteFunction) {
|
|
945
|
+
return err('This product has no reusable-function library.');
|
|
946
|
+
}
|
|
947
|
+
if (!confirm) {
|
|
948
|
+
try {
|
|
949
|
+
const fn = await adapter.getFunction(id);
|
|
950
|
+
return ok(`⚠️ About to delete function **${fn.name}**` +
|
|
951
|
+
`${fn.code ? ` (${fn.code})` : ''} — ${fn.steps.length} step${fn.steps.length === 1 ? '' : 's'}. ` +
|
|
952
|
+
`To proceed, call again with { id: "${id}", confirm: true }. Deletion will be refused if ` +
|
|
953
|
+
'the function is still referenced by a test case, another function, or a workflow.', { preview: true, function: fn });
|
|
954
|
+
}
|
|
955
|
+
catch (e) {
|
|
956
|
+
return err(describeError(e));
|
|
957
|
+
}
|
|
958
|
+
}
|
|
959
|
+
try {
|
|
960
|
+
await adapter.deleteFunction(id);
|
|
961
|
+
return ok(`Deleted function ${id}.`);
|
|
962
|
+
}
|
|
963
|
+
catch (e) {
|
|
964
|
+
return err(describeError(e));
|
|
965
|
+
}
|
|
966
|
+
});
|
|
967
|
+
server.registerTool('fn_clone', {
|
|
968
|
+
title: 'Save a reusable function as a new function (same project + module)',
|
|
969
|
+
description: 'FOR REUSABLE FUNCTIONS ONLY. NOT for test cases: if the user names a `TC_*` key or asks to ' +
|
|
970
|
+
'clone a test case / scenario / script, use `tc_clone` instead. Trigger words for THIS tool: ' +
|
|
971
|
+
'"function", "reusable function", "FN_", "FN-".\n\n' +
|
|
972
|
+
'Save an existing reusable FUNCTION as a NEW function (new FN id) in the SAME project + ' +
|
|
973
|
+
'module. Mirrors the FE in-editor "Save as new function" dialog (operation: SAVEASNEWFN). ' +
|
|
974
|
+
'Clones ONE source version — pass `sourceVersionId` to pick which; defaults to the FN\'s ' +
|
|
975
|
+
'newest version. `fnId` accepts the numeric id or business key (`FN_*`).\n\n' +
|
|
976
|
+
'`newName` is REQUIRED — backend rejects an empty name on SAVEASNEWFN.\n\n' +
|
|
977
|
+
'TESTDATA — TWO-STEP: call once WITHOUT `tdCopy` to get the "Copy Test Data" prompt and ' +
|
|
978
|
+
'confirm with the user; then call again with `tdCopy` set. Mirrors the FE\'s "COPY TEST ' +
|
|
979
|
+
'DATA" modal (Cancel = false, Confirm = true). The tool REFUSES to clone until `tdCopy` ' +
|
|
980
|
+
'is passed — the prompt step is not skippable.\n\n' +
|
|
981
|
+
'`tdCopy:true` clones the source version\'s testdata iterations across every environment. ' +
|
|
982
|
+
'`tdCopy:false` copies only the column STRUCTURE — one empty iteration (`ITR-1`) per ' +
|
|
983
|
+
'environment; cells fall back to each parameter\'s project-level `defaultValue` if any.\n\n' +
|
|
984
|
+
'Requires a live connection.',
|
|
985
|
+
inputSchema: {
|
|
986
|
+
fnId: z.string().describe('The source function id or business key (e.g. FN_123).'),
|
|
987
|
+
newName: z.string().min(1).describe('Name for the new function (required by backend).'),
|
|
988
|
+
tdCopy: z.boolean().optional().describe('REQUIRED to actually clone. Whether to clone the source version\'s testdata iterations. Omit on the first call to get the confirmation prompt; ask the user, then call again with the chosen value.'),
|
|
989
|
+
sourceVersionId: z.string().optional().describe('Which version of the source FN to clone; defaults to the FN\'s newest version.'),
|
|
990
|
+
sourceVersionName: z.string().optional().describe('Version to use, by NAME/number as the user says it (e.g. "v2", "2"). Preferred over sourceVersionId — the user should never need an id. If the source has several versions and this is omitted, the tool lists them and asks.'),
|
|
991
|
+
},
|
|
992
|
+
annotations: { readOnlyHint: false },
|
|
993
|
+
}, async ({ fnId, newName, tdCopy, sourceVersionId, sourceVersionName }) => {
|
|
994
|
+
const adapter = deps.getAdapter();
|
|
995
|
+
if (!adapter)
|
|
996
|
+
return err(NOT_CONNECTED);
|
|
997
|
+
if (!adapter.cloneFunction)
|
|
998
|
+
return err('This product does not support save-as-new-function.');
|
|
999
|
+
const picked = await pickSourceVersion(adapter, 'FN', fnId, sourceVersionName ?? sourceVersionId);
|
|
1000
|
+
if (picked.message)
|
|
1001
|
+
return ok(picked.message, { needs: 'sourceVersionName' });
|
|
1002
|
+
if (picked.version)
|
|
1003
|
+
sourceVersionId = picked.version.id;
|
|
1004
|
+
const srcNote = picked.version ? ` Source version: **${picked.version.name}**.` : '';
|
|
1005
|
+
// Prompt step: no `tdCopy` → hand back the "Copy Test Data" question.
|
|
1006
|
+
if (tdCopy === undefined) {
|
|
1007
|
+
return ok(`**COPY TEST DATA** — Do you want to copy test data to new function **${newName}** (from ${fnId})?\n\n` +
|
|
1008
|
+
`If you do not want to copy the test data, only the column structure will be carried over (one empty ITR-1 per environment).\n\n` +
|
|
1009
|
+
`**Ask the user**, then call \`fn_clone\` again:\n` +
|
|
1010
|
+
`- \`tdCopy: true\` → copy iterations across all environments (Confirm)\n` +
|
|
1011
|
+
`- \`tdCopy: false\` → structure only, empty values (Cancel)`, { preview: true, needs: 'tdCopy' });
|
|
1012
|
+
}
|
|
1013
|
+
try {
|
|
1014
|
+
const ref = await adapter.cloneFunction(fnId, newName, {
|
|
1015
|
+
tdCopy,
|
|
1016
|
+
...(sourceVersionId !== undefined ? { sourceVersionId } : {}),
|
|
1017
|
+
});
|
|
1018
|
+
const tdNote = tdCopy
|
|
1019
|
+
? ' Testdata iterations were copied across environments.'
|
|
1020
|
+
: ' Testdata structure was carried over but values are empty (tdCopy:false).';
|
|
1021
|
+
return ok(`Cloned ${fnId} → **${newName}**. New id: **${ref.id}**` +
|
|
1022
|
+
srcNote +
|
|
1023
|
+
(ref.productUrl ? ` · ${ref.productUrl}` : '') +
|
|
1024
|
+
`.${tdNote}`, { savedRef: ref });
|
|
1025
|
+
}
|
|
1026
|
+
catch (e) {
|
|
1027
|
+
return err(describeError(e));
|
|
1028
|
+
}
|
|
1029
|
+
});
|
|
1030
|
+
server.registerTool('fn_save_as_new_version', {
|
|
1031
|
+
title: 'Snapshot a reusable function as a new version',
|
|
1032
|
+
description: 'FOR REUSABLE FUNCTIONS ONLY. NOT for test cases: if the user names a `TC_*` key or asks to ' +
|
|
1033
|
+
'snapshot / create a new version of a test case, use `tc_save_as_new_version` instead. ' +
|
|
1034
|
+
'Trigger words for THIS tool: "function", "reusable function", "FN_", "FN-".\n\n' +
|
|
1035
|
+
'Freeze the CURRENT server state of a reusable FUNCTION under a NEW version name — same FN id, a ' +
|
|
1036
|
+
'new version row with cloned steps. Mirrors the SimplifyQA UI "Save as new version" dialog ' +
|
|
1037
|
+
'(operation: SAVENEWVERSION, type: FN). `fnId` accepts the numeric id or business key (`FN_*`).\n\n' +
|
|
1038
|
+
'`versionName` must be unique for this FN — the backend rejects duplicates.\n\n' +
|
|
1039
|
+
'TESTDATA — TWO-STEP: call once WITHOUT `tdCopy` to get the "Copy Test Data" prompt and ' +
|
|
1040
|
+
'confirm with the user; then call again with `tdCopy` set. Mirrors the FE\'s "COPY TEST ' +
|
|
1041
|
+
'DATA" modal (Cancel = false, Confirm = true). The tool REFUSES to snapshot until `tdCopy` ' +
|
|
1042
|
+
'is passed — the prompt step is not skippable.\n\n' +
|
|
1043
|
+
'`tdCopy:true` clones the source version\'s testdata iterations across every environment. ' +
|
|
1044
|
+
'`tdCopy:false` copies only the column STRUCTURE — one empty iteration (`ITR-1`) per ' +
|
|
1045
|
+
'environment; cells fall back to each parameter\'s project-level `defaultValue` if any.\n\n' +
|
|
1046
|
+
'`sourceVersionId` picks which version to snapshot; omit to snapshot the FN\'s newest ' +
|
|
1047
|
+
'version (the FN doc has no inline current-version marker). Requires a live connection.',
|
|
1048
|
+
inputSchema: {
|
|
1049
|
+
fnId: z.string().describe('The function id or business key (e.g. FN_123).'),
|
|
1050
|
+
versionName: z.string().min(1).describe('Name for the new version (must be unique for this FN).'),
|
|
1051
|
+
tdCopy: z.boolean().optional().describe('REQUIRED to actually snapshot. Clone testdata iterations from the source version. Omit on the first call to get the confirmation prompt; ask the user, then call again with the chosen value.'),
|
|
1052
|
+
sourceVersionId: z.string().optional().describe('Version to snapshot; defaults to the FN\'s newest version.'),
|
|
1053
|
+
sourceVersionName: z.string().optional().describe('Version to use, by NAME/number as the user says it (e.g. "v2", "2"). Preferred over sourceVersionId — the user should never need an id. If the source has several versions and this is omitted, the tool lists them and asks.'),
|
|
1054
|
+
},
|
|
1055
|
+
annotations: { readOnlyHint: false },
|
|
1056
|
+
}, async ({ fnId, versionName, tdCopy, sourceVersionId, sourceVersionName }) => {
|
|
1057
|
+
const adapter = deps.getAdapter();
|
|
1058
|
+
if (!adapter)
|
|
1059
|
+
return err(NOT_CONNECTED);
|
|
1060
|
+
if (!adapter.saveAsNewFunctionVersion)
|
|
1061
|
+
return err('This product does not support save-as-new-version for functions.');
|
|
1062
|
+
const picked = await pickSourceVersion(adapter, 'FN', fnId, sourceVersionName ?? sourceVersionId);
|
|
1063
|
+
if (picked.message)
|
|
1064
|
+
return ok(picked.message, { needs: 'sourceVersionName' });
|
|
1065
|
+
if (picked.version)
|
|
1066
|
+
sourceVersionId = picked.version.id;
|
|
1067
|
+
const srcNote = picked.version ? ` Source version: **${picked.version.name}**.` : '';
|
|
1068
|
+
// Prompt step: no `tdCopy` → hand back the "Copy Test Data" question so the caller can
|
|
1069
|
+
// confirm with the user before writing. Mirrors the FE's COPY TEST DATA modal.
|
|
1070
|
+
if (tdCopy === undefined) {
|
|
1071
|
+
return ok(`**COPY TEST DATA** — Do you want to copy test data to new version **${versionName}** of ${fnId}?\n\n` +
|
|
1072
|
+
`If you do not want to copy the test data, only the column structure will be carried over (one empty ITR-1 per environment).\n\n` +
|
|
1073
|
+
`**Ask the user**, then call \`fn_save_as_new_version\` again:\n` +
|
|
1074
|
+
`- \`tdCopy: true\` → copy iterations across all environments (Confirm)\n` +
|
|
1075
|
+
`- \`tdCopy: false\` → structure only, empty values (Cancel)`, { preview: true, needs: 'tdCopy' });
|
|
1076
|
+
}
|
|
1077
|
+
try {
|
|
1078
|
+
const ref = await adapter.saveAsNewFunctionVersion(fnId, {
|
|
1079
|
+
versionName,
|
|
1080
|
+
tdCopy,
|
|
1081
|
+
...(sourceVersionId !== undefined ? { sourceVersionId } : {}),
|
|
1082
|
+
});
|
|
1083
|
+
const tdNote = tdCopy
|
|
1084
|
+
? ' Testdata iterations were copied across environments.'
|
|
1085
|
+
: ' Testdata structure was carried over but values are empty (tdCopy:false).';
|
|
1086
|
+
return ok(`Snapshotted ${fnId} as new version **${versionName}**` +
|
|
1087
|
+
srcNote +
|
|
1088
|
+
(ref.productUrl ? ` · ${ref.productUrl}` : '') +
|
|
1089
|
+
`.${tdNote}`, { savedRef: ref });
|
|
1090
|
+
}
|
|
1091
|
+
catch (e) {
|
|
1092
|
+
return err(describeError(e));
|
|
1093
|
+
}
|
|
1094
|
+
});
|
|
1095
|
+
server.registerTool('list_modules', {
|
|
1096
|
+
title: 'List modules / folders (SimplifyQA test-case tree)',
|
|
1097
|
+
description: 'List the MODULES (folder tree) in the connected project — id, name, parent. Use for any ' +
|
|
1098
|
+
'"list / show / what modules" request. Also the source of the `folderOrModule` id passed to ' +
|
|
1099
|
+
'tc_draft_create (ask the user which one before drafting). SimplifyQA-only: Walnut has no ' +
|
|
1100
|
+
'module tree. Requires a live connection.',
|
|
1101
|
+
inputSchema: {},
|
|
1102
|
+
annotations: { readOnlyHint: true },
|
|
1103
|
+
}, async () => {
|
|
1104
|
+
const adapter = deps.getAdapter();
|
|
1105
|
+
if (!adapter)
|
|
1106
|
+
return err(NOT_CONNECTED);
|
|
1107
|
+
if (!adapter.listModules)
|
|
1108
|
+
return err('This product has no module tree.');
|
|
1109
|
+
try {
|
|
1110
|
+
const rows = await adapter.listModules();
|
|
1111
|
+
if (!rows.length)
|
|
1112
|
+
return ok('No modules found.', { modules: [], totalCount: totalOf(rows) ?? 0 });
|
|
1113
|
+
const text = `${countHeader(rows, 'module')}:\n\n` +
|
|
1114
|
+
'| id | name | type | parent | childIds |\n|---|---|---|---|---|\n' +
|
|
1115
|
+
rows.map((m) => {
|
|
1116
|
+
const type = m.isRoot ? 'root' : m.parentId ? 'sub' : '-';
|
|
1117
|
+
const children = m.childIds?.length ? m.childIds.join(', ') : '-';
|
|
1118
|
+
return `| ${escCell(m.id)} | ${escCell(m.name)} | ${type} | ${escCell(m.parentId ?? '-')} | ${escCell(children)} |`;
|
|
1119
|
+
}).join('\n');
|
|
1120
|
+
return ok(text, { modules: rows, totalCount: totalOf(rows) ?? rows.length });
|
|
1121
|
+
}
|
|
1122
|
+
catch (e) {
|
|
1123
|
+
return err(describeError(e));
|
|
1124
|
+
}
|
|
1125
|
+
});
|
|
1126
|
+
server.registerTool('get_module', {
|
|
1127
|
+
title: 'View module details',
|
|
1128
|
+
description: 'Fetch full detail for one MODULE — id, name, code, description, parentId, childIds. Use ' +
|
|
1129
|
+
'when list_modules\' summary row isn\'t enough (need description or child tree). SimplifyQA-only. ' +
|
|
1130
|
+
'Requires a live connection.',
|
|
1131
|
+
inputSchema: {
|
|
1132
|
+
id: z.string().describe('Module id (numeric or business key resolvable via list_modules).'),
|
|
1133
|
+
},
|
|
1134
|
+
annotations: { readOnlyHint: true },
|
|
1135
|
+
}, async ({ id }) => {
|
|
1136
|
+
const adapter = deps.getAdapter();
|
|
1137
|
+
if (!adapter)
|
|
1138
|
+
return err(NOT_CONNECTED);
|
|
1139
|
+
if (!adapter.getModule)
|
|
1140
|
+
return err('This product has no module tree.');
|
|
1141
|
+
try {
|
|
1142
|
+
const m = await adapter.getModule(id);
|
|
1143
|
+
const lines = [
|
|
1144
|
+
`**Module ${m.id}** — ${m.name}`,
|
|
1145
|
+
m.code ? `Code: ${m.code}` : undefined,
|
|
1146
|
+
m.parentId ? `Parent: ${m.parentId}` : 'Parent: (root)',
|
|
1147
|
+
m.description ? `Description: ${m.description}` : undefined,
|
|
1148
|
+
m.childIds?.length ? `Child module ids: ${m.childIds.join(', ')}` : undefined,
|
|
1149
|
+
].filter(Boolean);
|
|
1150
|
+
return ok(lines.join('\n'), { module: m });
|
|
1151
|
+
}
|
|
1152
|
+
catch (e) {
|
|
1153
|
+
return err(describeError(e));
|
|
1154
|
+
}
|
|
1155
|
+
});
|
|
1156
|
+
const zModuleChild = z.lazy(() => z.object({
|
|
1157
|
+
name: z.string().min(1),
|
|
1158
|
+
description: z.string().optional(),
|
|
1159
|
+
children: z.array(zModuleChild).optional(),
|
|
1160
|
+
}));
|
|
1161
|
+
server.registerTool('create_module', {
|
|
1162
|
+
title: 'Create a module (folder), optionally with a nested subtree, in the test-case tree',
|
|
1163
|
+
description: 'Create a new MODULE under the connected project. Set `isRoot:true` for a top-level folder; ' +
|
|
1164
|
+
'otherwise pass `parentId` (resolve via list_modules). To create a WHOLE HIERARCHY in one call ' +
|
|
1165
|
+
'(root + submodules + nested submodules), pass a `children` array — each child gets ' +
|
|
1166
|
+
'`isRoot:false` and its parentId auto-wired from the tree position (do NOT set `isRoot`/`parentId` ' +
|
|
1167
|
+
'on child nodes). Duplicate name in the same project is rejected server-side. On mid-subtree ' +
|
|
1168
|
+
'failure the response carries `failedAt`; every node before it is already persisted (no ' +
|
|
1169
|
+
'transactional rollback upstream). SimplifyQA-only. Requires a live connection.',
|
|
1170
|
+
inputSchema: {
|
|
1171
|
+
name: z.string().min(1).describe('Module name. Must be unique within the project.'),
|
|
1172
|
+
projectId: z.string().describe('Target project id (see list_projects).'),
|
|
1173
|
+
isRoot: z.boolean().describe('True → top-level folder; false → child of `parentId`.'),
|
|
1174
|
+
parentId: z.string().optional().describe('Parent module id (required when isRoot is false; MUST be omitted when isRoot is true).'),
|
|
1175
|
+
description: z.string().optional().describe('Free-text description.'),
|
|
1176
|
+
children: z.array(zModuleChild).optional().describe('Optional subtree under this module. Each child = { name, description?, children? } — no isRoot/parentId (derived).'),
|
|
1177
|
+
},
|
|
1178
|
+
}, async ({ name, projectId, isRoot, parentId, description, children }) => {
|
|
1179
|
+
const adapter = deps.getAdapter();
|
|
1180
|
+
if (!adapter)
|
|
1181
|
+
return err(NOT_CONNECTED);
|
|
1182
|
+
if (!adapter.createModule)
|
|
1183
|
+
return err('This product has no module tree.');
|
|
1184
|
+
if (!isRoot && !parentId) {
|
|
1185
|
+
return err('parentId is required when isRoot is false.');
|
|
1186
|
+
}
|
|
1187
|
+
if (isRoot && parentId) {
|
|
1188
|
+
return err('parentId must be omitted when isRoot is true — backend silently drops it and the module would land at root, not under the intended parent.');
|
|
1189
|
+
}
|
|
1190
|
+
try {
|
|
1191
|
+
const saved = await adapter.createModule({
|
|
1192
|
+
name,
|
|
1193
|
+
projectId,
|
|
1194
|
+
isRoot,
|
|
1195
|
+
...(parentId ? { parentId } : {}),
|
|
1196
|
+
...(description ? { description } : {}),
|
|
1197
|
+
...(children?.length ? { children } : {}),
|
|
1198
|
+
});
|
|
1199
|
+
return ok(formatModuleSaved(saved), { saved });
|
|
1200
|
+
}
|
|
1201
|
+
catch (e) {
|
|
1202
|
+
return err(describeError(e));
|
|
1203
|
+
}
|
|
1204
|
+
});
|
|
1205
|
+
server.registerTool('update_module', {
|
|
1206
|
+
title: 'Update a module (rename / edit description / move parent)',
|
|
1207
|
+
description: 'Edit an existing MODULE — pass `id` plus any of `name`, `description`, `parentId`. Name ' +
|
|
1208
|
+
'must remain unique within the project (duplicate rejected server-side). Works regardless of ' +
|
|
1209
|
+
'whether test cases/functions/etc. are tagged to the module — no need to delete and recreate ' +
|
|
1210
|
+
'it to rename or move it. `parentId` moves the module elsewhere in the tree (pass `""` to move ' +
|
|
1211
|
+
'it to project root); moving it under itself or under one of its own descendants is refused. ' +
|
|
1212
|
+
'SimplifyQA-only. Requires a live connection.',
|
|
1213
|
+
inputSchema: {
|
|
1214
|
+
id: z.string().describe('Module id (numeric or business key, e.g. MO_12).'),
|
|
1215
|
+
name: z.string().min(1).optional().describe('New module name.'),
|
|
1216
|
+
description: z.string().optional().describe('New description (pass "" to clear).'),
|
|
1217
|
+
parentId: z.string().optional().describe('New parent module id (from list_modules). Moves this module in the hierarchy. Pass "" to ' +
|
|
1218
|
+
'move it to project root instead of under another module.'),
|
|
1219
|
+
projectId: z.string().optional().describe('Project id; defaults to the connected project.'),
|
|
1220
|
+
},
|
|
1221
|
+
}, async ({ id, name, description, parentId, projectId }) => {
|
|
1222
|
+
const adapter = deps.getAdapter();
|
|
1223
|
+
if (!adapter)
|
|
1224
|
+
return err(NOT_CONNECTED);
|
|
1225
|
+
if (!adapter.updateModule)
|
|
1226
|
+
return err('This product has no module tree.');
|
|
1227
|
+
if (name === undefined && description === undefined && parentId === undefined) {
|
|
1228
|
+
return err('Nothing to update — pass at least `name`, `description` or `parentId`.');
|
|
1229
|
+
}
|
|
1230
|
+
if (adapter.getModule) {
|
|
1231
|
+
try {
|
|
1232
|
+
await adapter.getModule(id);
|
|
1233
|
+
}
|
|
1234
|
+
catch {
|
|
1235
|
+
let listing = '';
|
|
1236
|
+
try {
|
|
1237
|
+
const rows = await adapter.listModules?.();
|
|
1238
|
+
if (rows?.length)
|
|
1239
|
+
listing = `\n\nAvailable modules:\n${rows.map((m) => ` • \`${m.id}\` — ${m.name}`).join('\n')}`;
|
|
1240
|
+
}
|
|
1241
|
+
catch { /* best-effort listing only */ }
|
|
1242
|
+
return err(`Module "${id}" not found — nothing was updated.${listing}`);
|
|
1243
|
+
}
|
|
1244
|
+
}
|
|
1245
|
+
try {
|
|
1246
|
+
const saved = await adapter.updateModule(id, {
|
|
1247
|
+
...(name !== undefined ? { name } : {}),
|
|
1248
|
+
...(description !== undefined ? { description } : {}),
|
|
1249
|
+
...(parentId !== undefined ? { parentId } : {}),
|
|
1250
|
+
...(projectId ? { projectId } : {}),
|
|
1251
|
+
});
|
|
1252
|
+
const changed = [
|
|
1253
|
+
name !== undefined ? `name → "${name}"` : undefined,
|
|
1254
|
+
description !== undefined ? `description → "${description}"` : undefined,
|
|
1255
|
+
parentId !== undefined ? `parent → ${parentId === '' ? '(root)' : parentId}` : undefined,
|
|
1256
|
+
].filter(Boolean).join(', ');
|
|
1257
|
+
return ok(`Updated module ${saved.id || id}: ${changed}.`, { saved });
|
|
1258
|
+
}
|
|
1259
|
+
catch (e) {
|
|
1260
|
+
return err(describeError(e));
|
|
1261
|
+
}
|
|
1262
|
+
});
|
|
1263
|
+
server.registerTool('delete_module', {
|
|
1264
|
+
title: 'Delete modules (with dependency dry-run)',
|
|
1265
|
+
description: 'Delete one or more MODULES by id. Two phases: call with `confirm:false` (default) for a ' +
|
|
1266
|
+
'DRY RUN that returns each id\'s dependency footprint (test cases, functions, parameters, ' +
|
|
1267
|
+
'objects, defects, user stories that still reference the module). Call again with ' +
|
|
1268
|
+
'`confirm:true` to actually delete; the server drops only ids with EMPTY dependencies and ' +
|
|
1269
|
+
'silently skips the rest — surface those to the caller so they can move/remove the refs first. ' +
|
|
1270
|
+
'SimplifyQA-only. Requires a live connection.',
|
|
1271
|
+
inputSchema: {
|
|
1272
|
+
ids: z.array(z.string()).min(1).describe('Module ids to delete.'),
|
|
1273
|
+
projectId: z.string().describe('Project id the modules belong to.'),
|
|
1274
|
+
confirm: z.boolean().optional().describe('False (default) → dry-run; true → apply delete.'),
|
|
1275
|
+
},
|
|
1276
|
+
annotations: { destructiveHint: true },
|
|
1277
|
+
}, async ({ ids, projectId, confirm }) => {
|
|
1278
|
+
const adapter = deps.getAdapter();
|
|
1279
|
+
if (!adapter)
|
|
1280
|
+
return err(NOT_CONNECTED);
|
|
1281
|
+
if (!adapter.deleteModule)
|
|
1282
|
+
return err('This product has no module tree.');
|
|
1283
|
+
try {
|
|
1284
|
+
const result = await adapter.deleteModule({ ids, projectId, ...(confirm !== undefined ? { confirm } : {}) });
|
|
1285
|
+
const blockers = result.dependencies.filter((d) => d.tcArr.length || d.fnArr.length || d.parameterArr.length || d.objArr.length || d.defectArr.length || d.usArr.length);
|
|
1286
|
+
if (result.dryRun) {
|
|
1287
|
+
if (!blockers.length) {
|
|
1288
|
+
return ok(`Dry-run: ${ids.length} module(s) have NO dependencies — safe to delete. ` +
|
|
1289
|
+
'Call again with confirm:true to apply.', { result });
|
|
1290
|
+
}
|
|
1291
|
+
const text = `Dry-run: ${blockers.length} of ${ids.length} module(s) still have references. ` +
|
|
1292
|
+
'Deleting with confirm:true will SKIP these ids:\n\n' +
|
|
1293
|
+
'| id | test cases | functions | params | objects | defects | user stories |\n' +
|
|
1294
|
+
'|---|---|---|---|---|---|---|\n' +
|
|
1295
|
+
blockers
|
|
1296
|
+
.map((d) => `| ${d.id} | ${d.tcArr.length} | ${d.fnArr.length} | ${d.parameterArr.length} | ${d.objArr.length} | ${d.defectArr.length} | ${d.usArr.length} |`)
|
|
1297
|
+
.join('\n');
|
|
1298
|
+
return ok(text, { result });
|
|
1299
|
+
}
|
|
1300
|
+
if (blockers.length) {
|
|
1301
|
+
return ok(`Deleted ${ids.length - blockers.length} module(s). ${blockers.length} SKIPPED (still referenced). ` +
|
|
1302
|
+
'Move or remove the referring rows, then retry those ids.', { result });
|
|
1303
|
+
}
|
|
1304
|
+
return ok(`Deleted ${ids.length} module(s).`, { result });
|
|
1305
|
+
}
|
|
1306
|
+
catch (e) {
|
|
1307
|
+
return err(describeError(e));
|
|
1308
|
+
}
|
|
1309
|
+
});
|
|
1310
|
+
server.registerTool('delete_version', {
|
|
1311
|
+
title: 'Delete a version of a test case or function (two-step confirm)',
|
|
1312
|
+
description: 'Soft-delete ONE version of a test case (`kind:"tc"`) or a reusable function (`kind:"fn"`) ' +
|
|
1313
|
+
'in the connected product. `versionId` comes from the parent\'s `versions[]` (populated by ' +
|
|
1314
|
+
'`tc_get` for TCs and `get_function` for FNs); pass the version\'s `name` too (backend ' +
|
|
1315
|
+
'validator requires it). TWO-STEP CONFIRM: call once with `confirm:false` (default) to get ' +
|
|
1316
|
+
'a DRY RUN — the response lists every entity still referencing this version (defects, suites, ' +
|
|
1317
|
+
'exec plans, scenarios, schedulers, pipelines, workflows for a TC; TCs, other FNs, workflows ' +
|
|
1318
|
+
'for a FN). Only when EVERY dependency map is empty is the delete allowed; the server itself ' +
|
|
1319
|
+
"REFUSES a `confirm:true` call when refs still exist, so `confirm:true` doesn't guarantee " +
|
|
1320
|
+
'deletion — the tool inspects the response and reports honestly. Refuses to delete the LAST ' +
|
|
1321
|
+
'remaining version (the parent would be orphaned; use `tc_delete` / `delete_function` instead ' +
|
|
1322
|
+
'to remove the whole entity). SimplifyQA-only. Requires a live connection.',
|
|
1323
|
+
inputSchema: {
|
|
1324
|
+
kind: z.enum(['tc', 'fn']).describe("'tc' for a test-case version; 'fn' for a function version."),
|
|
1325
|
+
parentId: z.string().describe('Parent TC or FN id (numeric or business key like TC_123 / FN_45).'),
|
|
1326
|
+
versionId: z.string().describe("The version's uuid (from tc_get.versions[].id or get_function.versions[].id)."),
|
|
1327
|
+
versionName: z.string().describe("The version's human name (e.g. 'v1.0'). Required by the backend validator."),
|
|
1328
|
+
confirm: z.boolean().optional().describe('False (default) → dry-run; true → apply delete (server still refuses if any dependency exists).'),
|
|
1329
|
+
},
|
|
1330
|
+
annotations: { destructiveHint: true },
|
|
1331
|
+
}, async ({ kind, parentId, versionId, versionName, confirm }) => {
|
|
1332
|
+
const adapter = deps.getAdapter();
|
|
1333
|
+
if (!adapter)
|
|
1334
|
+
return err(NOT_CONNECTED);
|
|
1335
|
+
if (!adapter.deleteVersion)
|
|
1336
|
+
return err('This product has no per-version delete support.');
|
|
1337
|
+
// Client-side "last version" guard — mirrors the SQA UI (testcase.component.ts:2126,
|
|
1338
|
+
// function.component.ts:1600). Backend cheerfully deletes the sole remaining version and
|
|
1339
|
+
// orphans the parent, so we block it here.
|
|
1340
|
+
try {
|
|
1341
|
+
const parent = kind === 'tc'
|
|
1342
|
+
? await adapter.getTestCase(parentId)
|
|
1343
|
+
: adapter.getFunction ? await adapter.getFunction(parentId) : null;
|
|
1344
|
+
const versions = parent?.versions ?? [];
|
|
1345
|
+
if (versions.length === 0) {
|
|
1346
|
+
return err(`${kind === 'tc' ? 'Test case' : 'Function'} ${parentId} has no versions to delete.`);
|
|
1347
|
+
}
|
|
1348
|
+
if (versions.length === 1) {
|
|
1349
|
+
return err(`${kind === 'tc' ? 'Test case' : 'Function'} ${parentId} has only one version — ` +
|
|
1350
|
+
'deleting it would orphan the parent (all steps and testdata go with it). ' +
|
|
1351
|
+
`Delete the whole ${kind === 'tc' ? 'test case (tc_delete)' : 'function (delete_function)'} ` +
|
|
1352
|
+
'instead, or add another version first.');
|
|
1353
|
+
}
|
|
1354
|
+
if (!versions.some((v) => v.id === versionId)) {
|
|
1355
|
+
const listing = versions.map((v) => ` - ${v.name} \`${v.id}\``).join('\n');
|
|
1356
|
+
return err(`Version \`${versionId}\` not found on ${parentId}. Known versions:\n${listing}`);
|
|
1357
|
+
}
|
|
1358
|
+
}
|
|
1359
|
+
catch (e) {
|
|
1360
|
+
return err(describeError(e));
|
|
1361
|
+
}
|
|
1362
|
+
try {
|
|
1363
|
+
const result = await adapter.deleteVersion({
|
|
1364
|
+
kind,
|
|
1365
|
+
parentId,
|
|
1366
|
+
versionId,
|
|
1367
|
+
versionName,
|
|
1368
|
+
...(confirm !== undefined ? { confirm } : {}),
|
|
1369
|
+
});
|
|
1370
|
+
if (result.dryRun) {
|
|
1371
|
+
if (!result.hasBlockers) {
|
|
1372
|
+
return ok(`Dry-run: version \`${versionId}\` (${versionName}) has NO dependencies — safe to delete. ` +
|
|
1373
|
+
'Call again with confirm:true to apply.', { result });
|
|
1374
|
+
}
|
|
1375
|
+
const rows = result.dependencies.map((d) => renderVersionDepRow(d));
|
|
1376
|
+
return ok(`Dry-run: version \`${versionId}\` (${versionName}) still has references. ` +
|
|
1377
|
+
'Deleting is blocked until the referring rows are moved or removed:\n\n' +
|
|
1378
|
+
rows.join('\n'), { result });
|
|
1379
|
+
}
|
|
1380
|
+
if (result.deleted) {
|
|
1381
|
+
return ok(`Deleted version \`${versionId}\` (${versionName}). Cascade: steps, testdata and ` +
|
|
1382
|
+
'testdata iterations for this version were soft-deleted along with it.', { result });
|
|
1383
|
+
}
|
|
1384
|
+
// confirm:true but server returned deps → refused.
|
|
1385
|
+
const rows = result.dependencies.map((d) => renderVersionDepRow(d));
|
|
1386
|
+
return err(`Server REFUSED to delete version \`${versionId}\` — it is still referenced. ` +
|
|
1387
|
+
'Remove or move the refs, then retry:\n\n' + rows.join('\n'));
|
|
1388
|
+
}
|
|
1389
|
+
catch (e) {
|
|
1390
|
+
return err(describeError(e));
|
|
1391
|
+
}
|
|
1392
|
+
});
|
|
1393
|
+
server.registerTool('suite_list', {
|
|
1394
|
+
title: 'List test suites',
|
|
1395
|
+
description: 'List the test suites in the connected product — id, name, type (Manual/Automation, where the ' +
|
|
1396
|
+
'provider has a suite-level type — SimplifyQA does, Walnut doesn\'t), and number of test ' +
|
|
1397
|
+
'cases. Use suite_get to read one with its ordered test cases, or suite_run to execute one. ' +
|
|
1398
|
+
'Requires a live connection (qa_connect). Read-only and product-neutral. When presenting this ' +
|
|
1399
|
+
'as a table, label the count column "Number of testcases", not "Members".',
|
|
1400
|
+
inputSchema: {},
|
|
1401
|
+
annotations: { readOnlyHint: true },
|
|
1402
|
+
}, async () => {
|
|
1403
|
+
const adapter = deps.getAdapter();
|
|
1404
|
+
if (!adapter)
|
|
1405
|
+
return err(NOT_CONNECTED);
|
|
1406
|
+
try {
|
|
1407
|
+
const rows = await adapter.listSuites();
|
|
1408
|
+
if (!rows.length)
|
|
1409
|
+
return ok('No test suites found.', { suites: [], totalCount: totalOf(rows) ?? 0 });
|
|
1410
|
+
const text = `${countHeader(rows, 'suite')}:\n\n` +
|
|
1411
|
+
'| id | name | type | Number of testcases |\n|---|---|---|---|\n' +
|
|
1412
|
+
rows.map((s) => `| ${escCell(s.id)} | ${escCell(s.name)} | ${escCell(s.suiteType ?? '-')} | ${s.memberCount ?? '-'} |`).join('\n');
|
|
1413
|
+
return ok(text, { suites: rows, totalCount: totalOf(rows) ?? rows.length });
|
|
1414
|
+
}
|
|
1415
|
+
catch (e) {
|
|
1416
|
+
return err(describeError(e));
|
|
1417
|
+
}
|
|
1418
|
+
});
|
|
1419
|
+
server.registerTool('list_users', {
|
|
1420
|
+
title: 'List users (resolve a name to a userId)',
|
|
1421
|
+
description: 'List users the caller can see in the connected product — id, name, email, username, status. ' +
|
|
1422
|
+
'Use this to resolve a person\'s NAME to a userId before filtering tc_list / story_list by ' +
|
|
1423
|
+
'`createdBy` / `updatedBy`. Non-admin callers are auto-scoped server-side to users in their ' +
|
|
1424
|
+
'assigned projects. Optional `search` matches on name (case-insensitive substring). Optional ' +
|
|
1425
|
+
'`projectId` narrows further to that project\'s members. Requires a live connection. Read-only.',
|
|
1426
|
+
inputSchema: {
|
|
1427
|
+
search: z.string().optional().describe('Case-insensitive substring over user name.'),
|
|
1428
|
+
projectId: z.string().optional().describe('Only users assigned to this project (from list_projects).'),
|
|
1429
|
+
limit: z.number().int().positive().optional().describe('Max results (default 100).'),
|
|
1430
|
+
offset: z.number().int().nonnegative().optional().describe('Result offset (paging).'),
|
|
1431
|
+
},
|
|
1432
|
+
annotations: { readOnlyHint: true },
|
|
1433
|
+
}, async ({ search, projectId, limit, offset }) => {
|
|
1434
|
+
const adapter = deps.getAdapter();
|
|
1435
|
+
if (!adapter)
|
|
1436
|
+
return err(NOT_CONNECTED);
|
|
1437
|
+
if (!adapter.listUsers)
|
|
1438
|
+
return err('This product does not expose a user directory.');
|
|
1439
|
+
try {
|
|
1440
|
+
const rows = await adapter.listUsers({
|
|
1441
|
+
...(search ? { search } : {}),
|
|
1442
|
+
...(projectId ? { projectId } : {}),
|
|
1443
|
+
...(limit != null ? { limit } : {}),
|
|
1444
|
+
...(offset != null ? { offset } : {}),
|
|
1445
|
+
});
|
|
1446
|
+
if (!rows.length)
|
|
1447
|
+
return ok('No users found.', { users: [], totalCount: totalOf(rows) ?? 0 });
|
|
1448
|
+
const text = `${countHeader(rows, 'user')}:\n\n` +
|
|
1449
|
+
'| id | name | email | username | status |\n|---|---|---|---|---|\n' +
|
|
1450
|
+
rows.map((u) => `| ${escCell(u.id)} | ${escCell(u.name ?? '-')} | ${escCell(u.email ?? '-')} | ${escCell(u.username ?? '-')} | ${escCell(u.status ?? '-')} |`).join('\n');
|
|
1451
|
+
return ok(text, { users: rows, totalCount: totalOf(rows) ?? rows.length });
|
|
1452
|
+
}
|
|
1453
|
+
catch (e) {
|
|
1454
|
+
return err(describeError(e));
|
|
1455
|
+
}
|
|
1456
|
+
});
|
|
1457
|
+
server.registerTool('suite_get', {
|
|
1458
|
+
title: 'Read one test suite (with test cases)',
|
|
1459
|
+
description: 'Read a single test suite — its name, description, and ORDERED test cases — from the ' +
|
|
1460
|
+
'connected product. Requires a live connection (qa_connect). `id` is the suite id. ' +
|
|
1461
|
+
'Product-neutral: same shape on any connected product.',
|
|
1462
|
+
inputSchema: {
|
|
1463
|
+
id: z.string().describe('The suite id to read.'),
|
|
1464
|
+
},
|
|
1465
|
+
annotations: { readOnlyHint: true },
|
|
1466
|
+
}, async ({ id }) => {
|
|
1467
|
+
const adapter = deps.getAdapter();
|
|
1468
|
+
if (!adapter)
|
|
1469
|
+
return err(NOT_CONNECTED);
|
|
1470
|
+
try {
|
|
1471
|
+
const suite = await adapter.getSuite(id);
|
|
1472
|
+
const n = suite.members.length;
|
|
1473
|
+
const header = `**${suite.name}**${suite.id ? ` · ${suite.id}` : ''}` +
|
|
1474
|
+
`${suite.description ? `\n${suite.description}` : ''}\n${n} test case${n === 1 ? '' : 's'}`;
|
|
1475
|
+
const body = n
|
|
1476
|
+
? '\n\n| order | test case |\n|---|---|\n' +
|
|
1477
|
+
suite.members.map((m) => `| ${m.order} | ${escCell(m.tcId)} |`).join('\n')
|
|
1478
|
+
: '';
|
|
1479
|
+
return ok(`${header}${body}`, { suite });
|
|
1480
|
+
}
|
|
1481
|
+
catch (e) {
|
|
1482
|
+
return err(describeError(e));
|
|
1483
|
+
}
|
|
1484
|
+
});
|
|
1485
|
+
server.registerTool('suite_create', {
|
|
1486
|
+
title: 'Create a new suite from a few test cases',
|
|
1487
|
+
description: 'Create a NEW test suite in the connected project from a small set of existing test cases. ' +
|
|
1488
|
+
'`tcIds` accepts numeric ids, business keys (TC_123), OR plain test case NAMES — a name is ' +
|
|
1489
|
+
'resolved by searching the project (tc_list under the hood); an ambiguous name (multiple ' +
|
|
1490
|
+
'matches) or one with zero matches is reported back rather than guessed. NOTE: a suite can ' +
|
|
1491
|
+
'only hold test cases of ONE category (all manual OR all automated) — a mixed set is refused.\n\n' +
|
|
1492
|
+
'NAME: if `name` is omitted, this tool does NOT create anything yet — it resolves the test ' +
|
|
1493
|
+
'cases, SUGGESTS a suite name, and returns a preview. Show the user the suggested name and the ' +
|
|
1494
|
+
'resolved test cases, ask them to confirm it or give their own, then call suite_create again ' +
|
|
1495
|
+
'with `name` set (and the same `tcIds`) to actually create it. Requires a live connection.',
|
|
1496
|
+
inputSchema: {
|
|
1497
|
+
tcIds: z.array(z.string()).min(1).describe('Test case ids, business keys (TC_123), or plain names to include.'),
|
|
1498
|
+
name: z.string().optional().describe('Suite name. Omit to get a suggested name + preview first (does not create).'),
|
|
1499
|
+
description: z.string().optional().describe('Optional suite description.'),
|
|
1500
|
+
},
|
|
1501
|
+
annotations: { readOnlyHint: false },
|
|
1502
|
+
}, async ({ tcIds, name, description }) => {
|
|
1503
|
+
const adapter = deps.getAdapter();
|
|
1504
|
+
if (!adapter)
|
|
1505
|
+
return err(NOT_CONNECTED);
|
|
1506
|
+
if (!adapter.createSuite)
|
|
1507
|
+
return err('This product does not support creating suites.');
|
|
1508
|
+
if (!adapter.getTestCase)
|
|
1509
|
+
return err('This product does not support test-case read.');
|
|
1510
|
+
// Resolve each ref: try it as an id/business key first, else search by name.
|
|
1511
|
+
const resolved = [];
|
|
1512
|
+
const unresolved = [];
|
|
1513
|
+
for (const ref of tcIds) {
|
|
1514
|
+
try {
|
|
1515
|
+
const tc = await adapter.getTestCase(ref);
|
|
1516
|
+
resolved.push({ tcId: tc.id ?? ref, title: tc.title || ref, category: tc.category === 'manual' ? 'manual' : 'automated' });
|
|
1517
|
+
continue;
|
|
1518
|
+
}
|
|
1519
|
+
catch {
|
|
1520
|
+
// Not a direct id/key hit — fall through to a name search below.
|
|
1521
|
+
}
|
|
1522
|
+
if (adapter.listTestCases) {
|
|
1523
|
+
try {
|
|
1524
|
+
const matches = await adapter.listTestCases({ search: ref, limit: 5 });
|
|
1525
|
+
if (matches.length === 1) {
|
|
1526
|
+
const m = matches[0];
|
|
1527
|
+
const category = String(m.executionType ?? '').toUpperCase() === 'MANUAL' ? 'manual' : 'automated';
|
|
1528
|
+
resolved.push({ tcId: m.id, title: m.title, category });
|
|
1529
|
+
continue;
|
|
1530
|
+
}
|
|
1531
|
+
if (matches.length > 1) {
|
|
1532
|
+
return err(`"${ref}" matches ${matches.length} test cases — be more specific or pass the id: ` +
|
|
1533
|
+
matches.map((m) => `${m.title} (${m.id})`).join(', '));
|
|
1534
|
+
}
|
|
1535
|
+
}
|
|
1536
|
+
catch {
|
|
1537
|
+
// fall through to unresolved
|
|
1538
|
+
}
|
|
1539
|
+
}
|
|
1540
|
+
unresolved.push(ref);
|
|
1541
|
+
}
|
|
1542
|
+
if (unresolved.length) {
|
|
1543
|
+
return err(`Could not find a test case for: ${unresolved.join(', ')} — check the id/name, or use ` +
|
|
1544
|
+
'tc_list to search first.');
|
|
1545
|
+
}
|
|
1546
|
+
// Same rule the backend enforces: a suite can only hold ONE category. Catch a mismatch here,
|
|
1547
|
+
// before suggesting a name / asking the user to confirm — no point previewing a suite that
|
|
1548
|
+
// createSuite would refuse anyway.
|
|
1549
|
+
const categories = new Set(resolved.map((r) => r.category));
|
|
1550
|
+
if (categories.size > 1) {
|
|
1551
|
+
const byCategory = (cat) => resolved.filter((r) => r.category === cat).map((r) => `${r.title} (${r.tcId})`).join(', ') || '(none)';
|
|
1552
|
+
return err('Cannot create suite: the test cases are a mix of manual and automated — a suite can only ' +
|
|
1553
|
+
`hold ONE category. Manual: ${byCategory('manual')}. Automated: ${byCategory('automated')}. ` +
|
|
1554
|
+
'Split them into two suites, or pick only same-category test cases.');
|
|
1555
|
+
}
|
|
1556
|
+
if (!name) {
|
|
1557
|
+
const suggested = resolved.length === 1
|
|
1558
|
+
? `${resolved[0].title} Suite`
|
|
1559
|
+
: `${resolved[0].title} + ${resolved.length - 1} more Suite`;
|
|
1560
|
+
return ok(`Resolved ${resolved.length} test case${resolved.length === 1 ? '' : 's'}: ` +
|
|
1561
|
+
`${resolved.map((r) => `${r.title} (${r.tcId})`).join(', ')}.\n\n` +
|
|
1562
|
+
`Suggested suite name: "${suggested}" — ASK the user to confirm this or give their own ` +
|
|
1563
|
+
`name, then call suite_create again with { name, tcIds } (reuse the same tcIds, or the ` +
|
|
1564
|
+
`resolved ids: ${resolved.map((r) => r.tcId).join(', ')}).`, { preview: true, suggestedName: suggested, testCases: resolved });
|
|
1565
|
+
}
|
|
1566
|
+
try {
|
|
1567
|
+
const ref = await adapter.createSuite({
|
|
1568
|
+
name,
|
|
1569
|
+
...(description !== undefined ? { description } : {}),
|
|
1570
|
+
members: resolved.map((r, i) => ({ tcId: r.tcId, order: i + 1 })),
|
|
1571
|
+
});
|
|
1572
|
+
return ok(`Created suite **${name}**${ref.id ? ` · ${ref.id}` : ''} with ${resolved.length} test ` +
|
|
1573
|
+
`case${resolved.length === 1 ? '' : 's'}: ${resolved.map((r) => r.title).join(', ')}.` +
|
|
1574
|
+
(ref.productUrl ? ` ${ref.productUrl}` : ''), { savedRef: ref });
|
|
1575
|
+
}
|
|
1576
|
+
catch (e) {
|
|
1577
|
+
return err(describeError(e));
|
|
1578
|
+
}
|
|
1579
|
+
});
|
|
1580
|
+
// --- Suite membership edits (writes) --------------------------------------
|
|
1581
|
+
// Kept beside suite_list/suite_get so all suite tools live together; they mutate
|
|
1582
|
+
// via the adapter's updateSuiteMembers (→ update_suite_members provider-op).
|
|
1583
|
+
const testCasesTable = (suite) => suite.members.length
|
|
1584
|
+
? '\n\n| order | test case |\n|---|---|\n' +
|
|
1585
|
+
suite.members.map((m) => `| ${m.order} | ${escCell(m.tcId)} |`).join('\n')
|
|
1586
|
+
: '';
|
|
1587
|
+
server.registerTool('suite_add_testcases', {
|
|
1588
|
+
title: 'Add test cases to a suite',
|
|
1589
|
+
description: 'Add one or more EXISTING test cases to a suite (appended in order). `tcIds` accepts ids or ' +
|
|
1590
|
+
'business keys (e.g. TC_123) — use suite_list / tc_list to find them. NOTE: a suite can only ' +
|
|
1591
|
+
'hold test cases of ONE category (all manual OR all automated) — the product rejects a mix. ' +
|
|
1592
|
+
'Requires a live connection. Returns the updated suite with its test cases.',
|
|
1593
|
+
inputSchema: {
|
|
1594
|
+
suiteId: z.string().describe('The suite id to add to (from suite_list).'),
|
|
1595
|
+
tcIds: z.array(z.string()).min(1).describe('Test case ids / business keys to add.'),
|
|
1596
|
+
},
|
|
1597
|
+
annotations: { readOnlyHint: false },
|
|
1598
|
+
}, async ({ suiteId, tcIds }) => {
|
|
1599
|
+
const adapter = deps.getAdapter();
|
|
1600
|
+
if (!adapter)
|
|
1601
|
+
return err(NOT_CONNECTED);
|
|
1602
|
+
try {
|
|
1603
|
+
const ops = tcIds.map((tcId) => ({ op: 'add', tcId }));
|
|
1604
|
+
const suite = await adapter.updateSuiteMembers(suiteId, ops);
|
|
1605
|
+
const n = suite.members.length;
|
|
1606
|
+
// Resolve titles for the confirmation — membership rows only carry `tcId`.
|
|
1607
|
+
const added = await Promise.all(tcIds.map(async (tcId) => {
|
|
1608
|
+
try {
|
|
1609
|
+
const tc = await adapter.getTestCase(tcId);
|
|
1610
|
+
return tc.title ? `${tc.title} (${tcId})` : tcId;
|
|
1611
|
+
}
|
|
1612
|
+
catch {
|
|
1613
|
+
return tcId;
|
|
1614
|
+
}
|
|
1615
|
+
}));
|
|
1616
|
+
return ok(`Added ${added.length} test case${added.length === 1 ? '' : 's'} to **${suite.name}**: ` +
|
|
1617
|
+
`${added.join(', ')} — now ${n} test case${n === 1 ? '' : 's'} total.` +
|
|
1618
|
+
testCasesTable(suite), { suite });
|
|
1619
|
+
}
|
|
1620
|
+
catch (e) {
|
|
1621
|
+
return err(describeError(e));
|
|
1622
|
+
}
|
|
1623
|
+
});
|
|
1624
|
+
server.registerTool('suite_remove_testcases', {
|
|
1625
|
+
title: 'Remove test cases from a suite',
|
|
1626
|
+
description: 'Remove one or more test cases from a suite. `tcIds` accepts ids or business keys; every ' +
|
|
1627
|
+
'occurrence of each is removed and the remaining test cases are reordered. Requires a live ' +
|
|
1628
|
+
'connection. Returns the updated suite with its test cases.',
|
|
1629
|
+
inputSchema: {
|
|
1630
|
+
suiteId: z.string().describe('The suite id to remove from.'),
|
|
1631
|
+
tcIds: z.array(z.string()).min(1).describe('Test case ids / business keys to remove.'),
|
|
1632
|
+
},
|
|
1633
|
+
annotations: { readOnlyHint: false },
|
|
1634
|
+
}, async ({ suiteId, tcIds }) => {
|
|
1635
|
+
const adapter = deps.getAdapter();
|
|
1636
|
+
if (!adapter)
|
|
1637
|
+
return err(NOT_CONNECTED);
|
|
1638
|
+
try {
|
|
1639
|
+
const ops = tcIds.map((tcId) => ({ op: 'remove', tcId }));
|
|
1640
|
+
const suite = await adapter.updateSuiteMembers(suiteId, ops);
|
|
1641
|
+
const n = suite.members.length;
|
|
1642
|
+
return ok(`Removed ${tcIds.length} test case${tcIds.length === 1 ? '' : 's'} from **${suite.name}** — now ${n} test case${n === 1 ? '' : 's'} total.` +
|
|
1643
|
+
testCasesTable(suite), { suite });
|
|
1644
|
+
}
|
|
1645
|
+
catch (e) {
|
|
1646
|
+
return err(describeError(e));
|
|
1647
|
+
}
|
|
1648
|
+
});
|
|
1649
|
+
// --- Journal-first editing: READ side (journal_grep) ----------------------
|
|
1650
|
+
// The write side (journal_modify) forwards to the agent's edit_journal op.
|
|
1651
|
+
server.registerTool('journal_grep', {
|
|
1652
|
+
title: 'Read a test case for editing (journal view)',
|
|
1653
|
+
description: 'Load a test case as NUMBERED steps to edit — from its recording JOURNAL when one exists (so a ' +
|
|
1654
|
+
'later journal_modify stays healer/re-record consistent), else from its persisted steps (the ' +
|
|
1655
|
+
'`source` is reported). Optional `pattern` filters shown rows (case-insensitive substring over ' +
|
|
1656
|
+
'the step description) to help locate a range for journal_modify. Requires a live connection.',
|
|
1657
|
+
inputSchema: {
|
|
1658
|
+
tcId: z.string().describe('Test case id or business key.'),
|
|
1659
|
+
pattern: z.string().optional().describe('Case-insensitive substring filter over step descriptions.'),
|
|
1660
|
+
},
|
|
1661
|
+
annotations: { readOnlyHint: true },
|
|
1662
|
+
}, async ({ tcId, pattern }) => {
|
|
1663
|
+
const adapter = deps.getAdapter();
|
|
1664
|
+
if (!adapter)
|
|
1665
|
+
return err(NOT_CONNECTED);
|
|
1666
|
+
if (!adapter.readJournal)
|
|
1667
|
+
return err('This product has no recording journal.');
|
|
1668
|
+
try {
|
|
1669
|
+
const view = await adapter.readJournal(tcId);
|
|
1670
|
+
const p = pattern?.toLowerCase();
|
|
1671
|
+
const rows = view.steps
|
|
1672
|
+
.filter((s) => !p || (s.description ?? '').toLowerCase().includes(p))
|
|
1673
|
+
.map((s) => `| ${s.n} | ${escCell(s.stepType)}${s.controlFlow ? `/${s.controlFlow.kind}` : ''} | ${escCell(s.description)} |`);
|
|
1674
|
+
const staleness = view.source === 'journal'
|
|
1675
|
+
? ` · journal seed${view.ageDays != null ? ` (${view.ageDays}d old)` : ''}`
|
|
1676
|
+
: ' · NO journal seed — showing persisted steps (a new-interaction add would be steps-only)';
|
|
1677
|
+
const header = `**${tcId}** — ${view.steps.length} step${view.steps.length === 1 ? '' : 's'} · source: ${view.source}${staleness}`;
|
|
1678
|
+
const body = rows.length
|
|
1679
|
+
? '\n\n| n | type | description |\n|---|---|---|\n' + rows.join('\n')
|
|
1680
|
+
: `\n\n(no steps${pattern ? ' match the filter' : ''})`;
|
|
1681
|
+
return ok(`${header}${body}`, { view });
|
|
1682
|
+
}
|
|
1683
|
+
catch (e) {
|
|
1684
|
+
return err(describeError(e));
|
|
1685
|
+
}
|
|
1686
|
+
});
|
|
1687
|
+
server.registerTool('journal_modify', {
|
|
1688
|
+
title: 'Modify a test case (steps, loops, if-else, nested)',
|
|
1689
|
+
description: 'Apply granular edits to an EXISTING test case and persist them, opening the result in the ' +
|
|
1690
|
+
'test-case editor. Use journal_grep first to see the numbered steps, then pass ops (numbers are ' +
|
|
1691
|
+
'from that view, 1-based):\n' +
|
|
1692
|
+
' • add_step / update_step / remove_step / move_step — edit individual steps\n' +
|
|
1693
|
+
' • duplicate_step { n, through?, at? } — copy the WHOLE step (parameters, values, object, flags, settings) to the end or to `at`; ' +
|
|
1694
|
+
'use this for "add the same step again", not add_step. `through` is required when n opens an IF / loop / function block.\n' +
|
|
1695
|
+
' • update_steps { where, patch } — one patch for EVERY matching step ("skip every step that uses X"); where: numbers, from/to, stepType, actionType, object, descriptionContains, parameter, or all:true\n' +
|
|
1696
|
+
' • a step patch may carry swapParams [{ from, to, value? }] to replace one parameter with another in the same slot (recordedParam only adds)\n' +
|
|
1697
|
+
' • add_assertions { n, assertions:[{ path, condition, expectedValue }] } — APPEND response assertions to an ' +
|
|
1698
|
+
'EXISTING API step (path: statusCode | responseTime | responseSize | $.body.x | $.headers.Name). The request, object, ' +
|
|
1699
|
+
'action, parameters and existing assertions are untouched — use this for "add only the assertion to step N".\n' +
|
|
1700
|
+
' • update_step patch.api is MERGED into the saved API request (add an assertion: api.addAssertions [{ path, condition, expectedValue }]; api.assertions replaces the list) — edit an API step with this, never remove_step + add_step\n' +
|
|
1701
|
+
' • wrap_in_loop { from, to, condition?, maxIterations? } — wrap steps from..to in a while loop\n' +
|
|
1702
|
+
' • wrap_in_if { from, to, condition? } — wrap steps from..to in an if block\n' +
|
|
1703
|
+
' • insert_nested { at?, tcId, name? } — insert an existing test case as a nested step (reuse)\n' +
|
|
1704
|
+
'For a test case backed by a recording journal the journal is kept in sync (so healer / ' +
|
|
1705
|
+
're-record stay consistent); others edit the persisted steps. NOTE: adding a brand-new ' +
|
|
1706
|
+
'INTERACTION step (click/type on a new element) via add_step has no captured locator, so it is ' +
|
|
1707
|
+
'a manual/non-executable step — unless you give it an object: pass objectRef { id } or { name } to reuse an ' +
|
|
1708
|
+
'existing object from the repository, or { name, locators:[{ name, value }] } to create one. A step that ' +
|
|
1709
|
+
'needs NO element — e.g. Minimum Wait — needs none. Use add_step { at?, step: { actionType:"Minimum Wait", ' +
|
|
1710
|
+
'stepType, description, value? } } — `at` (alias `seq`) is the 1-based position the new step takes; it is ' +
|
|
1711
|
+
'inserted there DIRECTLY (the recorder window does not open) and the other steps just shift down. ' +
|
|
1712
|
+
'Requires a live connection.',
|
|
1713
|
+
inputSchema: {
|
|
1714
|
+
tcId: z.string().describe('Test case id or business key.'),
|
|
1715
|
+
ops: z.array(zJournalOp).min(1).describe('Ops to apply, in order.'),
|
|
1716
|
+
},
|
|
1717
|
+
annotations: { readOnlyHint: false },
|
|
1718
|
+
}, async ({ tcId, ops }) => {
|
|
1719
|
+
const adapter = deps.getAdapter();
|
|
1720
|
+
if (!adapter)
|
|
1721
|
+
return err(NOT_CONNECTED);
|
|
1722
|
+
if (!adapter.editJournal)
|
|
1723
|
+
return err('This product has no editable recording journal.');
|
|
1724
|
+
// A live recording's id is its SESSION id (mcp-xxxxxxxx), not a test case. Editing steps there
|
|
1725
|
+
// would not work anyway: Save persists the recorder WINDOW's step list, not the journal, so a
|
|
1726
|
+
// journal edit is invisible to the user and lost at save. Point at the tool that does work.
|
|
1727
|
+
if (/^mcp-[a-z0-9]+$/i.test(tcId.trim())) {
|
|
1728
|
+
return err(`"${tcId}" is a LIVE recording session, not a saved test case.\n` +
|
|
1729
|
+
'The recorder window owns the steps that Save persists, so a pre-save removal has to happen there:\n' +
|
|
1730
|
+
' • core_remove_steps({ numbers: [3,5] }) → preview\n' +
|
|
1731
|
+
' • core_remove_steps({ numbers: [3,5], confirm: true }) → deletes those rows in the recorder window\n' +
|
|
1732
|
+
'Once the recording is saved, edit the test case with journal_modify({ tcId: "TC-…" }).');
|
|
1733
|
+
}
|
|
1734
|
+
try {
|
|
1735
|
+
const view = await adapter.editJournal(tcId, ops);
|
|
1736
|
+
const rows = view.steps.map((s) => `| ${s.n} | ${escCell(s.stepType)}${s.controlFlow ? `/${s.controlFlow.kind}` : ''} | ${escCell(s.description)} |`);
|
|
1737
|
+
return ok(`Updated **${tcId}** — ${view.steps.length} step${view.steps.length === 1 ? '' : 's'}${view.source === 'steps' ? '' : ' (opened in the editor)'}.` +
|
|
1738
|
+
'\n\n| n | type | description |\n|---|---|---|\n' +
|
|
1739
|
+
rows.join('\n'), { view });
|
|
1740
|
+
}
|
|
1741
|
+
catch (e) {
|
|
1742
|
+
return err(describeError(e));
|
|
1743
|
+
}
|
|
1744
|
+
});
|
|
1745
|
+
}
|
|
1746
|
+
//# sourceMappingURL=discovery.tools.js.map
|