From 1ee91fcc2ff462c36c1b4906f989803279389cfb Mon Sep 17 00:00:00 2001 From: Gerkinfeltser Date: Thu, 19 Feb 2026 11:09:55 -0600 Subject: [PATCH] fix: skip beforeunload handler in test environment The static cleanup handler was interfering with test lifecycle, causing the server to be killed during database migration. Skip registration when VITEST environment variable is set. --- src/server/process/WindowsProcess.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/server/process/WindowsProcess.ts b/src/server/process/WindowsProcess.ts index 915bcb0..7e1ee65 100644 --- a/src/server/process/WindowsProcess.ts +++ b/src/server/process/WindowsProcess.ts @@ -78,7 +78,8 @@ export class WindowsProcess implements OpenCodeProcess { } // Register beforeunload handler for window close cleanup - if (typeof window !== "undefined") { + // Skip in test environment to avoid interfering with test lifecycle + if (typeof window !== "undefined" && !process.env.VITEST) { window.addEventListener("beforeunload", () => { if (WindowsProcess.currentProcess?.pid) { WindowsProcess.killProcessSync(WindowsProcess.currentProcess.pid);