File size: 1,738 Bytes
a1b6014 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | import { afterEach, describe, expect, it, vi } from 'vitest'
import { setApiRequestConnection, setApiRequestProfile } from '@/hermes'
import { activeConnection } from './plugins'
// desktop.getConnection/getConnectionFor are IPC round-trips into the main
// process with no timeout of their own (#93454). A wedged main-process
// round-trip must reject instead of hanging pluginSocket's connect() forever.
describe('activeConnection connection timeout (#93454)', () => {
afterEach(() => {
setApiRequestConnection(null)
setApiRequestProfile(null)
Reflect.deleteProperty(window, 'hermesDesktop')
vi.useRealTimers()
})
it('rejects instead of hanging forever when getConnection() wedges', async () => {
vi.useFakeTimers()
setApiRequestProfile('coder')
Object.defineProperty(window, 'hermesDesktop', {
configurable: true,
value: { getConnection: vi.fn(() => new Promise(() => undefined)) }
})
const pending = expect(activeConnection()).rejects.toThrow('Timed out connecting to profile "coder"')
await vi.advanceTimersByTimeAsync(20_000)
await pending
})
it('rejects instead of hanging forever when getConnectionFor() wedges', async () => {
vi.useFakeTimers()
setApiRequestConnection('gw-tailscale')
setApiRequestProfile('research')
Object.defineProperty(window, 'hermesDesktop', {
configurable: true,
value: {
getConnection: vi.fn(() => new Promise(() => undefined)),
getConnectionFor: vi.fn(() => new Promise(() => undefined))
}
})
const pending = expect(activeConnection()).rejects.toThrow('Timed out connecting to profile "research"')
await vi.advanceTimersByTimeAsync(20_000)
await pending
})
})
|