diff options
| author | Jerop Kipruto <[email protected]> | 2025-06-15 16:35:15 -0400 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-06-15 16:35:15 -0400 |
| commit | 101b6fe767eba2063687ec30797e729decf3f6db (patch) | |
| tree | eaf8bb0123730ea338adc87b668035205eb7bd45 /packages/cli/src | |
| parent | 714421c2da4f5d6b9c1c7060fdf5c47ba1c965ca (diff) | |
Stabilize /bug command tests with consistent version mocking (#1070)
The `/bug` command tests in `slashCommandProcessor.test.ts` were flaky due to inconsistent CLI versioning.
This commit:
- Implements a flexible, top-level mock for `getCliVersion` that can be overridden per test.
- Sets a default mock value for `/bug` command tests via `beforeEach`.
- Overrides the mock in one test case requiring a specific version ('test-version').
- Ensures the test's helper `getExpectedUrl` receives the correct explicit version.
- Aligns the expected CLI version in the custom bug URL test with the default mock.
These changes ensure consistent CLI versioning in tests, resolving flakiness.
#1071
Diffstat (limited to 'packages/cli/src')
| -rw-r--r-- | packages/cli/src/ui/hooks/slashCommandProcessor.test.ts | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/packages/cli/src/ui/hooks/slashCommandProcessor.test.ts b/packages/cli/src/ui/hooks/slashCommandProcessor.test.ts index 1bcfbdf5..adbfac61 100644 --- a/packages/cli/src/ui/hooks/slashCommandProcessor.test.ts +++ b/packages/cli/src/ui/hooks/slashCommandProcessor.test.ts @@ -48,6 +48,11 @@ vi.mock('node:fs/promises', () => ({ mkdir: vi.fn(), })); +const mockGetCliVersionFn = vi.fn(() => '0.1.0'); +vi.mock('../../utils/version.js', () => ({ + getCliVersion: (...args: []) => mockGetCliVersionFn(...args), +})); + import { act, renderHook } from '@testing-library/react'; import { vi, describe, it, expect, beforeEach, afterEach, Mock } from 'vitest'; import open from 'open'; @@ -350,6 +355,7 @@ describe('useSlashCommandProcessor', () => { const originalEnv = process.env; beforeEach(() => { vi.resetModules(); + mockGetCliVersionFn.mockReturnValue('0.1.0'); process.env = { ...originalEnv }; }); @@ -399,16 +405,16 @@ Add any other context about the problem here. }; it('should call open with the correct GitHub issue URL and return true', async () => { + mockGetCliVersionFn.mockReturnValue('test-version'); process.env.SANDBOX = 'gemini-sandbox'; process.env.SEATBELT_PROFILE = 'test_profile'; - process.env.CLI_VERSION = 'test-version'; const { handleSlashCommand } = getProcessor(); const bugDescription = 'This is a test bug'; const expectedUrl = getExpectedUrl( bugDescription, process.env.SANDBOX, process.env.SEATBELT_PROFILE, - process.env.CLI_VERSION, + 'test-version', ); let commandResult: SlashCommandActionReturn | boolean = false; await act(async () => { @@ -440,7 +446,7 @@ A clear and concise description of what the bug is. Add any other context about the problem here. ## Diagnostic Information -* **CLI Version:** unknown +* **CLI Version:** 0.1.0 * **Git Commit:** ${GIT_COMMIT_INFO} * **Operating System:** test-platform test-node-version * **Sandbox Environment:** no sandbox |
