mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-23 03:24:42 -07:00
Refactor Authentication Components and Hooks (#7750)
This commit is contained in:
committed by
GitHub
parent
d8dbe6271f
commit
7239c5cd9a
@@ -15,7 +15,6 @@ import type {
|
||||
ToolRegistry,
|
||||
SandboxConfig,
|
||||
GeminiClient,
|
||||
AuthType,
|
||||
} from '@google/gemini-cli-core';
|
||||
import {
|
||||
ApprovalMode,
|
||||
@@ -34,7 +33,6 @@ import type { UpdateObject } from './utils/updateCheck.js';
|
||||
import { checkForUpdates } from './utils/updateCheck.js';
|
||||
import { EventEmitter } from 'node:events';
|
||||
import { updateEventEmitter } from '../utils/updateEventEmitter.js';
|
||||
import * as auth from '../config/auth.js';
|
||||
import * as useTerminalSize from './hooks/useTerminalSize.js';
|
||||
|
||||
// Define a more complete mock server config based on actual Config
|
||||
@@ -224,14 +222,12 @@ vi.mock('./hooks/useGeminiStream', () => ({
|
||||
})),
|
||||
}));
|
||||
|
||||
vi.mock('./hooks/useAuthCommand', () => ({
|
||||
vi.mock('./auth/useAuth.js', () => ({
|
||||
useAuthCommand: vi.fn(() => ({
|
||||
isAuthDialogOpen: false,
|
||||
openAuthDialog: vi.fn(),
|
||||
handleAuthSelect: vi.fn(),
|
||||
handleAuthHighlight: vi.fn(),
|
||||
isAuthenticating: false,
|
||||
cancelAuthentication: vi.fn(),
|
||||
authState: 'authenticated',
|
||||
setAuthState: vi.fn(),
|
||||
authError: null,
|
||||
onAuthError: vi.fn(),
|
||||
})),
|
||||
}));
|
||||
|
||||
@@ -1189,60 +1185,6 @@ describe('App UI', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('auth validation', () => {
|
||||
it('should call validateAuthMethod when useExternalAuth is false', async () => {
|
||||
const validateAuthMethodSpy = vi.spyOn(auth, 'validateAuthMethod');
|
||||
mockSettings = createMockSettings({
|
||||
workspace: {
|
||||
security: {
|
||||
auth: {
|
||||
selectedType: 'USE_GEMINI' as AuthType,
|
||||
useExternal: false,
|
||||
},
|
||||
},
|
||||
ui: { theme: 'Default' },
|
||||
},
|
||||
});
|
||||
|
||||
const { unmount } = renderWithProviders(
|
||||
<App
|
||||
config={mockConfig as unknown as ServerConfig}
|
||||
settings={mockSettings}
|
||||
version={mockVersion}
|
||||
/>,
|
||||
);
|
||||
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: {
|
||||
security: {
|
||||
auth: {
|
||||
selectedType: 'USE_GEMINI' as AuthType,
|
||||
useExternal: true,
|
||||
},
|
||||
},
|
||||
ui: { theme: 'Default' },
|
||||
},
|
||||
});
|
||||
|
||||
const { unmount } = renderWithProviders(
|
||||
<App
|
||||
config={mockConfig as unknown as ServerConfig}
|
||||
settings={mockSettings}
|
||||
version={mockVersion}
|
||||
/>,
|
||||
);
|
||||
currentUnmount = unmount;
|
||||
|
||||
expect(validateAuthMethodSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('when in a narrow terminal', () => {
|
||||
it('should render with a column layout', () => {
|
||||
vi.spyOn(useTerminalSize, 'useTerminalSize').mockReturnValue({
|
||||
|
||||
Reference in New Issue
Block a user