test: cover login-oauth account selection and cancellation predicates - #559
Conversation
The login machinery extracted by the phase-4 refactor had only indirect CLI-suite coverage. This pins login-oauth's resolveAccountSelection — distinct from the deps-injected lib/runtime/account-selection.ts, which already has its own suite — through the REAL candidate extraction (decodeJWT mocked to controlled claims, everything else live): - single/multiple candidate adoption with default-non-personal preference, and the issue #491/#512 contract that every workspace the token exposes is persisted — including on the explicit --org path - --org binding as manual with the matched candidate's label, and bare binding without a fabricated label for unknown orgs - the org-override precedence: explicit --org beats the ambient CODEX_AUTH_ACCOUNT_ID env, whitespace --org falls through to env - isOAuthCancellation / isAbortError edge behavior 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 1 minute and 41 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 |
Add the reason-only true case for isOAuthCancellation (the message ?? reason fallback was only exercised through message) and assert accountIdSource === "org" on the multi-candidate selection path. https://claude.ai/code/session_01XNtnkLbBiXZxfQQYLMpucB
Adds section 5.2 listing the eight independent test suites (ndycode#559-ndycode#567) that give the phase-3/phase-4 extracted login machinery, health check, and persistence helpers direct coverage. https://claude.ai/code/session_01XNtnkLbBiXZxfQQYLMpucB
Summary
The phase-4-extracted login machinery (
lib/codex-manager/login-oauth.ts) previously had only indirect coverage through the CLI suites. This adds a direct suite (test/login-oauth-selection.test.ts, 10 tests) for its three exported building blocks:resolveAccountSelection,isOAuthCancellation, andisAbortError.Note: this
resolveAccountSelectionis distinct from the deps-injected one inlib/runtime/account-selection.ts(already covered bytest/account-selection.test.ts). The login-oauth variant runs the real candidate extraction (getAccountIdCandidates/resolveOrgOverride/selectBestAccountCandidate) — onlydecodeJWTis mocked, via avi.hoistedtoken→payload map with animportOriginalspread so the rest oflib/auth/auth.jsstays live.What the tests pin
resolveAccountSelection:workspacesfield.accountIdSource: "token"and surfaced as a default-enabled workspace.workspace <account>switch later).--orgmatching a candidate →accountIdSource: "manual", candidate label reused, and workspaces still built on the explicit-binding path (Same email + different workspace login says 'Added account' but overwrites existing saved entry #512).--org→ bare manual binding, no fabricated label.CODEX_AUTH_ACCOUNT_IDenv fallback applies when no--orgis given; an explicit--orgwins over it; a whitespace-only--orgfalls through to the env override.Predicates:
isOAuthCancellationmatches cancelled/canceled case-insensitively in eithermessageorreason, and rejects everything else.isAbortErroracceptsAbortErrornames andABORT_ERRcodes on realErrorinstances only — plain objects and strings are rejected.The env override is saved/restored around every test so the suite can't leak
CODEX_AUTH_ACCOUNT_IDinto other suites.Validation
vitest run test/login-oauth-selection.test.ts— 10/10 passingnpm run typecheck— cleannpx eslint test/login-oauth-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 a direct 10-test vitest suite (
test/login-oauth-selection.test.ts) for the three exported building blocks inlib/codex-manager/login-oauth.ts—resolveAccountSelection,isOAuthCancellation, andisAbortError— which previously only had indirect CLI-level coverage.resolveAccountSelectiontests span the zero-candidate, single-candidate, multi-candidate, explicit--org, unknown--org, env-fallback, and whitespace-override paths, withdecodeJWTstubbed via avi.hoistedtoken→payload map while the rest oflib/auth/auth.jsstays live throughimportOriginal.isOAuthCancellationandisAbortErrorpredicate tests cover positive and negative branches including thereasonfallback field, case-insensitive matching, and theinstanceof Errorguard.CODEX_AUTH_ACCOUNT_IDwithbeforeEach/afterEachsave-restore; note that this still mutatesprocess.envdirectly, so running with widened vitest worker parallelism carries the concurrency risk flagged in the existing review thread.Confidence Score: 5/5
test-only addition; no production code touched, safe to merge.
the change is a new test file with no production code modifications. the happy-path and error-path assertions for all three exported functions are present and correct; the two thin env-override tests are coverage gaps rather than incorrect assertions. no risk of regression to the auth machinery itself.
test/login-oauth-selection.test.ts — the two env-override tests (lines 156-169 and 183-192) could be strengthened, but they do not cause any test to mis-pass.
Important Files Changed
Flowchart
%%{init: {'theme': 'neutral'}}%% flowchart TD A[resolveAccountSelection] --> B{getAccountIdCandidates} B -->|length == 0| C[return tokens unchanged] B -->|length > 0| D{resolveOrgOverride} D -->|override present| E[find matched candidate] E --> F[return manual binding + workspaces] D -->|no override| G{length == 1?} G -->|yes| H[return single candidate + workspaces] G -->|no| I[selectBestAccountCandidate] I -->|best found| J[return best + workspaces] I -->|no best| C subgraph ENV["env-override priority"] K["explicit --org arg"] -->|wins| D L["CODEX_AUTH_ACCOUNT_ID env"] -->|fallback| D M["whitespace-only --org"] -->|treated as absent| D endPrompt To Fix All With AI
Reviews (2): Last reviewed commit: "test: strengthen login-oauth assertions ..." | Re-trigger Greptile