@quantumai/quantum-cli-core
Version:
Quantum CLI Core - Multi-LLM Collaboration System
33 lines • 1.41 kB
JavaScript
import { describe, it, expect, beforeEach } from 'vitest';
import { QueryCache } from './query-cache.js';
describe('QueryCache', () => {
let queryCache;
beforeEach(() => {
queryCache = new QueryCache(5);
});
it('should cache and retrieve a response', () => {
const query = 'test query';
const response = { content: 'test response', model: 'test-model', providerId: 'test-provider', confidence: 0.9 };
queryCache.set(query, response, 'test-provider');
const cached = queryCache.get(query);
expect(cached).toBeDefined();
expect(cached?.response.content).toBe('test response');
});
it('should return undefined for a non-cached query', () => {
const cached = queryCache.get('non-existent-query');
expect(cached).toBeUndefined();
});
it('should update stats correctly', () => {
const query1 = 'query1';
const query2 = 'query2';
const response = { content: 'response', model: 'test-model', providerId: 'test-provider', confidence: 0.9 };
queryCache.set(query1, response, 'test-provider');
queryCache.get(query1); // hit
queryCache.get(query2); // miss
const stats = queryCache.getStats();
expect(stats.hits).toBe(1);
expect(stats.misses).toBe(1);
expect(stats.hitRate).toBe(0.5);
});
});
//# sourceMappingURL=query-cache.test.js.map