name: Tests

on:
  push:
  pull_request:

jobs:
  test:
    name: Lint, unit tests, and coverage
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        python-version: ["3.11", "3.12", "3.13"]

    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: ${{ matrix.python-version }}
          cache: 'pip'

      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          # dev extra usually includes ruff, pytest, coverage, etc.
          pip install .[dev]
          # Fallbacks if your extras don't include them:
          pip install pytest coverage || true

      - name: Ruff (lint)
        run: ruff check --output-format=github --no-cache .

      - name: Run tests with coverage
        run: |
          pytest --maxfail=1 --disable-warnings \
                 --cov=. --cov-report=term-missing --cov-report=xml

      - name: Upload coverage.xml (artifact)
        uses: actions/upload-artifact@v4
        with:
          name: coverage-${{ matrix.python-version }}
          path: coverage.xml

      # Optional: publish to codecov if you use it (set CODECOV_TOKEN in repo secrets)
      # - name: Upload to Codecov
      #   uses: codecov/codecov-action@v4
      #   with:
      #     token: ${{ secrets.CODECOV_TOKEN }}
      #     files: coverage.xml
      #     flags: py${{ matrix.python-version }}

    concurrency:
      group: tests-${{ github.ref }}-${{ matrix.python-version }}
      cancel-in-progress: true