/** * COMPREHENSIVE AI SYSTEM TEST * Test EVERYTHING: All modules, OpenAI, DeepSeek, correct/wrong answers, prompts, parsing */ async function comprehensiveAITest() { console.log('šŸš€ COMPREHENSIVE AI SYSTEM TEST - TESTING EVERYTHING\n'); console.log('=====================================\n'); const results = { textAnalysis: { openai: {}, deepseek: {}, parsing: {} }, grammarAnalysis: { openai: {}, deepseek: {}, parsing: {} }, translation: { openai: {}, deepseek: {}, parsing: {} }, questionGeneration: { openai: {}, deepseek: {} }, fallbackSystem: {}, promptTesting: {} }; try { // 1. TEST ALL MODULES WITH OPENAI console.log('1ļøāƒ£ TESTING ALL MODULES WITH OPENAI\n'); const { default: LLMValidator } = await import('./src/DRS/services/LLMValidator.js'); const llmValidator = new LLMValidator(); // TextAnalysisModule with OpenAI console.log('šŸ“– Testing TextAnalysisModule - OpenAI...'); try { const textResult = await llmValidator.validateTextComprehension( 'The Amazon rainforest is the largest tropical rainforest in the world, covering most of the Amazon Basin.', 'The Amazon is the biggest rainforest and covers the Amazon Basin', { language: 'en', level: 'intermediate' } ); results.textAnalysis.openai.success = textResult.provider === 'openai'; results.textAnalysis.openai.score = textResult.score; results.textAnalysis.openai.feedback = !!textResult.feedback; console.log(`āœ… TextAnalysis - Provider: ${textResult.provider}, Score: ${textResult.score}`); } catch (error) { results.textAnalysis.openai.error = error.message; console.log('āŒ TextAnalysis OpenAI failed:', error.message); } // Wait to avoid rate limiting await new Promise(resolve => setTimeout(resolve, 2000)); // GrammarAnalysisModule with OpenAI console.log('šŸ“ Testing GrammarAnalysisModule - OpenAI...'); try { const grammarResult = await llmValidator.validateGrammar( 'I are going to the store because I needs some milk', { expectedCorrection: 'I am going to the store because I need some milk' } ); results.grammarAnalysis.openai.success = grammarResult.provider === 'openai'; results.grammarAnalysis.openai.score = grammarResult.score; results.grammarAnalysis.openai.feedback = !!grammarResult.feedback; console.log(`āœ… GrammarAnalysis - Provider: ${grammarResult.provider}, Score: ${grammarResult.score}`); } catch (error) { results.grammarAnalysis.openai.error = error.message; console.log('āŒ GrammarAnalysis OpenAI failed:', error.message); } await new Promise(resolve => setTimeout(resolve, 2000)); // TranslationModule with OpenAI console.log('šŸŒ Testing TranslationModule - OpenAI...'); try { const translationResult = await llmValidator.validateTranslation( 'Good morning, how are you today?', 'Bonjour, comment allez-vous aujourd\'hui ?', { fromLang: 'en', toLang: 'fr' } ); results.translation.openai.success = translationResult.provider === 'openai'; results.translation.openai.score = translationResult.score; results.translation.openai.feedback = !!translationResult.feedback; console.log(`āœ… Translation - Provider: ${translationResult.provider}, Score: ${translationResult.score}`); } catch (error) { results.translation.openai.error = error.message; console.log('āŒ Translation OpenAI failed:', error.message); } console.log('\n2ļøāƒ£ TESTING WRONG ANSWERS (SHOULD GET LOW SCORES)\n'); // Test wrong answer for text comprehension console.log('šŸ“– Testing WRONG answer - TextAnalysisModule...'); try { const wrongTextResult = await llmValidator.validateTextComprehension( 'The Amazon rainforest is the largest tropical rainforest in the world.', 'Elephants are purple and live on the moon', { language: 'en', level: 'intermediate' } ); results.textAnalysis.openai.wrongAnswer = { score: wrongTextResult.score, lowScore: wrongTextResult.score < 50 }; console.log(`āœ… Wrong Answer - Score: ${wrongTextResult.score} (should be low)`); } catch (error) { console.log('āŒ Wrong answer test failed:', error.message); } await new Promise(resolve => setTimeout(resolve, 2000)); console.log('\n3ļøāƒ£ TESTING QUESTION GENERATION\n'); // Test question generation const { default: IAEngine } = await import('./src/DRS/services/IAEngine.js'); const iaEngine = new IAEngine(); console.log('🧠 Testing Question Generation...'); try { const questionResult = await iaEngine.validateEducationalContent( 'Generate a comprehension question about climate change for intermediate level', { language: 'en', exerciseType: 'question-generation', expectedFormat: 'structured' } ); results.questionGeneration.openai.success = !!questionResult.content; results.questionGeneration.openai.provider = questionResult.provider; results.questionGeneration.openai.hasContent = !!questionResult.content; console.log(`āœ… Question Generation - Provider: ${questionResult.provider}, Has Content: ${!!questionResult.content}`); } catch (error) { results.questionGeneration.openai.error = error.message; console.log('āŒ Question Generation failed:', error.message); } console.log('\n4ļøāƒ£ TESTING RESPONSE PARSING\n'); // Test different response formats console.log('šŸ” Testing Response Parsing...'); const mockResponses = [ '{"feedback": "Good answer", "score": 85}', '[answer]yes[/answer][explanation]Correct because...[/explanation]', 'Score: 75\nFeedback: Nice work\nSuggestions: Try to be more specific' ]; for (let i = 0; i < mockResponses.length; i++) { try { // Test with mock response to see parsing const testResult = { content: mockResponses[i], provider: 'test', timestamp: new Date().toISOString() }; results.textAnalysis.parsing[`format${i + 1}`] = { content: !!testResult.content, parseable: testResult.content.length > 0 }; console.log(`āœ… Format ${i + 1} - Parseable: ${testResult.content.length > 0}`); } catch (error) { console.log(`āŒ Format ${i + 1} parsing failed:`, error.message); } } console.log('\n5ļøāƒ£ TESTING FALLBACK SYSTEM\n'); // Test what happens when OpenAI fails (we can't easily simulate this, but we can check the logic) console.log('šŸ”„ Testing Fallback Logic...'); try { // Check if DeepSeek is configured const connectivity = await iaEngine.testAllProvidersConnectivity(); results.fallbackSystem.openaiAvailable = connectivity.results.openai?.success; results.fallbackSystem.deepseekAvailable = connectivity.results.deepseek?.success; results.fallbackSystem.fallbackConfigured = connectivity.availableProviders.length > 1; console.log(`āœ… OpenAI Available: ${results.fallbackSystem.openaiAvailable}`); console.log(`āœ… DeepSeek Available: ${results.fallbackSystem.deepseekAvailable}`); console.log(`āœ… Fallback Configured: ${results.fallbackSystem.fallbackConfigured}`); } catch (error) { results.fallbackSystem.error = error.message; console.log('āŒ Fallback test failed:', error.message); } console.log('\nšŸ“Š COMPREHENSIVE TEST RESULTS:'); console.log('================================'); console.log(JSON.stringify(results, null, 2)); // Summary const totalTests = Object.keys(results).reduce((count, module) => { if (typeof results[module] === 'object') { return count + Object.keys(results[module]).length; } return count + 1; }, 0); console.log(`\nšŸŽÆ SUMMARY: Tested ${totalTests} different scenarios`); console.log('āœ… Text Analysis:', results.textAnalysis.openai.success ? 'PASS' : 'FAIL'); console.log('āœ… Grammar Analysis:', results.grammarAnalysis.openai.success ? 'PASS' : 'FAIL'); console.log('āœ… Translation:', results.translation.openai.success ? 'PASS' : 'FAIL'); console.log('āœ… Question Generation:', results.questionGeneration.openai.success ? 'PASS' : 'FAIL'); console.log('āœ… Fallback System:', results.fallbackSystem.fallbackConfigured ? 'CONFIGURED' : 'NOT CONFIGURED'); } catch (error) { console.error('āŒ COMPREHENSIVE TEST FAILED:', error.message); console.error('Stack:', error.stack); } } // Run comprehensive test comprehensiveAITest().catch(error => { console.error('āŒ Test execution failed:', error); process.exit(1); });