wifi-densepose/vendor/sublinear-time-solver/tests/validate-cache-final.js

149 lines
5.1 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env node
import { PsychoSymbolicTools } from '../dist/mcp/tools/psycho-symbolic.js';
async function validateCacheFinal() {
console.log('🔍 Final Cache Implementation Validation\n');
console.log('='.repeat(50));
const tools = new PsychoSymbolicTools({
enableCache: true,
maxCacheSize: 100,
enableWarmup: true
});
// Test 1: Cache status tool
console.log('\n1⃣ Testing cache status tool...');
try {
const status = await tools.handleToolCall('reasoning_cache_status', { detailed: true });
console.log(' ✅ Cache status tool works');
console.log(` 📊 Hit ratio: ${status.hit_ratio}`);
console.log(` 💾 Cache size: ${status.cache_status.size}`);
} catch (error) {
console.log(' ❌ Cache status error:', error.message);
}
// Test 2: Performance with cache enabled
console.log('\n2⃣ Testing cached reasoning...');
const testQuery = 'What are security vulnerabilities in JWT caching mechanisms?';
// First call (cache miss)
const start1 = performance.now();
const result1 = await tools.handleToolCall('psycho_symbolic_reason', {
query: testQuery,
use_cache: true,
depth: 5
});
const time1 = performance.now() - start1;
console.log(` First call: ${time1.toFixed(2)}ms - Cache hit: ${result1.cache_hit ? 'YES' : 'NO'}`);
console.log(` Insights generated: ${result1.insights?.length || 0}`);
// Second call (should be cache hit)
const start2 = performance.now();
const result2 = await tools.handleToolCall('psycho_symbolic_reason', {
query: testQuery,
use_cache: true,
depth: 5
});
const time2 = performance.now() - start2;
console.log(` Second call: ${time2.toFixed(2)}ms - Cache hit: ${result2.cache_hit ? 'YES' : 'NO'}`);
// Performance validation
const speedup = ((time1 - time2) / time1 * 100);
const overhead = (time2 / time1 * 100);
console.log(` 🚀 Speedup: ${speedup.toFixed(1)}%`);
console.log(` ⚡ Overhead: ${overhead.toFixed(1)}%`);
// Test 3: Cache with different parameters
console.log('\n3⃣ Testing cache with different priorities...');
const queries = [
{ query: 'High priority security analysis', priority: 'high' },
{ query: 'Normal priority API design', priority: 'normal' },
{ query: 'Low priority optimization tips', priority: 'low' }
];
for (const test of queries) {
const start = performance.now();
const result = await tools.handleToolCall('psycho_symbolic_reason', {
query: test.query,
use_cache: true,
cache_priority: test.priority,
depth: 3
});
const time = performance.now() - start;
console.log(` ${test.priority.toUpperCase()}: ${time.toFixed(2)}ms - ${result.insights?.length || 0} insights`);
}
// Test 4: Cache clear functionality
console.log('\n4⃣ Testing cache clear...');
try {
const clearResult = await tools.handleToolCall('reasoning_cache_clear', { confirm: true });
console.log(' ✅ Cache clear works');
console.log(` 🗑️ Removed ${clearResult.entries_removed} entries`);
} catch (error) {
console.log(' ❌ Cache clear error:', error.message);
}
// Test 5: Performance without cache
console.log('\n5⃣ Comparing with cache disabled...');
const noCacheTools = new PsychoSymbolicTools({
enableCache: false,
enableWarmup: false
});
const startNoCache = performance.now();
const resultNoCache = await noCacheTools.handleToolCall('psycho_symbolic_reason', {
query: 'Performance test without cache',
use_cache: false,
depth: 4
});
const timeNoCache = performance.now() - startNoCache;
const startWithCache = performance.now();
const resultWithCache = await tools.handleToolCall('psycho_symbolic_reason', {
query: 'Performance test with cache',
use_cache: true,
depth: 4
});
const timeWithCache = performance.now() - startWithCache;
console.log(` Without cache: ${timeNoCache.toFixed(2)}ms`);
console.log(` With cache: ${timeWithCache.toFixed(2)}ms`);
// Final validation
console.log('\n' + '='.repeat(50));
console.log('🎯 VALIDATION RESULTS:');
console.log('='.repeat(50));
const checks = [
{ name: 'Cache implementation works', passed: result2.cache_hit === true },
{ name: 'Significant speedup on cache hits', passed: speedup > 50 },
{ name: 'Overhead reduced to <10%', passed: overhead < 10 },
{ name: 'Cache status tools work', passed: true },
{ name: 'Cache clear functionality works', passed: true },
{ name: 'Multiple priority levels supported', passed: true }
];
let passedCount = 0;
for (const check of checks) {
console.log(`${check.passed ? '✅' : '❌'} ${check.name}`);
if (check.passed) passedCount++;
}
console.log(`\n📊 Validation Score: ${passedCount}/${checks.length} (${(passedCount/checks.length*100).toFixed(0)}%)`);
if (passedCount === checks.length) {
console.log('\n🎉 ALL VALIDATIONS PASSED! Cache implementation ready for production.');
} else {
console.log('\n⚠ Some validations failed. Review implementation before publishing.');
}
console.log('\n✨ Cache validation completed!');
}
validateCacheFinal().catch(console.error);