db logs
This commit is contained in:
+23
-2
@@ -1,5 +1,11 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { createRequestLogger, ensureSchema, insertRequest, removeNonChatCompletionRequests } from '../src/db.js';
|
||||
import {
|
||||
createRequestLogger,
|
||||
ensureSchema,
|
||||
insertRequest,
|
||||
removeNonChatCompletionRequests,
|
||||
selectTrainingRequests,
|
||||
} from '../src/db.js';
|
||||
|
||||
describe('request database', () => {
|
||||
it('creates the requests table, compatible columns, and recent-request index', async () => {
|
||||
@@ -37,12 +43,13 @@ describe('request database', () => {
|
||||
]);
|
||||
});
|
||||
|
||||
it('removes requests that are not for the chat completions endpoint', async () => {
|
||||
it('removes successful non-training requests but retains failures', 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('response_status BETWEEN 200 AND 299');
|
||||
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',
|
||||
@@ -50,6 +57,20 @@ describe('request database', () => {
|
||||
]]);
|
||||
});
|
||||
|
||||
it('selects only successful training requests for export', async () => {
|
||||
const pool = { query: vi.fn().mockResolvedValue({ rows: [] }) };
|
||||
|
||||
await selectTrainingRequests(pool, { limit: 250 });
|
||||
|
||||
const [sql, params] = pool.query.mock.calls[0];
|
||||
expect(sql).toContain('response_status BETWEEN 200 AND 299');
|
||||
expect(sql).toContain("split_part(endpoint, '?', 1) = ANY($1::text[])");
|
||||
expect(params).toEqual([[
|
||||
'/oai/v1/chat/completions', '/oai/v1/responses',
|
||||
'/ant/v1/messages', '/ant/v1/v1/messages',
|
||||
], 250]);
|
||||
});
|
||||
|
||||
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 });
|
||||
|
||||
Reference in New Issue
Block a user