From f54fe58d062b5a7ffd0dd8a9212e5cb19f421c6b Mon Sep 17 00:00:00 2001 From: Taylor Mullen Date: Mon, 9 Feb 2026 23:18:02 -0800 Subject: [PATCH] test: fix windows environment and cleanup issues - Ensure 'SystemRoot', 'COMSPEC', 'windir', and 'PATHEXT' are passed to node-pty on Windows to prevent 'posix_spawnp' failures. - Clean up test directories in 'TestRig.setup' to ensure a fresh state for retries and prevent telemetry log accumulation (fixing the 1, 2, 3 failure pattern). - Fix path normalization in 'Hook Disabling' test to ensure disabled hooks are correctly matched on Windows. Part of https://github.com/google-gemini/gemini-cli/pull/18665 --- integration-tests/hooks-system.test.ts | 2 +- packages/test-utils/src/test-rig.ts | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/integration-tests/hooks-system.test.ts b/integration-tests/hooks-system.test.ts index 0916c3b9d2..265f77428a 100644 --- a/integration-tests/hooks-system.test.ts +++ b/integration-tests/hooks-system.test.ts @@ -1831,7 +1831,7 @@ console.log(JSON.stringify({decision: "block", systemMessage: "Disabled hook sho settings: { hooksConfig: { enabled: true, - disabled: [`node "${disabledPath}"`], // Disable the second hook + disabled: [normalizePath(`node "${disabledPath}"`)], // Disable the second hook }, hooks: { BeforeTool: [ diff --git a/packages/test-utils/src/test-rig.ts b/packages/test-utils/src/test-rig.ts index 6d4446c919..56e735a915 100644 --- a/packages/test-utils/src/test-rig.ts +++ b/packages/test-utils/src/test-rig.ts @@ -367,6 +367,15 @@ export class TestRig { env['INTEGRATION_TEST_FILE_DIR'] || join(os.tmpdir(), 'gemini-cli-tests'); this.testDir = join(testFileDir, sanitizedName); this.homeDir = join(testFileDir, sanitizedName + '-home'); + + // Clean up existing directories from previous runs (e.g. retries) + if (fs.existsSync(this.testDir)) { + fs.rmSync(this.testDir, { recursive: true, force: true }); + } + if (fs.existsSync(this.homeDir)) { + fs.rmSync(this.homeDir, { recursive: true, force: true }); + } + mkdirSync(this.testDir, { recursive: true }); mkdirSync(this.homeDir, { recursive: true }); if (options.fakeResponsesPath) { @@ -1308,6 +1317,15 @@ export class TestRig { envVars['PATH'] = process.env['PATH']; } + // Add critical Windows environment variables if missing + if (process.platform === 'win32') { + ['SystemRoot', 'COMSPEC', 'windir', 'PATHEXT'].forEach((key) => { + if (!envVars[key] && process.env[key]) { + envVars[key] = process.env[key]; + } + }); + } + const ptyOptions: pty.IPtyForkOptions = { name: 'xterm-color', cols: 80,