File size: 4,747 Bytes
e8293cd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/usr/bin/env python3
"""
Test script to verify the pipeline fixes work correctly
"""

import sys
import os
import traceback
from typing import Dict, Any

# Add the project root to the path
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))

def test_pipeline_fixes():
    """Test the pipeline with improved error handling"""
    
    print("πŸ§ͺ Testing Monster Generation Pipeline Fixes")
    print("=" * 50)
    
    try:
        # Import the pipeline
        from core.ai_pipeline import MonsterGenerationPipeline
        print("βœ… Successfully imported MonsterGenerationPipeline")
        
        # Initialize pipeline
        print("πŸ”§ Initializing pipeline...")
        pipeline = MonsterGenerationPipeline(device="cpu")  # Use CPU for testing
        print("βœ… Pipeline initialized successfully")
        
        # Test with a simple text input
        print("\nπŸš€ Testing monster generation...")
        test_input = "Create a friendly fire monster with wings"
        
        result = pipeline.generate_monster(
            text_input=test_input,
            user_id="test_user"
        )
        
        print(f"\nπŸ“Š Generation Result:")
        print(f"Status: {result.get('status', 'unknown')}")
        print(f"Success: {result.get('generation_log', {}).get('success', False)}")
        print(f"Stages completed: {result.get('generation_log', {}).get('stages_completed', [])}")
        print(f"Fallbacks used: {result.get('generation_log', {}).get('fallbacks_used', [])}")
        print(f"Errors: {result.get('generation_log', {}).get('errors', [])}")
        
        if result.get('traits'):
            print(f"Monster name: {result.get('traits', {}).get('name', 'Unknown')}")
            print(f"Monster element: {result.get('traits', {}).get('element', 'Unknown')}")
        
        if result.get('dialogue'):
            print(f"Monster dialogue: {result.get('dialogue', '')}")
        
        print(f"Download files: {result.get('download_files', [])}")
        
        # Clean up
        pipeline.cleanup()
        print("\n🧹 Pipeline cleaned up successfully")
        
        return True
        
    except Exception as e:
        print(f"❌ Test failed with error: {e}")
        print(f"Error type: {type(e).__name__}")
        print("Full traceback:")
        traceback.print_exc()
        return False

def test_fallback_manager():
    """Test the fallback manager"""
    
    print("\nπŸ§ͺ Testing Fallback Manager")
    print("=" * 30)
    
    try:
        from utils.fallbacks import FallbackManager
        
        fallback = FallbackManager()
        
        # Test text generation fallback
        print("πŸ“ Testing text generation fallback...")
        traits, dialogue = fallback.handle_text_gen_failure("Create a water monster")
        print(f"βœ… Generated traits: {traits.get('name', 'Unknown')}")
        print(f"βœ… Generated dialogue: {dialogue}")
        
        # Test image generation fallback
        print("🎨 Testing image generation fallback...")
        image = fallback.handle_image_gen_failure("Create a fire monster")
        print(f"βœ… Generated image: {type(image)}")
        
        # Test 3D generation fallback
        print("πŸ”² Testing 3D generation fallback...")
        model_3d = fallback.handle_3d_gen_failure(image)
        print(f"βœ… Generated 3D model: {type(model_3d)}")
        
        print("βœ… All fallback tests passed!")
        return True
        
    except Exception as e:
        print(f"❌ Fallback test failed: {e}")
        traceback.print_exc()
        return False

def main():
    """Main test function"""
    
    print("πŸ” Starting Pipeline Fix Verification")
    print("=" * 50)
    
    # Test fallback manager first (doesn't require heavy models)
    fallback_success = test_fallback_manager()
    
    # Test full pipeline (may fail due to missing models, but should show better error handling)
    pipeline_success = test_pipeline_fixes()
    
    print("\n" + "=" * 50)
    print("πŸ“‹ Test Results Summary:")
    print(f"Fallback Manager: {'βœ… PASSED' if fallback_success else '❌ FAILED'}")
    print(f"Pipeline: {'βœ… PASSED' if pipeline_success else '❌ FAILED'}")
    
    if fallback_success and pipeline_success:
        print("\nπŸŽ‰ All tests passed! Pipeline fixes are working correctly.")
    elif fallback_success:
        print("\n⚠️ Fallback manager works, but pipeline may need model dependencies.")
        print("This is expected if models aren't installed.")
    else:
        print("\n❌ Some tests failed. Check the error messages above.")
    
    return fallback_success and pipeline_success

if __name__ == "__main__":
    success = main()
    sys.exit(0 if success else 1)