[test] Add tests for launcher.GetOrLaunchForSession#1291
Merged
Conversation
Improves coverage of GetOrLaunchForSession from 22.9% to 79.2% and overall launcher package from 84.4% to 93.0%. New tests added: - TestGetOrLaunchForSession_StdioSessionPoolHit: verifies session pool cache hit returns the existing connection without re-launching - TestGetOrLaunchForSession_StdioLaunchFailure: verifies error is returned when stdio backend fails to launch - TestGetOrLaunchForSession_DirectCommandWarningInContainer: exercises the security warning path for direct (non-docker) commands in containers - TestGetOrLaunchForSession_StdioSessionPoolHit_DifferentSessions: verifies independent session IDs each return their cached connections Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds comprehensive test coverage for the GetOrLaunchForSession function in the launcher package, improving coverage from 22.9% to 79.2% and bringing overall package coverage to 93.0%. The function manages session-scoped MCP backend connections with complex logic including double-check locking, session pool caching, and container security warnings.
Changes:
- Added 4 new test cases targeting previously uncovered code paths (session pool cache hits, launch failures, container warnings, multiple sessions)
- Introduced
newMockHTTPMCPServerhelper function to support testing session pool behavior without requiring actual MCP protocol implementations
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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 Coverage Improvement: GetOrLaunchForSession
Function Analyzed
internal/launcherGetOrLaunchForSessioninternal/launcher/launcher.go:180Why This Function?
GetOrLaunchForSessionhad the lowest coverage (22.9%) among complex functions in the codebase. It manages session-scoped MCP backend connections with a double-check locking pattern, security warnings for containerized environments, and multiple backend types. Despite 18 existing tests, all were skipped because they assumedechoimplements the MCP protocol handshake. Only the HTTP backend and invalid-server tests provided any coverage.Tests Added
TestGetOrLaunchForSession_StdioSessionPoolHit): Pre-populates the session pool using a real HTTP connection pointer, verifies cache hit returns the existing connection without re-launchingTestGetOrLaunchForSession_StdioLaunchFailure): Uses a nonexistent command to verify error propagation from the stdio launch pathTestGetOrLaunchForSession_DirectCommandWarningInContainer): SetsrunningInContainer=trueto exercise the security warning branch for direct (non-docker) commandsTestGetOrLaunchForSession_StdioSessionPoolHit_DifferentSessions): Verifies independent session IDs each resolve their own cached connectionsCoverage Report
Generated by Test Coverage Improver
Next run will target the next most complex under-tested function