@simonecoelhosfo/optimizely-mcp-server
Version:
Optimizely MCP Server for AI assistants with integrated CLI tools
189 lines • 6.87 kB
JavaScript
/**
* Regression Test Suite - Ensure JSON fixes didn't break existing functionality
*/
import { IntelligentQueryEngine } from './IntelligentQueryEngine.js';
import { OptimizelyAdapter } from './adapters/OptimizelyAdapter.js';
import Database from 'better-sqlite3';
async function runTest(engine, test) {
const startTime = Date.now();
try {
const result = await engine.query(test.query);
return {
name: test.name,
success: true,
sql: undefined, // SQL not available in metadata
executionTime: Date.now() - startTime
};
}
catch (error) {
return {
name: test.name,
success: false,
error: error instanceof Error ? error.message : String(error),
executionTime: Date.now() - startTime
};
}
}
async function runRegressionTests() {
console.log('# Regression Test Suite - Post JSON Fix Validation\n');
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);
await new Promise(resolve => setTimeout(resolve, 500));
const tests = [
{
category: 'Basic Aggregations',
tests: [
{
name: 'COUNT(*) aggregation',
query: {
find: 'flag',
select: ['archived', 'COUNT(*) as total'],
groupBy: ['archived']
},
description: 'Basic COUNT aggregation'
},
{
name: 'Multiple aggregations',
query: {
find: 'experiment',
select: ['status', 'COUNT(*) as count', 'MAX(created_time) as latest'],
groupBy: ['status']
},
description: 'COUNT and MAX together'
}
]
},
{
category: 'Date Functions',
tests: [
{
name: 'Date function in WHERE',
query: {
find: 'flag',
select: ['name', 'created_time'],
where: [{ field: 'created_time', operator: '>', value: 'LAST_30_DAYS' }],
limit: 5
},
description: 'Relative date filtering'
},
{
name: 'STRFTIME in SELECT',
query: {
find: 'experiment',
select: ['name', "STRFTIME('%Y-%m', created_time) as month"],
limit: 5
},
description: 'SQLite date formatting'
}
]
},
{
category: 'String Functions',
tests: [
{
name: 'UPPER function',
query: {
find: 'flag',
select: ['key', 'UPPER(name) as name_upper'],
limit: 3
},
description: 'String transformation'
},
{
name: 'LENGTH function',
query: {
find: 'audience',
select: ['name', 'LENGTH(conditions) as condition_length'],
where: [{ field: 'archived', operator: '=', value: false }],
limit: 3
},
description: 'String length calculation'
}
]
},
{
category: 'Complex Expressions',
tests: [
{
name: 'COALESCE function',
query: {
find: 'experiment',
select: ['name', "COALESCE(description, 'No description') as desc"],
limit: 3
},
description: 'Null handling with COALESCE'
},
{
name: 'CASE expression',
query: {
find: 'flag',
select: [
'name',
"CASE WHEN archived = 1 THEN 'Archived' ELSE 'Active' END as status"
],
limit: 5
},
description: 'Conditional logic'
}
]
},
{
category: 'Mixed JSON and Regular Functions',
tests: [
{
name: 'JSON and COUNT together',
query: {
find: 'flag',
select: [
'COUNT(*) as total',
'JSON_ARRAY_LENGTH($.variations) as avg_variations'
],
where: [{ field: 'archived', operator: '=', value: false }],
limit: 1
},
description: 'Mixing JSON and regular aggregations'
}
]
}
];
const results = [];
for (const category of tests) {
console.log(`\n## ${category.category}\n`);
for (const test of category.tests) {
const result = await runTest(engine, test);
results.push(result);
const status = result.success ? '✅' : '❌';
console.log(`${status} ${test.name}`);
console.log(` ${test.description}`);
if (!result.success) {
console.log(` Error: ${result.error}`);
}
console.log(` Time: ${result.executionTime}ms\n`);
}
}
const passed = results.filter(r => r.success).length;
const total = results.length;
const successRate = ((passed / total) * 100).toFixed(1);
console.log('\n## Summary');
console.log(`- Total Tests: ${total}`);
console.log(`- Passed: ${passed}`);
console.log(`- Failed: ${total - passed}`);
console.log(`- Success Rate: ${successRate}%`);
if (passed === total) {
console.log('\nNO REGRESSIONS DETECTED - All existing functionality intact!');
}
else {
console.log('\nREGRESSION DETECTED - Some functionality broken!');
}
db.close();
}
runRegressionTests().catch(console.error);
//# sourceMappingURL=test-regression-check.js.map