fix(test): skip live auth browser caches (#91907)

* fix(test): skip live auth browser caches

* fix(test): scope Gemini live auth exclusions

---------

Co-authored-by: Peter Steinberger <steipete@gmail.com>
This commit is contained in:
Bryan Tegomoh, MD, MPH
2026-07-06 10:57:48 -07:00
committed by GitHub
parent a9b0a9a12b
commit e88f5cea7e
2 changed files with 82 additions and 2 deletions

View File

@@ -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", () => {

View File

@@ -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));