test: fix failing tests in core due to shell stream logic changes

This commit is contained in:
Spencer
2026-04-09 16:18:35 +00:00
parent 35bc1e6e0f
commit 3dba67afa8
2 changed files with 17 additions and 6 deletions
@@ -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 // 1. Setup Config for Truncation
vi.spyOn(config, 'getTruncateToolOutputThreshold').mockReturnValue(100); vi.spyOn(config, 'getTruncateToolOutputThreshold').mockReturnValue(100);
const unlinkSpy = vi const unlinkSpy = vi
.spyOn(fsPromises, 'unlink') .spyOn(fsPromises, 'unlink')
.mockResolvedValue(undefined); .mockResolvedValue(undefined);
vi.spyOn(fileUtils, 'moveToolOutputToFile').mockResolvedValue({
outputFile: '/tmp/moved_output_short.txt',
});
const mockTool = new MockTool({ name: SHELL_TOOL_NAME }); const mockTool = new MockTool({ name: SHELL_TOOL_NAME });
const invocation = mockTool.build({}); const invocation = mockTool.build({});
@@ -643,19 +646,27 @@ describe('ToolExecutor', () => {
onUpdateToolCall: vi.fn(), onUpdateToolCall: vi.fn(),
}); });
// 4. Verify file deletion // 4. Verify file preservation
expect(unlinkSpy).toHaveBeenCalledWith('/tmp/temp_full_output_short.txt'); 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(); 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); expect(result.status).toBe(CoreToolCallStatus.Success);
if (result.status === CoreToolCallStatus.Success) { if (result.status === CoreToolCallStatus.Success) {
const response = result.response.responseParts[0]?.functionResponse const response = result.response.responseParts[0]?.functionResponse
?.response as Record<string, unknown>; ?.response as Record<string, unknown>;
expect(response).toEqual({ expect(response).toEqual({
output: 'Short', 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(); unlinkSpy.mockRestore();
@@ -1348,7 +1348,7 @@ export class ShellExecutionService {
cmdCleanup?.(); cmdCleanup?.();
const activePty = ShellExecutionService.activePtys.get(ptyPid); const activePty = ShellExecutionService.activePtys.get(ptyPid);
if (activePty) { if (activePty && isStreamingRawContent) {
emitPendingLines(activePty, ptyPid, onOutputEvent, true); emitPendingLines(activePty, ptyPid, onOutputEvent, true);
} }