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
+14 -1
View File
@@ -1,5 +1,5 @@
import { describe, expect, it, vi } from 'vitest';
import { createRequestLogger, ensureSchema, insertRequest } from '../src/db.js';
import { createRequestLogger, ensureSchema, insertRequest, removeNonChatCompletionRequests } from '../src/db.js';
describe('request database', () => {
it('creates the requests table, compatible columns, and recent-request index', async () => {
@@ -37,6 +37,19 @@ describe('request database', () => {
]);
});
it('removes requests that are not for the chat completions endpoint', async () => {
const pool = { query: vi.fn().mockResolvedValue({ rowCount: 4 }) };
await expect(removeNonChatCompletionRequests(pool)).resolves.toBe(4);
expect(pool.query).toHaveBeenCalledOnce();
expect(pool.query.mock.calls[0][0]).toContain("split_part(endpoint, '?', 1) <> ALL($1::text[])");
expect(pool.query.mock.calls[0][1]).toEqual([[
'/oai/v1/chat/completions', '/oai/v1/responses',
'/ant/v1/messages', '/ant/v1/v1/messages',
]]);
});
it('reports storage failures without rejecting request handling', async () => {
const onError = vi.fn();
const logger = createRequestLogger({ query: vi.fn().mockRejectedValue(new Error('database offline')) }, { onError });