From 4973e7e1e04004547021986a0e2dc5eeb4a8bf9d Mon Sep 17 00:00:00 2001 From: Kamal Raj Sekar Date: Thu, 14 Aug 2025 22:00:30 +0530 Subject: [PATCH] /chat save command saves empty conversations with only system context (#6121) Co-authored-by: Jacob Richman --- .../cli/src/ui/commands/chatCommand.test.ts | 44 ++++++++++--------- packages/cli/src/ui/commands/chatCommand.ts | 2 +- 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/packages/cli/src/ui/commands/chatCommand.test.ts b/packages/cli/src/ui/commands/chatCommand.test.ts index ccdfd4b2..c7299883 100644 --- a/packages/cli/src/ui/commands/chatCommand.test.ts +++ b/packages/cli/src/ui/commands/chatCommand.test.ts @@ -185,30 +185,32 @@ describe('chatCommand', () => { }); }); - it('should inform if conversation history is empty', async () => { + it('should inform if conversation history is empty or only contains system context', async () => { mockGetHistory.mockReturnValue([]); - const result = await saveCommand?.action?.(mockContext, tag); + let result = await saveCommand?.action?.(mockContext, tag); expect(result).toEqual({ type: 'message', messageType: 'info', content: 'No conversation found to save.', }); - }); - it('should save the conversation if checkpoint does not exist', async () => { - const history: HistoryItemWithoutId[] = [ - { - type: 'user', - text: 'hello', - }, - ]; - mockGetHistory.mockReturnValue(history); - mockCheckpointExists.mockResolvedValue(false); + mockGetHistory.mockReturnValue([ + { role: 'user', parts: [{ text: 'context for our chat' }] }, + { role: 'model', parts: [{ text: 'Got it. Thanks for the context!' }] }, + ]); + result = await saveCommand?.action?.(mockContext, tag); + expect(result).toEqual({ + type: 'message', + messageType: 'info', + content: 'No conversation found to save.', + }); - const result = await saveCommand?.action?.(mockContext, tag); - - expect(mockCheckpointExists).toHaveBeenCalledWith(tag); - expect(mockSaveCheckpoint).toHaveBeenCalledWith(history, tag); + mockGetHistory.mockReturnValue([ + { role: 'user', parts: [{ text: 'context for our chat' }] }, + { role: 'model', parts: [{ text: 'Got it. Thanks for the context!' }] }, + { role: 'user', parts: [{ text: 'Hello, how are you?' }] }, + ]); + result = await saveCommand?.action?.(mockContext, tag); expect(result).toEqual({ type: 'message', messageType: 'info', @@ -237,11 +239,11 @@ describe('chatCommand', () => { }); it('should save the conversation if overwrite is confirmed', async () => { - const history: HistoryItemWithoutId[] = [ - { - type: 'user', - text: 'hello', - }, + const history: Content[] = [ + { role: 'user', parts: [{ text: 'context for our chat' }] }, + { role: 'model', parts: [{ text: 'Got it. Thanks for the context!' }] }, + { role: 'user', parts: [{ text: 'hello' }] }, + { role: 'model', parts: [{ text: 'Hi there!' }] }, ]; mockGetHistory.mockReturnValue(history); mockContext.overwriteConfirmed = true; diff --git a/packages/cli/src/ui/commands/chatCommand.ts b/packages/cli/src/ui/commands/chatCommand.ts index 56eebe1a..14714df3 100644 --- a/packages/cli/src/ui/commands/chatCommand.ts +++ b/packages/cli/src/ui/commands/chatCommand.ts @@ -142,7 +142,7 @@ const saveCommand: SlashCommand = { } const history = chat.getHistory(); - if (history.length > 0) { + if (history.length > 2) { await logger.saveCheckpoint(history, tag); return { type: 'message',