client-handler.spec.ts 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  1. /**
  2. * Wire-protocol coverage over the isomorphic point: InProcessApiClient →
  3. * toFetchHandler(scripted impl) runs the real envelope wrap/unwrap, zod
  4. * two-level parse, rpcId discipline, and SSE framing with no network and no
  5. * browser. Each case scripts its own minimal ApiProxy.
  6. */
  7. import { describe, expect, it, vi } from 'vitest'
  8. import type { SessionId } from '@deepseek-ai/dsh-session'
  9. import type { ApiProxy, HostFrame, MuxFrame, RpcMessage, RpcRequest, RpcResponse } from '@deepseek-ai/dsh-host-apiproxy'
  10. import { InProcessApiClient, RpcId, toFetchHandler } from '@deepseek-ai/dsh-host-apiproxy'
  11. const sid = (id: string): SessionId => id as SessionId
  12. function ok<T>(request: RpcRequest<unknown>, value: T): Promise<RpcResponse<T>> {
  13. return Promise.resolve({ rpcId: request.rpcId, result: { ok: true, value } })
  14. }
  15. /** Scripted impl: every method resolves an empty-ish OK unless a case overrides it. */
  16. function scriptedApi(overrides: {
  17. sessions?: Partial<ApiProxy['sessions']>
  18. host?: Partial<ApiProxy['host']>
  19. commands?: Partial<ApiProxy['commands']>
  20. skills?: Partial<ApiProxy['skills']>
  21. events?: Partial<ApiProxy['events']>
  22. respond?: ApiProxy['respond']
  23. } = {}): ApiProxy {
  24. async function *empty<F>(): AsyncGenerator<RpcRequest<F>> { /* no frames */ }
  25. return {
  26. sessions: {
  27. list: r => ok(r, { items: [] }),
  28. create: r => ok(r, { sessionId: sid('s-new') }),
  29. history: r => ok(r, { events: [], hasMore: false }),
  30. prompt: r => ok(r, { accepted: true as const }),
  31. cancel: r => ok(r, { accepted: true as const }),
  32. ...overrides.sessions,
  33. },
  34. host: {
  35. describe: r => ok(r, { version: '0-test', cwd: '/t', attachedSessions: 0 }),
  36. pickDirectory: r => ok(r, { path: null }),
  37. ...overrides.host,
  38. },
  39. workspace: {
  40. list: r => ok(r, { items: [] }),
  41. create: r => ok(r, { workspace: { workspaceId: 'w1' as never, path: '/t', title: 't', sessionIds: [], createdAt: '0', updatedAt: '0' }, created: true }),
  42. rename: r => ok(r, { workspace: { workspaceId: 'w1' as never, path: '/t', title: 't', sessionIds: [], createdAt: '0', updatedAt: '0' } }),
  43. delete: r => ok(r, { deleted: true as const }),
  44. insertSessionBefore: r => ok(r, { workspace: { workspaceId: 'w1' as never, path: '/t', title: 't', sessionIds: [], createdAt: '0', updatedAt: '0' } }),
  45. },
  46. commands: {
  47. list: r => ok(r, { commands: [] }),
  48. execute: r => ok(r, { matched: false }),
  49. ...overrides.commands,
  50. },
  51. skills: { list: r => ok(r, { skills: [] }), ...overrides.skills },
  52. events: { mux: () => empty<MuxFrame>(), host: () => empty<HostFrame>(), ...overrides.events },
  53. respond: overrides.respond ?? (() => Promise.resolve({ accepted: false as const, reason: 'not-pending' as const })),
  54. }
  55. }
  56. function client(api: ApiProxy, timeoutMs?: number): InProcessApiClient {
  57. return new InProcessApiClient(toFetchHandler(api), timeoutMs)
  58. }
  59. describe('unary round trip', () => {
  60. it('carries payload out and value back through the full wire form', async () => {
  61. let seen: RpcRequest<{ cursor?: string }> | undefined
  62. const api = scriptedApi({
  63. sessions: {
  64. list: (r) => {
  65. seen = r
  66. return ok(r, { items: [{ sessionId: sid('s1'), updatedAt: 7, running: false, blank: false }] })
  67. },
  68. },
  69. })
  70. const response = await client(api).sessions.list({ cursor: 'c1' })
  71. // Impl received the narrow form with a minted id; client returned the same id and value.
  72. expect(seen?.payload).toEqual({ cursor: 'c1' })
  73. expect(seen?.rpcId).toBeTruthy()
  74. expect(response.rpcId).toBe(seen?.rpcId)
  75. expect(response.result).toEqual({ ok: true, value: { items: [{ sessionId: 's1', updatedAt: 7, running: false, blank: false }] } })
  76. })
  77. it('routes workspace rename, delete, and insertSessionBefore through the wire', async () => {
  78. const api = scriptedApi()
  79. const c = client(api)
  80. const renamed = await c.workspace.rename({ workspaceId: 'w1' as never, title: 'next' })
  81. expect(renamed.result.ok).toBe(true)
  82. const blankTitle = await c.workspace.rename({ workspaceId: 'w1' as never, title: ' ' })
  83. expect(blankTitle.result).toMatchObject({ ok: false, error: { code: 'bad-request' } })
  84. const deleted = await c.workspace.delete({ workspaceId: 'w1' as never })
  85. expect(deleted.result).toEqual({ ok: true, value: { deleted: true } })
  86. const anchored = await c.workspace.insertSessionBefore({ workspaceId: 'w1' as never, sessionId: sid('s1'), beforeSessionId: sid('s2') })
  87. expect(anchored.result.ok).toBe(true)
  88. const appended = await c.workspace.insertSessionBefore({ workspaceId: 'w1' as never, sessionId: sid('s1') })
  89. expect(appended.result.ok).toBe(true)
  90. })
  91. it('passes business errors through as 200 + err result, not a throw', async () => {
  92. const api = scriptedApi({
  93. sessions: {
  94. cancel: r => Promise.resolve({ rpcId: r.rpcId, result: { ok: false, error: { code: 'session-not-found', message: 'nope', details: { sessionId: sid('sx') } } } }),
  95. },
  96. })
  97. const response = await client(api).sessions.cancel({ sessionId: sid('sx') })
  98. expect(response.result).toEqual({ ok: false, error: { code: 'session-not-found', message: 'nope', details: { sessionId: 'sx' } } })
  99. })
  100. it('throws on rpcId echo mismatch', async () => {
  101. const api = scriptedApi({
  102. sessions: { list: () => Promise.resolve({ rpcId: RpcId('forged'), result: { ok: true, value: { items: [] } } }) },
  103. })
  104. await expect(client(api).sessions.list({})).rejects.toThrow(/rpcId mismatch/)
  105. })
  106. it('rejects an invalid payload at the handler as 200 + bad-request with issues', async () => {
  107. const api = scriptedApi()
  108. const response = await client(api).sessions.history({ sessionId: 123 as unknown as SessionId })
  109. expect(response.result.ok).toBe(false)
  110. if (!response.result.ok) {
  111. expect(response.result.error.code).toBe('bad-request')
  112. expect((response.result.error.details as { issues: unknown[] }).issues.length).toBeGreaterThan(0)
  113. }
  114. })
  115. it('rejects a method/path mismatch as bad-request', async () => {
  116. const handler = toFetchHandler(scriptedApi())
  117. const body = { type: 'client-request', rpcId: 'r1', method: 'session.create', payload: {} }
  118. const response = await handler.fetch('http://dsh.internal/api/session.list', { method: 'POST', body: JSON.stringify(body) })
  119. expect(response.status).toBe(200)
  120. const parsed = await response.json() as { result: { ok: boolean; error?: { code: string; message: string } } }
  121. expect(parsed.result.ok).toBe(false)
  122. expect(parsed.result.error?.code).toBe('bad-request')
  123. expect(parsed.result.error?.message).toMatch(/does not match path/)
  124. })
  125. it('rejects a malformed envelope as bad-request, salvaging the rpcId or falling back to the sentinel', async () => {
  126. const handler = toFetchHandler(scriptedApi())
  127. // No salvageable rpcId → the fixed invalid-request sentinel keeps the response a valid ServerResponse.
  128. const noId = await handler.fetch('http://dsh.internal/api/session.list', { method: 'POST', body: JSON.stringify({ nonsense: true }) })
  129. expect(noId.status).toBe(200)
  130. const noIdParsed = await noId.json() as { rpcId: string; result: { ok: boolean } }
  131. expect(noIdParsed.result.ok).toBe(false)
  132. expect(noIdParsed.rpcId).toBe('invalid-request')
  133. // A string rpcId in the otherwise-bad body is salvaged for correlation.
  134. const withId = await handler.fetch('http://dsh.internal/api/session.list', { method: 'POST', body: JSON.stringify({ rpcId: 'salvage-me', nonsense: true }) })
  135. const withIdParsed = await withId.json() as { rpcId: string; result: { ok: boolean } }
  136. expect(withIdParsed.result.ok).toBe(false)
  137. expect(withIdParsed.rpcId).toBe('salvage-me')
  138. })
  139. it('maps carrier failures to HTTP statuses and the client throws transport failure', async () => {
  140. const handler = toFetchHandler(scriptedApi())
  141. // Unknown method → 404.
  142. const notFound = await handler.fetch('http://dsh.internal/api/no.such', { method: 'POST', body: '{}' })
  143. expect(notFound.status).toBe(404)
  144. // Non-JSON body → 400.
  145. const badBody = await handler.fetch('http://dsh.internal/api/session.list', { method: 'POST', body: '{oops' })
  146. expect(badBody.status).toBe(400)
  147. // Impl crash → 500, and through the client that is a throw, not an err result.
  148. const crashing = scriptedApi({ sessions: { list: () => { throw new Error('impl exploded') } } })
  149. await expect(client(crashing).sessions.list({})).rejects.toThrow(/transport failure .*500/)
  150. })
  151. it('rejects when the transport never resolves within timeoutMs', async () => {
  152. // AbortSignal.timeout is immune to fake timers; a short real timeout keeps this fast.
  153. const never = new InProcessApiClient({
  154. fetch: (_i: RequestInfo | URL, init?: RequestInit) => new Promise<Response>((_resolve, reject) => {
  155. init?.signal?.addEventListener('abort', () => { reject(new Error('aborted by timeout')) })
  156. }),
  157. }, 25)
  158. await expect(never.sessions.list({})).rejects.toThrow()
  159. })
  160. it('aborts a unary call through the caller-supplied external signal', async () => {
  161. // Real-fetch semantics: on abort the rejection is the signal's reason, and the abort
  162. // works even when the transport ignores the signal entirely (hung impl).
  163. const gate = new AbortController()
  164. const hung = new InProcessApiClient({ fetch: () => new Promise<Response>(() => {}) }, 60_000)
  165. const call = hung.sessions.list({}, gate.signal)
  166. gate.abort(new Error('externally aborted'))
  167. await expect(call).rejects.toThrow(/externally aborted/)
  168. })
  169. it('rejects an already-aborted signal before touching the transport, mapping a string reason to an Error', async () => {
  170. let touched = false
  171. const c = new InProcessApiClient({
  172. fetch: () => {
  173. touched = true
  174. return Promise.resolve(new Response('{}'))
  175. },
  176. }, 60_000)
  177. const gate = new AbortController()
  178. gate.abort('gone before start')
  179. await expect(c.sessions.list({}, gate.signal)).rejects.toThrow('gone before start')
  180. expect(touched).toBe(false)
  181. })
  182. it('maps a non-Error, non-string abort reason to the default AbortError message', async () => {
  183. const gate = new AbortController()
  184. const hung = new InProcessApiClient({ fetch: () => new Promise<Response>(() => {}) }, 60_000)
  185. const call = hung.sessions.list({}, gate.signal)
  186. gate.abort(42)
  187. await expect(call).rejects.toThrow('This operation was aborted')
  188. })
  189. it('passes a signal-less doFetch straight through to the handler', async () => {
  190. class Probe extends InProcessApiClient {
  191. direct(url: URL): Promise<Response> {
  192. return this.doFetch(url)
  193. }
  194. }
  195. const probe = new Probe({ fetch: () => Promise.resolve(new Response('raw')) })
  196. const response = await probe.direct(new URL('http://dsh.internal/probe'))
  197. expect(await response.text()).toBe('raw')
  198. })
  199. it('throws on an S→C ok value that fails the method value schema (second-level parse)', async () => {
  200. // Impl echoes rpcId but returns a wrong-shaped value: envelope parse passes, value parse must reject.
  201. const api = scriptedApi({
  202. sessions: { list: r => Promise.resolve({ rpcId: r.rpcId, result: { ok: true, value: { items: 'not-an-array' } } }) as never },
  203. })
  204. await expect(client(api).sessions.list({})).rejects.toThrow()
  205. })
  206. })
  207. describe('workspace domain round trip', () => {
  208. it('routes both workspace methods through their handler rows and value schemas', async () => {
  209. const c = client(scriptedApi())
  210. const list = await c.workspace.list({})
  211. expect(list.result).toEqual({ ok: true, value: { items: [] } })
  212. const created = await c.workspace.create({ path: '/t' })
  213. expect(created.result.ok).toBe(true)
  214. if (created.result.ok) expect(created.result.value.created).toBe(true)
  215. })
  216. it('rejects a create payload violating the exactly-one refine at the handler', async () => {
  217. const response = await client(scriptedApi()).workspace.create({})
  218. expect(response.result.ok).toBe(false)
  219. if (!response.result.ok) expect(response.result.error.code).toBe('bad-request')
  220. })
  221. })
  222. describe('SSE stream path', () => {
  223. it('yields frames in order and skips the comment preamble', async () => {
  224. const frames: MuxFrame[] = [
  225. { type: 'session/subscribed', sessionId: sid('s1'), lastSeq: 3 },
  226. { type: 'stream/error', error: { code: 'internal', message: 'x', details: {} } },
  227. ]
  228. const api = scriptedApi({
  229. events: {
  230. async *mux(request) {
  231. let n = 0
  232. for (const frame of frames) yield { rpcId: RpcId(`push-${n++}-${request.rpcId}`), payload: frame }
  233. },
  234. },
  235. })
  236. const seen: MuxFrame[] = []
  237. for await (const envelope of client(api).events.mux({}, new AbortController().signal)) {
  238. seen.push(envelope.payload)
  239. }
  240. expect(seen).toEqual(frames)
  241. })
  242. it('reassembles frames across arbitrary chunk boundaries', async () => {
  243. // Two SSE frames split so one frame spans chunks and one chunk carries parts of both.
  244. const f1 = { type: 'server-request', rpcId: 'a', method: 'session/subscribed', payload: { type: 'session/subscribed', sessionId: 's1', lastSeq: 1 } }
  245. const f2 = { type: 'server-request', rpcId: 'b', method: 'session/subscribed', payload: { type: 'session/subscribed', sessionId: 's2', lastSeq: 2 } }
  246. const wire = `: connected\n\ndata: ${JSON.stringify(f1)}\n\ndata: ${JSON.stringify(f2)}\n\n`
  247. const cuts = [5, 40, wire.indexOf('data: ', 40) + 3]
  248. const encoder = new TextEncoder()
  249. const doFetch = (): Promise<Response> => Promise.resolve(new Response(new ReadableStream<Uint8Array>({
  250. start(controller) {
  251. let prev = 0
  252. for (const cut of [...cuts, wire.length]) {
  253. controller.enqueue(encoder.encode(wire.slice(prev, cut)))
  254. prev = cut
  255. }
  256. controller.close()
  257. },
  258. }), { status: 200 }))
  259. const chopped = new InProcessApiClient({ fetch: doFetch })
  260. const seen: string[] = []
  261. for await (const envelope of chopped.events.mux({}, new AbortController().signal)) {
  262. seen.push((envelope.payload as { sessionId: string }).sessionId)
  263. expect(envelope.rpcId).toBe(seen.length === 1 ? 'a' : 'b')
  264. }
  265. expect(seen).toEqual(['s1', 's2'])
  266. })
  267. it('emits a stream/error frame then closes when the impl throws mid-stream', async () => {
  268. const api = scriptedApi({
  269. events: {
  270. async *host(request): AsyncGenerator<RpcRequest<HostFrame>> {
  271. yield { rpcId: RpcId(`p-${request.rpcId}`), payload: { type: 'host/session-added', sessionId: sid('s1'), blank: true } }
  272. throw new Error('impl died mid-stream')
  273. },
  274. },
  275. })
  276. const seen: HostFrame[] = []
  277. for await (const envelope of client(api).events.host({}, new AbortController().signal)) {
  278. seen.push(envelope.payload)
  279. }
  280. expect(seen.map(f => f.type)).toEqual(['host/session-added', 'stream/error'])
  281. const last = seen.at(-1)
  282. if (last?.type === 'stream/error') expect(last.error.message).toMatch(/impl died mid-stream/)
  283. })
  284. it('drops a malformed SSE frame and keeps the stream alive (S→C two-level parse)', async () => {
  285. const good = { type: 'server-request', rpcId: 'g1', method: 'session/subscribed', payload: { type: 'session/subscribed', sessionId: 's1', lastSeq: 1 } }
  286. const badEnvelope = { type: 'server-response', rpcId: 'x' } // wrong quadrant for a stream
  287. const badFrame = { type: 'server-request', rpcId: 'b1', method: 'nope', payload: { type: 'no/such-frame' } }
  288. const wire = [
  289. 'data: {oops', // not JSON
  290. `data: ${JSON.stringify(badEnvelope)}`,
  291. `data: ${JSON.stringify(badFrame)}`,
  292. `data: ${JSON.stringify(good)}`,
  293. ].map(l => `${l}\n\n`).join('')
  294. const doFetch = (): Promise<Response> => Promise.resolve(new Response(new ReadableStream<Uint8Array>({
  295. start(controller) {
  296. controller.enqueue(new TextEncoder().encode(wire))
  297. controller.close()
  298. },
  299. }), { status: 200 }))
  300. const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => undefined)
  301. try {
  302. const seen: MuxFrame[] = []
  303. for await (const envelope of new InProcessApiClient({ fetch: doFetch }).events.mux({}, new AbortController().signal)) {
  304. seen.push(envelope.payload)
  305. }
  306. // The three corrupt frames are reported and skipped; the good one still arrives.
  307. expect(seen).toEqual([{ type: 'session/subscribed', sessionId: 's1', lastSeq: 1 }])
  308. expect(errorSpy.mock.calls.length).toBe(3)
  309. } finally {
  310. errorSpy.mockRestore()
  311. }
  312. })
  313. it('fires onOpen once headers are in, before the first frame, and not on transport failure', async () => {
  314. const api = scriptedApi({
  315. events: {
  316. async *mux(request): AsyncGenerator<RpcRequest<MuxFrame>> {
  317. yield { rpcId: RpcId(`p-${request.rpcId}`), payload: { type: 'session/subscribed', sessionId: sid('s1'), lastSeq: 0 } }
  318. },
  319. },
  320. })
  321. const order: string[] = []
  322. const iterator = client(api).events.mux({}, new AbortController().signal, () => order.push('open'))
  323. expect(order).toEqual([]) // lazy generator: no fetch (and no onOpen) before iteration
  324. for await (const _ of iterator) order.push('frame')
  325. expect(order).toEqual(['open', 'frame'])
  326. // Transport failure path: onOpen must not fire.
  327. const failing = new InProcessApiClient({ fetch: () => Promise.resolve(new Response('down', { status: 503 })) })
  328. const failOrder: string[] = []
  329. await expect((async () => {
  330. for await (const _ of failing.events.mux({}, new AbortController().signal, () => failOrder.push('open'))) { /* unreachable */ }
  331. })()).rejects.toThrow(/transport failure/)
  332. expect(failOrder).toEqual([])
  333. })
  334. it('stops consuming when the caller aborts', async () => {
  335. let implSawAbort = false
  336. const api = scriptedApi({
  337. events: {
  338. async *mux(_request, signal): AsyncGenerator<RpcRequest<MuxFrame>> {
  339. try {
  340. let n = 0
  341. while (true) {
  342. yield { rpcId: RpcId(`p${n}`), payload: { type: 'session/subscribed', sessionId: sid('s1'), lastSeq: n++ } }
  343. await new Promise(resolve => setTimeout(resolve, 5))
  344. if (signal.aborted) return
  345. }
  346. } finally {
  347. implSawAbort = true
  348. }
  349. },
  350. },
  351. })
  352. const abort = new AbortController()
  353. let count = 0
  354. // In-process abort ends the stream (impl returns on signal.aborted); over a real
  355. // network fetch the same abort surfaces as a rejection — both stop the loop.
  356. await (async () => {
  357. for await (const _ of client(api).events.mux({}, abort.signal)) {
  358. if (++count === 2) abort.abort()
  359. }
  360. })().catch(() => undefined)
  361. expect(count).toBe(2)
  362. // Generator teardown may lag the abort by a microtask; poll briefly.
  363. await vi.waitFor(() => { expect(implSawAbort).toBe(true) })
  364. })
  365. })
  366. describe('respond path', () => {
  367. it('round-trips a client-response to a receipt', async () => {
  368. const seen: unknown[] = []
  369. const api = scriptedApi({
  370. respond: (message) => {
  371. seen.push(message)
  372. return Promise.resolve({ accepted: true as const })
  373. },
  374. })
  375. const receipt = await client(api).respond({ type: 'client-response', rpcId: RpcId('req-1'), result: { ok: true, value: { behavior: 'allow' } } })
  376. expect(receipt).toEqual({ accepted: true })
  377. expect(seen).toEqual([{ type: 'client-response', rpcId: 'req-1', result: { ok: true, value: { behavior: 'allow' } } }])
  378. })
  379. it('returns bad-response for a malformed client-response without reaching the impl', async () => {
  380. const respond = vi.fn()
  381. const handler = toFetchHandler(scriptedApi({ respond }))
  382. const response = await handler.fetch('http://dsh.internal/api/respond', { method: 'POST', body: JSON.stringify({ type: 'client-response' }) })
  383. expect(await response.json()).toEqual({ accepted: false, reason: 'bad-response' })
  384. expect(respond).not.toHaveBeenCalled()
  385. })
  386. })
  387. describe('envelope tap', () => {
  388. it('delivers one microtask batch of full forms per unary call', async () => {
  389. const api = scriptedApi()
  390. const tapped = client(api)
  391. const batches: (readonly RpcMessage[])[] = []
  392. tapped.subscribeEnvelopes(batch => batches.push(batch))
  393. await tapped.sessions.list({})
  394. await vi.waitFor(() => { expect(batches.length).toBeGreaterThan(0) })
  395. const all = batches.flat()
  396. expect(all.map(m => m.type)).toEqual(['client-request', 'server-response'])
  397. expect(all[0]?.rpcId).toBe(all[1]?.rpcId)
  398. })
  399. it('isolates a throwing listener and keeps serving the call', async () => {
  400. const api = scriptedApi()
  401. const tapped = client(api)
  402. const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => undefined)
  403. try {
  404. const good: string[] = []
  405. tapped.subscribeEnvelopes(() => { throw new Error('listener bug') })
  406. tapped.subscribeEnvelopes(batch => good.push(...batch.map(m => m.type)))
  407. const response = await tapped.sessions.list({})
  408. expect(response.result.ok).toBe(true)
  409. await vi.waitFor(() => { expect(good).toContain('server-response') })
  410. } finally {
  411. errorSpy.mockRestore()
  412. }
  413. })
  414. it('buffers nothing with zero subscribers and unsubscribes cleanly', async () => {
  415. const api = scriptedApi()
  416. const tapped = client(api)
  417. await tapped.sessions.list({}) // no subscribers: must not accumulate
  418. const batches: (readonly RpcMessage[])[] = []
  419. const unsubscribe = tapped.subscribeEnvelopes(batch => batches.push(batch))
  420. unsubscribe()
  421. await tapped.sessions.list({})
  422. await new Promise(resolve => setTimeout(resolve, 0))
  423. expect(batches).toEqual([])
  424. })
  425. })