|
| 1 | +import { OpenAI } from 'openai'; |
| 2 | +import { DeepseekEngine } from '../../src/engine/deepseek'; |
| 3 | + |
| 4 | +describe('DeepseekEngine', () => { |
| 5 | + const baseConfig = { |
| 6 | + apiKey: 'test-deepseek-key', |
| 7 | + maxTokensInput: 4096, |
| 8 | + maxTokensOutput: 256 |
| 9 | + }; |
| 10 | + |
| 11 | + const messages: Array<OpenAI.Chat.Completions.ChatCompletionMessageParam> = [ |
| 12 | + { role: 'system', content: 'system message' }, |
| 13 | + { role: 'user', content: 'diff --git a/file b/file' } |
| 14 | + ]; |
| 15 | + |
| 16 | + it('disables thinking mode via a top-level request body field', async () => { |
| 17 | + const engine = new DeepseekEngine({ |
| 18 | + ...baseConfig, |
| 19 | + model: 'deepseek-v4-flash' |
| 20 | + }); |
| 21 | + |
| 22 | + const create = jest |
| 23 | + .spyOn(engine.client.chat.completions, 'create') |
| 24 | + .mockResolvedValue({ |
| 25 | + choices: [{ message: { content: 'feat(deepseek): thinking off' } }] |
| 26 | + } as any); |
| 27 | + |
| 28 | + await engine.generateCommitMessage(messages); |
| 29 | + |
| 30 | + // The JavaScript OpenAI SDK forwards unknown top-level fields as-is, so |
| 31 | + // `thinking` must be a top-level key in the request body for DeepSeek to |
| 32 | + // honour it. See https://api-docs.deepseek.com/guides/thinking_mode |
| 33 | + expect(create).toHaveBeenCalledWith( |
| 34 | + expect.objectContaining({ |
| 35 | + model: 'deepseek-v4-flash', |
| 36 | + max_tokens: 256, |
| 37 | + temperature: 0, |
| 38 | + top_p: 0.1, |
| 39 | + thinking: { type: 'disabled' } |
| 40 | + }) |
| 41 | + ); |
| 42 | + }); |
| 43 | + |
| 44 | + it('does not send extra_body (a Python SDK helper) in the request', async () => { |
| 45 | + const engine = new DeepseekEngine({ |
| 46 | + ...baseConfig, |
| 47 | + model: 'deepseek-v4-flash' |
| 48 | + }); |
| 49 | + |
| 50 | + const create = jest |
| 51 | + .spyOn(engine.client.chat.completions, 'create') |
| 52 | + .mockResolvedValue({ |
| 53 | + choices: [{ message: { content: 'feat(deepseek): no extra_body' } }] |
| 54 | + } as any); |
| 55 | + |
| 56 | + await engine.generateCommitMessage(messages); |
| 57 | + |
| 58 | + // `extra_body` is only understood by the Python SDK. If it ever sneaks |
| 59 | + // back into the JS request, DeepSeek receives an `extra_body` field and |
| 60 | + // thinking mode stays enabled, re-introducing EMPTY_MESSAGE failures. |
| 61 | + expect(create).toHaveBeenCalledWith( |
| 62 | + expect.not.objectContaining({ |
| 63 | + extra_body: expect.anything() |
| 64 | + }) |
| 65 | + ); |
| 66 | + }); |
| 67 | + |
| 68 | + it('uses the DeepSeek endpoint by default', () => { |
| 69 | + const engine = new DeepseekEngine({ |
| 70 | + ...baseConfig, |
| 71 | + model: 'deepseek-v4-flash' |
| 72 | + }); |
| 73 | + |
| 74 | + expect(engine.client.baseURL).toContain('api.deepseek.com'); |
| 75 | + }); |
| 76 | +}); |
0 commit comments