diff options
Diffstat (limited to 'packages/cli/src')
| -rw-r--r-- | packages/cli/src/ui/hooks/slashCommandProcessor.test.ts | 1 | ||||
| -rw-r--r-- | packages/cli/src/utils/startupWarnings.test.ts | 75 |
2 files changed, 76 insertions, 0 deletions
diff --git a/packages/cli/src/ui/hooks/slashCommandProcessor.test.ts b/packages/cli/src/ui/hooks/slashCommandProcessor.test.ts index 497104b9..2316bc86 100644 --- a/packages/cli/src/ui/hooks/slashCommandProcessor.test.ts +++ b/packages/cli/src/ui/hooks/slashCommandProcessor.test.ts @@ -438,6 +438,7 @@ Add any other context about the problem here. ...mockConfig, getBugCommand: vi.fn(() => bugCommand), } as unknown as Config; + process.env.CLI_VERSION = '0.1.0'; const { handleSlashCommand } = getProcessor(); const bugDescription = 'This is a custom bug'; diff --git a/packages/cli/src/utils/startupWarnings.test.ts b/packages/cli/src/utils/startupWarnings.test.ts new file mode 100644 index 00000000..980d6fe5 --- /dev/null +++ b/packages/cli/src/utils/startupWarnings.test.ts @@ -0,0 +1,75 @@ +/** + * @license + * Copyright 2025 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import { describe, it, expect, vi, beforeEach } from 'vitest'; +import { getStartupWarnings } from './startupWarnings.js'; +import * as fs from 'fs/promises'; +import { getErrorMessage } from '@gemini-cli/core'; + +vi.mock('fs/promises'); +vi.mock('@gemini-cli/core', async (importOriginal) => { + const actual = await importOriginal(); + return { + ...actual, + getErrorMessage: vi.fn(), + }; +}); + +describe.skip('startupWarnings', () => { + beforeEach(() => { + vi.resetAllMocks(); + }); + + it('should return warnings from the file and delete it', async () => { + const mockWarnings = 'Warning 1\nWarning 2'; + vi.spyOn(fs, 'access').mockResolvedValue(); + vi.spyOn(fs, 'readFile').mockResolvedValue(mockWarnings); + vi.spyOn(fs, 'unlink').mockResolvedValue(); + + const warnings = await getStartupWarnings(); + + expect(fs.access).toHaveBeenCalled(); + expect(fs.readFile).toHaveBeenCalled(); + expect(fs.unlink).toHaveBeenCalled(); + expect(warnings).toEqual(['Warning 1', 'Warning 2']); + }); + + it('should return an empty array if the file does not exist', async () => { + const error = new Error('File not found'); + (error as Error & { code: string }).code = 'ENOENT'; + vi.spyOn(fs, 'access').mockRejectedValue(error); + + const warnings = await getStartupWarnings(); + + expect(warnings).toEqual([]); + }); + + it('should return an error message if reading the file fails', async () => { + const error = new Error('Permission denied'); + vi.spyOn(fs, 'access').mockRejectedValue(error); + vi.mocked(getErrorMessage).mockReturnValue('Permission denied'); + + const warnings = await getStartupWarnings(); + + expect(warnings).toEqual([ + 'Error checking/reading warnings file: Permission denied', + ]); + }); + + it('should return a warning if deleting the file fails', async () => { + const mockWarnings = 'Warning 1'; + vi.spyOn(fs, 'access').mockResolvedValue(); + vi.spyOn(fs, 'readFile').mockResolvedValue(mockWarnings); + vi.spyOn(fs, 'unlink').mockRejectedValue(new Error('Permission denied')); + + const warnings = await getStartupWarnings(); + + expect(warnings).toEqual([ + 'Warning 1', + 'Warning: Could not delete temporary warnings file.', + ]); + }); +}); |
