11import path from "node:path" ;
22import { randomBytes } from "node:crypto" ;
3- import { mkdirSync } from "node:fs" ;
3+ import { mkdirSync , copyFileSync } from "node:fs" ;
44import { AgentTestRunner } from "./agent-test-runner.js" ;
55import { GeminiCliRunner } from "./gemini-cli-runner.js" ;
66import { buildFirebaseCli } from "./setup.js" ;
@@ -13,6 +13,10 @@ export * from "./agent-test-runner.js";
1313
1414const dateName = new Date ( ) . toISOString ( ) . replace ( "T" , "_" ) . replace ( / : / g, "-" ) . replace ( "." , "-" ) ;
1515
16+ const FIREBASE_CONFIG_FILENAME = "firebase-tools.json" ;
17+ const CONFIGSTORE_DIR = ".config/configstore" ;
18+ const HOME_CONFIGSTORE_DIR = path . resolve ( path . join ( process . env . HOME || "" , CONFIGSTORE_DIR ) ) ;
19+
1620export async function setupEnvironment ( ) : Promise < void > {
1721 await buildFirebaseCli ( ) ;
1822 await buildTemplates ( ) ;
@@ -40,6 +44,13 @@ export async function startAgentTest(
4044 if ( options ?. templateName ) {
4145 copyTemplate ( options . templateName , dirs . runDir ) ;
4246 }
47+ if ( process . env . COPY_FIREBASE_CLI_CONFIG ) {
48+ const toDir = path . resolve ( dirs . userDir , CONFIGSTORE_DIR ) ;
49+ console . log (
50+ `Copying Firebase CLI configs from ${ HOME_CONFIGSTORE_DIR } to \n${ toDir } so the test can use your auth credentials` ,
51+ ) ;
52+ copyFirebaseCliConfigstore ( HOME_CONFIGSTORE_DIR , toDir ) ;
53+ }
4354
4455 const run = new GeminiCliRunner ( testName , dirs , options ?. toolMocks || [ ] ) ;
4556 await run . waitForReadyPrompt ( ) ;
@@ -65,3 +76,13 @@ function createRunDirectory(testName: string): RunDirectories {
6576
6677 return { testDir, runDir, userDir } ;
6778}
79+
80+ function copyFirebaseCliConfigstore ( fromDir : string , toDir : string ) {
81+ const toDirResolved = path . resolve ( toDir ) ;
82+ mkdirSync ( toDirResolved , { recursive : true } ) ;
83+
84+ copyFileSync (
85+ path . join ( fromDir , FIREBASE_CONFIG_FILENAME ) ,
86+ path . join ( toDirResolved , FIREBASE_CONFIG_FILENAME ) ,
87+ ) ;
88+ }
0 commit comments