name: test

on:
  push:
    branches:
      - main
      - stable
      - 'releases/**'
    tags:
      - '*'
  pull_request:
  workflow_dispatch:
    
jobs:
  tests:
    name: ${{matrix.test}} 
    runs-on: ubuntu-latest
    strategy:
      matrix:
        test:
        # TODO:
        # - browser/patchright
        # - browser/playwright
        # - browser/user_binary
        # - browser/remote_cdp
        # - models/openai
        # - models/google
        # - models/anthropic
        # - models/azure
        # - models/deepseek
        # - models/grok
        # - functionality/click
        # - functionality/tabs
        # - functionality/input
        # - functionality/scroll
        # - functionality/upload
        # - functionality/download
        # - functionality/save
        # - functionality/vision
        # - functionality/memory
        # - functionality/planner
        # - functionality/hooks
        - test_controller
        - test_tab_management
        - test_sensitive_data
        - test_url_allowlist_security
    steps:
      - uses: actions/checkout@v4
      - uses: astral-sh/setup-uv@v6
        with:
          enable-cache: true
          activate-environment: true

      - run: uv sync

      - name: Detect installed Playwright or Patchright version
        run: echo "PLAYWRIGHT_VERSION=$(uv pip list --format json | jq -r '.[] | select(.name == "playwright") | .version')" >> $GITHUB_ENV

      - name: Cache playwright binaries
        uses: actions/cache@v3
        with:
          path: |
            ~/.cache/ms-playwright
          key: ${{ runner.os }}-playwright-${{ env.PLAYWRIGHT_VERSION }}

      - run: playwright install --no-shell chromium

      - run: pytest tests/${{ matrix.test }}.py
