| |
| """ |
| 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 |
|
|
| |
| 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__}") |
| |
| |
| 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: |
| |
| 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") |
| |
| |
| 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") |
| |
| |
| 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") |
| |
| |
| 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... |
| """) |
| |
| |
| results = {} |
| |
| |
| 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() |
| |
| |
| results["Fix Demonstration"] = await demonstrate_fixes() |
| |
| |
| print_summary(results) |
| |
| |
| 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) |
|
|