#4086: Test/add backoff tests
Cluster:
Backoff and Duration Tests
Closes #4013
## Summary
Adds missing unit tests for `src/infra/backoff.ts` to verify exponential backoff calculations and abortable sleep behavior.
## Changes
- **src/infra/backoff.test.ts**: New test file covering `computeBackoff` and `sleepWithAbort`.
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
Adds unit coverage for the backoff utilities by introducing `src/infra/backoff.test.ts`, validating exponential growth, max capping, jitter bounds, and `sleepWithAbort` resolve/abort behavior. Also extends the existing unhandled rejection tests with a regression case for Node/undici `TypeError("fetch failed")` when the underlying `cause` is missing or has an unknown code, matching the updated fallback logic in `isTransientNetworkError`.
Overall this fits into the `src/infra` layer by strengthening the safety net around retry timing and the gateway’s “don’t crash on transient network issues” behavior.
<h3>Confidence Score: 4/5</h3>
- This PR is safe to merge; changes are tests and a small tweak to transient error classification.
- No obvious functional regressions in the updated `fetch failed` handling, and the new tests exercise the intended behavior. Main concern is test reliability: one jitter test is probabilistic and the fake-timers test doesn’t guarantee cleanup on failure.
- src/infra/backoff.test.ts (test determinism and timer cleanup)
<!-- greptile_other_comments_section -->
**Context used:**
- Context from `dashboard` - CLAUDE.md ([source](https://app.greptile.com/review/custom-context?memory=fd949e91-5c3a-4ab5-90a1-cbe184fd6ce8))
- Context from `dashboard` - AGENTS.md ([source](https://app.greptile.com/review/custom-context?memory=0d0c8278-ef8e-4d6c-ab21-f5527e322f13))
<!-- /greptile_comment -->
Most Similar PRs
#4095: Test/add format duration tests
by TechWizard9999 · 2026-01-29
85.4%
#12684: Test: add missing unit tests for src/utils modules
by shaynhornik · 2026-02-09
78.7%
#12995: feat(infra): Add retry with exponential backoff for transient failures
by trevorgordon981 · 2026-02-10
78.7%
#19540: feat: add timeout and exponential backoff retry for frontend API calls
by Mozzzaic · 2026-02-17
77.3%
#11101: fix: handle AbortError and WebSocket 1006 in unhandled rejection ha...
by Nipurn123 · 2026-02-07
77.1%
#20496: test(utils): add comprehensive unit tests for utility functions
by masifislamm · 2026-02-19
76.1%
#10276: fix(infra): use bidirectional jitter in computeBackoff
by programming-pupil · 2026-02-06
75.7%
#11874: fix: handle fetch rejections in provider usage withTimeout
by Zjianru · 2026-02-08
75.6%
#11421: Tests: add unit tests for infra/format-duration
by PythonUser42 · 2026-02-07
75.4%
#4137: [AI-assisted] test(cli): add missing test cases for parseDurationMs
by sind00 · 2026-01-29
75.2%