@@ -10,11 +10,12 @@ import {
1010} from "./tool-matcher.js" ;
1111import fs from "fs" ;
1212import { throwFailure } from "./logging.js" ;
13- import { getAgentEvalsRoot } from "./paths.js" ;
13+ import { getAgentEvalsRoot , RunDirectories } from "./paths.js" ;
1414import { execSync } from "node:child_process" ;
1515import { ToolMockName } from "../mock/tool-mocks.js" ;
1616
1717const READY_PROMPT = "Type your message" ;
18+ const INSTALL_ID = "238efa5b-efb2-44bd-9dce-9b081532681c" ;
1819
1920interface ParsedTelemetryLog {
2021 attributes ?: {
@@ -44,15 +45,16 @@ export class GeminiCliRunner implements AgentTestRunner {
4445
4546 constructor (
4647 private readonly testName : string ,
47- testDir : string ,
48- runDir : string ,
48+ dirs : RunDirectories ,
4949 toolMocks : ToolMockName [ ] ,
5050 ) {
5151 // Create a settings file to point the CLI to a local telemetry log
52- this . telemetryPath = path . join ( testDir , "telemetry.log" ) ;
52+ this . telemetryPath = path . join ( dirs . testDir , "telemetry.log" ) ;
5353 const mockPath = path . resolve ( path . join ( getAgentEvalsRoot ( ) , "lib/mock/mock-tools-main.js" ) ) ;
5454 const firebasePath = execSync ( "which firebase" ) . toString ( ) . trim ( ) ;
55- const settings = {
55+
56+ // Write workspace Gemini Settings
57+ this . writeGeminiSettings ( dirs . runDir , {
5658 general : {
5759 disableAutoUpdate : true ,
5860 } ,
@@ -71,15 +73,29 @@ export class GeminiCliRunner implements AgentTestRunner {
7173 } ,
7274 } ,
7375 } ,
74- } ;
75- const geminiDir = path . join ( runDir , ".gemini" ) ;
76- mkdirSync ( geminiDir , { recursive : true } ) ;
77- writeFileSync ( path . join ( geminiDir , "settings.json" ) , JSON . stringify ( settings , null , 2 ) ) ;
76+ } ) ;
77+
78+ // Write user Gemini Settings
79+ this . writeGeminiSettings ( dirs . userDir , {
80+ security : {
81+ auth : {
82+ selectedType : "gemini-api-key" ,
83+ } ,
84+ } ,
85+ hasSeenIdeIntegrationNudge : true ,
86+ } ) ;
87+
88+ this . writeGeminiInstallId ( dirs . userDir ) ;
7889
7990 this . cli = new InteractiveCLI ( "gemini" , [ "--yolo" ] , {
80- cwd : runDir ,
91+ cwd : dirs . runDir ,
8192 readyPrompt : READY_PROMPT ,
8293 showOutput : true ,
94+ env : {
95+ // Overwrite $HOME so that we can support GCLI features that only apply
96+ // on a per-user basis, like memories and extensions
97+ HOME : dirs . userDir ,
98+ } ,
8399 } ) ;
84100 }
85101
@@ -101,6 +117,21 @@ export class GeminiCliRunner implements AgentTestRunner {
101117 await this . cli . kill ( ) ;
102118 }
103119
120+ writeGeminiSettings ( dir : string , settings : any ) {
121+ const geminiDir = path . join ( dir , ".gemini" ) ;
122+ mkdirSync ( geminiDir , { recursive : true } ) ;
123+ writeFileSync ( path . join ( geminiDir , "settings.json" ) , JSON . stringify ( settings , null , 2 ) ) ;
124+ }
125+
126+ /**
127+ * Writes a constant, real install ID so that we don't bump Gemini metrics
128+ * with fake users
129+ */
130+ writeGeminiInstallId ( userDir : string ) {
131+ const geminiDir = path . join ( userDir , ".gemini" ) ;
132+ writeFileSync ( path . join ( geminiDir , "installation_id" ) , INSTALL_ID ) ;
133+ }
134+
104135 /**
105136 * Reads the agent's telemetry file and looks for the given event. Throws if
106137 * the event is not found
0 commit comments