diff --git a/src/lib/constants.ts b/src/lib/constants.ts index d0ccf1a..01fe078 100644 --- a/src/lib/constants.ts +++ b/src/lib/constants.ts @@ -15,6 +15,8 @@ export const AppAutomateLogType = { CrashLogs: "crashLogs", } as const; -export type SessionType = typeof SessionType[keyof typeof SessionType]; -export type AutomateLogType = typeof AutomateLogType[keyof typeof AutomateLogType]; -export type AppAutomateLogType = typeof AppAutomateLogType[keyof typeof AppAutomateLogType]; \ No newline at end of file +export type SessionType = (typeof SessionType)[keyof typeof SessionType]; +export type AutomateLogType = + (typeof AutomateLogType)[keyof typeof AutomateLogType]; +export type AppAutomateLogType = + (typeof AppAutomateLogType)[keyof typeof AppAutomateLogType]; diff --git a/src/tools/automate-utils/fetch-screenshots.ts b/src/tools/automate-utils/fetch-screenshots.ts index 623a5a8..eabbc7a 100644 --- a/src/tools/automate-utils/fetch-screenshots.ts +++ b/src/tools/automate-utils/fetch-screenshots.ts @@ -3,12 +3,14 @@ import { assertOkResponse, maybeCompressBase64 } from "../../lib/utils.js"; import { SessionType } from "../../lib/constants.js"; //Extracts screenshot URLs from BrowserStack session logs -async function extractScreenshotUrls(sessionId: string, sessionType: SessionType): Promise { - +async function extractScreenshotUrls( + sessionId: string, + sessionType: SessionType, +): Promise { const credentials = `${config.browserstackUsername}:${config.browserstackAccessKey}`; const auth = Buffer.from(credentials).toString("base64"); - const baseUrl = `https://api.browserstack.com/${sessionType === SessionType.Automate ? 'automate' : 'app-automate'}`; + const baseUrl = `https://api.browserstack.com/${sessionType === SessionType.Automate ? "automate" : "app-automate"}`; const url = `${baseUrl}/sessions/${sessionId}/logs`; const response = await fetch(url, { @@ -21,7 +23,7 @@ async function extractScreenshotUrls(sessionId: string, sessionType: SessionType await assertOkResponse(response, "Session"); const text = await response.text(); - + const urls: string[] = []; const SCREENSHOT_PATTERN = /REQUEST.*GET.*\/screenshot/; const RESPONSE_VALUE_PATTERN = /"value"\s*:\s*"([^"]+)"/; @@ -68,7 +70,10 @@ async function convertUrlsToBase64( } //Fetches and converts screenshot URLs to base64 encoded images -export async function fetchAutomationScreenshots(sessionId: string, sessionType: SessionType = SessionType.Automate) { +export async function fetchAutomationScreenshots( + sessionId: string, + sessionType: SessionType = SessionType.Automate, +) { const urls = await extractScreenshotUrls(sessionId, sessionType); if (urls.length === 0) { return []; diff --git a/src/tools/automate.ts b/src/tools/automate.ts index 83da8c2..b0f1f73 100644 --- a/src/tools/automate.ts +++ b/src/tools/automate.ts @@ -12,7 +12,10 @@ export async function fetchAutomationScreenshotsTool(args: { sessionType: SessionType; }): Promise { try { - const screenshots = await fetchAutomationScreenshots(args.sessionId, args.sessionType); + const screenshots = await fetchAutomationScreenshots( + args.sessionId, + args.sessionType, + ); if (screenshots.length === 0) { return { @@ -60,14 +63,21 @@ export default function addAutomationTools(server: McpServer) { .describe("The BrowserStack session ID to fetch screenshots from"), sessionType: z .enum([SessionType.Automate, SessionType.AppAutomate]) - .describe("Type of BrowserStack session") + .describe("Type of BrowserStack session"), }, async (args) => { try { - trackMCP("fetchAutomationScreenshots", server.server.getClientVersion()!); + trackMCP( + "fetchAutomationScreenshots", + server.server.getClientVersion()!, + ); return await fetchAutomationScreenshotsTool(args); } catch (error) { - trackMCP("fetchAutomationScreenshots", server.server.getClientVersion()!,error); + trackMCP( + "fetchAutomationScreenshots", + server.server.getClientVersion()!, + error, + ); const errorMessage = error instanceof Error ? error.message : "Unknown error"; return { diff --git a/src/tools/getFailureLogs.ts b/src/tools/getFailureLogs.ts index 0c2f072..33dc184 100644 --- a/src/tools/getFailureLogs.ts +++ b/src/tools/getFailureLogs.ts @@ -15,7 +15,11 @@ import { retrieveCrashLogs, } from "./failurelogs-utils/app-automate.js"; import { trackMCP } from "../lib/instrumentation.js"; -import { AppAutomateLogType, AutomateLogType, SessionType } from "../lib/constants.js"; +import { + AppAutomateLogType, + AutomateLogType, + SessionType, +} from "../lib/constants.js"; type LogType = AutomateLogType | AppAutomateLogType; type SessionTypeValues = SessionType; diff --git a/src/tools/testmanagement.ts b/src/tools/testmanagement.ts index a2a8277..e5c60bc 100644 --- a/src/tools/testmanagement.ts +++ b/src/tools/testmanagement.ts @@ -250,18 +250,18 @@ export async function addTestResultTool( /** * Uploads files such as PDRs or screenshots to BrowserStack Test Management and get file mapping ID back. */ -export async function uploadFileTestManagementTool( +export async function uploadProductRequirementFileTool( args: z.infer, ): Promise { try { trackMCP( - "uploadFileTestManagement", + "uploadProductRequirementFile", serverInstance.server.getClientVersion()!, ); return await uploadFile(args); } catch (err) { trackMCP( - "uploadFileTestManagement", + "uploadProductRequirementFile", serverInstance.server.getClientVersion()!, err, ); @@ -367,10 +367,10 @@ export default function addTestManagementTools(server: McpServer) { ); server.tool( - "uploadFileTestManagement", + "uploadProductRequirementFile", "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.", UploadFileSchema.shape, - uploadFileTestManagementTool, + uploadProductRequirementFileTool, ); server.tool( "createTestCasesFromFile", diff --git a/tests/tools/testmanagement.test.ts b/tests/tools/testmanagement.test.ts index b852557..1195329 100644 --- a/tests/tools/testmanagement.test.ts +++ b/tests/tools/testmanagement.test.ts @@ -5,7 +5,7 @@ import { addTestResultTool, listTestRunsTool, updateTestRunTool, - uploadFileTestManagementTool, + uploadProductRequirementFileTool, createTestCasesFromFileTool } from '../../src/tools/testmanagement'; import addTestManagementTools from '../../src/tools/testmanagement'; @@ -443,12 +443,12 @@ const mockFileId = 12345; const mockDownloadUrl = "https://cdn.browserstack.com/mock.pdf"; const mockContext = { sendNotification: vi.fn(), _meta: { progressToken: "test-progress-token" } }; -describe("uploadFileTestManagementTool", () => { +describe("uploadProductRequirementFileTool", () => { beforeEach(() => vi.resetAllMocks()); it("returns error when file does not exist", async () => { (fs.existsSync as Mock).mockReturnValue(false); - const res = await uploadFileTestManagementTool({ project_identifier: testProjectId, file_path: testFilePath }); + const res = await uploadProductRequirementFileTool({ project_identifier: testProjectId, file_path: testFilePath }); expect(res.isError).toBe(true); expect(res.content[0].text).toContain("does not exist"); }); @@ -472,7 +472,7 @@ describe("uploadFileTestManagementTool", () => { }; mockedAxios.get.mockResolvedValue({ data: { success: true, projects: [{ identifier: testProjectId, id: "999" }] } }); mockedAxios.post.mockResolvedValue(mockUpload); - const res = await uploadFileTestManagementTool({ project_identifier: testProjectId, file_path: testFilePath }); + const res = await uploadProductRequirementFileTool({ project_identifier: testProjectId, file_path: testFilePath }); expect(res.isError ?? false).toBe(false); expect(res.content[1].text).toContain("documentID"); });