Skip to content

Commit a334aa3

Browse files
committed
Add tests for double ampersand rewriting
1 parent fc298c2 commit a334aa3

File tree

1 file changed

+42
-3
lines changed

1 file changed

+42
-3
lines changed

src/vs/workbench/contrib/terminalContrib/chatAgentTools/test/browser/commandSimplifier.test.ts renamed to src/vs/workbench/contrib/terminalContrib/chatAgentTools/test/electron-browser/commandSimplifier.test.ts

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,21 @@ import type { ITerminalInstance } from '../../../../terminal/browser/terminal.js
1515
import { URI } from '../../../../../../base/common/uri.js';
1616
import type { IRunInTerminalInputParams } from '../../browser/tools/runInTerminalTool.js';
1717
import { Workspace } from '../../../../../../platform/workspace/test/common/testWorkspace.js';
18+
import { TreeSitterCommandParser } from '../../browser/treeSitterCommandParser.js';
19+
import { ITreeSitterLibraryService } from '../../../../../../editor/common/services/treeSitter/treeSitterLibraryService.js';
20+
import { TestIPCFileSystemProvider } from '../../../../../test/electron-browser/workbenchTestServices.js';
21+
import { NullLogService } from '../../../../../../platform/log/common/log.js';
22+
import { FileService } from '../../../../../../platform/files/common/fileService.js';
23+
import { Schemas } from '../../../../../../base/common/network.js';
24+
import { TreeSitterLibraryService } from '../../../../../services/treeSitter/browser/treeSitterLibraryService.js';
1825

1926
suite('command re-writing', () => {
2027
const store = ensureNoDisposablesAreLeakedInTestSuite();
2128

2229
let instantiationService: TestInstantiationService;
2330
let workspaceService: TestContextService;
2431

32+
let parser: TreeSitterCommandParser;
2533
let commandSimplifier: CommandSimplifier;
2634

2735
function createRewriteParams(command: string, chatSessionId?: string): IRunInTerminalInputParams {
@@ -45,14 +53,27 @@ suite('command re-writing', () => {
4553
}
4654

4755
setup(() => {
48-
instantiationService = workbenchInstantiationService(undefined, store);
56+
const fileService = store.add(new FileService(new NullLogService()));
57+
const fileSystemProvider = new TestIPCFileSystemProvider();
58+
store.add(fileService.registerProvider(Schemas.file, fileSystemProvider));
59+
60+
instantiationService = workbenchInstantiationService({
61+
fileService: () => fileService,
62+
}, store);
63+
64+
const treeSitterLibraryService = store.add(instantiationService.createInstance(TreeSitterLibraryService));
65+
treeSitterLibraryService.isTest = true;
66+
instantiationService.stub(ITreeSitterLibraryService, treeSitterLibraryService);
67+
68+
parser = instantiationService.createInstance(TreeSitterCommandParser);
69+
4970
workspaceService = instantiationService.get(IWorkspaceContextService) as TestContextService;
5071
});
5172

5273
suite('cd <cwd> && <suffix> -> <suffix>', () => {
5374
(!isWindows ? suite : suite.skip)('Posix', () => {
5475
setup(() => {
55-
commandSimplifier = instantiationService.createInstance(CommandSimplifier, Promise.resolve(OperatingSystem.Linux));
76+
commandSimplifier = instantiationService.createInstance(CommandSimplifier, Promise.resolve(OperatingSystem.Linux), parser);
5677
});
5778

5879
test('should return original command when no cd prefix pattern matches', async () => {
@@ -168,7 +189,7 @@ suite('command re-writing', () => {
168189

169190
(isWindows ? suite : suite.skip)('Windows', () => {
170191
setup(() => {
171-
commandSimplifier = instantiationService.createInstance(CommandSimplifier, Promise.resolve(OperatingSystem.Windows));
192+
commandSimplifier = instantiationService.createInstance(CommandSimplifier, Promise.resolve(OperatingSystem.Windows), parser);
172193
});
173194

174195
test('should ignore any trailing back slash', async () => {
@@ -344,4 +365,22 @@ suite('command re-writing', () => {
344365
});
345366
});
346367
});
368+
369+
suite('PowerShell: && -> ;', () => {
370+
async function t(originalCommandLine: string, expectedResult: string) {
371+
const parameters = createRewriteParams(originalCommandLine);
372+
const result = await commandSimplifier.rewriteIfNeeded(parameters, undefined, 'pwsh');
373+
strictEqual(result, expectedResult);
374+
}
375+
setup(() => {
376+
commandSimplifier = instantiationService.createInstance(CommandSimplifier, Promise.resolve(OperatingSystem.Windows), parser);
377+
});
378+
379+
test('should rewrite && to ; in PowerShell commands', () => t('echo hello && echo world', 'echo hello ; echo world'));
380+
test('should rewrite multiple && to ; in PowerShell commands', () => t('echo first && echo second && echo third', 'echo first ; echo second ; echo third'));
381+
test('should handle complex commands with && operators', () => t('npm install && npm test && echo "build complete"', 'npm install ; npm test ; echo "build complete"'));
382+
test('should work with Windows PowerShell shell identifier', () => t('Get-Process && Stop-Process', 'Get-Process ; Stop-Process'));
383+
test('should preserve existing semicolons', () => t('echo hello; echo world && echo final', 'echo hello; echo world ; echo final'));
384+
test('should not rewrite strings', () => t('echo "&&" && Write-Host "&& &&" && "&&"', 'echo "&&" ; Write-Host "&& &&" ; "&&"'));
385+
});
347386
});

0 commit comments

Comments
 (0)