Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions apps/desktop/src/store/gateway.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { afterEach, beforeEach, describe, expect, it } from 'vitest'

import type { HermesGateway } from '@/hermes'

import {
$gateway,
activeGateway,
closeSecondaryGateways,
ensureGatewayForProfile,
setPrimaryGateway
} from './gateway'

describe('activeGateway profile isolation', () => {
beforeEach(async () => {
closeSecondaryGateways()
setPrimaryGateway(null)
await ensureGatewayForProfile('default')
})

afterEach(async () => {
closeSecondaryGateways()
setPrimaryGateway(null)
await ensureGatewayForProfile('default')
})

it('does not substitute a newly-primary gateway for the previously active profile', () => {
const primary = { connectionState: 'open' } as HermesGateway

// The primary backend can be re-homed while the store still has the
// previous profile as active. Until that profile's own socket is active,
// callers must see no gateway rather than send to the new primary.
setPrimaryGateway(primary, 'work')

expect(activeGateway()).toBeNull()
expect($gateway.get()).toBeNull()
})
})
2 changes: 1 addition & 1 deletion apps/desktop/src/store/gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export function activeGateway(): HermesGateway | null {
return g.primaryGateway
}

return g.secondaries.get(g.activeKey)?.gateway ?? g.primaryGateway
return g.secondaries.get(g.activeKey)?.gateway ?? null
}

// Mirror a backend's connection state into the global composer state, but only
Expand Down
Loading