#!/bin/bash # Script to test the Visual AI QC system before deployment set -e # Exit on any error echo "===========================================" echo " Visual AI QC - System Testing" echo "===========================================" # Get the script directory and app root SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" APP_DIR="$(dirname "$SCRIPT_DIR")" echo "Testing directory: $APP_DIR" # Change to app directory cd "$APP_DIR" # Determine Python command if command -v python3 &> /dev/null; then PYTHON_CMD=python3 elif command -v python &> /dev/null; then PYTHON_CMD=python else echo "ERROR: Python not found!" exit 1 fi echo "Using Python: $PYTHON_CMD" # Test 1: Python syntax check echo "" echo "Test 1: Python syntax validation" echo "================================" find . -name "*.py" -not -path "./venv/*" | while read -r file; do echo "Checking: $file" $PYTHON_CMD -m py_compile "$file" || { echo "ERROR: Syntax error in $file" exit 1 } done echo "✅ All Python files have valid syntax" # Test 2: Core module imports echo "" echo "Test 2: Core module imports" echo "==========================" $PYTHON_CMD -c " try: import api_server import llm_config import profile_config import jwt_validator import auth_middleware print('✅ All core modules imported successfully') except Exception as e: print(f'ERROR: Core module import failed: {e}') exit(1) " # Test 3: Profile system validation echo "" echo "Test 3: Profile system validation" echo "=================================" $PYTHON_CMD -c " from profile_config import get_profile profiles = ['general_check', 'unilever_key_visual', 'unilever_packaging', 'diageo_key_visual', 'diageo_packaging', 'inclusive_accessibility'] for p in profiles: try: profile = get_profile(p) enabled_checks = profile.get_enabled_checks() print(f'✅ {profile.name} ({len(enabled_checks)} checks)') except Exception as e: print(f'ERROR: Profile {p} failed to load: {e}') exit(1) " # Test 4: QC module validation echo "" echo "Test 4: QC module validation" echo "============================" $PYTHON_CMD -c " import os import importlib.util import sys qc_apps_dir = 'visual_qc_apps' error_count = 0 for item in os.listdir(qc_apps_dir): item_path = os.path.join(qc_apps_dir, item) if os.path.isdir(item_path) and not item.startswith('__'): app_file = os.path.join(item_path, 'app.py') if os.path.exists(app_file): try: spec = importlib.util.spec_from_file_location(f'{item}.app', app_file) module = importlib.util.module_from_spec(spec) spec.loader.exec_module(module) print(f'✅ {item}/app.py') except Exception as e: print(f'ERROR: {item}/app.py - {e}') error_count += 1 if error_count > 0: print(f'ERROR: {error_count} QC modules failed to load') sys.exit(1) else: print(f'✅ All QC modules loaded successfully') " # Test 5: Configuration validation echo "" echo "Test 5: Configuration validation" echo "===============================" if [ ! -f "config.env" ] && [ ! -f "config/production.env" ] && [ ! -f "config/development.env" ]; then echo "ERROR: No configuration files found!" exit 1 fi # Check for required environment variables $PYTHON_CMD -c " import os from dotenv import load_dotenv # Try to load any available config if os.path.exists('config/development.env'): load_dotenv('config/development.env') elif os.path.exists('config/production.env'): load_dotenv('config/production.env') elif os.path.exists('config.env'): load_dotenv('config.env') required_vars = ['OPENAI_API_KEY', 'GOOGLE_API_KEY', 'AZURE_TENANT_ID', 'AZURE_CLIENT_ID'] missing_vars = [] for var in required_vars: if not os.environ.get(var): missing_vars.append(var) if missing_vars: print(f'ERROR: Missing required environment variables: {missing_vars}') exit(1) else: print('✅ All required environment variables are set') " # Test 6: Brand guidelines database echo "" echo "Test 6: Brand guidelines database" echo "================================" $PYTHON_CMD -c " try: from brand_guidelines_db import BrandGuidelinesDB brand_db = BrandGuidelinesDB() brands = brand_db.get_all_brands() print(f'✅ Brand guidelines database loaded ({len(brands)} brands)') except Exception as e: print(f'ERROR: Brand guidelines database failed: {e}') exit(1) " # Final summary echo "" echo "===========================================" echo "🎉 ALL TESTS PASSED!" echo "The system is ready for deployment." echo "==========================================="