name: CI

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

jobs:
  test:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        python-version: ["3.10", "3.11", "3.12"]
    steps:
      - uses: actions/checkout@v4
      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: ${{ matrix.python-version }}
      - name: Install package
        run: pip install -e .
      - name: Download sources and build index
        run: python -m openrights ingest
      - name: Run evaluation
        run: python -m openrights evaluate
      - name: Check answer coverage
        run: python -m openrights coverage
      - name: Run unit tests
        run: python -m unittest discover -s tests -v
      - name: Run benchmark
        run: python -m openrights benchmark
      - name: Export web archive
        run: python -m openrights export-web
      - name: Build single-file demo
        run: python -m openrights bundle
      - name: Check archive size
        run: |
          SIZE=$(stat -c%s app/data/index.js)
          echo "Archive size: $SIZE bytes"
          if [ $SIZE -gt 5242880 ]; then
            echo "ERROR: Archive exceeds 5 MB budget"
            exit 1
          fi
