mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-26 13:04:49 -07:00
refactor: Replace exec with spawn (#8510)
This commit is contained in:
@@ -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' },
|
||||
);
|
||||
});
|
||||
|
||||
@@ -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.`,
|
||||
|
||||
Reference in New Issue
Block a user