@smartbear/mcp 0.28.0 → 0.30.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/README.md +1 -1
- package/dist/bearq/client.js +5 -3
- package/dist/bearq/tool/environments/list-environments.js +28 -0
- package/dist/bearq/tool/tasks/run-regression-tests.js +10 -3
- package/dist/bearq/tool/tasks/run-test-cases.js +12 -3
- package/dist/bearq/tool/tasks/run-tests-in-functional-areas.js +12 -3
- package/dist/bugsnag/client.js +2 -2
- package/dist/collaborator/client.js +5 -2
- package/dist/common/client-identity.js +20 -0
- package/dist/common/info.js +21 -1
- package/dist/common/initialize.js +7 -0
- package/dist/common/request-context.js +7 -0
- package/dist/common/server.js +37 -1
- package/dist/common/transport-http.js +13 -13
- package/dist/package.json.js +1 -1
- package/dist/pactflow/client/tools.js +408 -0
- package/dist/pactflow/client.js +5 -12
- package/dist/qmetry/client/api/client-api.js +2 -2
- package/dist/qmetry/client/automation.js +2 -2
- package/dist/qtm4j/http/auth-service.js +2 -2
- package/dist/reflect/client.js +7 -3
- package/dist/reflect/tool/tests/create-segment.js +18 -0
- package/dist/reflect/tool/tests/create-test.js +18 -0
- package/dist/reflect/tool/tests/definition.js +190 -0
- package/dist/swagger/client/api.js +2 -1
- package/dist/swagger/client/functional-testing-api.js +193 -42
- package/dist/swagger/client/functional-testing-tools.js +50 -2
- package/dist/swagger/client/functional-testing-types.js +27 -0
- package/dist/swagger/client/portal-types.js +144 -10
- package/dist/swagger/client/registry-types.js +60 -1
- package/dist/swagger/client/tool-constants.js +20 -0
- package/dist/swagger/client/tools.js +87 -29
- package/dist/swagger/client/user-management-types.js +14 -0
- package/dist/swagger/client.js +24 -2
- package/dist/zephyr/common/auth-service.js +2 -2
- package/dist/zephyr/common/rest-api-schemas.js +1 -1
- package/package.json +3 -1
package/dist/pactflow/client.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import zod__default from "zod";
|
|
2
|
-
import {
|
|
2
|
+
import { getUserAgent } from "../common/info.js";
|
|
3
3
|
import { isSamplingPolyfillResult } from "../common/pollyfills.js";
|
|
4
4
|
import { getRequestHeader } from "../common/request-context.js";
|
|
5
5
|
import { ToolError } from "../common/tools.js";
|
|
@@ -170,10 +170,6 @@ class PactflowClient {
|
|
|
170
170
|
if (Array.isArray(contextToken)) {
|
|
171
171
|
contextToken = contextToken[0];
|
|
172
172
|
}
|
|
173
|
-
const clientInfo = this._server?.getClientInfo();
|
|
174
|
-
const sourceApplicationHeader = {
|
|
175
|
-
SOURCE_APPLICATION: clientInfo ? `${clientInfo.name}/${clientInfo.version}` : "unknown"
|
|
176
|
-
};
|
|
177
173
|
if (contextToken) {
|
|
178
174
|
let authHeader = contextToken;
|
|
179
175
|
if (!contextToken.startsWith("Basic ") && !contextToken.startsWith("Bearer ")) {
|
|
@@ -182,8 +178,7 @@ class PactflowClient {
|
|
|
182
178
|
return {
|
|
183
179
|
Authorization: authHeader,
|
|
184
180
|
"Content-Type": "application/json",
|
|
185
|
-
"User-Agent":
|
|
186
|
-
...sourceApplicationHeader
|
|
181
|
+
"User-Agent": getUserAgent()
|
|
187
182
|
};
|
|
188
183
|
}
|
|
189
184
|
if (this.token) {
|
|
@@ -194,16 +189,14 @@ class PactflowClient {
|
|
|
194
189
|
return {
|
|
195
190
|
Authorization: authHeader,
|
|
196
191
|
"Content-Type": "application/json",
|
|
197
|
-
"User-Agent":
|
|
198
|
-
...sourceApplicationHeader
|
|
192
|
+
"User-Agent": getUserAgent()
|
|
199
193
|
};
|
|
200
194
|
} else if (this.username && this.password) {
|
|
201
195
|
const authString = `${this.username}:${this.password}`;
|
|
202
196
|
return {
|
|
203
197
|
Authorization: `Basic ${Buffer.from(authString).toString("base64")}`,
|
|
204
198
|
"Content-Type": "application/json",
|
|
205
|
-
"User-Agent":
|
|
206
|
-
...sourceApplicationHeader
|
|
199
|
+
"User-Agent": getUserAgent()
|
|
207
200
|
};
|
|
208
201
|
}
|
|
209
202
|
return void 0;
|
|
@@ -1884,7 +1877,7 @@ class PactflowClient {
|
|
|
1884
1877
|
`${this.baseUrl}/admin/teams/${encodeURIComponent(teamId)}/users`,
|
|
1885
1878
|
{
|
|
1886
1879
|
method: "PUT",
|
|
1887
|
-
body: { uuids },
|
|
1880
|
+
body: { users: uuids },
|
|
1888
1881
|
errorContext: "Set Team Users"
|
|
1889
1882
|
}
|
|
1890
1883
|
);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getUserAgent } from "../../../common/info.js";
|
|
2
2
|
import { QMETRY_DEFAULTS } from "../../config/constants.js";
|
|
3
3
|
import { handleQMetryFetchError, handleQMetryApiError } from "./error-handler.js";
|
|
4
4
|
async function qmetryRequest({
|
|
@@ -16,7 +16,7 @@ async function qmetryRequest({
|
|
|
16
16
|
const headers = {
|
|
17
17
|
apikey: token,
|
|
18
18
|
project: project || QMETRY_DEFAULTS.PROJECT_KEY,
|
|
19
|
-
"User-Agent":
|
|
19
|
+
"User-Agent": getUserAgent(),
|
|
20
20
|
"qmetry-source": "smartbear-mcp"
|
|
21
21
|
};
|
|
22
22
|
if (scopeId !== void 0) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getUserAgent } from "../../common/info.js";
|
|
2
2
|
import { QMETRY_DEFAULTS } from "../config/constants.js";
|
|
3
3
|
import { QMETRY_PATHS } from "../config/rest-endpoints.js";
|
|
4
4
|
import { DEFAULT_IMPORT_AUTOMATION_PAYLOAD } from "../types/automation.js";
|
|
@@ -91,7 +91,7 @@ async function importAutomationResults(token, baseUrl, project, payload) {
|
|
|
91
91
|
const headers = {
|
|
92
92
|
apikey: token,
|
|
93
93
|
project: finalPayload.projectID || project || QMETRY_DEFAULTS.PROJECT_KEY,
|
|
94
|
-
"User-Agent":
|
|
94
|
+
"User-Agent": getUserAgent(),
|
|
95
95
|
"qmetry-source": "smartbear-mcp"
|
|
96
96
|
// Note: Content-Type will be set automatically by fetch for FormData
|
|
97
97
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getUserAgent } from "../../common/info.js";
|
|
2
2
|
import { CONTENT_TYPES, HTTP_HEADERS } from "../config/constants.js";
|
|
3
3
|
class AuthService {
|
|
4
4
|
apiKey;
|
|
@@ -13,7 +13,7 @@ class AuthService {
|
|
|
13
13
|
return {
|
|
14
14
|
[HTTP_HEADERS.API_KEY]: this.apiKey,
|
|
15
15
|
[HTTP_HEADERS.CONTENT_TYPE]: CONTENT_TYPES.JSON,
|
|
16
|
-
[HTTP_HEADERS.USER_AGENT]:
|
|
16
|
+
[HTTP_HEADERS.USER_AGENT]: getUserAgent(),
|
|
17
17
|
[HTTP_HEADERS.ACCEPT]: CONTENT_TYPES.JSON
|
|
18
18
|
};
|
|
19
19
|
}
|
package/dist/reflect/client.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import {
|
|
2
|
+
import { getUserAgent } from "../common/info.js";
|
|
3
3
|
import { getRequestHeader } from "../common/request-context.js";
|
|
4
4
|
import { ToolError } from "../common/tools.js";
|
|
5
5
|
import { API_KEY_HEADER, REFLECT_API_TOKEN_HEADER, AUTHORIZATION_HEADER } from "./config/constants.js";
|
|
@@ -14,6 +14,8 @@ import { ExecuteSuite } from "./tool/suites/execute-suite.js";
|
|
|
14
14
|
import { GetSuiteExecutionStatus } from "./tool/suites/get-suite-execution-status.js";
|
|
15
15
|
import { ListSuiteExecutions } from "./tool/suites/list-suite-executions.js";
|
|
16
16
|
import { ListSuites } from "./tool/suites/list-suites.js";
|
|
17
|
+
import { CreateSegment } from "./tool/tests/create-segment.js";
|
|
18
|
+
import { CreateTest } from "./tool/tests/create-test.js";
|
|
17
19
|
import { GetTestDetail } from "./tool/tests/get-test-detail.js";
|
|
18
20
|
import { GetTestStatus } from "./tool/tests/get-test-status.js";
|
|
19
21
|
import { ListSegments } from "./tool/tests/list-segments.js";
|
|
@@ -73,7 +75,7 @@ class ReflectClient {
|
|
|
73
75
|
return {
|
|
74
76
|
...this.getAuthHeader(),
|
|
75
77
|
"Content-Type": "application/json",
|
|
76
|
-
"User-Agent":
|
|
78
|
+
"User-Agent": getUserAgent()
|
|
77
79
|
};
|
|
78
80
|
}
|
|
79
81
|
getSessionState(sessionId) {
|
|
@@ -123,7 +125,9 @@ class ReflectClient {
|
|
|
123
125
|
new ListTests(this),
|
|
124
126
|
new GetTestDetail(this),
|
|
125
127
|
new RunTest(this),
|
|
126
|
-
new GetTestStatus(this)
|
|
128
|
+
new GetTestStatus(this),
|
|
129
|
+
new CreateTest(this),
|
|
130
|
+
new CreateSegment(this)
|
|
127
131
|
];
|
|
128
132
|
const oAuthAndAPISupportedTools = [
|
|
129
133
|
new ListSegments(this),
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Tool } from "../../../common/tools.js";
|
|
2
|
+
import { buildCreateDefinitionSchema, createReflectDefinition } from "./definition.js";
|
|
3
|
+
class CreateSegment extends Tool {
|
|
4
|
+
specification = {
|
|
5
|
+
title: "Create Segment",
|
|
6
|
+
toolset: "Tests",
|
|
7
|
+
summary: "Create a new Reflect segment which contains an ordered list of steps. Segments are reusable groups of steps that can be referenced from tests, and cannot reference other segments.",
|
|
8
|
+
readOnly: false,
|
|
9
|
+
idempotent: false,
|
|
10
|
+
inputSchema: buildCreateDefinitionSchema({ isSegment: true })
|
|
11
|
+
};
|
|
12
|
+
handle = async (args) => {
|
|
13
|
+
return createReflectDefinition(this.client, "segments", "segment", args);
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export {
|
|
17
|
+
CreateSegment
|
|
18
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Tool } from "../../../common/tools.js";
|
|
2
|
+
import { buildCreateDefinitionSchema, createReflectDefinition } from "./definition.js";
|
|
3
|
+
class CreateTest extends Tool {
|
|
4
|
+
specification = {
|
|
5
|
+
title: "Create Test",
|
|
6
|
+
toolset: "Tests",
|
|
7
|
+
summary: "Create a new Reflect test which contains an ordered list of steps.",
|
|
8
|
+
readOnly: false,
|
|
9
|
+
idempotent: false,
|
|
10
|
+
inputSchema: buildCreateDefinitionSchema({ isSegment: false })
|
|
11
|
+
};
|
|
12
|
+
handle = async (args) => {
|
|
13
|
+
return createReflectDefinition(this.client, "tests", "test", args);
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export {
|
|
17
|
+
CreateTest
|
|
18
|
+
};
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { ToolError } from "../../../common/tools.js";
|
|
3
|
+
import { API_HOSTNAME } from "../../config/constants.js";
|
|
4
|
+
const BASE_STEP_TYPES = [
|
|
5
|
+
"click",
|
|
6
|
+
"text-validation",
|
|
7
|
+
"input",
|
|
8
|
+
"submit",
|
|
9
|
+
"scroll",
|
|
10
|
+
"focus",
|
|
11
|
+
"hover",
|
|
12
|
+
"drag-and-drop",
|
|
13
|
+
"text-highlight",
|
|
14
|
+
"browser-navigate",
|
|
15
|
+
"browser-back",
|
|
16
|
+
"browser-forward",
|
|
17
|
+
"browser-refresh",
|
|
18
|
+
"api",
|
|
19
|
+
"javascript",
|
|
20
|
+
"appium",
|
|
21
|
+
"prompt",
|
|
22
|
+
"update-parameters",
|
|
23
|
+
"wait",
|
|
24
|
+
"receive-email",
|
|
25
|
+
"receive-sms",
|
|
26
|
+
"rotate-device",
|
|
27
|
+
"reset-device",
|
|
28
|
+
"deeplink",
|
|
29
|
+
"set-device-location"
|
|
30
|
+
];
|
|
31
|
+
const TEST_STEP_TYPES = ["segment", ...BASE_STEP_TYPES];
|
|
32
|
+
const headerSchema = z.object({
|
|
33
|
+
name: z.string().describe("Header name."),
|
|
34
|
+
value: z.string().describe("Header value.")
|
|
35
|
+
});
|
|
36
|
+
const parameterSchema = z.object({
|
|
37
|
+
name: z.string().describe("Parameter name."),
|
|
38
|
+
value: z.string().optional().describe("Default value for the parameter.")
|
|
39
|
+
});
|
|
40
|
+
const emailFilterSchema = z.object({
|
|
41
|
+
fromAddress: z.string().optional().describe("Only match emails sent from this address."),
|
|
42
|
+
fromName: z.string().optional().describe("Only match emails sent from this sender name."),
|
|
43
|
+
subject: z.string().optional().describe("Only match emails with this subject."),
|
|
44
|
+
toAddress: z.string().optional().describe("Only match emails sent to this address.")
|
|
45
|
+
});
|
|
46
|
+
const emailSchema = z.object({
|
|
47
|
+
text: z.string().optional().describe("Text to extract from, or validate against, the matched email."),
|
|
48
|
+
filters: emailFilterSchema.describe(
|
|
49
|
+
"Filters selecting which inbound email this step waits for."
|
|
50
|
+
)
|
|
51
|
+
});
|
|
52
|
+
const smsFilterSchema = z.object({
|
|
53
|
+
fromNumber: z.string().optional().describe("Only match SMS messages sent from this number."),
|
|
54
|
+
toNumber: z.string().optional().describe("Only match SMS messages sent to this number.")
|
|
55
|
+
});
|
|
56
|
+
const smsSchema = z.object({
|
|
57
|
+
text: z.string().optional().describe("Text to extract from, or validate against, the matched SMS."),
|
|
58
|
+
filters: smsFilterSchema.optional().describe("Filters selecting which inbound SMS this step waits for.")
|
|
59
|
+
});
|
|
60
|
+
function buildStepSchema(stepTypes, { includeSegmentReference }) {
|
|
61
|
+
return z.object({
|
|
62
|
+
type: z.enum(stepTypes).describe(
|
|
63
|
+
"The kind of step to perform. Determines which of the other fields are required."
|
|
64
|
+
),
|
|
65
|
+
description: z.string().optional().describe(
|
|
66
|
+
"Human-readable description of the step. For 'prompt' steps, this field holds the natural-language instruction to execute."
|
|
67
|
+
),
|
|
68
|
+
selector: z.string().optional().describe(
|
|
69
|
+
"CSS selector of the target element. Used by 'click', 'input', 'submit', 'scroll', 'focus', 'hover', 'text-validation', 'text-highlight', and the source element of 'drag-and-drop'."
|
|
70
|
+
),
|
|
71
|
+
tag: z.string().optional().describe("Tag name of the target element (e.g. 'button', 'input')."),
|
|
72
|
+
toSelector: z.string().optional().describe(
|
|
73
|
+
"CSS selector of the destination element for a 'drag-and-drop' step."
|
|
74
|
+
),
|
|
75
|
+
toTag: z.string().optional().describe(
|
|
76
|
+
"Tag name of the destination element for a 'drag-and-drop' step."
|
|
77
|
+
),
|
|
78
|
+
inputText: z.string().optional().describe("Text to type. Used by 'input' steps."),
|
|
79
|
+
url: z.string().optional().describe(
|
|
80
|
+
"Target URL. Required by 'api' steps; used as the navigation URL for 'browser-navigate' and as the deep link for 'deeplink'."
|
|
81
|
+
),
|
|
82
|
+
script: z.string().optional().describe("JavaScript source to execute. Used by 'javascript' steps."),
|
|
83
|
+
command: z.string().optional().describe("Appium command to run. Required by 'appium' steps."),
|
|
84
|
+
argument: z.string().optional().describe("Argument for the Appium command in an 'appium' step."),
|
|
85
|
+
httpMethod: z.string().optional().describe(
|
|
86
|
+
"HTTP method for an 'api' step (e.g. 'GET', 'POST'). Defaults to 'GET'."
|
|
87
|
+
),
|
|
88
|
+
requestBody: z.string().optional().describe("Request body for an 'api' step."),
|
|
89
|
+
requestHeaders: z.array(headerSchema).optional().describe("Request headers for an 'api' step."),
|
|
90
|
+
followRedirects: z.boolean().optional().describe("Whether an 'api' step should follow HTTP redirects."),
|
|
91
|
+
email: emailSchema.optional().describe("Configuration for a 'receive-email' step."),
|
|
92
|
+
sms: smsSchema.optional().describe("Configuration for a 'receive-sms' step."),
|
|
93
|
+
expectedText: z.string().optional().describe(
|
|
94
|
+
"Text expected on the page. Used by 'text-validation' steps, which require an exact match of the target element's text (not a substring or case-insensitive match)."
|
|
95
|
+
),
|
|
96
|
+
title: z.string().optional().describe(
|
|
97
|
+
"Expected page title for a navigation step ('browser-navigate', 'browser-back', 'browser-forward', 'browser-refresh')."
|
|
98
|
+
),
|
|
99
|
+
expectedResult: z.string().optional().describe("Expected result text for a 'prompt' step."),
|
|
100
|
+
promptType: z.enum(["action", "assert", "query"]).optional().describe(
|
|
101
|
+
"The kind of AI 'prompt' step (required for 'prompt' steps): 'action' performs an action; 'assert' checks a condition; 'query' answers a question. Prompt steps only take into account what is currently visible on the screen."
|
|
102
|
+
),
|
|
103
|
+
expectedResponse: z.union([z.boolean(), z.string()]).optional().describe(
|
|
104
|
+
"Expected response for a 'prompt' step: a boolean for an 'assert' prompt, or a string for a 'query' prompt."
|
|
105
|
+
),
|
|
106
|
+
latitude: z.number().optional().describe("Latitude for a 'set-device-location' step."),
|
|
107
|
+
longitude: z.number().optional().describe("Longitude for a 'set-device-location' step."),
|
|
108
|
+
seconds: z.number().optional().describe("Number of seconds to pause. Used by 'wait' steps."),
|
|
109
|
+
// Only tests can reference segments, so this field is omitted from segment steps.
|
|
110
|
+
...includeSegmentReference ? {
|
|
111
|
+
id: z.number().optional().describe(
|
|
112
|
+
"Id of the segment to reference. Required for 'segment' steps."
|
|
113
|
+
)
|
|
114
|
+
} : {},
|
|
115
|
+
name: z.string().optional().describe("Optional display name for the step."),
|
|
116
|
+
parameters: z.array(parameterSchema).optional().describe(
|
|
117
|
+
"Parameter name/value assignments applied by an 'update-parameters' step."
|
|
118
|
+
)
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
function buildCreateDefinitionSchema({
|
|
122
|
+
isSegment
|
|
123
|
+
}) {
|
|
124
|
+
const definitionType = isSegment ? "segment" : "test";
|
|
125
|
+
const stepSchema = buildStepSchema(
|
|
126
|
+
isSegment ? BASE_STEP_TYPES : TEST_STEP_TYPES,
|
|
127
|
+
{ includeSegmentReference: !isSegment }
|
|
128
|
+
);
|
|
129
|
+
const selectorGuidance = "Prefer deterministic, selector-based steps ('click', 'input', 'submit', 'text-validation', 'hover', etc.) over AI-driven 'prompt' steps whenever a stable selector is available. Reserve 'prompt' steps for behavior that can't be expressed with a selector.";
|
|
130
|
+
const referenceGuidance = `Any text field in a step (e.g. 'inputText', 'url', 'expectedText', 'requestBody', header values, prompt text) may embed Reflect variable and function references using '\${...}' syntax, which are resolved at run time: '\${var(name)}' inserts the value of a parameter/variable named 'name' (declare parameters via the top-level 'parameters' field, or assign them mid-run with an 'update-parameters' step); '\${sec(name)}' inserts the value of the account secret 'name'. Functions generate dynamic values: '\${alphanum(n)}', '\${alpha(n)}', '\${num(n)}' (random alphanumeric / alphabetic / numeric string of length n), '\${range(min, max)}' (random integer, inclusive), '\${time(offsetMs)}' and '\${datetime(offsetMs)}' (current epoch-millis / date-time, with an optional millisecond offset), and '\${date(format, offsetDays)}' (current date formatted with tokens like 'MM/dd/yyyy', with an optional day offset).`;
|
|
131
|
+
const stepsDescription = isSegment ? `Ordered list of steps that make up the segment. Segments cannot reference other segments. ${selectorGuidance} ${referenceGuidance}` : `Ordered list of steps that make up the test. Web tests must begin with a 'browser-navigate' step. ${selectorGuidance} ${referenceGuidance}`;
|
|
132
|
+
return z.object({
|
|
133
|
+
name: z.string().describe(`Name of the ${definitionType} to create.`),
|
|
134
|
+
type: z.enum(["web", "api", "native-mobile"]).describe(`Platform of the ${definitionType}.`),
|
|
135
|
+
description: z.string().optional().describe(`Optional description of the ${definitionType}.`),
|
|
136
|
+
deviceProfile: z.string().optional().describe(
|
|
137
|
+
`Device profile id. Required for a 'web' ${definitionType}; ignored for 'api' and 'native-mobile'. One of: 'desktop', 'tablet', 'mobile'.`
|
|
138
|
+
),
|
|
139
|
+
steps: z.array(stepSchema).describe(stepsDescription),
|
|
140
|
+
parameters: z.array(parameterSchema).optional().describe(
|
|
141
|
+
`Optional named parameters (variables) for the ${definitionType}, each with a 'name' and optional default 'value'. Reference a parameter's value inside any step text field with '\${var(name)}'.`
|
|
142
|
+
)
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
async function readErrorMessage(response) {
|
|
146
|
+
try {
|
|
147
|
+
const text = await response.text();
|
|
148
|
+
if (!text) {
|
|
149
|
+
return "";
|
|
150
|
+
}
|
|
151
|
+
try {
|
|
152
|
+
const parsed = JSON.parse(text);
|
|
153
|
+
return parsed.message ? `: ${parsed.message}` : `: ${text}`;
|
|
154
|
+
} catch {
|
|
155
|
+
return `: ${text}`;
|
|
156
|
+
}
|
|
157
|
+
} catch {
|
|
158
|
+
return "";
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
async function createReflectDefinition(client, endpoint, noun, body) {
|
|
162
|
+
const response = await fetch(`https://${API_HOSTNAME}/v1/${endpoint}`, {
|
|
163
|
+
method: "POST",
|
|
164
|
+
headers: client.getHeaders(),
|
|
165
|
+
body: JSON.stringify(body)
|
|
166
|
+
});
|
|
167
|
+
if (!response.ok) {
|
|
168
|
+
const detail = await readErrorMessage(response);
|
|
169
|
+
throw new ToolError(
|
|
170
|
+
`Failed to create ${noun}: ${response.status} ${response.statusText}${detail}`
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
const data = await response.json();
|
|
174
|
+
return {
|
|
175
|
+
content: [
|
|
176
|
+
{
|
|
177
|
+
type: "text",
|
|
178
|
+
text: JSON.stringify({
|
|
179
|
+
success: true,
|
|
180
|
+
id: data.id,
|
|
181
|
+
message: `Created ${noun} with id ${data.id}`
|
|
182
|
+
})
|
|
183
|
+
}
|
|
184
|
+
]
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
export {
|
|
188
|
+
buildCreateDefinitionSchema,
|
|
189
|
+
createReflectDefinition
|
|
190
|
+
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { appendClientIdentity } from "../../common/info.js";
|
|
1
2
|
import { ToolError } from "../../common/tools.js";
|
|
2
3
|
import { buildSubdomainCandidate, buildSuffixedSubdomain, buildPortalName, isConflictError, isOrganizationPortalConflict } from "./portal-utils.js";
|
|
3
4
|
import { findTableOfContentsItem, buildPortalLiveUrl, normalizeSlug } from "./utils.js";
|
|
@@ -22,7 +23,7 @@ class SwaggerAPI {
|
|
|
22
23
|
this.userAgent = userAgent;
|
|
23
24
|
}
|
|
24
25
|
get headers() {
|
|
25
|
-
return this.config.getHeaders(this.userAgent);
|
|
26
|
+
return this.config.getHeaders(appendClientIdentity(this.userAgent));
|
|
26
27
|
}
|
|
27
28
|
/**
|
|
28
29
|
* Core response parsing logic shared between different response handlers.
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { appendClientIdentity } from "../../common/info.js";
|
|
1
2
|
import { ToolError } from "../../common/tools.js";
|
|
2
3
|
const API_HOSTNAME = "api.reflect.run";
|
|
3
4
|
const FUNCTIONAL_TESTING_API_KEY_HEADER = "X-API-KEY";
|
|
@@ -16,80 +17,230 @@ class FunctionalTestingAPI {
|
|
|
16
17
|
return {
|
|
17
18
|
[FUNCTIONAL_TESTING_API_KEY_HEADER]: token,
|
|
18
19
|
"Content-Type": "application/json",
|
|
19
|
-
"User-Agent": this.userAgent
|
|
20
|
+
"User-Agent": appendClientIdentity(this.userAgent)
|
|
20
21
|
};
|
|
21
22
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Wrapper around the fetch function for the Functional Testing API. It generates the full URL and performs
|
|
25
|
+
* common error handling.
|
|
26
|
+
* @param relativePath Path of the resource to fetch relative to the base URL
|
|
27
|
+
* @param init RequestInit passed to the fetch function
|
|
28
|
+
* @param onFailure Handler that generates the error message for failed responses
|
|
29
|
+
* @returns Response having asserted it has not failed (status is 2xx)
|
|
30
|
+
*/
|
|
31
|
+
async ftFetch(relativePath, init, onFailure) {
|
|
32
|
+
let response;
|
|
33
|
+
try {
|
|
34
|
+
response = await fetch(`${this.baseUrl}/${relativePath}`, init);
|
|
35
|
+
} catch {
|
|
28
36
|
throw new ToolError(
|
|
29
|
-
|
|
37
|
+
"Swagger Functional Testing service is currently unreachable. Retry after a moment."
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
if (response.status === 401 || response.status === 403) {
|
|
41
|
+
throw new ToolError(
|
|
42
|
+
"Authentication failed. Verify your API token is valid and has not expired."
|
|
30
43
|
);
|
|
31
44
|
}
|
|
45
|
+
if (!response.ok) {
|
|
46
|
+
throw new ToolError(onFailure(response));
|
|
47
|
+
}
|
|
48
|
+
return response;
|
|
49
|
+
}
|
|
50
|
+
async listTests() {
|
|
51
|
+
const response = await this.ftFetch(
|
|
52
|
+
`tests`,
|
|
53
|
+
{
|
|
54
|
+
method: "GET",
|
|
55
|
+
headers: this.getFtHeaders()
|
|
56
|
+
},
|
|
57
|
+
errorMessageFor(`list Functional Testing tests`)
|
|
58
|
+
);
|
|
32
59
|
return response.json();
|
|
33
60
|
}
|
|
34
61
|
async runTest(args) {
|
|
35
62
|
if (!args.testId) throw new ToolError("testId argument is required");
|
|
36
|
-
const response = await
|
|
37
|
-
|
|
63
|
+
const response = await this.ftFetch(
|
|
64
|
+
`tests/${encodeURIComponent(args.testId)}/executions`,
|
|
38
65
|
{
|
|
39
66
|
method: "POST",
|
|
40
67
|
headers: this.getFtHeaders()
|
|
41
|
-
}
|
|
68
|
+
},
|
|
69
|
+
errorMessageFor(`run test`)
|
|
42
70
|
);
|
|
43
|
-
if (!response.ok) {
|
|
44
|
-
throw new ToolError(
|
|
45
|
-
`Failed to run test: ${response.status} ${response.statusText}`
|
|
46
|
-
);
|
|
47
|
-
}
|
|
48
71
|
return response.json();
|
|
49
72
|
}
|
|
50
73
|
async getTestExecution(args) {
|
|
51
74
|
if (!args.executionId) {
|
|
52
75
|
throw new ToolError("executionId argument is required");
|
|
53
76
|
}
|
|
54
|
-
const response = await
|
|
55
|
-
|
|
77
|
+
const response = await this.ftFetch(
|
|
78
|
+
`executions/${encodeURIComponent(args.executionId)}`,
|
|
56
79
|
{
|
|
57
80
|
method: "GET",
|
|
58
81
|
headers: this.getFtHeaders()
|
|
59
|
-
}
|
|
82
|
+
},
|
|
83
|
+
errorMessageFor("get test status")
|
|
60
84
|
);
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
85
|
+
const data = await response.json();
|
|
86
|
+
if (Array.isArray(data.tests)) {
|
|
87
|
+
for (const test of data.tests) {
|
|
88
|
+
const run = test.run;
|
|
89
|
+
if (run) {
|
|
90
|
+
delete run.videoUrl;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
65
93
|
}
|
|
66
|
-
return
|
|
94
|
+
return data;
|
|
95
|
+
}
|
|
96
|
+
async listSuiteExecutions(args) {
|
|
97
|
+
if (!args.suiteId) throw new ToolError("suiteId argument is required");
|
|
98
|
+
const response = await this.ftFetch(
|
|
99
|
+
`suites/${encodeURIComponent(args.suiteId)}/executions`,
|
|
100
|
+
{
|
|
101
|
+
method: "GET",
|
|
102
|
+
headers: this.getFtHeaders()
|
|
103
|
+
},
|
|
104
|
+
handleStatus(
|
|
105
|
+
/* @__PURE__ */ new Map([
|
|
106
|
+
// Defensive: the Reflect API currently returns 200 with an empty
|
|
107
|
+
// `executions.data` list for an unknown suiteId rather than a 404, so this
|
|
108
|
+
// branch is not expected to fire today. Kept in case the API starts
|
|
109
|
+
// returning 404 for missing suites.
|
|
110
|
+
[
|
|
111
|
+
404,
|
|
112
|
+
"Test suite not found. Verify the suiteId is correct and belongs to your workspace."
|
|
113
|
+
]
|
|
114
|
+
]),
|
|
115
|
+
errorMessageFor("list suite executions")
|
|
116
|
+
)
|
|
117
|
+
);
|
|
118
|
+
const data = await response.json();
|
|
119
|
+
return {
|
|
120
|
+
...data,
|
|
121
|
+
executions: {
|
|
122
|
+
data: data.executions.data.map(
|
|
123
|
+
({ executionId, status, isFinished }) => ({
|
|
124
|
+
executionId,
|
|
125
|
+
status,
|
|
126
|
+
isFinished
|
|
127
|
+
})
|
|
128
|
+
)
|
|
129
|
+
}
|
|
130
|
+
};
|
|
67
131
|
}
|
|
68
132
|
async listSuites() {
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
response = await fetch(`${this.baseUrl}/suites`, {
|
|
133
|
+
const response = await this.ftFetch(
|
|
134
|
+
`suites`,
|
|
135
|
+
{
|
|
73
136
|
method: "GET",
|
|
74
|
-
headers
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
137
|
+
headers: this.getFtHeaders()
|
|
138
|
+
},
|
|
139
|
+
errorMessageFor("list Functional Testing suites")
|
|
140
|
+
);
|
|
141
|
+
return response.json();
|
|
142
|
+
}
|
|
143
|
+
async cancelSuiteExecution(args) {
|
|
144
|
+
if (!args.suiteId) throw new ToolError("suiteId argument is required");
|
|
145
|
+
if (!args.executionId) {
|
|
146
|
+
throw new ToolError("executionId argument is required");
|
|
80
147
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
148
|
+
const response = await this.ftFetch(
|
|
149
|
+
`suites/${encodeURIComponent(args.suiteId)}/executions/${encodeURIComponent(args.executionId)}/cancel`,
|
|
150
|
+
{
|
|
151
|
+
method: "PATCH",
|
|
152
|
+
headers: this.getFtHeaders()
|
|
153
|
+
},
|
|
154
|
+
handleStatus(
|
|
155
|
+
/* @__PURE__ */ new Map([
|
|
156
|
+
[
|
|
157
|
+
404,
|
|
158
|
+
"Suite execution not found. Verify the suiteId and executionId are correct and belong to your workspace."
|
|
159
|
+
],
|
|
160
|
+
[
|
|
161
|
+
409,
|
|
162
|
+
"Suite execution cannot be cancelled because it has already finished."
|
|
163
|
+
]
|
|
164
|
+
]),
|
|
165
|
+
errorMessageFor("cancel suite execution")
|
|
166
|
+
)
|
|
167
|
+
);
|
|
168
|
+
return response.json();
|
|
169
|
+
}
|
|
170
|
+
async runSuite(args) {
|
|
171
|
+
if (!args.suiteId) throw new ToolError("suiteId argument is required");
|
|
172
|
+
const body = args.tunnelAgentName ? JSON.stringify({
|
|
173
|
+
overrides: { agent: { name: args.tunnelAgentName } }
|
|
174
|
+
}) : void 0;
|
|
175
|
+
const response = await this.ftFetch(
|
|
176
|
+
`suites/${args.suiteId}/executions`,
|
|
177
|
+
{
|
|
178
|
+
method: "POST",
|
|
179
|
+
headers: this.getFtHeaders(),
|
|
180
|
+
body
|
|
181
|
+
},
|
|
182
|
+
errorMessageFor("run suite")
|
|
183
|
+
);
|
|
184
|
+
return this.withoutField("url", response);
|
|
185
|
+
}
|
|
186
|
+
async getSuiteExecution(args) {
|
|
187
|
+
if (!args.suiteId) throw new ToolError("suiteId argument is required");
|
|
188
|
+
if (!args.executionId) {
|
|
189
|
+
throw new ToolError("executionId argument is required");
|
|
85
190
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
191
|
+
const response = await this.ftFetch(
|
|
192
|
+
`suites/${args.suiteId}/executions/${args.executionId}`,
|
|
193
|
+
{
|
|
194
|
+
method: "GET",
|
|
195
|
+
headers: this.getFtHeaders()
|
|
196
|
+
},
|
|
197
|
+
errorMessageFor("get suite execution status")
|
|
198
|
+
);
|
|
199
|
+
const data = await this.withoutField("url", response);
|
|
200
|
+
const testsData = data.tests?.data;
|
|
201
|
+
if (Array.isArray(testsData)) {
|
|
202
|
+
for (const test of testsData) {
|
|
203
|
+
if (Array.isArray(test.runs)) {
|
|
204
|
+
for (const run of test.runs) {
|
|
205
|
+
delete run.videoUrl;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
90
209
|
}
|
|
210
|
+
return data;
|
|
211
|
+
}
|
|
212
|
+
async getTestHistory(args) {
|
|
213
|
+
if (!args.testId) throw new ToolError("testId argument is required");
|
|
214
|
+
const params = new URLSearchParams();
|
|
215
|
+
if (args.limit !== void 0) params.set("limit", String(args.limit));
|
|
216
|
+
if (args.offset !== void 0) params.set("offset", String(args.offset));
|
|
217
|
+
const query = params.toString() ? `?${params.toString()}` : "";
|
|
218
|
+
const response = await this.ftFetch(
|
|
219
|
+
`tests/${encodeURIComponent(args.testId)}/runs${query}`,
|
|
220
|
+
{
|
|
221
|
+
method: "GET",
|
|
222
|
+
headers: this.getFtHeaders()
|
|
223
|
+
},
|
|
224
|
+
handleStatus(
|
|
225
|
+
/* @__PURE__ */ new Map([
|
|
226
|
+
[404, "Test not found. Verify the testId belongs to your workspace."]
|
|
227
|
+
]),
|
|
228
|
+
errorMessageFor("get test execution history")
|
|
229
|
+
)
|
|
230
|
+
);
|
|
91
231
|
return response.json();
|
|
92
232
|
}
|
|
233
|
+
async withoutField(field, response) {
|
|
234
|
+
const data = await response.json();
|
|
235
|
+
delete data[field];
|
|
236
|
+
return data;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
function handleStatus(messages, defaultMessage) {
|
|
240
|
+
return (response) => messages.get(response.status) || defaultMessage(response);
|
|
241
|
+
}
|
|
242
|
+
function errorMessageFor(operation) {
|
|
243
|
+
return (response) => `Failed to ${operation}: ${response.status} ${response.statusText}`;
|
|
93
244
|
}
|
|
94
245
|
export {
|
|
95
246
|
FUNCTIONAL_TESTING_API_KEY_HEADER,
|