forked from cline/cline
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
feat: auto-switch to imported mode with architect fallback #9003
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mrubens
merged 12 commits into
main
from
feat/auto-switch-imported-mode-with-architect-fallback
Nov 6, 2025
Merged
Changes from 11 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
a2792d1
feat: auto-switch to imported mode after successful import
heyseth 2bdaff0
fix(modes): resolve react-hooks/exhaustive-deps in window message lis…
heyseth 61d746e
Update webview-ui/src/components/modes/ModesView.tsx
heyseth 90ab20b
fix: propagate updateCustomMode errors to prevent false-positive impo…
heyseth bce52d6
Merge branch 'feat/auto-switch-to-imported-mode-after-successful-impo…
heyseth 34134f9
refactor(modes): hoist ImportModeResult type to module scope
heyseth 6fe074d
fix(modes): wrap updateCustomMode in try-catch to prevent unhandled r…
heyseth 3e3d324
fix(modes): address parser consistency, UI desync, and test coverage …
heyseth 5183aec
revert: replace parseYamlSafely with yaml.parse
heyseth f07b1c0
feat: auto-switch to imported mode with architect fallback
daniel-lxs 387acca
fix: use defaultModeSlug instead of hardcoded architect for better ma…
daniel-lxs d71035c
fix: correct indentation for try block in updateCustomMode case
roomote File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
156 changes: 156 additions & 0 deletions
156
webview-ui/src/components/modes/__tests__/ModesView.import-switch.spec.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,156 @@ | ||
| // npx vitest src/components/modes/__tests__/ModesView.import-switch.spec.tsx | ||
|
|
||
| import { render, waitFor } from "@/utils/test-utils" | ||
| import ModesView from "../ModesView" | ||
| import { ExtensionStateContext } from "@src/context/ExtensionStateContext" | ||
| import { vscode } from "@src/utils/vscode" | ||
| import { defaultModeSlug } from "@roo/modes" | ||
|
|
||
| // Mock vscode API | ||
| vitest.mock("@src/utils/vscode", () => ({ | ||
| vscode: { | ||
| postMessage: vitest.fn(), | ||
| }, | ||
| })) | ||
|
|
||
| const mockExtensionState = { | ||
| customModePrompts: {}, | ||
| listApiConfigMeta: [ | ||
| { id: "config1", name: "Config 1" }, | ||
| { id: "config2", name: "Config 2" }, | ||
| ], | ||
| enhancementApiConfigId: "", | ||
| setEnhancementApiConfigId: vitest.fn(), | ||
| mode: "code", | ||
| customModes: [], | ||
| customSupportPrompts: [], | ||
| currentApiConfigName: "", | ||
| customInstructions: "", | ||
| setCustomInstructions: vitest.fn(), | ||
| } | ||
|
|
||
| const renderModesView = (props = {}) => { | ||
| const mockOnDone = vitest.fn() | ||
| return render( | ||
| <ExtensionStateContext.Provider value={{ ...mockExtensionState, ...props } as any}> | ||
| <ModesView onDone={mockOnDone} /> | ||
| </ExtensionStateContext.Provider>, | ||
| ) | ||
| } | ||
|
|
||
| Element.prototype.scrollIntoView = vitest.fn() | ||
|
|
||
| describe("ModesView Import Auto-Switch", () => { | ||
| beforeEach(() => { | ||
| vitest.clearAllMocks() | ||
| }) | ||
|
|
||
| it("should auto-switch to imported mode when found in current state", async () => { | ||
| const importedModeSlug = "custom-test-mode" | ||
| const customModes = [ | ||
| { | ||
| slug: importedModeSlug, | ||
| name: "Custom Test Mode", | ||
| roleDefinition: "Test role", | ||
| groups: [], | ||
| }, | ||
| ] | ||
|
|
||
| renderModesView({ customModes }) | ||
|
|
||
| // Simulate successful import message with the mode already in state | ||
| const importMessage = { | ||
| data: { | ||
| type: "importModeResult", | ||
| success: true, | ||
| slug: importedModeSlug, | ||
| }, | ||
| } | ||
|
|
||
| window.dispatchEvent(new MessageEvent("message", importMessage)) | ||
|
|
||
| // Wait for the mode switch message to be sent | ||
| await waitFor(() => { | ||
| expect(vscode.postMessage).toHaveBeenCalledWith({ | ||
| type: "mode", | ||
| text: importedModeSlug, | ||
| }) | ||
| }) | ||
| }) | ||
|
|
||
| it("should fallback to architect mode when imported slug not yet in state (race condition)", async () => { | ||
| const importedModeSlug = "custom-new-mode" | ||
|
|
||
| // Render without the imported mode in customModes (simulating race condition) | ||
| renderModesView({ customModes: [] }) | ||
|
|
||
| // Simulate successful import message but mode not yet in state | ||
| const importMessage = { | ||
| data: { | ||
| type: "importModeResult", | ||
| success: true, | ||
| slug: importedModeSlug, | ||
| }, | ||
| } | ||
|
|
||
| window.dispatchEvent(new MessageEvent("message", importMessage)) | ||
|
|
||
| // Wait for the fallback to default mode (architect) | ||
| await waitFor(() => { | ||
| expect(vscode.postMessage).toHaveBeenCalledWith({ | ||
| type: "mode", | ||
| text: defaultModeSlug, | ||
| }) | ||
| }) | ||
| }) | ||
|
|
||
| it("should not switch modes on import failure", async () => { | ||
| renderModesView() | ||
|
|
||
| // Simulate failed import message | ||
| const importMessage = { | ||
| data: { | ||
| type: "importModeResult", | ||
| success: false, | ||
| error: "Import failed", | ||
| }, | ||
| } | ||
|
|
||
| window.dispatchEvent(new MessageEvent("message", importMessage)) | ||
|
|
||
| // Wait a bit to ensure no mode switch happens | ||
| await new Promise((resolve) => setTimeout(resolve, 100)) | ||
|
|
||
| // Verify no mode switch message was sent | ||
| expect(vscode.postMessage).not.toHaveBeenCalledWith( | ||
| expect.objectContaining({ | ||
| type: "mode", | ||
| }), | ||
| ) | ||
| }) | ||
|
|
||
| it("should not switch modes on cancelled import", async () => { | ||
| renderModesView() | ||
|
|
||
| // Simulate cancelled import message | ||
| const importMessage = { | ||
| data: { | ||
| type: "importModeResult", | ||
| success: false, | ||
| error: "cancelled", | ||
| }, | ||
| } | ||
|
|
||
| window.dispatchEvent(new MessageEvent("message", importMessage)) | ||
|
|
||
| // Wait a bit to ensure no mode switch happens | ||
| await new Promise((resolve) => setTimeout(resolve, 100)) | ||
|
|
||
| // Verify no mode switch message was sent | ||
| expect(vscode.postMessage).not.toHaveBeenCalledWith( | ||
| expect.objectContaining({ | ||
| type: "mode", | ||
| }), | ||
| ) | ||
| }) | ||
| }) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.