diff --git a/scripts/agent-evals/package.json b/scripts/agent-evals/package.json index 1900a9d92a5..f4bbe8df723 100644 --- a/scripts/agent-evals/package.json +++ b/scripts/agent-evals/package.json @@ -6,7 +6,7 @@ "scripts": { "build": "tsc", "test": "npm run build && mocha 'lib/**/*.spec.js' --reporter spec", - "test:dev": "SKIP_REBUILD=true npm run test" + "test:dev": "SKIP_REBUILD=true COPY_FIREBASE_CLI_CONFIG=true npm run test" }, "keywords": [], "author": "", diff --git a/scripts/agent-evals/src/runner/index.ts b/scripts/agent-evals/src/runner/index.ts index 0494e24a481..0a3919af6c1 100644 --- a/scripts/agent-evals/src/runner/index.ts +++ b/scripts/agent-evals/src/runner/index.ts @@ -1,6 +1,7 @@ import path from "node:path"; +import os from "node:os"; import { randomBytes } from "node:crypto"; -import { mkdirSync } from "node:fs"; +import { mkdirSync, copyFileSync } from "node:fs"; import { AgentTestRunner } from "./agent-test-runner.js"; import { GeminiCliRunner } from "./gemini-cli-runner.js"; import { buildFirebaseCli } from "./setup.js"; @@ -13,6 +14,10 @@ export * from "./agent-test-runner.js"; const dateName = new Date().toISOString().replace("T", "_").replace(/:/g, "-").replace(".", "-"); +const FIREBASE_CONFIG_FILENAME = "firebase-tools.json"; +const CONFIGSTORE_DIR = ".config/configstore"; +const HOME_CONFIGSTORE_DIR = path.resolve(path.join(os.homedir(), CONFIGSTORE_DIR)); + export async function setupEnvironment(): Promise { await buildFirebaseCli(); await buildTemplates(); @@ -40,6 +45,13 @@ export async function startAgentTest( if (options?.templateName) { copyTemplate(options.templateName, dirs.runDir); } + if (process.env.COPY_FIREBASE_CLI_CONFIG) { + const toDir = path.resolve(dirs.userDir, CONFIGSTORE_DIR); + console.log( + `Copying Firebase CLI configs from ${HOME_CONFIGSTORE_DIR} to \n${toDir} so the test can use your auth credentials`, + ); + copyFirebaseCliConfigstore(HOME_CONFIGSTORE_DIR, toDir); + } const run = new GeminiCliRunner(testName, dirs, options?.toolMocks || []); await run.waitForReadyPrompt(); @@ -65,3 +77,22 @@ function createRunDirectory(testName: string): RunDirectories { return { testDir, runDir, userDir }; } + +function copyFirebaseCliConfigstore(fromDir: string, toDir: string) { + mkdirSync(toDir, { recursive: true }); + try { + copyFileSync( + path.join(fromDir, FIREBASE_CONFIG_FILENAME), + path.join(toDir, FIREBASE_CONFIG_FILENAME), + ); + } catch (e: any) { + if (e.code === "ENOENT") { + const sourceFile = path.join(fromDir, FIREBASE_CONFIG_FILENAME); + console.warn( + `Firebase CLI config file not found at ${sourceFile}. Skipping copy. If you want to use your local Firebase login, please log in with the Firebase CLI.`, + ); + } else { + throw e; + } + } +}