[test] Add tests for launcher.handleErrorState and launcher.clearServerForRestart#7161
Merged
lpcox merged 2 commits intoJun 7, 2026
Merged
Conversation
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>
Contributor
There was a problem hiding this comment.
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
clearServerForRestartbehavior when a cached HTTP backend connection exists. - Adds tests covering
handleErrorStatewhen 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.Connectioninstances 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. |
Collaborator
|
@copilot resolve the merge conflicts in this pull request and address review feedback |
Contributor
Resolved the merge conflict with |
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:
launchererror-handling pathsFunctions Analyzed
handleErrorStateinternal/launcher/health_monitor.goclearServerForRestartinternal/launcher/launcher.gointernal/launcherWhy These Functions?
Both functions had two-to-four statement blocks that were never exercised:
clearServerForRestart— theif 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:if consecutiveFailures >= maxConsecutiveRestartFailureslog printed when a restart attempt bumps the counter exactly to the cap (not from already being at the cap).consecutiveFailures = 0+ info log) whenGetOrLaunchsucceeds after clearing the error state.Tests Added
TestClearServerForRestart_WithExistingConnection*mcp.Connectionfrom an HTTP mock MCP server viaGetOrLaunchl.connectionsclearServerForRestartand asserts the connection is closed and removedlauncher.golines 345–348TestHealthMonitor_ErrorStateReachesMaxFailuresconsecutiveFailures = maxConsecutiveRestartFailures - 1(= 2)checkAll()against a failing servermaxConsecutiveRestartFailures(= 3)health_monitor.golines 122–126TestHealthMonitor_SuccessfulRestartResetsFailureCountercheckAll()with a live HTTP mock backend soGetOrLaunchsucceedsconsecutiveFailuresis reset to 0 and server state isrunninghealth_monitor.golines 130–132Coverage Report
Test Execution
All tests pass (17 s, 0 failures):
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.iogo.yaml.ingolang.orggoogle.golang.orggopkg.inproxy.golang.orgSee Network Configuration for more information.