name: CI

on:
  push:
    branches: [main, beta]
  pull_request:
    branches: [main, beta]

permissions:
  contents: read

jobs:
  lint:
    name: Lint (Ruff)
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: "3.12"

      - name: Install Ruff
        run: pip install ruff

      - name: Ruff check (critical errors)
        run: ruff check src/ tests/ --select=F821,F811 --no-fix

      - name: Ruff format check
        run: ruff format --check src/ tests/

  test:
    name: Test (Python ${{ matrix.python-version }}, ${{ matrix.os }})
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest, windows-latest]
        python-version: ["3.12", "3.13"]

    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 core + dev dependencies
        run: |
          python -m pip install --upgrade pip
          pip install -e ".[dev]"

      - name: Install optional dependency groups
        run: |
          echo "::group::memory"
          pip install -e ".[memory]" || echo "::warning::memory extras failed"
          echo "::endgroup::"

          echo "::group::search"
          pip install -e ".[search]" || echo "::warning::search extras failed"
          echo "::endgroup::"

          echo "::group::mcp"
          pip install -e ".[mcp]" || echo "::warning::mcp extras failed"
          echo "::endgroup::"

          echo "::group::telegram"
          pip install -e ".[telegram]" || echo "::warning::telegram extras failed"
          echo "::endgroup::"

          echo "::group::discord"
          pip install -e ".[discord]" || echo "::warning::discord extras failed"
          echo "::endgroup::"

          echo "::group::slack"
          pip install -e ".[slack]" || echo "::warning::slack extras failed"
          echo "::endgroup::"

          echo "::group::matrix"
          pip install -e ".[matrix]" || echo "::warning::matrix extras failed"
          echo "::endgroup::"

          echo "::group::web"
          pip install -e ".[web]" || echo "::warning::web extras failed"
          echo "::endgroup::"

          echo "::group::documents"
          pip install -e ".[documents]" || echo "::warning::documents extras failed"
          echo "::endgroup::"

          echo "::group::cron"
          pip install -e ".[cron]" || echo "::warning::cron extras failed"
          echo "::endgroup::"

          echo "::group::vector"
          pip install -e ".[vector]" || echo "::warning::vector extras failed (faiss-cpu)"
          echo "::endgroup::"

          echo "::group::postgresql"
          pip install -e ".[postgresql]" || echo "::warning::postgresql extras failed"
          echo "::endgroup::"

          echo "::group::irc"
          pip install -e ".[irc]" || echo "::warning::irc extras failed"
          echo "::endgroup::"

          echo "::group::twitch"
          pip install -e ".[twitch]" || echo "::warning::twitch extras failed"
          echo "::endgroup::"

      - name: Show installed packages
        run: pip list --format=columns

      - name: Run tests
        # test_voice_ws_bridge.py is excluded because it requires system audio
        # devices (microphone/speaker) which are not available in CI runners.
        run: python -m pytest tests/ -x -q --tb=short --ignore=tests/test_channels/test_voice_ws_bridge.py
        env:
          JARVIS_TEST_MODE: "1"
