summaryrefslogtreecommitdiff
path: root/packages/cli/src/ui/commands/bugCommand.test.ts
diff options
context:
space:
mode:
authorHarold Mciver <[email protected]>2025-07-16 21:46:35 -0400
committerGitHub <[email protected]>2025-07-17 01:46:35 +0000
commit01e66bb12392c3e8cd0222dc495c8dc61ebe4fba (patch)
tree68c73d9e67ecb782b8903b34dab18c1173438aee /packages/cli/src/ui/commands/bugCommand.test.ts
parent0c76affe6dee2577aa072ee690f38906eecdf2d1 (diff)
update `/bug` to new slash command arch (#4246)
Co-authored-by: Abhi <[email protected]> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Co-authored-by: Abhi <[email protected]>
Diffstat (limited to 'packages/cli/src/ui/commands/bugCommand.test.ts')
-rw-r--r--packages/cli/src/ui/commands/bugCommand.test.ts98
1 files changed, 98 insertions, 0 deletions
diff --git a/packages/cli/src/ui/commands/bugCommand.test.ts b/packages/cli/src/ui/commands/bugCommand.test.ts
new file mode 100644
index 00000000..1a618fd1
--- /dev/null
+++ b/packages/cli/src/ui/commands/bugCommand.test.ts
@@ -0,0 +1,98 @@
+/**
+ * @license
+ * Copyright 2025 Google LLC
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
+import open from 'open';
+import { bugCommand } from './bugCommand.js';
+import { createMockCommandContext } from '../../test-utils/mockCommandContext.js';
+import { getCliVersion } from '../../utils/version.js';
+import { GIT_COMMIT_INFO } from '../../generated/git-commit.js';
+import { formatMemoryUsage } from '../utils/formatters.js';
+
+// Mock dependencies
+vi.mock('open');
+vi.mock('../../utils/version.js');
+vi.mock('../utils/formatters.js');
+vi.mock('node:process', () => ({
+ default: {
+ platform: 'test-platform',
+ version: 'v20.0.0',
+ // Keep other necessary process properties if needed by other parts of the code
+ env: process.env,
+ memoryUsage: () => ({ rss: 0 }),
+ },
+}));
+
+describe('bugCommand', () => {
+ beforeEach(() => {
+ vi.mocked(getCliVersion).mockResolvedValue('0.1.0');
+ vi.mocked(formatMemoryUsage).mockReturnValue('100 MB');
+ vi.stubEnv('SANDBOX', 'gemini-test');
+ });
+
+ afterEach(() => {
+ vi.unstubAllEnvs();
+ vi.clearAllMocks();
+ });
+
+ it('should generate the default GitHub issue URL', async () => {
+ const mockContext = createMockCommandContext({
+ services: {
+ config: {
+ getModel: () => 'gemini-pro',
+ getBugCommand: () => undefined,
+ },
+ },
+ });
+
+ if (!bugCommand.action) throw new Error('Action is not defined');
+ await bugCommand.action(mockContext, 'A test bug');
+
+ const expectedInfo = `
+* **CLI Version:** 0.1.0
+* **Git Commit:** ${GIT_COMMIT_INFO}
+* **Operating System:** test-platform v20.0.0
+* **Sandbox Environment:** test
+* **Model Version:** gemini-pro
+* **Memory Usage:** 100 MB
+`;
+ const expectedUrl =
+ 'https://github.com/google-gemini/gemini-cli/issues/new?template=bug_report.yml&title=A%20test%20bug&info=' +
+ encodeURIComponent(expectedInfo);
+
+ expect(open).toHaveBeenCalledWith(expectedUrl);
+ });
+
+ it('should use a custom URL template from config if provided', async () => {
+ const customTemplate =
+ 'https://internal.bug-tracker.com/new?desc={title}&details={info}';
+ const mockContext = createMockCommandContext({
+ services: {
+ config: {
+ getModel: () => 'gemini-pro',
+ getBugCommand: () => ({ urlTemplate: customTemplate }),
+ },
+ },
+ });
+
+ if (!bugCommand.action) throw new Error('Action is not defined');
+ await bugCommand.action(mockContext, 'A custom bug');
+
+ const expectedInfo = `
+* **CLI Version:** 0.1.0
+* **Git Commit:** ${GIT_COMMIT_INFO}
+* **Operating System:** test-platform v20.0.0
+* **Sandbox Environment:** test
+* **Model Version:** gemini-pro
+* **Memory Usage:** 100 MB
+`;
+ const expectedUrl = customTemplate
+ .replace('{title}', encodeURIComponent('A custom bug'))
+ .replace('{info}', encodeURIComponent(expectedInfo));
+
+ expect(open).toHaveBeenCalledWith(expectedUrl);
+ });
+});