@browserstack/mcp-server 1.0.12 → 1.0.14

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.
Files changed (52) hide show
  1. package/README.md +22 -0
  2. package/dist/config.js +2 -6
  3. package/dist/index.js +31 -30
  4. package/dist/lib/api.js +3 -57
  5. package/dist/lib/constants.js +14 -0
  6. package/dist/lib/device-cache.js +32 -33
  7. package/dist/lib/error.js +3 -6
  8. package/dist/lib/fuzzy.js +1 -4
  9. package/dist/lib/inmemory-store.js +1 -0
  10. package/dist/lib/instrumentation.js +12 -18
  11. package/dist/lib/local.js +27 -35
  12. package/dist/lib/utils.js +29 -4
  13. package/dist/logger.js +4 -9
  14. package/dist/tools/accessibility.js +9 -12
  15. package/dist/tools/accessiblity-utils/accessibility.js +14 -22
  16. package/dist/tools/appautomate-utils/appautomate.js +95 -0
  17. package/dist/tools/appautomate.js +116 -0
  18. package/dist/tools/applive-utils/fuzzy-search.js +3 -6
  19. package/dist/tools/applive-utils/start-session.js +14 -20
  20. package/dist/tools/applive-utils/upload-app.js +12 -51
  21. package/dist/tools/applive.js +18 -25
  22. package/dist/tools/automate-utils/fetch-screenshots.js +59 -0
  23. package/dist/tools/automate.js +44 -37
  24. package/dist/tools/bstack-sdk.js +14 -18
  25. package/dist/tools/failurelogs-utils/app-automate.js +88 -0
  26. package/dist/tools/failurelogs-utils/automate.js +97 -0
  27. package/dist/tools/getFailureLogs.js +173 -0
  28. package/dist/tools/live-utils/desktop-filter.js +8 -11
  29. package/dist/tools/live-utils/mobile-filter.js +7 -10
  30. package/dist/tools/live-utils/start-session.js +17 -23
  31. package/dist/tools/live-utils/types.js +2 -5
  32. package/dist/tools/live-utils/version-resolver.js +1 -4
  33. package/dist/tools/live.js +23 -29
  34. package/dist/tools/observability.js +12 -19
  35. package/dist/tools/sdk-utils/constants.js +3 -9
  36. package/dist/tools/sdk-utils/instructions.js +4 -9
  37. package/dist/tools/sdk-utils/types.js +1 -2
  38. package/dist/tools/testmanagement-utils/TCG-utils/api.js +259 -0
  39. package/dist/tools/testmanagement-utils/TCG-utils/config.js +5 -0
  40. package/dist/tools/testmanagement-utils/TCG-utils/helpers.js +53 -0
  41. package/dist/tools/testmanagement-utils/TCG-utils/types.js +8 -0
  42. package/dist/tools/testmanagement-utils/add-test-result.js +61 -0
  43. package/dist/tools/testmanagement-utils/create-project-folder.js +21 -28
  44. package/dist/tools/testmanagement-utils/create-testcase.js +30 -38
  45. package/dist/tools/testmanagement-utils/create-testrun.js +23 -30
  46. package/dist/tools/testmanagement-utils/list-testcases.js +16 -23
  47. package/dist/tools/testmanagement-utils/list-testruns.js +13 -20
  48. package/dist/tools/testmanagement-utils/testcase-from-file.js +42 -0
  49. package/dist/tools/testmanagement-utils/update-testrun.js +16 -23
  50. package/dist/tools/testmanagement-utils/upload-file.js +101 -0
  51. package/dist/tools/testmanagement.js +115 -46
  52. package/package.json +10 -6
