Thanks to visit codestin.com
Credit goes to github.com

Skip to content

test: cover login-oauth account selection and cancellation predicates - #559

Merged
ndycode merged 2 commits into
mainfrom
claude/audit-41-login-oauth-tests
Jun 11, 2026
Merged

ndycode merged 2 commits into
mainfrom
claude/audit-41-login-oauth-tests

Conversation

@ndycode

@ndycode ndycode commented Jun 10, 2026

Copy link
Copy Markdown
Owner

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, and isAbortError.

Note: this resolveAccountSelection is distinct from the deps-injected one in lib/runtime/account-selection.ts (already covered by test/account-selection.test.ts). The login-oauth variant runs the real candidate extraction (getAccountIdCandidates / resolveOrgOverride / selectBestAccountCandidate) — only decodeJWT is mocked, via a vi.hoisted token→payload map with an importOriginal spread so the rest of lib/auth/auth.js stays live.

What the tests pin

resolveAccountSelection:

Predicates:

  • isOAuthCancellation matches cancelled/canceled case-insensitively in either message or reason, and rejects everything else.
  • isAbortError accepts AbortError names and ABORT_ERR codes on real Error instances 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_ID into other suites.

Validation

  • vitest run test/login-oauth-selection.test.ts — 10/10 passing
  • npm run typecheck — clean
  • npx eslint test/login-oauth-selection.test.ts --max-warnings=0 — clean

https://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 in lib/codex-manager/login-oauth.tsresolveAccountSelection, isOAuthCancellation, and isAbortError — which previously only had indirect CLI-level coverage.

  • resolveAccountSelection tests span the zero-candidate, single-candidate, multi-candidate, explicit --org, unknown --org, env-fallback, and whitespace-override paths, with decodeJWT stubbed via a vi.hoisted token→payload map while the rest of lib/auth/auth.js stays live through importOriginal.
  • isOAuthCancellation and isAbortError predicate tests cover positive and negative branches including the reason fallback field, case-insensitive matching, and the instanceof Error guard.
  • env isolation uses a module-load-time snapshot of CODEX_AUTH_ACCOUNT_ID with beforeEach/afterEach save-restore; note that this still mutates process.env directly, 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

Filename Overview
test/login-oauth-selection.test.ts New 10-test suite for resolveAccountSelection, isOAuthCancellation, and isAbortError; most paths well-covered, but two env-override tests have thin assertion sets that leave accountIdSource and workspaces un-validated.

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
    end
Loading

Fix All in Codex

Prompt To Fix All With AI
Fix the following 2 code review issues. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 2
test/login-oauth-selection.test.ts:183-192
**thin assertions on the whitespace-fallback path**

the test verifies that `accountIdOverride` resolves to the env value, but omits `accountIdSource`, `accountLabel`, and `workspaces`. the whitespace-only `--org` goes through the same `override` branch as every other explicit-binding path (source lines 111-125), so the #512 workspace-persistence contract and the `"manual"` source type are equally in-scope here. a regression that dropped `workspaces` on this path or mis-labelled the source would pass this test unnoticed.

### Issue 2 of 2
test/login-oauth-selection.test.ts:156-169
**missing `accountIdSource` and `workspaces` in the priority test**

the test confirms the winning `accountIdOverride` and `accountLabel`, but neither `accountIdSource` (should be `"manual"`) nor `workspaces` (both `org_env` and `org_cli` should be present) are asserted. since the PR description calls out the #512 contract on the explicit-binding path, and the parallel "binds explicit --org" test at line 110 does check `workspaces`, omitting it here leaves the priority path partially unverified.

Reviews (2): Last reviewed commit: "test: strengthen login-oauth assertions ..." | Re-trigger Greptile

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
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

@coderabbitai

coderabbitai Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@ndycode, we couldn't start this review because you've reached your PR review rate limit.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 713b17df-1c40-4cfe-9592-1aa0c4e77828

📥 Commits

Reviewing files that changed from the base of the PR and between 6ede089 and eefe8b6.

📒 Files selected for processing (1)
  • test/login-oauth-selection.test.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/audit-41-login-oauth-tests
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch claude/audit-41-login-oauth-tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Comment thread test/login-oauth-selection.test.ts
Comment thread test/login-oauth-selection.test.ts
Comment thread test/login-oauth-selection.test.ts
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
@ndycode
ndycode merged commit 1ca9d0b into main Jun 11, 2026
2 checks passed
luo178 pushed a commit to luo178/codex-multi-auth that referenced this pull request Jun 23, 2026
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants