@@ -7,6 +7,7 @@ import { strict as assert } from 'assert'
7
7
import sinon from 'sinon'
8
8
import { destructiveCommandWarningMessage , ExecuteBash } from '../../../codewhispererChat/tools/executeBash'
9
9
import { ChildProcess } from '../../../shared/utilities/processUtils'
10
+ import * as vscode from 'vscode'
10
11
11
12
describe ( 'ExecuteBash Tool' , ( ) => {
12
13
let runStub : sinon . SinonStub
@@ -114,4 +115,55 @@ describe('ExecuteBash Tool', () => {
114
115
115
116
assert . strictEqual ( invokeStub . callCount , 1 )
116
117
} )
118
+
119
+ it ( 'requires acceptance if the command references an absolute file path outside the workspace' , ( ) => {
120
+ // Stub workspace folders to simulate a workspace at '/workspace/folder'
121
+ const workspaceStub = sinon
122
+ . stub ( vscode . workspace , 'workspaceFolders' )
123
+ . value ( [ { uri : { fsPath : '/workspace/folder' } } as any ] )
124
+ // Command references an absolute path outside the workspace
125
+ const execBash = new ExecuteBash ( { command : 'cat /not/in/workspace/file.txt' , cwd : '/workspace/folder' } )
126
+ const result = execBash . requiresAcceptance ( )
127
+
128
+ assert . equal (
129
+ result . requiresAcceptance ,
130
+ true ,
131
+ 'Should require acceptance for an absolute path outside of workspace'
132
+ )
133
+ workspaceStub . restore ( )
134
+ } )
135
+
136
+ it ( 'does NOT require acceptance if the command references a relative file path inside the workspace' , ( ) => {
137
+ // Stub workspace folders to simulate a workspace at '/workspace/folder'
138
+ const workspaceStub = sinon
139
+ . stub ( vscode . workspace , 'workspaceFolders' )
140
+ . value ( [ { uri : { fsPath : '/workspace/folder' } } as any ] )
141
+
142
+ // Command references a relative path that resolves within the workspace
143
+ const execBash = new ExecuteBash ( { command : 'cat ./file.txt' , cwd : '/workspace/folder' } )
144
+ const result = execBash . requiresAcceptance ( )
145
+
146
+ assert . equal ( result . requiresAcceptance , false , 'Relative path inside workspace should not require acceptance' )
147
+
148
+ workspaceStub . restore ( )
149
+ } )
150
+
151
+ it ( 'does NOT require acceptance if there is no path-like token in the command' , ( ) => {
152
+ // Stub workspace folders (even though they are not used in this case)
153
+ const workspaceStub = sinon
154
+ . stub ( vscode . workspace , 'workspaceFolders' )
155
+ . value ( [ { uri : { fsPath : '/workspace/folder' } } as any ] )
156
+
157
+ // Command with tokens that do not look like file paths
158
+ const execBash = new ExecuteBash ( { command : 'echo hello world' , cwd : '/workspace/folder' } )
159
+ const result = execBash . requiresAcceptance ( )
160
+
161
+ assert . equal (
162
+ result . requiresAcceptance ,
163
+ false ,
164
+ 'A command without any path-like token should not require acceptance'
165
+ )
166
+
167
+ workspaceStub . restore ( )
168
+ } )
117
169
} )
0 commit comments