adding better exporting

This commit is contained in:
2026-07-21 14:31:54 -05:00
parent 5304c2e30c
commit b9b183df40
10 changed files with 225 additions and 25 deletions
+27 -7
View File
@@ -126,17 +126,37 @@ describe('proxy', () => {
});
});
it('collects error and not-found responses too', async () => {
it('does not collect requests to non-chat-completion endpoints', async () => {
const fetchImpl = vi.fn().mockResolvedValue(response('{"object":"list","data":[]}'));
const requestLogger = { log: vi.fn() };
const app = createProxyApp({ keys: ['key'], requestLogger });
const app = createProxyApp({ keys: ['key'], fetchImpl, requestLogger });
await request(app).get('/missing').expect(404);
await request(app).get('/oai/v1/models').expect(200);
expect(requestLogger.log).toHaveBeenCalledOnce();
expect(requestLogger.log.mock.calls[0][0]).toMatchObject({
method: 'GET', endpoint: '/missing', requestBody: null, responseStatus: 404,
});
expect(requestLogger.log.mock.calls[0][0].responseBody).toContain('Cannot GET /missing');
expect(requestLogger.log).not.toHaveBeenCalled();
});
it('collects OpenAI Responses and Anthropic Messages requests', async () => {
const cases = [
{ endpoint: '/oai/v1/responses', body: { model: 'm', input: 'Hi' } },
{ endpoint: '/ant/v1/messages', body: { model: 'm', max_tokens: 10, messages: [{ role: 'user', content: 'Hi' }] } },
{ endpoint: '/ant/v1/v1/messages', body: { model: 'm', max_tokens: 10, messages: [{ role: 'user', content: 'Hi' }] } },
];
for (const { endpoint, body } of cases) {
const fetchImpl = vi.fn().mockResolvedValue(response(JSON.stringify({
id: 'chatcmpl-response', model: 'm',
choices: [{ message: { role: 'assistant', content: 'Hello' }, finish_reason: 'stop' }],
})));
const requestLogger = { log: vi.fn() };
const app = createProxyApp({ keys: ['key'], fetchImpl, requestLogger });
await request(app).post(endpoint).send(body).expect(200);
expect(requestLogger.log).toHaveBeenCalledOnce();
expect(requestLogger.log.mock.calls[0][0]).toMatchObject({ method: 'POST', endpoint, requestBody: body });
}
});
it('translates Responses requests and returns a Responses object', async () => {