coverage-edges.spec.ts 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532
  1. import { describe, expect, it } from 'vitest'
  2. import { Context } from '@deepseek-ai/cordis'
  3. import LlmRuntime, { createUserMessage, ToolCallId, LlmError, StreamChunk, errorChain } from '@deepseek-ai/dsh-llm'
  4. import SessionStore, { SessionId, TurnEndReason } from '@deepseek-ai/dsh-session'
  5. import type { SessionEvent } from '@deepseek-ai/dsh-session'
  6. import SystemPrompt from '@deepseek-ai/dsh-system-prompt'
  7. import ToolRuntime, { defineContentToolFixture } from '@deepseek-ai/dsh-tools'
  8. import AgentRegistry, { type Agent } from '@deepseek-ai/dsh-agent'
  9. import AgentLoop from '@deepseek-ai/dsh-agent-loop'
  10. import SessionProjectionRegistry from '@deepseek-ai/dsh-session-projection'
  11. import { MockAdapter, textResponse, toolCallResponse } from './mock-adapter.ts'
  12. function driverDone(agent: Agent): Promise<void> {
  13. return (agent as Agent & { done: Promise<void> }).done
  14. }
  15. async function harness(adapter: MockAdapter) {
  16. const ctx = new Context()
  17. await ctx.plugin(LlmRuntime)
  18. await ctx.plugin(SessionStore)
  19. await ctx.plugin(SessionProjectionRegistry)
  20. await ctx.plugin(SystemPrompt)
  21. await ctx.plugin(ToolRuntime)
  22. await ctx.plugin(AgentRegistry)
  23. await ctx.plugin(AgentLoop, { agents: [] })
  24. ctx.llm.registerAdapter(['mock'], adapter)
  25. return ctx
  26. }
  27. function waitForIdle(ctx: Context, agent: Agent): Promise<void> {
  28. return new Promise((resolve) => {
  29. const dispose = ctx.on('agent/status', ({ agent: subject, status }) => {
  30. if (subject === agent && status === 'idle') {
  31. dispose()
  32. resolve()
  33. }
  34. })
  35. })
  36. }
  37. function send(agent: Agent, text: string) {
  38. agent.followup(createUserMessage({ content: [{ type: 'text', text }], source: { kind: 'user' } }))
  39. }
  40. describe('tool JSON parse', () => {
  41. it('passes through non-JSON arguments string without crashing', async () => {
  42. const adapter = new MockAdapter([
  43. // model emits tool-call with malformed arguments (not valid JSON)
  44. [
  45. { type: 'block-start' as const, index: 0, blockType: 'tool-call' as const },
  46. { type: 'block-end' as const, index: 0, block: { type: 'tool-call' as const, id: ToolCallId('c1'), name: 'echo', arguments: 'not json' } },
  47. { type: 'finish' as const, reason: { kind: 'tool-calls' as const } },
  48. ] satisfies StreamChunk[],
  49. textResponse('done'),
  50. ])
  51. const ctx = await harness(adapter)
  52. ctx.tools.register(defineContentToolFixture({
  53. name: 'echo',
  54. description: 'echo tool',
  55. parameters: { input: { type: 'string' } },
  56. async execute(args: unknown) {
  57. return [{ type: 'text', text: typeof args === 'string' ? `raw: ${args}` : JSON.stringify(args) }]
  58. },
  59. }))
  60. const agent = await ctx.agentLoop.create(SessionId('a1'), { provider: 'mock', model: 'mock' })
  61. send(agent, 'use tool')
  62. await waitForIdle(ctx, agent)
  63. // tool/call event should have recorded the raw arguments string
  64. const callEvent = agent.session.snapshotEvents().find(e => e.type === 'tool/call')
  65. expect(callEvent).toBeDefined()
  66. if (callEvent!.type === 'tool/call') {
  67. expect(callEvent!.data.arguments).toBe('not json')
  68. }
  69. // the loop did not crash — a result was produced
  70. expect(agent.session.snapshotEvents().some(e => e.type === 'tool/result')).toBe(true)
  71. })
  72. it('uses empty object when tool-call arguments are empty string', async () => {
  73. const adapter = new MockAdapter([
  74. [
  75. { type: 'block-start' as const, index: 0, blockType: 'tool-call' as const },
  76. { type: 'block-end' as const, index: 0, block: { type: 'tool-call' as const, id: ToolCallId('c1'), name: 'noarg', arguments: '' } },
  77. { type: 'finish' as const, reason: { kind: 'tool-calls' as const } },
  78. ] satisfies StreamChunk[],
  79. textResponse('done'),
  80. ])
  81. const ctx = await harness(adapter)
  82. ctx.tools.register(defineContentToolFixture({
  83. name: 'noarg',
  84. description: 'no-arg tool',
  85. parameters: {},
  86. async execute() {
  87. return [{ type: 'text', text: 'ran with empty args' }]
  88. },
  89. }))
  90. const agent = await ctx.agentLoop.create(SessionId('a1'), { provider: 'mock', model: 'mock' })
  91. send(agent, 'use tool')
  92. await waitForIdle(ctx, agent)
  93. expect(agent.session.snapshotEvents().some(e => e.type === 'tool/result')).toBe(true)
  94. })
  95. })
  96. describe('thrown-value propagation', () => {
  97. it('preserves non-Error throws from pre-commit dispatch validation', async () => {
  98. const adapter = new MockAdapter([textResponse('ok')])
  99. const ctx = await harness(adapter)
  100. const agent = await ctx.agentLoop.create(SessionId('a1'), { provider: 'mock', model: 'mock' })
  101. let threwOnce = false
  102. ctx.on('internal/dispatch', (_mode, name, args) => {
  103. if (name !== 'session/event') return
  104. const event = args[1] as SessionEvent
  105. if (event.type === 'turn/start' && !threwOnce) {
  106. threwOnce = true
  107. throw 'naked string error'
  108. }
  109. })
  110. const errors: unknown[] = []
  111. ctx.on('agent/error', ({ error }) => void errors.push(error))
  112. send(agent, 'fails before turn start')
  113. send(agent, 'survives as the next item')
  114. await waitForIdle(ctx, agent)
  115. expect(errors).toHaveLength(1)
  116. expect(errors[0]).toBe('naked string error')
  117. expect(adapter.requests).toHaveLength(0)
  118. const starts = agent.session.snapshotEvents().filter(event => event.type === 'turn/start')
  119. const ends = agent.session.snapshotEvents().filter(event => event.type === 'turn/end')
  120. const messages = agent.session.snapshotEvents().filter(event => event.type === 'user/message')
  121. expect(starts).toHaveLength(0)
  122. expect(ends).toHaveLength(0)
  123. expect(messages).toHaveLength(0)
  124. expect(agent.inbox.nextTurn).toHaveLength(2)
  125. })
  126. it('preserves non-Error throws from the agent/request waterfall', async () => {
  127. const adapter = new MockAdapter([textResponse('irrelevant')])
  128. const ctx = await harness(adapter)
  129. const agent = await ctx.agentLoop.create(SessionId('a1'), { provider: 'mock', model: 'mock' })
  130. let threwOnce = false
  131. ctx.on('agent/request', async (_payload, next) => {
  132. if (!threwOnce) {
  133. threwOnce = true
  134. throw { code: 500 }
  135. }
  136. return next()
  137. })
  138. send(agent, 'go')
  139. await waitForIdle(ctx, agent)
  140. const turnEnd = agent.session.snapshotEvents().find(e => e.type === 'turn/end')
  141. expect(turnEnd?.type === 'turn/end' && turnEnd.data.reason.kind === 'error'
  142. ? turnEnd.data.reason.error.message
  143. : undefined).toBe('[object Object]')
  144. })
  145. })
  146. describe('durable error rendering', () => {
  147. it('renders a coded error thrown from a plugin', async () => {
  148. const adapter = new MockAdapter([textResponse('turn 1')])
  149. const ctx = await harness(adapter)
  150. const agent = await ctx.agentLoop.create(SessionId('a1'), { provider: 'mock', model: 'mock' })
  151. let threwOnce = false
  152. ctx.on('agent/request', async (_payload, next) => {
  153. if (!threwOnce) {
  154. threwOnce = true
  155. throw new LlmError('server overloaded', 'RATE_LIMIT')
  156. }
  157. return next()
  158. })
  159. send(agent, 'go')
  160. await waitForIdle(ctx, agent)
  161. const turnEnd = agent.session.snapshotEvents().find(e => e.type === 'turn/end')
  162. expect(turnEnd).toBeDefined()
  163. if (turnEnd?.type === 'turn/end' && turnEnd.data.reason.kind === 'error') {
  164. expect(turnEnd.data.reason.error).toEqual({
  165. message: 'server overloaded',
  166. code: 'RATE_LIMIT',
  167. })
  168. }
  169. })
  170. })
  171. describe('disposed vs aborted branching', () => {
  172. it('handles dispose during model streaming producing reason "disposed"', async () => {
  173. const adapter = new MockAdapter(['hang'])
  174. const ctx = await harness(adapter)
  175. let agent!: Agent
  176. const fiber = await ctx.plugin(Object.assign(async (inner: Context) => {
  177. agent = await inner.agentLoop.create(SessionId('scoped'), { provider: 'mock', model: 'mock' })
  178. }, { inject: ['agentLoop'] }))
  179. const reasons: TurnEndReason[] = []
  180. ctx.on('session/event', (_s, event) => { if (event.type === 'turn/end') reasons.push(event.data.reason) })
  181. send(agent, 'go')
  182. await new Promise(r => setTimeout(r, 30))
  183. await fiber.dispose() // dispose during hang
  184. await driverDone(agent)
  185. // Disposal wins abort classification because the error path checks it first.
  186. expect(reasons).toContainEqual({ kind: 'aborted', reason: { kind: 'disposed' } })
  187. })
  188. })
  189. describe('structured tool error propagation (the runtime-validation Agent Note, part 2)', () => {
  190. it('forwards a tool HarnessError onto the tool/result session event', async () => {
  191. const { HarnessError } = await import('@deepseek-ai/dsh-llm')
  192. // First model turn calls the tool; second turn (after the tool result is
  193. // fed back) ends with plain text so the loop settles.
  194. const adapter = new MockAdapter([
  195. toolCallResponse('c1', 'boom', {}),
  196. textResponse('done'),
  197. ])
  198. const ctx = await harness(adapter)
  199. const agent = await ctx.agentLoop.create(SessionId('a1'), { provider: 'mock', model: 'mock' })
  200. ctx.tools.register(defineContentToolFixture({
  201. name: 'boom',
  202. description: 'always fails',
  203. parameters: {},
  204. async execute() {
  205. throw new HarnessError('exploded', 'BOOM')
  206. },
  207. }))
  208. send(agent, 'go')
  209. await waitForIdle(ctx, agent)
  210. const toolResult = agent.session.snapshotEvents().find(e => e.type === 'tool/result')
  211. expect(toolResult?.type === 'tool/result' && toolResult.data.message.content[0].isError).toBe(true)
  212. expect(toolResult?.type === 'tool/result' && toolResult.data.error)
  213. .toEqual({ name: 'HarnessError', code: 'BOOM' })
  214. })
  215. })
  216. describe('request-error action edges', () => {
  217. it('ignores a retry action returned after the turn was aborted', async () => {
  218. const { LlmError } = await import('@deepseek-ai/dsh-llm')
  219. const adapter = new MockAdapter([
  220. () => { throw new LlmError('busy', 'RATE_LIMIT') },
  221. textResponse('never used'),
  222. ])
  223. const ctx = await harness(adapter)
  224. const agent = await ctx.agentLoop.create(SessionId('retry-after-cancel'), { provider: 'mock', model: 'mock' })
  225. ctx.on('agent/request-error', async ({ agent: subject }) => {
  226. subject.cancel({ kind: 'user' })
  227. return { kind: 'retry' }
  228. })
  229. send(agent, 'go')
  230. await agent.whenIdle()
  231. // One failed request, no retry turn.
  232. expect(adapter.requests).toHaveLength(1)
  233. const ends = agent.session.snapshotEvents().filter(e => e.type === 'turn/end')
  234. expect(ends).toHaveLength(1)
  235. })
  236. it('completed recovery does not retry when cancellation raced the waterfall', async () => {
  237. const { LlmError } = await import('@deepseek-ai/dsh-llm')
  238. const adapter = new MockAdapter([
  239. () => { throw new LlmError('busy', 'RATE_LIMIT') },
  240. ])
  241. const ctx = await harness(adapter)
  242. const agent = await ctx.agentLoop.create(SessionId('retry-raced'), { provider: 'mock', model: 'mock' })
  243. ctx.on('agent/request-error', async ({ agent: subject, signal }, next) => {
  244. await next()
  245. subject.cancel({ kind: 'user' })
  246. expect(signal.aborted).toBe(true)
  247. return { kind: 'retry' }
  248. })
  249. send(agent, 'go')
  250. await agent.whenIdle()
  251. expect(adapter.requests).toHaveLength(1)
  252. const end = agent.session.snapshotEvents().findLast(e => e.type === 'turn/end')
  253. expect(end?.type === 'turn/end' && end.data.reason.kind).toBe('aborted')
  254. })
  255. })
  256. describe('stream failure edges', () => {
  257. it('rethrows a mid-stream throw that carries no adapter failure facts', async () => {
  258. const adapter = new MockAdapter([textResponse('will be vetoed')])
  259. const ctx = await harness(adapter)
  260. const agent = await ctx.agentLoop.create(SessionId('stream-no-facts'), { provider: 'mock', model: 'mock' })
  261. let recoveries = 0
  262. ctx.on('agent/request-error', async () => { recoveries += 1 })
  263. // A pre-commit durable-settlement veto is not an adapter-boundary failure,
  264. // so it is not offered to request recovery.
  265. let vetoed = false
  266. ctx.on('internal/dispatch', (_mode, name, args) => {
  267. if (name !== 'session/event') return
  268. const event = args[1] as SessionEvent
  269. if (event.type === 'assistant/message' && !vetoed) {
  270. vetoed = true
  271. throw new Error('reject the first chunk')
  272. }
  273. })
  274. send(agent, 'go')
  275. await agent.whenIdle()
  276. // No facts -> not offered to recovery; the turn fails through settle().
  277. expect(recoveries).toBe(0)
  278. const end = agent.session.snapshotEvents().findLast(e => e.type === 'turn/end')
  279. expect(end?.type === 'turn/end' && end.data.reason.kind).toBe('error')
  280. })
  281. })
  282. describe('post-turn continuation edges', () => {
  283. it('whenIdle resolves for a waiter whose awaited run fails', async () => {
  284. const adapter = new MockAdapter([textResponse('unused')])
  285. const ctx = await harness(adapter)
  286. const agent = await ctx.agentLoop.create(SessionId('whenidle-reject'), { provider: 'mock', model: 'mock' })
  287. let rejected = false
  288. ctx.on('internal/dispatch', (_mode, name, args) => {
  289. if (name !== 'session/event') return
  290. const event = args[1] as SessionEvent
  291. if (event.type === 'turn/start' && !rejected) {
  292. rejected = true
  293. throw new Error('veto turn start while a waiter is pending')
  294. }
  295. })
  296. send(agent, 'go')
  297. await expect(agent.whenIdle()).resolves.toBeUndefined()
  298. expect(agent.status).toBe('idle')
  299. })
  300. })
  301. describe('persistent step-close rejection', () => {
  302. it('still publishes the terminal status when both step-close attempts are vetoed', async () => {
  303. const adapter = new MockAdapter([textResponse('will not close')])
  304. const ctx = await harness(adapter)
  305. const agent = await ctx.agentLoop.create(SessionId('stepend-double-veto'), { provider: 'mock', model: 'mock' })
  306. // Persistently reject step/end: the catch's own close attempt fails too,
  307. // and the contained failure must not strand status at running.
  308. ctx.on('internal/dispatch', (_mode, name, args) => {
  309. if (name !== 'session/event') return
  310. const event = args[1] as SessionEvent
  311. if (event.type === 'step/end') throw new Error('step close permanently rejected')
  312. })
  313. const statuses: string[] = []
  314. ctx.on('agent/status', ({ agent: subject, status }) => { if (subject === agent) statuses.push(status) })
  315. send(agent, 'go')
  316. await agent.whenIdle()
  317. expect(agent.status).toBe('idle')
  318. expect(statuses).toEqual(['running', 'idle'])
  319. })
  320. })
  321. describe('tool result meta persistence', () => {
  322. it('records a presentationMeta payload on the tool/result event', async () => {
  323. const { defineTool } = await import('@deepseek-ai/dsh-tools')
  324. const adapter = new MockAdapter([
  325. toolCallResponse('c1', 'meta-tool', {}),
  326. textResponse('done'),
  327. ])
  328. const ctx = await harness(adapter)
  329. const agent = await ctx.agentLoop.create(SessionId('tool-meta'), { provider: 'mock', model: 'mock' })
  330. ctx.tools.register(defineTool({
  331. name: 'meta-tool',
  332. description: 'carries presentation meta',
  333. parameters: {},
  334. output: {
  335. schema: { type: 'string' },
  336. render: (_args, value) => [{ type: 'text', text: value }],
  337. presentationMeta: () => ({ presentation: 'diff-card' }),
  338. },
  339. async execute() {
  340. return 'ran'
  341. },
  342. }))
  343. send(agent, 'go')
  344. await waitForIdle(ctx, agent)
  345. const result = agent.session.snapshotEvents().find(e => e.type === 'tool/result')
  346. expect(result?.type === 'tool/result' && result.data.meta).toEqual({ presentation: 'diff-card' })
  347. })
  348. })
  349. describe('turn close failure containment', () => {
  350. it('a rejected turn/end append is contained: warn + agent/error, no retry', async () => {
  351. const adapter = new MockAdapter([textResponse('ok')])
  352. const ctx = await harness(adapter)
  353. const agent = await ctx.agentLoop.create(SessionId('turnend-veto'), { provider: 'mock', model: 'mock' })
  354. let vetoed = false
  355. ctx.on('internal/dispatch', (_mode, name, args) => {
  356. if (name !== 'session/event') return
  357. const event = args[1] as SessionEvent
  358. if (event.type === 'turn/end' && !vetoed) {
  359. vetoed = true
  360. throw new Error('reject turn end')
  361. }
  362. })
  363. const errors: unknown[] = []
  364. ctx.on('agent/error', ({ error }) => { errors.push(error) })
  365. send(agent, 'go')
  366. await agent.whenIdle()
  367. // The close failure is reported live; the machine still reaches idle.
  368. expect(errors.map(e => e instanceof Error && e.message)).toContain('reject turn end')
  369. expect(agent.status).toBe('idle')
  370. expect(adapter.requests).toHaveLength(1)
  371. })
  372. })
  373. describe('recovery without a retry action', () => {
  374. it('a completed recovery that returns no action leaves the failed turn terminal', async () => {
  375. const { LlmError } = await import('@deepseek-ai/dsh-llm')
  376. const adapter = new MockAdapter([
  377. () => { throw new LlmError('down', 'SERVICE_UNAVAILABLE') },
  378. ])
  379. const ctx = await harness(adapter)
  380. const agent = await ctx.agentLoop.create(SessionId('recovery-no-retry'), { provider: 'mock', model: 'mock' })
  381. let recoveries = 0
  382. ctx.on('agent/request-error', async () => { recoveries += 1 })
  383. send(agent, 'go')
  384. await agent.whenIdle()
  385. expect(recoveries).toBe(1)
  386. expect(adapter.requests).toHaveLength(1)
  387. const end = agent.session.snapshotEvents().findLast(e => e.type === 'turn/end')
  388. expect(end?.type === 'turn/end' && end.data.reason.kind).toBe('error')
  389. })
  390. })
  391. describe('unrenderable failure settlement', () => {
  392. it('drops the rendered message when the error chain cannot be rendered', async () => {
  393. const { LlmError } = await import('@deepseek-ai/dsh-llm')
  394. const adapter = new MockAdapter([
  395. () => {
  396. const error = new LlmError('will become hostile', 'SERVER')
  397. // A hostile message getter makes errorChain collapse to its sentinel;
  398. // settle() must then fall back to the failure facts alone.
  399. Object.defineProperty(error, 'message', {
  400. get() { throw new Error('hostile accessor') },
  401. })
  402. throw error
  403. },
  404. ])
  405. const ctx = await harness(adapter)
  406. const agent = await ctx.agentLoop.create(SessionId('unrenderable'), { provider: 'mock', model: 'mock' })
  407. send(agent, 'go')
  408. await agent.whenIdle()
  409. const end = agent.session.snapshotEvents().findLast(e => e.type === 'turn/end')
  410. expect(end?.type === 'turn/end' && end.data.reason.kind).toBe('error')
  411. if (end?.type === 'turn/end' && end.data.reason.kind === 'error') {
  412. // The durable failure keeps the adapter facts' message, not the
  413. // unrenderable chain.
  414. expect(errorChain(end.data.reason.error.message)).not.toBe('<unrenderable value>')
  415. }
  416. })
  417. })
  418. describe('driver bookkeeping edges', () => {
  419. it('rejects a direct turn invocation without a driver reservation', async () => {
  420. const ctx = await harness(new MockAdapter([]))
  421. const agent = await ctx.agentLoop.create(SessionId('turn-without-reservation'), { provider: 'mock', model: 'mock' })
  422. await expect((agent as unknown as { turn(): Promise<boolean> }).turn())
  423. .rejects.toThrow('turn without driver reservation')
  424. expect(agent.status).toBe('idle')
  425. })
  426. it('closes an entered turn as blocked when its next step is rejected', async () => {
  427. const adapter = new MockAdapter([textResponse('first step')])
  428. const ctx = await harness(adapter)
  429. const agent = await ctx.agentLoop.create(SessionId('reject-next-step'), { provider: 'mock', model: 'mock' })
  430. let proposals = 0
  431. ctx.on('agent/pre-step', async (_payload, next) => {
  432. proposals += 1
  433. return proposals === 2 ? { kind: 'reject' } : next()
  434. })
  435. ctx.on('agent/turn-stopping', ({ agent: subject }) => {
  436. subject.inject(createUserMessage({
  437. content: [{ type: 'text', text: 'do not enter the next step' }],
  438. source: { kind: 'plugin', plugin: 'test' },
  439. }))
  440. })
  441. send(agent, 'go')
  442. await agent.whenIdle()
  443. expect(proposals).toBe(2)
  444. expect(adapter.requests).toHaveLength(1)
  445. const end = agent.session.snapshotEvents().findLast(event => event.type === 'turn/end')
  446. expect(end?.type === 'turn/end' && end.data.reason).toEqual({ kind: 'blocked' })
  447. })
  448. it('a request failure that concludes recovery after step/end closed keeps the boundary balanced', async () => {
  449. const { LlmError } = await import('@deepseek-ai/dsh-llm')
  450. // The failure finish-chunk path returns request-failed AFTER step() has
  451. // already appended step/end, so the request-failed branch's own
  452. // step-close guard must see stepOpen === false and skip the append.
  453. const adapter = new MockAdapter([
  454. [
  455. { type: 'usage' as const, usage: { inputTokens: 1, outputTokens: 0 } },
  456. { type: 'finish' as const, reason: { kind: 'error' as const, failure: { message: 'empty', code: 'EMPTY_RESPONSE' } } },
  457. ] satisfies StreamChunk[],
  458. ])
  459. const ctx = await harness(adapter)
  460. const agent = await ctx.agentLoop.create(SessionId('finish-after-close'), { provider: 'mock', model: 'mock' })
  461. void LlmError
  462. send(agent, 'go')
  463. await agent.whenIdle()
  464. const types = agent.session.snapshotEvents().map(e => e.type)
  465. expect(types.filter(t => t === 'step/end')).toHaveLength(1)
  466. const end = agent.session.snapshotEvents().findLast(e => e.type === 'turn/end')
  467. expect(end?.type === 'turn/end' && end.data.reason.kind).toBe('error')
  468. })
  469. })