Skip to content

test(source/alloydb): create MCP integration tests#2843

Open
anubhav756 wants to merge 1 commit intomainfrom
anubhav-feat-native-mcp-alloydb
Open

test(source/alloydb): create MCP integration tests#2843
anubhav756 wants to merge 1 commit intomainfrom
anubhav-feat-native-mcp-alloydb

Conversation

@anubhav756
Copy link
Copy Markdown
Contributor

@anubhav756 anubhav756 commented Mar 25, 2026

Overview

This PR adds the mapped integration tests for AlloyDB tools using the native MCP harness.

Changes

  • Created tests/alloydb/alloydb_mcp_test.go to test database listing and cluster operations over the native /mcp pathway.
  • Achieves parity with coverage from the legacy alloydb_integration_test.go.

Checklist

  • Ensure the tests and linter pass

@anubhav756 anubhav756 self-assigned this Mar 25, 2026
@anubhav756 anubhav756 requested review from a team as code owners March 25, 2026 07:06
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refactors the AlloyDB integration tests to leverage a newly introduced native MCP JSON-RPC harness. This change standardizes how tools are invoked and their responses are processed within the test suite, leading to a more robust and maintainable testing framework. The update ensures that all AlloyDB-related tests interact with the tool endpoints through a consistent and unified interface.

Highlights

  • Migration to Native MCP JSON-RPC Harness: The AlloyDB integration tests have been migrated from direct HTTP API calls to a new native MCP JSON-RPC harness, centralizing tool invocation and response handling.
  • Simplified Tool Invocation: Replaced manual HTTP request creation and response parsing with helper functions like tests.GetMCPToolsList and tests.InvokeMCPTool for consistency.
  • Updated Response Handling: Modified test logic to parse responses from the new mcpResp structure, including specific handling for JSON-RPC errors, application-level errors, and successful results.
  • Removed Redundant Structs: The ToolResponse struct, previously used for parsing generic tool responses, was removed as its functionality is now handled by the new harness.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors several AlloyDB integration tests to use a new tests.InvokeMCPTool helper function and a standardized mcpResp structure for handling tool invocation responses. This includes updating runAlloyDBToolGetTest, runAlloyDBListClustersTest, runAlloyDBListInstancesTest, runAlloyDBGetClusterTest, runAlloyDBGetInstanceTest, runAlloyDBGetUserTest, and TestWaitToolEndpoints. However, several tests (runAlloyDBListUsersTest, runAlloyDBGetClusterTest, runAlloyDBGetInstanceTest, runAlloyDBGetUserTest) were only partially refactored, resulting in compilation errors due to undefined resultStr variables and incorrect usage of the old body.Result field. Additionally, error handling for io.ReadAll is missing in runAlloyDBListClustersTest and runAlloyDBListInstancesTest, which should be addressed for robustness.

