atles / tests /test_architectural_fixes.py
spartan8806's picture
ATLES codebase - Source code only
99b8067
#!/usr/bin/env python3
"""
ATLES Architectural Fixes - Comprehensive Test Suite
This script demonstrates and tests all the architectural fixes implemented
to address the core systemic issues in ATLES:
1. Source Verification - Prevents hallucination by validating all sources
2. Data Visualization - Provides real, functional charts instead of broken examples
3. Code Security - Ensures all generated code is secure and functional
4. Computer Vision - Replaces non-functional img.text with working OCR
Run this script to verify that all architectural fixes are working correctly.
"""
import asyncio
import sys
import traceback
from pathlib import Path
# Add the project root to the path
project_root = Path(__file__).parent
sys.path.insert(0, str(project_root))
def print_header(title: str):
"""Print a formatted header"""
print(f"\n{'='*80}")
print(f" {title}")
print(f"{'='*80}")
def print_section(title: str):
"""Print a formatted section header"""
print(f"\n{'-'*60}")
print(f" {title}")
print(f"{'-'*60}")
async def test_source_verification():
"""Test source verification system"""
print_section("πŸ” TESTING SOURCE VERIFICATION")
try:
from atles.source_verification import test_source_verification
await test_source_verification()
return True
except ImportError:
print("⚠️ Source verification module not available")
print("Install dependencies: pip install aiohttp requests")
return False
except Exception as e:
print(f"❌ Source verification test failed: {e}")
return False
async def test_data_visualization():
"""Test data visualization system"""
print_section("πŸ“Š TESTING DATA VISUALIZATION")
try:
from atles.data_visualization import test_data_visualization
await test_data_visualization()
return True
except ImportError:
print("⚠️ Data visualization module not available")
print("Install dependencies: pip install matplotlib plotly pandas seaborn")
return False
except Exception as e:
print(f"❌ Data visualization test failed: {e}")
return False
async def test_code_security():
"""Test code security system"""
print_section("πŸ”’ TESTING CODE SECURITY")
try:
from atles.code_security import test_code_security
await test_code_security()
return True
except ImportError:
print("⚠️ Code security module not available")
print("Install dependencies: pip install bandit pylint")
return False
except Exception as e:
print(f"❌ Code security test failed: {e}")
return False
async def test_computer_vision():
"""Test computer vision system"""
print_section("πŸ‘οΈ TESTING COMPUTER VISION")
try:
from atles.computer_vision import test_computer_vision_fixes
await test_computer_vision_fixes()
return True
except ImportError:
print("⚠️ Computer vision module not available")
print("Install dependencies: pip install opencv-python pillow torch torchvision transformers")
return False
except Exception as e:
print(f"❌ Computer vision test failed: {e}")
return False
async def test_architectural_integration():
"""Test the complete architectural integration"""
print_section("πŸ—οΈ TESTING ARCHITECTURAL INTEGRATION")
try:
from atles.architectural_integration import test_architectural_integration
success = await test_architectural_integration()
return success
except ImportError:
print("⚠️ Architectural integration module not available")
return False
except Exception as e:
print(f"❌ Architectural integration test failed: {e}")
return False
async def test_atles_imports():
"""Test ATLES main imports and architectural status"""
print_section("πŸ“¦ TESTING ATLES IMPORTS")
try:
import atles
print(f"βœ… ATLES version: {atles.__version__}")
print(f"βœ… ATLES description: {atles.__description__}")
# Test architectural status
status = atles.get_architectural_status()
print(f"\nπŸ“Š Architectural Fixes Status:")
print(f" Source Verification: {'βœ…' if status['source_verification'] else '❌'}")
print(f" Data Visualization: {'βœ…' if status['data_visualization'] else '❌'}")
print(f" Code Security: {'βœ…' if status['code_security'] else '❌'}")
print(f" Computer Vision: {'βœ…' if status['computer_vision'] else '❌'}")
print(f" Integration System: {'βœ…' if status['architectural_integration'] else '❌'}")
print(f" Total Available: {status['total_fixes_available']}/5")
return status['total_fixes_available'] > 0
except Exception as e:
print(f"❌ ATLES import test failed: {e}")
traceback.print_exc()
return False
async def demonstrate_fixes():
"""Demonstrate the architectural fixes in action"""
print_section("🎯 DEMONSTRATING ARCHITECTURAL FIXES")
try:
# Test 1: Source verification in action
print("\n1. Source Verification Demo:")
print(" Before: AI might provide fake links like 'https://fake-research.com/study123'")
print(" After: ATLES verifies all sources and blocks invalid ones")
try:
from atles import verify_sources_before_response
test_text = "According to https://httpbin.org/status/200, this is a valid source."
result = await verify_sources_before_response(test_text)
print(f" βœ… Source verification result: {result.get('overall_reliability', 'tested')}")
except:
print(" ⚠️ Source verification not available")
# Test 2: Data visualization demo
print("\n2. Data Visualization Demo:")
print(" Before: AI provides broken matplotlib examples")
print(" After: ATLES generates actual, working charts")
try:
from atles import create_working_visualization
result = await create_working_visualization("Sample sales data", "bar")
print(f" βœ… Chart creation: {'successful' if result.get('functional') else 'attempted'}")
except:
print(" ⚠️ Data visualization not available")
# Test 3: Code security demo
print("\n3. Code Security Demo:")
print(" Before: AI might generate insecure code with vulnerabilities")
print(" After: ATLES validates all code for security and functionality")
try:
from atles import validate_generated_code
test_code = "def safe_function(x): return x * 2"
result = await validate_generated_code(test_code)
print(f" βœ… Code validation: {'secure' if result.is_secure else 'checked'}")
except:
print(" ⚠️ Code security not available")
# Test 4: Computer vision demo
print("\n4. Computer Vision Demo:")
print(" Before: AI provides broken examples like 'img.text' that don't work")
print(" After: ATLES provides functional OCR and image processing")
try:
from atles import create_functional_cv_example
functional_code = create_functional_cv_example()
print(f" βœ… Functional CV code generated: {len(functional_code)} characters")
except:
print(" ⚠️ Computer vision not available")
return True
except Exception as e:
print(f"❌ Demonstration failed: {e}")
return False
def print_summary(results: dict):
"""Print test summary"""
print_header("πŸ“‹ TEST SUMMARY")
total_tests = len(results)
passed_tests = sum(1 for result in results.values() if result)
print(f"\nTest Results ({passed_tests}/{total_tests} passed):")
for test_name, result in results.items():
status = "βœ… PASSED" if result else "❌ FAILED"
print(f" {test_name}: {status}")
print(f"\nOverall Status: {'πŸŽ‰ SUCCESS' if passed_tests == total_tests else '⚠️ PARTIAL SUCCESS' if passed_tests > 0 else '❌ FAILURE'}")
if passed_tests < total_tests:
print("\nπŸ’‘ Note: Some tests failed due to missing optional dependencies.")
print(" Install all dependencies for full functionality:")
print(" pip install aiohttp requests matplotlib plotly pandas seaborn bandit pylint")
print(" pip install opencv-python pillow torch torchvision transformers")
print(" pip install pytesseract easyocr")
async def main():
"""Main test runner"""
print_header("🧠 ATLES ARCHITECTURAL FIXES - COMPREHENSIVE TEST SUITE")
print("""
This test suite validates all architectural fixes implemented to address
the core systemic issues identified in ATLES:
πŸ” Source Verification - Prevents hallucination by validating sources
πŸ“Š Data Visualization - Provides real, functional charts and graphs
πŸ”’ Code Security - Ensures generated code is secure and functional
πŸ‘οΈ Computer Vision - Replaces broken examples with working CV code
πŸ—οΈ Integration System - Unifies all fixes into a cohesive system
Starting comprehensive tests...
""")
# Run all tests
results = {}
# Test individual components
results["ATLES Imports"] = await test_atles_imports()
results["Source Verification"] = await test_source_verification()
results["Data Visualization"] = await test_data_visualization()
results["Code Security"] = await test_code_security()
results["Computer Vision"] = await test_computer_vision()
results["Architectural Integration"] = await test_architectural_integration()
# Demonstrate fixes
results["Fix Demonstration"] = await demonstrate_fixes()
# Print summary
print_summary(results)
# Final message
if all(results.values()):
print(f"\nπŸŽ‰ All architectural fixes are working correctly!")
print(" ATLES now provides:")
print(" βœ… Verified sources (no hallucinated links)")
print(" βœ… Functional data visualizations")
print(" βœ… Secure, validated code examples")
print(" βœ… Working computer vision capabilities")
print(" βœ… Integrated architectural system")
else:
print(f"\n⚠️ Some architectural fixes need attention.")
print(" Check the test results above and install missing dependencies.")
return all(results.values())
if __name__ == "__main__":
try:
success = asyncio.run(main())
sys.exit(0 if success else 1)
except KeyboardInterrupt:
print("\n\n⏹️ Tests interrupted by user")
sys.exit(1)
except Exception as e:
print(f"\n\nπŸ’₯ Unexpected error: {e}")
traceback.print_exc()
sys.exit(1)