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

cerebras-reasoning.test.ts

178 lines5.2 KB

1import { readFileSync } from 'node:fs'
2​
3import { describe, expect, it } from 'vitest'
4​
5import {
6 cerebrasRequestMap,
7 cerebrasThinking,
8 parseCerebrasChatSpec,
9 parseCerebrasReasoning,
10} from './cerebras-reasoning.ts'
11​
12/** https://inference-docs.cerebras.ai/capabilities/reasoning.md on 2026-11-13. */
13const REASONING = readFileSync(
14 new URL('./fixtures/cerebras-reasoning.md.txt', import.meta.url),
15 'utf8',
17​
18/** One model whose section never says whether reasoning can be turned off. */
19const UNSTATED = `
20| Model | Default effort | Availability |
21| - | - | - |
22| [GPT OSS 120B](#gpt-oss-120b) | \`medium\` | Shared |
23​
24## Model behavior
25​
26### GPT OSS 120B
27​
28[\`gpt-oss-120b\`](/models/openai-oss) supports reasoning.
29​
30| Value | Behavior |
31| - | - |
32| \`low\` | Selects low reasoning effort |
33| \`medium\` (default) | Selects medium reasoning effort |
34| \`high\` | Selects high reasoning effort |
36​
37/** The chat-spec sentences the request map is allowed to trust. */
38const SPEC = `
39 max_completion_tokens:
40 type: integer
41 nullable: true
42 description: >
43 The maximum number of tokens that can be generated in the
44 completion, including reasoning tokens.
45 max_tokens:
46 type: integer
47 nullable: true
48 description: >
49 An alias for \`max_completion_tokens\`. Do not send both parameters
50 in the same request.
51 description: >
52 A message in the conversation. Developer messages are supported only by \`gpt-oss-120b\`.
54​
55describe('cerebras reasoning page', () => {
56 const parsed = parseCerebrasReasoning(REASONING)
57​
58 it('reads each model section for efforts and whether reasoning can be disabled', () => {
59 expect(parsed.configured.get('qwen-3.8-27b')).toEqual({
60 mode: 'effort',
61 mandatory: false,
62 efforts: ['none', 'low', 'medium', 'high'],
63 })
64 expect(parsed.configured.get('kimi-k3')).toEqual({
65 mode: 'effort',
66 mandatory: true,
67 efforts: ['low', 'high', 'max'],
68 })
69 expect(parsed.configured.get('kimi-k3.1-pro')).toEqual({
70 mode: 'effort',
71 mandatory: true,
72 efforts: ['low', 'medium', 'high', 'max'],
73 })
74 expect(parsed.configured.get('zai-glm-5.3-flash')).toEqual({
75 mode: 'effort',
76 mandatory: true,
77 efforts: ['low', 'high', 'max'],
78 })
79 expect(parsed.configured.get('gpt-oss-120b')).toEqual({
80 mode: 'effort',
81 mandatory: true,
82 efforts: ['low', 'medium', 'high'],
83 })
84 expect(parsed.configured.get('gemma-4-31b')).toEqual({
85 mode: 'effort',
86 mandatory: false,
87 efforts: ['none', 'low', 'medium', 'high'],
88 })
89 expect(parsed.ignored).toEqual(['kimi-k2.7-code'])
90 expect([...parsed.configured.keys()]).toEqual([
91 'qwen-3.8-27b',
92 'kimi-k3',
93 'kimi-k3.1-pro',
94 'zai-glm-5.3-flash',
95 'gpt-oss-120b',
96 'gemma-4-31b',
97 ])
98 })
99​
100 it('throws when a behavior cell is not accept, disable, or unsupported', () => {
101 expect(() =>
102 parseCerebrasReasoning(
103 REASONING.replace(
104 '| `medium` (default) | Selects medium reasoning effort |',
105 '| `medium` (default) | Sometimes |',
106 ),
107 ),
108 ).toThrow(/gpt-oss-120b unread behavior/)
109 })
110​
111 it('throws when the section never says whether reasoning can be disabled', () => {
112 expect(() => parseCerebrasReasoning(UNSTATED)).toThrow(
113 /does not state whether reasoning can be disabled/,
114 )
115 })
116​
117 it('throws when the page has no model behavior section', () => {
118 expect(() =>
119 parseCerebrasReasoning(
120 REASONING.replace('## Model behavior', '## Notes'),
121 ),
122 ).toThrow(/no model behavior section/)
123 })
124})
125​
126describe('cerebras chat spec', () => {
127 const spec = parseCerebrasChatSpec(SPEC)
128​
129 it('keeps max_completion_tokens and the developer-role ids', () => {
130 expect(spec).toEqual({
131 maxTokensField: 'max_completion_tokens',
132 developerIds: ['gpt-oss-120b'],
133 })
134 })
135​
136 it('throws when max_tokens stops being the alias', () => {
137 expect(() =>
138 parseCerebrasChatSpec(SPEC.replace('An alias for', 'Previously')),
139 ).toThrow(/not an alias/)
140 })
141​
142 it('maps qwen off to none and leaves gpt-oss with no off body', () => {
143 const reasoning = parseCerebrasReasoning(REASONING)
144 expect(cerebrasThinking(['none', 'low', 'medium', 'high'])).toEqual({
145 on: { reasoning_effort: 'high' },
146 off: { reasoning_effort: 'none' },
147 levels: {
148 off: 'none',
149 minimal: null,
150 low: 'low',
151 medium: 'medium',
152 high: 'high',
153 xhigh: null,
154 max: null,
155 },
156 })
157 const qwen = cerebrasRequestMap(
158 'qwen-3.8-27b',
159 spec,
160 reasoning.configured.get('qwen-3.8-27b'),
161 false,
162 )
163 const oss = cerebrasRequestMap(
164 'gpt-oss-120b',
165 spec,
166 reasoning.configured.get('gpt-oss-120b'),
167 false,
168 )
169 expect(qwen.developerRole).toBe(false)
170 expect(qwen.thinking?.off).toEqual({ reasoning_effort: 'none' })
171 expect(qwen.reasoningEffort).toBe(true)
172 expect(oss.developerRole).toBe(true)
173 expect(oss.thinking?.off).toBeNull()
174 expect(oss.maxTokensField).toBe('max_completion_tokens')
175 expect(oss.replayReasoningContent).toBeNull()
176 expect(oss.toolStream).toBeNull()
177 })
178})