From ecc6aec4bf9947bbd3df3c8258576f686ee79de5 Mon Sep 17 00:00:00 2001 From: Brooklyn Nicholson Date: Thu, 23 Jul 2026 02:15:39 -0500 Subject: [PATCH] fix(desktop): isolate gateway HMR survivor across vitest cases Vitest keeps import.meta.hot truthy, so boot-effect cleanup parks the open socket; drain it between cases so the next test boots fresh. --- .../gateway/hooks/use-gateway-boot.test.tsx | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/apps/desktop/src/app/gateway/hooks/use-gateway-boot.test.tsx b/apps/desktop/src/app/gateway/hooks/use-gateway-boot.test.tsx index 74828222551e..4388eac7eb1e 100644 --- a/apps/desktop/src/app/gateway/hooks/use-gateway-boot.test.tsx +++ b/apps/desktop/src/app/gateway/hooks/use-gateway-boot.test.tsx @@ -4,6 +4,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import { $desktopBoot } from '@/store/boot' import { $gatewayState } from '@/store/session' +import { takeGatewaySurvivor } from './gateway-hmr-survivor' import { useGatewayBoot } from './use-gateway-boot' // End-to-end-ish repro of the "remote VPS → stuck on CONNECTING, no Settings" @@ -131,6 +132,15 @@ function Harness({ const originalWebSocket = globalThis.WebSocket beforeEach(() => { + // Drop any parked gateway left by a prior file/case (globalThis slot). + const leftover = takeGatewaySurvivor() + if (leftover) { + try { + leftover.gateway.close() + } catch { + // ignore + } + } vi.useFakeTimers() FakeWebSocket.mode = 'open' FakeWebSocket.instances = [] @@ -152,6 +162,17 @@ beforeEach(() => { afterEach(() => { cleanup() + // Vitest keeps import.meta.hot truthy, so the boot effect's cleanup parks an + // open gateway instead of tearing it down (the real HMR path). Drain + close + // that survivor so the next test boots a fresh socket instead of adoptBoot(). + const survivor = takeGatewaySurvivor() + if (survivor) { + try { + survivor.gateway.close() + } catch { + // ignore + } + } vi.useRealTimers() ;(globalThis as { WebSocket: unknown }).WebSocket = originalWebSocket delete (window as { hermesDesktop?: unknown }).hermesDesktop