From ad28dc83c34de9ef3307e11fda8b8e30c6369a49 Mon Sep 17 00:00:00 2001 From: Spencer Date: Thu, 9 Apr 2026 16:18:35 +0000 Subject: [PATCH] test: fix failing tests in core due to shell stream logic changes --- .../core/src/scheduler/tool-executor.test.ts | 21 ++++++++++++++----- .../src/services/shellExecutionService.ts | 2 +- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/packages/core/src/scheduler/tool-executor.test.ts b/packages/core/src/scheduler/tool-executor.test.ts index f3a3ff9da6..141f2bef80 100644 --- a/packages/core/src/scheduler/tool-executor.test.ts +++ b/packages/core/src/scheduler/tool-executor.test.ts @@ -604,12 +604,15 @@ describe('ToolExecutor', () => { } }); - it('should delete temporary file when fullOutputFilePath is provided but output is not truncated', async () => { + it('should preserve temporary file when fullOutputFilePath is provided but output is not truncated', async () => { // 1. Setup Config for Truncation vi.spyOn(config, 'getTruncateToolOutputThreshold').mockReturnValue(100); const unlinkSpy = vi .spyOn(fsPromises, 'unlink') .mockResolvedValue(undefined); + vi.spyOn(fileUtils, 'moveToolOutputToFile').mockResolvedValue({ + outputFile: '/tmp/moved_output_short.txt', + }); const mockTool = new MockTool({ name: SHELL_TOOL_NAME }); const invocation = mockTool.build({}); @@ -643,19 +646,27 @@ describe('ToolExecutor', () => { onUpdateToolCall: vi.fn(), }); - // 4. Verify file deletion - expect(unlinkSpy).toHaveBeenCalledWith('/tmp/temp_full_output_short.txt'); + // 4. Verify file preservation + expect(fileUtils.moveToolOutputToFile).toHaveBeenCalledWith( + '/tmp/temp_full_output_short.txt', + SHELL_TOOL_NAME, + 'call-short-full', + expect.any(String), + expect.any(String), + ); + expect(unlinkSpy).not.toHaveBeenCalled(); expect(fileUtils.formatTruncatedToolOutput).not.toHaveBeenCalled(); - // We should not save it since it was not truncated + // We should save it since fullOutputFilePath was provided expect(result.status).toBe(CoreToolCallStatus.Success); if (result.status === CoreToolCallStatus.Success) { const response = result.response.responseParts[0]?.functionResponse ?.response as Record; expect(response).toEqual({ output: 'Short', + outputFile: '/tmp/moved_output_short.txt', }); - expect(result.response.outputFile).toBeUndefined(); + expect(result.response.outputFile).toBe('/tmp/moved_output_short.txt'); } unlinkSpy.mockRestore(); diff --git a/packages/core/src/services/shellExecutionService.ts b/packages/core/src/services/shellExecutionService.ts index f3a4cd5545..c2697a19ac 100644 --- a/packages/core/src/services/shellExecutionService.ts +++ b/packages/core/src/services/shellExecutionService.ts @@ -1380,7 +1380,7 @@ export class ShellExecutionService { cmdCleanup?.(); const activePty = ShellExecutionService.activePtys.get(ptyPid); - if (activePty) { + if (activePty && isStreamingRawContent) { emitPendingLines(activePty, ptyPid, onOutputEvent, true); }