name: CI
on:
  push:
    branches: [main]
  pull_request:

jobs:
  test:
    name: Test (${{ matrix.os }}, Python ${{ matrix.python }})
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest, macos-latest, windows-latest]
        python: ['3.12', '3.13']
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v5
        with:
          python-version: ${{ matrix.python }}
      - uses: dtolnay/rust-toolchain@stable
      - uses: Swatinem/rust-cache@v2
      - name: Build and test
        shell: bash
        run: |
          python -m venv .venv
          # Correct cross-platform activation
          if [ "$RUNNER_OS" == "Windows" ]; then
            source .venv/Scripts/activate
          else
            source .venv/bin/activate
          fi
          python -m pip install --upgrade pip
          pip install maturin pytest pydantic httpx websockets python-multipart pytest-cov
          maturin develop --release
          pytest tests/ -v --tb=short --cov=python/ignyx --cov-report=term-missing

  lint:
    name: Lint
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
        with:
          components: rustfmt, clippy
      - uses: actions/setup-python@v5
        with:
          python-version: '3.12'
      - name: Rust fmt check
        run: cargo fmt --check
      - name: Cargo clippy
        run: cargo clippy -- -D warnings
      - name: Python lint
        run: |
          pip install ruff
          ruff check python/
