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

deepseek.test.ts

141 lines4.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 { provider } from './deepseek.ts'
6​
7describe('deepseek classify', () => {
8 it('maps chat completions and drops platform paths', () => {
9 expect(
10 provider.classify('/chat/completions', {
11 'x-modelschemas-deepseek-native': true,
12 }),
13 ).toBe('chat')
14 expect(provider.classify('/chat/completions', {})).toBeNull()
15 expect(provider.classify('/v1/chat/completions', {})).toBeNull()
16 expect(provider.classify('/models', {})).toBeNull()
17 expect(provider.classify('/files', {})).toBeNull()
18 expect(provider.classify('/fine_tuning/jobs', {})).toBeNull()
19 })
20})
21​
22describe('deepseek listModels', () => {
23 it('skips when the key is absent', async () => {
24 const result = await provider.listModels({})
25 expect(result.models).toEqual([])
26 expect(result.skipped).toBe('deepseek: DEEPSEEK_API_KEY not set — skipped')
27 })
28​
29 it('lists models when a key is present', async () => {
30 const original = globalThis.fetch
31 const urls: Array<string> = []
32 globalThis.fetch = ((url: string, init?: RequestInit) => {
33 urls.push(String(url))
34 if (String(url).includes('api-docs.deepseek.com')) {
35 return Promise.resolve(
36 new Response(
37 [
38 'MODEL',
39 'deepseek-other',
40 'PRICING',
41 '$0.1',
42 '$0.2',
43 '$0.3',
44 '$0.4',
45 '$0.5',
46 '$0.6',
47 'Concurrency',
48 ].join('\n'),
49 ),
50 )
51 }
52 const headers = new Headers(init?.headers)
53 expect(headers.get('Authorization')).toBe('Bearer test-key')
54 return Promise.resolve(
55 new Response(
56 JSON.stringify({
57 data: [{ id: 'deepseek-v4-pro', created: 1_700_000_000 }],
58 }),
59 ),
60 )
61 }) as typeof fetch
62 try {
63 const result = await provider.listModels({
64 DEEPSEEK_API_KEY: 'test-key',
65 })
66 expect(urls[0]).toBe('https://api.deepseek.com/models')
67 expect(result.skipped).toBeUndefined()
68 expect(result.models).toEqual([
69 {
70 rawId: 'deepseek-v4-pro',
71 releasedAt: 1_700_000_000,
72 activity: null,
73 },
74 ])
75 } finally {
76 globalThis.fetch = original
77 }
78 })
79})
80​
81it('sources DeepSeek effort and replay without losing other native capabilities', async () => {
82 const original = globalThis.fetch
83 globalThis.fetch = ((url: string) => {
84 if (String(url) === DEEPSEEK_THINKING_URL)
85 return Promise.resolve(new Response(DEEPSEEK_REPLAY_FIXTURE))
86 if (String(url).includes('api-docs.deepseek.com'))
87 return Promise.resolve(
88 new Response(
89 [
90 'MODEL',
91 'deepseek-v4-pro',
92 'PRICING',
93 '$1',
94 '$2',
95 '$3',
96 '$4',
97 '$5',
98 '$6',
99 'Concurrency',
100 ].join('\n'),
101 ),
102 )
103 return Promise.resolve(
104 new Response(
105 JSON.stringify({
106 data: [
107 {
108 id: 'deepseek-v4-pro',
109 output_modalities: ['text'],
110 supports_tools: true,
111 effort: { supported_levels: ['high', 'max'] },
112 },
113 ],
114 }),
115 ),
116 )
117 }) as typeof fetch
118 try {
119 const model = (await provider.listModels({ DEEPSEEK_API_KEY: 'test-key' }))
120 .models[0]
121 expect(model?.reasoning).toEqual({
122 mode: 'effort',
123 mandatory: null,
124 efforts: ['high', 'max'],
125 })
126 expect(model?.capabilities).toEqual(
127 expect.arrayContaining(['tools', 'reasoning']),
128 )
129 expect(model?.requestMap).toMatchObject({
130 replayReasoningContent: true,
131 thinking: null,
132 developerRole: null,
133 })
134 expect(model?.factSources?.requestMap?.sourceUrl).toBe(
135 DEEPSEEK_THINKING_URL,
136 )
137 expect(model?.pricing).not.toBeNull()
138 } finally {
139 globalThis.fetch = original
140 }
141})