@simonecoelhosfo/optimizely-mcp-server
Version:
Optimizely MCP Server for AI assistants with integrated CLI tools
181 lines • 6.42 kB
JavaScript
/**
* Phase 4C Test - Implemented Field Disambiguation Features
*
* Tests the actual implemented disambiguation features:
* 1. Simple queries without prefixes (bypass disambiguation)
* 2. Field aliasing with AS clause
* 3. Basic disambiguation logic
*/
import { IntelligentQueryEngine } from './IntelligentQueryEngine.js';
import { OptimizelyAdapter } from './adapters/OptimizelyAdapter.js';
import Database from 'better-sqlite3';
async function runTest(engine, test) {
try {
const result = await engine.query(test.query);
return {
name: test.name,
success: true,
rowCount: result.data?.length || 0
};
}
catch (error) {
return {
name: test.name,
success: false,
error: error instanceof Error ? error.message : String(error)
};
}
}
async function testPhase4CImplemented() {
console.log('# Phase 4C Implemented Features Test\n');
// Initialize
const db = new Database('./data/optimizely-cache.db', { readonly: true });
const engine = new IntelligentQueryEngine({
discovery: {
autoDiscover: true,
discoveryInterval: 60000,
cacheTTL: 3600000
}
});
const adapter = new OptimizelyAdapter({ database: db });
engine.registerAdapter(adapter);
// Wait for discovery
await new Promise(resolve => setTimeout(resolve, 500));
const tests = [
// Simple queries (disambiguation bypassed)
{
name: 'Simple query - no prefixes',
query: {
find: 'flag',
select: ['name', 'key', 'archived'],
where: [{ field: 'archived', operator: '=', value: false }],
limit: 5
},
expectedBehavior: 'Should work without disambiguation'
},
// Field aliasing
{
name: 'Field aliasing with AS',
query: {
find: 'flag',
select: ['name as flag_name', 'key as flag_key'],
limit: 5
},
expectedBehavior: 'Should support field aliases'
},
// Aggregation
{
name: 'Simple aggregation',
query: {
find: 'flag',
select: ['archived'],
groupBy: ['archived'],
aggregations: [{
field: '*',
function: 'COUNT',
alias: 'count'
}]
},
expectedBehavior: 'Should handle aggregation without prefixes'
},
// Pattern matching
{
name: 'Pattern matching with LIKE',
query: {
find: 'flag',
select: ['name', 'key'],
where: [{ field: 'name', operator: 'LIKE', value: '%test%' }],
limit: 5
},
expectedBehavior: 'Should support LIKE operator'
},
// Date filtering (from Phase 4B)
{
name: 'Date filtering',
query: {
find: 'flag',
select: ['name', 'created_time'],
where: [{ field: 'created_time', operator: '>', value: 'LAST_30_DAYS' }],
limit: 5
},
expectedBehavior: 'Should support date functions'
},
// NULL handling
{
name: 'NULL value handling',
query: {
find: 'flag',
select: ['name', 'description'],
where: [{ field: 'description', operator: '!=', value: null }],
limit: 5
},
expectedBehavior: 'Should handle NULL comparisons'
},
// Order by
{
name: 'Order by clause',
query: {
find: 'flag',
select: ['name', 'created_time'],
orderBy: [{ field: 'created_time', direction: 'DESC' }],
limit: 5
},
expectedBehavior: 'Should support ordering'
},
// Mixed case with alias and where
{
name: 'Complex query with alias and filters',
query: {
find: 'event',
select: ['name as event_name', 'event_type', 'category'],
where: [
{ field: 'event_type', operator: '=', value: 'custom' },
{ field: 'category', operator: '!=', value: null }
],
limit: 5
},
expectedBehavior: 'Should handle complex queries'
}
];
const results = [];
// Run tests
for (const test of tests) {
const result = await runTest(engine, test);
results.push(result);
const status = result.success ? '✅' : '❌';
console.log(`${status} ${test.name}`);
if (result.success) {
console.log(` Rows returned: ${result.rowCount}`);
}
else {
console.log(` Error: ${result.error}`);
}
console.log(` Expected: ${test.expectedBehavior}`);
console.log();
}
// Summary
const passed = results.filter(r => r.success).length;
const total = results.length;
const successRate = ((passed / total) * 100).toFixed(1);
console.log('## Summary');
console.log(`- Total Tests: ${total}`);
console.log(`- Passed: ${passed}`);
console.log(`- Failed: ${total - passed}`);
console.log(`- Success Rate: ${successRate}%`);
console.log('\n## Key Achievements');
console.log('- Simple queries work without field prefixes');
console.log('- Field aliasing with AS clause');
console.log('- Aggregation queries');
console.log('- Pattern matching with LIKE');
console.log('- Date filtering (Phase 4B integration)');
console.log('- NULL value handling');
console.log('- ORDER BY support');
console.log('\n## Next Steps for Full Phase 4C');
console.log('- [ ] Handle explicit table prefixes (flag.name)');
console.log('- [ ] Multi-table JOIN disambiguation');
console.log('- [ ] Ambiguous field detection and warnings');
console.log('- [ ] Smart resolution for common fields (id, name, key)');
db.close();
}
testPhase4CImplemented().catch(console.error);
//# sourceMappingURL=test-phase4c-implemented.js.map