@simonecoelhosfo/optimizely-mcp-server
Version:
Optimizely MCP Server for AI assistants with integrated CLI tools
72 lines • 2.66 kB
JavaScript
/**
* Test CacheOrchestrator directly with the same query flow
*/
import { CacheOrchestrator } from './cache/CacheOrchestrator.js';
console.log('Testing CacheOrchestrator directly...\n');
async function testDirect() {
const orchestrator = new CacheOrchestrator({ enabled: true });
// Listen to cache events
orchestrator.on('cache-event', (event) => {
console.log(`📍 Cache Event: ${event.type}`);
if (event.key)
console.log(` Key: ${event.key}`);
if (event.error)
console.log(` Error:`, event.error);
});
let executionCount = 0;
// Mock executor that returns a QueryResult
const mockExecutor = async (query) => {
executionCount++;
console.log(`\nExecutor called (count: ${executionCount})`);
console.log(` Query:`, query);
// Simulate execution delay
await new Promise(resolve => setTimeout(resolve, 50));
// Return a proper QueryResult structure
return {
data: [
{ key: 'flag_a', name: 'Flag A' },
{ key: 'flag_c', name: 'Flag C' }
],
metadata: {
rowCount: 2,
executionTime: 50,
cacheHit: false,
warnings: []
}
};
};
// Test query (UniversalQuery format)
const query = {
find: 'flags',
select: ['key', 'name'],
where: [{ field: 'enabled', operator: '=', value: 1 }],
};
console.log('=== Test 1: First Execution ===');
try {
const result1 = await orchestrator.executeWithCache(query, mockExecutor);
console.log('\nResult 1:');
console.log(' Cached:', result1.cached);
console.log(' Cache Key:', result1.cacheKey);
console.log(' Data:', result1.data);
}
catch (error) {
console.error('Error on first execution:', error);
}
console.log('\n=== Test 2: Second Execution (should be cached) ===');
try {
const result2 = await orchestrator.executeWithCache(query, mockExecutor);
console.log('\nResult 2:');
console.log(' Cached:', result2.cached);
console.log(' Cache Key:', result2.cacheKey);
console.log(' Execution count:', executionCount, '(should still be 1)');
}
catch (error) {
console.error('Error on second execution:', error);
}
console.log('\n=== Cache Statistics ===');
const stats = orchestrator.getStats();
console.log('Stats:', stats);
orchestrator.shutdown();
}
testDirect().catch(console.error);
//# sourceMappingURL=test-cache-orchestrator-direct.js.map