name: Test Suite

on:
  push:
    branches: [main]
    paths-ignore:
      - docs/**
  pull_request:
    branches: [main]
    paths-ignore:
      - docs/**

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

permissions:
  contents: read

jobs:
  test:
    runs-on: ${{ matrix.os }}
    timeout-minutes: 20
    strategy:
      fail-fast: false
      matrix:
        os: ${{ fromJSON('["ubuntu-latest","windows-latest"]') }}
        # CI concentrates on newer runtimes (3.11/3.12 still supported per pyproject requires-python).
        python-version: ${{ fromJSON('["3.13","3.14"]') }}

    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 uv
        uses: astral-sh/setup-uv@v4

      - name: Install system dependencies (Linux)
        if: runner.os == 'Linux'
        run: sudo apt-get update && sudo apt-get install -y libolm-dev build-essential

      - name: Install dependencies
        run: uv sync --all-extras --dev

      - name: Lint with ruff
        run: uv run ruff check nanobot --select F

      - name: Run tests
        run: uv run python -m pytest tests/ --cov=nanobot --cov-report=term-missing:skip-covered

  webui:
    runs-on: ubuntu-latest
    timeout-minutes: 15

    steps:
      - uses: actions/checkout@v4

      - name: Set up Bun
        uses: oven-sh/setup-bun@v2
        with:
          bun-version: 1.3.6

      - name: Install WebUI dependencies
        working-directory: webui
        run: bun install

      - name: Lint WebUI
        working-directory: webui
        run: bun run lint

      - name: Test WebUI
        working-directory: webui
        run: bun run test

      - name: Build WebUI
        working-directory: webui
        run: bun run build
