@@ -19,11 +19,11 @@ import {
1919} from '@google/gemini-cli-core' ;
2020
2121// Mock os.homedir to control the home directory in tests
22- vi . mock ( 'os' , async ( importOriginal ) => {
22+ vi . mock ( 'node: os' , async ( importOriginal ) => {
2323 const actualOs = await importOriginal < typeof os > ( ) ;
2424 return {
2525 ...actualOs ,
26- homedir : vi . fn ( ) ,
26+ homedir : vi . fn ( ( ) => actualOs . homedir ( ) ) ,
2727 } ;
2828} ) ;
2929
@@ -32,7 +32,6 @@ vi.mock('@google/gemini-cli-core', async (importOriginal) => {
3232 await importOriginal < typeof import ( '@google/gemini-cli-core' ) > ( ) ;
3333 return {
3434 ...actual ,
35- homedir : ( ) => os . homedir ( ) ,
3635 getCompatibilityWarnings : vi . fn ( ) . mockReturnValue ( [ ] ) ,
3736 isHeadlessMode : vi . fn ( ) . mockReturnValue ( false ) ,
3837 WarningPriority : {
@@ -66,6 +65,7 @@ describe('getUserStartupWarnings', () => {
6665
6766 afterEach ( async ( ) => {
6867 await fs . rm ( testRootDir , { recursive : true , force : true } ) ;
68+ vi . unstubAllEnvs ( ) ;
6969 vi . restoreAllMocks ( ) ;
7070 } ) ;
7171
@@ -98,6 +98,54 @@ describe('getUserStartupWarnings', () => {
9898 expect ( warnings . find ( ( w ) => w . id === 'home-directory' ) ) . toBeUndefined ( ) ;
9999 } ) ;
100100
101+ it ( 'should not return a warning when running in a subdirectory of home' , async ( ) => {
102+ const subDir = path . join ( homeDir , 'projects' , 'my-app' ) ;
103+ await fs . mkdir ( subDir , { recursive : true } ) ;
104+ const warnings = await getUserStartupWarnings ( { } , subDir ) ;
105+ expect ( warnings . find ( ( w ) => w . id === 'home-directory' ) ) . toBeUndefined ( ) ;
106+ } ) ;
107+
108+ it ( 'should not return a warning when home directory is a symlink and running in a subdirectory' , async ( ) => {
109+ const realHome = path . join ( testRootDir , 'real-home' ) ;
110+ await fs . mkdir ( realHome , { recursive : true } ) ;
111+ const symlinkedHome = path . join ( testRootDir , 'symlinked-home' ) ;
112+ await fs . symlink ( realHome , symlinkedHome ) ;
113+ vi . mocked ( os . homedir ) . mockReturnValue ( symlinkedHome ) ;
114+
115+ const subDir = path . join ( symlinkedHome , 'projects' ) ;
116+ await fs . mkdir ( subDir , { recursive : true } ) ;
117+ const warnings = await getUserStartupWarnings ( { } , subDir ) ;
118+ expect ( warnings . find ( ( w ) => w . id === 'home-directory' ) ) . toBeUndefined ( ) ;
119+ } ) ;
120+
121+ it ( 'should return a warning when home directory is a symlink and running in it' , async ( ) => {
122+ const realHome = path . join ( testRootDir , 'real-home2' ) ;
123+ await fs . mkdir ( realHome , { recursive : true } ) ;
124+ const symlinkedHome = path . join ( testRootDir , 'symlinked-home2' ) ;
125+ await fs . symlink ( realHome , symlinkedHome ) ;
126+ vi . mocked ( os . homedir ) . mockReturnValue ( symlinkedHome ) ;
127+
128+ const warnings = await getUserStartupWarnings ( { } , symlinkedHome ) ;
129+ expect ( warnings ) . toContainEqual (
130+ expect . objectContaining ( {
131+ id : 'home-directory' ,
132+ message : expect . stringContaining (
133+ 'Warning you are running Gemini CLI in your home directory' ,
134+ ) ,
135+ priority : WarningPriority . Low ,
136+ } ) ,
137+ ) ;
138+ } ) ;
139+
140+ it ( 'should not return a warning when GEMINI_CLI_HOME differs from os.homedir' , async ( ) => {
141+ const projectDir = path . join ( testRootDir , 'project' ) ;
142+ await fs . mkdir ( projectDir , { recursive : true } ) ;
143+ vi . stubEnv ( 'GEMINI_CLI_HOME' , projectDir ) ;
144+
145+ const warnings = await getUserStartupWarnings ( { } , projectDir ) ;
146+ expect ( warnings . find ( ( w ) => w . id === 'home-directory' ) ) . toBeUndefined ( ) ;
147+ } ) ;
148+
101149 it ( 'should not return a warning when folder trust is enabled and workspace is trusted' , async ( ) => {
102150 vi . mocked ( isFolderTrustEnabled ) . mockReturnValue ( true ) ;
103151 vi . mocked ( isWorkspaceTrusted ) . mockReturnValue ( {
0 commit comments