|
| 1 | +/** |
| 2 | + * @license |
| 3 | + * Copyright 2026 Google LLC |
| 4 | + * SPDX-License-Identifier: Apache-2.0 |
| 5 | + */ |
| 6 | + |
| 7 | +import { describe, it, expect } from 'vitest'; |
| 8 | +import os from 'node:os'; |
| 9 | +import { ShellExecutionService } from './shellExecutionService.js'; |
| 10 | +import { NoopSandboxManager } from './sandboxManager.js'; |
| 11 | + |
| 12 | +const isWindows = os.platform() === 'win32'; |
| 13 | + |
| 14 | +/** |
| 15 | + * Real-shell integration tests that reproduce the regression class from |
| 16 | + * issue #25859: commands with inline double quotes executed on Windows |
| 17 | + * lose their quotes when they reach the native executable, because |
| 18 | + * Windows PowerShell 5.1 mangles embedded " during native-command |
| 19 | + * argument passing. PowerShell 7 (pwsh.exe) passes arguments correctly. |
| 20 | + * |
| 21 | + * These tests exercise the full pipeline end-to-end. They pass when |
| 22 | + * gemini-cli selects pwsh.exe from PATH; they fail when the pipeline |
| 23 | + * routes through Windows PowerShell 5.1. |
| 24 | + */ |
| 25 | +describe.skipIf(!isWindows)( |
| 26 | + 'ShellExecutionService Windows quoting (real shell)', |
| 27 | + () => { |
| 28 | + const baseConfig = { |
| 29 | + sanitizationConfig: { |
| 30 | + allowedEnvironmentVariables: [], |
| 31 | + blockedEnvironmentVariables: [], |
| 32 | + enableEnvironmentVariableRedaction: false, |
| 33 | + }, |
| 34 | + sandboxManager: new NoopSandboxManager(), |
| 35 | + }; |
| 36 | + |
| 37 | + async function runReal(command: string) { |
| 38 | + const controller = new AbortController(); |
| 39 | + const handle = await ShellExecutionService.execute( |
| 40 | + command, |
| 41 | + process.cwd(), |
| 42 | + () => {}, |
| 43 | + controller.signal, |
| 44 | + false, |
| 45 | + baseConfig, |
| 46 | + ); |
| 47 | + const result = await handle.result; |
| 48 | + return { result, output: result.output }; |
| 49 | + } |
| 50 | + |
| 51 | + it('should preserve inline double quotes through node -e', async () => { |
| 52 | + const { result, output } = await runReal( |
| 53 | + `node -e 'console.log("preserved")'`, |
| 54 | + ); |
| 55 | + expect(result.exitCode).toBe(0); |
| 56 | + expect(output).toBe('preserved'); |
| 57 | + }); |
| 58 | + |
| 59 | + it('should preserve double quotes inside JSON output', async () => { |
| 60 | + const { result, output } = await runReal( |
| 61 | + `node -e 'console.log(JSON.stringify({ok:"yes"}))'`, |
| 62 | + ); |
| 63 | + expect(result.exitCode).toBe(0); |
| 64 | + expect(output).toBe('{"ok":"yes"}'); |
| 65 | + }); |
| 66 | + |
| 67 | + it('should handle quoted argument containing a space', async () => { |
| 68 | + const { result, output } = await runReal( |
| 69 | + `node -e "console.log('hello world')"`, |
| 70 | + ); |
| 71 | + expect(result.exitCode).toBe(0); |
| 72 | + expect(output).toBe('hello world'); |
| 73 | + }); |
| 74 | + |
| 75 | + it('should handle a mixed-quote regex literal', async () => { |
| 76 | + const { result, output } = await runReal( |
| 77 | + `node -e 'console.log(String("a").match(/"/))'`, |
| 78 | + ); |
| 79 | + expect(result.exitCode).toBe(0); |
| 80 | + expect(output).toBe('null'); |
| 81 | + }); |
| 82 | + |
| 83 | + it('should pass a literal double-quote byte through to stdout', async () => { |
| 84 | + const { result, output } = await runReal(`node -e 'console.log("\\"")'`); |
| 85 | + expect(result.exitCode).toBe(0); |
| 86 | + expect(output).toBe('"'); |
| 87 | + }); |
| 88 | + }, |
| 89 | +); |
0 commit comments