fix: use && for windows background keep-alive ping and add test

This commit is contained in:
xuewenjie
2025-12-09 13:33:42 +08:00
parent d622f8d1bf
commit 6fc09a82fb
2 changed files with 36 additions and 1 deletions

View File

@@ -833,6 +833,41 @@ describe('ShellTool', () => {
});
describe('Windows background execution', () => {
it('should append keep-alive ping with && on Windows for background tasks', async () => {
vi.mocked(os.platform).mockReturnValue('win32');
const mockAbortSignal = new AbortController().signal;
const invocation = shellTool.build({
command: 'npm start',
is_background: true,
});
const promise = invocation.execute(mockAbortSignal);
// Simulate immediate success (process started)
resolveExecutionPromise({
rawOutput: Buffer.from(''),
output: '',
exitCode: 0,
signal: null,
error: null,
aborted: false,
pid: 12345,
executionMethod: 'child_process',
});
await promise;
expect(mockShellExecutionService).toHaveBeenCalledWith(
expect.stringContaining('npm start && ping -n 86400 127.0.0.1 >nul'),
expect.any(String),
expect.any(Function),
expect.any(AbortSignal),
false,
{},
);
});
it('should detect immediate failure in Windows background task', async () => {
vi.mocked(os.platform).mockReturnValue('win32');
const mockAbortSignal = new AbortController().signal;

View File

@@ -174,7 +174,7 @@ export class ShellToolInvocation extends BaseToolInvocation<
while (cmd.endsWith('&')) {
cmd = cmd.slice(0, -1).trim();
}
finalCommand = cmd + ' & ping -n 86400 127.0.0.1 >nul';
finalCommand = cmd + ' && ping -n 86400 127.0.0.1 >nul';
}
// pgrep is not available on Windows, so we can't get background PIDs