name: Run Pytest on Pull Request

permissions:
  contents: read

on:
  pull_request:
  push:
    branches: [main]

jobs:
  test:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout code
        uses: actions/checkout@v7

      - name: Set up Python
        uses: actions/setup-python@v7
        with:
          python-version: "3.13.15"

      - name: Install uv
        run: |
          python -m pip install --upgrade pip
          pip install uv

      - name: Sync environment with uv
        run: |
          uv sync --extra dev

      - name: Run tests
        run: |
          uv run pytest --finalize --check-config-side-effect -vs --cov src --cov-report term-missing

      - name: Upload test artifacts
        if: failure()
        uses: actions/upload-artifact@v7
        with:
          name: optimize-results
          path: tests/testdata/**/new_optimize_result*
          if-no-files-found: ignore
