Skip to content

[test] Add tests for launcher.handleErrorState and launcher.clearServerForRestart#7161

Merged
lpcox merged 2 commits into
mainfrom
test/coverage-launcher-error-handling-57953e3bd28cd791
Jun 7, 2026
Merged

[test] Add tests for launcher.handleErrorState and launcher.clearServerForRestart#7161
lpcox merged 2 commits into
mainfrom
test/coverage-launcher-error-handling-57953e3bd28cd791

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot commented Jun 7, 2026

Test Coverage Improvement: launcher error-handling paths

Functions Analyzed

Function File Previous Coverage New Coverage
handleErrorState internal/launcher/health_monitor.go 74.1% 100%
clearServerForRestart internal/launcher/launcher.go 75% 100%
Package total internal/launcher 93.7% 96.0%

Why These Functions?

Both functions had two-to-four statement blocks that were never exercised:

  • clearServerForRestart — the if conn, ok := l.connections[serverID]; ok { conn.Close(); delete(...) } branch was dead because existing tests never established a live connection before calling the function.
  • handleErrorState — two paths were unreached:
    1. The inner if consecutiveFailures >= maxConsecutiveRestartFailures log printed when a restart attempt bumps the counter exactly to the cap (not from already being at the cap).
    2. The success path (consecutiveFailures = 0 + info log) when GetOrLaunch succeeds after clearing the error state.

Tests Added

TestClearServerForRestart_WithExistingConnection

  • Obtains a real *mcp.Connection from an HTTP mock MCP server via GetOrLaunch
  • Verifies the connection is stored in l.connections
  • Calls clearServerForRestart and asserts the connection is closed and removed
  • ✅ Covers launcher.go lines 345–348

TestHealthMonitor_ErrorStateReachesMaxFailures

  • Sets consecutiveFailures = maxConsecutiveRestartFailures - 1 (= 2)
  • Calls checkAll() against a failing server
  • Asserts the counter increments to exactly maxConsecutiveRestartFailures (= 3)
  • ✅ Covers health_monitor.go lines 122–126

TestHealthMonitor_SuccessfulRestartResetsFailureCounter

  • Places a server in error state with a non-zero failure count
  • Calls checkAll() with a live HTTP mock backend so GetOrLaunch succeeds
  • Asserts consecutiveFailures is reset to 0 and server state is running
  • ✅ Covers health_monitor.go lines 130–132

Coverage Report

Before: 93.7% (launcher package)
After:  96.0% (launcher package)
Improvement: +2.3 pp

handleErrorState:    74.1% → 100%
clearServerForRestart: 75%  → 100%

Test Execution

All tests pass (17 s, 0 failures):

ok  github.com/github/gh-aw-mcpg/internal/launcher  16.879s

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

Warning

Firewall blocked 6 domains

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

  • go.opentelemetry.io
  • go.yaml.in
  • golang.org
  • google.golang.org
  • gopkg.in
  • proxy.golang.org

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

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

See Network Configuration for more information.

Generated by Test Coverage Improver · sonnet46 14M ·

Cover three previously-untested paths in internal/launcher:

- clearServerForRestart: connection close/delete branch (lines 345-348)
  when a live connection is stored in l.connections before clearing
- handleErrorState: inner 'max failures reached' log (line 122-126)
  when consecutiveFailures reaches maxConsecutiveRestartFailures
- handleErrorState: success path (lines 130-132) where GetOrLaunch
  succeeds after clearServerForRestart (verified with HTTP mock server)

Before: health_monitor.go handleErrorState 74.1%, clearServerForRestart 75%
After:  both at 100%; launcher package overall 93.7% → 96.0%

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@lpcox lpcox marked this pull request as ready for review June 7, 2026 17:17
Copilot AI review requested due to automatic review settings June 7, 2026 17:17
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 targeted unit tests to improve coverage of internal/launcher error-handling and restart paths, specifically exercising previously-uncovered branches in HealthMonitor.handleErrorState and Launcher.clearServerForRestart.

Changes:

  • Adds a test covering clearServerForRestart behavior when a cached HTTP backend connection exists.
  • Adds tests covering handleErrorState when restart failures hit the max cap, and when a subsequent restart succeeds and resets the counter.
  • Uses an HTTP mock MCP server to obtain real *mcp.Connection instances for the new coverage paths.
Show a summary per file
File Description
internal/launcher/health_monitor_test.go Adds new tests to cover handleErrorState and clearServerForRestart branches using failing stdio configs and an HTTP mock MCP server.

Copilot's findings

Tip

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

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

Comment on lines +187 to +188
l := newTestLauncher(servers)
l.recordError("bad-server", "process crashed")
Comment on lines +209 to +210
l := newTestLauncher(servers)

Comment on lines +139 to +140
// TestClearServerForRestart_WithExistingConnection tests that clearServerForRestart
// closes and removes a connection that is stored in l.connections.
@lpcox
Copy link
Copy Markdown
Collaborator

lpcox commented Jun 7, 2026

@copilot resolve the merge conflicts in this pull request and address review feedback

Copy link
Copy Markdown
Contributor

Copilot AI commented Jun 7, 2026

@copilot resolve the merge conflicts in this pull request and address review feedback

Resolved the merge conflict with main and addressed the launcher test review feedback in commit bc7c70aa (added missing defer l.Close() in the affected tests and updated the test comment to match assertions).

Copilot finished work on behalf of lpcox June 7, 2026 17:32
Copilot AI requested a review from lpcox June 7, 2026 17:32
@lpcox lpcox merged commit 27e350c into main Jun 7, 2026
16 checks passed
@lpcox lpcox deleted the test/coverage-launcher-error-handling-57953e3bd28cd791 branch June 7, 2026 17:35
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