From d1fc46da42211079244a6896f8626bf3aa813d6c Mon Sep 17 00:00:00 2001 From: YeonGyu-Kim Date: Sat, 18 Apr 2026 20:51:24 +0900 Subject: [PATCH] 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. --- .../tmux/tmux-utils/stale-session-sweep.test.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/shared/tmux/tmux-utils/stale-session-sweep.test.ts b/src/shared/tmux/tmux-utils/stale-session-sweep.test.ts index d79b6b3b8..98f6aa1f8 100644 --- a/src/shared/tmux/tmux-utils/stale-session-sweep.test.ts +++ b/src/shared/tmux/tmux-utils/stale-session-sweep.test.ts @@ -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 { - 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)