@@ -500,6 +500,84 @@ suite('RunInTerminalTool', () => {
500
500
501
501
strictEqual ( result , 'npm test' ) ;
502
502
} ) ;
503
+
504
+ test ( 'should handle cd /d flag when directory matches cwd' , async ( ) => {
505
+ const testDir = 'C:\\test\\workspace' ;
506
+ const options = createRewriteParams ( `cd /d ${ testDir } && echo hello` , 'session-1' ) ;
507
+ workspaceService . setWorkspace ( {
508
+ folders : [ { uri : { fsPath : testDir } } ]
509
+ } as any ) ;
510
+
511
+ const result = await runInTerminalTool . rewriteCommandIfNeeded ( options , undefined , 'pwsh' ) ;
512
+
513
+ strictEqual ( result , 'echo hello' ) ;
514
+ } ) ;
515
+
516
+ test ( 'should handle cd /d flag with quoted paths when directory matches cwd' , async ( ) => {
517
+ const testDir = 'C:\\test\\workspace' ;
518
+ const options = createRewriteParams ( `cd /d "${ testDir } " && echo hello` , 'session-1' ) ;
519
+ workspaceService . setWorkspace ( {
520
+ folders : [ { uri : { fsPath : testDir } } ]
521
+ } as any ) ;
522
+
523
+ const result = await runInTerminalTool . rewriteCommandIfNeeded ( options , undefined , 'pwsh' ) ;
524
+
525
+ strictEqual ( result , 'echo hello' ) ;
526
+ } ) ;
527
+
528
+ test ( 'should handle cd /d flag with quoted paths from issue example' , async ( ) => {
529
+ const testDir = 'd:\\microsoft\\vscode' ;
530
+ const options = createRewriteParams ( `cd /d "${ testDir } " && .\\scripts\\test.bat` , 'session-1' ) ;
531
+ workspaceService . setWorkspace ( {
532
+ folders : [ { uri : { fsPath : testDir } } ]
533
+ } as any ) ;
534
+
535
+ const result = await runInTerminalTool . rewriteCommandIfNeeded ( options , undefined , 'pwsh' ) ;
536
+
537
+ strictEqual ( result , '.\\scripts\\test.bat' ) ;
538
+ } ) ;
539
+
540
+ test ( 'should not rewrite cd /d when directory does not match cwd' , async ( ) => {
541
+ const testDir = 'C:\\test\\workspace' ;
542
+ const differentDir = 'C:\\different\\path' ;
543
+ const command = `cd /d ${ differentDir } && echo hello` ;
544
+ const options = createRewriteParams ( command , 'session-1' ) ;
545
+ workspaceService . setWorkspace ( {
546
+ folders : [ { uri : { fsPath : testDir } } ]
547
+ } as any ) ;
548
+
549
+ const result = await runInTerminalTool . rewriteCommandIfNeeded ( options , undefined , 'pwsh' ) ;
550
+
551
+ strictEqual ( result , command ) ;
552
+ } ) ;
553
+
554
+ test ( 'should handle cd /d flag with instance priority' , async ( ) => {
555
+ const instanceDir = 'C:\\instance\\workspace' ;
556
+ const workspaceDir = 'C:\\workspace\\service' ;
557
+ const command = `cd /d ${ instanceDir } && npm test` ;
558
+ const parameters = createRewriteParams ( command , 'session-1' ) ;
559
+
560
+ workspaceService . setWorkspace ( {
561
+ folders : [ { uri : { fsPath : workspaceDir } } ]
562
+ } as any ) ;
563
+ const instance = createInstanceWithCwd ( { fsPath : instanceDir } as any ) ;
564
+
565
+ const result = await runInTerminalTool . rewriteCommandIfNeeded ( parameters , instance , 'pwsh' ) ;
566
+
567
+ strictEqual ( result , 'npm test' ) ;
568
+ } ) ;
569
+
570
+ test ( 'should handle cd /d flag with semicolon separator' , async ( ) => {
571
+ const testDir = 'C:\\test\\workspace' ;
572
+ const options = createRewriteParams ( `cd /d ${ testDir } ; echo hello` , 'session-1' ) ;
573
+ workspaceService . setWorkspace ( {
574
+ folders : [ { uri : { fsPath : testDir } } ]
575
+ } as any ) ;
576
+
577
+ const result = await runInTerminalTool . rewriteCommandIfNeeded ( options , undefined , 'pwsh' ) ;
578
+
579
+ strictEqual ( result , 'echo hello' ) ;
580
+ } ) ;
503
581
} ) ;
504
582
} ) ;
505
583
} ) ;
0 commit comments