Skip to content

Commit be5293f

Browse files
committed
fix the test
1 parent 2781764 commit be5293f

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

packages/core/src/codewhispererChat/tools/executeBash.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,24 +189,24 @@ export class ExecuteBash {
189189
if (cmdArgs.length === 0) {
190190
return { requiresAcceptance: true }
191191
}
192-
192+
let hasOutsideWorkspacePath = false
193193
// For each command, validate arguments for path safety within workspace
194194
for (const arg of cmdArgs) {
195195
if (this.looksLikePath(arg)) {
196-
// If not absolute, resolve using workingDirectory if available.
197196
let fullPath = arg
198197
if (!path.isAbsolute(arg) && this.workingDirectory) {
199198
fullPath = path.join(this.workingDirectory, arg)
200199
}
201200
const workspaceFolders = vscode.workspace.workspaceFolders
202201
if (!workspaceFolders || workspaceFolders.length === 0) {
203-
return { requiresAcceptance: true }
202+
hasOutsideWorkspacePath = true
203+
continue
204204
}
205205
const isInWorkspace = workspaceFolders.some((folder) =>
206206
isInDirectory(folder.uri.fsPath, fullPath)
207207
)
208208
if (!isInWorkspace) {
209-
return { requiresAcceptance: true }
209+
hasOutsideWorkspacePath = true
210210
}
211211
}
212212
}
@@ -216,10 +216,19 @@ export class ExecuteBash {
216216

217217
switch (category) {
218218
case CommandCategory.Destructive:
219-
return { requiresAcceptance: true, warning: destructiveCommandWarningMessage }
219+
return {
220+
requiresAcceptance: true,
221+
warning: destructiveCommandWarningMessage,
222+
}
220223
case CommandCategory.Mutate:
221-
return { requiresAcceptance: true, warning: mutateCommandWarningMessage }
224+
return {
225+
requiresAcceptance: true,
226+
warning: mutateCommandWarningMessage,
227+
}
222228
case CommandCategory.ReadOnly:
229+
if (hasOutsideWorkspacePath) {
230+
return { requiresAcceptance: true }
231+
}
223232
continue
224233
default:
225234
return { requiresAcceptance: true }

packages/core/src/test/codewhispererChat/tools/executeBash.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ describe('ExecuteBash Tool', () => {
4444
})
4545

4646
it('set requiresAcceptance=true if the command has dangerous patterns', () => {
47-
const execBash = new ExecuteBash({ command: 'rm -rf /' })
47+
const execBash = new ExecuteBash({ command: 'ls && rm -rf /' })
4848
const needsAcceptance = execBash.requiresAcceptance().requiresAcceptance
4949
assert.equal(needsAcceptance, true, 'Should require acceptance for dangerous pattern')
5050
assert.equal(

0 commit comments

Comments
 (0)