#!/bin/bash # Comprehensive Test Suite Runner for Foxhunt HFT System # Implements TDD test pyramid with coverage enforcement set -e echo "==================================================" echo " Foxhunt HFT System - Comprehensive Test Suite" echo "==================================================" echo "" # Color codes for output GREEN='\033[0;32m' YELLOW='\033[1;33m' RED='\033[0;31m' NC='\033[0m' # No Color # Test counters TOTAL_TESTS=0 PASSED_TESTS=0 FAILED_TESTS=0 # Function to print colored output print_status() { local status=$1 local message=$2 if [ "$status" = "PASS" ]; then echo -e "${GREEN}✅ $message${NC}" elif [ "$status" = "FAIL" ]; then echo -e "${RED}❌ $message${NC}" elif [ "$status" = "INFO" ]; then echo -e "${YELLOW}ℹ️ $message${NC}" fi } # Function to run test category run_test_category() { local category=$1 local command=$2 echo "" echo "────────────────────────────────────────────────" echo " Running: $category" echo "────────────────────────────────────────────────" if eval "$command"; then print_status "PASS" "$category completed successfully" PASSED_TESTS=$((PASSED_TESTS + 1)) return 0 else print_status "FAIL" "$category failed" FAILED_TESTS=$((FAILED_TESTS + 1)) return 1 fi } # 1. Unit Tests (30-40% of pyramid) echo "" echo "📊 LEVEL 1: Unit Tests (Library Code)" echo "──────────────────────────────────────" run_test_category "Unit Tests - ML Package" \ "cargo test -p ml --lib --no-fail-fast 2>&1 | tail -20" run_test_category "Unit Tests - Trading Engine" \ "cargo test -p trading_engine --lib --no-fail-fast 2>&1 | tail -20" run_test_category "Unit Tests - Risk Management" \ "cargo test -p risk --lib --no-fail-fast 2>&1 | tail -20" run_test_category "Unit Tests - Data Providers" \ "cargo test -p data --lib --no-fail-fast 2>&1 | tail -20" run_test_category "Unit Tests - Common" \ "cargo test -p common --lib --no-fail-fast 2>&1 | tail -20" # 2. Component Tests (40-50% of pyramid) echo "" echo "📊 LEVEL 2: Component Tests" echo "────────────────────────────────────" run_test_category "Streaming Pipeline Tests" \ "cargo test -p ml --test streaming_pipeline_edge_cases --no-fail-fast 2>&1 | tail -20" || true run_test_category "Ensemble Disagreement Tests" \ "cargo test -p ml --test ensemble_disagreement_tests --no-fail-fast 2>&1 | tail -20" || true run_test_category "Training Chaos Tests" \ "cargo test -p ml --test training_chaos_tests --no-fail-fast 2>&1 | tail -20" || true run_test_category "Multi-Day Training Simulation" \ "cargo test -p ml --test multi_day_training_simulation --no-fail-fast 2>&1 | tail -20" || true run_test_category "Adaptive Strategy Tests" \ "cargo test -p adaptive-strategy --test '*' --no-fail-fast 2>&1 | tail -20" # 3. Integration Tests (20-30% of pyramid) echo "" echo "📊 LEVEL 3: Integration Tests" echo "──────────────────────────────────" run_test_category "E2E Ensemble Integration" \ "cargo test -p ml --test e2e_ensemble_integration --no-fail-fast 2>&1 | tail -20" run_test_category "Pipeline Integration" \ "cargo test -p ml --test pipeline_integration_tests --no-fail-fast 2>&1 | tail -20" run_test_category "Database Integration" \ "cargo test -p database --test '*' --no-fail-fast 2>&1 | tail -20" # 4. E2E Tests (5-10% of pyramid) echo "" echo "📊 LEVEL 4: End-to-End Tests" echo "────────────────────────────────" run_test_category "Smoke Tests" \ "cargo test -p foxhunt --test smoke_tests --no-fail-fast 2>&1 | tail -20" # 5. Coverage Report echo "" echo "📊 Coverage Analysis" echo "────────────────────────────" print_status "INFO" "Generating coverage report..." if command -v cargo-llvm-cov &> /dev/null; then cargo llvm-cov --workspace --html --output-dir coverage_report 2>&1 | tail -10 # Extract coverage percentage COVERAGE=$(cargo llvm-cov --workspace --summary-only 2>&1 | grep "TOTAL" | awk '{print $NF}' | tr -d '%' || echo "0") echo "" echo "Coverage: $COVERAGE%" if (( $(echo "$COVERAGE >= 60" | bc -l) )); then print_status "PASS" "Coverage $COVERAGE% meets minimum 60%" else print_status "FAIL" "Coverage $COVERAGE% below minimum 60%" FAILED_TESTS=$((FAILED_TESTS + 1)) fi print_status "INFO" "Coverage report: coverage_report/index.html" else print_status "INFO" "cargo-llvm-cov not installed, skipping coverage" fi # Final Summary echo "" echo "==================================================" echo " Test Suite Summary" echo "==================================================" echo "" echo "Total Test Categories: $((PASSED_TESTS + FAILED_TESTS))" echo "Passed: $PASSED_TESTS" echo "Failed: $FAILED_TESTS" echo "" if [ $FAILED_TESTS -eq 0 ]; then print_status "PASS" "ALL TESTS PASSED ✨" echo "" echo "📈 Test Pyramid Breakdown:" echo " Unit Tests (30-40%): ✅" echo " Component Tests (40-50%): ✅" echo " Integration Tests (20-30%): ✅" echo " E2E Tests (5-10%): ✅" echo "" exit 0 else print_status "FAIL" "$FAILED_TESTS test categories failed" echo "" echo "Please review the test output above for details." exit 1 fi