@simonecoelhosfo/optimizely-mcp-server
Version:
Optimizely MCP Server for AI assistants with integrated CLI tools
110 lines • 5 kB
JavaScript
/**
* Test Path Generation System
* Quick test to verify the complete path generation system works
*/
import { fieldsSchemaResolver } from './FieldsSchemaResolver.js';
import { recursivePathBuilder } from './RecursivePathBuilder.js';
import { createPathIndexGenerator } from './PathIndexGenerator.js';
// Create a mock database for testing
class MockDatabase {
async query(sql, params) {
// Return mock data based on the query
if (sql.includes('COUNT(*)')) {
return { rows: [{ count: 0 }] };
}
return { rows: [] };
}
async initialize() {
// No-op for mock
}
async close() {
// No-op for mock
}
}
async function testPathGeneration() {
console.log('Testing Path Generation System...\n');
try {
// 1. Test FieldsSchemaResolver
console.log('1. Testing FieldsSchemaResolver...');
await fieldsSchemaResolver.initialize();
const entityTypes = fieldsSchemaResolver.getAvailableEntityTypes();
console.log(`Found ${entityTypes.length} entity types`);
const flagPaths = await fieldsSchemaResolver.getQueryablePaths('flag');
console.log(`Found ${flagPaths.length} schema paths for flags\n`);
// 2. Test RecursivePathBuilder
console.log('2. Testing RecursivePathBuilder...');
// Create mock database
const database = new MockDatabase();
await database.initialize();
const pathBuilder = recursivePathBuilder(database);
// Mock some data for testing
const mockDb = database;
const originalQuery = mockDb.query.bind(mockDb);
mockDb.query = async (sql, params) => {
if (sql.includes('FROM flags')) {
return {
rows: [{
id: 1,
key: 'test_flag',
name: 'Test Flag',
data_json: {
id: 1,
key: 'test_flag',
name: 'Test Flag',
environments: {
production: { enabled: true },
staging: { enabled: false }
},
variable_definitions: {
discount: { type: 'double', default_value: '0.1' }
}
}
}]
};
}
return originalQuery(sql, params);
};
const analysisResult = await pathBuilder.analyzeEntity('flag', 10);
console.log(`Analyzed ${analysisResult.totalRecords} flag records`);
console.log(`Discovered ${analysisResult.discoveredPaths.length} database paths`);
console.log(`Complexity score: ${analysisResult.complexityScore}\n`);
// 3. Test PathIndexGenerator
console.log('3. Testing PathIndexGenerator...');
const indexGenerator = createPathIndexGenerator(database);
// Generate index for a single entity
const flagIndex = await indexGenerator.generateEntityIndex('flag');
console.log(`Generated flag index:`);
console.log(` - Total paths: ${flagIndex.totalPaths}`);
console.log(` - Schema paths: ${flagIndex.schemaPaths}`);
console.log(` - Database paths: ${flagIndex.databasePaths}`);
console.log(` - Coverage: ${flagIndex.statistics.coverage}%\n`);
// 4. Test path searching
console.log('4. Testing path search...');
const cdnPaths = await indexGenerator.searchPaths('enabled');
console.log(`Found ${cdnPaths.length} paths matching 'enabled':`);
cdnPaths.slice(0, 5).forEach(path => {
console.log(` - ${path.fullPath} (${path.entityType})`);
});
console.log('');
// 5. Generate statistics summary
console.log('5. Generating statistics summary...');
const summary = await indexGenerator.getStatisticsSummary();
console.log('Statistics Summary:');
console.log(` - Total entities: ${summary.totalEntities}`);
console.log(` - Total paths: ${summary.totalPaths}`);
console.log(` - Average coverage: ${summary.averageCoverage}%`);
console.log(` - High coverage entities: ${summary.entitiesWithHighCoverage.join(', ') || 'none'}`);
console.log(` - Low coverage entities: ${summary.entitiesWithLowCoverage.join(', ') || 'none'}`);
console.log(` - Most complex entities: ${summary.mostComplexEntities.join(', ')}`);
console.log('\nAll tests passed!');
// Close database
await database.close();
}
catch (error) {
console.error('Test failed:', error);
process.exit(1);
}
}
// Run the test
testPathGeneration().catch(console.error);
//# sourceMappingURL=test-path-generation.js.map