feat: ship Wave 5-6 multi-surface hygiene, optimization, and bug fixes

This commit is contained in:
Yun Chan 2026-11-14 11:51:41 +09:00
parent 01ef3293cf
commit 66b6b45ba9
399 changed files with 17828 additions and 11330 deletions

View file

@ -376,3 +376,29 @@ Deno.test('SSE completion tracker finds message_stop split across chunks', () =>
tracker.push(encoder.encode('op\ndata: {}\n\n'))
assert(tracker.completed, 'completed')
})
Deno.test('non-stream invalid upstream JSON returns 502 and refunds quota', async () => {
const store = new FakeLlmQuotaStore(5)
const handler = createLlmProxyHandler(buildDeps(store, () => Promise.resolve(new Response('not-json', { status: 200 }))))
const resp = await handler(llmRequest(false))
assertEquals(resp.status, 502, 'status')
assertEquals(await resp.json(), { error: 'provider_invalid_response' }, 'body')
assertEquals(store.finalized, [{ id: 'res-1', succeeded: false }], 'refunded')
})
Deno.test('oversized JSON body returns 413 without reserving quota', async () => {
const store = new FakeLlmQuotaStore(5)
const handler = createLlmProxyHandler(buildDeps(store, () => Promise.resolve(okJson())))
const resp = await handler(new Request('http://localhost/llm-proxy', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
messages: [{ role: 'user', content: 'a'.repeat(600 * 1024) }],
}),
}))
assertEquals(resp.status, 413, 'status')
assertEquals(await resp.json(), { error: 'request_too_large' }, 'body')
assertEquals(store.reserveCalls, 0, 'quota must not be touched')
})