Commit 88effd1
authored
[test] Add tests for server.parseRateLimitResetFromText edge cases (#6021)
## Test Coverage Improvement: `parseRateLimitResetFromText`
### Function Analyzed
- **Package**: `internal/server`
- **Function**: `parseRateLimitResetFromText`
- **File**: `internal/server/circuit_breaker.go` (lines 320–340)
- **Previous test file**: `internal/server/circuit_breaker_test.go` (4
cases)
- **New test file**:
`internal/server/circuit_breaker_parse_coverage_test.go` (8 cases)
- **Complexity**: Medium — regex-adjacent string parsing with multiple
exit paths
### Why This Function?
`parseRateLimitResetFromText` is called on every rate-limit tool result
to extract the GitHub API rate-limit reset window. It has several
distinct code branches that were not covered by the existing four test
cases:
| Branch | Existing coverage |
|---|---|
| Pattern not found | ✅ (`"some other error"`) |
| No `s`/`]`/`)` terminator | ✅ (`"rate reset in 42"`) |
| `secs == 0` | ✅ (`"rate reset in 0s"`) |
| `secs > 0` (happy path) | ✅ (`"rate reset in 42s"`) |
| `secs < 0` | ❌ |
| `ParseInt` error (non-numeric) | ❌ |
| Case-insensitive pattern search with correct offset into original text
| ❌ |
| `]` as terminator (vs `s`) | ❌ |
| Large value (3600 s) | ❌ |
| Whitespace padding before digits (`TrimSpace` path) | ❌ |
An additional case documents a subtle behaviour: the terminator search
in `IndexAny(rest, "s])")` is **case-sensitive**, so an uppercase `'S'`
is not recognised as the `'s'` terminator and the function falls through
to `']'`. This causes `ParseInt("10S")` to fail and the function returns
zero time — a non-obvious edge case now pinned as a test.
### Tests Added
- ✅ Negative seconds (`secs <= 0` branch) → zero time
- ✅ Non-numeric content (`ParseInt` error branch) → zero time
- ✅ Uppercase input + lowercase `'s'` terminator → verifies offset
arithmetic
- ✅ Uppercase `'S'` terminator — documents case-sensitive `IndexAny`
behaviour
- ✅ `']'` bracket terminator (second `IndexAny` character) → valid reset
time
- ✅ Large value (3600 s / 1-hour window) → valid reset time
- ✅ Whitespace-padded number → `TrimSpace` path → valid reset time
- ✅ Minimum positive value (1 s) → boundary test
### Notes
1 file changed
Lines changed: 106 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
0 commit comments