name: test-suite-on-tag

on:
  push:
    tags:
      - 'v*'
      - 'release-*'

jobs:
  test-ci:
    name: Test Suite (tier-1 + tier-2, CI-compatible)
    runs-on: windows-latest
    timeout-minutes: 30

    steps:
      - name: Checkout
        uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Setup Python
        uses: actions/setup-python@v5
        with:
          python-version: '3.11'

      - name: Install uv
        run: pip install uv

      - name: Cache uv dependencies
        uses: actions/cache@v4
        with:
          path: |
            .venv
            ~\AppData\Local\uv\cache
          key: ${{ runner.os }}-uv-${{ hashFiles('uv.lock', 'pyproject.toml') }}
          restore-keys: |
            ${{ runner.os }}-uv-

      - name: Sync dependencies
        run: uv sync --extra local-rag

      - name: Run unit + mock_app tests (skip tier-3 live_gui)
        run: |
          $tagName = "${{ github.ref_name }}"
          $logPath = "tests/artifacts/ci_tag_run_${tagName}.log"
          uv run python scripts/run_tests_batched.py --tiers 1,2 2>&1 | Tee-Object -FilePath $logPath | Select-Object -Last 250
        shell: pwsh
        timeout-minutes: 20

      - name: Upload test logs
        if: always()
        uses: actions/upload-artifact@v4
        with:
          name: test-logs-${{ github.ref_name }}
          path: |
            tests/artifacts/ci_tag_run_*.log
          if-no-files-found: ignore
          retention-days: 30
