[test-improver] Improve tests for server/http_server#5495
Merged
Conversation
- Convert TestNewHTTPServer to table-driven test covering multiple addresses - Add TestBuildMCPHTTPServer_ReturnsServerWithCorrectAddr - Add TestBuildMCPHTTPServer_RouteBuilderIsCalled - Add TestBuildMCPHTTPServer_RouteBuilderReceivesSessionTimeout - Add TestBuildMCPHTTPServer_HealthEndpointResponds - Add TestBuildMCPHTTPServer_OAuthDiscoveryEndpointResponds - Add TestBuildMCPHTTPServer_CustomRouteFromBuilder buildMCPHTTPServer was previously untested; the new tests cover its route builder invocation, session-timeout propagation, common endpoint registration, and custom route accessibility. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request expands test coverage for internal/server’s HTTP server construction, moving beyond the previously minimal newHTTPServer test to also validate the buildMCPHTTPServer scaffold that underpins both unified and routed server modes.
Changes:
- Refactors
TestNewHTTPServerinto a table-driven test covering multiple address formats. - Adds unit tests asserting
buildMCPHTTPServeraddress propagation, callback invocation, session-timeout forwarding, and handler wiring viahttptest.
Show a summary per file
| File | Description |
|---|---|
internal/server/http_server_test.go |
Refactors newHTTPServer test and adds several new tests covering buildMCPHTTPServer behavior and common endpoint wiring. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 1/1 changed files
- Comments generated: 2
Comment on lines
+100
to
+103
| // TestBuildMCPHTTPServer_HealthEndpointResponds verifies that the /health endpoint | ||
| // registered by buildMCPHTTPServer returns a successful response. | ||
| func TestBuildMCPHTTPServer_HealthEndpointResponds(t *testing.T) { | ||
| us, err := NewUnified(context.Background(), &config.Config{}) |
Comment on lines
+116
to
+121
| // TestBuildMCPHTTPServer_OAuthDiscoveryEndpointResponds verifies that the OAuth | ||
| // discovery endpoint registered by buildMCPHTTPServer returns 404. | ||
| func TestBuildMCPHTTPServer_OAuthDiscoveryEndpointResponds(t *testing.T) { | ||
| us, err := NewUnified(context.Background(), &config.Config{}) | ||
| require.NoError(t, err) | ||
| t.Cleanup(func() { us.Close() }) |
Collaborator
|
@copilot address review feedback |
Contributor
Addressed in commit |
This was referenced May 12, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Test Improvements:
http_server_test.goFile Analyzed
internal/server/http_server_test.gointernal/serverImprovements Made
1. Better Testing Patterns
TestNewHTTPServerfrom a single flat test to a table-driven test covering four distinct address formats (host:port,:port,127.0.0.1:0, empty string)t.Setenvfor environment variable control in timeout test2. Increased Coverage —
buildMCPHTTPServercontract coverageTestBuildMCPHTTPServer_ReturnsServerWithCorrectAddr— verifies the returned server is bound to the requested addressTestBuildMCPHTTPServer_RouteBuilderIsCalled— verifies the routeBuilder callback is actually invokedTestBuildMCPHTTPServer_RouteBuilderReceivesSessionTimeout— verifies the session timeout fromMCP_GATEWAY_SESSION_TIMEOUTenv var is passed through to the routeBuilderTestBuildMCPHTTPServer_CustomRouteFromBuilder— verifies routes registered inside the routeBuilder callback are accessible through the built server's handler3. Follow-up review feedback addressed
/healthand OAuth discovery coverage in other server test filesbuildMCPHTTPServer-specific contract assertions to reduce duplicated maintenance surface4. Cleaner & More Stable Tests
UnifiedServerandt.Cleanupfor teardownhttptest.NewRecorder/httptest.NewRequest— no real ports openedTest Execution
Targeted and full validation pass:
go test ./internal/server -run 'TestNewHTTPServer|TestBuildMCPHTTPServer'make agent-finishedWhy These Changes?
http_server_test.gooriginally had minimal coverage. This PR improves direct coverage ofnewHTTPServerandbuildMCPHTTPServer-specific contracts (address propagation, routeBuilder invocation, session-timeout forwarding, and custom route wiring) while removing duplicate endpoint assertions already covered elsewhere.Generated by Test Improver Workflow
Focuses on better patterns, increased coverage, and more stable tests
> Generated by Test Improver · ● 3.9M · ◷