name: Tests

on:
  push:
    branches: ["main", "develop"]
  pull_request:
    branches: ["main"]

jobs:
  test:
    name: pytest (Python ${{ matrix.python-version }})
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        python-version: ["3.11", "3.12"]

    steps:
      - uses: actions/checkout@v4

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

      - name: Install package + dev deps
        run: |
          pip install --upgrade pip
          pip install -e ".[dev]"

      - name: Run tests
        run: |
          pytest tests/ -v --tb=short

      - name: Check test count (regression guard)
        run: |
          COUNT=$(pytest tests/ --collect-only -q 2>/dev/null | tail -1 | grep -oE '[0-9]+ (test|item)' | head -1 | grep -oE '[0-9]+')
          echo "Collected $COUNT tests"
          if [ -n "$COUNT" ] && [ "$COUNT" -lt 80 ]; then
            echo "ERROR: Expected >= 80 tests, got $COUNT. Possible test files missing."
            exit 1
          fi