@@ -0,0 +1,61 @@
1
+ import axios from "axios";
2
+ import config from "../../config.js";
3
+ import { z } from "zod";
4
+ import { formatAxiosError } from "../../lib/error.js";
5
+ /**
6
+ * Schema for adding a test result to a test run.
7
+ */
8
+ export const AddTestResultSchema = z.object({
9
+ project_identifier: z
10
+ .string()
11
+ .describe("Identifier of the project (Starts with 'PR-')"),
12
+ test_run_id: z.string().describe("Identifier of the test run (e.g., TR-678)"),
13
+ test_result: z.object({
14
+ status: z
15
+ .string()
16
+ .describe("Status of the test result, e.g., 'passed', 'failed'."),
17
+ description: z
18
+ .string()
19
+ .optional()
20
+ .describe("Optional description of the test result."),
21
+ }),
22
+ test_case_id: z
23
+ .string()
24
+ .describe("Identifier of the test case, e.g., 'TC-13'."),
25
+ });
26
+ /**
27
+ * Adds a test result to a specific test run via BrowserStack Test Management API.
28
+ */
29
+ export async function addTestResult(rawArgs) {
30
+ try {
31
+ const args = AddTestResultSchema.parse(rawArgs);
32
+ const url = `https://test-management.browserstack.com/api/v2/projects/${encodeURIComponent(args.project_identifier)}/test-runs/${encodeURIComponent(args.test_run_id)}/results`;
33
+ const body = {
34
+ test_result: args.test_result,
35
+ test_case_id: args.test_case_id,
36
+ };
37
+ const response = await axios.post(url, body, {
38
+ auth: {
39
+ username: config.browserstackUsername,
40
+ password: config.browserstackAccessKey,
41
+ },
42
+ headers: { "Content-Type": "application/json" },
43
+ });
44
+ const data = response.data;
45
+ if (!data.success) {
46
+ throw new Error(`API returned unsuccessful response: ${JSON.stringify(data)}`);
47
+ }
48
+ return {
49
+ content: [
50
+ {
51
+ type: "text",
52
+ text: `Successfully added test result with ID=${data["test-result"].id}`,
53
+ },
54
+ { type: "text", text: JSON.stringify(data["test-result"], null, 2) },
55
+ ],
56
+ };
57
+ }
58
+ catch (err) {
59
+ return formatAxiosError(err, "Failed to add test result to test run");
60
+ }
61
+ }
@@ -1,34 +1,27 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.CreateProjFoldSchema = void 0;
7
- exports.createProjectOrFolder = createProjectOrFolder;
8
- const axios_1 = __importDefault(require("axios"));
9
- const config_1 = __importDefault(require("../../config"));
10
- const zod_1 = require("zod");
11
- const error_1 = require("../../lib/error"); // or correct path
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 path
12
5
  // Schema for combined project/folder creation
