test(cli): refactor tests for async render utilities (#23252)

This commit is contained in:
Tommaso Sciortino
2026-03-20 20:08:29 +00:00
committed by GitHub
parent 86a3a913b5
commit 6c78eb7a39
198 changed files with 3592 additions and 4802 deletions
@@ -139,7 +139,7 @@ describe('useShellCommandProcessor', () => {
});
});
const renderProcessorHook = () => {
const renderProcessorHook = async () => {
let hookResult: ReturnType<typeof useShellCommandProcessor>;
let renderCount = 0;
function TestComponent({
@@ -163,7 +163,7 @@ describe('useShellCommandProcessor', () => {
);
return null;
}
const { rerender } = render(<TestComponent />);
const { rerender } = await render(<TestComponent />);
return {
result: {
get current() {
@@ -193,7 +193,7 @@ describe('useShellCommandProcessor', () => {
});
it('should initiate command execution and set pending state', async () => {
const { result } = renderProcessorHook();
const { result } = await renderProcessorHook();
await act(async () => {
result.current.handleShellCommand('ls -l', new AbortController().signal);
@@ -226,7 +226,7 @@ describe('useShellCommandProcessor', () => {
});
it('should handle successful execution and update history correctly', async () => {
const { result } = renderProcessorHook();
const { result } = await renderProcessorHook();
act(() => {
result.current.handleShellCommand(
@@ -258,7 +258,7 @@ describe('useShellCommandProcessor', () => {
});
it('should handle command failure and display error status', async () => {
const { result } = renderProcessorHook();
const { result } = await renderProcessorHook();
act(() => {
result.current.handleShellCommand(
@@ -293,7 +293,7 @@ describe('useShellCommandProcessor', () => {
});
it('should update UI for text streams (non-interactive)', async () => {
const { result } = renderProcessorHook();
const { result } = await renderProcessorHook();
await act(async () => {
result.current.handleShellCommand(
'stream',
@@ -356,7 +356,7 @@ describe('useShellCommandProcessor', () => {
});
it('should show binary progress messages correctly', async () => {
const { result } = renderProcessorHook();
const { result } = await renderProcessorHook();
act(() => {
result.current.handleShellCommand(
'cat img',
@@ -424,7 +424,7 @@ describe('useShellCommandProcessor', () => {
it('should not wrap the command on Windows', async () => {
vi.mocked(os.platform).mockReturnValue('win32');
const { result } = renderProcessorHook();
const { result } = await renderProcessorHook();
await act(async () => {
result.current.handleShellCommand('dir', new AbortController().signal);
@@ -446,7 +446,7 @@ describe('useShellCommandProcessor', () => {
});
it('should handle command abort and display cancelled status', async () => {
const { result } = renderProcessorHook();
const { result } = await renderProcessorHook();
const abortController = new AbortController();
act(() => {
@@ -470,7 +470,7 @@ describe('useShellCommandProcessor', () => {
});
it('should handle binary output result correctly', async () => {
const { result } = renderProcessorHook();
const { result } = await renderProcessorHook();
const binaryBuffer = Buffer.from([0x89, 0x50, 0x4e, 0x47]);
mockIsBinary.mockReturnValue(true);
@@ -497,7 +497,7 @@ describe('useShellCommandProcessor', () => {
});
it('should handle promise rejection and show an error', async () => {
const { result } = renderProcessorHook();
const { result } = await renderProcessorHook();
const testError = new Error('Unexpected failure');
mockShellExecutionService.mockImplementation(() => ({
pid: 12345,
@@ -531,7 +531,7 @@ describe('useShellCommandProcessor', () => {
// Mock that the temp file was created before the error was thrown
vi.mocked(fs.existsSync).mockReturnValue(true);
const { result } = renderProcessorHook();
const { result } = await renderProcessorHook();
act(() => {
result.current.handleShellCommand(
@@ -561,7 +561,7 @@ describe('useShellCommandProcessor', () => {
vi.mocked(fs.existsSync).mockReturnValue(true);
vi.mocked(fs.readFileSync).mockReturnValue('/test/dir/new'); // A different directory
const { result } = renderProcessorHook();
const { result } = await renderProcessorHook();
act(() => {
result.current.handleShellCommand(
'cd new',
@@ -586,7 +586,7 @@ describe('useShellCommandProcessor', () => {
vi.mocked(fs.existsSync).mockReturnValue(true);
vi.mocked(fs.readFileSync).mockReturnValue('/test/dir'); // The same directory
const { result } = renderProcessorHook();
const { result } = await renderProcessorHook();
act(() => {
result.current.handleShellCommand('ls', new AbortController().signal);
});
@@ -616,13 +616,13 @@ describe('useShellCommandProcessor', () => {
});
});
it('should have activeShellPtyId as null initially', () => {
const { result } = renderProcessorHook();
it('should have activeShellPtyId as null initially', async () => {
const { result } = await renderProcessorHook();
expect(result.current.activeShellPtyId).toBeNull();
});
it('should set activeShellPtyId when a command with a PID starts', async () => {
const { result } = renderProcessorHook();
const { result } = await renderProcessorHook();
await act(async () => {
result.current.handleShellCommand('ls', new AbortController().signal);
@@ -632,7 +632,7 @@ describe('useShellCommandProcessor', () => {
});
it('should update the pending history item with the ptyId', async () => {
const { result } = renderProcessorHook();
const { result } = await renderProcessorHook();
await act(async () => {
result.current.handleShellCommand('ls', new AbortController().signal);
@@ -655,7 +655,7 @@ describe('useShellCommandProcessor', () => {
});
it('should reset activeShellPtyId to null after successful execution', async () => {
const { result } = renderProcessorHook();
const { result } = await renderProcessorHook();
await act(async () => {
result.current.handleShellCommand('ls', new AbortController().signal);
@@ -673,7 +673,7 @@ describe('useShellCommandProcessor', () => {
});
it('should reset activeShellPtyId to null after failed execution', async () => {
const { result } = renderProcessorHook();
const { result } = await renderProcessorHook();
await act(async () => {
result.current.handleShellCommand(
@@ -703,7 +703,7 @@ describe('useShellCommandProcessor', () => {
}),
}),
);
const { result } = renderProcessorHook();
const { result } = await renderProcessorHook();
await act(async () => {
result.current.handleShellCommand('cmd', new AbortController().signal);
@@ -725,7 +725,7 @@ describe('useShellCommandProcessor', () => {
mockShellExecutionService.mockImplementation(() => {
throw new Error('Sync Error');
});
const { result } = renderProcessorHook();
const { result } = await renderProcessorHook();
expect(result.current.activeShellPtyId).toBeNull(); // Pre-condition
@@ -754,7 +754,7 @@ describe('useShellCommandProcessor', () => {
});
});
const { result } = renderProcessorHook();
const { result } = await renderProcessorHook();
act(() => {
result.current.handleShellCommand('ls', new AbortController().signal);
@@ -769,7 +769,7 @@ describe('useShellCommandProcessor', () => {
describe('Background Shell Management', () => {
it('should register a background shell and update count', async () => {
const { result } = renderProcessorHook();
const { result } = await renderProcessorHook();
act(() => {
result.current.registerBackgroundShell(1001, 'bg-cmd', 'initial');
@@ -792,7 +792,7 @@ describe('useShellCommandProcessor', () => {
});
it('should toggle background shell visibility', async () => {
const { result } = renderProcessorHook();
const { result } = await renderProcessorHook();
act(() => {
result.current.registerBackgroundShell(1001, 'bg-cmd', 'initial');
@@ -814,7 +814,7 @@ describe('useShellCommandProcessor', () => {
});
it('should show info message when toggling background shells if none are active', async () => {
const { result } = renderProcessorHook();
const { result } = await renderProcessorHook();
act(() => {
result.current.toggleBackgroundShell();
@@ -831,7 +831,7 @@ describe('useShellCommandProcessor', () => {
});
it('should dismiss a background shell and remove it from state', async () => {
const { result } = renderProcessorHook();
const { result } = await renderProcessorHook();
act(() => {
result.current.registerBackgroundShell(1001, 'bg-cmd', 'initial');
@@ -858,7 +858,7 @@ describe('useShellCommandProcessor', () => {
});
});
const { result } = renderProcessorHook();
const { result } = await renderProcessorHook();
await act(async () => {
result.current.handleShellCommand('top', new AbortController().signal);
@@ -892,7 +892,7 @@ describe('useShellCommandProcessor', () => {
});
it('should persist background shell on successful exit and mark as exited', async () => {
const { result } = renderProcessorHook();
const { result } = await renderProcessorHook();
act(() => {
result.current.registerBackgroundShell(888, 'auto-exit', '');
@@ -919,7 +919,7 @@ describe('useShellCommandProcessor', () => {
});
it('should persist background shell on failed exit', async () => {
const { result } = renderProcessorHook();
const { result } = await renderProcessorHook();
act(() => {
result.current.registerBackgroundShell(999, 'fail-exit', '');
@@ -950,7 +950,7 @@ describe('useShellCommandProcessor', () => {
});
it('should NOT trigger re-render on background shell output when visible', async () => {
const { result, getRenderCount } = renderProcessorHook();
const { result, getRenderCount } = await renderProcessorHook();
act(() => {
result.current.registerBackgroundShell(1001, 'bg-cmd', 'initial');
@@ -980,7 +980,7 @@ describe('useShellCommandProcessor', () => {
});
it('should NOT trigger re-render on background shell output when hidden', async () => {
const { result, getRenderCount } = renderProcessorHook();
const { result, getRenderCount } = await renderProcessorHook();
act(() => {
result.current.registerBackgroundShell(1001, 'bg-cmd', 'initial');
@@ -1006,7 +1006,7 @@ describe('useShellCommandProcessor', () => {
});
it('should trigger re-render on binary progress when visible', async () => {
const { result, getRenderCount } = renderProcessorHook();
const { result, getRenderCount } = await renderProcessorHook();
act(() => {
result.current.registerBackgroundShell(1001, 'bg-cmd', 'initial');
@@ -1037,7 +1037,7 @@ describe('useShellCommandProcessor', () => {
});
it('should NOT hide background shell when model is responding without confirmation', async () => {
const { result, rerender } = renderProcessorHook();
const { result, rerender } = await renderProcessorHook();
// 1. Register and show background shell
act(() => {
@@ -1058,7 +1058,7 @@ describe('useShellCommandProcessor', () => {
});
it('should hide background shell when waiting for confirmation and restore after delay', async () => {
const { result, rerender } = renderProcessorHook();
const { result, rerender } = await renderProcessorHook();
// 1. Register and show background shell
act(() => {
@@ -1092,7 +1092,7 @@ describe('useShellCommandProcessor', () => {
});
it('should auto-hide background shell when foreground shell starts and restore when it ends', async () => {
const { result } = renderProcessorHook();
const { result } = await renderProcessorHook();
// 1. Register and show background shell
act(() => {
@@ -1128,7 +1128,7 @@ describe('useShellCommandProcessor', () => {
});
it('should NOT restore background shell if it was manually hidden during foreground execution', async () => {
const { result } = renderProcessorHook();
const { result } = await renderProcessorHook();
// 1. Register and show background shell
act(() => {