refactor: extract best command#161
refactor: extract best command#161ndycode wants to merge 2 commits intorefactor/pr1-route-verify-flagged-directfrom
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 bestimplementation into a dedicated command moduleWhat Changed
lib/codex-manager/commands/best.tsfor best-account selection, live probe refresh handling, and JSON/human output pathslib/codex-manager.tssorunBest(...)delegates through the extracted command module with injected dependenciestest/codex-manager-best-command.test.tsfor command-level coverageValidation
npm run test -- test/codex-manager-best-command.test.ts test/codex-manager-cli.test.tsnpm run lintnpm run typechecknpm run buildRisk and Rollback
30854b7to restore the inline best-account implementationAdditional Notes
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 extracts the
codex auth bestimplementation from the monolithiclib/codex-manager.tsintolib/codex-manager/commands/best.ts, following the same command-module pattern used bycheck,forecast, andreport. the two issues flagged in previous threads (refreshed tokens dropped on early-exit paths and theshouldSyncCurrentBestgate dropping non-best token saves) are both addressed —persistProbeChangesIfNeedednow accepts abeforeSavecallback that setslastUsedin-place and is called unconditionally in the already-best branch, and thechanged-flag detection logic is refactored to snapshot-then-diff rather than conditional-assign.key points:
runBestincodex-manager.tsis now a 1-line delegate; all 14 production deps are injected, making the command fully unit-testable without filesystem or networkgetNowandlogInfo/logWarn/logErrordeps mean tests can freeze time and assert on exact log calls without touchingconsoleresolveActiveIndexO(n) call: called once per account inside theforecastInputsmap — should be hoisted to a local before the map (see inline comment)changed = true(refreshed tokens surviving an account switch), thequeuedRefreshfailure branch (probeErrorspropagation), and theloadAccounts → nullpath are not yet covered — token safety on windows depends on the switch-path gap being exercisedConfidence Score: 4/5
persistAndSyncSelectedAccountever becomes a partial-save), the unexercised refresh-failure branch, and the null-storage gapImportant Files Changed
persistProbeChangesIfNeededcallback pattern; minor:resolveActiveIndexcalled O(n) times inside theforecastInputsmaprunBestnow delegates torunBestCommandwith all required deps,BestCliOptionsinterface moved to the new module and re-exported; no logic changeschanged = true,queuedRefreshfailure branch (probeErrorspropagation), andloadAccountsreturningnullFlowchart
%%{init: {'theme': 'neutral'}}%% flowchart TD A[runBestCommand] --> B{--help/-h?} B -- yes --> C[printBestUsage, return 0] B -- no --> D{parseBestArgs ok?} D -- no --> E[logError + printBestUsage, return 1] D -- yes --> F{modelProvided && !live?} F -- yes --> G[logError + printBestUsage, return 1] F -- no --> H[loadAccounts] H --> I{storage empty?} I -- yes --> J[output error, return 1] I -- no --> K[Live probe loop per account] K --> L{hasUsableAccessToken?} L -- no --> M[queuedRefresh] M -- failure --> N[store in refreshFailures, continue] M -- success --> O[update tokens, set changed=true if delta] O --> P[fetchCodexQuotaSnapshot] L -- yes --> P P --> Q[evaluateForecastAccounts + recommendForecastAccount] Q --> R{recommendedIndex null?} R -- yes --> S[persistProbeChangesIfNeeded, output error, return 1] R -- no --> T{bestAccount exists?} T -- no --> U[persistProbeChangesIfNeeded, output error, return 1] T -- yes --> V{currentIndex === bestIndex?} V -- yes --> W[persistProbeChangesIfNeeded with lastUsed=now] W --> X{shouldSyncCurrentBest?} X -- yes --> Y[setCodexCliActiveSelection] X -- no --> Z[output already-best, return 0] Y --> Z V -- no --> AA[persistAndSyncSelectedAccount] AA --> AB[output switched, return 0]Prompt To Fix All With AI
Last reviewed commit: "fix: preserve best c..."