Skip to content

Commit b67bea9

Browse files
committed
refactor: update params and improve descriptions
1 parent a1c2f26 commit b67bea9

File tree

4 files changed

+36
-22
lines changed

4 files changed

+36
-22
lines changed

src/tools/rca-agent-utils/constants.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ export const FETCH_RCA_PARAMS = {
1111
};
1212

1313
export const GET_BUILD_ID_PARAMS = {
14-
projectName: z
14+
browserStackProjectName: z
1515
.string()
1616
.describe(
17-
"The Browserstack project name used while creation of test run. Check browserstack.yml or similar project configuration files. If found extract it and provide to user, IF not found or unsure, prompt the user for this value. Do not make assumptions",
17+
"The BrowserStack project name used during test run creation. Action: First, check browserstack.yml or any equivalent project configuration files. If the project name is found, extract and return it. If it is not found or if there is any uncertainty, immediately prompt the user to provide the value. Do not infer, guess, or assume a default.",
1818
),
19-
buildName: z
19+
browserStackBuildName: z
2020
.string()
2121
.describe(
22-
"The Browserstack build name used while creation of test run. Check browserstack.yml or similar project configuration files. If found extract it and provide to user, IF not found or unsure, prompt the user for this value. Do not make assumptions",
22+
"The BrowserStack build name used during test run creation. Action: First, check browserstack.yml or any equivalent project configuration files. If the build name is found, extract and return it. If it is not found or if there is any uncertainty, immediately prompt the user to provide the value. Do not infer, guess, or assume a default.",
2323
),
2424
};
2525

src/tools/rca-agent-utils/get-failed-test-id.ts

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,22 +36,25 @@ export async function getTestIds(
3636

3737
// Extract failed IDs from current page
3838
if (data.hierarchy && data.hierarchy.length > 0) {
39-
const currentFailedTests = extractFailedTestIds(data.hierarchy);
39+
const currentFailedTests = extractFailedTestIds(data.hierarchy, status);
4040
allFailedTests = allFailedTests.concat(currentFailedTests);
4141
}
4242

4343
// Check for pagination termination conditions
44-
if (!data.pagination?.has_next || !data.pagination.next_page) {
44+
if (
45+
!data.pagination?.has_next ||
46+
!data.pagination.next_page ||
47+
requestNumber >= 5
48+
) {
4549
break;
4650
}
4751

48-
// Safety limit to prevent runaway requests
49-
if (requestNumber >= 5) {
50-
break;
51-
}
52+
const params: Record<string, string> = {
53+
next_page: data.pagination.next_page,
54+
};
55+
if (status) params.test_statuses = status;
5256

53-
// Prepare next request
54-
url = `${baseUrl}?next_page=${encodeURIComponent(data.pagination.next_page)}`;
57+
url = `${baseUrl}?${new URLSearchParams(params).toString()}`;
5558
}
5659

5760
// Return unique failed test IDs
@@ -63,11 +66,14 @@ export async function getTestIds(
6366
}
6467

6568
// Recursive function to extract failed test IDs from hierarchy
66-
function extractFailedTestIds(hierarchy: TestDetails[]): FailedTestInfo[] {
69+
function extractFailedTestIds(
70+
hierarchy: TestDetails[],
71+
status?: TestStatus,
72+
): FailedTestInfo[] {
6773
let failedTests: FailedTestInfo[] = [];
6874

6975
for (const node of hierarchy) {
70-
if (node.details?.status === "failed" && node.details?.run_count) {
76+
if (node.details?.status === status && node.details?.run_count) {
7177
if (node.details?.observability_url) {
7278
const idMatch = node.details.observability_url.match(/details=(\d+)/);
7379
if (idMatch) {
@@ -80,7 +86,9 @@ function extractFailedTestIds(hierarchy: TestDetails[]): FailedTestInfo[] {
8086
}
8187

8288
if (node.children && node.children.length > 0) {
83-
failedTests = failedTests.concat(extractFailedTestIds(node.children));
89+
failedTests = failedTests.concat(
90+
extractFailedTestIds(node.children, status),
91+
);
8492
}
8593
}
8694

src/tools/rca-agent-utils/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,8 @@ export interface RCATestCase {
4848
export interface RCAResponse {
4949
testCases: RCATestCase[];
5050
}
51+
52+
export interface BuildIdArgs {
53+
browserStackProjectName: string;
54+
browserStackBuildName: string;
55+
}

src/tools/rca-agent.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { formatRCAData } from "./rca-agent-utils/format-rca.js";
1010
import { TestStatus } from "./rca-agent-utils/types.js";
1111
import { handleMCPError } from "../lib/utils.js";
1212
import { trackMCP } from "../index.js";
13+
import { BuildIdArgs } from "./rca-agent-utils/types.js";
1314
import {
1415
FETCH_RCA_PARAMS,
1516
GET_BUILD_ID_PARAMS,
@@ -18,22 +19,22 @@ import {
1819

1920
// Tool function to fetch build ID
2021
export async function getBuildIdTool(
21-
args: {
22-
projectName: string;
23-
buildName: string;
24-
},
22+
args: BuildIdArgs,
2523
config: BrowserStackConfig,
2624
): Promise<CallToolResult> {
2725
try {
28-
const { projectName, buildName } = args;
26+
const { browserStackProjectName, browserStackBuildName } = args;
27+
2928
const authString = getBrowserStackAuth(config);
3029
const [username, accessKey] = authString.split(":");
30+
3131
const buildId = await getBuildId(
32-
projectName,
33-
buildName,
32+
browserStackProjectName,
33+
browserStackBuildName,
3434
username,
3535
accessKey,
3636
);
37+
3738
return {
3839
content: [
3940
{

0 commit comments

Comments
 (0)