Open History to see the last commit
1import { afterEach, describe, expect, it, vi } from 'vitest'
2import { resolveDebugOption } from '@tanstack/ai/adapter-internals'
3import { createMistralText } from '../src/adapters/text'
4import type { ReasoningRequest } from '@tanstack/ai'
5import type { MISTRAL_CHAT_MODELS } from '../src/model-meta'
6
7const logger = resolveDebugOption(false)
8
9/** Run one streaming call and return the JSON body it sent. */
10async function send(
11 model: (typeof MISTRAL_CHAT_MODELS)[number],
12 reasoning: ReasoningRequest | undefined,
13) {
14 const fetchMock = vi.fn().mockResolvedValue({
15 ok: true,
16 status: 200,
17 body: new ReadableStream({
18 start(controller) {
19 controller.enqueue(new TextEncoder().encode('data: [DONE]\n\n'))
20 controller.close()
21 },
22 }),
23 })
24 vi.stubGlobal('fetch', fetchMock)
25 const adapter = createMistralText(model, 'test-key')
26 for await (const _chunk of adapter.chatStream({
27 threadId: 'thread-1',
28 logger,
29 model,
30 messages: [{ role: 'user', content: 'hi' }],
31 ...(reasoning ? { reasoning } : {}),
32 })) {
33 // Drain the stream.
34 }
35 const [, init] = fetchMock.mock.calls[0] ?? []
36 return JSON.parse(init.body) as Record<string, unknown>
37}
38
39const on = (level: ReasoningRequest['level']): ReasoningRequest => ({
40 level,
41 summary: true,
42})
43
44describe('Mistral chat({ reasoning }) request shape', () => {
45 afterEach(() => {
46 vi.unstubAllGlobals()
47 })
48
49 it('effort models: reasoning_effort, and none for off', async () => {
50 expect(await send('mistral-small-latest', on('high'))).toMatchObject({
51 reasoning_effort: 'high',
52 })
53 expect(await send('mistral-small-latest', on('off'))).toMatchObject({
54 reasoning_effort: 'none',
55 })
56 })
57
58 it.each(['magistral-medium-latest', 'magistral-small-latest'] as const)(
59 '%s: prompt_mode reasoning, and nothing for off',
60 async (model) => {
61 const high = await send(model, on('medium'))
62 expect(high.prompt_mode).toBe('reasoning')
63 expect(high).not.toHaveProperty('reasoning_effort')
64 const off = await send(model, on('off'))
65 expect(off).not.toHaveProperty('prompt_mode')
66 },
67 )
68
69 it('sends no reasoning fields without a request', async () => {
70 const body = await send('mistral-small-latest', undefined)
71 expect(body).not.toHaveProperty('reasoning_effort')
72 expect(body).not.toHaveProperty('prompt_mode')
73 })
74})