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:
程序员阿江(Relakkes) 2026-06-09 22:16:38 +08:00
parent d3b2f868a9
commit e8bf789961
3 changed files with 38 additions and 2 deletions

View File

@ -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 () => {
await fs.writeFile(
path.join(tmpDir, 'settings.json'),

View File

@ -53,7 +53,7 @@ export function anthropicToOpenaiChat(
const result: OpenAIChatRequest = {
model: body.model,
messages,
stream: body.stream,
stream: body.stream === true,
}
// max_tokens — omit to let upstream provider use its own default/max.

View File

@ -603,7 +603,7 @@ function buildDirectTestRequest(
return {
url: `${base}/v1/chat/completions`,
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') {