Skip to content

[test] Add tests for launcher.GetOrLaunchForSession#1291

Merged
lpcox merged 1 commit intomainfrom
add-tests-launcher-getorlaunchforsession-3197a3da87adadb4
Feb 23, 2026
Merged

[test] Add tests for launcher.GetOrLaunchForSession#1291
lpcox merged 1 commit intomainfrom
add-tests-launcher-getorlaunchforsession-3197a3da87adadb4

Conversation

@github-actions
Copy link
Contributor

Test Coverage Improvement: GetOrLaunchForSession

Function Analyzed

  • Package: internal/launcher
  • Function: GetOrLaunchForSession
  • File: internal/launcher/launcher.go:180
  • Previous Coverage: 22.9%
  • New Coverage: 79.2%
  • Package Coverage: 84.4% → 93.0%
  • Complexity: High (multiple branches: unknown server, HTTP backend, session pool cache hit, double-check lock, container warning, stdio launch)

Why This Function?

GetOrLaunchForSession had 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 assumed echo implements the MCP protocol handshake. Only the HTTP backend and invalid-server tests provided any coverage.

Tests Added

  • Session pool cache hit (TestGetOrLaunchForSession_StdioSessionPoolHit): Pre-populates the session pool using a real HTTP connection pointer, verifies cache hit returns the existing connection without re-launching
  • Launch failure error handling (TestGetOrLaunchForSession_StdioLaunchFailure): Uses a nonexistent command to verify error propagation from the stdio launch path
  • Container security warning path (TestGetOrLaunchForSession_DirectCommandWarningInContainer): Sets runningInContainer=true to exercise the security warning branch for direct (non-docker) commands
  • Multiple session cache hits (TestGetOrLaunchForSession_StdioSessionPoolHit_DifferentSessions): Verifies independent session IDs each resolve their own cached connections

Coverage Report

Before: 22.9% coverage  (GetOrLaunchForSession)
After:  79.2% coverage  (GetOrLaunchForSession)
Improvement: +56.3%

Package overall:
Before: 84.4%
After:  93.0%
````

## Test Execution

All new tests pass:
````
ok  	github.com/github/gh-aw-mcpg/internal/launcher	17.090s	coverage: 93.0% of statements

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

AI generated by Test Coverage Improver

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>
@lpcox lpcox marked this pull request as ready for review February 23, 2026 04:06
Copilot AI review requested due to automatic review settings February 23, 2026 04:06
@lpcox lpcox merged commit 9f8ecbf into main Feb 23, 2026
2 checks passed
@lpcox lpcox deleted the add-tests-launcher-getorlaunchforsession-3197a3da87adadb4 branch February 23, 2026 04:06
Copy link
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 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 newMockHTTPMCPServer helper 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.

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