test: cover chooseAccount selection tiers and cursor discipline#570
Conversation
Direct coverage for the phase-2-extracted rotation selector, driven through a REAL AccountManager (markSwitched/skip reasons/cursor logic all live; only the hybrid/sequential selectors are stubbed per test for deterministic path control): - pinned selection (issue #474): the pin wins without any cursor commit, and never falls back — already-attempted, missing, policy-blocked, disabled, and rate-limited pins each fail the request with the recorded reason - session affinity: the remembered account wins and commits the cursor; an unusable sticky account records its skip reason and falls through to the hybrid tier - hybrid tier: the selector's pick is returned without an extra cursor commit; an attempted/blocked pick falls back to the linear scan, which records per-account reasons and commits the winner; an exhausted pool returns null with a reason for every account - sequential mode (issue #509): the drain-first selector governs and the affinity tier is never consulted; a transient failure on the active account retries another account WITHOUT moving the drain-first primary 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 14 minutes and 24 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 |
From review: the pin tier now exercises the cooling-down:<reason> and circuit-open skip reasons (real cooldown bookkeeping and a tripped breaker), and sequential mode covers a policy-blocked primary — the blocked set is threaded into the drain-first selector, the linear fallback records the block, and the primary pointer stays put. https://claude.ai/code/session_01XNtnkLbBiXZxfQQYLMpucB
Summary
Tenth suite in the direct-coverage wave (siblings: #559–#561, #563–#567, #569; all independent, based on
main).lib/runtime/rotation-account-selection.tsis the phase-2-extracted rotation selector at the heart of the proxy hot path. The proxy giant suite exercises it indirectly; this addstest/rotation-account-selection.test.ts(13 tests) pinning its documented selection contracts directly.The suite drives a real
AccountManagerbuilt from V3 storage fixtures —markSwitched, the skip-reason taxonomy, and the cursor bookkeeping are all live. Only the hybrid/sequential selector methods are stubbed per test (viavi.spyOnon the real instance) for deterministic path control, and module-level circuit/rate trackers are reset per test.What the tests pin
Pinned selection (issue #474):
Session affinity tier:
markSwitched(account, "rotation", family).Hybrid tier and linear fallback:
already-attempted,policy-blocked) and commits the winner as the new cursor.Sequential / drain-first mode (issue #509):
markSwitchedis not called on the within-request fallback, so only true exhaustion advances the pointer.Validation
vitest run test/rotation-account-selection.test.ts— 13/13 passingnpm run typecheck— cleannpx eslint test/rotation-account-selection.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-account-selection.test.ts— 13 direct-coverage tests forchooseAccountinlib/runtime/rotation-account-selection.ts, driving a liveAccountManagerbuilt from v3 fixtures with per-test volatile state resets. both issues flagged in previous review threads (missingcooling-down/circuit-openpin coverage and the sequential policy-blocked primary path) are addressed.already-attempted,missing,policy-blocked,disabled,rate-limited,cooling-down:*,circuit-open) and asserts cursor is not committed.Confidence Score: 5/5
test-only addition with no production code changes; the live AccountManager and module-level state reset in beforeEach are correct and all 13 contracts align with the implementation.
the suite correctly drives the real AccountManager, resets volatile circuit/rate state per test, and properly stubs only the hybrid/sequential selector methods — the selection contracts asserted match the chooseAccount implementation exactly. all findings are coverage gaps, not defects in the tests or the code they exercise.
no files require special attention
Important Files Changed
Flowchart
%%{init: {'theme': 'neutral'}}%% flowchart TD A[chooseAccount] --> B{pinnedIndex?} B -- yes --> C{attempted / missing / blocked?} C -- yes --> D[record skip reason] C -- no --> E{enabled? runtime skip?} E -- no --> D E -- yes --> F[return pinned no markSwitched] B -- no --> G{schedulingStrategy = sequential?} G -- yes --> H[getCurrentOrNextForFamilySequential] H --> I{usable and not attempted/blocked?} I -- yes --> J[return selected no markSwitched] I -- no --> K[chooseLinearScanFallback advancePtr=false] K --> L[return winner no markSwitched] G -- no --> M{session affinity hit?} M -- yes --> N{usable?} N -- yes --> O[markSwitched then return preferred] N -- no --> P[record skip reason then fall through] M -- no --> Q[getCurrentOrNextForFamilyHybrid] P --> Q Q --> R{usable and not attempted/blocked?} R -- yes --> S[return hybrid pick no markSwitched] R -- no --> T[chooseLinearScanFallback advancePtr=true] T --> U[markSwitched then return winner] T -- exhausted --> V[null]Prompt To Fix All With AI
Reviews (2): Last reviewed commit: "test: cover cooling-down and circuit-ope..." | Re-trigger Greptile