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

deepseek.test.ts

286 lines9.0 KB

1import { DEEPSEEK_THINKING_URL } from '../provider-replay.ts'
2import { DEEPSEEK_REPLAY_FIXTURE } from '../fixtures/provider-replay.ts'
3import { describe, expect, it } from 'vitest'
4​
5import { DEEPSEEK_PRICING_URL } from '../deepseek-pricing.ts'
6import { provider } from './deepseek.ts'
7​
8describe('deepseek classify', () => {
9 it('maps chat completions and drops platform paths', () => {
10 expect(
11 provider.classify('/chat/completions', {
12 'x-modelschemas-deepseek-native': true,
13 }),
14 ).toBe('chat')
15 expect(provider.classify('/chat/completions', {})).toBeNull()
16 expect(provider.classify('/v1/chat/completions', {})).toBeNull()
17 expect(provider.classify('/models', {})).toBeNull()
18 expect(provider.classify('/files', {})).toBeNull()
19 expect(provider.classify('/fine_tuning/jobs', {})).toBeNull()
20 })
21})
22​
23describe('deepseek listModels', () => {
24 it('skips when the key is absent', async () => {
25 const result = await provider.listModels({})
26 expect(result.models).toEqual([])
27 expect(result.skipped).toBe('deepseek: DEEPSEEK_API_KEY not set — skipped')
28 })
29​
30 it('lists models when a key is present', async () => {
31 const original = globalThis.fetch
32 const urls: Array<string> = []
33 globalThis.fetch = ((url: string, init?: RequestInit) => {
34 urls.push(String(url))
35 if (String(url).includes('api-docs.deepseek.com')) {
36 return Promise.resolve(
37 new Response(
38 [
39 'MODEL',
40 'deepseek-other',
41 'PRICING',
42 '$0.1',
43 '$0.2',
44 '$0.3',
45 '$0.4',
46 '$0.5',
47 '$0.6',
48 'Concurrency',
49 ].join('\n'),
50 ),
51 )
52 }
53 const headers = new Headers(init?.headers)
54 expect(headers.get('Authorization')).toBe('Bearer test-key')
55 return Promise.resolve(
56 new Response(
57 JSON.stringify({
58 data: [{ id: 'deepseek-v4-pro', created: 1_700_000_000 }],
59 }),
60 ),
61 )
62 }) as typeof fetch
63 try {
64 const result = await provider.listModels({
65 DEEPSEEK_API_KEY: 'test-key',
66 })
67 expect(urls[0]).toBe('https://api.deepseek.com/models')
68 expect(result.skipped).toBeUndefined()
69 expect(result.models).toEqual([
70 {
71 rawId: 'deepseek-v4-pro',
72 releasedAt: 1_700_000_000,
73 activity: null,
74 },
75 ])
76 } finally {
77 globalThis.fetch = original
78 }
79 })
80})
81​
82it('sources DeepSeek effort and replay without losing other native capabilities', async () => {
83 const original = globalThis.fetch
84 globalThis.fetch = ((url: string) => {
85 if (String(url) === DEEPSEEK_THINKING_URL)
86 return Promise.resolve(new Response(DEEPSEEK_REPLAY_FIXTURE))
87 if (String(url).includes('api-docs.deepseek.com'))
88 return Promise.resolve(
89 new Response(
90 [
91 'MODEL',
92 'deepseek-v4-pro',
93 'PRICING',
94 '$1',
95 '$2',
96 '$3',
97 '$4',
98 '$5',
99 '$6',
100 'Concurrency',
101 ].join('\n'),
102 ),
103 )
104 return Promise.resolve(
105 new Response(
106 JSON.stringify({
107 data: [
108 {
109 id: 'deepseek-v4-pro',
110 output_modalities: ['text'],
111 supports_tools: true,
112 effort: { supported_levels: ['high', 'max'] },
113 },
114 ],
115 }),
116 ),
117 )
118 }) as typeof fetch
119 try {
120 const model = (await provider.listModels({ DEEPSEEK_API_KEY: 'test-key' }))
121 .models[0]
122 expect(model?.reasoning).toEqual({
123 mode: 'effort',
124 mandatory: null,
125 efforts: ['high', 'max'],
126 })
127 // A guide that names no model's non-thinking mode changed shape: the
128 // stored `mandatory` is kept rather than overwritten with null.
129 expect(model?.absent?.reasoning).toBe('unavailable')
130 expect(model?.capabilities).toEqual(
131 expect.arrayContaining(['tools', 'reasoning']),
132 )
133 expect(model?.requestMap).toMatchObject({
134 replayReasoningContent: true,
135 thinking: null,
136 developerRole: null,
137 })
138 expect(model?.factSources?.requestMap?.sourceUrl).toBe(
139 DEEPSEEK_THINKING_URL,
140 )
141 expect(model?.pricing).not.toBeNull()
142 } finally {
143 globalThis.fetch = original
144 }
145})
146​
147it('reads mandatory false only for a model whose own top_p bullet names its non-thinking mode', async () => {
148 // Shape of https://api-docs.deepseek.com/guides/thinking_mode/ (2026-10-22).
149 const guide = `${DEEPSEEK_REPLAY_FIXTURE}
150 <p>Thinking mode does not support the temperature parameter. top_p behavior depends on the model:</p>
151 <ul><li><code>deepseek-v4-pro</code>: in thinking mode your value is ignored; in non-thinking mode it takes effect.</li></ul>`
152 const original = globalThis.fetch
153 globalThis.fetch = ((url: string) => {
154 if (String(url) === DEEPSEEK_THINKING_URL)
155 return Promise.resolve(new Response(guide))
156 if (String(url).includes('api-docs.deepseek.com'))
157 return Promise.resolve(new Response('MODEL\nPRICING\nConcurrency'))
158 return Promise.resolve(
159 new Response(
160 JSON.stringify({
161 data: ['deepseek-v4-pro', 'deepseek-flash'].map((id) => ({
162 id,
163 effort: { supported_levels: ['low', 'high', 'max'] },
164 })),
165 }),
166 ),
167 )
168 }) as typeof fetch
169 try {
170 const [pro, flash] = (
171 await provider.listModels({ DEEPSEEK_API_KEY: 'test-key' })
172 ).models
173 expect(pro?.reasoning).toEqual({
174 mode: 'effort',
175 mandatory: false,
176 efforts: ['low', 'high', 'max'],
177 })
178 expect(pro?.factSources?.reasoning?.sourceUrl).toBe(DEEPSEEK_THINKING_URL)
179 expect(flash?.reasoning?.mandatory).toBeNull()
180 expect(flash?.absent?.reasoning).toBeUndefined()
181 } finally {
182 globalThis.fetch = original
183 }
184})
185​
186it('reads prices from the slashed pricing path, not the home page the bare path serves', async () => {
187 const original = globalThis.fetch
188 globalThis.fetch = ((url: string) => {
189 if (String(url) === 'https://api-docs.deepseek.com/quick_start/pricing/')
190 return Promise.resolve(
191 new Response(
192 [
193 'MODEL',
194 'deepseek-v4-pro',
195 'PRICING',
196 '$1',
197 '$2',
198 '$3',
199 '$4',
200 '$5',
201 '$6',
202 'Concurrency',
203 ].join('\n'),
204 ),
205 )
206 if (String(url).includes('api-docs.deepseek.com'))
207 return Promise.resolve(
208 new Response(
209 '<html><title>Your First API Call | DeepSeek API Docs</title></html>',
210 ),
211 )
212 return Promise.resolve(
213 new Response(JSON.stringify({ data: [{ id: 'deepseek-v4-pro' }] })),
214 )
215 }) as typeof fetch
216 try {
217 const result = await provider.listModels({ DEEPSEEK_API_KEY: 'test-key' })
218 expect(result.models[0]?.pricing).toBeDefined()
219 expect(result.models[0]?.absent?.pricing).toBeUndefined()
220 } finally {
221 globalThis.fetch = original
222 }
223})
224​
225it('keeps the poll when the pricing page has no table', async () => {
226 const original = globalThis.fetch
227 globalThis.fetch = ((url: string) => {
228 if (String(url).includes('api-docs.deepseek.com'))
229 return Promise.resolve(
230 new Response('<html><title>Just a moment</title><p>wait</p></html>'),
231 )
232 return Promise.resolve(
233 new Response(JSON.stringify({ data: [{ id: 'deepseek-v4-pro' }] })),
234 )
235 }) as typeof fetch
236 try {
237 const result = await provider.listModels({ DEEPSEEK_API_KEY: 'test-key' })
238 expect(result.models[0]?.rawId).toBe('deepseek-v4-pro')
239 expect(result.models[0]?.pricing).toBeUndefined()
240 expect(result.models[0]?.absent).toEqual({ pricing: 'unavailable' })
241 expect(result.docsFailures?.failed).toBe(1)
242 expect(result.docsFailures?.first[0]?.error).toBe(
243 'deepseek pricing page (52 chars, title "Just a moment"): parsed 0 model rows',
244 )
245 } finally {
246 globalThis.fetch = original
247 }
248})
249​
250it('keeps the poll when the whole docs host serves a page with no table', async () => {
251 const original = globalThis.fetch
252 globalThis.fetch = ((url: string) => {
253 if (String(url).includes('api-docs.deepseek.com'))
254 return Promise.resolve(
255 new Response('<html><title>Just a moment</title><p>wait</p></html>'),
256 )
257 return Promise.resolve(
258 new Response(
259 JSON.stringify({
260 data: [
261 {
262 id: 'deepseek-v4-pro',
263 effort: { supported_levels: ['high', 'max'] },
264 },
265 ],
266 }),
267 ),
268 )
269 }) as typeof fetch
270 try {
271 const result = await provider.listModels({ DEEPSEEK_API_KEY: 'test-key' })
272 const model = result.models[0]
273 expect(model?.reasoning).not.toBeNull()
274 expect(model?.absent).toEqual({
275 pricing: 'unavailable',
276 requestMap: 'unavailable',
277 reasoning: 'unavailable',
278 })
279 expect(model?.factSources?.requestMapFields).toBeUndefined()
280 expect(result.docsFailures?.first.map((failure) => failure.source)).toEqual(
281 [DEEPSEEK_PRICING_URL, DEEPSEEK_THINKING_URL],
282 )
283 } finally {
284 globalThis.fetch = original
285 }
286})