13
- exports.CreateProjFoldSchema = zod_1.z.object({
14
- project_name: zod_1.z
6
+ export const CreateProjFoldSchema = z.object({
7
+ project_name: z
15
8
  .string()
16
9
  .optional()
17
10
  .describe("Name of the project to create."),
18
- project_description: zod_1.z
11
+ project_description: z
19
12
  .string()
20
13
  .optional()
21
14
  .describe("Description for the new project."),
22
- project_identifier: zod_1.z
15
+ project_identifier: z
23
16
  .string()
24
17
  .optional()
25
18
  .describe("Existing project identifier to use for folder creation."),
26
- folder_name: zod_1.z.string().optional().describe("Name of the folder to create."),
27
- folder_description: zod_1.z
19
+ folder_name: z.string().optional().describe("Name of the folder to create."),
20
+ folder_description: z
28
21
  .string()
29
22
  .optional()
30
23
  .describe("Description for the new folder."),
31
- parent_id: zod_1.z
24
+ parent_id: z
32
25
  .number()
33
26
  .optional()
34
27
  .describe("Parent folder ID; if omitted, folder is created at root."),
@@ -36,8 +29,8 @@ exports.CreateProjFoldSchema = zod_1.z.object({
36
29
  /**
37
30
  * Creates a project and/or folder in BrowserStack Test Management.
38
31
  */
39
- async function createProjectOrFolder(args) {
40
- const { project_name, project_description, project_identifier, folder_name, folder_description, parent_id, } = exports.CreateProjFoldSchema.parse(args);
32
+ export async function createProjectOrFolder(args) {
33
+ const { project_name, project_description, project_identifier, folder_name, folder_description, parent_id, } = CreateProjFoldSchema.parse(args);
41
34
  if (!project_name && !project_identifier && !folder_name) {
42
35
  throw new Error("Provide project_name (to create project), or project_identifier and folder_name (to create folder).");
43
36
  }
@@ -45,10 +38,10 @@ async function createProjectOrFolder(args) {
45
38
  // Step 1: Create project if project_name provided
46
39
  if (project_name) {
47
40
  try {
48
- const res = await axios_1.default.post("https://test-management.browserstack.com/api/v2/projects", { project: { name: project_name, description: project_description } }, {
41
+ const res = await axios.post("https://test-management.browserstack.com/api/v2/projects", { project: { name: project_name, description: project_description } }, {
49
42
  auth: {
50
- username: config_1.default.browserstackUsername,
51
- password: config_1.default.browserstackAccessKey,
43
+ username: config.browserstackUsername,
44
+ password: config.browserstackAccessKey,
52
45
  },
53
46
  headers: { "Content-Type": "application/json" },
54
47
  });
@@ -59,7 +52,7 @@ async function createProjectOrFolder(args) {
59
52
  projId = res.data.project.identifier;
60
53
  }
61
54
  catch (err) {
62
- return (0, error_1.formatAxiosError)(err, "Failed to create project..");
55
+ return formatAxiosError(err, "Failed to create project..");
63
56
  }
64
57
  }
65
58
  // Step 2: Create folder if folder_name provided
@@ -67,7 +60,7 @@ async function createProjectOrFolder(args) {
67
60
  if (!projId)
68
61
  throw new Error("Cannot create folder without project_identifier.");
69
62
  try {
70
- const res = await axios_1.default.post(`https://test-management.browserstack.com/api/v2/projects/${encodeURIComponent(projId)}/folders`, {
63
+ const res = await axios.post(`https://test-management.browserstack.com/api/v2/projects/${encodeURIComponent(projId)}/folders`, {
71
64
  folder: {
72
65
  name: folder_name,
73
66
  description: folder_description,
@@ -75,8 +68,8 @@ async function createProjectOrFolder(args) {
75
68
  },
76
69
  }, {
77
70
  auth: {
78
- username: config_1.default.browserstackUsername,
79
- password: config_1.default.browserstackAccessKey,
71
+ username: config.browserstackUsername,
72
+ password: config.browserstackAccessKey,
80
73
  },
81
74
  headers: { "Content-Type": "application/json" },
82
75
  });
@@ -95,7 +88,7 @@ async function createProjectOrFolder(args) {
95
88
  };
96
89
  }
97
90
  catch (err) {
98
- return (0, error_1.formatAxiosError)(err, "Failed to create folder.");
91
+ return formatAxiosError(err, "Failed to create folder.");
99
92
  }
100
93
  }
101
94
  // Only project was created
@@ -1,64 +1,56 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.CreateTestCaseSchema = void 0;
7
- exports.sanitizeArgs = sanitizeArgs;
8
- exports.createTestCase = createTestCase;
9
- const axios_1 = __importDefault(require("axios"));
10
- const config_1 = __importDefault(require("../../config"));
11
- const zod_1 = require("zod");
12
- const error_1 = require("../../lib/error"); // 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: zod_1.z
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: zod_1.z.string().describe("Name of the test case."),
21
- description: zod_1.z
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: zod_1.z
17
+ owner: z
26
18
  .string()
27
19
  .email()
28
20
  .describe("Email of the test case owner.")
29
21
  .optional(),
30
- preconditions: zod_1.z
22
+ preconditions: z
31
23
  .string()
32
24
  .optional()
33
25
  .describe("Any preconditions (HTML allowed)."),
34
- test_case_steps: zod_1.z
35
- .array(zod_1.z.object({
36
- step: zod_1.z.string().describe("Action to perform in this step."),
37
- result: zod_1.z.string().describe("Expected result of this step."),
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: zod_1.z
41
- .array(zod_1.z.string())
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: zod_1.z
36
+ issue_tracker: z
45
37
  .object({
46
- name: zod_1.z
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: zod_1.z.string().url().describe("Base URL of the issue tracker."),
41
+ host: z.string().url().describe("Base URL of the issue tracker."),
50
42
  })
51
43
  .optional(),
52
- tags: zod_1.z
53
- .array(zod_1.z.string())
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: zod_1.z
57
- .record(zod_1.z.string(), zod_1.z.string())
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 axios_1.default.post(`https://test-management.browserstack.com/api/v2/projects/${encodeURIComponent(params.project_identifier)}/folders/${encodeURIComponent(params.folder_id)}/test-cases`, body, {
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: config_1.default.browserstackUsername,
83
- password: config_1.default.browserstackAccessKey,
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 (0, error_1.formatAxiosError)(err, "Failed to create test case");
105
+ return formatAxiosError(err, "Failed to create test case");
114
106
  }
115
107
  }
@@ -1,28 +1,21 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
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_1 = __importDefault(require("../../config"));
10
- const zod_1 = require("zod");
11
- const error_1 = require("../../lib/error");
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
- exports.CreateTestRunSchema = zod_1.z.object({
16
- project_identifier: zod_1.z
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: zod_1.z.object({
20
- name: zod_1.z.string().describe("Name of the test run"),
21
- description: zod_1.z
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: zod_1.z
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: zod_1.z.array(zod_1.z.string()).optional().describe("Linked issue IDs"),
37
- issue_tracker: zod_1.z
38
- .object({ name: zod_1.z.string(), host: zod_1.z.string().url() })
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: zod_1.z
42
- .array(zod_1.z.string())
34
+ test_cases: z
35
+ .array(z.string())
43
36
  .optional()
44
37
  .describe("List of test case IDs"),
45
- folder_ids: zod_1.z
46
- .array(zod_1.z.number())
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 = exports.CreateTestRunSchema.parse(inputArgs);
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 axios_1.default.post(url, { test_run: args.test_run }, {
58
+ const response = await axios.post(url, { test_run: args.test_run }, {
66
59
  auth: {
67
- username: config_1.default.browserstackUsername,
68
- password: config_1.default.browserstackAccessKey,
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 (0, error_1.formatAxiosError)(err, "Failed to create test run");
81
+ return formatAxiosError(err, "Failed to create test run");
89
82
  }
90
83
  }
@@ -1,39 +1,32 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
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_1 = __importDefault(require("../../config"));
10
- const zod_1 = require("zod");
11
- const error_1 = require("../../lib/error");
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
- exports.ListTestCasesSchema = zod_1.z.object({
16
- project_identifier: zod_1.z
8
+ export const ListTestCasesSchema = z.object({
9
+ project_identifier: z
17
10
  .string()
18
- .describe("Identifier of the project to fetch test cases from. Example: PR-12345"),
19
- folder_id: zod_1.z
11
+ .describe("Identifier of the project to fetch test cases from. This id starts with a PR- and is followed by a number."),
12
+ folder_id: z
20
13
  .string()
21
14
  .optional()
22
15
  .describe("If provided, only return cases in this folder."),
23
- case_type: zod_1.z
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: zod_1.z
20
+ priority: z
28
21
  .string()
29
22
  .optional()
30
23
  .describe("Comma-separated list of priorities (e.g. critical,medium,low)."),
31
- p: zod_1.z.number().optional().describe("Page number."),
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 axios_1.default.get(url, {
42
+ const resp = await axios.get(url, {
50
43
  auth: {
51
- username: config_1.default.browserstackUsername,
52
- password: config_1.default.browserstackAccessKey,
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 (0, error_1.formatAxiosError)(err, "Failed to list test cases");
81
+ return formatAxiosError(err, "Failed to list test cases");
89
82
  }
90
83
  }
@@ -1,22 +1,15 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
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_1 = __importDefault(require("../../config"));
10
- const zod_1 = require("zod");
11
- const error_1 = require("../../lib/error");
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
- exports.ListTestRunsSchema = zod_1.z.object({
16
- project_identifier: zod_1.z
8
+ export const ListTestRunsSchema = z.object({
9
+ project_identifier: z
17
10
  .string()
18
- .describe("Identifier of the project to fetch test runs from (e.g., PR-12345)"),
19
- run_state: zod_1.z
11
+ .describe("Identifier of the project to fetch test runs from (usually starts with PR-)."),
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 axios_1.default.get(url, {
27
+ const resp = await axios.get(url, {
35
28
  auth: {
36
- username: config_1.default.browserstackUsername,
37
- password: config_1.default.browserstackAccessKey,
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 (0, error_1.formatAxiosError)(err, "Failed to list test runs");
59
+ return formatAxiosError(err, "Failed to list test runs");
67
60
  }
68
61
  }
@@ -0,0 +1,42 @@
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}`);
8
+ if (args.projectReferenceId.startsWith("PR-")) {
9
+ args.projectReferenceId = await projectIdentifierToId(args.projectReferenceId);
10
+ }
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);
15
+ if (!documentObj) {
16
+ return {
17
+ content: [
18
+ {
19
+ type: "text",
20
+ text: `Document with ID ${args.documentId} not found.`,
21
+ isError: true,
22
+ },
23
+ ],
24
+ isError: true,
25
+ };
26
+ }
27
+ const documentId = documentObj.fileId;
28
+ const document = documentObj.downloadUrl;
29
+ const source = "jira-on-prem";
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);
34
+ return {
35
+ content: [
36
+ {
37
+ type: "text",
38
+ text: resultString,
39
+ },
40
+ ],
41
+ };
42
+ }
@@ -1,25 +1,18 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
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_1 = __importDefault(require("../../config"));
10
- const zod_1 = require("zod");
11
- const error_1 = require("../../lib/error");
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
- exports.UpdateTestRunSchema = zod_1.z.object({
16
- project_identifier: zod_1.z
8
+ export const UpdateTestRunSchema = z.object({
9
+ project_identifier: z
17
10
  .string()
18
- .describe("Project identifier (e.g., PR-12345)"),
19
- test_run_id: zod_1.z.string().describe("Test run identifier (e.g., TR-678)"),
20
- test_run: zod_1.z.object({
21
- name: zod_1.z.string().optional().describe("New name of the test run"),
22
- run_state: zod_1.z
11
+ .describe("Identifier of the project (Starts with 'PR-')"),
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 axios_1.default.patch(url, body, {
35
+ const resp = await axios.patch(url, body, {
43
36
  auth: {
44
- username: config_1.default.browserstackUsername,
45
- password: config_1.default.browserstackAccessKey,
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 (0, error_1.formatAxiosError)(err, "Failed to update test run");
65
+ return formatAxiosError(err, "Failed to update test run");
73
66
  }
74
67
  }