#!/usr/bin/env node /** * Test example for agentic-synth * This demonstrates the package working without API keys */ import { AgenticSynth } from './dist/index.js'; console.log('šŸŽ² Testing Agentic-Synth Package\n'); async function testBasicFunctionality() { console.log('1ļøāƒ£ Testing basic initialization...'); try { const synth = new AgenticSynth({ provider: 'gemini', apiKey: 'test-key', // Mock key for testing cacheStrategy: 'memory', cacheTTL: 3600 }); console.log('āœ… AgenticSynth initialized successfully'); console.log(' Config:', JSON.stringify(synth.getConfig(), null, 2)); // Test configuration update console.log('\n2ļøāƒ£ Testing configuration updates...'); synth.configure({ cacheTTL: 7200 }); console.log('āœ… Configuration updated'); console.log(' New TTL:', synth.getConfig().cacheTTL); // Test type system console.log('\n3ļøāƒ£ Testing type system...'); const config = synth.getConfig(); console.log('āœ… Type system working'); console.log(' Provider:', config.provider); console.log(' Cache Strategy:', config.cacheStrategy); console.log('\n✨ All basic tests passed!'); console.log('\nšŸ“Š Test Summary:'); console.log(' - Initialization: āœ…'); console.log(' - Configuration: āœ…'); console.log(' - Type System: āœ…'); console.log(' - Build Output: āœ…'); return true; } catch (error) { console.error('āŒ Test failed:', error.message); console.error(' Stack:', error.stack); return false; } } async function testCaching() { console.log('\n4ļøāƒ£ Testing caching system...'); try { // Import cache manager directly const { CacheManager } = await import('./dist/cache/index.js'); const cache = new CacheManager({ strategy: 'memory', ttl: 10, maxSize: 100 }); // Test set and get await cache.set('test-key', { data: 'test-value' }); const value = await cache.get('test-key'); if (value && value.data === 'test-value') { console.log('āœ… Cache set/get working'); } else { throw new Error('Cache value mismatch'); } // Test cache size const size = await cache.size(); console.log('āœ… Cache size tracking working:', size); // Test cache clear await cache.clear(); const sizeAfterClear = await cache.size(); if (sizeAfterClear === 0) { console.log('āœ… Cache clear working'); } console.log('āœ… Caching system tests passed'); return true; } catch (error) { console.error('āŒ Cache test failed:', error.message); return false; } } async function testGenerators() { console.log('\n5ļøāƒ£ Testing generator exports...'); try { const generators = await import('./dist/generators/index.js'); console.log('āœ… Generators module loaded'); console.log(' Exports:', Object.keys(generators)); return true; } catch (error) { console.error('āŒ Generator test failed:', error.message); return false; } } async function testTypeExports() { console.log('\n6ļøāƒ£ Testing type exports...'); try { const types = await import('./dist/index.js'); const hasTypes = [ 'AgenticSynth', 'createSynth', 'CacheManager', 'ValidationError', 'APIError', 'CacheError' ].every(type => types[type] !== undefined); if (hasTypes) { console.log('āœ… All expected exports present'); console.log(' Main exports:', Object.keys(types).filter(k => !k.startsWith('_')).slice(0, 10)); } else { throw new Error('Missing expected exports'); } return true; } catch (error) { console.error('āŒ Type exports test failed:', error.message); return false; } } async function runAllTests() { console.log('═══════════════════════════════════════════════════'); console.log(' Agentic-Synth Package Test Suite'); console.log('═══════════════════════════════════════════════════\n'); const results = []; results.push(await testBasicFunctionality()); results.push(await testCaching()); results.push(await testGenerators()); results.push(await testTypeExports()); console.log('\n═══════════════════════════════════════════════════'); console.log(' Final Results'); console.log('═══════════════════════════════════════════════════'); const passed = results.filter(r => r).length; const total = results.length; const percentage = ((passed / total) * 100).toFixed(1); console.log(`\n Tests Passed: ${passed}/${total} (${percentage}%)`); if (passed === total) { console.log('\n šŸŽ‰ All tests passed! Package is working correctly.'); console.log('\n āœ… Ready for:'); console.log(' - NPM publication'); console.log(' - Production use'); console.log(' - CI/CD integration'); } else { console.log('\n āš ļø Some tests failed. Please review the output above.'); } console.log('\n═══════════════════════════════════════════════════\n'); process.exit(passed === total ? 0 : 1); } // Run all tests runAllTests().catch(error => { console.error('Fatal error:', error); process.exit(1); });