name: Windows Tests

on:
  workflow_dispatch: {}
  # pull_request:
  #   branches:
  #   paths:
  #     - "pyproject.toml"
  #     - "src/prefect/**/*.py"
  #     - "scripts/test_unc_paths.py"
  #     - ".github/workflows/windows-tests.yaml"

permissions: {}

jobs:
  run-tests-sqlite:
    name: Test with SQLite

    strategy:
      matrix:
        python-version:
          - "3.10"
          - "3.12"
          - "3.14"

      fail-fast: true

    permissions:
      contents: read

    runs-on: windows-latest
    timeout-minutes: 10

    env:
      # enable colored output
      PY_COLORS: 1

    steps:
      - uses: actions/checkout@v6
        with:
          persist-credentials: false
          fetch-depth: 0

      - name: Set up uv and Python ${{ matrix.python-version }}
        uses: astral-sh/setup-uv@v7
        with:
          enable-cache: true
          python-version: ${{ matrix.python-version }}
          cache-dependency-glob: "pyproject.toml"

      - name: Run tests
        run: |
          # Parallelize tests by scope to reduce expensive service fixture duplication
          uv run pytest tests -vv --numprocesses auto --dist worksteal --exclude-services --durations=25

  test-unc-paths:
    name: Test Windows UNC Paths
    # Only run this job when triggered manually
    if: github.event_name == 'workflow_dispatch'

    runs-on: windows-latest
    timeout-minutes: 5

    steps:
      - uses: actions/checkout@v6
        with:
          persist-credentials: false
          fetch-depth: 0

      - name: Set up Python
        uses: astral-sh/setup-uv@v7
        with:
          enable-cache: true
          python-version: "3.12"
          cache-dependency-glob: "pyproject.toml"

      - name: Create test UNC path and run flow
        shell: pwsh
        run: |
          # Create a test directory
          New-Item -ItemType Directory -Path "C:\ShareTest" -Force

          # Create network share
          New-SmbShare -Name "PrefectTest" -Path "C:\ShareTest" -FullAccess "Everyone"

          # Run the test script from the current directory
          uv run scripts/test_unc_paths.py
        env:
          PYTHONPATH: ${{ github.workspace }}

      - name: Cleanup
        if: always()
        shell: pwsh
        run: |
          Remove-SmbShare -Name "PrefectTest" -Force
