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