-
Notifications
You must be signed in to change notification settings - Fork 48
fix: getBuildId & failedTestIds mcp tool #323
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
SavioBS629
wants to merge
8
commits into
browserstack:main
Choose a base branch
from
SavioBS629:getBuildId-fix
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+221
−5
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
4a37f4b
fix: getBuildId mcp tool
SavioBS629 442d468
fix: fixed failedTestIds
SavioBS629 35b9a51
Merge branch 'main' of github.com:SavioBS629/mcp-server into getBuild…
SavioBS629 be1f166
feat: add listBuildId tool for recent build IDs
SavioBS629 d7ab77e
feat: updated description and reverted getBuildId changes
SavioBS629 cb612fc
feat: added test and exported extractFailedTestIds
SavioBS629 86ad299
fix: updated the comments
SavioBS629 2fe3e35
fix: updated listBuildId
SavioBS629 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| /** | ||
| * Same as getBuildId, but without the user_name filter — returns the latest | ||
| * build for a project + build name across all users (not just the caller's). | ||
| */ | ||
| export async function listBuildId( | ||
| projectName: string, | ||
| buildName: string, | ||
| username: string, | ||
| accessKey: string, | ||
| ): Promise<string> { | ||
| const url = new URL( | ||
| "https://api-automation.browserstack.com/ext/v1/builds/latest", | ||
| ); | ||
| url.searchParams.append("project_name", projectName); | ||
| url.searchParams.append("build_name", buildName); | ||
|
|
||
| const authHeader = | ||
| "Basic " + Buffer.from(`${username}:${accessKey}`).toString("base64"); | ||
|
|
||
| const response = await fetch(url.toString(), { | ||
| headers: { | ||
| Authorization: authHeader, | ||
| "Content-Type": "application/json", | ||
| }, | ||
| }); | ||
|
|
||
| if (!response.ok) { | ||
| throw new Error( | ||
| `Failed to fetch build ID: ${response.status} ${response.statusText}`, | ||
| ); | ||
| } | ||
|
|
||
| const data = await response.json(); | ||
| return data.build_id; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| import { describe, it, expect } from "vitest"; | ||
| import { extractFailedTestIds } from "../../src/tools/rca-agent-utils/get-failed-test-id"; | ||
| import { TestStatus } from "../../src/tools/rca-agent-utils/types"; | ||
|
|
||
| const node = (details: any, display_name?: string, children: any[] = []) => | ||
| ({ details, display_name, children }) as any; | ||
|
|
||
| describe("extractFailedTestIds", () => { | ||
| it("includes a status match even when run_count is 0 (the regression this fixes)", () => { | ||
| const hierarchy = [ | ||
| node( | ||
| { | ||
| status: TestStatus.FAILED, | ||
| run_count: 0, | ||
| observability_url: "https://observability.bs.com/x?details=111", | ||
| }, | ||
| "zero-run failure", | ||
| ), | ||
| ]; | ||
|
|
||
| const result = extractFailedTestIds(hierarchy, TestStatus.FAILED); | ||
|
|
||
| expect(result).toEqual([ | ||
| { test_id: "111", test_name: "zero-run failure" }, | ||
| ]); | ||
| }); | ||
|
|
||
| it("skips nodes with a non-matching status", () => { | ||
| const hierarchy = [ | ||
| node({ | ||
| status: TestStatus.PASSED, | ||
| run_count: 3, | ||
| observability_url: "https://observability.bs.com/x?details=222", | ||
| }), | ||
| ]; | ||
|
|
||
| expect(extractFailedTestIds(hierarchy, TestStatus.FAILED)).toEqual([]); | ||
| }); | ||
|
|
||
| it("does not crash and skips a node with missing details", () => { | ||
| const hierarchy = [node(undefined, "no details"), node(null, "null")]; | ||
|
|
||
| expect(extractFailedTestIds(hierarchy, TestStatus.FAILED)).toEqual([]); | ||
| }); | ||
|
|
||
| it("skips a status match that has no observability_url (no id to extract)", () => { | ||
| const hierarchy = [node({ status: TestStatus.FAILED }, "no url")]; | ||
|
|
||
| expect(extractFailedTestIds(hierarchy, TestStatus.FAILED)).toEqual([]); | ||
| }); | ||
|
|
||
| it("recurses into children and collects nested matches", () => { | ||
| const hierarchy = [ | ||
| node({ status: TestStatus.PASSED }, "parent", [ | ||
| node( | ||
| { | ||
| status: TestStatus.FAILED, | ||
| observability_url: "https://observability.bs.com/x?details=333", | ||
| }, | ||
| "nested failure", | ||
| ), | ||
| ]), | ||
| ]; | ||
|
|
||
| expect(extractFailedTestIds(hierarchy, TestStatus.FAILED)).toEqual([ | ||
| { test_id: "333", test_name: "nested failure" }, | ||
| ]); | ||
| }); | ||
|
|
||
| it("falls back to a generated name when display_name is absent", () => { | ||
| const hierarchy = [ | ||
| node({ | ||
| status: TestStatus.FAILED, | ||
| observability_url: "https://observability.bs.com/x?details=444", | ||
| }), | ||
| ]; | ||
|
|
||
| expect(extractFailedTestIds(hierarchy, TestStatus.FAILED)).toEqual([ | ||
| { test_id: "444", test_name: "Test 444" }, | ||
| ]); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.