From 4642de2a5ceaf264ce3238accc1142aec4661db4 Mon Sep 17 00:00:00 2001 From: Victor May Date: Wed, 20 Aug 2025 15:51:31 -0400 Subject: Fixing at command race condition (#6663) --- .../cli/src/ui/hooks/atCommandProcessor.test.ts | 57 +++++++++++++--------- 1 file changed, 33 insertions(+), 24 deletions(-) (limited to 'packages/cli/src/ui/hooks/atCommandProcessor.test.ts') diff --git a/packages/cli/src/ui/hooks/atCommandProcessor.test.ts b/packages/cli/src/ui/hooks/atCommandProcessor.test.ts index 7403f788..837e0d32 100644 --- a/packages/cli/src/ui/hooks/atCommandProcessor.test.ts +++ b/packages/cli/src/ui/hooks/atCommandProcessor.test.ts @@ -98,10 +98,6 @@ describe('handleAtCommand', () => { processedQuery: [{ text: query }], shouldProceed: true, }); - expect(mockAddItem).toHaveBeenCalledWith( - { type: 'user', text: query }, - 123, - ); }); it('should pass through original query if only a lone @ symbol is present', async () => { @@ -120,10 +116,6 @@ describe('handleAtCommand', () => { processedQuery: [{ text: queryWithSpaces }], shouldProceed: true, }); - expect(mockAddItem).toHaveBeenCalledWith( - { type: 'user', text: queryWithSpaces }, - 124, - ); expect(mockOnDebugMessage).toHaveBeenCalledWith( 'Lone @ detected, will be treated as text in the modified query.', ); @@ -156,10 +148,6 @@ describe('handleAtCommand', () => { ], shouldProceed: true, }); - expect(mockAddItem).toHaveBeenCalledWith( - { type: 'user', text: query }, - 125, - ); expect(mockAddItem).toHaveBeenCalledWith( expect.objectContaining({ type: 'tool_group', @@ -198,10 +186,6 @@ describe('handleAtCommand', () => { ], shouldProceed: true, }); - expect(mockAddItem).toHaveBeenCalledWith( - { type: 'user', text: query }, - 126, - ); expect(mockOnDebugMessage).toHaveBeenCalledWith( `Path ${dirPath} resolved to directory, using glob: ${resolvedGlob}`, ); @@ -236,10 +220,6 @@ describe('handleAtCommand', () => { ], shouldProceed: true, }); - expect(mockAddItem).toHaveBeenCalledWith( - { type: 'user', text: query }, - 128, - ); }); it('should correctly unescape paths with escaped spaces', async () => { @@ -270,10 +250,6 @@ describe('handleAtCommand', () => { ], shouldProceed: true, }); - expect(mockAddItem).toHaveBeenCalledWith( - { type: 'user', text: query }, - 125, - ); expect(mockAddItem).toHaveBeenCalledWith( expect.objectContaining({ type: 'tool_group', @@ -1090,4 +1066,37 @@ describe('handleAtCommand', () => { }); }); }); + + it("should not add the user's turn to history, as that is the caller's responsibility", async () => { + // Arrange + const fileContent = 'This is the file content.'; + const filePath = await createTestFile( + path.join(testRootDir, 'path', 'to', 'another-file.txt'), + fileContent, + ); + const query = `A query with @${filePath}`; + + // Act + await handleAtCommand({ + query, + config: mockConfig, + addItem: mockAddItem, + onDebugMessage: mockOnDebugMessage, + messageId: 999, + signal: abortController.signal, + }); + + // Assert + // It SHOULD be called for the tool_group + expect(mockAddItem).toHaveBeenCalledWith( + expect.objectContaining({ type: 'tool_group' }), + 999, + ); + + // It should NOT have been called for the user turn + const userTurnCalls = mockAddItem.mock.calls.filter( + (call) => call[0].type === 'user', + ); + expect(userTurnCalls).toHaveLength(0); + }); }); -- cgit v1.2.3