@anubhav756 anubhav756 force-pushed the anubhav-feat-native-mcp-alloydb branch 13 times, most recently from ffeb175 to 2bbbe7a Compare March 25, 2026 08:57
@anubhav756 anubhav756 requested a review from a team as a code owner March 25, 2026 11:06
@anubhav756 anubhav756 force-pushed the anubhav-feat-native-mcp-alloydb branch from c4ee2d5 to feb8ced Compare March 25, 2026 11:16
@anubhav756 anubhav756 changed the title test(tests/alloydb): migrate to native MCP json-rpc harness test(tests/alloydb): migrate Postgres family of tests to MCP Mar 25, 2026
@anubhav756 anubhav756 changed the title test(tests/alloydb): migrate Postgres family of tests to MCP test(tests/pg-family): migrate Postgres family of tests to MCP Mar 25, 2026
@anubhav756 anubhav756 force-pushed the anubhav-feat-native-mcp-alloydb branch 6 times, most recently from 13ad9d5 to 3465675 Compare March 25, 2026 12:51
@anubhav756 anubhav756 force-pushed the anubhav-feat-native-mcp-http branch from 78ea17e to 1633f13 Compare March 30, 2026 12:41
@anubhav756 anubhav756 force-pushed the anubhav-feat-native-mcp-alloydb branch 2 times, most recently from 5edc923 to 3510b3a Compare March 30, 2026 12:43
@anubhav756 anubhav756 force-pushed the anubhav-feat-native-mcp-http branch 2 times, most recently from c1dc605 to 004eb32 Compare March 30, 2026 12:55
@anubhav756 anubhav756 force-pushed the anubhav-feat-native-mcp-alloydb branch from 3510b3a to c7d0b80 Compare March 30, 2026 12:57
@anubhav756 anubhav756 changed the title test(tests/alloydbpg): migrate Postgres family of tests to MCP test(tests/alloydb): migrate Postgres family of tests to MCP Mar 30, 2026
@anubhav756 anubhav756 changed the title test(tests/alloydb): migrate Postgres family of tests to MCP test(source/alloydb): migrate Postgres family of tests to MCP Mar 30, 2026
@anubhav756 anubhav756 force-pushed the anubhav-feat-native-mcp-http branch 2 times, most recently from 948e1d9 to 1dd5ab3 Compare March 30, 2026 13:47
@anubhav756 anubhav756 force-pushed the anubhav-feat-native-mcp-alloydb branch from c7d0b80 to 19e1bb2 Compare March 30, 2026 13:47
@anubhav756 anubhav756 force-pushed the anubhav-feat-native-mcp-http branch from 1dd5ab3 to df8a1e1 Compare March 30, 2026 13:51
@anubhav756 anubhav756 force-pushed the anubhav-feat-native-mcp-alloydb branch from 19e1bb2 to 67debd9 Compare March 30, 2026 13:51
@anubhav756 anubhav756 force-pushed the anubhav-feat-native-mcp-http branch from df8a1e1 to 5ed2bd1 Compare March 30, 2026 14:24
@anubhav756 anubhav756 force-pushed the anubhav-feat-native-mcp-alloydb branch from 67debd9 to 4d26ecd Compare March 30, 2026 14:25
@anubhav756 anubhav756 force-pushed the anubhav-feat-native-mcp-http branch from 5ed2bd1 to 815da44 Compare March 30, 2026 14:44
@anubhav756 anubhav756 force-pushed the anubhav-feat-native-mcp-alloydb branch 2 times, most recently from c9f38b7 to 31ac3eb Compare March 30, 2026 15:08
@anubhav756 anubhav756 changed the title test(source/alloydb): migrate Postgres family of tests to MCP test(source/alloydb): create MCP integration tests Mar 30, 2026
@anubhav756 anubhav756 force-pushed the anubhav-feat-native-mcp-http branch from 815da44 to f2c1e86 Compare March 30, 2026 21:52
@anubhav756 anubhav756 force-pushed the anubhav-feat-native-mcp-alloydb branch from 31ac3eb to f090f91 Compare March 30, 2026 21:52
@anubhav756 anubhav756 force-pushed the anubhav-feat-native-mcp-http branch from f2c1e86 to 62d2c4f Compare March 30, 2026 22:13
@anubhav756 anubhav756 force-pushed the anubhav-feat-native-mcp-alloydb branch from f090f91 to 5d14d97 Compare March 30, 2026 22:14
@anubhav756 anubhav756 force-pushed the anubhav-feat-native-mcp-http branch from 62d2c4f to d994aa8 Compare March 30, 2026 22:46
@anubhav756 anubhav756 force-pushed the anubhav-feat-native-mcp-alloydb branch from 5d14d97 to 8bae0e7 Compare March 30, 2026 22:47
@anubhav756 anubhav756 force-pushed the anubhav-feat-native-mcp-http branch from d994aa8 to 5749645 Compare March 30, 2026 22:54
})
}

func TestAlloyDBMCPReadEndpoints(t *testing.T) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are there TestAlloyDBCallTool vs TestAlloyDBMCPReadEndpoints?

Copy link
Copy Markdown
Contributor

@Yuan325 Yuan325 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you double-check the comments across all test cases? Just want to make sure the updates carried over to all of them. Thank you!

Comment on lines +288 to +292
for _, want := range tc.want {
if !regexp.MustCompile(want).MatchString(got) {
t.Errorf("Expected substring not found: %q", want)
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we expecting that all the want will be within got?

Can we keep the original check?: I think in here, we want to make sure that got doesn't return more cluster than it originally should.

var got []string
for _, cluster := range clustersData.Clusters {
	got = append(got, cluster.Name)
}

sort.Strings(got)
sort.Strings(tc.want)

if !reflect.DeepEqual(got, tc.want) {
	t.Errorf("cluster list mismatch:\n got: %v\nwant: %v", got, tc.want)
}

name string
args map[string]any
want []string
wantContains string
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
wantContains string
wantContentErr string

want vs wantContains feels very confusing.
If you can update for the other tests as well that'll be great, ty!

name string
args map[string]any
want []string
wantContains string
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
wantContains string
wantContentErr string

if mcpResp.Result.IsError {
t.Fatalf("returned error result: %v", mcpResp.Result)
}
if len(tc.want) > 0 {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we might be able to just remove this check since tc.want will always be >0.

if mcpResp.Result.IsError {
t.Fatalf("returned error result: %v", mcpResp.Result)
}
if len(tc.want) > 0 {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should be able to remove this check since tc.want is always >0

name string
args map[string]any
want map[string]any
wantContains string
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
wantContains string
wantContentErr string

if mcpResp.Result.IsError {
t.Fatalf("returned error result: %v", mcpResp.Result)
}
if tc.want != nil {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might not need to check this based on the test cases that we have.

name string
args map[string]any
want map[string]any
wantContains string
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
wantContains string
wantContentErr string

if mcpResp.Result.IsError {
t.Fatalf("returned error result: %v", mcpResp.Result)
}
if tc.want != nil {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

won't need to check this.

Suggested change
if tc.want != nil {

if mcpResp.Result.IsError {
t.Fatalf("returned error result: %v", mcpResp.Result)
}
if tc.want != nil {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

won't need to check this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants