fix: time out git runner execFile calls (#3836)

This commit is contained in:
Neil
2026-05-30 12:02:08 -07:00
committed by GitHub
parent e59ddd59a7
commit f66e42a2bb
2 changed files with 163 additions and 10 deletions
+44 -1
View File
@@ -13,7 +13,7 @@ vi.mock('node:child_process', () => ({
spawn: spawnMock
}))
import { commandExecFileAsync } from './runner'
import { commandExecFileAsync, gitExecFileAsync } from './runner'
type MockChildProcess = EventEmitter & {
stdout: EventEmitter
@@ -168,3 +168,46 @@ describe('commandExecFileAsync Windows command shims', () => {
})
})
})
describe('runner execFile timeout handling', () => {
beforeEach(() => {
execFileMock.mockReset()
execFileSyncMock.mockReset()
spawnMock.mockReset()
vi.useFakeTimers()
})
afterEach(() => {
vi.useRealTimers()
})
it('rejects command executions when execFile never calls back after timeout', async () => {
const child = createMockChildProcess(1234)
execFileMock.mockReturnValue(child)
const promise = commandExecFileAsync('git', ['status'], {
cwd: '/repo',
timeout: 1000
})
const rejection = expect(promise).rejects.toThrow('git timed out.')
await vi.advanceTimersByTimeAsync(1000)
await rejection
expect(child.kill).toHaveBeenCalled()
})
it('rejects git executions when execFile never calls back after timeout', async () => {
const child = createMockChildProcess(1234)
execFileMock.mockReturnValue(child)
const promise = gitExecFileAsync(['status'], {
cwd: '/repo',
timeout: 1000
})
const rejection = expect(promise).rejects.toThrow('git timed out.')
await vi.advanceTimersByTimeAsync(1000)
await rejection
expect(child.kill).toHaveBeenCalled()
})
})