@@ -6,12 +6,22 @@ import assert from 'assert'
66import { ListDirectory } from '../../../codewhispererChat/tools/listDirectory'
77import { TestFolder } from '../../testUtil'
88import path from 'path'
9+ import * as vscode from 'vscode'
10+ import * as sinon from 'sinon'
911
1012describe ( 'ListDirectory Tool' , ( ) => {
1113 let testFolder : TestFolder
14+ let workspaceFoldersStub : sinon . SinonStub
1215
1316 before ( async ( ) => {
1417 testFolder = await TestFolder . create ( )
18+ // Initialize the stub
19+ workspaceFoldersStub = sinon . stub ( vscode . workspace , 'workspaceFolders' )
20+ } )
21+
22+ after ( ( ) => {
23+ // Restore the stub after tests
24+ workspaceFoldersStub . restore ( )
1525 } )
1626
1727 it ( 'throws if path is empty' , async ( ) => {
@@ -86,4 +96,48 @@ describe('ListDirectory Tool', () => {
8696 assert . strictEqual ( result . output . kind , 'text' )
8797 assert . ok ( result . output . content . length > 0 )
8898 } )
99+
100+ it ( 'set requiresAcceptance=true if path is outside workspace' , ( ) => {
101+ // Mock empty workspace folders
102+ workspaceFoldersStub . value ( [ ] )
103+
104+ const listDirectory = new ListDirectory ( { path : '/some/outside/path' } )
105+ const validation = listDirectory . requiresAcceptance ( )
106+
107+ assert . strictEqual ( validation . requiresAcceptance , true , 'Should require acceptance for path outside workspace' )
108+ } )
109+
110+ it ( 'set requiresAcceptance=true if path is not within any workspace folder' , ( ) => {
111+ // Mock workspace folders that don't contain the target path
112+ workspaceFoldersStub . value ( [
113+ { uri : { fsPath : '/workspace/folder1' } } ,
114+ { uri : { fsPath : '/workspace/folder2' } } ,
115+ ] )
116+
117+ const listDirectory = new ListDirectory ( { path : '/some/outside/path' } )
118+ const validation = listDirectory . requiresAcceptance ( )
119+
120+ assert . strictEqual (
121+ validation . requiresAcceptance ,
122+ true ,
123+ 'Should require acceptance for path outside workspace folders'
124+ )
125+ } )
126+
127+ it ( 'set requiresAcceptance=false if path is within a workspace folder' , ( ) => {
128+ // Mock workspace folders with one containing the target path
129+ const workspacePath = '/workspace/folder1'
130+ const targetPath = `${ workspacePath } /subfolder`
131+
132+ workspaceFoldersStub . value ( [ { uri : { fsPath : workspacePath } } , { uri : { fsPath : '/workspace/folder2' } } ] )
133+
134+ const listDirectory = new ListDirectory ( { path : targetPath } )
135+ const validation = listDirectory . requiresAcceptance ( )
136+
137+ assert . strictEqual (
138+ validation . requiresAcceptance ,
139+ false ,
140+ 'Should not require acceptance for path within workspace folder'
141+ )
142+ } )
89143} )
0 commit comments