11import path from "node:path" ;
2+ import os from "node:os" ;
23import { randomBytes } from "node:crypto" ;
3- import { mkdirSync } from "node:fs" ;
4+ import { mkdirSync , copyFileSync } from "node:fs" ;
45import { AgentTestRunner } from "./agent-test-runner.js" ;
56import { GeminiCliRunner } from "./gemini-cli-runner.js" ;
67import { buildFirebaseCli } from "./setup.js" ;
@@ -13,6 +14,10 @@ export * from "./agent-test-runner.js";
1314
1415const 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+
1621export 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