Skip to content

Commit dfd3ae0

Browse files
refactor: improve type exports and formatting in constants and tools (#44)
1 parent 6dd14f2 commit dfd3ae0

File tree

6 files changed

+43
-22
lines changed

6 files changed

+43
-22
lines changed

src/lib/constants.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ export const AppAutomateLogType = {
1515
CrashLogs: "crashLogs",
1616
} as const;
1717

18-
export type SessionType = typeof SessionType[keyof typeof SessionType];
19-
export type AutomateLogType = typeof AutomateLogType[keyof typeof AutomateLogType];
20-
export type AppAutomateLogType = typeof AppAutomateLogType[keyof typeof AppAutomateLogType];
18+
export type SessionType = (typeof SessionType)[keyof typeof SessionType];
19+
export type AutomateLogType =
20+
(typeof AutomateLogType)[keyof typeof AutomateLogType];
21+
export type AppAutomateLogType =
22+
(typeof AppAutomateLogType)[keyof typeof AppAutomateLogType];

src/tools/automate-utils/fetch-screenshots.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ import { assertOkResponse, maybeCompressBase64 } from "../../lib/utils.js";
33
import { SessionType } from "../../lib/constants.js";
44

55
//Extracts screenshot URLs from BrowserStack session logs
6-
async function extractScreenshotUrls(sessionId: string, sessionType: SessionType): Promise<string[]> {
7-
6+
async function extractScreenshotUrls(
7+
sessionId: string,
8+
sessionType: SessionType,
9+
): Promise<string[]> {
810
const credentials = `${config.browserstackUsername}:${config.browserstackAccessKey}`;
911
const auth = Buffer.from(credentials).toString("base64");
1012

11-
const baseUrl = `https://api.browserstack.com/${sessionType === SessionType.Automate ? 'automate' : 'app-automate'}`;
13+
const baseUrl = `https://api.browserstack.com/${sessionType === SessionType.Automate ? "automate" : "app-automate"}`;
1214

1315
const url = `${baseUrl}/sessions/${sessionId}/logs`;
1416
const response = await fetch(url, {
@@ -21,7 +23,7 @@ async function extractScreenshotUrls(sessionId: string, sessionType: SessionType
2123
await assertOkResponse(response, "Session");
2224

2325
const text = await response.text();
24-
26+
2527
const urls: string[] = [];
2628
const SCREENSHOT_PATTERN = /REQUEST.*GET.*\/screenshot/;
2729
const RESPONSE_VALUE_PATTERN = /"value"\s*:\s*"([^"]+)"/;
@@ -68,7 +70,10 @@ async function convertUrlsToBase64(
6870
}
6971

7072
//Fetches and converts screenshot URLs to base64 encoded images
71-
export async function fetchAutomationScreenshots(sessionId: string, sessionType: SessionType = SessionType.Automate) {
73+
export async function fetchAutomationScreenshots(
74+
sessionId: string,
75+
sessionType: SessionType = SessionType.Automate,
76+
) {
7277
const urls = await extractScreenshotUrls(sessionId, sessionType);
7378
if (urls.length === 0) {
7479
return [];

src/tools/automate.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ export async function fetchAutomationScreenshotsTool(args: {
1212
sessionType: SessionType;
1313
}): Promise<CallToolResult> {
1414
try {
15-
const screenshots = await fetchAutomationScreenshots(args.sessionId, args.sessionType);
15+
const screenshots = await fetchAutomationScreenshots(
16+
args.sessionId,
17+
args.sessionType,
18+
);
1619

1720
if (screenshots.length === 0) {
1821
return {
@@ -60,14 +63,21 @@ export default function addAutomationTools(server: McpServer) {
6063
.describe("The BrowserStack session ID to fetch screenshots from"),
6164
sessionType: z
6265
.enum([SessionType.Automate, SessionType.AppAutomate])
63-
.describe("Type of BrowserStack session")
66+
.describe("Type of BrowserStack session"),
6467
},
6568
async (args) => {
6669
try {
67-
trackMCP("fetchAutomationScreenshots", server.server.getClientVersion()!);
70+
trackMCP(
71+
"fetchAutomationScreenshots",
72+
server.server.getClientVersion()!,
73+
);
6874
return await fetchAutomationScreenshotsTool(args);
6975
} catch (error) {
70-
trackMCP("fetchAutomationScreenshots", server.server.getClientVersion()!,error);
76+
trackMCP(
77+
"fetchAutomationScreenshots",
78+
server.server.getClientVersion()!,
79+
error,
80+
);
7181
const errorMessage =
7282
error instanceof Error ? error.message : "Unknown error";
7383
return {

src/tools/getFailureLogs.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ import {
1515
retrieveCrashLogs,
1616
} from "./failurelogs-utils/app-automate.js";
1717
import { trackMCP } from "../lib/instrumentation.js";
18-
import { AppAutomateLogType, AutomateLogType, SessionType } from "../lib/constants.js";
18+
import {
19+
AppAutomateLogType,
20+
AutomateLogType,
21+
SessionType,
22+
} from "../lib/constants.js";
1923

2024
type LogType = AutomateLogType | AppAutomateLogType;
2125
type SessionTypeValues = SessionType;

src/tools/testmanagement.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -250,18 +250,18 @@ export async function addTestResultTool(
250250
/**
251251
* Uploads files such as PDRs or screenshots to BrowserStack Test Management and get file mapping ID back.
252252
*/
253-
export async function uploadFileTestManagementTool(
253+
export async function uploadProductRequirementFileTool(
254254
args: z.infer<typeof UploadFileSchema>,
255255
): Promise<CallToolResult> {
256256
try {
257257
trackMCP(
258-
"uploadFileTestManagement",
258+
"uploadProductRequirementFile",
259259
serverInstance.server.getClientVersion()!,
260260
);
261261
return await uploadFile(args);
262262
} catch (err) {
263263
trackMCP(
264-
"uploadFileTestManagement",
264+
"uploadProductRequirementFile",
265265
serverInstance.server.getClientVersion()!,
266266
err,
267267
);
@@ -367,10 +367,10 @@ export default function addTestManagementTools(server: McpServer) {
367367
);
368368

369369
server.tool(
370-
"uploadFileTestManagement",
370+
"uploadProductRequirementFile",
371371
"Upload files such as PDRs or PDFs to BrowserStack Test Management and get file mapping ID back. Its Used for generating test cases from file.",
372372
UploadFileSchema.shape,
373-
uploadFileTestManagementTool,
373+
uploadProductRequirementFileTool,
374374
);
375375
server.tool(
376376
"createTestCasesFromFile",

tests/tools/testmanagement.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
addTestResultTool,
66
listTestRunsTool,
77
updateTestRunTool,
8-
uploadFileTestManagementTool,
8+
uploadProductRequirementFileTool,
99
createTestCasesFromFileTool
1010
} from '../../src/tools/testmanagement';
1111
import addTestManagementTools from '../../src/tools/testmanagement';
@@ -443,12 +443,12 @@ const mockFileId = 12345;
443443
const mockDownloadUrl = "https://cdn.browserstack.com/mock.pdf";
444444
const mockContext = { sendNotification: vi.fn(), _meta: { progressToken: "test-progress-token" } };
445445

446-
describe("uploadFileTestManagementTool", () => {
446+
describe("uploadProductRequirementFileTool", () => {
447447
beforeEach(() => vi.resetAllMocks());
448448

449449
it("returns error when file does not exist", async () => {
450450
(fs.existsSync as Mock).mockReturnValue(false);
451-
const res = await uploadFileTestManagementTool({ project_identifier: testProjectId, file_path: testFilePath });
451+
const res = await uploadProductRequirementFileTool({ project_identifier: testProjectId, file_path: testFilePath });
452452
expect(res.isError).toBe(true);
453453
expect(res.content[0].text).toContain("does not exist");
454454
});
@@ -472,7 +472,7 @@ describe("uploadFileTestManagementTool", () => {
472472
};
473473
mockedAxios.get.mockResolvedValue({ data: { success: true, projects: [{ identifier: testProjectId, id: "999" }] } });
474474
mockedAxios.post.mockResolvedValue(mockUpload);
475-
const res = await uploadFileTestManagementTool({ project_identifier: testProjectId, file_path: testFilePath });
475+
const res = await uploadProductRequirementFileTool({ project_identifier: testProjectId, file_path: testFilePath });
476476
expect(res.isError ?? false).toBe(false);
477477
expect(res.content[1].text).toContain("documentID");
478478
});

0 commit comments

Comments
 (0)