Skip to content
Source
Sign inSign up
TanStack/ai
Open History to see the last commit

chat-client-noop-devtools.test.ts

34 lines1.4 KB

1// Regression coverage for the shipping default. The suite-wide setup file
2// (`use-real-devtools-bridges.ts`) re-routes the no-op devtools factories to
3// the real bridges, so no other test exercises the bridge production
4// consumers actually get when they don't opt into devtools. Unmock here so
5// `ChatClient` runs against the actual no-op bridge that ships as the
6// default, instead of the real-bridge substitute the setup file installs.
7import { describe, expect, it, vi } from 'vitest'
8import { ChatClient } from '../src/chat-client'
9import { createMockConnectionAdapter, createTextChunks } from './test-utils'
10​
11vi.unmock('../src/devtools-noop')
12​
13describe('ChatClient with default no-op devtools bridge', () => {
14 it('sends the first message and appends it', async () => {
15 const adapter = createMockConnectionAdapter({
16 chunks: createTextChunks('Hi there'),
17 })
18 const client = new ChatClient({ connection: adapter })
19​
20 await client.sendMessage('hello')
21​
22 const messages = client.getMessages()
23 expect(messages.at(0)?.role).toBe('user')
24 expect(messages.at(0)?.parts).toEqual([{ type: 'text', content: 'hello' }])
25 expect(messages.at(1)?.role).toBe('assistant')
26 })
27​
28 it('updates tools without throwing', () => {
29 const adapter = createMockConnectionAdapter()
30 const client = new ChatClient({ connection: adapter })
31​
32 expect(() => client.updateOptions({ tools: [] })).not.toThrow()
33 })
34})