Add unit tests covering all 429 retry scenarios with proper backoff behavior:
- Test429WithRetryAfterMetricVerification: Verifies 429 with Retry-After header
honours the delay before retry, returns success, makes exactly 2 upstream calls,
and increments zai_proxy_retry_attempts_total{reason="429"} once
- Test429WithoutRetryAfterMetricVerification: Verifies 429 without Retry-After
uses exponential backoff up to MAX_RETRIES, surfaces 429, makes MAX_RETRIES+1
upstream calls, and increments metric MAX_RETRIES times
- Test429MultipleRetriesMetricVerification: Verifies multiple 429 retries with
correct metric increments and upstream call counts
- Test429MetricLabelVerification: Verifies retry metric uses correct reason labels
- Test429ConcurrentMetricVerification: Verifies concurrent 429 responses are
tracked correctly in metrics
- Integration tests: TestIntegration429WithRetryAfter, TestIntegration429NoHeader
test retry behavior through real proxy handler
All tests pass with -race detector. Uses test infrastructure from bf-3zp.
Add NewAdaptiveRateLimiterWithWindow constructor for test-only refactor:
- Production code uses NewAdaptiveRateLimiter with default 30s window
- Tests can inject shorter durations (e.g., 100ms) for fast execution
- No behavior changes to production rate limiting logic
Acceptance criteria:
- NewAdaptiveRateLimiterWithWindow accepts configurable window duration
- Production callers continue using default 30s window
- Tests can inject millisecond-scale windows for fast iteration
- No changes to rate limiting logic or defaults
Co-Authored-By: Claude <noreply@anthropic.com>