Fix shell output display (#24490)

This commit is contained in:
Jacob Richman
2026-04-01 22:53:46 -07:00
committed by GitHub
parent 973092df50
commit 40b73c9447
10 changed files with 240 additions and 56 deletions
@@ -101,6 +101,7 @@ import {
type GeminiClient,
type ShellExecutionResult,
type ShellOutputEvent,
type AnsiOutput,
CoreToolCallStatus,
} from '@google/gemini-cli-core';
import * as fs from 'node:fs';
@@ -521,6 +522,52 @@ describe('useExecutionLifecycle', () => {
);
});
it('should prepend warnings to AnsiOutput array', async () => {
const { result } = await renderProcessorHook();
act(() => {
result.current.handleShellCommand('ls', new AbortController().signal);
});
const execPromise = onExecMock.mock.calls[0][0];
const ansiOutput: AnsiOutput = [
[
{
text: 'ansi line 1',
fg: '',
bg: '',
bold: false,
dim: false,
italic: false,
underline: false,
inverse: false,
},
],
];
act(() => {
resolveExecutionPromise(
createMockServiceResult({
exitCode: 1,
output: 'ansi line 1',
ansiOutput,
}),
);
});
await act(async () => await execPromise);
expect(setPendingHistoryItemMock).toHaveBeenCalledWith(null);
expect(addItemToHistoryMock).toHaveBeenCalledTimes(2);
const historyCall = addItemToHistoryMock.mock.calls[1][0];
const display = historyCall.tools[0].resultDisplay;
expect(Array.isArray(display)).toBe(true);
expect(display.length).toBe(3); // Error line, empty line, original output
expect(display[0][0].text).toBe('Command exited with code 1.');
expect(display[2][0].text).toBe('ansi line 1');
});
it('should handle promise rejection and show an error', async () => {
const { result } = await renderProcessorHook();
const testError = new Error('Unexpected failure');