This commit is contained in:
Gal Zahavi
2025-08-15 10:27:33 -07:00
committed by GitHub
parent ab1c483cab
commit 1a2906a8ad
16 changed files with 412 additions and 442 deletions

View File

@@ -104,6 +104,8 @@ describe('useShellCommandProcessor', () => {
): ShellExecutionResult => ({
rawOutput: Buffer.from(overrides.output || ''),
output: 'Success',
stdout: 'Success',
stderr: '',
exitCode: 0,
signal: null,
error: null,
@@ -221,6 +223,7 @@ describe('useShellCommandProcessor', () => {
act(() => {
mockShellOutputCallback({
type: 'data',
stream: 'stdout',
chunk: 'hello',
});
});
@@ -231,9 +234,12 @@ describe('useShellCommandProcessor', () => {
// Advance time and send another event to trigger the throttled update
await act(async () => {
await vi.advanceTimersByTimeAsync(OUTPUT_UPDATE_INTERVAL_MS + 1);
});
act(() => {
mockShellOutputCallback({
type: 'data',
chunk: 'hello world',
stream: 'stdout',
chunk: ' world',
});
});

View File

@@ -104,6 +104,7 @@ export const useShellCommandProcessor = (
const execPromise = new Promise<void>((resolve) => {
let lastUpdateTime = Date.now();
let cumulativeStdout = '';
let cumulativeStderr = '';
let isBinaryStream = false;
let binaryBytesReceived = 0;
@@ -141,7 +142,11 @@ export const useShellCommandProcessor = (
case 'data':
// Do not process text data if we've already switched to binary mode.
if (isBinaryStream) break;
cumulativeStdout = event.chunk;
if (event.stream === 'stdout') {
cumulativeStdout += event.chunk;
} else {
cumulativeStderr += event.chunk;
}
break;
case 'binary_detected':
isBinaryStream = true;
@@ -167,7 +172,9 @@ export const useShellCommandProcessor = (
'[Binary output detected. Halting stream...]';
}
} else {
currentDisplayOutput = cumulativeStdout;
currentDisplayOutput =
cumulativeStdout +
(cumulativeStderr ? `\n${cumulativeStderr}` : '');
}
// Throttle pending UI updates to avoid excessive re-renders.

View File

@@ -62,8 +62,6 @@ export type TrackedToolCall =
| TrackedCompletedToolCall
| TrackedCancelledToolCall;
import { useTerminalSize } from './useTerminalSize.js';
export function useReactToolScheduler(
onComplete: (tools: CompletedToolCall[]) => Promise<void>,
config: Config,
@@ -73,7 +71,6 @@ export function useReactToolScheduler(
getPreferredEditor: () => EditorType | undefined,
onEditorClose: () => void,
): [TrackedToolCall[], ScheduleFn, MarkToolsAsSubmittedFn] {
const terminalSize = useTerminalSize();
const [toolCallsForDisplay, setToolCallsForDisplay] = useState<
TrackedToolCall[]
>([]);
@@ -143,7 +140,6 @@ export function useReactToolScheduler(
onToolCallsUpdate: toolCallsUpdateHandler,
getPreferredEditor,
config,
getTerminalSize: () => terminalSize,
onEditorClose,
}),
[
@@ -152,7 +148,6 @@ export function useReactToolScheduler(
allToolCallsCompleteHandler,
toolCallsUpdateHandler,
getPreferredEditor,
terminalSize,
onEditorClose,
],
);

View File

@@ -36,13 +36,6 @@ import {
HistoryItemToolGroup,
} from '../types.js';
vi.mock('./useTerminalSize', () => ({
useTerminalSize: () => ({
columns: 80,
rows: 24,
}),
}));
// Mocks
vi.mock('@google/gemini-cli-core', async () => {
const actual = await vi.importActual('@google/gemini-cli-core');
@@ -231,8 +224,8 @@ describe('useReactToolScheduler in YOLO Mode', () => {
request.args,
expect.any(AbortSignal),
undefined,
80,
24,
undefined,
undefined,
);
// Check that onComplete was called with success
@@ -383,8 +376,8 @@ describe('useReactToolScheduler', () => {
request.args,
expect.any(AbortSignal),
undefined,
80,
24,
undefined,
undefined,
);
expect(onComplete).toHaveBeenCalledWith([
expect.objectContaining({