@@ -25,8 +25,8 @@ class TestRunInTerminalTool extends RunInTerminalTool {
25
25
26
26
get commandLineAutoApprover ( ) : CommandLineAutoApprover { return this . _commandLineAutoApprover ; }
27
27
28
- async rewriteCommandIfNeeded ( options : IToolInvocationPreparationContext , args : IRunInTerminalInputParams , instance : Pick < ITerminalInstance , 'getCwdResource' > | undefined , shell : string ) : Promise < string > {
29
- return this . _rewriteCommandIfNeeded ( options , args , instance , shell ) ;
28
+ async rewriteCommandIfNeeded ( args : IRunInTerminalInputParams , instance : Pick < ITerminalInstance , 'getCwdResource' > | undefined , shell : string ) : Promise < string > {
29
+ return this . _rewriteCommandIfNeeded ( args , instance , shell ) ;
30
30
}
31
31
32
32
setBackendOs ( os : OperatingSystem ) {
@@ -222,15 +222,12 @@ suite('RunInTerminalTool', () => {
222
222
} ) ;
223
223
224
224
suite ( 'command re-writing' , ( ) => {
225
- function createRewriteOptions ( command : string , chatSessionId ?: string ) : IToolInvocationPreparationContext {
225
+ function createRewriteParams ( command : string , chatSessionId ?: string ) : IRunInTerminalInputParams {
226
226
return {
227
- parameters : {
228
- command,
229
- explanation : 'Test command' ,
230
- isBackground : false
231
- } as IRunInTerminalInputParams ,
232
- chatSessionId
233
- } as IToolInvocationPreparationContext ;
227
+ command,
228
+ explanation : 'Test command' ,
229
+ isBackground : false
230
+ } ;
234
231
}
235
232
236
233
suite ( 'cd <cwd> && <suffix> -> <suffix>' , ( ) => {
@@ -240,52 +237,52 @@ suite('RunInTerminalTool', () => {
240
237
} ) ;
241
238
242
239
test ( 'should return original command when no cd prefix pattern matches' , async ( ) => {
243
- const options = createRewriteOptions ( 'echo hello world' ) ;
244
- const result = await runInTerminalTool . rewriteCommandIfNeeded ( options , options . parameters as IRunInTerminalInputParams , undefined , 'pwsh' ) ;
240
+ const parameters = createRewriteParams ( 'echo hello world' ) ;
241
+ const result = await runInTerminalTool . rewriteCommandIfNeeded ( parameters , undefined , 'pwsh' ) ;
245
242
246
243
strictEqual ( result , 'echo hello world' ) ;
247
244
} ) ;
248
245
249
246
test ( 'should return original command when cd pattern does not have suffix' , async ( ) => {
250
247
runInTerminalTool . setBackendOs ( OperatingSystem . Linux ) ;
251
- const options = createRewriteOptions ( 'cd /some/path' ) ;
252
- const result = await runInTerminalTool . rewriteCommandIfNeeded ( options , options . parameters as IRunInTerminalInputParams , undefined , 'pwsh' ) ;
248
+ const parameters = createRewriteParams ( 'cd /some/path' ) ;
249
+ const result = await runInTerminalTool . rewriteCommandIfNeeded ( parameters , undefined , 'pwsh' ) ;
253
250
254
251
strictEqual ( result , 'cd /some/path' ) ;
255
252
} ) ;
256
253
257
254
test ( 'should rewrite command with ; separator when directory matches cwd' , async ( ) => {
258
255
const testDir = '/test/workspace' ;
259
- const options = createRewriteOptions ( `cd ${ testDir } ; npm test` , 'session-1' ) ;
256
+ const parameters = createRewriteParams ( `cd ${ testDir } ; npm test` , 'session-1' ) ;
260
257
workspaceService . setWorkspace ( {
261
258
folders : [ { uri : { fsPath : testDir } } ]
262
259
} as any ) ;
263
260
264
- const result = await runInTerminalTool . rewriteCommandIfNeeded ( options , options . parameters as IRunInTerminalInputParams , undefined , 'pwsh' ) ;
261
+ const result = await runInTerminalTool . rewriteCommandIfNeeded ( parameters , undefined , 'pwsh' ) ;
265
262
266
263
strictEqual ( result , 'npm test' ) ;
267
264
} ) ;
268
265
269
266
test ( 'should rewrite command with && separator when directory matches cwd' , async ( ) => {
270
267
const testDir = '/test/workspace' ;
271
- const options = createRewriteOptions ( `cd ${ testDir } && npm install` , 'session-1' ) ;
268
+ const parameters = createRewriteParams ( `cd ${ testDir } && npm install` , 'session-1' ) ;
272
269
workspaceService . setWorkspace ( {
273
270
folders : [ { uri : { fsPath : testDir } } ]
274
271
} as any ) ;
275
272
276
- const result = await runInTerminalTool . rewriteCommandIfNeeded ( options , options . parameters as IRunInTerminalInputParams , undefined , 'bash' ) ;
273
+ const result = await runInTerminalTool . rewriteCommandIfNeeded ( parameters , undefined , 'bash' ) ;
277
274
278
275
strictEqual ( result , 'npm install' ) ;
279
276
} ) ;
280
277
281
278
test ( 'should rewrite command when the path is wrapped in double quotes' , async ( ) => {
282
279
const testDir = '/test/workspace' ;
283
- const options = createRewriteOptions ( `cd "${ testDir } " && npm install` , 'session-1' ) ;
280
+ const parameters = createRewriteParams ( `cd "${ testDir } " && npm install` , 'session-1' ) ;
284
281
workspaceService . setWorkspace ( {
285
282
folders : [ { uri : { fsPath : testDir } } ]
286
283
} as any ) ;
287
284
288
- const result = await runInTerminalTool . rewriteCommandIfNeeded ( options , options . parameters as IRunInTerminalInputParams , undefined , 'bash' ) ;
285
+ const result = await runInTerminalTool . rewriteCommandIfNeeded ( parameters , undefined , 'bash' ) ;
289
286
290
287
strictEqual ( result , 'npm install' ) ;
291
288
} ) ;
@@ -294,76 +291,76 @@ suite('RunInTerminalTool', () => {
294
291
const testDir = '/test/workspace' ;
295
292
const differentDir = '/different/path' ;
296
293
const command = `cd ${ differentDir } && npm install` ;
297
- const options = createRewriteOptions ( command , 'session-1' ) ;
294
+ const parameters = createRewriteParams ( command , 'session-1' ) ;
298
295
workspaceService . setWorkspace ( {
299
296
folders : [ { uri : { fsPath : testDir } } ]
300
297
} as any ) ;
301
298
302
- const result = await runInTerminalTool . rewriteCommandIfNeeded ( options , options . parameters as IRunInTerminalInputParams , undefined , 'bash' ) ;
299
+ const result = await runInTerminalTool . rewriteCommandIfNeeded ( parameters , undefined , 'bash' ) ;
303
300
304
301
strictEqual ( result , command ) ;
305
302
} ) ;
306
303
307
304
test ( 'should return original command when no workspace folders available' , async ( ) => {
308
305
const command = 'cd /some/path && npm install' ;
309
- const options = createRewriteOptions ( command , 'session-1' ) ;
306
+ const parameters = createRewriteParams ( command , 'session-1' ) ;
310
307
workspaceService . setWorkspace ( {
311
308
folders : [ ]
312
309
} as any ) ;
313
310
314
- const result = await runInTerminalTool . rewriteCommandIfNeeded ( options , options . parameters as IRunInTerminalInputParams , undefined , 'bash' ) ;
311
+ const result = await runInTerminalTool . rewriteCommandIfNeeded ( parameters , undefined , 'bash' ) ;
315
312
316
313
strictEqual ( result , command ) ;
317
314
} ) ;
318
315
319
316
test ( 'should return original command when multiple workspace folders available' , async ( ) => {
320
317
const command = 'cd /some/path && npm install' ;
321
- const options = createRewriteOptions ( command , 'session-1' ) ;
318
+ const parameters = createRewriteParams ( command , 'session-1' ) ;
322
319
workspaceService . setWorkspace ( {
323
320
folders : [
324
321
{ uri : { fsPath : '/workspace1' } } ,
325
322
{ uri : { fsPath : '/workspace2' } }
326
323
]
327
324
} as any ) ;
328
325
329
- const result = await runInTerminalTool . rewriteCommandIfNeeded ( options , options . parameters as IRunInTerminalInputParams , undefined , 'bash' ) ;
326
+ const result = await runInTerminalTool . rewriteCommandIfNeeded ( parameters , undefined , 'bash' ) ;
330
327
331
328
strictEqual ( result , command ) ;
332
329
} ) ;
333
330
334
331
test ( 'should handle commands with complex suffixes' , async ( ) => {
335
332
const testDir = '/test/workspace' ;
336
333
const command = `cd ${ testDir } && npm install && npm test && echo "done"` ;
337
- const options = createRewriteOptions ( command , 'session-1' ) ;
334
+ const parameters = createRewriteParams ( command , 'session-1' ) ;
338
335
workspaceService . setWorkspace ( {
339
336
folders : [ { uri : { fsPath : testDir } } ]
340
337
} as any ) ;
341
338
342
- const result = await runInTerminalTool . rewriteCommandIfNeeded ( options , options . parameters as IRunInTerminalInputParams , undefined , 'bash' ) ;
339
+ const result = await runInTerminalTool . rewriteCommandIfNeeded ( parameters , undefined , 'bash' ) ;
343
340
344
341
strictEqual ( result , 'npm install && npm test && echo "done"' ) ;
345
342
} ) ;
346
343
347
344
test ( 'should handle session without chatSessionId' , async ( ) => {
348
345
const command = 'cd /some/path && npm install' ;
349
- const options = createRewriteOptions ( command ) ;
346
+ const parameters = createRewriteParams ( command ) ;
350
347
workspaceService . setWorkspace ( {
351
348
folders : [ { uri : { fsPath : '/some/path' } } ]
352
349
} as any ) ;
353
350
354
- const result = await runInTerminalTool . rewriteCommandIfNeeded ( options , options . parameters as IRunInTerminalInputParams , undefined , 'bash' ) ;
351
+ const result = await runInTerminalTool . rewriteCommandIfNeeded ( parameters , undefined , 'bash' ) ;
355
352
356
353
strictEqual ( result , 'npm install' ) ;
357
354
} ) ;
358
355
359
356
test ( 'should ignore any trailing forward slash' , async ( ) => {
360
357
const testDir = '/test/workspace' ;
361
- const options = createRewriteOptions ( `cd ${ testDir } / && npm install` , 'session-1' ) ;
358
+ const parameters = createRewriteParams ( `cd ${ testDir } / && npm install` , 'session-1' ) ;
362
359
workspaceService . setWorkspace ( {
363
360
folders : [ { uri : { fsPath : testDir } } ]
364
361
} as any ) ;
365
362
366
- const result = await runInTerminalTool . rewriteCommandIfNeeded ( options , options . parameters as IRunInTerminalInputParams , undefined , 'bash' ) ;
363
+ const result = await runInTerminalTool . rewriteCommandIfNeeded ( parameters , undefined , 'bash' ) ;
367
364
368
365
strictEqual ( result , 'npm install' ) ;
369
366
} ) ;
@@ -376,12 +373,12 @@ suite('RunInTerminalTool', () => {
376
373
377
374
test ( 'should ignore any trailing back slash' , async ( ) => {
378
375
const testDir = 'c:\\test\\workspace' ;
379
- const options = createRewriteOptions ( `cd ${ testDir } \\ && npm install` , 'session-1' ) ;
376
+ const parameters = createRewriteParams ( `cd ${ testDir } \\ && npm install` , 'session-1' ) ;
380
377
workspaceService . setWorkspace ( {
381
378
folders : [ { uri : { fsPath : testDir } } ]
382
379
} as any ) ;
383
380
384
- const result = await runInTerminalTool . rewriteCommandIfNeeded ( options , options . parameters as IRunInTerminalInputParams , undefined , 'cmd' ) ;
381
+ const result = await runInTerminalTool . rewriteCommandIfNeeded ( parameters , undefined , 'cmd' ) ;
385
382
386
383
strictEqual ( result , 'npm install' ) ;
387
384
} ) ;
@@ -390,14 +387,14 @@ suite('RunInTerminalTool', () => {
390
387
const instanceDir = 'C:\\instance\\workspace' ;
391
388
const workspaceDir = 'C:\\workspace\\service' ;
392
389
const command = `cd ${ instanceDir } && npm test` ;
393
- const options = createRewriteOptions ( command , 'session-1' ) ;
390
+ const parameters = createRewriteParams ( command , 'session-1' ) ;
394
391
395
392
workspaceService . setWorkspace ( {
396
393
folders : [ { uri : { fsPath : workspaceDir } } ]
397
394
} as any ) ;
398
395
const instance = createInstanceWithCwd ( { fsPath : instanceDir } as any ) ;
399
396
400
- const result = await runInTerminalTool . rewriteCommandIfNeeded ( options , options . parameters as IRunInTerminalInputParams , instance , 'cmd' ) ;
397
+ const result = await runInTerminalTool . rewriteCommandIfNeeded ( parameters , instance , 'cmd' ) ;
401
398
402
399
strictEqual ( result , 'npm test' ) ;
403
400
} ) ;
@@ -406,14 +403,14 @@ suite('RunInTerminalTool', () => {
406
403
const instanceDir = 'C:\\instance\\workspace' ;
407
404
const workspaceDir = 'C:\\workspace\\service' ;
408
405
const command = `cd ${ instanceDir } ; npm test` ;
409
- const options = createRewriteOptions ( command , 'session-1' ) ;
406
+ const parameters = createRewriteParams ( command , 'session-1' ) ;
410
407
411
408
workspaceService . setWorkspace ( {
412
409
folders : [ { uri : { fsPath : workspaceDir } } ]
413
410
} as any ) ;
414
411
const instance = createInstanceWithCwd ( { fsPath : instanceDir } as any ) ;
415
412
416
- const result = await runInTerminalTool . rewriteCommandIfNeeded ( options , options . parameters as IRunInTerminalInputParams , instance , 'pwsh' ) ;
413
+ const result = await runInTerminalTool . rewriteCommandIfNeeded ( parameters , instance , 'pwsh' ) ;
417
414
418
415
strictEqual ( result , 'npm test' ) ;
419
416
} ) ;
@@ -423,14 +420,14 @@ suite('RunInTerminalTool', () => {
423
420
const cdDir = 'C:\\different\\path' ;
424
421
const workspaceDir = 'C:\\workspace\\service' ;
425
422
const command = `cd ${ cdDir } && npm test` ;
426
- const options = createRewriteOptions ( command , 'session-1' ) ;
423
+ const parameters = createRewriteParams ( command , 'session-1' ) ;
427
424
428
425
workspaceService . setWorkspace ( {
429
426
folders : [ { uri : { fsPath : workspaceDir } } ]
430
427
} as any ) ;
431
428
const instance = createInstanceWithCwd ( { fsPath : instanceDir } as any ) ;
432
429
433
- const result = await runInTerminalTool . rewriteCommandIfNeeded ( options , options . parameters as IRunInTerminalInputParams , instance , 'cmd' ) ;
430
+ const result = await runInTerminalTool . rewriteCommandIfNeeded ( parameters , instance , 'cmd' ) ;
434
431
435
432
// Should not rewrite since instance cwd doesn't match cd path
436
433
strictEqual ( result , command ) ;
@@ -439,29 +436,29 @@ suite('RunInTerminalTool', () => {
439
436
test ( 'should fallback to workspace service when instance getCwdResource returns undefined' , async ( ) => {
440
437
const workspaceDir = 'C:\\workspace\\service' ;
441
438
const command = `cd ${ workspaceDir } && npm test` ;
442
- const options = createRewriteOptions ( command , 'session-1' ) ;
439
+ const parameters = createRewriteParams ( command , 'session-1' ) ;
443
440
444
441
workspaceService . setWorkspace ( {
445
442
folders : [ { uri : { fsPath : workspaceDir } } ]
446
443
} as any ) ;
447
444
const instance = createInstanceWithCwd ( undefined ) ;
448
445
449
- const result = await runInTerminalTool . rewriteCommandIfNeeded ( options , options . parameters as IRunInTerminalInputParams , instance , 'cmd' ) ;
446
+ const result = await runInTerminalTool . rewriteCommandIfNeeded ( parameters , instance , 'cmd' ) ;
450
447
451
448
strictEqual ( result , 'npm test' ) ;
452
449
} ) ;
453
450
454
451
test ( 'should prioritize instance cwd over workspace service even when both match cd path' , async ( ) => {
455
452
const sharedDir = 'C:\\shared\\workspace' ;
456
453
const command = `cd ${ sharedDir } && npm build` ;
457
- const options = createRewriteOptions ( command , 'session-1' ) ;
454
+ const parameters = createRewriteParams ( command , 'session-1' ) ;
458
455
459
456
workspaceService . setWorkspace ( {
460
457
folders : [ { uri : { fsPath : sharedDir } } ]
461
458
} as any ) ;
462
459
const instance = createInstanceWithCwd ( { fsPath : sharedDir } as any ) ;
463
460
464
- const result = await runInTerminalTool . rewriteCommandIfNeeded ( options , options . parameters as IRunInTerminalInputParams , instance , 'cmd' ) ;
461
+ const result = await runInTerminalTool . rewriteCommandIfNeeded ( parameters , instance , 'cmd' ) ;
465
462
466
463
strictEqual ( result , 'npm build' ) ;
467
464
} ) ;
@@ -470,26 +467,26 @@ suite('RunInTerminalTool', () => {
470
467
const instanceDir = 'C:\\Instance\\Workspace' ;
471
468
const cdDir = 'c:\\instance\\workspace' ; // Different case
472
469
const command = `cd ${ cdDir } && npm test` ;
473
- const options = createRewriteOptions ( command , 'session-1' ) ;
470
+ const parameters = createRewriteParams ( command , 'session-1' ) ;
474
471
475
472
const instance = createInstanceWithCwd ( { fsPath : instanceDir } as any ) ;
476
473
477
- const result = await runInTerminalTool . rewriteCommandIfNeeded ( options , options . parameters as IRunInTerminalInputParams , instance , 'cmd' ) ;
474
+ const result = await runInTerminalTool . rewriteCommandIfNeeded ( parameters , instance , 'cmd' ) ;
478
475
479
476
strictEqual ( result , 'npm test' ) ;
480
477
} ) ;
481
478
482
479
test ( 'should handle quoted paths with instance priority' , async ( ) => {
483
480
const instanceDir = 'C:\\instance\\workspace' ;
484
481
const command = 'cd "C:\\instance\\workspace" && npm test' ;
485
- const options = createRewriteOptions ( command , 'session-1' ) ;
482
+ const parameters = createRewriteParams ( command , 'session-1' ) ;
486
483
487
484
workspaceService . setWorkspace ( {
488
485
folders : [ { uri : { fsPath : 'C:\\different\\workspace' } } ]
489
486
} as any ) ;
490
487
const instance = createInstanceWithCwd ( { fsPath : instanceDir } as any ) ;
491
488
492
- const result = await runInTerminalTool . rewriteCommandIfNeeded ( options , options . parameters as IRunInTerminalInputParams , instance , 'cmd' ) ;
489
+ const result = await runInTerminalTool . rewriteCommandIfNeeded ( parameters , instance , 'cmd' ) ;
493
490
494
491
strictEqual ( result , 'npm test' ) ;
495
492
} ) ;
0 commit comments