refactor: extract switch command handler#150
refactor: extract switch command handler#150ndycode wants to merge 1 commit intorefactor/pr0-guardrails-and-runbooksfrom
Conversation
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
|
Important Review skippedAuto reviews are limited based on label configuration. 🚫 Review skipped — only excluded labels are configured. (1)
Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ 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 |
Summary
codex auth switchimplementation into a dedicated command moduleWhat Changed
lib/codex-manager/commands/switch.tswith the switch command flow and injected dependencies for storage, sync, and outputlib/codex-manager.tsso the switch path delegates to the new command module instead of keeping the command body inlinetest/codex-manager-switch-command.test.tsfor missing-index, range-validation, and sync-warning behaviorValidation
npm run lintnpm run typechecknpm run test -- test/codex-manager-switch-command.test.ts test/codex-manager-cli.test.tsnpm run buildDocs and Governance Checklist
docs/getting-started.mdupdated (if onboarding flow changed)docs/features.mdupdated (if capability surface changed)docs/reference/*pages updated (if commands/settings/paths changed)docs/upgrade.mdupdated (if migration behavior changed)SECURITY.mdandCONTRIBUTING.mdreviewed for alignmentRisk and Rollback
585ee57to restore the inline switch handler inlib/codex-manager.tsAdditional Notes
#149so the manager split stays reviewable in small slices from the same worktreenote: 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 extracts the
codex auth switchinline handler intolib/codex-manager/commands/switch.tswith injectable deps for storage, sync, and output — a clean, focused slice of the ongoing codex-manager split. the bulk of thelib/codex-manager.tsdiff is just prettier reformatting; the functional change is the eight-linerunSwitchdelegation. the new unit test covers the three paths called out in the PR description.two issues worth resolving before merge:
runSwitch()passes only the three mandatory deps and omitslogError,logWarn, andlogInfo. all switch output therefore falls back to rawconsole.*in production, which matches the old inline behaviour but leaves the injectable-logger mechanism unused and the call site untestable via the injected log mocks.synced: true, wasDisabled: false) are not covered; given the project's 80% branch threshold this is worth closing before the stacked PRs accumulate more untested branches.loadAccounts()→persistAndSyncSelectedAccount()sequence is not atomic; two concurrentcodex auth switchcalls can race and the last writer wins. this is pre-existing and not introduced here, but the extraction makes it easier to address in a follow-up withwithAccountStorageTransaction.Confidence Score: 4/5
Important Files Changed
switchReasonis hardcoded to"rotation"(inherited from the inline original) and all log deps default to rawconsole.*since the call site doesn't wire them uprunSwitchdelegation, butlogError/logWarn/logInfodeps are not wired up, leaving the injectable logging unused in productionFlowchart
%%{init: {'theme': 'neutral'}}%% flowchart TD A[runSwitchCommand] --> B[setStoragePath null] B --> C{args index present?} C -- no --> D[logError: Missing index] D --> E[return 1] C -- yes --> F[parseInt indexArg] F --> G{isFinite AND ge 1?} G -- no --> H[logError: Invalid index] H --> E G -- yes --> I[targetIndex = parsed - 1] I --> J[loadAccounts] J --> K{storage non-empty?} K -- no --> L[logError: No accounts] L --> E K -- yes --> M{targetIndex in range?} M -- no --> N[logError: Out of range] N --> E M -- yes --> O{account exists?} O -- no --> P[logError: Not found] P --> E O -- yes --> Q[persistAndSyncSelectedAccount] Q --> R{synced?} R -- no --> S[logWarn: sync incomplete] S --> T[logInfo: Switched to account N] R -- yes --> T T --> U[return 0]Prompt To Fix All With AI
Last reviewed commit: "refactor: extract sw..."