mirror of
https://github.com/NanmiCoder/cc-haha
synced 2026-07-26 15:03:34 +08:00
fix(provider): request non-stream OpenAI chat tests (#638)
Ensure custom OpenAI-compatible provider tests explicitly request non-stream responses for both direct connectivity checks and the proxy pipeline. This avoids default SSE responses being parsed as empty JSON by provider validation. Tested: bun test src/server/__tests__/providers.test.ts --test-name-pattern "requests non-stream OpenAI Chat responses during provider tests" Tested: bun test src/server/__tests__/providers.test.ts Tested: bun test src/server/__tests__/proxy-transform.test.ts Tested: bun run check:server Confidence: high Scope-risk: narrow
This commit is contained in:
parent
d3b2f868a9
commit
e8bf789961
@ -1263,6 +1263,42 @@ describe('ProviderService', () => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('requests non-stream OpenAI Chat responses during provider tests', async () => {
|
||||||
|
const originalFetch = globalThis.fetch
|
||||||
|
const calls: Array<{ body: Record<string, unknown> }> = []
|
||||||
|
globalThis.fetch = mock(async (_url: string | URL | Request, init?: RequestInit) => {
|
||||||
|
calls.push({ body: JSON.parse(String(init?.body)) as Record<string, unknown> })
|
||||||
|
return new Response(JSON.stringify({
|
||||||
|
id: 'chatcmpl-1',
|
||||||
|
object: 'chat.completion',
|
||||||
|
created: 0,
|
||||||
|
model: 'deepseek-v4-flash',
|
||||||
|
choices: [{ index: 0, message: { role: 'assistant', content: 'ok' }, finish_reason: 'stop' }],
|
||||||
|
usage: { prompt_tokens: 1, completion_tokens: 1, total_tokens: 2 },
|
||||||
|
}), {
|
||||||
|
status: 200,
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
})
|
||||||
|
}) as typeof fetch
|
||||||
|
|
||||||
|
try {
|
||||||
|
const svc = new ProviderService()
|
||||||
|
const result = await svc.testProviderConfig({
|
||||||
|
baseUrl: 'https://api.example.com',
|
||||||
|
apiKey: 'sk-api',
|
||||||
|
modelId: 'deepseek-v4-flash',
|
||||||
|
authStrategy: 'api_key',
|
||||||
|
apiFormat: 'openai_chat',
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(result.connectivity.success).toBe(true)
|
||||||
|
expect(result.proxy?.success).toBe(true)
|
||||||
|
expect(calls.map((call) => call.body.stream)).toEqual([false, false])
|
||||||
|
} finally {
|
||||||
|
globalThis.fetch = originalFetch
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
test('should use configured network timeout for provider tests', async () => {
|
test('should use configured network timeout for provider tests', async () => {
|
||||||
await fs.writeFile(
|
await fs.writeFile(
|
||||||
path.join(tmpDir, 'settings.json'),
|
path.join(tmpDir, 'settings.json'),
|
||||||
|
|||||||
@ -53,7 +53,7 @@ export function anthropicToOpenaiChat(
|
|||||||
const result: OpenAIChatRequest = {
|
const result: OpenAIChatRequest = {
|
||||||
model: body.model,
|
model: body.model,
|
||||||
messages,
|
messages,
|
||||||
stream: body.stream,
|
stream: body.stream === true,
|
||||||
}
|
}
|
||||||
|
|
||||||
// max_tokens — omit to let upstream provider use its own default/max.
|
// max_tokens — omit to let upstream provider use its own default/max.
|
||||||
|
|||||||
@ -603,7 +603,7 @@ function buildDirectTestRequest(
|
|||||||
return {
|
return {
|
||||||
url: `${base}/v1/chat/completions`,
|
url: `${base}/v1/chat/completions`,
|
||||||
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${apiKey}` },
|
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${apiKey}` },
|
||||||
body: { model: modelId, max_tokens: 16, messages: [{ role: 'user', content: prompt }] },
|
body: { model: modelId, max_tokens: 16, stream: false, messages: [{ role: 'user', content: prompt }] },
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (format === 'openai_responses') {
|
if (format === 'openai_responses') {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user