[test-improver] Improve tests for mcp package by github-actions[bot] · Pull Request #8109 · github/gh-aw-mcpg · GitHub
Skip to content

[test-improver] Improve tests for mcp package#8109

Merged
lpcox merged 2 commits into
mainfrom
test-improve-mcp-prompts-capability-14512ea9722b28cf
Jun 26, 2026
Merged

[test-improver] Improve tests for mcp package#8109
lpcox merged 2 commits into
mainfrom
test-improve-mcp-prompts-capability-14512ea9722b28cf

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

Test Improvements: reconnect_sdk_test.go

File Analyzed

  • Test File: internal/mcp/reconnect_sdk_test.go
  • Package: internal/mcp
  • Lines Added: +125

Improvements Made

1. Better Testing Patterns

  • ✅ Table-driven sub-tests with descriptive names for BackendHasPromptsCapability
  • ✅ Each sub-test uses its own real streamable HTTP test server for isolation
  • ✅ Clear assertion messages explain what each test verifies

2. Increased Coverage

  • ✅ Added TestBackendHasPromptsCapability covering all 4 branches:
    • Nil session (no SDK session available) → returns false
    • Session with "prompts": {} in capabilities → returns true
    • Session with empty capabilities (no prompts key) → returns false
    • Session with nil capabilities (omitted from initialize response) → returns false
  • ✅ Added TestServerInfo_NilServerInfoInResult covering the initResult.ServerInfo == nil guard (server omits serverInfo from initialize response → returns "", "")
Function Before After
BackendHasPromptsCapability 0% 100%
ServerInfo 85.7% 100%
mcp package total 91.0% 92.3%

3. Cleaner & More Stable Tests

  • ✅ Follows existing newStreamableMCPTestServer + newStreamableConn patterns
  • ✅ Uses t.Cleanup via newStreamableConn for automatic connection teardown
  • ✅ Real HTTP test servers provide deterministic, isolated test scenarios
  • ✅ Consistent defer srv.Close() cleanup for test servers

Test Execution

All tests pass:

=== RUN   TestBackendHasPromptsCapability
=== RUN   TestBackendHasPromptsCapability/nil_session_returns_false
=== RUN   TestBackendHasPromptsCapability/session_with_prompts_capability_returns_true
=== RUN   TestBackendHasPromptsCapability/session_without_prompts_capability_returns_false
=== RUN   TestBackendHasPromptsCapability/session_with_nil_capabilities_returns_false
--- PASS: TestBackendHasPromptsCapability (0.00s)
=== RUN   TestServerInfo_NilServerInfoInResult
--- PASS: TestServerInfo_NilServerInfoInResult (0.00s)
PASS
ok  github.com/github/gh-aw-mcpg/internal/mcp  2.952s  coverage: 92.3% of statements

Why These Changes?

BackendHasPromptsCapability was completely untested (0%) despite being an important guard that prevents issuing prompts/list requests to backends that don't support them — a call that can corrupt an SDK session with an EOF response. The function has 4 distinct branches, all of which are now covered.

ServerInfo was at 85.7% because the initResult.ServerInfo == nil branch (server doesn't return serverInfo in its initialize response) was never exercised. The new test creates a server that omits serverInfo, covering that final edge case.


Generated by Test Improver Workflow
Focuses on better patterns, increased coverage, and more stable tests

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • index.crates.io

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

network:
  allowed:
    - defaults
    - "index.crates.io"

See Network Configuration for more information.

Generated by Test Improver · 1.5K AIC · ⊞ 29.5K ·

Add tests to reconnect_sdk_test.go covering previously untested branches:

- TestBackendHasPromptsCapability: 4 sub-tests covering nil session (returns
  false), session with prompts capability (returns true), session without
  prompts capability (returns false), and session with nil capabilities
  (returns false). Coverage: 0% → 100%.

- TestServerInfo_NilServerInfoInResult: tests the branch where the server's
  initialize response omits the serverInfo field, exercising the
  initResult.ServerInfo == nil guard. Coverage: 85.7% → 100%.

Overall mcp package coverage: 91.0% → 92.3%.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

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

This PR improves unit test coverage and robustness for the internal/mcp package by adding missing edge-case tests around SDK session initialization-derived state (capabilities and serverInfo).

Changes:

  • Added subtests covering Connection.BackendHasPromptsCapability() across nil session, prompts-present, prompts-absent, and nil-capabilities scenarios.
  • Added a test covering the ServerInfo() guard path when the initialize response omits serverInfo.
  • Uses isolated per-subtest streamable HTTP test servers to keep scenarios deterministic.
Show a summary per file
File Description
internal/mcp/reconnect_sdk_test.go Adds missing tests for prompts capability detection and ServerInfo() nil-serverInfo edge case using streamable test servers.

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: 1
  • Review effort level: Low

Comment thread internal/mcp/reconnect_sdk_test.go Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
GitHub Advanced Security started work on behalf of lpcox June 26, 2026 15:08 View session
GitHub Advanced Security finished work on behalf of lpcox June 26, 2026 15:09
@lpcox lpcox merged commit 483a826 into main Jun 26, 2026
27 checks passed
@lpcox lpcox deleted the test-improve-mcp-prompts-capability-14512ea9722b28cf branch June 26, 2026 15:14
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.

2 participants