[test-improver] Improve tests for server/circuit_breaker#3837
Merged
Conversation
Add four new test functions to cover previously untested paths: - TestCircuitBreakerState_String: verifies all String() representations including the defensive UNKNOWN default case (circuitBreakerState(99)) - TestFormatResetAt: directly tests the formatResetAt helper for both zero time (returns 'unknown') and non-zero time (RFC3339 + duration hint) - TestIsRateLimitText_Direct: directly tests isRateLimitText with all five match patterns plus edge cases (case insensitivity, empty string, 'rate limit' without qualifying context) - TestCircuitBreaker_RecordRateLimitWhenAlreadyOpen: tests the OPEN→OPEN path in RecordRateLimit, verifying resetAt is updated on subsequent rate-limit errors while the circuit remains OPEN Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR strengthens internal/server’s circuit breaker unit test coverage by adding direct, table-driven tests for previously untested helper/state paths, improving confidence in rate-limit detection and circuit state handling.
Changes:
- Added direct unit tests for
circuitBreakerState.String()including the defensive unknown-state case. - Added isolated tests for
formatResetAt()(zero vs non-zero time formatting). - Added direct pattern/edge-case coverage for
isRateLimitText()and the OPEN→OPENRecordRateLimit()path (reset time update while staying OPEN).
Show a summary per file
| File | Description |
|---|---|
| internal/server/circuit_breaker_test.go | Adds targeted table-driven tests covering helper functions and an additional circuit breaker state transition path. |
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: 0
This was referenced Apr 15, 2026
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.
File Analyzed
internal/server/circuit_breaker_test.gointernal/serverImprovements Made
1. Better Testing Patterns
t.Parallel()subtestsTestType_Scenarioconventionrequirefor fatal preconditions,assertfor non-fatal checks2. Increased Coverage
Four previously untested code paths now have direct tests:
TestCircuitBreakerState_StringString()method for all 4 states including defensivedefault: "UNKNOWN"caseTestFormatResetAtformatResetAt()helper — zero time and non-zero RFC3339+duration outputTestIsRateLimitText_DirectisRateLimitText()— all 5 match patterns plus edge cases (case insensitivity, empty string,"rate limit"without qualifier)TestCircuitBreaker_RecordRateLimitWhenAlreadyOpenRecordRateLimit()OPEN→OPEN path — verifiesresetAtis updated on subsequent errors while circuit stays OPENPreviously these were either:
String()default case,formatResetAt()directlyisRateLimitText()viaisRateLimitToolResult(), the OPEN→OPEN path via logging only3. No Regressions
Why These Changes?
The circuit breaker is security-critical infrastructure (rate-limit protection). The four gaps found were:
String()method'sdefaultcase is defensive code that can never occur with valid iota values — but it should be documented via a test so future readers know it exists and won't get dropped in refactoring.formatResetAtis called inErrCircuitOpen.Error()and several log lines but had no isolated test — a regression in its formatting would only surface through integration test failures.isRateLimitTexthas 5 OR-combined patterns. The indirect tests covered only 4 of them throughisRateLimitToolResult. The "rate limit combined with 403" branch (strings.Contains(lower, "rate limit") && strings.Contains(lower, "403")) had no test for a string that contains"rate limit"without"403"being present — confirming the boundary between true/false is correctly placed.RecordRateLimitpath (updatingresetAtwhile already open) is a normal operational scenario (multiple rate-limit errors in a row) that had no test at all.Generated by Test Improver Workflow
Focuses on better patterns, increased coverage, and more stable tests