11import { describe , expect , it , vi , beforeEach , afterEach } from "vitest" ;
2- import { join } from "node:path" ;
2+ import { join , parse } from "node:path" ;
33
44// Mock fs module before importing the module under test
55const mockExistsSync = vi . fn ( ) ;
@@ -19,7 +19,9 @@ vi.mock("node:fs", async (importOriginal) => {
1919} ) ;
2020
2121describe ( "extractGeminiCliCredentials" , ( ) => {
22- const normalizePath = ( value : string ) => value . replace ( / \\ / g, "/" ) ;
22+ const normalizePath = ( value : string ) =>
23+ value . replace ( / \\ / g, "/" ) . replace ( / \/ + $ / , "" ) . toLowerCase ( ) ;
24+ const rootDir = parse ( process . cwd ( ) ) . root || "/" ;
2325 const FAKE_CLIENT_ID = "123456789-abcdef.apps.googleusercontent.com" ;
2426 const FAKE_CLIENT_SECRET = "GOCSPX-FakeSecretValue123" ;
2527 const FAKE_OAUTH2_CONTENT = `
@@ -49,11 +51,33 @@ describe("extractGeminiCliCredentials", () => {
4951 } ) ;
5052
5153 it ( "extracts credentials from oauth2.js in known path" , async ( ) => {
52- const fakeBinDir = "/ fake/ bin";
54+ const fakeBinDir = join ( rootDir , " fake" , " bin") ;
5355 const fakeGeminiPath = join ( fakeBinDir , "gemini" ) ;
54- const fakeResolvedPath = "/fake/lib/node_modules/@google/gemini-cli/dist/index.js" ;
55- const fakeOauth2Path =
56- "/fake/lib/node_modules/@google/gemini-cli/node_modules/@google/gemini-cli-core/dist/src/code_assist/oauth2.js" ;
56+ const fakeResolvedPath = join (
57+ rootDir ,
58+ "fake" ,
59+ "lib" ,
60+ "node_modules" ,
61+ "@google" ,
62+ "gemini-cli" ,
63+ "dist" ,
64+ "index.js" ,
65+ ) ;
66+ const fakeOauth2Path = join (
67+ rootDir ,
68+ "fake" ,
69+ "lib" ,
70+ "node_modules" ,
71+ "@google" ,
72+ "gemini-cli" ,
73+ "node_modules" ,
74+ "@google" ,
75+ "gemini-cli-core" ,
76+ "dist" ,
77+ "src" ,
78+ "code_assist" ,
79+ "oauth2.js" ,
80+ ) ;
5781
5882 process . env . PATH = fakeBinDir ;
5983
@@ -77,9 +101,18 @@ describe("extractGeminiCliCredentials", () => {
77101 } ) ;
78102
79103 it ( "returns null when oauth2.js cannot be found" , async ( ) => {
80- const fakeBinDir = "/ fake/ bin";
104+ const fakeBinDir = join ( rootDir , " fake" , " bin") ;
81105 const fakeGeminiPath = join ( fakeBinDir , "gemini" ) ;
82- const fakeResolvedPath = "/fake/lib/node_modules/@google/gemini-cli/dist/index.js" ;
106+ const fakeResolvedPath = join (
107+ rootDir ,
108+ "fake" ,
109+ "lib" ,
110+ "node_modules" ,
111+ "@google" ,
112+ "gemini-cli" ,
113+ "dist" ,
114+ "index.js" ,
115+ ) ;
83116
84117 process . env . PATH = fakeBinDir ;
85118
@@ -95,11 +128,33 @@ describe("extractGeminiCliCredentials", () => {
95128 } ) ;
96129
97130 it ( "returns null when oauth2.js lacks credentials" , async ( ) => {
98- const fakeBinDir = "/ fake/ bin";
131+ const fakeBinDir = join ( rootDir , " fake" , " bin") ;
99132 const fakeGeminiPath = join ( fakeBinDir , "gemini" ) ;
100- const fakeResolvedPath = "/fake/lib/node_modules/@google/gemini-cli/dist/index.js" ;
101- const fakeOauth2Path =
102- "/fake/lib/node_modules/@google/gemini-cli/node_modules/@google/gemini-cli-core/dist/src/code_assist/oauth2.js" ;
133+ const fakeResolvedPath = join (
134+ rootDir ,
135+ "fake" ,
136+ "lib" ,
137+ "node_modules" ,
138+ "@google" ,
139+ "gemini-cli" ,
140+ "dist" ,
141+ "index.js" ,
142+ ) ;
143+ const fakeOauth2Path = join (
144+ rootDir ,
145+ "fake" ,
146+ "lib" ,
147+ "node_modules" ,
148+ "@google" ,
149+ "gemini-cli" ,
150+ "node_modules" ,
151+ "@google" ,
152+ "gemini-cli-core" ,
153+ "dist" ,
154+ "src" ,
155+ "code_assist" ,
156+ "oauth2.js" ,
157+ ) ;
103158
104159 process . env . PATH = fakeBinDir ;
105160
@@ -118,11 +173,33 @@ describe("extractGeminiCliCredentials", () => {
118173 } ) ;
119174
120175 it ( "caches credentials after first extraction" , async ( ) => {
121- const fakeBinDir = "/ fake/ bin";
176+ const fakeBinDir = join ( rootDir , " fake" , " bin") ;
122177 const fakeGeminiPath = join ( fakeBinDir , "gemini" ) ;
123- const fakeResolvedPath = "/fake/lib/node_modules/@google/gemini-cli/dist/index.js" ;
124- const fakeOauth2Path =
125- "/fake/lib/node_modules/@google/gemini-cli/node_modules/@google/gemini-cli-core/dist/src/code_assist/oauth2.js" ;
178+ const fakeResolvedPath = join (
179+ rootDir ,
180+ "fake" ,
181+ "lib" ,
182+ "node_modules" ,
183+ "@google" ,
184+ "gemini-cli" ,
185+ "dist" ,
186+ "index.js" ,
187+ ) ;
188+ const fakeOauth2Path = join (
189+ rootDir ,
190+ "fake" ,
191+ "lib" ,
192+ "node_modules" ,
193+ "@google" ,
194+ "gemini-cli" ,
195+ "node_modules" ,
196+ "@google" ,
197+ "gemini-cli-core" ,
198+ "dist" ,
199+ "src" ,
200+ "code_assist" ,
201+ "oauth2.js" ,
202+ ) ;
126203
127204 process . env . PATH = fakeBinDir ;
128205
0 commit comments