Preserve separate OpenAI LLM selections for API key and ChatGPT login - #1092
Preserve separate OpenAI LLM selections for API key and ChatGPT login#1092fqf555 wants to merge 1 commit into
Conversation
📝 WalkthroughWalkthroughThe OpenAI plugin now stores separate LLM model selections for API-key and ChatGPT authentication modes. Activation migrates legacy state, selection updates persist the active mode, and normalization validates fallback models. Tests cover switching and restoring selections. ChangesOpenAI model selection
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant OpenAIPlugin
participant PersistentStorage
participant AvailableModels
OpenAIPlugin->>PersistentStorage: Load mode-specific and legacy selections
OpenAIPlugin->>OpenAIPlugin: Resolve selection for active authentication mode
OpenAIPlugin->>AvailableModels: Validate selected model
AvailableModels-->>OpenAIPlugin: Return available models
OpenAIPlugin->>PersistentStorage: Persist normalized selection
Possibly related PRs
Suggested labels: Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
🧪 Generate unit tests (beta)
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)
TypeWhisperPluginSDK/Plugins/OpenAIPlugin/Tests/OpenAIPluginTests.swift (1)
599-600: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winCover restoration after a new plugin activation.
Lines 599-600 verify the in-memory selection after
setAuthMode. They do not verify thatactivate(host:)reloads both new storage keys. Create a secondOpenAIPluginafter both selections are stored. Activate it, then assert the ChatGPT selection and the API-key selection after switching mode.Proposed test update
- plugin.setAuthMode(.apiKey) - XCTAssertEqual(plugin.selectedLLMModelId, "gpt-4.1-mini") + let restoredPlugin = OpenAIPlugin() + restoredPlugin.activate(host: host) + XCTAssertEqual(restoredPlugin.selectedLLMModelId, "gpt-5.3-codex-spark") + + restoredPlugin.setAuthMode(.apiKey) + XCTAssertEqual(restoredPlugin.selectedLLMModelId, "gpt-4.1-mini")🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@TypeWhisperPluginSDK/Plugins/OpenAIPlugin/Tests/OpenAIPluginTests.swift` around lines 599 - 600, Extend the test around OpenAIPlugin activation to persist both ChatGPT and API-key model selections, then create a second OpenAIPlugin instance and call activate(host:). After switching authentication mode, assert that the restored ChatGPT and API-key selections match their stored values, covering reload of both storage keys rather than only the in-memory setAuthMode result.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@TypeWhisperPluginSDK/Plugins/OpenAIPlugin/Tests/OpenAIPluginTests.swift`:
- Around line 599-600: Extend the test around OpenAIPlugin activation to persist
both ChatGPT and API-key model selections, then create a second OpenAIPlugin
instance and call activate(host:). After switching authentication mode, assert
that the restored ChatGPT and API-key selections match their stored values,
covering reload of both storage keys rather than only the in-memory setAuthMode
result.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: a5090503-dada-4034-9fe7-46806bb402fc
📒 Files selected for processing (2)
TypeWhisperPluginSDK/Plugins/OpenAIPlugin/OpenAIPlugin.swiftTypeWhisperPluginSDK/Plugins/OpenAIPlugin/Tests/OpenAIPluginTests.swift
|
Closing this for now so the higher-impact startup responsiveness PR can proceed within the repository's one-open-PR policy. The branch will remain available if this fix is useful to revisit later. Thank you for taking a look. |
Context
The OpenAI plugin currently uses one
selectedLLMModelpreference for both API-key and ChatGPT-login modes. When the authentication mode changes, that shared value is normalized against the newly active model catalog and may be replaced by its fallback. Switching back can therefore lose the user's previous model choice.This builds on the dynamic ChatGPT model catalog introduced in #1016 by keeping a selection for each authentication mode.
Changes
User impact
Users can switch between API-key and ChatGPT authentication without having to reselect their preferred model each time.
Test plan
cd TypeWhisperPluginSDK && swift test --filter OpenAIPluginTestsSummary by CodeRabbit