Skip to content

The agent that grows with you

test(desktop): trim keepalive suite to two behaviour cases

kshitijk4poorfa67a4c9ea18
diff --git a/apps/desktop/electron/ssh-isolated-keepalive.test.ts b/apps/desktop/electron/ssh-isolated-keepalive.test.ts
index 81ce902f01c..0b213319411 100644
--- a/apps/desktop/electron/ssh-isolated-keepalive.test.ts
+++ b/apps/desktop/electron/ssh-isolated-keepalive.test.ts
@@ -4,8 +4,8 @@
* ownership liveness; renderer sockets can drop while sshConnections still owns
* the scope. Sticky artifacts (nonce / token file / lockfile) are NOT liveness.
*
- * Wiring through main.ts is asserted via pool-stop / bootstrap-coordinator
- * behavior tests — AGENTS.md forbids reading `.ts` source from tests.
+ * The pool-stop teardown fence that closes this socket is asserted in
+ * pool-stop.test.ts (afterStop) — AGENTS.md forbids reading `.ts` source from tests.
*/
import { afterEach, describe, expect, it, vi } from 'vitest'
@@ -45,7 +45,7 @@ describe('ssh-isolated keep-alive registry (#106935)', () => {
vi.useRealTimers()
})
- it('holds an open WebSocket until stop and does not reconnect afterwards', async () => {
+ it('holds an open WebSocket per scope until that scope stops, then never reconnects it', async () => {
const { createSshIsolatedKeepaliveRegistry } = await import('./ssh-isolated-keepalive')
const { FakeWs, instances } = makeFakeWs()
const registry = createSshIsolatedKeepaliveRegistry({
@@ -57,8 +57,9 @@ describe('ssh-isolated keep-alive registry (#106935)', () => {
baseUrl: 'http://127.0.0.1:53101',
token: 'sess-work'
})
+ registry.start('conn:office::less', { baseUrl: 'http://127.0.0.1:53102', token: 'sess-less' })
- expect(instances).toHaveLength(1)
+ expect(instances).toHaveLength(2)
expect(instances[0].url).toBe('ws://127.0.0.1:53101/api/ws?token=sess-work')
expect(registry.isArmed('conn:office::work')).toBe(true)
@@ -68,18 +69,26 @@ describe('ssh-isolated keep-alive registry (#106935)', () => {
registry.stop('conn:office::work')
expect(instances[0].closed).toBe(true)
expect(registry.isArmed('conn:office::work')).toBe(false)
+ // Tearing down one sibling must not drop the other owned scope.
+ expect(instances[1].closed).toBe(false)
+ expect(registry.isArmed('conn:office::less')).toBe(true)
instances[0].emit('close', { code: 1006 })
await new Promise(resolve => setTimeout(resolve, 50))
- expect(instances).toHaveLength(1)
+ expect(instances).toHaveLength(2)
expect(registry.openUrl('conn:office::work')).toBeNull()
})
- it('treats empty-string scope as the v1/global SSH primary', async () => {
+ it('treats empty-string scope as the v1/global SSH primary but still requires baseUrl and token', async () => {
const { createSshIsolatedKeepaliveRegistry } = await import('./ssh-isolated-keepalive')
const { FakeWs, instances } = makeFakeWs()
const registry = createSshIsolatedKeepaliveRegistry({ WebSocketImpl: FakeWs })
+ registry.start('', { baseUrl: '', token: 'tok' })
+ registry.start('', { baseUrl: 'http://127.0.0.1:9', token: '' })
+ expect(instances).toHaveLength(0)
+ expect(registry.isArmed('')).toBe(false)
+
registry.start('', { baseUrl: 'http://127.0.0.1:53100', token: 'primary' })
expect(instances).toHaveLength(1)
@@ -93,33 +102,4 @@ describe('ssh-isolated keep-alive registry (#106935)', () => {
expect(instances[0].closed).toBe(true)
expect(registry.isArmed('')).toBe(false)
})
-
- it('rejects missing baseUrl or token even for the empty primary key', async () => {
- const { createSshIsolatedKeepaliveRegistry } = await import('./ssh-isolated-keepalive')
- const { FakeWs, instances } = makeFakeWs()
- const registry = createSshIsolatedKeepaliveRegistry({ WebSocketImpl: FakeWs })
-
- registry.start('', { baseUrl: '', token: 'tok' })
- registry.start('', { baseUrl: 'http://127.0.0.1:9', token: '' })
- registry.start('', { baseUrl: 'http://127.0.0.1:9', token: undefined as unknown as string })
- registry.start('', { baseUrl: undefined as unknown as string, token: 'tok' })
-
- expect(instances).toHaveLength(0)
- expect(registry.isArmed('')).toBe(false)
- })
-
- it('tracks independent scopes so tearing down one sibling cannot drop the other', async () => {
- const { createSshIsolatedKeepaliveRegistry } = await import('./ssh-isolated-keepalive')
- const { FakeWs, instances } = makeFakeWs()
- const registry = createSshIsolatedKeepaliveRegistry({ WebSocketImpl: FakeWs })
-
- registry.start('profile-less', { baseUrl: 'http://127.0.0.1:53101', token: 'a' })
- registry.start('profile-work', { baseUrl: 'http://127.0.0.1:53102', token: 'b' })
-
- expect(instances).toHaveLength(2)
- registry.stop('profile-work')
- expect(instances[0].closed).toBe(false)
- expect(instances[1].closed).toBe(true)
- expect(registry.isArmed('profile-less')).toBe(true)
- })
})