[test-improver] Improve tests for launcher/health_monitor#7124
Draft
github-actions[bot] wants to merge 1 commit into
Draft
[test-improver] Improve tests for launcher/health_monitor#7124github-actions[bot] wants to merge 1 commit into
github-actions[bot] wants to merge 1 commit into
Conversation
…lure paths Add two tests to health_monitor_test.go that cover the previously uncovered branches in handleErrorState: - TestHealthMonitor_LogsErrorWhenMaxFailuresReached: starts the consecutive-failure counter at maxConsecutiveRestartFailures-1 so the next failed restart pushes it exactly to the threshold, exercising the "reached max restart attempts" log path. - TestHealthMonitor_SuccessfulRestartResetCounter: uses an in-process httptest.Server that speaks plain JSON-RPC to let GetOrLaunch succeed, covering the success branch that resets the counter to 0 and transitions the server back to running state. Also extracts mockMCPHandler as a reusable test helper and adds the encoding/json, net/http, net/http/httptest imports required by the new tests. handleErrorState coverage: 75% → 100% launcher package coverage: 94.3% → 95.4% Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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 Improvements:
health_monitor_test.goFile Analyzed
internal/launcher/health_monitor_test.gointernal/launcherImprovements Made
1. Increased Coverage
ifblock insidehandleErrorStatethat fires when a failed restart increments the counter to exactlymaxConsecutiveRestartFailures.httptest.Serverspeaking plain JSON-RPC soGetOrLaunchactually succeeds, covering the branch that resetsconsecutiveFailuresto 0 and verifies the server transitions to"running".handleErrorState2. Cleaner Test Structure
mockMCPHandleras a reusable helper to avoid duplicating mock server setup in future tests.require.Equalfor the critical counter assertion in the max-failures test (stops the test immediately if the assertion fails, preventing confusing downstream failures).Test Execution
All tests pass:
Why These Changes?
handleErrorStatehad two unreachable-from-existing-tests branches:The log emitted when a restart failure increments the counter to
maxConsecutiveRestartFailures(not just above it). Existing tests either started at 0 (never reached max in one step) or started at max (early-return path, no restart attempted).The success path (
consecutiveFailures = 0) which requiresGetOrLaunchto actually return a connection. All existing tests usednonexistent-binary-xyzas the command, ensuring the restart always failed.The new tests are deterministic, fast (sub-millisecond for the failure test; the HTTP test uses a local
httptest.Server), and isolated.Generated by Test Improver Workflow
Focuses on better patterns, increased coverage, and more stable tests
Warning
Firewall blocked 1 domain
The following domain was blocked by the firewall during workflow execution:
index.crates.ioSee Network Configuration for more information.