Open History to see the last commit
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 expect(model?.capabilities).toEqual(
128 expect.arrayContaining(['tools', 'reasoning']),
129 )
130 expect(model?.requestMap).toMatchObject({
131 replayReasoningContent: true,
132 thinking: null,
133 developerRole: null,
134 })
135 expect(model?.factSources?.requestMap?.sourceUrl).toBe(
136 DEEPSEEK_THINKING_URL,
137 )
138 expect(model?.pricing).not.toBeNull()
139 } finally {
140 globalThis.fetch = original
141 }
142})
143
144it('reads prices from the slashed pricing path, not the home page the bare path serves', async () => {
145 const original = globalThis.fetch
146 globalThis.fetch = ((url: string) => {
147 if (String(url) === 'https://api-docs.deepseek.com/quick_start/pricing/')
148 return Promise.resolve(
149 new Response(
150 [
151 'MODEL',
152 'deepseek-v4-pro',
153 'PRICING',
154 '$1',
155 '$2',
156 '$3',
157 '$4',
158 '$5',
159 '$6',
160 'Concurrency',
161 ].join('\n'),
162 ),
163 )
164 if (String(url).includes('api-docs.deepseek.com'))
165 return Promise.resolve(
166 new Response(
167 '<html><title>Your First API Call | DeepSeek API Docs</title></html>',
168 ),
169 )
170 return Promise.resolve(
171 new Response(JSON.stringify({ data: [{ id: 'deepseek-v4-pro' }] })),
172 )
173 }) as typeof fetch
174 try {
175 const result = await provider.listModels({ DEEPSEEK_API_KEY: 'test-key' })
176 expect(result.models[0]?.pricing).toBeDefined()
177 expect(result.models[0]?.absent?.pricing).toBeUndefined()
178 } finally {
179 globalThis.fetch = original
180 }
181})
182
183it('keeps the poll when the pricing page has no table', async () => {
184 const original = globalThis.fetch
185 globalThis.fetch = ((url: string) => {
186 if (String(url).includes('api-docs.deepseek.com'))
187 return Promise.resolve(
188 new Response('<html><title>Just a moment</title><p>wait</p></html>'),
189 )
190 return Promise.resolve(
191 new Response(JSON.stringify({ data: [{ id: 'deepseek-v4-pro' }] })),
192 )
193 }) as typeof fetch
194 try {
195 const result = await provider.listModels({ DEEPSEEK_API_KEY: 'test-key' })
196 expect(result.models[0]?.rawId).toBe('deepseek-v4-pro')
197 expect(result.models[0]?.pricing).toBeUndefined()
198 expect(result.models[0]?.absent).toEqual({ pricing: 'unavailable' })
199 expect(result.docsFailures?.failed).toBe(1)
200 expect(result.docsFailures?.first[0]?.error).toBe(
201 'deepseek pricing page (52 chars, title "Just a moment"): parsed 0 model rows',
202 )
203 } finally {
204 globalThis.fetch = original
205 }
206})
207
208it('keeps the poll when the whole docs host serves a page with no table', async () => {
209 const original = globalThis.fetch
210 globalThis.fetch = ((url: string) => {
211 if (String(url).includes('api-docs.deepseek.com'))
212 return Promise.resolve(
213 new Response('<html><title>Just a moment</title><p>wait</p></html>'),
214 )
215 return Promise.resolve(
216 new Response(
217 JSON.stringify({
218 data: [
219 {
220 id: 'deepseek-v4-pro',
221 effort: { supported_levels: ['high', 'max'] },
222 },
223 ],
224 }),
225 ),
226 )
227 }) as typeof fetch
228 try {
229 const result = await provider.listModels({ DEEPSEEK_API_KEY: 'test-key' })
230 const model = result.models[0]
231 expect(model?.reasoning).not.toBeNull()
232 expect(model?.absent).toEqual({
233 pricing: 'unavailable',
234 requestMap: 'unavailable',
235 })
236 expect(model?.factSources?.requestMapFields).toBeUndefined()
237 expect(result.docsFailures?.first.map((failure) => failure.source)).toEqual(
238 [DEEPSEEK_PRICING_URL, DEEPSEEK_THINKING_URL],
239 )
240 } finally {
241 globalThis.fetch = original
242 }
243})