mirror of
https://github.com/tiennm99/ccs.git
synced 2026-10-11 12:09:03 +00:00
fix(proxy): keep stream guards active through sse piping
This commit is contained in:
1 parent
a3407093d7
commit
841eeb497c
4 files changed
+36
-16
No files matched your search
@@ -140,7 +140,7 @@ describe('openai proxy message edge cases', () => {
|
||||
type: 'error',
|
||||
error: {
|
||||
type: 'api_error',
|
||||
message: 'Failed to translate Cursor JSON response',
|
||||
message: 'Failed to translate OpenAI-compatible JSON response',
|
||||
},
|
||||
});
|
||||
});
|
||||
@@ -202,6 +202,28 @@ describe('openai proxy message edge cases', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('emits an SSE error if the upstream stalls after response headers are sent', async () => {
|
||||
process.env.CCS_OPENAI_PROXY_REQUEST_TIMEOUT_MS = '50';
|
||||
await startProxyWithHandler((_req, res) => {
|
||||
res.writeHead(200, { 'Content-Type': 'text/event-stream' });
|
||||
res.write(
|
||||
'data: {"id":"chatcmpl_1","model":"hf-model","choices":[{"index":0,"delta":{"role":"assistant","content":"partial"}}]}\n\n'
|
||||
);
|
||||
});
|
||||
|
||||
const response = await requestProxy({
|
||||
model: 'hf-model',
|
||||
stream: true,
|
||||
messages: [{ role: 'user', content: 'hello' }],
|
||||
});
|
||||
|
||||
expect(response.status).toBe(200);
|
||||
const body = await response.text();
|
||||
expect(body).toContain('event: message_start');
|
||||
expect(body).toContain('event: error');
|
||||
expect(body).toContain('"message":"Failed to translate OpenAI-compatible SSE response"');
|
||||
});
|
||||
|
||||
it('aborts the upstream request when the client disconnects mid-flight', async () => {
|
||||
await startProxyWithHandler(() => {});
|
||||
|
||||
|
||||
Reference in new issue
Block a user