test: cover ensureFreshAccessToken refresh, cooldown, and dedup paths#571
Conversation
Direct coverage for the phase-2-extracted rotation token-refresh helper, driven through a REAL AccountManager (cooldown bookkeeping, commitRefreshedAuth rollback machinery, and the live in-memory pool all run; only the refresh queue and the storage transaction seam are mocked): - a fresh token short-circuits without touching the refresh queue - a stale token refreshes and the rotated credentials land in both the result and the in-memory pool - concurrent callers share one in-flight commit (gated transaction so the dedup window is actually open) and receive the same token - a non-retryable 401 applies the 30s auth-failure cooldown and reports retryable=false, invalidated=false; a network error reports retryable=true - an explicit revocation message applies the long invalidation cooldown and signals invalidated=true (issue #495) - the monotonic guard never lets a later 30s generic failure truncate a concurrent 5-minute invalidation cooldown, and applyMonotonicAuthCooldown only ever extends deadlines - a failed commit cools the account down and stays retryable https://claude.ai/code/session_01XNtnkLbBiXZxfQQYLMpucB
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
|
Warning Review limit reached
More reviews will be available in 9 minutes and 25 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (1)
✨ Finishing Touches🧪 Generate unit tests (beta)
✨ Simplify code
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
When commitRefreshedAuth cannot resolve the account after persist it returns null, and the caller must fall back to the refresh result's access token (never the stale token on the original account object, which would 401 downstream and falsely trigger invalidation cooldown). https://claude.ai/code/session_01XNtnkLbBiXZxfQQYLMpucB
Summary
Eleventh suite in the direct-coverage wave (siblings: #559–#561, #563–#567, #569, #570; all independent, based on
main).lib/runtime/rotation-token-refresh.tsdecides on the proxy hot path whether an account's token is usable, refreshes it through the queue, and applies the auth-failure cooldowns — including the issue #495 invalidation handling. This addstest/rotation-token-refresh.test.ts(9 tests).Like #570, the suite drives a real
AccountManager— the cooldown bookkeeping,commitRefreshedAuth's snapshot/rollback machinery, and the live in-memory pool all run. OnlyqueuedRefreshand the storage-transaction seam are mocked, and the realisTokenInvalidationError/isTokenRefreshRetryablepredicates classify the failures.What the tests pin
commitRefreshedAuthand both receive the committed token (the transaction is gated open so the dedup window genuinely exists during the test).retryable: false,invalidated: false; a network error →retryable: true; an explicit "OAuth token has been invalidated" body → the long invalidation cooldown plusinvalidated: true, telling the caller to stop rotating instead of parading other accounts' tokens from the same IP (issue Rotation gateway triggers mass OAuth token invalidation across accounts #495).applyMonotonicAuthCooldownonly ever extends deadlines.retryable: truewith the rollback machinery exercised.Validation
vitest run test/rotation-token-refresh.test.ts— 9/9 passingnpm run typecheck— cleannpx eslint test/rotation-token-refresh.test.ts --max-warnings=0— cleanhttps://claude.ai/code/session_01XNtnkLbBiXZxfQQYLMpucB
Generated by Claude Code
note: greptile review for oc-chatgpt-multi-auth. cite files like
lib/foo.ts:123. confirm regression tests + windows concurrency/token redaction coverage.Greptile Summary
adds
test/rotation-token-refresh.test.tswith 9 tests forensureFreshAccessTokenandapplyMonotonicAuthCooldown, driving a realAccountManagerwith onlyqueuedRefreshand the storage-transaction seam mocked.null-return fallback added in this PR.invalidated: true, monotonic guard, and commit-exception paths are all covered with realisTokenInvalidationError/isTokenRefreshRetryablepredicates classifying the failures.withAccountStorageTransactionso both concurrent callers genuinely overlap in the in-flight window before the gate opens.Confidence Score: 5/5
test-only PR adding 9 vitest tests with no production code changes; safe to merge
the change is purely additive test code. all 9 tests drive the real AccountManager and pass according to the author's validation run. the two notes above are minor gaps in assertion coverage that leave some production behaviors under-pinned but do not introduce regressions.
no files require special attention; all changes are in the test file
Important Files Changed
Sequence Diagram
sequenceDiagram participant T as Test participant E as ensureFreshAccessToken participant Q as queuedRefresh (mock) participant D as commitRefreshedAuthOnce participant C as AccountManager.commitRefreshedAuth participant S as withAccountStorageTransaction (mock) T->>E: params (stale token) E->>E: hasUsableAccessToken → false E->>Q: queuedRefresh(refreshToken) Q-->>E: "{type:success, access:access-new}" E->>D: commitRefreshedAuthOnce(manager, account, auth) D->>C: accountManager.commitRefreshedAuth(account, auth) C->>S: withAccountStorageTransaction(handler) S-->>C: handler(null, persist) C-->>D: liveAccount (updated in-memory) D-->>E: liveAccount E-->>T: "{ok:true, accessToken:access-new, account}" Note over D: dedup: 2nd concurrent caller returns same in-flight promise Note over E: on failure: applyMonotonicAuthCooldown only extends, never shortensPrompt To Fix All With AI
Reviews (2): Last reviewed commit: "test: cover the commit-null token fallba..." | Re-trigger Greptile