diff --git a/test/test-env.test.ts b/test/test-env.test.ts index 1a1acc944972..a0fae5de5c9a 100644 --- a/test/test-env.test.ts +++ b/test/test-env.test.ts @@ -133,6 +133,35 @@ describe("installTestEnv", () => { path.join(realHome, ".codex", "sessions", "2026", "02", "26", "rollout.jsonl"), "session\n", ); + writeFile(path.join(realHome, ".gemini", "oauth_creds.json"), '{"token":"gemini"}\n'); + writeFile(path.join(realHome, ".gemini", "settings.json"), '{"theme":"dark"}\n'); + writeFile(path.join(realHome, ".gemini", "commands", "Cache", "review.toml"), "prompt\n"); + writeFile(path.join(realHome, ".minimax", "Cache", "credentials.json"), "minimax\n"); + writeFile( + path.join( + realHome, + ".gemini", + "antigravity-browser-profile", + "Default", + "Cache", + "Cache_Data", + "blob", + ), + "cached-browser-bytes\n", + ); + writeFile( + path.join(realHome, ".gemini", "antigravity", "browser_recordings", "session.webm"), + "recording\n", + ); + writeFile( + path.join(realHome, ".gemini", "cli-browser-profile", "Default", "History"), + "browser-history\n", + ); + writeFile(path.join(realHome, ".gemini", "GPUCache", "data.bin"), "gpu-cache\n"); + writeFile( + path.join(realHome, ".gemini", "Service Worker", "CacheStorage", "cache.bin"), + "worker-cache\n", + ); setTestEnvValue("HOME", realHome); setTestEnvValue("USERPROFILE", realHome); @@ -214,6 +243,27 @@ describe("installTestEnv", () => { expect(fs.existsSync(path.join(testEnv.tempHome, ".codex", "auth.json"))).toBe(true); expect(fs.existsSync(path.join(testEnv.tempHome, ".codex", "config.toml"))).toBe(true); expect(fs.existsSync(path.join(testEnv.tempHome, ".codex", "sessions"))).toBe(false); + expect(fs.existsSync(path.join(testEnv.tempHome, ".gemini", "oauth_creds.json"))).toBe(true); + expect(fs.existsSync(path.join(testEnv.tempHome, ".gemini", "settings.json"))).toBe(true); + expect( + fs.existsSync(path.join(testEnv.tempHome, ".gemini", "commands", "Cache", "review.toml")), + ).toBe(true); + expect( + fs.existsSync(path.join(testEnv.tempHome, ".minimax", "Cache", "credentials.json")), + ).toBe(true); + expect( + fs.existsSync(path.join(testEnv.tempHome, ".gemini", "antigravity-browser-profile")), + ).toBe(false); + expect( + fs.existsSync(path.join(testEnv.tempHome, ".gemini", "antigravity", "browser_recordings")), + ).toBe(false); + expect(fs.existsSync(path.join(testEnv.tempHome, ".gemini", "cli-browser-profile"))).toBe( + false, + ); + expect(fs.existsSync(path.join(testEnv.tempHome, ".gemini", "GPUCache"))).toBe(false); + expect( + fs.existsSync(path.join(testEnv.tempHome, ".gemini", "Service Worker", "CacheStorage")), + ).toBe(false); }); it("allows explicit live runs against the real HOME", () => { diff --git a/test/test-env.ts b/test/test-env.ts index bdd12a643377..65204c572301 100644 --- a/test/test-env.ts +++ b/test/test-env.ts @@ -31,6 +31,14 @@ const LIVE_EXTERNAL_AUTH_FILES = [ ".codex/auth.json", ".codex/config.toml", ] as const; +// Keep Gemini credentials and user configuration; only generated browser data can be dropped. +const LIVE_GEMINI_EXCLUDED_PATHS = [ + "antigravity-browser-profile", + "antigravity/browser_recordings", + "cli-browser-profile", + "GPUCache", + "Service Worker/CacheStorage", +] as const; const requireFromHere = createRequire(import.meta.url); type LegacyConfigCompatApi = typeof import("../src/commands/doctor/shared/legacy-config-compat.js"); @@ -264,7 +272,23 @@ function ensureParentDir(targetPath: string): void { fs.mkdirSync(path.dirname(targetPath), { recursive: true }); } -function copyDirIfExists(sourcePath: string, targetPath: string): void { +function shouldStageLiveGeminiPath(sourceRoot: string, sourcePath: string): boolean { + const relativePath = path.relative(sourceRoot, sourcePath); + if (!relativePath || relativePath.startsWith("..")) { + return true; + } + const normalizedPath = relativePath.split(path.sep).join("/"); + return !LIVE_GEMINI_EXCLUDED_PATHS.some( + (excludedPath) => + normalizedPath === excludedPath || normalizedPath.startsWith(`${excludedPath}/`), + ); +} + +function copyDirIfExists( + sourcePath: string, + targetPath: string, + options?: { filter?: (sourcePath: string) => boolean }, +): void { if (!fs.existsSync(sourcePath)) { return; } @@ -272,6 +296,7 @@ function copyDirIfExists(sourcePath: string, targetPath: string): void { fs.cpSync(sourcePath, targetPath, { recursive: true, force: true, + filter: options?.filter, }); } @@ -423,7 +448,12 @@ function stageLiveTestState(params: { copyLiveAuthProfiles(realStateDir, tempStateDir); for (const authDir of LIVE_EXTERNAL_AUTH_DIRS) { - copyDirIfExists(path.join(params.realHome, authDir), path.join(params.tempHome, authDir)); + const sourcePath = path.join(params.realHome, authDir); + const filter = + authDir === ".gemini" + ? (entryPath: string) => shouldStageLiveGeminiPath(sourcePath, entryPath) + : undefined; + copyDirIfExists(sourcePath, path.join(params.tempHome, authDir), { filter }); } for (const authFile of LIVE_EXTERNAL_AUTH_FILES) { copyFileIfExists(path.join(params.realHome, authFile), path.join(params.tempHome, authFile));