benchmark-db.test.js
1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/**
* Unit Tests — benchmark-db.js
*/
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
import fs from 'fs';
describe('benchmark-db', () => {
let benchmarkDB;
const TEST_DB_PATH = `/tmp/test-benchmark-${Date.now()}.sqlite`;
beforeAll(() => {
if (fs.existsSync(TEST_DB_PATH)) fs.unlinkSync(TEST_DB_PATH);
process.env.BENCHMARK_DB_PATH = TEST_DB_PATH;
delete require.cache[require.resolve('../../services/benchmark-db')];
benchmarkDB = require('../../services/benchmark-db');
benchmarkDB.initDB();
});
afterAll(() => {
try { benchmarkDB.closeDB(); } catch {}
try { fs.unlinkSync(TEST_DB_PATH); } catch {}
});
it('should initialize without error', () => {
expect(() => benchmarkDB.initDB()).not.toThrow();
});
it('should insert a benchmark run', () => {
expect(() =>
benchmarkDB.insertBenchmarkRun({
skillName: 'benchmark_test',
scores: { successRate: 0.95, accuracy: 0.88, speed: 1.2, cost: 0.5 },
elo: 1250,
version: '1.0.0',
})
).not.toThrow();
});
it('should get skill history', () => {
const history = benchmarkDB.getSkillHistory('benchmark_test', 10);
expect(Array.isArray(history)).toBe(true);
});
it('should get ELO history', () => {
const history = benchmarkDB.getEloHistory('benchmark_test', 10);
expect(Array.isArray(history)).toBe(true);
});
it('should get benchmark stats', () => {
const stats = benchmarkDB.getBenchmarkStats();
expect(stats).toBeDefined();
});
it('should get recent comparisons', () => {
const comps = benchmarkDB.getRecentComparisons(5);
expect(Array.isArray(comps)).toBe(true);
});
});