test(tmux): restore process.kill in afterEach to prevent cross-file leak

Oracle noted that loadSweeper() monkey-patches process.kill without
ever restoring it. Added afterEach hook to set process.kill back to the
captured original. Individual file runs already passed, and
script/run-ci-tests.ts confirms the full CI suite - 4781 pass, 0 fail
across 491 files - but this makes the test file safe under non-isolated
local runs as well.
This commit is contained in:
YeonGyu-Kim
2026-04-18 20:51:24 +09:00
parent 913fac05f5
commit d1fc46da42
@@ -1,4 +1,4 @@
import { beforeEach, describe, expect, it, mock } from "bun:test"
import { afterEach, beforeEach, describe, expect, it, mock } from "bun:test"
type SweepStaleOmoAgentSessions = typeof import("./stale-session-sweep").sweepStaleOmoAgentSessions
@@ -64,8 +64,9 @@ function registerModuleMocks(): void {
mock.module(sessionKillSpecifier, () => ({ killTmuxSessionIfExists: killTmuxSessionMock }))
}
const originalProcessKill = process.kill
async function loadSweeper(overrideProcessAlive?: (pid: number) => boolean): Promise<SweepStaleOmoAgentSessions> {
const originalKill = process.kill
const processAlive = overrideProcessAlive ?? isProcessAliveMock
process.kill = ((pid: number, signal?: number | string): true => {
if (signal === 0) {
@@ -76,7 +77,7 @@ async function loadSweeper(overrideProcessAlive?: (pid: number) => boolean): Pro
err.code = "ESRCH"
throw err
}
return originalKill.call(process, pid, signal)
return originalProcessKill.call(process, pid, signal)
}) as typeof process.kill
const module = await import(`${sweepSpecifier}?test=${crypto.randomUUID()}`)
return module.sweepStaleOmoAgentSessions
@@ -100,6 +101,10 @@ describe("sweepStaleOmoAgentSessions", () => {
isProcessAliveMock.mockImplementation((_pid: number): boolean => false)
})
afterEach(() => {
process.kill = originalProcessKill
})
it("#given not inside tmux #when sweepStaleOmoAgentSessions called #then returns 0 without spawn", async () => {
// given
isInsideTmuxMock.mockImplementation((): boolean => false)