Open History to see the last commit
1import { describe, expect, it } from 'vitest'
2
3import { takeIngestEvents } from '../ingest/ingest-signals.ts'
4import {
5 keepValidReasoning,
6 openRouterReasoning,
7 parseByteplusReasoning,
8 parseCohereReasoning,
9 parseGroqReasoning,
10 parseMistralReasoning,
11} from './reasoning-config.ts'
12import { reasoningViolation } from './types.ts'
13
14describe('reasoningViolation', () => {
15 it.each([
16 { mode: 'effort', mandatory: true },
17 { mode: 'effort', mandatory: null, efforts: ['low', 'max'] },
18 { mode: 'effort', mandatory: false, efforts: ['none', 'low'] },
19 { mode: 'effort', mandatory: null, efforts: ['none', 'low'] },
20 { mode: 'adaptive', mandatory: false },
21 // One prod budget row carries efforts; that is allowed.
22 { mode: 'budget', mandatory: false, efforts: ['low'] },
23 { mode: 'toggle', mandatory: false },
24 { mode: 'toggle', mandatory: true },
25 ])('accepts %j', (value) => {
26 expect(reasoningViolation(value)).toBeNull()
27 })
28
29 it.each([
30 ['a non-object', 'effort', 'not an object'],
31 ['an unknown mode', { mode: 'switch', mandatory: false }, 'unknown mode'],
32 ['a missing mandatory', { mode: 'effort' }, 'mandatory is not'],
33 ['a string mandatory', { mode: 'effort', mandatory: 'no' }, 'mandatory'],
34 [
35 'a toggle with an unstated mandatory',
36 { mode: 'toggle', mandatory: null },
37 'a toggle needs a stated mandatory',
38 ],
39 [
40 'efforts on a toggle',
41 { mode: 'toggle', mandatory: false, efforts: ['low'] },
42 'a toggle takes no efforts',
43 ],
44 [
45 'empty efforts',
46 { mode: 'effort', mandatory: true, efforts: [] },
47 'efforts',
48 ],
49 [
50 'a non-string effort',
51 { mode: 'effort', mandatory: true, efforts: ['low', 1] },
52 'efforts',
53 ],
54 [
55 'a mandatory true with a none effort',
56 { mode: 'effort', mandatory: true, efforts: ['none', 'low'] },
57 'mandatory is true but efforts include none',
58 ],
59 [
60 'null efforts',
61 { mode: 'effort', mandatory: true, efforts: null },
62 'efforts',
63 ],
64 ])('refuses %s', (_case, value, reason) => {
65 expect(reasoningViolation(value)).toContain(reason)
66 })
67})
68
69describe('keepValidReasoning', () => {
70 const source = { derivation: 'listing' as const, sourceUrl: 'https://x.test' }
71
72 it('passes a valid or absent object through untouched', () => {
73 const valid = {
74 rawId: 'm',
75 reasoning: { mode: 'toggle', mandatory: false },
76 }
77 expect(keepValidReasoning('p', valid as never)).toBe(valid)
78 const none = { rawId: 'm', reasoning: null }
79 expect(keepValidReasoning('p', none)).toBe(none)
80 expect(takeIngestEvents()).toEqual([])
81 })
82
83 it('keeps the prior value and source, and reports the refusal', () => {
84 const prior = {
85 reasoning: { mode: 'effort', mandatory: true },
86 factSources: { reasoning: { ...source, path: 'old' } },
87 }
88 const kept = keepValidReasoning(
89 'prov',
90 {
91 rawId: 'm-1',
92 reasoning: { mode: 'toggle', mandatory: null },
93 factSources: { reasoning: source, contextWindow: source },
94 },
95 prior,
96 )
97 expect(kept.reasoning).toEqual(prior.reasoning)
98 expect(kept.factSources).toEqual({
99 contextWindow: source,
100 reasoning: prior.factSources.reasoning,
101 })
102 expect(takeIngestEvents()).toEqual([
103 {
104 event: 'ingest_failed',
105 properties: {
106 job: 'models-poll',
107 providerId: 'prov',
108 error: 'm-1: reasoning not stored: a toggle needs a stated mandatory',
109 },
110 },
111 ])
112 })
113
114 it('keeps the prior value over a mandatory true with a none effort', () => {
115 const prior = {
116 reasoning: { mode: 'effort', mandatory: false, efforts: ['none', 'low'] },
117 factSources: null,
118 }
119 const kept = keepValidReasoning(
120 'prov',
121 {
122 rawId: 'm-3',
123 reasoning: {
124 mode: 'effort',
125 mandatory: true,
126 efforts: ['none', 'low'],
127 },
128 },
129 prior,
130 )
131 expect(kept.reasoning).toEqual(prior.reasoning)
132 expect(takeIngestEvents()).toEqual([
133 {
134 event: 'ingest_failed',
135 properties: {
136 job: 'models-poll',
137 providerId: 'prov',
138 error:
139 'm-3: reasoning not stored: mandatory is true but efforts include none',
140 },
141 },
142 ])
143 })
144
145 it('stores nothing on a new row', () => {
146 const kept = keepValidReasoning('prov', {
147 rawId: 'm-2',
148 reasoning: { mode: 'toggle', mandatory: null },
149 factSources: { reasoning: source },
150 })
151 expect(kept.reasoning).toBeNull()
152 expect(kept.factSources).toBeUndefined()
153 takeIngestEvents()
154 })
155})
156
157const MISTRAL = `
158# Reasoning
159
160- \`mistral-small-latest\`: Supports adjustable reasoning via the \`reasoning_effort\` parameter. No extra configuration required.
161- \`mistral-medium-3-5\`: Supports adjustable reasoning via the \`reasoning_effort\` parameter.
162- \`zai-glm-5-3\`: Supports adjustable reasoning via the \`reasoning_effort\` parameter. Supported values are \`low\`, \`high\`, and \`max\` (see note below).
163
164- \`reasoning_effort = "high"\`: full thinking chunk.
165- \`reasoning_effort = "none"\`: thinking chunk omitted.
166
167\`zai-glm-5-3\` supports \`low\`, \`high\`, and \`max\` — not \`none\`.
168
169## Handling thinking chunks
170`
171
172const NATIVE = `
173# Native reasoning (deprecated)
174
175Native reasoning models always generate thinking traces without any extra parameters:
176
177- \`magistral-small-latest\`: open smaller version.
178- \`magistral-medium-latest\`: more powerful reasoning model.
179`
180
181const GROQ = `
182# Reasoning
183
184## [Supported Models](#supported-models)
185
186| Model ID | Model |
187| --- | --- |
188| openai/gpt-oss-120b | [OpenAI GPT-OSS 120B](https://example.com/120) |
189| openai/gpt-oss-safeguard-20b | [OpenAI GPT-OSS-Safeguard 20B](https://example.com/safe) |
190| qwen/qwen3.8-27b | [Qwen 3.8 27B](https://example.com/qwen) |
191| minimaxai/minimax-m2.7 | [MiniMax M2.7](https://example.com/mini) |
192
193### Options for Reasoning Effort (Qwen 3.8 27B)
194
195[Qwen 3.8 27B](https://example.com/qwen) supports the following options:
196
197| reasoning_effort Options | Description |
198| --- | --- |
199| none | Disable reasoning. |
200| default | Default behavior. |
201| low | Low effort. |
202| medium | Medium effort. |
203| high | High effort. |
204
205### Options for Reasoning Effort (GPT-OSS)
206
207This is only supported by [GPT-OSS 120B](https://example.com/120).
208
209| reasoning_effort Options | Description |
210| --- | --- |
211| low | Low effort. |
212| medium | Medium effort. |
213| high | High effort. |
214`
215
216const COHERE = `
217# Reasoning
218
219\`\`\`python
220response = co.chat(
221 model="command-a-reasoning-08-2025",
222 messages=[{"role": "user", "content": "Hi"}],
223)
224\`\`\`
225
226thinking={
227 "type": "disabled" # turns off thinking. It is set to "enabled" by default.
228}
229
230thinking = {"token_budget": 500}
231`
232
233const COHERE_SILENT = `
234# Reasoning
235
236model="command-r-08-2024"
237
238Reasoning is on by default. No budget or effort parameter is documented.
239`
240
241const BYTEPLUS = `
242## Adjust chain-of-thought length
243
244* \`none\`: Turn off reasoning.
245* \`minimal\`: Turns off reasoning and answers directly.
246* \`low\`: Light reasoning.
247* \`high\`: Deep analysis.
248
249|Supported models |Default value |Compatibility mapping |
250|---|---|---|
251|\\* \`dola-seed-2-1-turbo-260628\` | | |
252|* \`seed-2-0-lite-260228\`<br>* \`glm-5-2-260617\` |\`medium\` | If \`none\` is passed, reasoning is turned off. |
253
254## Pass thinking content back
255
256\`seed-1-6-250615\` supports thinking but is not in the effort table.
257`
258
259describe('openRouterReasoning', () => {
260 it('copies published efforts and does not invent a mode', () => {
261 expect(
262 openRouterReasoning({
263 reasoning: {
264 supported_efforts: ['high', 'low', null],
265 mandatory: false,
266 },
267 }),
268 ).toEqual({
269 mode: 'effort',
270 mandatory: false,
271 efforts: ['high', 'low'],
272 })
273 expect(
274 openRouterReasoning({
275 reasoning: { supported_efforts: null, mandatory: true },
276 }),
277 ).toEqual({ mode: 'effort', mandatory: true })
278 expect(
279 openRouterReasoning({
280 reasoning: { supports_max_tokens: true, mandatory: true },
281 }),
282 ).toEqual({ mode: 'budget', mandatory: true })
283 expect(
284 openRouterReasoning({
285 reasoning: { mandatory: true },
286 }),
287 ).toBeNull()
288 expect(
289 openRouterReasoning({
290 reasoning: null,
291 }),
292 ).toBeNull()
293 })
294})
295
296describe('parseMistralReasoning', () => {
297 it('reads effort names the guide states, and leaves native models unset', () => {
298 const parsed = parseMistralReasoning(MISTRAL)
299 expect(parsed.get('mistral-small-latest')).toEqual({
300 mode: 'effort',
301 mandatory: false,
302 })
303 expect(parsed.get('mistral-medium-3-5')).toEqual({
304 mode: 'effort',
305 mandatory: false,
306 })
307 expect(parsed.get('mistral-medium-3-5')?.mode).toBe('effort')
308 expect(parsed.get('zai-glm-5-3')).toEqual({
309 mode: 'effort',
310 mandatory: null,
311 efforts: ['low', 'high', 'max'],
312 })
313 expect(parseMistralReasoning(NATIVE).get('magistral-medium-latest')).toBe(
314 undefined,
315 )
316 })
317})
318
319describe('parseGroqReasoning', () => {
320 it('reads each effort table and leaves models with no options unset', () => {
321 const parsed = parseGroqReasoning(GROQ)
322 expect(parsed.get('qwen/qwen3.8-27b')).toEqual({
323 mode: 'effort',
324 mandatory: false,
325 efforts: ['none', 'default', 'low', 'medium', 'high'],
326 })
327 expect(parsed.get('openai/gpt-oss-120b')).toEqual({
328 mode: 'effort',
329 mandatory: true,
330 efforts: ['low', 'medium', 'high'],
331 })
332 expect(parsed.get('openai/gpt-oss-safeguard-20b')).toBeUndefined()
333 expect(parsed.get('minimaxai/minimax-m2.7')).toBeUndefined()
334 })
335})
336
337describe('parseCohereReasoning', () => {
338 it('uses token_budget as budget mode and stays null without that knob', () => {
339 expect(
340 parseCohereReasoning(COHERE).get('command-a-reasoning-08-2025'),
341 ).toEqual({ mode: 'budget', mandatory: false })
342 expect(
343 parseCohereReasoning(COHERE_SILENT).get('command-r-08-2024'),
344 ).toBeUndefined()
345 })
346
347 it('covers every reasoning model only while the guide calls them hybrid', () => {
348 // The sentence as https://docs.cohere.com/docs/reasoning.md had it on
349 // 2026-10-07.
350 const hybrid = `Cohere's reasoning models are *hybrid*, meaning reasoning can be enabled (in which case they generate internal reasoning processes before delivering their final responses) or disabled (in which case they function the way any other LLM would).`
351 expect(parseCohereReasoning(COHERE).has('*')).toBe(false)
352 expect(parseCohereReasoning(`${hybrid}\n${COHERE}`).get('*')).toEqual({
353 mode: 'budget',
354 mandatory: false,
355 })
356 expect(
357 parseCohereReasoning(
358 `${hybrid.replace('or disabled', 'but not disabled')}\n${COHERE}`,
359 ).has('*'),
360 ).toBe(false)
361 // Without the budget knob the sentence configures nothing.
362 expect(parseCohereReasoning(`${hybrid}\n${COHERE_SILENT}`).size).toBe(0)
363 })
364})
365
366describe('parseByteplusReasoning', () => {
367 it('copies the published effort list onto supported-model ids only', () => {
368 const parsed = parseByteplusReasoning(BYTEPLUS)
369 expect(parsed.get('seed-2-0-lite-260228')).toEqual({
370 mode: 'effort',
371 mandatory: false,
372 efforts: ['none', 'minimal', 'low', 'high'],
373 })
374 expect(parsed.get('dola-seed-2-1-turbo-260628')?.mode).toBe('effort')
375 expect(parsed.get('glm-5-2-260617')?.efforts).toEqual([
376 'none',
377 'minimal',
378 'low',
379 'high',
380 ])
381 expect(parsed.get('seed-1-6-250615')).toBeUndefined()
382 })
383})