/** * 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); }); });