# Continuous integration: run the three project gates on every push
# and pull request. Mirrors what `AGENTS.md` says you have to run
# locally before claiming a change is done:
#
#   uv run pytest -q
#   uv run ruff check src tests
#   uv run pyright
#
# We intentionally do NOT run integration / live-LLM tests that need
# ANTHROPIC_API_KEY — those are gated locally with `pytest.skip` and
# stay skipped on CI without a secret.
#
# References submodules are study material (see AGENTS.md "references/
# is read-only"); the tests don't touch them, so we keep checkout
# fast by not recursing.

name: CI

on:
  push:
    branches: ["**"]
  pull_request:
    branches: ["**"]

# Cancel in-progress runs on the same ref when a newer commit lands —
# saves runner minutes on rapid-fire push cycles.
concurrency:
  group: ci-${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

jobs:
  gates:
    name: pytest + ruff + pyright
    runs-on: ubuntu-latest
    timeout-minutes: 10
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Install uv
        uses: astral-sh/setup-uv@v5
        with:
          # Match the project's pinned interpreter. UV will provision
          # this if the runner image doesn't ship 3.13 yet.
          python-version: "3.13"
          # Cache uv's wheel + index cache keyed on uv.lock so reruns
          # against the same lockfile skip resolution and downloads.
          enable-cache: true
          cache-dependency-glob: "uv.lock"

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

      - name: ruff check
        run: uv run ruff check src tests

      - name: pyright (strict)
        run: uv run pyright

      - name: pytest
        run: uv run pytest -q
