diff options
| author | Abhi <[email protected]> | 2025-06-23 23:43:00 -0400 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-06-24 03:43:00 +0000 |
| commit | d3f13c71ae78494b69c36a6d62dd9b3852bdfec2 (patch) | |
| tree | e82a7dc5d35caa1c49360ce03c9a7cef40862de5 /packages/cli/src/ui/hooks/useGeminiStream.test.tsx | |
| parent | f7caca5f941c7ab1f4c25f2d117b2217703e7d79 (diff) | |
feat: add custom message for 429 errors (#1366)
Diffstat (limited to 'packages/cli/src/ui/hooks/useGeminiStream.test.tsx')
| -rw-r--r-- | packages/cli/src/ui/hooks/useGeminiStream.test.tsx | 58 |
1 files changed, 57 insertions, 1 deletions
diff --git a/packages/cli/src/ui/hooks/useGeminiStream.test.tsx b/packages/cli/src/ui/hooks/useGeminiStream.test.tsx index 29871e8a..ed1eea4d 100644 --- a/packages/cli/src/ui/hooks/useGeminiStream.test.tsx +++ b/packages/cli/src/ui/hooks/useGeminiStream.test.tsx @@ -16,7 +16,7 @@ import { TrackedExecutingToolCall, TrackedCancelledToolCall, } from './useReactToolScheduler.js'; -import { Config, EditorType } from '@gemini-cli/core'; +import { Config, EditorType, AuthType } from '@gemini-cli/core'; import { Part, PartListUnion } from '@google/genai'; import { UseHistoryManagerReturn } from './useHistoryManager.js'; import { HistoryItem, MessageType, StreamingState } from '../types.js'; @@ -117,6 +117,11 @@ vi.mock('./slashCommandProcessor.js', () => ({ handleSlashCommand: vi.fn().mockReturnValue(false), })); +const mockParseAndFormatApiError = vi.hoisted(() => vi.fn()); +vi.mock('../utils/errorParsing.js', () => ({ + parseAndFormatApiError: mockParseAndFormatApiError, +})); + // --- END MOCKS --- describe('mergePartListUnions', () => { @@ -1033,4 +1038,55 @@ describe('useGeminiStream', () => { }); }); }); + + describe('Error Handling', () => { + it('should call parseAndFormatApiError with the correct authType on stream initialization failure', async () => { + // 1. Setup + const mockError = new Error('Rate limit exceeded'); + const mockAuthType = AuthType.LOGIN_WITH_GOOGLE_ENTERPRISE; + mockParseAndFormatApiError.mockClear(); + mockSendMessageStream.mockReturnValue( + (async function* () { + yield { type: 'content', value: '' }; + throw mockError; + })(), + ); + + const testConfig = { + ...mockConfig, + getContentGeneratorConfig: vi.fn(() => ({ + authType: mockAuthType, + })), + } as unknown as Config; + + const { result } = renderHook(() => + useGeminiStream( + new MockedGeminiClientClass(testConfig), + [], + mockAddItem, + mockSetShowHelp, + testConfig, + mockOnDebugMessage, + mockHandleSlashCommand, + false, + () => 'vscode' as EditorType, + () => {}, + () => Promise.resolve(), + ), + ); + + // 2. Action + await act(async () => { + await result.current.submitQuery('test query'); + }); + + // 3. Assertion + await waitFor(() => { + expect(mockParseAndFormatApiError).toHaveBeenCalledWith( + 'Rate limit exceeded', + mockAuthType, + ); + }); + }); + }); }); |
