fix(background-agent): mock process.exit in forced-exit tests

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
YeonGyu-Kim
2026-05-29 16:32:05 +09:00
parent 0691779d2e
commit e8dcdded12
@@ -89,6 +89,7 @@ describe("#given process cleanup registration", () => {
const sigintListenersBefore = process.listeners("SIGINT")
const setTimeoutSpy = spyOn(globalThis, "setTimeout")
const clearTimeoutSpy = spyOn(globalThis, "clearTimeout")
const exitSpy = spyOn(process, "exit").mockImplementation((() => undefined) as never)
// Re-enable forced exit so we can verify setTimeout/clearTimeout are called
__enableScheduledForcedExitForTesting()
@@ -109,13 +110,42 @@ describe("#given process cleanup registration", () => {
expect(setTimeoutSpy).toHaveBeenCalledTimes(1)
expect(clearTimeoutSpy).toHaveBeenCalledTimes(1)
expect(exitSpy).toHaveBeenCalledWith(0)
} finally {
exitSpy.mockRestore()
setTimeoutSpy.mockRestore()
clearTimeoutSpy.mockRestore()
__disableScheduledForcedExitForTesting()
process.exitCode = 0
}
})
test("#when cleanup finishes after SIGTERM #then process exits after cleanup", async () => {
const sigtermListenersBefore = process.listeners("SIGTERM")
const exitSpy = spyOn(process, "exit").mockImplementation((() => undefined) as never)
const shutdown = mock(async () => {
await Promise.resolve()
})
const manager = { shutdown }
registeredManagers.push(manager)
__enableScheduledForcedExitForTesting()
try {
registerManagerForCleanup(manager)
const sigtermListener = getNewListener("SIGTERM", sigtermListenersBefore)
sigtermListener()
await flushMicrotasks()
expect(shutdown).toHaveBeenCalledTimes(1)
expect(exitSpy).toHaveBeenCalledWith(0)
} finally {
exitSpy.mockRestore()
__disableScheduledForcedExitForTesting()
process.exitCode = 0
}
})
})
describe("#given multiple cleanup managers", () => {