From 01c577c371185a36acb79eabb4d13412aee3f8f1 Mon Sep 17 00:00:00 2001 From: Jacob Richman Date: Thu, 16 Oct 2025 14:55:16 -0700 Subject: [PATCH] Jacob314/safe home dir (#10861) --- integration-tests/globalSetup.ts | 43 ++++++++------------------------ 1 file changed, 11 insertions(+), 32 deletions(-) diff --git a/integration-tests/globalSetup.ts b/integration-tests/globalSetup.ts index 5ef7081e07..4fab2e261c 100644 --- a/integration-tests/globalSetup.ts +++ b/integration-tests/globalSetup.ts @@ -9,39 +9,29 @@ if (process.env['NO_COLOR'] !== undefined) { delete process.env['NO_COLOR']; } -import { - mkdir, - readdir, - rm, - readFile, - writeFile, - unlink, -} from 'node:fs/promises'; +import { mkdir, readdir, rm } from 'node:fs/promises'; import { join, dirname } from 'node:path'; import { fileURLToPath } from 'node:url'; -import { getGlobalMemoryFilePath } from '../packages/core/src/tools/memoryTool.js'; const __dirname = dirname(fileURLToPath(import.meta.url)); const rootDir = join(__dirname, '..'); const integrationTestsDir = join(rootDir, '.integration-tests'); let runDir = ''; // Make runDir accessible in teardown -const memoryFilePath = getGlobalMemoryFilePath(); -let originalMemoryContent: string | null = null; - export async function setup() { - try { - originalMemoryContent = await readFile(memoryFilePath, 'utf-8'); - } catch (e) { - if ((e as NodeJS.ErrnoException).code !== 'ENOENT') { - throw e; - } - // File doesn't exist, which is fine. - } - runDir = join(integrationTestsDir, `${Date.now()}`); await mkdir(runDir, { recursive: true }); + // Set the home directory to the test run directory to avoid conflicts + // with the user's local config. + process.env['HOME'] = runDir; + if (process.platform === 'win32') { + process.env['USERPROFILE'] = runDir; + } + // We also need to set the config dir explicitly, since the code might + // construct the path before the HOME env var is set. + process.env['GEMINI_CONFIG_DIR'] = join(runDir, '.gemini'); + // Clean up old test runs, but keep the latest few for debugging try { const testRuns = await readdir(integrationTestsDir); @@ -77,15 +67,4 @@ export async function teardown() { if (process.env['KEEP_OUTPUT'] !== 'true' && runDir) { await rm(runDir, { recursive: true, force: true }); } - - if (originalMemoryContent !== null) { - await mkdir(dirname(memoryFilePath), { recursive: true }); - await writeFile(memoryFilePath, originalMemoryContent, 'utf-8'); - } else { - try { - await unlink(memoryFilePath); - } catch { - // File might not exist if the test failed before creating it. - } - } }