Skip to content

[test] Add tests for mcp.NewHTTPConnection with OIDC provider#9341

Merged
lpcox merged 2 commits into
mainfrom
add-tests-mcp-NewHTTPConnection-oidc-b61c4211cbd62ff8
Jul 14, 2026
Merged

[test] Add tests for mcp.NewHTTPConnection with OIDC provider#9341
lpcox merged 2 commits into
mainfrom
add-tests-mcp-NewHTTPConnection-oidc-b61c4211cbd62ff8

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

Test Coverage Improvement: NewHTTPConnection

Function Analyzed

  • Package: internal/mcp
  • Function: NewHTTPConnection
  • Previous Coverage: 82.1%
  • New Coverage: 89.3%
  • Complexity: Medium-High (9 branches including OIDC, keepalive, header injection paths)

Why This Function?

NewHTTPConnection is the primary entry point for establishing HTTP-based MCP connections. It has a meaningful oidcProvider != nil branch that builds a dedicated OIDC-authenticated HTTP client, but every existing test passed nil for the OIDC provider, leaving the branch entirely untested.

Tests Added

  • TestNewHTTPConnection_WithOIDCProvider — confirms that a non-nil oidcProvider causes buildHTTPClientWithOIDC to be invoked and that the resulting connection includes an OIDC Bearer token on every outgoing request.
  • TestNewHTTPConnection_WithOIDCAndStaticHeaders — confirms that non-Authorization static headers are preserved while the OIDC round-tripper correctly overrides any static Authorization header.

Both tests use the existing newTestOIDCServer / makeTestJWT test helpers from http_transport_test.go.

Coverage Report

Before: 82.1% coverage (NewHTTPConnection)
After:  89.3% coverage (NewHTTPConnection)
Improvement: +7.2%

Package total: 92.4% -> 92.7%

Test Execution

All tests pass:

=== RUN   TestNewHTTPConnection_WithOIDCProvider
--- PASS: TestNewHTTPConnection_WithOIDCProvider (0.00s)
=== RUN   TestNewHTTPConnection_WithOIDCAndStaticHeaders
--- PASS: TestNewHTTPConnection_WithOIDCAndStaticHeaders (0.00s)
PASS
ok  github.com/github/gh-aw-mcpg/internal/mcp  0.012s

Generated by Test Coverage Improver
Next run will target the next most complex under-tested function

Warning

Firewall blocked 8 domains

The following domains were blocked by the firewall during workflow execution:

  • awmgmcpg
  • go.opentelemetry.io
  • go.yaml.in
  • golang.org
  • google.golang.org
  • gopkg.in
  • proxy.golang.org
  • releaseassets.githubusercontent.com

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "awmgmcpg"
    - "go.opentelemetry.io"
    - "go.yaml.in"
    - "golang.org"
    - "google.golang.org"
    - "gopkg.in"
    - "proxy.golang.org"
    - "releaseassets.githubusercontent.com"

See Network Configuration for more information.

Generated by Test Coverage Improver · 637 AIC · ⊞ 6.9K ·

Test the previously-uncovered oidcProvider != nil branch in
NewHTTPConnection. Two new table-style tests:
- TestNewHTTPConnection_WithOIDCProvider: verifies that a non-nil
  oidcProvider causes the OIDC round-tripper to inject a Bearer token
  on every outgoing request.
- TestNewHTTPConnection_WithOIDCAndStaticHeaders: verifies that static
  (non-Authorization) headers are preserved while the OIDC token
  overrides a static Authorization header.

Coverage for NewHTTPConnection rises from 82.1% → 89.3%.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@lpcox
lpcox marked this pull request as ready for review July 14, 2026 17:37
Copilot AI review requested due to automatic review settings July 14, 2026 17:37
@lpcox

lpcox commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator

Copilot AI left a comment

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.

Pull request overview

Adds integration-style coverage for OIDC-authenticated HTTP MCP connections.

Changes:

  • Tests OIDC bearer-token injection.
  • Tests OIDC precedence over static authorization while preserving custom headers.
Show a summary per file
File Description
internal/mcp/oidc_connection_test.go Adds OIDC connection and header-layering tests.

Review details

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 1/1 changed files
  • Comments generated: 0
  • Review effort level: Medium

Copilot AI commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

@copilot fix the failing lint check https://github.com/github/gh-aw-mcpg/actions/runs/29352703106/job/87158869644?pr=9341

Fixed in commit fix: format oidc_connection_test.go with gofmt — ran gofmt on internal/mcp/oidc_connection_test.go to resolve the formatting issue.

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