From 24c5a15d7acdde3bd93c948db2227305951487a3 Mon Sep 17 00:00:00 2001 From: Billy Biggs Date: Fri, 1 Aug 2025 11:49:03 -0700 Subject: Add a setting to disable auth mode validation on startup (#5358) --- packages/cli/src/ui/App.test.tsx | 51 ++++++++++++++++++++++++++++++++++++++++ packages/cli/src/ui/App.tsx | 9 +++++-- 2 files changed, 58 insertions(+), 2 deletions(-) (limited to 'packages/cli/src/ui') diff --git a/packages/cli/src/ui/App.test.tsx b/packages/cli/src/ui/App.test.tsx index 79b9ce86..fc6dbb5a 100644 --- a/packages/cli/src/ui/App.test.tsx +++ b/packages/cli/src/ui/App.test.tsx @@ -26,6 +26,7 @@ import { Tips } from './components/Tips.js'; import { checkForUpdates, UpdateObject } from './utils/updateCheck.js'; import { EventEmitter } from 'events'; import { updateEventEmitter } from '../utils/updateEventEmitter.js'; +import * as auth from '../config/auth.js'; // Define a more complete mock server config based on actual Config interface MockServerConfig { @@ -232,6 +233,10 @@ vi.mock('./utils/updateCheck.js', () => ({ checkForUpdates: vi.fn(), })); +vi.mock('./config/auth.js', () => ({ + validateAuthMethod: vi.fn(), +})); + const mockedCheckForUpdates = vi.mocked(checkForUpdates); const { isGitRepository: mockedIsGitRepository } = vi.mocked( await import('@google/gemini-cli-core'), @@ -1005,4 +1010,50 @@ describe('App UI', () => { expect(lastFrame()).toContain('5 errors'); }); }); + + describe('auth validation', () => { + it('should call validateAuthMethod when useExternalAuth is false', async () => { + const validateAuthMethodSpy = vi.spyOn(auth, 'validateAuthMethod'); + mockSettings = createMockSettings({ + workspace: { + selectedAuthType: 'USE_GEMINI' as AuthType, + useExternalAuth: false, + theme: 'Default', + }, + }); + + const { unmount } = render( + , + ); + currentUnmount = unmount; + + expect(validateAuthMethodSpy).toHaveBeenCalledWith('USE_GEMINI'); + }); + + it('should NOT call validateAuthMethod when useExternalAuth is true', async () => { + const validateAuthMethodSpy = vi.spyOn(auth, 'validateAuthMethod'); + mockSettings = createMockSettings({ + workspace: { + selectedAuthType: 'USE_GEMINI' as AuthType, + useExternalAuth: true, + theme: 'Default', + }, + }); + + const { unmount } = render( + , + ); + currentUnmount = unmount; + + expect(validateAuthMethodSpy).not.toHaveBeenCalled(); + }); + }); }); diff --git a/packages/cli/src/ui/App.tsx b/packages/cli/src/ui/App.tsx index 046713ac..f63fcb35 100644 --- a/packages/cli/src/ui/App.tsx +++ b/packages/cli/src/ui/App.tsx @@ -234,14 +234,19 @@ const App = ({ config, settings, startupWarnings = [], version }: AppProps) => { } = useAuthCommand(settings, setAuthError, config); useEffect(() => { - if (settings.merged.selectedAuthType) { + if (settings.merged.selectedAuthType && !settings.merged.useExternalAuth) { const error = validateAuthMethod(settings.merged.selectedAuthType); if (error) { setAuthError(error); openAuthDialog(); } } - }, [settings.merged.selectedAuthType, openAuthDialog, setAuthError]); + }, [ + settings.merged.selectedAuthType, + settings.merged.useExternalAuth, + openAuthDialog, + setAuthError, + ]); // Sync user tier from config when authentication changes useEffect(() => { -- cgit v1.2.3