name: Test

on:
  push:
    branches: [master]
  pull_request:
    branches: [master]

env:
  CARGO_TERM_COLOR: always

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

jobs:
  test:
    runs-on: ubuntu-latest
    timeout-minutes: 30
    strategy:
      matrix:
        rust: [stable, beta]

    steps:
      - uses: actions/checkout@v4

      - name: Setup Rust and cache
        uses: ./.github/actions/setup-rust-cached
        with:
          toolchain: ${{ matrix.rust }}
          cache-key-suffix: ${{ matrix.rust }}

      - name: Install cargo-make
        uses: ./.github/actions/install-cargo-tools
        with:
          tools: make
          cache-tools: 'true'

      - name: Run unit tests
        run: cargo test --workspace --lib

      - name: Run integration tests
        run: cargo test --test cli --test marketplace --test e2e_github_integration --test e2e_lockfile_sha256 --test e2e_marketplace --test e2e_pqc_infrastructure --test e2e_production_marketplace

      - name: Run BDD tests
        run: cargo test --test bdd

      - name: Generate BDD report
        run: cargo test --test bdd -- --nocapture

      - name: Upload BDD results
        uses: actions/upload-artifact@v4
        with:
          name: bdd-results-${{ matrix.rust }}
          path: target/bdd-report.xml

      - name: Run examples
        run: cargo run --example cli-subcommand

      - name: "Run doctests (CRITICAL: Verify all doctests compile and run)"
        run: cargo test --doc --workspace
