-
-
Notifications
You must be signed in to change notification settings - Fork 541
Expand file tree
/
Copy pathlocalHandoff.test.ts
More file actions
30 lines (26 loc) · 1.28 KB
/
Copy pathlocalHandoff.test.ts
File metadata and controls
30 lines (26 loc) · 1.28 KB
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
import { describe, expect, it, vi } from 'vitest'
import { registerLocalHandoffHandler } from './localHandoff'
describe('registerLocalHandoffHandler', () => {
it('registers handoff-local and schedules clean exit', async () => {
const handlers = new Map<string, (params?: unknown) => unknown>()
const rpcHandlerManager: Parameters<typeof registerLocalHandoffHandler>[0] = {
registerHandler: (method, handler) => {
handlers.set(method, handler as (params?: unknown) => unknown)
}
}
const lifecycle = {
setArchiveReason: vi.fn(),
setSessionEndReason: vi.fn(),
hasExplicitSessionEndReason: vi.fn(() => false),
cleanupAndExit: vi.fn(async () => {})
}
registerLocalHandoffHandler(rpcHandlerManager, lifecycle)
const handler = handlers.get('handoff-local')
expect(handler).toBeDefined()
expect(await handler?.()).toEqual({ ok: true })
await new Promise((resolve) => setImmediate(resolve))
expect(lifecycle.setArchiveReason).toHaveBeenCalledWith('Handed off to local terminal')
expect(lifecycle.setSessionEndReason).toHaveBeenCalledWith('handoff')
expect(lifecycle.cleanupAndExit).toHaveBeenCalledWith(0)
})
})