# Wave 4 CI/CD Integration Guide **Version**: 1.0 **Date**: 2025-10-22 **Status**: Production Ready **Author**: Agent W4-5 (Test Documentation Specialist) --- ## Overview This guide describes the CI/CD integration strategy for automated testing in the Foxhunt HFT Trading System. --- ## 1. GitHub Actions Workflow ### Complete Workflow (.github/workflows/test.yml) ```yaml name: Test Suite on: push: branches: [main, develop] pull_request: branches: [main, develop] env: CARGO_TERM_COLOR: always RUST_BACKTRACE: 1 jobs: unit-tests: name: Unit Tests runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable - uses: Swatinem/rust-cache@v2 - run: cargo test --workspace --lib - run: cargo test --doc integration-tests: name: Integration Tests runs-on: ubuntu-latest services: postgres: image: timescaledb/timescaledb:latest-pg16 env: POSTGRES_USER: foxhunt POSTGRES_PASSWORD: foxhunt_dev_password POSTGRES_DB: foxhunt ports: - 5432:5432 options: >- --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 redis: image: redis:7-alpine ports: - 6379:6379 options: >- --health-cmd "redis-cli ping" --health-interval 10s --health-timeout 5s --health-retries 5 steps: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable - uses: Swatinem/rust-cache@v2 - name: Install SQLx CLI run: cargo install sqlx-cli --no-default-features --features postgres - name: Run migrations run: cargo sqlx migrate run env: DATABASE_URL: postgresql://foxhunt:foxhunt_dev_password@localhost:5432/foxhunt - name: Run integration tests run: cargo test --workspace --test "*" env: DATABASE_URL: postgresql://foxhunt:foxhunt_dev_password@localhost:5432/foxhunt REDIS_URL: redis://localhost:6379 e2e-tests: name: E2E Tests runs-on: ubuntu-latest needs: [unit-tests, integration-tests] steps: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable - uses: Swatinem/rust-cache@v2 - name: Start services run: docker-compose -f tests/docker/docker-compose.test.yml up -d - name: Wait for services run: | timeout 60 bash -c 'until docker-compose -f tests/docker/docker-compose.test.yml ps | grep healthy; do sleep 2; done' - name: Run E2E tests run: cargo test -p tli e2e:: -p foxhunt_e2e - name: Cleanup if: always() run: docker-compose -f tests/docker/docker-compose.test.yml down -v coverage: name: Code Coverage runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable - uses: Swatinem/rust-cache@v2 - uses: taiki-e/install-action@cargo-llvm-cov - name: Generate coverage run: cargo llvm-cov --workspace --lcov --output-path lcov.info - name: Upload to Codecov uses: codecov/codecov-action@v4 with: files: lcov.info fail_ci_if_error: false clippy: name: Clippy runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable with: components: clippy - uses: Swatinem/rust-cache@v2 - run: cargo clippy --workspace --all-targets -- -D warnings fmt: name: Rustfmt runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable with: components: rustfmt - run: cargo fmt --all -- --check ``` --- ## 2. Nightly Stress Tests (.github/workflows/nightly.yml) ```yaml name: Nightly Stress Tests on: schedule: - cron: '0 2 * * *' # 2 AM UTC daily workflow_dispatch: jobs: stress-tests: name: Stress Tests runs-on: ubuntu-latest-8core timeout-minutes: 120 steps: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable - uses: Swatinem/rust-cache@v2 - name: Run stress tests run: cargo test --release --features stress-test env: RUST_LOG: info benchmarks: name: Performance Benchmarks runs-on: ubuntu-latest-8core steps: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable - uses: Swatinem/rust-cache@v2 - name: Run benchmarks run: cargo bench --workspace - name: Upload benchmark results uses: actions/upload-artifact@v4 with: name: benchmark-results path: target/criterion/ - name: Compare with baseline run: | if [ -f baseline/bench_results.json ]; then cargo install criterion-compare criterion-compare baseline/bench_results.json target/criterion/ fi ``` --- ## 3. Pre-Commit Hooks (.git/hooks/pre-commit) ```bash #!/bin/bash set -e echo "Running pre-commit checks..." # Run fast unit tests echo "Running unit tests..." cargo test --lib --quiet # Run clippy echo "Running clippy..." cargo clippy --workspace --all-targets --quiet -- -D warnings # Run rustfmt echo "Checking formatting..." cargo fmt --all -- --check echo "All pre-commit checks passed!" ``` Install with: ```bash chmod +x .git/hooks/pre-commit ``` --- ## 4. Pre-Push Hooks (.git/hooks/pre-push) ```bash #!/bin/bash set -e echo "Running pre-push checks..." # Run all tests echo "Running all tests..." cargo test --workspace # Check documentation echo "Checking documentation..." cargo doc --no-deps --workspace echo "All pre-push checks passed!" ``` --- ## 5. Performance Regression Detection ### Baseline Storage ```bash # Store performance baseline cargo bench --workspace -- --save-baseline main # Compare against baseline cargo bench --workspace -- --baseline main # Fail if regression > 10% cargo bench --workspace -- --baseline main --threshold 10 ``` ### Automated Regression Alerts ```yaml # .github/workflows/performance.yml - name: Check for regressions run: | cargo bench --workspace -- --baseline main > bench_output.txt if grep -q "regressed" bench_output.txt; then echo "::error::Performance regression detected!" exit 1 fi ``` --- ## 6. Coverage Reporting ### Codecov Integration ```yaml # codecov.yml coverage: status: project: default: target: 60% # Wave 4 target threshold: 2% # Allow 2% drop patch: default: target: 70% # New code should be well-tested ignore: - "tests/**" - "benches/**" - "**/tests/**" ``` --- ## 7. Docker Compose for CI ```yaml # tests/docker/docker-compose.test.yml version: '3.8' services: postgres: image: timescaledb/timescaledb:latest-pg16 environment: POSTGRES_USER: foxhunt POSTGRES_PASSWORD: foxhunt_test_password POSTGRES_DB: foxhunt_test ports: - "5432:5432" healthcheck: test: ["CMD-SHELL", "pg_isready -U foxhunt"] interval: 5s timeout: 5s retries: 5 redis: image: redis:7-alpine ports: - "6379:6379" healthcheck: test: ["CMD", "redis-cli", "ping"] interval: 5s timeout: 3s retries: 5 vault: image: hashicorp/vault:latest environment: VAULT_DEV_ROOT_TOKEN_ID: foxhunt-test-root VAULT_DEV_LISTEN_ADDRESS: 0.0.0.0:8200 ports: - "8200:8200" cap_add: - IPC_LOCK ``` --- ## 8. Test Matrix Strategy ```yaml # .github/workflows/test-matrix.yml strategy: matrix: os: [ubuntu-latest, macos-latest, windows-latest] rust: [stable, beta, nightly] exclude: - os: macos-latest rust: beta - os: windows-latest rust: nightly runs-on: ${{ matrix.os }} steps: - uses: dtolnay/rust-toolchain@${{ matrix.rust }} - run: cargo test --workspace ``` --- **Last Updated**: 2025-10-22