diff --git a/packages/cli/src/ui/commands/bugCommand.test.ts b/packages/cli/src/ui/commands/bugCommand.test.ts index 8b287c9cb5..f47ba0716c 100644 --- a/packages/cli/src/ui/commands/bugCommand.test.ts +++ b/packages/cli/src/ui/commands/bugCommand.test.ts @@ -9,7 +9,11 @@ import open from 'open'; import path from 'node:path'; import { bugCommand } from './bugCommand.js'; import { createMockCommandContext } from '../../test-utils/mockCommandContext.js'; -import { getVersion, type Config } from '@google/gemini-cli-core'; +import { + getVersion, + type Config, + type ConversationRecord, +} from '@google/gemini-cli-core'; import { GIT_COMMIT_INFO } from '../../generated/git-commit.js'; import { formatBytes } from '../utils/formatters.js'; import { MessageType } from '../types.js'; @@ -206,6 +210,57 @@ describe('bugCommand', () => { expect(messageText).toContain(encodeURIComponent(reminder)); }); + it('should include subagent trajectories in history export if available', async () => { + const history = [ + { role: 'user', parts: [{ text: 'hello' }] }, + { role: 'model', parts: [{ text: 'hi' }] }, + ]; + const trajectories = { + 'subagent-1': { + sessionId: 'subagent-1', + messages: [], + } as unknown as ConversationRecord, + }; + const mockGetSubagentTrajectories = vi.fn().mockResolvedValue(trajectories); + + const mockContext = createMockCommandContext({ + services: { + agentContext: { + config: { + getModel: () => 'gemini-pro', + getBugCommand: () => undefined, + getIdeMode: () => true, + getContentGeneratorConfig: () => ({ authType: 'vertex-ai' }), + storage: { + getProjectTempDir: () => '/tmp/gemini', + }, + getSessionId: vi.fn().mockReturnValue('test-session-id'), + } as unknown as Config, + geminiClient: { + getChat: () => ({ + getHistory: () => history, + getSubagentTrajectories: mockGetSubagentTrajectories, + }), + }, + }, + }, + }); + + if (!bugCommand.action) throw new Error('Action is not defined'); + await bugCommand.action(mockContext, 'Bug with trajectories'); + + const expectedPath = path.join( + '/tmp/gemini', + 'bug-report-history-1704067200000.json', + ); + expect(mockGetSubagentTrajectories).toHaveBeenCalled(); + expect(exportHistoryToFile).toHaveBeenCalledWith({ + history, + filePath: expectedPath, + trajectories, + }); + }); + it('should use a custom URL template from config if provided', async () => { const customTemplate = 'https://internal.bug-tracker.com/new?desc={title}&details={info}';