diff options
| author | Hiroaki Mitsuyoshi <[email protected]> | 2025-08-09 15:59:22 +0900 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-08-09 06:59:22 +0000 |
| commit | 6487cc16895976ef6c983f8beca08a64addb6688 (patch) | |
| tree | e2d4d06bc37331d0c36a1c27442457d42f81d385 /packages/cli/src/ui/commands/chatCommand.test.ts | |
| parent | 191cc01bf5833a4c7636f8fc4d9b4c5066982822 (diff) | |
feat(chat): Add overwrite confirmation dialog to `/chat save` (#5686)
Co-authored-by: Jacob Richman <[email protected]>
Diffstat (limited to 'packages/cli/src/ui/commands/chatCommand.test.ts')
| -rw-r--r-- | packages/cli/src/ui/commands/chatCommand.test.ts | 50 |
1 files changed, 49 insertions, 1 deletions
diff --git a/packages/cli/src/ui/commands/chatCommand.test.ts b/packages/cli/src/ui/commands/chatCommand.test.ts index aad0897c..ccdfd4b2 100644 --- a/packages/cli/src/ui/commands/chatCommand.test.ts +++ b/packages/cli/src/ui/commands/chatCommand.test.ts @@ -168,8 +168,12 @@ describe('chatCommand', () => { describe('save subcommand', () => { let saveCommand: SlashCommand; const tag = 'my-tag'; + let mockCheckpointExists: ReturnType<typeof vi.fn>; + beforeEach(() => { saveCommand = getSubCommand('save'); + mockCheckpointExists = vi.fn().mockResolvedValue(false); + mockContext.services.logger.checkpointExists = mockCheckpointExists; }); it('should return an error if tag is missing', async () => { @@ -191,7 +195,48 @@ describe('chatCommand', () => { }); }); - it('should save the conversation', async () => { + it('should save the conversation if checkpoint does not exist', async () => { + const history: HistoryItemWithoutId[] = [ + { + type: 'user', + text: 'hello', + }, + ]; + mockGetHistory.mockReturnValue(history); + mockCheckpointExists.mockResolvedValue(false); + + const result = await saveCommand?.action?.(mockContext, tag); + + expect(mockCheckpointExists).toHaveBeenCalledWith(tag); + expect(mockSaveCheckpoint).toHaveBeenCalledWith(history, tag); + expect(result).toEqual({ + type: 'message', + messageType: 'info', + content: `Conversation checkpoint saved with tag: ${tag}.`, + }); + }); + + it('should return confirm_action if checkpoint already exists', async () => { + mockCheckpointExists.mockResolvedValue(true); + mockContext.invocation = { + raw: `/chat save ${tag}`, + name: 'save', + args: tag, + }; + + const result = await saveCommand?.action?.(mockContext, tag); + + expect(mockCheckpointExists).toHaveBeenCalledWith(tag); + expect(mockSaveCheckpoint).not.toHaveBeenCalled(); + expect(result).toMatchObject({ + type: 'confirm_action', + originalInvocation: { raw: `/chat save ${tag}` }, + }); + // Check that prompt is a React element + expect(result).toHaveProperty('prompt'); + }); + + it('should save the conversation if overwrite is confirmed', async () => { const history: HistoryItemWithoutId[] = [ { type: 'user', @@ -199,8 +244,11 @@ describe('chatCommand', () => { }, ]; mockGetHistory.mockReturnValue(history); + mockContext.overwriteConfirmed = true; + const result = await saveCommand?.action?.(mockContext, tag); + expect(mockCheckpointExists).not.toHaveBeenCalled(); // Should skip existence check expect(mockSaveCheckpoint).toHaveBeenCalledWith(history, tag); expect(result).toEqual({ type: 'message', |
