name: Tests

on:
  workflow_call:

jobs:
  test-fast:
    name: Unit & Service Tests
    runs-on: ubuntu-latest
    timeout-minutes: 5

    steps:
      - uses: actions/checkout@v4

      - name: Set up uv
        uses: astral-sh/setup-uv@v5
        with:
          enable-cache: true
          cache-dependency-glob: "pyproject.toml"

      - name: Install Python 3.14
        run: uv python install 3.14

      - name: Install dependencies
        run: uv sync --frozen

      - name: Run unit & service tests (parallel)
        run: uv run pytest tests/test_services tests/test_api tests/test_unit tests/test_auth tests/test_utils tests/test_cli.py tests/test_config.py tests/test_database_isolation.py -n auto --cov=app --cov-report=xml
        env:
          SECRET_KEY: test-secret-key-for-ci-only
          FUELLHORN_SECRET: test-fuellhorn-secret-for-ci-only

      - name: Upload coverage artifact
        uses: actions/upload-artifact@v4
        with:
          name: coverage-fast
          path: coverage.xml
          retention-days: 7

  test-ui:
    name: UI Tests
    runs-on: ubuntu-latest
    timeout-minutes: 10

    steps:
      - uses: actions/checkout@v4

      - name: Set up uv
        uses: astral-sh/setup-uv@v5
        with:
          enable-cache: true
          cache-dependency-glob: "pyproject.toml"

      - name: Install Python 3.14
        run: uv python install 3.14

      - name: Install dependencies
        run: uv sync --frozen

      - name: Run UI tests
        run: uv run pytest tests/test_ui --cov=app --cov-report=xml --cov-report=term
        env:
          SECRET_KEY: test-secret-key-for-ci-only
          FUELLHORN_SECRET: test-fuellhorn-secret-for-ci-only

      - name: Upload coverage artifact
        uses: actions/upload-artifact@v4
        with:
          name: coverage-ui
          path: coverage.xml
          retention-days: 7
