@@ -247,54 +247,108 @@ describe('ChatView - Auto Approval Tests', () => {
247247 } )
248248 } )
249249
250- it ( 'auto-approves write tools when alwaysAllowWrite is enabled' , async ( ) => {
251- render (
252- < ExtensionStateContextProvider >
253- < ChatView
254- isHidden = { false }
255- showAnnouncement = { false }
256- hideAnnouncement = { ( ) => { } }
257- showHistoryView = { ( ) => { } }
258- />
259- </ ExtensionStateContextProvider >
260- )
250+ describe ( 'Write Tool Auto-Approval Tests' , ( ) => {
251+ it ( 'auto-approves write tools when alwaysAllowWrite is enabled and message is a tool request' , async ( ) => {
252+ render (
253+ < ExtensionStateContextProvider >
254+ < ChatView
255+ isHidden = { false }
256+ showAnnouncement = { false }
257+ hideAnnouncement = { ( ) => { } }
258+ showHistoryView = { ( ) => { } }
259+ />
260+ </ ExtensionStateContextProvider >
261+ )
261262
262- // First hydrate state with initial task
263- mockPostMessage ( {
264- alwaysAllowWrite : true ,
265- clineMessages : [
266- {
267- type : 'say' ,
268- say : 'task' ,
269- ts : Date . now ( ) - 2000 ,
270- text : 'Initial task'
271- }
272- ]
273- } )
263+ // First hydrate state with initial task
264+ mockPostMessage ( {
265+ alwaysAllowWrite : true ,
266+ clineMessages : [
267+ {
268+ type : 'say' ,
269+ say : 'task' ,
270+ ts : Date . now ( ) - 2000 ,
271+ text : 'Initial task'
272+ }
273+ ]
274+ } )
274275
275- // Then send the write tool ask message
276- mockPostMessage ( {
277- alwaysAllowWrite : true ,
278- clineMessages : [
279- {
280- type : 'say' ,
281- say : 'task' ,
282- ts : Date . now ( ) - 2000 ,
283- text : 'Initial task'
284- } ,
285- {
286- type : 'ask' ,
287- ask : 'tool' ,
288- ts : Date . now ( ) ,
289- text : JSON . stringify ( { tool : 'editedExistingFile' , path : 'test.txt' } ) ,
290- partial : false
291- }
292- ]
276+ // Then send the write tool ask message
277+ mockPostMessage ( {
278+ alwaysAllowWrite : true ,
279+ clineMessages : [
280+ {
281+ type : 'say' ,
282+ say : 'task' ,
283+ ts : Date . now ( ) - 2000 ,
284+ text : 'Initial task'
285+ } ,
286+ {
287+ type : 'ask' ,
288+ ask : 'tool' ,
289+ ts : Date . now ( ) ,
290+ text : JSON . stringify ( { tool : 'editedExistingFile' , path : 'test.txt' } ) ,
291+ partial : false
292+ }
293+ ]
294+ } )
295+
296+ // Wait for the auto-approval message
297+ await waitFor ( ( ) => {
298+ expect ( vscode . postMessage ) . toHaveBeenCalledWith ( {
299+ type : 'askResponse' ,
300+ askResponse : 'yesButtonClicked'
301+ } )
302+ } )
293303 } )
294304
295- // Wait for the auto-approval message
296- await waitFor ( ( ) => {
297- expect ( vscode . postMessage ) . toHaveBeenCalledWith ( {
305+ it ( 'does not auto-approve write operations when alwaysAllowWrite is enabled but message is not a tool request' , ( ) => {
306+ render (
307+ < ExtensionStateContextProvider >
308+ < ChatView
309+ isHidden = { false }
310+ showAnnouncement = { false }
311+ hideAnnouncement = { ( ) => { } }
312+ showHistoryView = { ( ) => { } }
313+ />
314+ </ ExtensionStateContextProvider >
315+ )
316+
317+ // First hydrate state with initial task
318+ mockPostMessage ( {
319+ alwaysAllowWrite : true ,
320+ clineMessages : [
321+ {
322+ type : 'say' ,
323+ say : 'task' ,
324+ ts : Date . now ( ) - 2000 ,
325+ text : 'Initial task'
326+ }
327+ ]
328+ } )
329+
330+ // Then send a non-tool write operation message
331+ mockPostMessage ( {
332+ alwaysAllowWrite : true ,
333+ clineMessages : [
334+ {
335+ type : 'say' ,
336+ say : 'task' ,
337+ ts : Date . now ( ) - 2000 ,
338+ text : 'Initial task'
339+ } ,
340+ {
341+ type : 'ask' ,
342+ ask : 'write_operation' ,
343+ ts : Date . now ( ) ,
344+ text : JSON . stringify ( { path : 'test.txt' , content : 'test content' } ) ,
345+ partial : false
346+ }
347+ ]
348+ } )
349+
350+ // Verify no auto-approval message was sent
351+ expect ( vscode . postMessage ) . not . toHaveBeenCalledWith ( {
298352 type : 'askResponse' ,
299353 askResponse : 'yesButtonClicked'
300354 } )
0 commit comments