@@ -313,4 +313,168 @@ describe("ChatView - Auto Approval Tests", () => {
313313 } )
314314 } )
315315 } )
316+
317+ it ( "auto-approves mode switch when enabled" , async ( ) => {
318+ render (
319+ < ExtensionStateContextProvider >
320+ < ChatView
321+ isHidden = { false }
322+ showAnnouncement = { false }
323+ hideAnnouncement = { ( ) => { } }
324+ showHistoryView = { ( ) => { } }
325+ />
326+ </ ExtensionStateContextProvider > ,
327+ )
328+
329+ // First hydrate state with initial task
330+ mockPostMessage ( {
331+ alwaysAllowModeSwitch : true ,
332+ autoApprovalEnabled : true ,
333+ clineMessages : [
334+ {
335+ type : "say" ,
336+ say : "task" ,
337+ ts : Date . now ( ) - 2000 ,
338+ text : "Initial task" ,
339+ } ,
340+ ] ,
341+ } )
342+
343+ // Then send the mode switch ask message
344+ mockPostMessage ( {
345+ alwaysAllowModeSwitch : true ,
346+ autoApprovalEnabled : true ,
347+ clineMessages : [
348+ {
349+ type : "say" ,
350+ say : "task" ,
351+ ts : Date . now ( ) - 2000 ,
352+ text : "Initial task" ,
353+ } ,
354+ {
355+ type : "ask" ,
356+ ask : "tool" ,
357+ ts : Date . now ( ) ,
358+ text : JSON . stringify ( { tool : "switchMode" } ) ,
359+ partial : false ,
360+ } ,
361+ ] ,
362+ } )
363+
364+ // Wait for the auto-approval message
365+ await waitFor ( ( ) => {
366+ expect ( vscode . postMessage ) . toHaveBeenCalledWith ( {
367+ type : "askResponse" ,
368+ askResponse : "yesButtonClicked" ,
369+ } )
370+ } )
371+ } )
372+
373+ it ( "does not auto-approve mode switch when disabled" , async ( ) => {
374+ render (
375+ < ExtensionStateContextProvider >
376+ < ChatView
377+ isHidden = { false }
378+ showAnnouncement = { false }
379+ hideAnnouncement = { ( ) => { } }
380+ showHistoryView = { ( ) => { } }
381+ />
382+ </ ExtensionStateContextProvider > ,
383+ )
384+
385+ // First hydrate state with initial task
386+ mockPostMessage ( {
387+ alwaysAllowModeSwitch : false ,
388+ autoApprovalEnabled : true ,
389+ clineMessages : [
390+ {
391+ type : "say" ,
392+ say : "task" ,
393+ ts : Date . now ( ) - 2000 ,
394+ text : "Initial task" ,
395+ } ,
396+ ] ,
397+ } )
398+
399+ // Then send the mode switch ask message
400+ mockPostMessage ( {
401+ alwaysAllowModeSwitch : false ,
402+ autoApprovalEnabled : true ,
403+ clineMessages : [
404+ {
405+ type : "say" ,
406+ say : "task" ,
407+ ts : Date . now ( ) - 2000 ,
408+ text : "Initial task" ,
409+ } ,
410+ {
411+ type : "ask" ,
412+ ask : "tool" ,
413+ ts : Date . now ( ) ,
414+ text : JSON . stringify ( { tool : "switchMode" } ) ,
415+ partial : false ,
416+ } ,
417+ ] ,
418+ } )
419+
420+ // Verify no auto-approval message was sent
421+ expect ( vscode . postMessage ) . not . toHaveBeenCalledWith ( {
422+ type : "askResponse" ,
423+ askResponse : "yesButtonClicked" ,
424+ } )
425+ } )
426+
427+ it ( "does not auto-approve mode switch when auto-approval is disabled" , async ( ) => {
428+ render (
429+ < ExtensionStateContextProvider >
430+ < ChatView
431+ isHidden = { false }
432+ showAnnouncement = { false }
433+ hideAnnouncement = { ( ) => { } }
434+ showHistoryView = { ( ) => { } }
435+ />
436+ </ ExtensionStateContextProvider > ,
437+ )
438+
439+ // First hydrate state with initial task
440+ mockPostMessage ( {
441+ alwaysAllowModeSwitch : true ,
442+ autoApprovalEnabled : false ,
443+ clineMessages : [
444+ {
445+ type : "say" ,
446+ say : "task" ,
447+ ts : Date . now ( ) - 2000 ,
448+ text : "Initial task" ,
449+ } ,
450+ ] ,
451+ } )
452+
453+ // Then send the mode switch ask message
454+ mockPostMessage ( {
455+ alwaysAllowModeSwitch : true ,
456+ autoApprovalEnabled : false ,
457+ clineMessages : [
458+ {
459+ type : "say" ,
460+ say : "task" ,
461+ ts : Date . now ( ) - 2000 ,
462+ text : "Initial task" ,
463+ } ,
464+ {
465+ type : "ask" ,
466+ ask : "tool" ,
467+ ts : Date . now ( ) ,
468+ text : JSON . stringify ( { tool : "switchMode" } ) ,
469+ partial : false ,
470+ } ,
471+ ] ,
472+ } )
473+
474+ // Verify no auto-approval message was sent
475+ expect ( vscode . postMessage ) . not . toHaveBeenCalledWith ( {
476+ type : "askResponse" ,
477+ askResponse : "yesButtonClicked" ,
478+ } )
479+ } )
316480} )
0 commit comments