fix(desktop): reconnect an active profile whose gateway is closed
This commit is contained in:
@@ -9,7 +9,7 @@ import type { ProfileInfo } from '@/types/hermes'
|
||||
const ensureGatewayForProfile = vi.fn(async () => undefined)
|
||||
const ensureGatewayForAgent = vi.fn(async () => undefined)
|
||||
const openGatewayForProfile = vi.fn(async (_profile: string) => undefined)
|
||||
const $gateway = atom<unknown>({ id: 'live-socket' })
|
||||
const $gateway = atom<unknown>({ id: 'live-socket', connectionState: 'open' })
|
||||
const resetStarmapGraph = vi.fn()
|
||||
|
||||
vi.mock('@/store/gateway', () => ({ $gateway, ensureGatewayForAgent, ensureGatewayForProfile, openGatewayForProfile }))
|
||||
@@ -55,7 +55,7 @@ beforeEach(() => {
|
||||
getConnection.mockReset()
|
||||
ensureGatewayForProfile.mockClear()
|
||||
openGatewayForProfile.mockClear()
|
||||
$gateway.set({ id: 'live-socket' })
|
||||
$gateway.set({ id: 'live-socket', connectionState: 'open' })
|
||||
$activeGatewayProfile.set('default')
|
||||
$connection.set(localConn())
|
||||
$profiles.set([])
|
||||
@@ -115,6 +115,17 @@ describe('ensureGatewayProfile → $connection sync (#46651)', () => {
|
||||
expect(ensureGatewayForProfile).not.toHaveBeenCalled()
|
||||
expect($connection.get()?.mode).toBe('remote')
|
||||
})
|
||||
|
||||
it('reconnects when the target profile is active but its gateway socket is closed', async () => {
|
||||
$activeGatewayProfile.set('vps-remote')
|
||||
$connection.set(remoteConn())
|
||||
$gateway.set({ connectionState: 'closed' })
|
||||
getConnection.mockResolvedValue(remoteConn())
|
||||
|
||||
await ensureGatewayProfile('vps-remote')
|
||||
|
||||
expect(ensureGatewayForProfile).toHaveBeenCalledWith('vps-remote')
|
||||
})
|
||||
})
|
||||
|
||||
describe('profile-scoped cache invalidation', () => {
|
||||
|
||||
@@ -491,7 +491,7 @@ export async function ensureGatewayProfile(profile: string | null | undefined):
|
||||
|
||||
const target = normalizeProfileKey(profile)
|
||||
|
||||
if (normalizeProfileKey($activeGatewayProfile.get()) === target && $gateway.get()) {
|
||||
if (normalizeProfileKey($activeGatewayProfile.get()) === target && $gateway.get()?.connectionState === 'open') {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -503,7 +503,7 @@ export async function ensureGatewayProfile(profile: string | null | undefined):
|
||||
await gatewaySwitch.catch(() => undefined)
|
||||
}
|
||||
|
||||
if (normalizeProfileKey($activeGatewayProfile.get()) === target && $gateway.get()) {
|
||||
if (normalizeProfileKey($activeGatewayProfile.get()) === target && $gateway.get()?.connectionState === 'open') {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user