@browserstack/mcp-server 1.1.0 → 1.1.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/dist/config.js +2 -6
- package/dist/index.js +29 -34
- package/dist/lib/api.js +3 -9
- package/dist/lib/constants.js +3 -6
- package/dist/lib/device-cache.js +14 -21
- package/dist/lib/error.js +3 -6
- package/dist/lib/fuzzy.js +1 -4
- package/dist/lib/inmemory-store.js +1 -4
- package/dist/lib/instrumentation.js +12 -18
- package/dist/lib/local.js +27 -35
- package/dist/lib/utils.js +6 -15
- package/dist/logger.js +4 -6
- package/dist/tools/accessibility.js +13 -16
- package/dist/tools/accessiblity-utils/report-fetcher.js +7 -14
- package/dist/tools/accessiblity-utils/report-parser.js +5 -11
- package/dist/tools/accessiblity-utils/scanner.js +9 -16
- package/dist/tools/appautomate-utils/appautomate.js +17 -27
- package/dist/tools/appautomate.js +29 -35
- package/dist/tools/applive-utils/fuzzy-search.js +3 -6
- package/dist/tools/applive-utils/start-session.js +14 -20
- package/dist/tools/applive-utils/upload-app.js +12 -51
- package/dist/tools/applive.js +18 -25
- package/dist/tools/automate-utils/fetch-screenshots.js +8 -14
- package/dist/tools/automate.js +14 -21
- package/dist/tools/bstack-sdk.js +14 -18
- package/dist/tools/failurelogs-utils/app-automate.js +15 -26
- package/dist/tools/failurelogs-utils/automate.js +13 -23
- package/dist/tools/getFailureLogs.js +42 -49
- package/dist/tools/live-utils/desktop-filter.js +8 -11
- package/dist/tools/live-utils/mobile-filter.js +7 -10
- package/dist/tools/live-utils/start-session.js +17 -23
- package/dist/tools/live-utils/types.js +2 -5
- package/dist/tools/live-utils/version-resolver.js +1 -4
- package/dist/tools/live.js +23 -29
- package/dist/tools/observability.js +12 -19
- package/dist/tools/sdk-utils/constants.js +3 -9
- package/dist/tools/sdk-utils/instructions.js +4 -9
- package/dist/tools/sdk-utils/types.js +1 -2
- package/dist/tools/testmanagement-utils/TCG-utils/api.js +26 -38
- package/dist/tools/testmanagement-utils/TCG-utils/config.js +5 -10
- package/dist/tools/testmanagement-utils/TCG-utils/helpers.js +3 -8
- package/dist/tools/testmanagement-utils/TCG-utils/types.js +5 -8
- package/dist/tools/testmanagement-utils/add-test-result.js +17 -24
- package/dist/tools/testmanagement-utils/create-project-folder.js +21 -28
- package/dist/tools/testmanagement-utils/create-testcase.js +30 -38
- package/dist/tools/testmanagement-utils/create-testrun.js +23 -30
- package/dist/tools/testmanagement-utils/list-testcases.js +15 -22
- package/dist/tools/testmanagement-utils/list-testruns.js +12 -19
- package/dist/tools/testmanagement-utils/testcase-from-file.js +16 -22
- package/dist/tools/testmanagement-utils/update-testrun.js +15 -22
- package/dist/tools/testmanagement-utils/upload-file.js +22 -29
- package/dist/tools/testmanagement.js +61 -76
- package/package.json +1 -1
|
@@ -1,64 +1,56 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
exports.sanitizeArgs = sanitizeArgs;
|
|
8
|
-
exports.createTestCase = createTestCase;
|
|
9
|
-
const axios_1 = __importDefault(require("axios"));
|
|
10
|
-
const config_js_1 = __importDefault(require("../../config.js"));
|
|
11
|
-
const zod_1 = require("zod");
|
|
12
|
-
const error_js_1 = require("../../lib/error.js"); // or correct
|
|
13
|
-
exports.CreateTestCaseSchema = zod_1.z.object({
|
|
14
|
-
project_identifier: zod_1.z
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
import config from "../../config.js";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { formatAxiosError } from "../../lib/error.js"; // or correct
|
|
5
|
+
export const CreateTestCaseSchema = z.object({
|
|
6
|
+
project_identifier: z
|
|
15
7
|
.string()
|
|
16
8
|
.describe("The ID of the BrowserStack project where the test case should be created. If no project identifier is provided, ask the user if they would like to create a new project using the createProjectOrFolder tool."),
|
|
17
|
-
folder_id:
|
|
9
|
+
folder_id: z
|
|
18
10
|
.string()
|
|
19
11
|
.describe("The ID of the folder within the project where the test case should be created. If not provided, ask the user if they would like to create a new folder using the createProjectOrFolder tool."),
|
|
20
|
-
name:
|
|
21
|
-
description:
|
|
12
|
+
name: z.string().describe("Name of the test case."),
|
|
13
|
+
description: z
|
|
22
14
|
.string()
|
|
23
15
|
.optional()
|
|
24
16
|
.describe("Brief description of the test case."),
|
|
25
|
-
owner:
|
|
17
|
+
owner: z
|
|
26
18
|
.string()
|
|
27
19
|
.email()
|
|
28
20
|
.describe("Email of the test case owner.")
|
|
29
21
|
.optional(),
|
|
30
|
-
preconditions:
|
|
22
|
+
preconditions: z
|
|
31
23
|
.string()
|
|
32
24
|
.optional()
|
|
33
25
|
.describe("Any preconditions (HTML allowed)."),
|
|
34
|
-
test_case_steps:
|
|
35
|
-
.array(
|
|
36
|
-
step:
|
|
37
|
-
result:
|
|
26
|
+
test_case_steps: z
|
|
27
|
+
.array(z.object({
|
|
28
|
+
step: z.string().describe("Action to perform in this step."),
|
|
29
|
+
result: z.string().describe("Expected result of this step."),
|
|
38
30
|
}))
|
|
39
31
|
.describe("List of steps and expected results."),
|
|
40
|
-
issues:
|
|
41
|
-
.array(
|
|
32
|
+
issues: z
|
|
33
|
+
.array(z.string())
|
|
42
34
|
.optional()
|
|
43
35
|
.describe("List of the linked Jira, Asana or Azure issues ID's. This should be strictly in array format not the string of json."),
|
|
44
|
-
issue_tracker:
|
|
36
|
+
issue_tracker: z
|
|
45
37
|
.object({
|
|
46
|
-
name:
|
|
38
|
+
name: z
|
|
47
39
|
.string()
|
|
48
40
|
.describe("Issue tracker name, For example, use jira for Jira, azure for Azure DevOps, or asana for Asana."),
|
|
49
|
-
host:
|
|
41
|
+
host: z.string().url().describe("Base URL of the issue tracker."),
|
|
50
42
|
})
|
|
51
43
|
.optional(),
|
|
52
|
-
tags:
|
|
53
|
-
.array(
|
|
44
|
+
tags: z
|
|
45
|
+
.array(z.string())
|
|
54
46
|
.optional()
|
|
55
47
|
.describe("Tags to attach to the test case. This should be strictly in array format not the string of json"),
|
|
56
|
-
custom_fields:
|
|
57
|
-
.record(
|
|
48
|
+
custom_fields: z
|
|
49
|
+
.record(z.string(), z.string())
|
|
58
50
|
.optional()
|
|
59
51
|
.describe("Map of custom field names to values."),
|
|
60
52
|
});
|
|
61
|
-
function sanitizeArgs(args) {
|
|
53
|
+
export function sanitizeArgs(args) {
|
|
62
54
|
const cleaned = { ...args };
|
|
63
55
|
if (cleaned.description === null)
|
|
64
56
|
delete cleaned.description;
|
|
@@ -74,13 +66,13 @@ function sanitizeArgs(args) {
|
|
|
74
66
|
}
|
|
75
67
|
return cleaned;
|
|
76
68
|
}
|
|
77
|
-
async function createTestCase(params) {
|
|
69
|
+
export async function createTestCase(params) {
|
|
78
70
|
const body = { test_case: params };
|
|
79
71
|
try {
|
|
80
|
-
const response = await
|
|
72
|
+
const response = await axios.post(`https://test-management.browserstack.com/api/v2/projects/${encodeURIComponent(params.project_identifier)}/folders/${encodeURIComponent(params.folder_id)}/test-cases`, body, {
|
|
81
73
|
auth: {
|
|
82
|
-
username:
|
|
83
|
-
password:
|
|
74
|
+
username: config.browserstackUsername,
|
|
75
|
+
password: config.browserstackAccessKey,
|
|
84
76
|
},
|
|
85
77
|
headers: { "Content-Type": "application/json" },
|
|
86
78
|
});
|
|
@@ -110,6 +102,6 @@ async function createTestCase(params) {
|
|
|
110
102
|
}
|
|
111
103
|
catch (err) {
|
|
112
104
|
// Delegate to our centralized Axios error formatter
|
|
113
|
-
return
|
|
105
|
+
return formatAxiosError(err, "Failed to create test case");
|
|
114
106
|
}
|
|
115
107
|
}
|
|
@@ -1,28 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.CreateTestRunSchema = void 0;
|
|
7
|
-
exports.createTestRun = createTestRun;
|
|
8
|
-
const axios_1 = __importDefault(require("axios"));
|
|
9
|
-
const config_js_1 = __importDefault(require("../../config.js"));
|
|
10
|
-
const zod_1 = require("zod");
|
|
11
|
-
const error_js_1 = require("../../lib/error.js");
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
import config from "../../config.js";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { formatAxiosError } from "../../lib/error.js";
|
|
12
5
|
/**
|
|
13
6
|
* Schema for creating a test run.
|
|
14
7
|
*/
|
|
15
|
-
|
|
16
|
-
project_identifier:
|
|
8
|
+
export const CreateTestRunSchema = z.object({
|
|
9
|
+
project_identifier: z
|
|
17
10
|
.string()
|
|
18
11
|
.describe("Identifier of the project in which to create the test run."),
|
|
19
|
-
test_run:
|
|
20
|
-
name:
|
|
21
|
-
description:
|
|
12
|
+
test_run: z.object({
|
|
13
|
+
name: z.string().describe("Name of the test run"),
|
|
14
|
+
description: z
|
|
22
15
|
.string()
|
|
23
16
|
.optional()
|
|
24
17
|
.describe("Brief information about the test run"),
|
|
25
|
-
run_state:
|
|
18
|
+
run_state: z
|
|
26
19
|
.enum([
|
|
27
20
|
"new_run",
|
|
28
21
|
"in_progress",
|
|
@@ -33,17 +26,17 @@ exports.CreateTestRunSchema = zod_1.z.object({
|
|
|
33
26
|
])
|
|
34
27
|
.optional()
|
|
35
28
|
.describe("State of the test run. One of new_run, in_progress, under_review, rejected, done, closed"),
|
|
36
|
-
issues:
|
|
37
|
-
issue_tracker:
|
|
38
|
-
.object({ name:
|
|
29
|
+
issues: z.array(z.string()).optional().describe("Linked issue IDs"),
|
|
30
|
+
issue_tracker: z
|
|
31
|
+
.object({ name: z.string(), host: z.string().url() })
|
|
39
32
|
.optional()
|
|
40
33
|
.describe("Issue tracker configuration"),
|
|
41
|
-
test_cases:
|
|
42
|
-
.array(
|
|
34
|
+
test_cases: z
|
|
35
|
+
.array(z.string())
|
|
43
36
|
.optional()
|
|
44
37
|
.describe("List of test case IDs"),
|
|
45
|
-
folder_ids:
|
|
46
|
-
.array(
|
|
38
|
+
folder_ids: z
|
|
39
|
+
.array(z.number())
|
|
47
40
|
.optional()
|
|
48
41
|
.describe("Folder IDs to include"),
|
|
49
42
|
}),
|
|
@@ -51,7 +44,7 @@ exports.CreateTestRunSchema = zod_1.z.object({
|
|
|
51
44
|
/**
|
|
52
45
|
* Creates a test run via BrowserStack Test Management API.
|
|
53
46
|
*/
|
|
54
|
-
async function createTestRun(rawArgs) {
|
|
47
|
+
export async function createTestRun(rawArgs) {
|
|
55
48
|
try {
|
|
56
49
|
const inputArgs = {
|
|
57
50
|
...rawArgs,
|
|
@@ -60,12 +53,12 @@ async function createTestRun(rawArgs) {
|
|
|
60
53
|
include_all: false,
|
|
61
54
|
},
|
|
62
55
|
};
|
|
63
|
-
const args =
|
|
56
|
+
const args = CreateTestRunSchema.parse(inputArgs);
|
|
64
57
|
const url = `https://test-management.browserstack.com/api/v2/projects/${encodeURIComponent(args.project_identifier)}/test-runs`;
|
|
65
|
-
const response = await
|
|
58
|
+
const response = await axios.post(url, { test_run: args.test_run }, {
|
|
66
59
|
auth: {
|
|
67
|
-
username:
|
|
68
|
-
password:
|
|
60
|
+
username: config.browserstackUsername,
|
|
61
|
+
password: config.browserstackAccessKey,
|
|
69
62
|
},
|
|
70
63
|
headers: { "Content-Type": "application/json" },
|
|
71
64
|
});
|
|
@@ -85,6 +78,6 @@ async function createTestRun(rawArgs) {
|
|
|
85
78
|
};
|
|
86
79
|
}
|
|
87
80
|
catch (err) {
|
|
88
|
-
return
|
|
81
|
+
return formatAxiosError(err, "Failed to create test run");
|
|
89
82
|
}
|
|
90
83
|
}
|
|
@@ -1,39 +1,32 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.ListTestCasesSchema = void 0;
|
|
7
|
-
exports.listTestCases = listTestCases;
|
|
8
|
-
const axios_1 = __importDefault(require("axios"));
|
|
9
|
-
const config_js_1 = __importDefault(require("../../config.js"));
|
|
10
|
-
const zod_1 = require("zod");
|
|
11
|
-
const error_js_1 = require("../../lib/error.js");
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
import config from "../../config.js";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { formatAxiosError } from "../../lib/error.js";
|
|
12
5
|
/**
|
|
13
6
|
* Schema for listing test cases with optional filters.
|
|
14
7
|
*/
|
|
15
|
-
|
|
16
|
-
project_identifier:
|
|
8
|
+
export const ListTestCasesSchema = z.object({
|
|
9
|
+
project_identifier: z
|
|
17
10
|
.string()
|
|
18
11
|
.describe("Identifier of the project to fetch test cases from. This id starts with a PR- and is followed by a number."),
|
|
19
|
-
folder_id:
|
|
12
|
+
folder_id: z
|
|
20
13
|
.string()
|
|
21
14
|
.optional()
|
|
22
15
|
.describe("If provided, only return cases in this folder."),
|
|
23
|
-
case_type:
|
|
16
|
+
case_type: z
|
|
24
17
|
.string()
|
|
25
18
|
.optional()
|
|
26
19
|
.describe("Comma-separated list of case types (e.g. functional,regression)."),
|
|
27
|
-
priority:
|
|
20
|
+
priority: z
|
|
28
21
|
.string()
|
|
29
22
|
.optional()
|
|
30
23
|
.describe("Comma-separated list of priorities (e.g. critical,medium,low)."),
|
|
31
|
-
p:
|
|
24
|
+
p: z.number().optional().describe("Page number."),
|
|
32
25
|
});
|
|
33
26
|
/**
|
|
34
27
|
* Calls BrowserStack Test Management to list test cases with filters.
|
|
35
28
|
*/
|
|
36
|
-
async function listTestCases(args) {
|
|
29
|
+
export async function listTestCases(args) {
|
|
37
30
|
try {
|
|
38
31
|
// Build query string
|
|
39
32
|
const params = new URLSearchParams();
|
|
@@ -46,10 +39,10 @@ async function listTestCases(args) {
|
|
|
46
39
|
if (args.p !== undefined)
|
|
47
40
|
params.append("p", args.p.toString());
|
|
48
41
|
const url = `https://test-management.browserstack.com/api/v2/projects/${encodeURIComponent(args.project_identifier)}/test-cases?${params.toString()}`;
|
|
49
|
-
const resp = await
|
|
42
|
+
const resp = await axios.get(url, {
|
|
50
43
|
auth: {
|
|
51
|
-
username:
|
|
52
|
-
password:
|
|
44
|
+
username: config.browserstackUsername,
|
|
45
|
+
password: config.browserstackAccessKey,
|
|
53
46
|
},
|
|
54
47
|
});
|
|
55
48
|
const resp_data = resp.data;
|
|
@@ -85,6 +78,6 @@ async function listTestCases(args) {
|
|
|
85
78
|
};
|
|
86
79
|
}
|
|
87
80
|
catch (err) {
|
|
88
|
-
return
|
|
81
|
+
return formatAxiosError(err, "Failed to list test cases");
|
|
89
82
|
}
|
|
90
83
|
}
|
|
@@ -1,22 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.ListTestRunsSchema = void 0;
|
|
7
|
-
exports.listTestRuns = listTestRuns;
|
|
8
|
-
const axios_1 = __importDefault(require("axios"));
|
|
9
|
-
const config_js_1 = __importDefault(require("../../config.js"));
|
|
10
|
-
const zod_1 = require("zod");
|
|
11
|
-
const error_js_1 = require("../../lib/error.js");
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
import config from "../../config.js";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { formatAxiosError } from "../../lib/error.js";
|
|
12
5
|
/**
|
|
13
6
|
* Schema for listing test runs with optional filters.
|
|
14
7
|
*/
|
|
15
|
-
|
|
16
|
-
project_identifier:
|
|
8
|
+
export const ListTestRunsSchema = z.object({
|
|
9
|
+
project_identifier: z
|
|
17
10
|
.string()
|
|
18
11
|
.describe("Identifier of the project to fetch test runs from (usually starts with PR-)."),
|
|
19
|
-
run_state:
|
|
12
|
+
run_state: z
|
|
20
13
|
.string()
|
|
21
14
|
.optional()
|
|
22
15
|
.describe("Return all test runs with this state (comma-separated)"),
|
|
@@ -24,17 +17,17 @@ exports.ListTestRunsSchema = zod_1.z.object({
|
|
|
24
17
|
/**
|
|
25
18
|
* Fetches and formats the list of test runs for a project.
|
|
26
19
|
*/
|
|
27
|
-
async function listTestRuns(args) {
|
|
20
|
+
export async function listTestRuns(args) {
|
|
28
21
|
try {
|
|
29
22
|
const params = new URLSearchParams();
|
|
30
23
|
if (args.run_state) {
|
|
31
24
|
params.set("run_state", args.run_state);
|
|
32
25
|
}
|
|
33
26
|
const url = `https://test-management.browserstack.com/api/v2/projects/${encodeURIComponent(args.project_identifier)}/test-runs?` + params.toString();
|
|
34
|
-
const resp = await
|
|
27
|
+
const resp = await axios.get(url, {
|
|
35
28
|
auth: {
|
|
36
|
-
username:
|
|
37
|
-
password:
|
|
29
|
+
username: config.browserstackUsername,
|
|
30
|
+
password: config.browserstackAccessKey,
|
|
38
31
|
},
|
|
39
32
|
});
|
|
40
33
|
const data = resp.data;
|
|
@@ -63,6 +56,6 @@ async function listTestRuns(args) {
|
|
|
63
56
|
};
|
|
64
57
|
}
|
|
65
58
|
catch (err) {
|
|
66
|
-
return
|
|
59
|
+
return formatAxiosError(err, "Failed to list test runs");
|
|
67
60
|
}
|
|
68
61
|
}
|
|
@@ -1,23 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const helpers_js_1 = require("./TCG-utils/helpers.js");
|
|
9
|
-
const inmemory_store_js_1 = require("../../lib/inmemory-store.js");
|
|
10
|
-
const logger_js_1 = __importDefault(require("../../logger.js"));
|
|
11
|
-
const api_js_2 = require("./TCG-utils/api.js");
|
|
12
|
-
async function createTestCasesFromFile(args, context) {
|
|
13
|
-
logger_js_1.default.info(`createTestCasesFromFile called with projectId: ${args.projectReferenceId}, folderId: ${args.folderId}`);
|
|
1
|
+
import { fetchFormFields, triggerTestCaseGeneration, pollScenariosTestDetails, bulkCreateTestCases, } from "./TCG-utils/api.js";
|
|
2
|
+
import { buildDefaultFieldMaps, findBooleanFieldId, } from "./TCG-utils/helpers.js";
|
|
3
|
+
import { signedUrlMap } from "../../lib/inmemory-store.js";
|
|
4
|
+
import logger from "../../logger.js";
|
|
5
|
+
import { projectIdentifierToId } from "./TCG-utils/api.js";
|
|
6
|
+
export async function createTestCasesFromFile(args, context) {
|
|
7
|
+
logger.info(`createTestCasesFromFile called with projectId: ${args.projectReferenceId}, folderId: ${args.folderId}`);
|
|
14
8
|
if (args.projectReferenceId.startsWith("PR-")) {
|
|
15
|
-
args.projectReferenceId = await
|
|
9
|
+
args.projectReferenceId = await projectIdentifierToId(args.projectReferenceId);
|
|
16
10
|
}
|
|
17
|
-
const { default_fields, custom_fields } = await
|
|
18
|
-
const fieldMaps =
|
|
19
|
-
const booleanFieldId =
|
|
20
|
-
const documentObj =
|
|
11
|
+
const { default_fields, custom_fields } = await fetchFormFields(args.projectReferenceId);
|
|
12
|
+
const fieldMaps = buildDefaultFieldMaps(default_fields);
|
|
13
|
+
const booleanFieldId = findBooleanFieldId(custom_fields);
|
|
14
|
+
const documentObj = signedUrlMap.get(args.documentId);
|
|
21
15
|
if (!documentObj) {
|
|
22
16
|
return {
|
|
23
17
|
content: [
|
|
@@ -33,10 +27,10 @@ async function createTestCasesFromFile(args, context) {
|
|
|
33
27
|
const documentId = documentObj.fileId;
|
|
34
28
|
const document = documentObj.downloadUrl;
|
|
35
29
|
const source = "jira-on-prem";
|
|
36
|
-
const traceId = await
|
|
37
|
-
const scenariosMap = await
|
|
38
|
-
const resultString = await
|
|
39
|
-
|
|
30
|
+
const traceId = await triggerTestCaseGeneration(document, documentId, args.folderId, args.projectReferenceId, source);
|
|
31
|
+
const scenariosMap = await pollScenariosTestDetails(args, traceId, context, documentId, source);
|
|
32
|
+
const resultString = await bulkCreateTestCases(scenariosMap, args.projectReferenceId, args.folderId, fieldMaps, booleanFieldId, traceId, context, documentId);
|
|
33
|
+
signedUrlMap.delete(args.documentId);
|
|
40
34
|
return {
|
|
41
35
|
content: [
|
|
42
36
|
{
|
|
@@ -1,25 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.UpdateTestRunSchema = void 0;
|
|
7
|
-
exports.updateTestRun = updateTestRun;
|
|
8
|
-
const axios_1 = __importDefault(require("axios"));
|
|
9
|
-
const config_js_1 = __importDefault(require("../../config.js"));
|
|
10
|
-
const zod_1 = require("zod");
|
|
11
|
-
const error_js_1 = require("../../lib/error.js");
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
import config from "../../config.js";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { formatAxiosError } from "../../lib/error.js";
|
|
12
5
|
/**
|
|
13
6
|
* Schema for updating a test run with partial fields.
|
|
14
7
|
*/
|
|
15
|
-
|
|
16
|
-
project_identifier:
|
|
8
|
+
export const UpdateTestRunSchema = z.object({
|
|
9
|
+
project_identifier: z
|
|
17
10
|
.string()
|
|
18
11
|
.describe("Identifier of the project (Starts with 'PR-')"),
|
|
19
|
-
test_run_id:
|
|
20
|
-
test_run:
|
|
21
|
-
name:
|
|
22
|
-
run_state:
|
|
12
|
+
test_run_id: z.string().describe("Test run identifier (e.g., TR-678)"),
|
|
13
|
+
test_run: z.object({
|
|
14
|
+
name: z.string().optional().describe("New name of the test run"),
|
|
15
|
+
run_state: z
|
|
23
16
|
.enum([
|
|
24
17
|
"new_run",
|
|
25
18
|
"in_progress",
|
|
@@ -35,14 +28,14 @@ exports.UpdateTestRunSchema = zod_1.z.object({
|
|
|
35
28
|
/**
|
|
36
29
|
* Partially updates an existing test run.
|
|
37
30
|
*/
|
|
38
|
-
async function updateTestRun(args) {
|
|
31
|
+
export async function updateTestRun(args) {
|
|
39
32
|
try {
|
|
40
33
|
const body = { test_run: args.test_run };
|
|
41
34
|
const url = `https://test-management.browserstack.com/api/v2/projects/${encodeURIComponent(args.project_identifier)}/test-runs/${encodeURIComponent(args.test_run_id)}/update`;
|
|
42
|
-
const resp = await
|
|
35
|
+
const resp = await axios.patch(url, body, {
|
|
43
36
|
auth: {
|
|
44
|
-
username:
|
|
45
|
-
password:
|
|
37
|
+
username: config.browserstackUsername,
|
|
38
|
+
password: config.browserstackAccessKey,
|
|
46
39
|
},
|
|
47
40
|
});
|
|
48
41
|
const data = resp.data;
|
|
@@ -69,6 +62,6 @@ async function updateTestRun(args) {
|
|
|
69
62
|
};
|
|
70
63
|
}
|
|
71
64
|
catch (err) {
|
|
72
|
-
return
|
|
65
|
+
return formatAxiosError(err, "Failed to update test run");
|
|
73
66
|
}
|
|
74
67
|
}
|
|
@@ -1,38 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const form_data_1 = __importDefault(require("form-data"));
|
|
11
|
-
const fs_1 = __importDefault(require("fs"));
|
|
12
|
-
const path_1 = __importDefault(require("path"));
|
|
13
|
-
const uuid_1 = require("uuid");
|
|
14
|
-
const config_js_1 = __importDefault(require("../../config.js"));
|
|
15
|
-
const inmemory_store_js_1 = require("../../lib/inmemory-store.js");
|
|
16
|
-
const api_js_1 = require("./TCG-utils/api.js");
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import axios from "axios";
|
|
3
|
+
import FormData from "form-data";
|
|
4
|
+
import fs from "fs";
|
|
5
|
+
import path from "path";
|
|
6
|
+
import { v4 as uuidv4 } from "uuid";
|
|
7
|
+
import config from "../../config.js";
|
|
8
|
+
import { signedUrlMap } from "../../lib/inmemory-store.js";
|
|
9
|
+
import { projectIdentifierToId } from "./TCG-utils/api.js";
|
|
17
10
|
/**
|
|
18
11
|
* Schema for the upload file tool
|
|
19
12
|
*/
|
|
20
|
-
|
|
21
|
-
project_identifier:
|
|
13
|
+
export const UploadFileSchema = z.object({
|
|
14
|
+
project_identifier: z
|
|
22
15
|
.string()
|
|
23
16
|
.describe("ID of the project where the file should be uploaded. Do not assume it, always ask user for it."),
|
|
24
|
-
file_path:
|
|
17
|
+
file_path: z
|
|
25
18
|
.string()
|
|
26
19
|
.describe("Full path to the file that should be uploaded"),
|
|
27
20
|
});
|
|
28
21
|
/**
|
|
29
22
|
* Uploads a file to BrowserStack Test Management and returns the signed URL.
|
|
30
23
|
*/
|
|
31
|
-
async function uploadFile(args) {
|
|
24
|
+
export async function uploadFile(args) {
|
|
32
25
|
const { project_identifier, file_path } = args;
|
|
33
26
|
try {
|
|
34
27
|
// Validate file exists
|
|
35
|
-
if (!
|
|
28
|
+
if (!fs.existsSync(file_path)) {
|
|
36
29
|
return {
|
|
37
30
|
content: [
|
|
38
31
|
{
|
|
@@ -45,14 +38,14 @@ async function uploadFile(args) {
|
|
|
45
38
|
};
|
|
46
39
|
}
|
|
47
40
|
// Get the project ID
|
|
48
|
-
const projectIdResponse = await
|
|
49
|
-
const formData = new
|
|
50
|
-
formData.append("attachments[]",
|
|
41
|
+
const projectIdResponse = await projectIdentifierToId(project_identifier);
|
|
42
|
+
const formData = new FormData();
|
|
43
|
+
formData.append("attachments[]", fs.createReadStream(file_path));
|
|
51
44
|
const uploadUrl = `https://test-management.browserstack.com/api/v1/projects/${projectIdResponse}/generic/attachments/ai_uploads`;
|
|
52
|
-
const response = await
|
|
45
|
+
const response = await axios.post(uploadUrl, formData, {
|
|
53
46
|
headers: {
|
|
54
47
|
...formData.getHeaders(),
|
|
55
|
-
"API-TOKEN": `${
|
|
48
|
+
"API-TOKEN": `${config.browserstackUsername}:${config.browserstackAccessKey}`,
|
|
56
49
|
accept: "application/json, text/plain, */*",
|
|
57
50
|
},
|
|
58
51
|
});
|
|
@@ -61,13 +54,13 @@ async function uploadFile(args) {
|
|
|
61
54
|
response.data.generic_attachment) {
|
|
62
55
|
const attachments = response.data.generic_attachment.map((attachment) => {
|
|
63
56
|
// Generate a unique ID for each attachment
|
|
64
|
-
const fileId = (
|
|
57
|
+
const fileId = uuidv4();
|
|
65
58
|
// Store the download URL in the signedUrlMap
|
|
66
59
|
const data = {
|
|
67
60
|
fileId: attachment.id,
|
|
68
61
|
downloadUrl: attachment.download_url,
|
|
69
62
|
};
|
|
70
|
-
|
|
63
|
+
signedUrlMap.set(fileId, data);
|
|
71
64
|
return {
|
|
72
65
|
name: attachment.name,
|
|
73
66
|
documentID: fileId,
|
|
@@ -80,7 +73,7 @@ async function uploadFile(args) {
|
|
|
80
73
|
content: [
|
|
81
74
|
{
|
|
82
75
|
type: "text",
|
|
83
|
-
text: `Successfully uploaded ${
|
|
76
|
+
text: `Successfully uploaded ${path.basename(file_path)} to BrowserStack Test Management.`,
|
|
84
77
|
},
|
|
85
78
|
{
|
|
86
79
|
type: "text",
|