@@ -15,6 +15,7 @@ import {
1515 shouldAutoUseCredits ,
1616 shouldShowOverageMenu ,
1717 shouldShowEmptyWalletMenu ,
18+ shouldLaunchBrowser ,
1819 logBillingEvent ,
1920 G1_CREDIT_TYPE ,
2021 UserTierId ,
@@ -32,6 +33,7 @@ vi.mock('@google/gemini-cli-core', async (importOriginal) => {
3233 shouldShowEmptyWalletMenu : vi . fn ( ) ,
3334 logBillingEvent : vi . fn ( ) ,
3435 openBrowserSecurely : vi . fn ( ) ,
36+ shouldLaunchBrowser : vi . fn ( ) . mockReturnValue ( true ) ,
3537 } ;
3638} ) ;
3739
@@ -237,4 +239,49 @@ describe('handleCreditsFlow', () => {
237239 expect ( isDialogPending . current ) . toBe ( false ) ;
238240 expect ( mockSetEmptyWalletRequest ) . toHaveBeenCalledWith ( null ) ;
239241 } ) ;
242+
243+ describe ( 'headless mode (shouldLaunchBrowser=false)' , ( ) => {
244+ beforeEach ( ( ) => {
245+ vi . mocked ( shouldLaunchBrowser ) . mockReturnValue ( false ) ;
246+ } ) ;
247+
248+ it ( 'should show manage URL in history when manage selected in headless mode' , async ( ) => {
249+ vi . mocked ( shouldShowOverageMenu ) . mockReturnValue ( true ) ;
250+
251+ const flowPromise = handleCreditsFlow ( makeArgs ( ) ) ;
252+ const request = mockSetOverageMenuRequest . mock . calls [ 0 ] [ 0 ] ;
253+ request . resolve ( 'manage' ) ;
254+ const result = await flowPromise ;
255+
256+ expect ( result ) . toBe ( 'stop' ) ;
257+ expect ( mockHistoryManager . addItem ) . toHaveBeenCalledWith (
258+ expect . objectContaining ( {
259+ type : MessageType . INFO ,
260+ text : expect . stringContaining ( 'Please open this URL in a browser:' ) ,
261+ } ) ,
262+ expect . any ( Number ) ,
263+ ) ;
264+ } ) ;
265+
266+ it ( 'should show credits URL in history when get_credits selected in headless mode' , async ( ) => {
267+ vi . mocked ( shouldShowEmptyWalletMenu ) . mockReturnValue ( true ) ;
268+
269+ const flowPromise = handleCreditsFlow ( makeArgs ( ) ) ;
270+ const request = mockSetEmptyWalletRequest . mock . calls [ 0 ] [ 0 ] ;
271+
272+ // Trigger onGetCredits callback and wait for it
273+ await request . onGetCredits ( ) ;
274+
275+ expect ( mockHistoryManager . addItem ) . toHaveBeenCalledWith (
276+ expect . objectContaining ( {
277+ type : MessageType . INFO ,
278+ text : expect . stringContaining ( 'Please open this URL in a browser:' ) ,
279+ } ) ,
280+ expect . any ( Number ) ,
281+ ) ;
282+
283+ request . resolve ( 'get_credits' ) ;
284+ await flowPromise ;
285+ } ) ;
286+ } ) ;
240287} ) ;
0 commit comments