name: Comprehensive Test Suite on: push: branches: [ main, develop, consolidate-side-enum ] pull_request: branches: [ main, develop ] schedule: # Run comprehensive tests nightly at 2 AM UTC - cron: '0 2 * * *' env: CARGO_TERM_COLOR: always RUST_BACKTRACE: 1 COVERAGE_TARGET: 95 jobs: comprehensive-tests: name: Comprehensive Test Suite (95%+ Coverage) runs-on: ubuntu-latest services: redis: image: redis:7-alpine ports: - 6379:6379 options: >- --health-cmd "redis-cli ping" --health-interval 10s --health-timeout 5s --health-retries 5 postgres: image: postgres:15-alpine env: POSTGRES_PASSWORD: testpass POSTGRES_USER: testuser POSTGRES_DB: foxhunt_test ports: - 5432:5432 options: >- --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 steps: - name: Checkout code uses: actions/checkout@v4 with: fetch-depth: 0 # Full history for coverage analysis - name: Install Rust toolchain uses: dtolnay/rust-toolchain@stable with: components: rustfmt, clippy - name: Cache Rust dependencies uses: Swatinem/rust-cache@v2 with: key: comprehensive-tests-v1 - name: Install system dependencies run: | sudo apt-get update sudo apt-get install -y \ pkg-config \ libssl-dev \ libpq-dev \ protobuf-compiler \ cmake \ build-essential - name: Install testing tools run: | cargo install cargo-tarpaulin --locked cargo install cargo-nextest --locked cargo install cargo-criterion --locked - name: Setup CUDA for ML tests (if available) uses: Jimver/cuda-toolkit@v0.2.11 with: cuda: '12.2' method: 'network' continue-on-error: true - name: Run code formatting check run: cargo fmt --all -- --check - name: Run clippy lints run: cargo clippy --workspace --all-targets --all-features - name: Phase 1 - Unit Tests (Core Types) run: | echo "๐Ÿงช Running comprehensive unit tests..." cargo nextest run \ --workspace \ --lib \ --bins \ --tests \ --retries 2 \ --test-threads $(nproc) \ --failure-output final - name: Phase 2 - Property-Based Tests run: | echo "๐Ÿ”ฌ Running property-based financial calculation tests..." cargo test \ --release \ --test comprehensive_financial_property_tests \ -- --test-threads=1 --nocapture timeout-minutes: 15 - name: Phase 3 - Integration Tests run: | echo "๐Ÿ”— Running service integration tests..." cargo test \ --release \ --test comprehensive_integration_tests \ -- --test-threads=$(nproc) --nocapture timeout-minutes: 20 - name: Phase 4 - End-to-End Tests run: | echo "๐ŸŒ Running end-to-end trading workflow tests..." cargo test \ --release \ --test comprehensive_trading_workflow_tests \ -- --test-threads=2 --nocapture timeout-minutes: 25 - name: Phase 5 - ML Model Tests run: | echo "๐Ÿค– Running ML model tests..." cargo test \ --release \ --package ml-models \ --test comprehensive_ml_tests \ -- --test-threads=1 --nocapture timeout-minutes: 30 continue-on-error: true # GPU tests may fail in CI - name: Phase 6 - Risk Management Tests run: | echo "โš ๏ธ Running risk management tests..." cargo test \ --release \ --package risk-management \ --test comprehensive_risk_tests \ -- --test-threads=$(nproc) --nocapture timeout-minutes: 15 - name: Phase 7 - Coverage Analysis run: | echo "๐Ÿ“Š Running comprehensive coverage analysis..." cargo tarpaulin \ --workspace \ --exclude-files "*/tests/*" "*/benches/*" "*/examples/*" "*/proto/*" "*/target/*" \ --skip-clean \ --count \ --ignore-panics \ --fail-under ${{ env.COVERAGE_TARGET }} \ --timeout 300 \ --out Html Xml Lcov \ --output-dir coverage-reports \ -- --test-threads=$(nproc) - name: Upload coverage to Codecov uses: codecov/codecov-action@v3 with: files: coverage-reports/cobertura.xml fail_ci_if_error: true verbose: true - name: Phase 8 - Performance Benchmarks run: | echo "โšก Running performance benchmarks..." cargo criterion \ --output-format html \ --plotting-backend plotters \ || echo "Benchmarks completed with warnings" continue-on-error: true timeout-minutes: 20 - name: Generate comprehensive test report run: | echo "๐Ÿ“„ Generating test report..." mkdir -p test-artifacts # Extract coverage percentage COVERAGE_PCT=$(grep -oP "Coverage: \K[\d.]+" coverage-reports/tarpaulin-report.xml | head -1 || echo "N/A") cat > test-artifacts/summary.md << EOF # Test Results Summary **Date**: $(date -u +"%Y-%m-%d %H:%M:%S UTC") **Commit**: ${{ github.sha }} **Coverage**: ${COVERAGE_PCT}% **Target**: ${{ env.COVERAGE_TARGET }}% ## Test Phases - โœ… Unit Tests (Core Types) - โœ… Property-Based Tests (Financial Calculations) - โœ… Integration Tests (Service Communication) - โœ… End-to-End Tests (Trading Workflows) - ๐Ÿค– ML Model Tests (May require GPU) - โœ… Risk Management Tests - ๐Ÿ“Š Coverage Analysis (Target: ${{ env.COVERAGE_TARGET }}%+) - โšก Performance Benchmarks ## Coverage Details - HTML Report: coverage-reports/tarpaulin-report.html - XML Report: coverage-reports/cobertura.xml - LCOV Report: coverage-reports/lcov.info ## Critical Paths Validated - Order execution pipeline - Risk management workflows - ML model training/inference - Portfolio management - Market data processing - Emergency response systems EOF echo "Coverage: ${COVERAGE_PCT}%" > test-artifacts/coverage.txt - name: Upload test artifacts uses: actions/upload-artifact@v3 if: always() with: name: comprehensive-test-results path: | coverage-reports/ test-artifacts/ target/criterion/ retention-days: 30 - name: Coverage status check run: | COVERAGE_PCT=$(cat test-artifacts/coverage.txt | grep -oP "\K[\d.]+") echo "Final coverage: ${COVERAGE_PCT}%" if (( $(echo "${COVERAGE_PCT} >= ${{ env.COVERAGE_TARGET }}" | bc -l) )); then echo "๐ŸŽ‰ Coverage target achieved: ${COVERAGE_PCT}% >= ${{ env.COVERAGE_TARGET }}%" exit 0 else echo "โŒ Coverage target missed: ${COVERAGE_PCT}% < ${{ env.COVERAGE_TARGET }}%" exit 1 fi - name: Comment PR with coverage if: github.event_name == 'pull_request' uses: actions/github-script@v6 with: script: | const fs = require('fs'); const coverage = fs.readFileSync('test-artifacts/coverage.txt', 'utf8').match(/[\d.]+/)[0]; const summary = fs.readFileSync('test-artifacts/summary.md', 'utf8'); const comment = `## ๐Ÿงช Comprehensive Test Results **Coverage**: ${coverage}% (Target: ${{ env.COVERAGE_TARGET }}%+) ${coverage >= ${{ env.COVERAGE_TARGET }} ? '๐ŸŽฏ Coverage target **ACHIEVED**!' : 'โš ๏ธ Coverage target **MISSED** - needs improvement'}
๐Ÿ“Š Detailed Results ${summary}
[View detailed coverage report](https://codecov.io/gh/${{ github.repository }}/pull/${{ github.event.number }}) `; github.rest.issues.createComment({ issue_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo, body: comment }); security-tests: name: Security and Vulnerability Tests runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Install Rust toolchain uses: dtolnay/rust-toolchain@stable - name: Install cargo-audit run: cargo install cargo-audit - name: Run security audit run: cargo audit --ignore RUSTSEC-0000-0000 # Ignore known false positives - name: Run cargo-deny uses: EmbarkStudios/cargo-deny-action@v1 with: log-level: warn command: check arguments: --all-features mutation-testing: name: Mutation Testing (Weekly) runs-on: ubuntu-latest if: github.event_name == 'schedule' steps: - uses: actions/checkout@v4 - name: Install Rust toolchain uses: dtolnay/rust-toolchain@stable - name: Install cargo-mutants run: cargo install cargo-mutants - name: Run mutation tests on core types run: | cargo mutants \ --package types \ --timeout 60 \ --jobs $(nproc) \ || echo "Mutation testing completed with findings" timeout-minutes: 120 continue-on-error: true