/ laxyfile / test_integration_simple.py
swadhin biswas redy to jump in work Β· 7/25/2025
d8c49a5
137 lines Β· 4.8 KB
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
133
134
135
136
137
#!/usr/bin/env python3
"""
Simple integration test to validate component integration
"""

import asyncio
import tempfile
from pathlib import Path

# Add the current directory to Python path
import sys
sys.path.insert(0, '.')

from laxyfile.core.config import Config
from laxyfile.integration.component_integration import ComponentIntegrator


async def test_basic_integration():
    """Test basic component integration"""
    print("πŸ§ͺ Testing LaxyFile Component Integration...")

    # Create temporary config directory
    with tempfile.TemporaryDirectory() as temp_dir:
        config_dir = Path(temp_dir)

        # Create test configuration
        config = Config(config_dir=config_dir)
        config.data.update({
            'logging': {
                'console': {'enabled': True, 'level': 'INFO'},
                'file': {'enabled': False},
                'performance': {'enabled': False},
                'error': {'enabled': False}
            },
            'ai': {'enabled': False},  # Disable AI for basic test
            'plugins': {'enabled': False}  # Disable plugins for basic test
        })

        # Create integrator
        integrator = ComponentIntegrator(config)

        try:
            print("  βœ… Created component integrator")

            # Initialize components
            print("  πŸ”„ Initializing components...")
            success = await integrator.initialize_all_components()

            if not success:
                print("  ❌ Component initialization failed")
                return False

            print("  βœ… All components initialized successfully")

            # Check component health
            print("  πŸ”„ Checking component health...")
            is_healthy = integrator.is_healthy()

            if not is_healthy:
                print("  ⚠️  Some components are unhealthy")
                # Print status for debugging
                for name, status in integrator.get_all_component_status().items():
                    health_status = "βœ…" if status.healthy else "❌"
                    print(f"    {health_status} {name}: {'healthy' if status.healthy else 'unhealthy'}")
            else:
                print("  βœ… All components are healthy")

            # Test component interactions
            print("  πŸ”„ Testing component interactions...")
            test_results = await integrator.test_component_interactions()

            passed_tests = sum(1 for result in test_results.values() if result is True)
            total_tests = len(test_results)

            print(f"  πŸ“Š Interaction tests: {passed_tests}/{total_tests} passed")

            for test_name, result in test_results.items():
                status = "βœ…" if result else "❌"
                print(f"    {status} {test_name}")

            # Test basic functionality
            print("  πŸ”„ Testing basic functionality...")

            # Test file manager
            file_manager = integrator.get_component('file_manager')
            if file_manager:
                current_dir = Path.cwd()
                files = await file_manager.list_directory(current_dir)
                print(f"    βœ… File manager: Listed {len(files)} files in current directory")
            else:
                print("    ❌ File manager not available")

            # Test preview system
            preview_system = integrator.get_component('preview_system')
            if preview_system:
                # Try to preview this test file
                test_file = Path(__file__)
                preview = await preview_system.generate_preview(test_file)
                if preview:
                    print(f"    βœ… Preview system: Generated preview for {test_file.name}")
                else:
                    print(f"    ⚠️  Preview system: No preview generated for {test_file.name}")
            else:
                print("    ❌ Preview system not available")

            print("  βœ… Basic functionality tests completed")

            # Get final statistics
            if hasattr(integrator, 'startup_time'):
                print(f"  πŸ“ˆ Startup time: {integrator.startup_time:.2f}s")

            print("πŸŽ‰ Integration test completed successfully!")
            return True

        except Exception as e:
            print(f"  ❌ Integration test failed: {e}")
            import traceback
            traceback.print_exc()
            return False

        finally:
            # Cleanup
            print("  🧹 Cleaning up...")
            await integrator.shutdown()
            print("  βœ… Cleanup completed")


async def main():
    """Run the integration test"""
    success = await test_basic_integration()
    if not success:
        sys.exit(1)
    print("\n✨ All tests passed! LaxyFile component integration is working correctly.")


if __name__ == "__main__":
    asyncio.run(main())