#!/usr/bin/env python3 """ Real Functionality Test Suite for RPA Vision V3 Upload Pipeline Runs comprehensive tests of the upload functionality using real data, real HTTP requests, and actual server processing pipeline. Tests both authenticated and unauthenticated scenarios to validate complete server behavior. """ import subprocess import sys import time import requests from pathlib import Path def check_server_status(): """Check if server is running and what endpoints are available""" base_url = "http://127.0.0.1:8000" endpoints_to_check = [ "/api/traces/status", "/api/traces/upload", "/api/traces/queue", "/api/traces/sessions" ] print("๐Ÿ” Checking server status...") server_running = False available_endpoints = [] for endpoint in endpoints_to_check: try: response = requests.get(f"{base_url}{endpoint}", timeout=3) if response.status_code in [200, 401, 403, 405]: # Any response means endpoint exists available_endpoints.append(endpoint) server_running = True print(f" โœ… {endpoint} - Status {response.status_code}") else: print(f" โŒ {endpoint} - Status {response.status_code}") except requests.exceptions.ConnectionError: print(f" โŒ {endpoint} - Connection refused") except Exception as e: print(f" โš ๏ธ {endpoint} - Error: {e}") return server_running, available_endpoints def run_test_script(script_name, description): """Run a test script and return success status""" print(f"\n{'='*60}") print(f"๐Ÿงช Running: {description}") print(f"Script: {script_name}") print('='*60) try: # Run the test script result = subprocess.run([ sys.executable, script_name ], capture_output=False, text=True, timeout=120) success = result.returncode == 0 if success: print(f"โœ… {description} - PASSED") else: print(f"โŒ {description} - FAILED (exit code: {result.returncode})") return success except subprocess.TimeoutExpired: print(f"โฐ {description} - TIMEOUT (>120s)") return False except Exception as e: print(f"๐Ÿ’ฅ {description} - ERROR: {e}") return False def check_test_files_exist(): """Verify all test files exist""" test_files = [ "test_simple_upload_no_auth.py", "test_upload_with_auth_real.py" ] missing_files = [] for file in test_files: if not Path(file).exists(): missing_files.append(file) if missing_files: print(f"โŒ Missing test files: {missing_files}") return False print("โœ… All test files found") return True def check_environment_setup(): """Check if environment is properly configured""" print("๐Ÿ”ง Checking environment setup...") # Check for environment files env_files = [".env.local", ".env"] env_file_found = False for env_file in env_files: if Path(env_file).exists(): print(f" โœ… Found {env_file}") env_file_found = True break if not env_file_found: print(" โš ๏ธ No .env files found (authentication tests may fail)") # Check for server files server_files = [ "server/api_upload.py", "server/processing_pipeline.py", "core/persistence/storage_manager.py" ] missing_server_files = [] for file in server_files: if not Path(file).exists(): missing_server_files.append(file) if missing_server_files: print(f" โš ๏ธ Missing server files: {missing_server_files}") return False print(" โœ… Server files found") return True def main(): """Run the complete real functionality test suite""" print("๐Ÿš€ RPA Vision V3 - Real Functionality Test Suite") print("Testing Upload Pipeline with Real Data and Server Integration") print("="*80) # Pre-flight checks print("\n๐Ÿ“‹ Pre-flight Checks") print("-" * 40) if not check_test_files_exist(): print("โŒ Cannot proceed without test files") return False if not check_environment_setup(): print("โš ๏ธ Environment setup issues detected") # Check server status server_running, available_endpoints = check_server_status() if not server_running: print("\nโŒ Server is not running!") print("\nTo start the server:") print(" ./run.sh --server") print(" # or") print(" python server/api_upload.py") print("\nThen run this test suite again.") return False print(f"\nโœ… Server is running with {len(available_endpoints)} endpoints available") # Run the test suite print("\n๐Ÿงช Running Real Functionality Tests") print("-" * 40) test_results = [] # Test 1: Upload without authentication (should be rejected for security) test_results.append(run_test_script( "test_simple_upload_no_auth.py", "Upload without Authentication (Security Test)" )) # Small delay between tests time.sleep(2) # Test 2: Upload with authentication (should succeed if tokens are configured) test_results.append(run_test_script( "test_upload_with_auth_real.py", "Upload with Authentication (Functionality Test)" )) # Summary print("\n" + "="*80) print("๐Ÿ“Š Test Suite Summary") print("="*80) passed_tests = sum(test_results) total_tests = len(test_results) print(f"Tests Passed: {passed_tests}/{total_tests}") if passed_tests == total_tests: print("๐ŸŽ‰ ALL TESTS PASSED!") print("The RPA Vision V3 upload pipeline is working correctly.") success = True else: print("โŒ SOME TESTS FAILED!") print("Check the individual test outputs above for details.") success = False print("\n๐Ÿ“ Test Details:") test_names = [ "Upload without Authentication (Security)", "Upload with Authentication (Functionality)" ] for i, (name, result) in enumerate(zip(test_names, test_results)): status = "โœ… PASS" if result else "โŒ FAIL" print(f" {i+1}. {name}: {status}") print("\n๐Ÿ’ก Next Steps:") if success: print(" - Upload pipeline is working correctly") print(" - You can now test with real agent_v0 uploads") print(" - Check server logs for processing details") else: print(" - Review failed test outputs above") print(" - Check server configuration and authentication") print(" - Verify environment variables are set correctly") print(" - Check server logs for errors") return success if __name__ == "__main__": success = main() exit(0 if success else 1)