test: cover login-menu manage actions and prompt fallbacks - #560
Conversation
The phase-4-extracted login-menu-actions.ts had only indirect CLI coverage. This suite drives handleManageAction with the REAL findMatchingAccountIndex (only the transaction wrapper is faked, so each test controls the reloaded storage and captures persists): - switch delegates to runSwitchCommand with a 1-based index and the storage deps bundle - delete re-resolves the account by identity inside the transaction (stale-reorder safe), rebalances activeIndex and every activeIndexByFamily entry, no-ops when the account vanished, and resets all indexes when the pool empties - toggle flips enabled in both persisted and in-memory storage and no-ops on vanished accounts - refresh runs the OAuth flow (non-TTY mode resolves to browser), persists/syncs the resolved selection, reports failures without persisting, and ignores out-of-range indexes - non-TTY fallbacks for the three prompts (browser / latest / first backup or null) 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 23 minutes and 39 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 toggle concurrent-reorder scenario (same identity re-resolution pipeline the delete suite proves), assert the in-memory storage stays untouched on the toggle no-op, and cover the refresh prompt's cancel/manual/non-transport branches by flipping TTY on with the UI select stubbed (the prompt is same-module, so a module-boundary mock cannot intercept it). https://claude.ai/code/session_01XNtnkLbBiXZxfQQYLMpucB
Summary
Continues the direct-coverage push for the phase-4-extracted login machinery (sibling of #559, independent — based on
main).lib/codex-manager/login-menu-actions.tspreviously had only indirect CLI coverage; this addstest/login-menu-actions.test.ts(14 tests) forhandleManageActionand the three prompt fallbacks.The mocking is deliberately narrow: the real
findMatchingAccountIndexruns (that identity matching is the thing under test), and onlywithAccountStorageTransactionis faked so each test controls the storage the handler reloads and captures exactly what it persists.runSwitchCommand, the login-oauth flow functions, andpersistAndSyncSelectedAccountare mocked at the module boundary.process.stdin/stdout.isTTYare forced false (and restored) so the prompt fallbacks are deterministic regardless of the runner.What the tests pin
Delete (the concurrency-safety core):
activeIndexand everyactiveIndexByFamilyentry rebalance: indexes after the removed row shift left, indexes pointing at the removed row clamp, families without an explicit entry inherit the adjustedactiveIndex.activeIndexand all family indexes to 0.Toggle: flips
enabledboth in the persisted storage and the in-memory copy, reports "Enabled"/"Disabled" with the 1-based row, and no-ops when the account vanished.Switch: delegates to
runSwitchCommandwith the 1-based index and the storage deps bundle, without opening a transaction.Refresh: non-TTY sign-in mode resolves to
"browser"without prompting; success path resolves the selection thenpersistAccountPool([resolved], false)+syncSelectionToCodex(resolved); a failed OAuth flow is reported viaconsole.errorwithout persisting; an out-of-range index is ignored entirely.Prompt fallbacks (non-TTY): sign-in →
"browser", backup restore →"latest", manual backup → first entry ornull.Validation
vitest run test/login-menu-actions.test.ts— 14/14 passingnpm run typecheck— cleannpx eslint test/login-menu-actions.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
this pr adds
test/login-menu-actions.test.ts— 14 direct-coverage tests forhandleManageActionand the three non-tty prompt fallbacks inlib/codex-manager/login-menu-actions.ts. the mocking strategy is well-scoped: realfindMatchingAccountIndexruns so identity-matching is exercised, and onlywithAccountStorageTransactionis faked to control disk state.activeIndex/activeIndexByFamily, no-op on vanished account, and last-account reset.Confidence Score: 5/5
test-only change adding direct coverage for previously-untested login menu action handlers; no production code touched, no token or filesystem paths modified.
the change is purely additive test code. the mocking boundaries are correct, tty state is saved and restored in afterEach, and all concurrency/no-op/index-rebalance scenarios are explicitly exercised. the two unfilled assertion slots in the manual-refresh and last-account-deleted tests are harmless gaps, not regressions.
no files require special attention; the two minor assertion gaps in the manual-refresh and last-account-deleted tests are worth tightening but do not block merge.
Important Files Changed
Prompt To Fix All With AI
Reviews (2): Last reviewed commit: "test: strengthen login-menu-actions cove..." | Re-trigger Greptile