Skip to content

Add MCP server unit tests using InMemoryTransport (no subprocess)#30223

Merged
pelikhan merged 4 commits intomainfrom
copilot/convert-mcp-integration-tests
May 5, 2026
Merged

Add MCP server unit tests using InMemoryTransport (no subprocess)#30223
pelikhan merged 4 commits intomainfrom
copilot/convert-mcp-integration-tests

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 4, 2026

All MCP server tests were tagged //go:build integration and spawned actual binary subprocesses, making them unavailable to make test-unit and requiring a compiled binary. The SDK provides mcp.NewInMemoryTransports() for in-process testing.

Changes

  • New file pkg/cli/mcp_server_unit_test.go (//go:build !integration) — four unit tests wiring server and client entirely in-process via the existing connectInMemory helper:
Test Coverage
TestMCPServerUnit_ListTools All 10 expected tools registered in createMCPServer
TestMCPServerUnit_ServerCapabilities Tools.ListChanged=false (static tool set)
TestMCPServerUnit_StatusTool Status tool returns valid JSON; calls GetWorkflowStatuses directly (no subprocess)
TestMCPServerUnit_CompileTool Compile tool passthrough with mock execCmd; validates --json flag forwarding
// All tests use the existing connectInMemory helper — no subprocess, no binary required
server := createMCPServer("", "", false, "")
session := connectInMemory(t, server)

result, err := session.ListTools(ctx, &mcp.ListToolsParams{})
// or: session.CallTool(ctx, &mcp.CallToolParams{Name: "status", ...})

The existing integration tests in mcp_server_tools_test.go and mcp_server_compile_test.go are preserved for end-to-end binary validation.

Copilot AI and others added 2 commits May 4, 2026 21:05
Copilot AI changed the title [WIP] Convert MCP server integration tests to unit tests using InMemoryTransport Add MCP server unit tests using InMemoryTransport (no subprocess) May 4, 2026
Copilot AI requested a review from gh-aw-bot May 4, 2026 21:11
@pelikhan pelikhan marked this pull request as ready for review May 5, 2026 00:37
Copilot AI review requested due to automatic review settings May 5, 2026 00:37
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

Adds non-integration (unit) test coverage for the MCP server by using the MCP SDK’s in-memory transports, enabling make test-unit to exercise tool registration/capabilities and key tool behaviors without requiring a prebuilt gh-aw binary subprocess.

Changes:

  • Introduces new !integration unit tests that connect an MCP client/server in-process via the existing connectInMemory helper.
  • Adds focused unit coverage for tool listing, server capabilities, the status tool JSON response, and compile tool flag forwarding via a mocked execCmd.
  • Updates the metrics-collector locked workflow to include GH_AW_INFO_VERSION.
Show a summary per file
File Description
pkg/cli/mcp_server_unit_test.go Adds in-process MCP server unit tests using NewInMemoryTransports to avoid requiring a compiled binary for unit test runs.
.github/workflows/metrics-collector.lock.yml Adds GH_AW_INFO_VERSION to the workflow environment configuration.

Copilot's findings

Tip

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

  • Files reviewed: 2/2 changed files
  • Comments generated: 1


// With no workflow files in the directory, the response should be a valid empty JSON array.
var statuses []any
require.NoError(t, json.Unmarshal([]byte(textContent.Text), &statuses), "status tool should return valid JSON")
@pelikhan
Copy link
Copy Markdown
Collaborator

pelikhan commented May 5, 2026

@copilot review all comments

Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 5, 2026

@copilot review all comments

Addressed the reviewer's feedback in be9107a: added require.NotNil(t, statuses, ...) before the assert.Empty check in TestMCPServerUnit_StatusTool, so the test correctly fails if the tool ever returns JSON null rather than an empty array [].

Copilot AI requested a review from pelikhan May 5, 2026 00:52
@pelikhan pelikhan merged commit a944a6b into main May 5, 2026
@pelikhan pelikhan deleted the copilot/convert-mcp-integration-tests branch May 5, 2026 01:26
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.

[plan] Convert MCP server integration tests to unit tests using InMemoryTransport

4 participants