refactor: Replace exec with spawn (#8510)

This commit is contained in:
Gal Zahavi
2025-09-16 12:03:17 -07:00
committed by GitHub
parent a015ea203f
commit 986b9fe7e9
11 changed files with 330 additions and 295 deletions
+15 -3
View File
@@ -12,7 +12,14 @@ import * as os from 'node:os';
import * as path from 'node:path';
import { DetectedIde } from './detect-ide.js';
vi.mock('child_process');
vi.mock('node:child_process', async (importOriginal) => {
const actual = (await importOriginal()) as typeof child_process;
return {
...actual,
execSync: vi.fn(),
spawnSync: vi.fn(() => ({ status: 0 })),
};
});
vi.mock('fs');
vi.mock('os');
@@ -97,8 +104,13 @@ describe('ide-installer', () => {
platform: 'linux',
});
await installer.install();
expect(child_process.execSync).toHaveBeenCalledWith(
'"code" --install-extension google.gemini-cli-vscode-ide-companion --force',
expect(child_process.spawnSync).toHaveBeenCalledWith(
'code',
[
'--install-extension',
'google.gemini-cli-vscode-ide-companion',
'--force',
],
{ stdio: 'pipe' },
);
});
+16 -2
View File
@@ -119,9 +119,23 @@ class VsCodeInstaller implements IdeInstaller {
};
}
const command = `"${commandPath}" --install-extension google.gemini-cli-vscode-ide-companion --force`;
try {
child_process.execSync(command, { stdio: 'pipe' });
const result = child_process.spawnSync(
commandPath,
[
'--install-extension',
'google.gemini-cli-vscode-ide-companion',
'--force',
],
{ stdio: 'pipe' },
);
if (result.status !== 0) {
throw new Error(
`Failed to install extension: ${result.stderr?.toString()}`,
);
}
return {
success: true,
message: `${this.ideInfo.displayName} companion extension was installed successfully.`,