Skip to content

[test-improver] Improve tests for server/http_server#5495

Merged
lpcox merged 2 commits into
mainfrom
test-improver/http-server-coverage-6847bbfe0358e0a3
May 12, 2026
Merged

[test-improver] Improve tests for server/http_server#5495
lpcox merged 2 commits into
mainfrom
test-improver/http-server-coverage-6847bbfe0358e0a3

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot commented May 12, 2026

Test Improvements: http_server_test.go

File Analyzed

  • Test File: internal/server/http_server_test.go
  • Package: internal/server

Improvements Made

1. Better Testing Patterns

  • ✅ Converted TestNewHTTPServer from a single flat test to a table-driven test covering four distinct address formats (host:port, :port, 127.0.0.1:0, empty string)
  • ✅ Added descriptive subtest names for each scenario
  • ✅ Used t.Setenv for environment variable control in timeout test

2. Increased Coverage — buildMCPHTTPServer contract coverage

  • TestBuildMCPHTTPServer_ReturnsServerWithCorrectAddr — verifies the returned server is bound to the requested address
  • TestBuildMCPHTTPServer_RouteBuilderIsCalled — verifies the routeBuilder callback is actually invoked
  • TestBuildMCPHTTPServer_RouteBuilderReceivesSessionTimeout — verifies the session timeout from MCP_GATEWAY_SESSION_TIMEOUT env var is passed through to the routeBuilder
  • TestBuildMCPHTTPServer_CustomRouteFromBuilder — verifies routes registered inside the routeBuilder callback are accessible through the built server's handler

3. Follow-up review feedback addressed

  • ✅ Removed redundant endpoint tests that duplicated existing /health and OAuth discovery coverage in other server test files
  • ✅ Kept only buildMCPHTTPServer-specific contract assertions to reduce duplicated maintenance surface

4. Cleaner & More Stable Tests

  • ✅ Each test is fully isolated with its own UnifiedServer and t.Cleanup for teardown
  • ✅ Uses httptest.NewRecorder / httptest.NewRequest — no real ports opened
  • ✅ No timing dependencies

Test Execution

Targeted and full validation pass:

  • go test ./internal/server -run 'TestNewHTTPServer|TestBuildMCPHTTPServer'
  • make agent-finished

Why These Changes?

http_server_test.go originally had minimal coverage. This PR improves direct coverage of newHTTPServer and buildMCPHTTPServer-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 ·

- 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>
@lpcox lpcox marked this pull request as ready for review May 12, 2026 00:19
Copilot AI review requested due to automatic review settings May 12, 2026 00:19
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 TestNewHTTPServer into a table-driven test covering multiple address formats.
  • Adds unit tests asserting buildMCPHTTPServer address propagation, callback invocation, session-timeout forwarding, and handler wiring via httptest.
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 thread internal/server/http_server_test.go Outdated
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 thread internal/server/http_server_test.go Outdated
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() })
@lpcox
Copy link
Copy Markdown
Collaborator

lpcox commented May 12, 2026

@copilot address review feedback

Copy link
Copy Markdown
Contributor

Copilot AI commented May 12, 2026

@copilot address review feedback

Addressed in commit 8e493e8 by removing the redundant buildMCPHTTPServer health and OAuth discovery endpoint tests, keeping the build-specific contract coverage.

Copilot AI requested a review from lpcox May 12, 2026 00:28
Copilot finished work on behalf of lpcox May 12, 2026 00:28
@lpcox lpcox merged commit 750b010 into main May 12, 2026
28 checks passed
@lpcox lpcox deleted the test-improver/http-server-coverage-6847bbfe0358e0a3 branch May 12, 2026 00:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants