@@ -2206,6 +2206,84 @@ describe("ClineProvider", () => {
22062206 } )
22072207 } )
22082208} )
2209+ describe ( "Bridge mode_slug handling" , ( ) => {
2210+ let provider : ClineProvider
2211+ let mockContext : vscode . ExtensionContext
2212+ let mockOutputChannel : vscode . OutputChannel
2213+ let mockWebviewView : vscode . WebviewView
2214+
2215+ beforeEach ( ( ) => {
2216+ vi . clearAllMocks ( )
2217+
2218+ mockContext = {
2219+ extensionPath : "/test/path" ,
2220+ extensionUri : { } as vscode . Uri ,
2221+ globalState : {
2222+ get : vi . fn ( ) ,
2223+ update : vi . fn ( ) ,
2224+ keys : vi . fn ( ) . mockReturnValue ( [ ] ) ,
2225+ } ,
2226+ secrets : {
2227+ get : vi . fn ( ) ,
2228+ store : vi . fn ( ) ,
2229+ delete : vi . fn ( ) ,
2230+ } ,
2231+ subscriptions : [ ] ,
2232+ extension : {
2233+ packageJSON : { version : "1.0.0" } ,
2234+ } ,
2235+ globalStorageUri : {
2236+ fsPath : "/test/storage/path" ,
2237+ } ,
2238+ } as unknown as vscode . ExtensionContext
2239+
2240+ mockOutputChannel = {
2241+ appendLine : vi . fn ( ) ,
2242+ clear : vi . fn ( ) ,
2243+ dispose : vi . fn ( ) ,
2244+ } as unknown as vscode . OutputChannel
2245+
2246+ mockWebviewView = {
2247+ webview : {
2248+ postMessage : vi . fn ( ) ,
2249+ html : "" ,
2250+ options : { } ,
2251+ onDidReceiveMessage : vi . fn ( ) ,
2252+ asWebviewUri : vi . fn ( ) ,
2253+ cspSource : "vscode-webview://test-csp-source" ,
2254+ } ,
2255+ visible : true ,
2256+ onDidDispose : vi . fn ( ) ,
2257+ onDidChangeVisibility : vi . fn ( ) ,
2258+ } as unknown as vscode . WebviewView
2259+
2260+ provider = new ClineProvider ( mockContext , mockOutputChannel , "sidebar" , new ContextProxy ( mockContext ) )
2261+ } )
2262+
2263+ it ( "applies mode_slug from bridge options when starting task" , async ( ) => {
2264+ await provider . resolveWebviewView ( mockWebviewView )
2265+
2266+ // Spy on handleModeSwitch to ensure it's invoked with the bridge-provided mode
2267+ const handleModeSwitchSpy = vi . spyOn ( provider , "handleModeSwitch" ) . mockResolvedValue ( undefined as any )
2268+
2269+ // Ensure getModeBySlug returns a valid mode for the provided slug
2270+ const { getModeBySlug } = await import ( "../../../shared/modes" )
2271+ vi . mocked ( getModeBySlug ) . mockReturnValueOnce ( {
2272+ slug : "architect" ,
2273+ name : "Architect Mode" ,
2274+ roleDefinition : "You are an architect" ,
2275+ groups : [ "read" , "edit" ] as any ,
2276+ } as any )
2277+
2278+ // Pass mode_slug through the options object (as provided by the bridge package)
2279+ await provider . initClineWithTask ( "Started from bridge" , undefined , undefined , {
2280+ experiments : { } ,
2281+ mode_slug : "architect" ,
2282+ } as any )
2283+
2284+ expect ( handleModeSwitchSpy ) . toHaveBeenCalledWith ( "architect" )
2285+ } )
2286+ } )
22092287
22102288describe ( "Project MCP Settings" , ( ) => {
22112289 let provider : ClineProvider
0 commit comments