/** * Manual installation and runtime test * Tests that the package works correctly when installed and run with environment variables */ import { AgenticSynth, createSynth } from '../dist/index.js'; console.log('๐Ÿงช Testing @ruvector/agentic-synth installation and runtime...\n'); // Test 1: Import validation console.log('โœ… Test 1: Module imports successful'); // Test 2: Environment variable detection console.log('\n๐Ÿ“‹ Test 2: Environment Variables'); console.log(' GEMINI_API_KEY:', process.env.GEMINI_API_KEY ? 'โœ“ Set' : 'โœ— Not set'); console.log(' OPENROUTER_API_KEY:', process.env.OPENROUTER_API_KEY ? 'โœ“ Set' : 'โœ— Not set'); // Test 3: Instance creation with default config console.log('\n๐Ÿ—๏ธ Test 3: Creating AgenticSynth instance with defaults'); try { const synth1 = new AgenticSynth(); console.log(' โœ“ Instance created successfully'); const config1 = synth1.getConfig(); console.log(' Provider:', config1.provider); console.log(' Model:', config1.model); console.log(' Enable Fallback:', config1.enableFallback); } catch (error) { console.error(' โœ— Failed:', error.message); process.exit(1); } // Test 4: Instance creation with custom config console.log('\n๐Ÿ”ง Test 4: Creating instance with custom config'); try { const synth2 = createSynth({ provider: 'openrouter', model: 'anthropic/claude-3.5-sonnet', enableFallback: false, cacheStrategy: 'memory', maxRetries: 5 }); console.log(' โœ“ Custom instance created successfully'); const config2 = synth2.getConfig(); console.log(' Provider:', config2.provider); console.log(' Model:', config2.model); console.log(' Enable Fallback:', config2.enableFallback); console.log(' Max Retries:', config2.maxRetries); } catch (error) { console.error(' โœ— Failed:', error.message); process.exit(1); } // Test 5: Validate config updates console.log('\n๐Ÿ”„ Test 5: Testing configuration updates'); try { const synth3 = new AgenticSynth({ provider: 'gemini' }); synth3.configure({ provider: 'openrouter', fallbackChain: ['gemini'] }); const config3 = synth3.getConfig(); console.log(' โœ“ Configuration updated successfully'); console.log(' New Provider:', config3.provider); } catch (error) { console.error(' โœ— Failed:', error.message); process.exit(1); } // Test 6: API key handling console.log('\n๐Ÿ”‘ Test 6: API Key Handling'); try { const synthWithKey = new AgenticSynth({ provider: 'gemini', apiKey: 'test-key-from-config' }); console.log(' โœ“ Config accepts apiKey parameter'); const synthFromEnv = new AgenticSynth({ provider: 'gemini' }); console.log(' โœ“ Falls back to environment variables when apiKey not provided'); } catch (error) { console.error(' โœ— Failed:', error.message); process.exit(1); } // Test 7: Error handling for missing schema console.log('\nโŒ Test 7: Error handling for missing required fields'); try { const synth4 = new AgenticSynth(); // This should fail validation await synth4.generateStructured({ count: 5 }); console.error(' โœ— Should have thrown error for missing schema'); process.exit(1); } catch (error) { if (error.message.includes('Schema is required')) { console.log(' โœ“ Correctly throws error for missing schema'); } else { console.error(' โœ— Unexpected error:', error.message); process.exit(1); } } // Test 8: Fallback chain configuration console.log('\n๐Ÿ”€ Test 8: Fallback chain configuration'); try { const synthNoFallback = new AgenticSynth({ provider: 'gemini', enableFallback: false }); console.log(' โœ“ Can disable fallbacks'); const synthCustomFallback = new AgenticSynth({ provider: 'gemini', fallbackChain: ['openrouter'] }); console.log(' โœ“ Can set custom fallback chain'); } catch (error) { console.error(' โœ— Failed:', error.message); process.exit(1); } console.log('\nโœ… All tests passed! Package is ready for installation and use.\n'); console.log('๐Ÿ“ฆ Installation Instructions:'); console.log(' npm install @ruvector/agentic-synth'); console.log('\n๐Ÿ”‘ Environment Setup:'); console.log(' export GEMINI_API_KEY="your-gemini-key"'); console.log(' export OPENROUTER_API_KEY="your-openrouter-key"'); console.log('\n๐Ÿš€ Usage:'); console.log(' import { AgenticSynth } from "@ruvector/agentic-synth";'); console.log(' const synth = new AgenticSynth({ provider: "gemini" });'); console.log(' const data = await synth.generateStructured({ schema: {...}, count: 10 });');