Skip to content

Commit 86e3888

Browse files
authored
Agent Evals: Copy Firebase CLI configs in dev mode (#9472)
1 parent 513e809 commit 86e3888

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

scripts/agent-evals/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"scripts": {
77
"build": "tsc",
88
"test": "npm run build && mocha 'lib/**/*.spec.js' --reporter spec",
9-
"test:dev": "SKIP_REBUILD=true npm run test"
9+
"test:dev": "SKIP_REBUILD=true COPY_FIREBASE_CLI_CONFIG=true npm run test"
1010
},
1111
"keywords": [],
1212
"author": "",

scripts/agent-evals/src/runner/index.ts

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import path from "node:path";
2+
import os from "node:os";
23
import { randomBytes } from "node:crypto";
3-
import { mkdirSync } from "node:fs";
4+
import { mkdirSync, copyFileSync } from "node:fs";
45
import { AgentTestRunner } from "./agent-test-runner.js";
56
import { GeminiCliRunner } from "./gemini-cli-runner.js";
67
import { buildFirebaseCli } from "./setup.js";
@@ -13,6 +14,10 @@ export * from "./agent-test-runner.js";
1314

1415
const dateName = new Date().toISOString().replace("T", "_").replace(/:/g, "-").replace(".", "-");
1516

17+
const FIREBASE_CONFIG_FILENAME = "firebase-tools.json";
18+
const CONFIGSTORE_DIR = ".config/configstore";
19+
const HOME_CONFIGSTORE_DIR = path.resolve(path.join(os.homedir(), CONFIGSTORE_DIR));
20+
1621
export async function setupEnvironment(): Promise<void> {
1722
await buildFirebaseCli();
1823
await buildTemplates();
@@ -40,6 +45,13 @@ export async function startAgentTest(
4045
if (options?.templateName) {
4146
copyTemplate(options.templateName, dirs.runDir);
4247
}
48+
if (process.env.COPY_FIREBASE_CLI_CONFIG) {
49+
const toDir = path.resolve(dirs.userDir, CONFIGSTORE_DIR);
50+
console.log(
51+
`Copying Firebase CLI configs from ${HOME_CONFIGSTORE_DIR} to \n${toDir} so the test can use your auth credentials`,
52+
);
53+
copyFirebaseCliConfigstore(HOME_CONFIGSTORE_DIR, toDir);
54+
}
4355

4456
const run = new GeminiCliRunner(testName, dirs, options?.toolMocks || []);
4557
await run.waitForReadyPrompt();
@@ -65,3 +77,22 @@ function createRunDirectory(testName: string): RunDirectories {
6577

6678
return { testDir, runDir, userDir };
6779
}
80+
81+
function copyFirebaseCliConfigstore(fromDir: string, toDir: string) {
82+
mkdirSync(toDir, { recursive: true });
83+
try {
84+
copyFileSync(
85+
path.join(fromDir, FIREBASE_CONFIG_FILENAME),
86+
path.join(toDir, FIREBASE_CONFIG_FILENAME),
87+
);
88+
} catch (e: any) {
89+
if (e.code === "ENOENT") {
90+
const sourceFile = path.join(fromDir, FIREBASE_CONFIG_FILENAME);
91+
console.warn(
92+
`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.`,
93+
);
94+
} else {
95+
throw e;
96+
}
97+
}
98+
}

0 commit comments

Comments
 (0)