mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-10 22:21:22 -07:00
fix(core): mock powershell output in shell-utils test (#15831)
This commit is contained in:
@@ -69,6 +69,24 @@ afterEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
const mockPowerShellResult = (
|
||||
commands: Array<{ name: string; text: string }>,
|
||||
hasRedirection: boolean,
|
||||
) => {
|
||||
mockSpawnSync.mockReturnValue({
|
||||
stdout: Buffer.from(
|
||||
JSON.stringify({
|
||||
success: true,
|
||||
commands,
|
||||
hasRedirection,
|
||||
}),
|
||||
),
|
||||
stderr: Buffer.from(''),
|
||||
status: 0,
|
||||
error: undefined,
|
||||
});
|
||||
};
|
||||
|
||||
describe('getCommandRoots', () => {
|
||||
it('should return a single command', () => {
|
||||
expect(getCommandRoots('ls -l')).toEqual(['ls']);
|
||||
@@ -197,6 +215,14 @@ describeWindowsOnly('PowerShell integration', () => {
|
||||
});
|
||||
|
||||
it('should return command roots using PowerShell AST output', () => {
|
||||
mockPowerShellResult(
|
||||
[
|
||||
{ name: 'Get-ChildItem', text: 'Get-ChildItem' },
|
||||
{ name: 'Select-Object', text: 'Select-Object Name' },
|
||||
],
|
||||
false,
|
||||
);
|
||||
|
||||
const roots = getCommandRoots('Get-ChildItem | Select-Object Name');
|
||||
expect(roots.length).toBeGreaterThan(0);
|
||||
expect(roots).toContain('Get-ChildItem');
|
||||
@@ -378,24 +404,6 @@ describe('hasRedirection (PowerShell via mock)', () => {
|
||||
process.env['ComSpec'] = 'powershell.exe';
|
||||
});
|
||||
|
||||
const mockPowerShellResult = (
|
||||
commands: Array<{ name: string; text: string }>,
|
||||
hasRedirection: boolean,
|
||||
) => {
|
||||
mockSpawnSync.mockReturnValue({
|
||||
stdout: Buffer.from(
|
||||
JSON.stringify({
|
||||
success: true,
|
||||
commands,
|
||||
hasRedirection,
|
||||
}),
|
||||
),
|
||||
stderr: Buffer.from(''),
|
||||
status: 0,
|
||||
error: undefined,
|
||||
});
|
||||
};
|
||||
|
||||
it('should return true when PowerShell parser detects redirection', () => {
|
||||
mockPowerShellResult([{ name: 'echo', text: 'echo hello' }], true);
|
||||
expect(hasRedirection('echo hello > file.txt')).toBe(true);
|
||||
|
||||
Reference in New Issue
Block a user