mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-07-24 16:54:43 +00:00
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.
This commit is contained in:
parent
cbea2acbb8
commit
ecc6aec4bf
1 changed files with 21 additions and 0 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue