@smartbear/mcp 0.30.0 → 0.32.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bearq/client.js +2 -6
- package/dist/bearq/tool/tasks/delete-test-cases.js +53 -0
- package/dist/package.json.js +1 -1
- package/dist/qtm4j/client.js +14 -0
- package/dist/qtm4j/config/constants.js +83 -2
- package/dist/qtm4j/config/field-resolution.types.js +12 -2
- package/dist/qtm4j/http/api-client.js +30 -4
- package/dist/qtm4j/http/auth-service.js +3 -2
- package/dist/qtm4j/resolver/resolver-registry.js +37 -1
- package/dist/qtm4j/resolver/resolvers/build-resolver.js +51 -0
- package/dist/qtm4j/resolver/resolvers/common-attribute-resolver.js +1 -3
- package/dist/qtm4j/resolver/resolvers/component-resolver.js +1 -1
- package/dist/qtm4j/resolver/resolvers/defect-id-resolver.js +44 -0
- package/dist/qtm4j/resolver/resolvers/defect-priority-resolver.js +55 -0
- package/dist/qtm4j/resolver/resolvers/defect-status-resolver.js +55 -0
- package/dist/qtm4j/resolver/resolvers/environment-resolver.js +51 -0
- package/dist/qtm4j/resolver/resolvers/execution-context-resolver.js +58 -0
- package/dist/qtm4j/resolver/resolvers/label-resolver.js +1 -1
- package/dist/qtm4j/resolver/resolvers/requirement-id-resolver.js +3 -4
- package/dist/qtm4j/resolver/resolvers/step-execution-context-resolver.js +62 -0
- package/dist/qtm4j/resolver/resolvers/test-case-uid-resolver.js +3 -4
- package/dist/qtm4j/resolver/resolvers/test-cycle-uid-resolver.js +3 -4
- package/dist/qtm4j/schema/get-bugs.schema.js +101 -0
- package/dist/qtm4j/schema/get-test-case.schema.js +3 -3
- package/dist/qtm4j/schema/link-bugs.schema.js +63 -0
- package/dist/qtm4j/schema/start-execution.schema.js +45 -0
- package/dist/qtm4j/schema/test-cycle.link.schema.js +10 -1
- package/dist/qtm4j/schema/update-test-case-execution.schema.js +41 -0
- package/dist/qtm4j/schema/update-test-step-execution.schema.js +41 -0
- package/dist/qtm4j/tool/project/get-projects.js +3 -3
- package/dist/qtm4j/tool/project/set-project-context.js +1 -1
- package/dist/qtm4j/tool/test-automation/get-automation-history.js +4 -7
- package/dist/qtm4j/tool/test-automation/upload-automation-result.js +4 -2
- package/dist/qtm4j/tool/test-execution/get-test-case-bugs.js +119 -0
- package/dist/qtm4j/tool/test-execution/get-test-step-bugs.js +122 -0
- package/dist/qtm4j/tool/test-execution/link-test-case-bugs.js +135 -0
- package/dist/qtm4j/tool/test-execution/link-test-step-bugs.js +140 -0
- package/dist/qtm4j/tool/test-execution/start-execution.js +150 -0
- package/dist/qtm4j/tool/test-execution/update-test-case-execution.js +123 -0
- package/dist/qtm4j/tool/test-execution/update-test-step-execution.js +126 -0
- package/dist/swagger/client/api.js +8 -1
- package/dist/swagger/client/functional-testing-api.js +5 -9
- package/dist/swagger/client/user-management-types.js +2 -1
- package/package.json +1 -1
- package/dist/bearq/tool/tasks/refine-all-draft-tests.js +0 -28
- package/dist/bearq/tool/tasks/refine-test-cases.js +0 -31
- package/dist/bearq/tool/tasks/refine-tests-in-functional-areas.js +0 -35
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { Tool, ToolError } from "../../../common/tools.js";
|
|
2
|
+
import { TOOL_NAMES, TOOLSETS, ENDPOINTS } from "../../config/constants.js";
|
|
3
|
+
import { ResolverKeys } from "../../config/field-resolution.types.js";
|
|
4
|
+
import { GetBugsResponse, GetTestCaseBugsBody } from "../../schema/get-bugs.schema.js";
|
|
5
|
+
const FILTER_FIELD_CONFIG = {
|
|
6
|
+
priority: ResolverKeys.SearchableField.DEFECT_PRIORITY,
|
|
7
|
+
status: ResolverKeys.SearchableField.DEFECT_STATUS
|
|
8
|
+
};
|
|
9
|
+
class GetTestCaseBugs extends Tool {
|
|
10
|
+
specification = {
|
|
11
|
+
title: TOOL_NAMES.GET_LINKED_BUGS_OF_TEST_CASE_EXECUTION.TITLE,
|
|
12
|
+
toolset: TOOLSETS.TEST_EXECUTIONS,
|
|
13
|
+
summary: TOOL_NAMES.GET_LINKED_BUGS_OF_TEST_CASE_EXECUTION.SUMMARY,
|
|
14
|
+
readOnly: true,
|
|
15
|
+
idempotent: true,
|
|
16
|
+
inputSchema: GetTestCaseBugsBody,
|
|
17
|
+
outputSchema: GetBugsResponse,
|
|
18
|
+
purpose: "Retrieve Jira bugs linked to a test case execution.",
|
|
19
|
+
useCases: [
|
|
20
|
+
"List all Jira bugs linked to a test case execution",
|
|
21
|
+
"Filter linked bugs by priority or status"
|
|
22
|
+
],
|
|
23
|
+
examples: [
|
|
24
|
+
{
|
|
25
|
+
description: "Get all linked bugs for a test case execution",
|
|
26
|
+
parameters: {
|
|
27
|
+
testCycleKey: "PROJ-TR-101",
|
|
28
|
+
testCaseKey: "PROJ-TC-42"
|
|
29
|
+
},
|
|
30
|
+
expectedOutput: "Paginated list of all bugs linked to the test case execution"
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
description: "Filter by priority",
|
|
34
|
+
parameters: {
|
|
35
|
+
testCycleKey: "PROJ-TR-101",
|
|
36
|
+
testCaseKey: "PROJ-TC-42",
|
|
37
|
+
filter: { priority: ["High"] }
|
|
38
|
+
},
|
|
39
|
+
expectedOutput: "Linked bugs with High priority"
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
description: "Filter by status",
|
|
43
|
+
parameters: {
|
|
44
|
+
testCycleKey: "PROJ-TR-101",
|
|
45
|
+
testCaseKey: "PROJ-TC-42",
|
|
46
|
+
filter: { status: ["To Do", "In Progress"] }
|
|
47
|
+
},
|
|
48
|
+
expectedOutput: "Linked bugs in To Do or In Progress status"
|
|
49
|
+
}
|
|
50
|
+
],
|
|
51
|
+
hints: [
|
|
52
|
+
"Call set_project_context before this tool.",
|
|
53
|
+
"An empty result (total = 0) means no bugs are linked — it is not an error.",
|
|
54
|
+
"priority and status names are resolved to numeric IDs; unresolved names are skipped with a warning.",
|
|
55
|
+
"Use get_linked_bugs_of_test_step_execution to retrieve bugs linked at a specific step level."
|
|
56
|
+
],
|
|
57
|
+
outputDescription: "JSON object with startAt, maxResults, total, and data array of linked bug objects. Each bug has: id, key, summary, status, priority, issueType, level, stepSeqNo, parameterGroup."
|
|
58
|
+
};
|
|
59
|
+
handle = async (rawArgs) => {
|
|
60
|
+
const args = GetTestCaseBugsBody.parse(rawArgs);
|
|
61
|
+
const fieldResolver = this.client.getResolverRegistry();
|
|
62
|
+
const context = fieldResolver.requireProjectContext();
|
|
63
|
+
const warnings = [];
|
|
64
|
+
const testCaseExecutionId = await this.resolveTestCaseExecutionId(
|
|
65
|
+
fieldResolver,
|
|
66
|
+
context,
|
|
67
|
+
args.testCycleKey,
|
|
68
|
+
args.testCaseKey
|
|
69
|
+
);
|
|
70
|
+
if (args.filter) {
|
|
71
|
+
await Promise.all(
|
|
72
|
+
Object.entries(FILTER_FIELD_CONFIG).map(
|
|
73
|
+
([inputField, resolverKey]) => fieldResolver.getResolver(resolverKey).resolve(
|
|
74
|
+
inputField,
|
|
75
|
+
resolverKey,
|
|
76
|
+
args.filter,
|
|
77
|
+
context,
|
|
78
|
+
warnings
|
|
79
|
+
)
|
|
80
|
+
)
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
const requestBody = args.filter ? { filter: args.filter } : {};
|
|
84
|
+
const params = new URLSearchParams();
|
|
85
|
+
params.set("startAt", String(args.startAt));
|
|
86
|
+
params.set("maxResults", String(args.maxResults));
|
|
87
|
+
params.set("level", args.level);
|
|
88
|
+
const endpoint = `${ENDPOINTS.GET_LINKED_BUGS_TEST_CASE_EXECUTION(
|
|
89
|
+
args.testCycleKey,
|
|
90
|
+
testCaseExecutionId
|
|
91
|
+
)}?${params.toString()}`;
|
|
92
|
+
const response = await this.client.getApiClient().post(endpoint, requestBody);
|
|
93
|
+
const validated = GetBugsResponse.parse(response);
|
|
94
|
+
return {
|
|
95
|
+
structuredContent: validated,
|
|
96
|
+
content: warnings.length > 0 ? [{ type: "text", text: `Note: ${warnings.join(" | ")}` }] : []
|
|
97
|
+
};
|
|
98
|
+
};
|
|
99
|
+
async resolveTestCaseExecutionId(fieldResolver, context, testCycleKey, testCaseKey) {
|
|
100
|
+
const result = await fieldResolver.getResolver(ResolverKeys.SearchableField.EXECUTION_CONTEXT).resolveAndReturn(context.projectKey, context.projectId, testCycleKey, [
|
|
101
|
+
testCaseKey
|
|
102
|
+
]);
|
|
103
|
+
const entry = result[testCaseKey];
|
|
104
|
+
if (!entry) {
|
|
105
|
+
throw new ToolError(
|
|
106
|
+
`Test case '${testCaseKey}' is not linked to test cycle '${testCycleKey}'. Verify the key and ensure it belongs to the cycle.`
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
if (entry.testCaseExecutionId == null) {
|
|
110
|
+
throw new ToolError(
|
|
111
|
+
`No execution has been started for test case '${testCaseKey}' in cycle '${testCycleKey}'. Use start_new_execution first.`
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
return entry.testCaseExecutionId;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
export {
|
|
118
|
+
GetTestCaseBugs
|
|
119
|
+
};
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { Tool, ToolError } from "../../../common/tools.js";
|
|
2
|
+
import { TOOL_NAMES, TOOLSETS, ENDPOINTS } from "../../config/constants.js";
|
|
3
|
+
import { ResolverKeys } from "../../config/field-resolution.types.js";
|
|
4
|
+
import { GetBugsResponse, GetTestStepBugsBody } from "../../schema/get-bugs.schema.js";
|
|
5
|
+
const FILTER_FIELD_CONFIG = {
|
|
6
|
+
priority: ResolverKeys.SearchableField.DEFECT_PRIORITY,
|
|
7
|
+
status: ResolverKeys.SearchableField.DEFECT_STATUS
|
|
8
|
+
};
|
|
9
|
+
class GetTestStepBugs extends Tool {
|
|
10
|
+
specification = {
|
|
11
|
+
title: TOOL_NAMES.GET_LINKED_BUGS_OF_TEST_STEP_EXECUTION.TITLE,
|
|
12
|
+
toolset: TOOLSETS.TEST_EXECUTIONS,
|
|
13
|
+
summary: TOOL_NAMES.GET_LINKED_BUGS_OF_TEST_STEP_EXECUTION.SUMMARY,
|
|
14
|
+
readOnly: true,
|
|
15
|
+
idempotent: true,
|
|
16
|
+
inputSchema: GetTestStepBugsBody,
|
|
17
|
+
outputSchema: GetBugsResponse,
|
|
18
|
+
purpose: "Retrieve Jira bugs linked to a specific test step execution.",
|
|
19
|
+
useCases: [
|
|
20
|
+
"List all Jira bugs linked to a specific test step execution",
|
|
21
|
+
"Filter step-level linked bugs by priority or status"
|
|
22
|
+
],
|
|
23
|
+
examples: [
|
|
24
|
+
{
|
|
25
|
+
description: "Get linked bugs for step 2",
|
|
26
|
+
parameters: {
|
|
27
|
+
testCycleKey: "PROJ-TR-101",
|
|
28
|
+
testCaseKey: "PROJ-TC-42",
|
|
29
|
+
testStepSeqNo: 2
|
|
30
|
+
},
|
|
31
|
+
expectedOutput: "Bugs linked to step 2 of the execution"
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
description: "Filter by priority",
|
|
35
|
+
parameters: {
|
|
36
|
+
testCycleKey: "PROJ-TR-101",
|
|
37
|
+
testCaseKey: "PROJ-TC-42",
|
|
38
|
+
testStepSeqNo: 1,
|
|
39
|
+
filter: { priority: ["High"] }
|
|
40
|
+
},
|
|
41
|
+
expectedOutput: "High-priority bugs linked to step 1"
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
description: "Filter by status",
|
|
45
|
+
parameters: {
|
|
46
|
+
testCycleKey: "PROJ-TR-101",
|
|
47
|
+
testCaseKey: "PROJ-TC-42",
|
|
48
|
+
testStepSeqNo: 1,
|
|
49
|
+
filter: { status: ["In Progress"] }
|
|
50
|
+
},
|
|
51
|
+
expectedOutput: "In Progress bugs linked to step 1"
|
|
52
|
+
}
|
|
53
|
+
],
|
|
54
|
+
hints: [
|
|
55
|
+
"Call set_project_context before this tool.",
|
|
56
|
+
"An empty result (total = 0) means no bugs are linked — it is not an error.",
|
|
57
|
+
"priority and status names are resolved to numeric IDs; unresolved names are skipped with a warning.",
|
|
58
|
+
"Use get_linked_bugs_of_test_case_execution to retrieve all bugs on the test case execution across all steps."
|
|
59
|
+
],
|
|
60
|
+
outputDescription: "JSON object with startAt, maxResults, total, and data array of linked bug objects. Each bug has: id, key, summary, status, priority, issueType, level, stepSeqNo, parameterGroup."
|
|
61
|
+
};
|
|
62
|
+
handle = async (rawArgs) => {
|
|
63
|
+
const args = GetTestStepBugsBody.parse(rawArgs);
|
|
64
|
+
const fieldResolver = this.client.getResolverRegistry();
|
|
65
|
+
const context = fieldResolver.requireProjectContext();
|
|
66
|
+
const warnings = [];
|
|
67
|
+
const testStepExecutionId = await this.resolveTestStepExecutionId(
|
|
68
|
+
fieldResolver,
|
|
69
|
+
context,
|
|
70
|
+
args.testCycleKey,
|
|
71
|
+
args.testCaseKey,
|
|
72
|
+
args.testStepSeqNo
|
|
73
|
+
);
|
|
74
|
+
if (args.filter) {
|
|
75
|
+
await Promise.all(
|
|
76
|
+
Object.entries(FILTER_FIELD_CONFIG).map(
|
|
77
|
+
([inputField, resolverKey]) => fieldResolver.getResolver(resolverKey).resolve(
|
|
78
|
+
inputField,
|
|
79
|
+
resolverKey,
|
|
80
|
+
args.filter,
|
|
81
|
+
context,
|
|
82
|
+
warnings
|
|
83
|
+
)
|
|
84
|
+
)
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
const requestBody = args.filter ? { filter: args.filter } : {};
|
|
88
|
+
const params = new URLSearchParams();
|
|
89
|
+
params.set("startAt", String(args.startAt));
|
|
90
|
+
params.set("maxResults", String(args.maxResults));
|
|
91
|
+
const endpoint = `${ENDPOINTS.GET_LINKED_BUGS_TEST_STEP_EXECUTION(
|
|
92
|
+
args.testCycleKey,
|
|
93
|
+
testStepExecutionId
|
|
94
|
+
)}?${params.toString()}`;
|
|
95
|
+
const response = await this.client.getApiClient().post(endpoint, requestBody);
|
|
96
|
+
const validated = GetBugsResponse.parse(response);
|
|
97
|
+
return {
|
|
98
|
+
structuredContent: validated,
|
|
99
|
+
content: warnings.length > 0 ? [{ type: "text", text: `Note: ${warnings.join(" | ")}` }] : []
|
|
100
|
+
};
|
|
101
|
+
};
|
|
102
|
+
async resolveTestStepExecutionId(fieldResolver, context, testCycleKey, testCaseKey, testStepSeqNo) {
|
|
103
|
+
const stepCtxResult = await fieldResolver.getResolver(ResolverKeys.SearchableField.STEP_EXECUTION_CONTEXT).resolveAndReturn(
|
|
104
|
+
context.projectKey,
|
|
105
|
+
context.projectId,
|
|
106
|
+
testCycleKey,
|
|
107
|
+
testCaseKey,
|
|
108
|
+
[testStepSeqNo]
|
|
109
|
+
);
|
|
110
|
+
const stepMap = stepCtxResult[testCaseKey] ?? {};
|
|
111
|
+
const testStepExecutionId = stepMap[testStepSeqNo];
|
|
112
|
+
if (testStepExecutionId == null) {
|
|
113
|
+
throw new ToolError(
|
|
114
|
+
`Step ${testStepSeqNo} was not found in this execution.`
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
return testStepExecutionId;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
export {
|
|
121
|
+
GetTestStepBugs
|
|
122
|
+
};
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { Tool, ToolError } from "../../../common/tools.js";
|
|
2
|
+
import { TOOL_NAMES, TOOLSETS, ENDPOINTS } from "../../config/constants.js";
|
|
3
|
+
import { ResolverKeys } from "../../config/field-resolution.types.js";
|
|
4
|
+
import { LinkBugsResponse, LinkTestCaseBugsBody } from "../../schema/link-bugs.schema.js";
|
|
5
|
+
const FIELD_CONFIG = {
|
|
6
|
+
defectIDs: ResolverKeys.SearchableField.DEFECT_KEY_TO_ID
|
|
7
|
+
};
|
|
8
|
+
class LinkTestCaseBugs extends Tool {
|
|
9
|
+
specification = {
|
|
10
|
+
title: TOOL_NAMES.LINK_BUGS_TO_TEST_CASE_EXECUTION.TITLE,
|
|
11
|
+
toolset: TOOLSETS.TEST_EXECUTIONS,
|
|
12
|
+
summary: TOOL_NAMES.LINK_BUGS_TO_TEST_CASE_EXECUTION.SUMMARY,
|
|
13
|
+
readOnly: false,
|
|
14
|
+
idempotent: false,
|
|
15
|
+
inputSchema: LinkTestCaseBugsBody,
|
|
16
|
+
outputSchema: LinkBugsResponse,
|
|
17
|
+
purpose: "Link Jira bugs to a test case execution.",
|
|
18
|
+
useCases: [
|
|
19
|
+
"Link one or more Jira bugs to a test case execution in a single request, supporting both single and bulk linking operations."
|
|
20
|
+
],
|
|
21
|
+
examples: [
|
|
22
|
+
{
|
|
23
|
+
description: "Link two bugs to a test case execution",
|
|
24
|
+
parameters: {
|
|
25
|
+
testCycleKey: "PROJ-TR-101",
|
|
26
|
+
testCaseKey: "PROJ-TC-42",
|
|
27
|
+
defectIDs: ["PROJ-456", "PROJ-789"]
|
|
28
|
+
},
|
|
29
|
+
expectedOutput: "{ testCycleKey: 'PROJ-TR-101', testCaseKey: 'PROJ-TC-42', linked: true, linkedDefectCount: 2 }"
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
description: "Link a bug and suppress defect count in response",
|
|
33
|
+
parameters: {
|
|
34
|
+
testCycleKey: "PROJ-TR-101",
|
|
35
|
+
testCaseKey: "PROJ-TC-42",
|
|
36
|
+
defectIDs: ["PROJ-456"],
|
|
37
|
+
returnLinkedDefectCount: false
|
|
38
|
+
},
|
|
39
|
+
expectedOutput: "{ testCycleKey: 'PROJ-TR-101', testCaseKey: 'PROJ-TC-42', linked: true }"
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
description: "Link bugs using a JQL filter",
|
|
43
|
+
parameters: {
|
|
44
|
+
testCycleKey: "PROJ-TR-101",
|
|
45
|
+
testCaseKey: "PROJ-TC-42",
|
|
46
|
+
filter: {
|
|
47
|
+
jql: "project = PROJ AND issuetype = Bug AND status = 'To Do'"
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
expectedOutput: "{ testCycleKey: 'PROJ-TR-101', testCaseKey: 'PROJ-TC-42', linked: true, linkedDefectCount: 5 }"
|
|
51
|
+
}
|
|
52
|
+
],
|
|
53
|
+
hints: [
|
|
54
|
+
"Call set_project_context before this tool.",
|
|
55
|
+
"An execution must already be started for the test case before bugs can be linked.",
|
|
56
|
+
"If the user provides a JQL expression, pass it as the `filter.jql` field. Correct or normalize JQL before calling this tool if needed — the handler passes it through unchanged."
|
|
57
|
+
],
|
|
58
|
+
outputDescription: "Confirmation object with testCycleKey, testCaseKey, linked: true, and linkedDefectCount (by default). warningMessages is included when the server reports per-bug issues."
|
|
59
|
+
};
|
|
60
|
+
handle = async (rawArgs) => {
|
|
61
|
+
const args = LinkTestCaseBugsBody.parse(rawArgs);
|
|
62
|
+
const fieldResolver = this.client.getResolverRegistry();
|
|
63
|
+
const context = fieldResolver.requireProjectContext();
|
|
64
|
+
const testCaseExecutionId = await this.resolveTestCaseExecutionId(
|
|
65
|
+
fieldResolver,
|
|
66
|
+
context,
|
|
67
|
+
args.testCycleKey,
|
|
68
|
+
args.testCaseKey
|
|
69
|
+
);
|
|
70
|
+
const endpoint = ENDPOINTS.LINK_BUGS_TEST_CASE_EXECUTION(
|
|
71
|
+
args.testCycleKey,
|
|
72
|
+
testCaseExecutionId,
|
|
73
|
+
args.returnLinkedDefectCount
|
|
74
|
+
);
|
|
75
|
+
const {
|
|
76
|
+
testCycleKey: _tc,
|
|
77
|
+
testCaseKey: _tck,
|
|
78
|
+
returnLinkedDefectCount: _rc,
|
|
79
|
+
...bodyArgs
|
|
80
|
+
} = args;
|
|
81
|
+
const body = { ...bodyArgs };
|
|
82
|
+
const warnings = [];
|
|
83
|
+
await Promise.all(
|
|
84
|
+
Object.entries(FIELD_CONFIG).map(
|
|
85
|
+
([inputField, resolverKey]) => fieldResolver.getResolver(resolverKey).resolve(inputField, resolverKey, body, context, warnings)
|
|
86
|
+
)
|
|
87
|
+
);
|
|
88
|
+
const hasDefectIDs = Array.isArray(body.defectIDs) && body.defectIDs.length > 0;
|
|
89
|
+
const hasJql = typeof body.filter?.jql === "string";
|
|
90
|
+
if (!hasDefectIDs && !hasJql) {
|
|
91
|
+
throw new ToolError(
|
|
92
|
+
`No bugs to link after resolution. ${warnings.join(" | ")}`
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
let apiResponse = {};
|
|
96
|
+
const resp = await this.client.getApiClient().put(endpoint, body);
|
|
97
|
+
if (resp && typeof resp === "object") {
|
|
98
|
+
apiResponse = resp;
|
|
99
|
+
}
|
|
100
|
+
const validated = LinkBugsResponse.parse({
|
|
101
|
+
testCycleKey: args.testCycleKey,
|
|
102
|
+
testCaseKey: args.testCaseKey,
|
|
103
|
+
linked: true,
|
|
104
|
+
...apiResponse.linkedDefectCount !== void 0 ? { linkedDefectCount: apiResponse.linkedDefectCount } : {},
|
|
105
|
+
...apiResponse.warningMessages?.length ? { warningMessages: apiResponse.warningMessages } : {}
|
|
106
|
+
});
|
|
107
|
+
if (apiResponse.warningMessages?.length) {
|
|
108
|
+
warnings.push(`API: ${apiResponse.warningMessages.join(" | ")}`);
|
|
109
|
+
}
|
|
110
|
+
return {
|
|
111
|
+
structuredContent: validated,
|
|
112
|
+
content: warnings.length > 0 ? [{ type: "text", text: `Note: ${warnings.join(" | ")}` }] : []
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
async resolveTestCaseExecutionId(fieldResolver, context, testCycleKey, testCaseKey) {
|
|
116
|
+
const result = await fieldResolver.getResolver(ResolverKeys.SearchableField.EXECUTION_CONTEXT).resolveAndReturn(context.projectKey, context.projectId, testCycleKey, [
|
|
117
|
+
testCaseKey
|
|
118
|
+
]);
|
|
119
|
+
const entry = result[testCaseKey];
|
|
120
|
+
if (!entry) {
|
|
121
|
+
throw new ToolError(
|
|
122
|
+
`Test case '${testCaseKey}' is not linked to test cycle '${testCycleKey}'. Verify the key and ensure it belongs to the cycle.`
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
if (entry.testCaseExecutionId == null) {
|
|
126
|
+
throw new ToolError(
|
|
127
|
+
`No execution has been started for test case '${testCaseKey}' in cycle '${testCycleKey}'. Use start_new_execution first.`
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
return entry.testCaseExecutionId;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
export {
|
|
134
|
+
LinkTestCaseBugs
|
|
135
|
+
};
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { Tool, ToolError } from "../../../common/tools.js";
|
|
2
|
+
import { TOOL_NAMES, TOOLSETS, ENDPOINTS } from "../../config/constants.js";
|
|
3
|
+
import { ResolverKeys } from "../../config/field-resolution.types.js";
|
|
4
|
+
import { LinkBugsResponse, LinkTestStepBugsBody } from "../../schema/link-bugs.schema.js";
|
|
5
|
+
const FIELD_CONFIG = {
|
|
6
|
+
defectIDs: ResolverKeys.SearchableField.DEFECT_KEY_TO_ID
|
|
7
|
+
};
|
|
8
|
+
class LinkTestStepBugs extends Tool {
|
|
9
|
+
specification = {
|
|
10
|
+
title: TOOL_NAMES.LINK_BUGS_TO_TEST_STEP_EXECUTION.TITLE,
|
|
11
|
+
toolset: TOOLSETS.TEST_EXECUTIONS,
|
|
12
|
+
summary: TOOL_NAMES.LINK_BUGS_TO_TEST_STEP_EXECUTION.SUMMARY,
|
|
13
|
+
readOnly: false,
|
|
14
|
+
idempotent: false,
|
|
15
|
+
inputSchema: LinkTestStepBugsBody,
|
|
16
|
+
outputSchema: LinkBugsResponse,
|
|
17
|
+
purpose: "Link Jira bugs to a specific test step execution.",
|
|
18
|
+
useCases: [
|
|
19
|
+
"Link one or more Jira bugs to a specific test step execution in a single request, supporting both single and bulk linking operations."
|
|
20
|
+
],
|
|
21
|
+
examples: [
|
|
22
|
+
{
|
|
23
|
+
description: "Link a bug to step 2 of a test case execution",
|
|
24
|
+
parameters: {
|
|
25
|
+
testCycleKey: "PROJ-TR-101",
|
|
26
|
+
testCaseKey: "PROJ-TC-42",
|
|
27
|
+
testStepSeqNo: 2,
|
|
28
|
+
defectIDs: ["PROJ-456"]
|
|
29
|
+
},
|
|
30
|
+
expectedOutput: "{ testCycleKey: 'PROJ-TR-101', testCaseKey: 'PROJ-TC-42', linked: true, linkedDefectCount: 1 }"
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
description: "Link multiple bugs to step 3 and suppress defect count",
|
|
34
|
+
parameters: {
|
|
35
|
+
testCycleKey: "PROJ-TR-101",
|
|
36
|
+
testCaseKey: "PROJ-TC-42",
|
|
37
|
+
testStepSeqNo: 3,
|
|
38
|
+
defectIDs: ["PROJ-456", "PROJ-789"],
|
|
39
|
+
returnLinkedDefectCount: false
|
|
40
|
+
},
|
|
41
|
+
expectedOutput: "{ testCycleKey: 'PROJ-TR-101', testCaseKey: 'PROJ-TC-42', linked: true }"
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
description: "Link bugs to a step using a JQL filter",
|
|
45
|
+
parameters: {
|
|
46
|
+
testCycleKey: "PROJ-TR-101",
|
|
47
|
+
testCaseKey: "PROJ-TC-42",
|
|
48
|
+
testStepSeqNo: 1,
|
|
49
|
+
filter: {
|
|
50
|
+
jql: "project = PROJ AND status = Open"
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
expectedOutput: "{ testCycleKey: 'PROJ-TR-101', testCaseKey: 'PROJ-TC-42', linked: true, linkedDefectCount: 2 }"
|
|
54
|
+
}
|
|
55
|
+
],
|
|
56
|
+
hints: [
|
|
57
|
+
"Call set_project_context before this tool.",
|
|
58
|
+
"An execution must already be started for the test case before bugs can be linked.",
|
|
59
|
+
"If the user provides a JQL expression, pass it as the `filter.jql` field. Correct or normalize JQL before calling if needed — the handler passes it through unchanged."
|
|
60
|
+
],
|
|
61
|
+
outputDescription: "Confirmation object with testCycleKey, testCaseKey, linked: true, and linkedDefectCount (by default). warningMessages is included when the server reports per-bug issues."
|
|
62
|
+
};
|
|
63
|
+
handle = async (rawArgs) => {
|
|
64
|
+
const args = LinkTestStepBugsBody.parse(rawArgs);
|
|
65
|
+
const fieldResolver = this.client.getResolverRegistry();
|
|
66
|
+
const context = fieldResolver.requireProjectContext();
|
|
67
|
+
const testStepExecutionId = await this.resolveTestStepExecutionId(
|
|
68
|
+
fieldResolver,
|
|
69
|
+
context,
|
|
70
|
+
args.testCycleKey,
|
|
71
|
+
args.testCaseKey,
|
|
72
|
+
args.testStepSeqNo
|
|
73
|
+
);
|
|
74
|
+
const endpoint = ENDPOINTS.LINK_BUGS_TEST_STEP_EXECUTION(
|
|
75
|
+
args.testCycleKey,
|
|
76
|
+
testStepExecutionId,
|
|
77
|
+
args.returnLinkedDefectCount
|
|
78
|
+
);
|
|
79
|
+
const {
|
|
80
|
+
testCycleKey: _tc,
|
|
81
|
+
testCaseKey: _tck,
|
|
82
|
+
testStepSeqNo: _sn,
|
|
83
|
+
returnLinkedDefectCount: _rc,
|
|
84
|
+
...bodyArgs
|
|
85
|
+
} = args;
|
|
86
|
+
const body = { ...bodyArgs };
|
|
87
|
+
const warnings = [];
|
|
88
|
+
await Promise.all(
|
|
89
|
+
Object.entries(FIELD_CONFIG).map(
|
|
90
|
+
([inputField, resolverKey]) => fieldResolver.getResolver(resolverKey).resolve(inputField, resolverKey, body, context, warnings)
|
|
91
|
+
)
|
|
92
|
+
);
|
|
93
|
+
const hasDefectIDs = Array.isArray(body.defectIDs) && body.defectIDs.length > 0;
|
|
94
|
+
const hasJql = typeof body.filter?.jql === "string";
|
|
95
|
+
if (!hasDefectIDs && !hasJql) {
|
|
96
|
+
throw new ToolError(
|
|
97
|
+
`No bugs to link after resolution. ${warnings.join(" | ")}`
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
let apiResponse = {};
|
|
101
|
+
const resp = await this.client.getApiClient().put(endpoint, body);
|
|
102
|
+
if (resp && typeof resp === "object") {
|
|
103
|
+
apiResponse = resp;
|
|
104
|
+
}
|
|
105
|
+
const validated = LinkBugsResponse.parse({
|
|
106
|
+
testCycleKey: args.testCycleKey,
|
|
107
|
+
testCaseKey: args.testCaseKey,
|
|
108
|
+
linked: true,
|
|
109
|
+
...apiResponse.linkedDefectCount !== void 0 ? { linkedDefectCount: apiResponse.linkedDefectCount } : {},
|
|
110
|
+
...apiResponse.warningMessages?.length ? { warningMessages: apiResponse.warningMessages } : {}
|
|
111
|
+
});
|
|
112
|
+
if (apiResponse.warningMessages?.length) {
|
|
113
|
+
warnings.push(`API: ${apiResponse.warningMessages.join(" | ")}`);
|
|
114
|
+
}
|
|
115
|
+
return {
|
|
116
|
+
structuredContent: validated,
|
|
117
|
+
content: warnings.length > 0 ? [{ type: "text", text: `Note: ${warnings.join(" | ")}` }] : []
|
|
118
|
+
};
|
|
119
|
+
};
|
|
120
|
+
async resolveTestStepExecutionId(fieldResolver, context, testCycleKey, testCaseKey, testStepSeqNo) {
|
|
121
|
+
const stepCtxResult = await fieldResolver.getResolver(ResolverKeys.SearchableField.STEP_EXECUTION_CONTEXT).resolveAndReturn(
|
|
122
|
+
context.projectKey,
|
|
123
|
+
context.projectId,
|
|
124
|
+
testCycleKey,
|
|
125
|
+
testCaseKey,
|
|
126
|
+
[testStepSeqNo]
|
|
127
|
+
);
|
|
128
|
+
const stepMap = stepCtxResult[testCaseKey] ?? {};
|
|
129
|
+
const testStepExecutionId = stepMap[testStepSeqNo];
|
|
130
|
+
if (testStepExecutionId == null) {
|
|
131
|
+
throw new ToolError(
|
|
132
|
+
`Step ${testStepSeqNo} was not found in this execution.`
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
return testStepExecutionId;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
export {
|
|
139
|
+
LinkTestStepBugs
|
|
140
|
+
};
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { Tool, ToolError } from "../../../common/tools.js";
|
|
2
|
+
import { TOOL_NAMES, TOOLSETS, ENDPOINTS } from "../../config/constants.js";
|
|
3
|
+
import { ResolverKeys } from "../../config/field-resolution.types.js";
|
|
4
|
+
import { StartExecutionResponse, StartExecutionBody } from "../../schema/start-execution.schema.js";
|
|
5
|
+
const FIELD_CONFIG = {
|
|
6
|
+
environmentId: ResolverKeys.SearchableField.ENVIRONMENT,
|
|
7
|
+
buildId: ResolverKeys.SearchableField.BUILD
|
|
8
|
+
};
|
|
9
|
+
class StartExecution extends Tool {
|
|
10
|
+
specification = {
|
|
11
|
+
title: TOOL_NAMES.START_NEW_EXECUTION.TITLE,
|
|
12
|
+
toolset: TOOLSETS.TEST_EXECUTIONS,
|
|
13
|
+
summary: TOOL_NAMES.START_NEW_EXECUTION.SUMMARY,
|
|
14
|
+
readOnly: false,
|
|
15
|
+
idempotent: false,
|
|
16
|
+
inputSchema: StartExecutionBody,
|
|
17
|
+
outputSchema: StartExecutionResponse,
|
|
18
|
+
purpose: "Start a new test case execution within a test cycle.",
|
|
19
|
+
useCases: [
|
|
20
|
+
"Start a fresh execution for a test case in a test cycle",
|
|
21
|
+
"Clone an existing execution"
|
|
22
|
+
],
|
|
23
|
+
examples: [
|
|
24
|
+
{
|
|
25
|
+
description: "Start an execution for a test case (minimal)",
|
|
26
|
+
parameters: {
|
|
27
|
+
testCycleKey: "PROJ-TR-101",
|
|
28
|
+
testCaseKey: "PROJ-TC-42"
|
|
29
|
+
},
|
|
30
|
+
expectedOutput: "{ testCycleKey: 'PROJ-TR-101', testCaseKey: 'PROJ-TC-42', created: true }"
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
description: "Start execution with environment, build and planned date",
|
|
34
|
+
parameters: {
|
|
35
|
+
testCycleKey: "PROJ-TR-101",
|
|
36
|
+
testCaseKey: "PROJ-TC-42",
|
|
37
|
+
environmentId: "Production",
|
|
38
|
+
buildId: "Build 2.0",
|
|
39
|
+
executionPlannedDate: "15/Oct/2025",
|
|
40
|
+
assignee: "5e4a642c1c9d440008f2a2b4"
|
|
41
|
+
},
|
|
42
|
+
expectedOutput: "{ testCycleKey: 'PROJ-TR-101', testCaseKey: 'PROJ-TC-42', created: true }"
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
description: "Clone an existing execution",
|
|
46
|
+
parameters: {
|
|
47
|
+
testCycleKey: "PROJ-TR-101",
|
|
48
|
+
testCaseKey: "PROJ-TC-42",
|
|
49
|
+
cloneFrom: 725981
|
|
50
|
+
},
|
|
51
|
+
expectedOutput: "{ testCycleKey: 'PROJ-TR-101', testCaseKey: 'PROJ-TC-42', created: true }"
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
description: "Start a fresh execution and carry over custom field values from the previous execution",
|
|
55
|
+
parameters: {
|
|
56
|
+
testCycleKey: "PROJ-TR-101",
|
|
57
|
+
testCaseKey: "PROJ-TC-42",
|
|
58
|
+
cloneExecutionCustomFields: true
|
|
59
|
+
},
|
|
60
|
+
expectedOutput: "{ testCycleKey: 'PROJ-TR-101', testCaseKey: 'PROJ-TC-42', created: true }"
|
|
61
|
+
}
|
|
62
|
+
],
|
|
63
|
+
hints: [
|
|
64
|
+
"Call set_project_context before this tool.",
|
|
65
|
+
"executionPlannedDate must be in 'dd/MMM/yyyy' format (e.g. '15/Oct/2025', month 3-letter capitalised). Normalize from any user-provided format before calling.",
|
|
66
|
+
"When cloneFrom is non-zero, the server ignores all body fields.",
|
|
67
|
+
"assignee must be a Jira account ID (e.g. '5e4a642c1c9d440008f2a2b4'), not a display name.",
|
|
68
|
+
"environmentId and buildId accept name as strings that are resolved to numeric IDs; unresolved names are dropped and a warning is returned.",
|
|
69
|
+
"actualTime must be in 'HH:mm:ss' format (e.g. '02:30:00'). Always include seconds."
|
|
70
|
+
],
|
|
71
|
+
outputDescription: "Confirmation object with testCycleKey, testCaseKey, and created: true (set when server returns 204)."
|
|
72
|
+
};
|
|
73
|
+
handle = async (rawArgs) => {
|
|
74
|
+
const args = StartExecutionBody.parse(rawArgs);
|
|
75
|
+
const fieldResolver = this.client.getResolverRegistry();
|
|
76
|
+
const context = fieldResolver.requireProjectContext();
|
|
77
|
+
const warnings = [];
|
|
78
|
+
const mapId = await this.resolveTestCycleTestCaseMapId(
|
|
79
|
+
fieldResolver,
|
|
80
|
+
context,
|
|
81
|
+
args.testCycleKey,
|
|
82
|
+
args.testCaseKey
|
|
83
|
+
);
|
|
84
|
+
const body = await this.buildRequestBody(
|
|
85
|
+
args,
|
|
86
|
+
fieldResolver,
|
|
87
|
+
context,
|
|
88
|
+
warnings
|
|
89
|
+
);
|
|
90
|
+
const endpoint = this.buildEndpoint(
|
|
91
|
+
args.testCycleKey,
|
|
92
|
+
mapId,
|
|
93
|
+
args.cloneFrom
|
|
94
|
+
);
|
|
95
|
+
await this.client.getApiClient().post(endpoint, body);
|
|
96
|
+
fieldResolver.getResolver(
|
|
97
|
+
ResolverKeys.SearchableField.EXECUTION_CONTEXT
|
|
98
|
+
).clearCache(context.projectKey);
|
|
99
|
+
fieldResolver.getResolver(
|
|
100
|
+
ResolverKeys.SearchableField.STEP_EXECUTION_CONTEXT
|
|
101
|
+
).clearCache(context.projectKey);
|
|
102
|
+
const validated = StartExecutionResponse.parse({
|
|
103
|
+
testCycleKey: args.testCycleKey,
|
|
104
|
+
testCaseKey: args.testCaseKey,
|
|
105
|
+
created: true
|
|
106
|
+
});
|
|
107
|
+
return {
|
|
108
|
+
structuredContent: validated,
|
|
109
|
+
content: warnings.length > 0 ? [{ type: "text", text: `Note: ${warnings.join(" | ")}` }] : []
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
async resolveTestCycleTestCaseMapId(fieldResolver, context, testCycleKey, testCaseKey) {
|
|
113
|
+
const result = await fieldResolver.getResolver(ResolverKeys.SearchableField.EXECUTION_CONTEXT).resolveAndReturn(context.projectKey, context.projectId, testCycleKey, [
|
|
114
|
+
testCaseKey
|
|
115
|
+
]);
|
|
116
|
+
const entry = result[testCaseKey];
|
|
117
|
+
if (!entry) {
|
|
118
|
+
throw new ToolError(
|
|
119
|
+
`Test case '${testCaseKey}' is not linked to test cycle '${testCycleKey}'. Verify the key and ensure it belongs to the cycle.`
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
return entry.testCycleTestCaseMapId;
|
|
123
|
+
}
|
|
124
|
+
async buildRequestBody(args, fieldResolver, context, warnings) {
|
|
125
|
+
if (args.cloneFrom !== void 0 && args.cloneFrom > 0) return {};
|
|
126
|
+
const {
|
|
127
|
+
testCycleKey: _tc,
|
|
128
|
+
testCaseKey: _tck,
|
|
129
|
+
cloneFrom: _cf,
|
|
130
|
+
...bodyArgs
|
|
131
|
+
} = args;
|
|
132
|
+
const body = { ...bodyArgs };
|
|
133
|
+
await Promise.all(
|
|
134
|
+
Object.entries(FIELD_CONFIG).map(
|
|
135
|
+
([inputField, resolverKey]) => fieldResolver.getResolver(resolverKey).resolve(inputField, resolverKey, body, context, warnings)
|
|
136
|
+
)
|
|
137
|
+
);
|
|
138
|
+
return body;
|
|
139
|
+
}
|
|
140
|
+
buildEndpoint(testCycleKey, testCycleTestCaseMapId, cloneFrom) {
|
|
141
|
+
const params = new URLSearchParams();
|
|
142
|
+
if (cloneFrom !== void 0 && cloneFrom > 0)
|
|
143
|
+
params.set("cloneFrom", String(cloneFrom));
|
|
144
|
+
const query = params.toString();
|
|
145
|
+
return `${ENDPOINTS.START_NEW_EXECUTION(testCycleKey, testCycleTestCaseMapId)}${query ? `?${query}` : ""}`;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
export {
|
|
149
|
+
StartExecution
|
|
150
|
+
};
|