Repository navigation
[leas code] Deduplicate account rate-limit target selection - #13428
Conversation
📝 WalkthroughWalkthroughAdded shared account rate-limit target resolution for Claude and Codex. The resolver handles explicit host and WSL settings, platform compatibility, configured targets, normalized selections, and single-account WSL fallback. Provider functions now supply provider-specific adapters to the shared resolver. Added parameterized tests for runtime, platform, legacy, stale-selection, distro, and multi-selection scenarios. Removed the previous provider-specific test files and project-runtime targeting module logic. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
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 |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/main/rate-limits/initial-account-rate-limit-target.ts (1)
44-53: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winExpress the legacy unset runtime in the parameter type.
GlobalSettings.localAccountRuntimeis a required'auto' | 'host' | 'wsl'. After the'host'and'wsl'returns, TypeScript narrows the value to'auto', so the check on Line 46 is always true by type and Lines 50-53 look unreachable to the compiler and tono-unnecessary-condition-style lint rules. The fallback is only reachable for legacy profiles that omit the field at runtime, which the tests simulate by deleting the property.Widen the parameter type so the legacy case is visible to the type system and cannot be removed by a later cleanup.
♻️ Proposed refactor
+type AccountRateLimitSettings = Omit<GlobalSettings, 'localAccountRuntime'> & { + /** Legacy profiles saved before the account-runtime policy omit this field. */ + localAccountRuntime?: GlobalSettings['localAccountRuntime'] +} + export function getInitialAccountRateLimitTarget( - settings: GlobalSettings, + settings: AccountRateLimitSettings, provider: AccountRuntimeSelectionProvider, platform: NodeJS.Platform = process.platform ): AccountRateLimitRuntimeTarget {
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 49919024-85e3-4d19-a86b-68aa602f59c9
📒 Files selected for processing (7)
src/main/rate-limits/claude-rate-limit-target.test.tssrc/main/rate-limits/claude-rate-limit-target.tssrc/main/rate-limits/codex-rate-limit-target.test.tssrc/main/rate-limits/codex-rate-limit-target.tssrc/main/rate-limits/initial-account-rate-limit-target.test.tssrc/main/rate-limits/initial-account-rate-limit-target.tssrc/main/rate-limits/project-runtime-rate-limit-target.ts
💤 Files with no reviewable changes (3)
- src/main/rate-limits/codex-rate-limit-target.test.ts
- src/main/rate-limits/claude-rate-limit-target.test.ts
- src/main/rate-limits/project-runtime-rate-limit-target.ts
Summary
Centralize the duplicated Codex and Claude startup rate-limit target policy behind their existing provider-specific entry points. The shared policy preserves explicit, automatic, and legacy runtime precedence; the mirrored test suites become one provider-crossed table; and the now-redundant project-runtime adapter is removed.
Net reduction: 249 lines across seven files.
Screenshots
No visual change.
Testing
pnpm lintpnpm run typecheck:nodepnpm testpnpm buildpnpm run check:code-quality:changedoxfmtandgit diff --checkAI Review Report
The review traced every old Codex and Claude decision branch through the shared policy: explicit host and WSL behavior, trimmed configured distros, automatic global-runtime selection, legacy unset settings, provider-specific selection fields, default WSL keys, and the unusual single-WSL fallback on non-Windows hosts. It found no correctness or API blocker. Two low-risk findings were addressed by restoring lazy provider-selection lookup and retaining a concise migration comment.
Cross-platform review explicitly covered macOS, Linux, and Windows. Explicit WSL remains host-only outside Windows, the legacy non-Windows fallback is preserved, and no shortcuts, labels, paths, shell behavior, Electron boundary, SSH execution, folder-workspace assumption, Git command, or remote wire shape changed.
Security Audit
No command execution, path handling, authentication, secrets, dependencies, IPC, or external input surface changed. The patch only consolidates pure settings-to-target selection and keeps the existing provider-specific adapters and return shapes.
Notes
Independent cleanup based on current
main. Public provider function names, import paths, defaultprocess.platformbehavior, and target types remain compatible; the deleted internal project-target module had no other consumers.