name: CI

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

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: '3.11'

      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
          if [ -f requirements-dev.txt ]; then pip install -r requirements-dev.txt; fi
          # Fallbacks if requirements-dev.txt not present
          pip install mypy pytest || true

      - name: Type check (mypy)
        run: |
          mypy code || true

      - name: Headless smoke test (dry-run)
        run: |
          python -m code.headless_runner --config config/deck.json --dry-run

      - name: Tests
        run: |
          python -m pytest -q || true

      - name: Theme catalog validation (non-strict)
        run: |
          python code/scripts/validate_theme_catalog.py

      - name: Theme catalog strict alias check
        run: |
          python code/scripts/validate_theme_catalog.py --strict-alias

      - name: Fast path catalog presence & hash validation
        run: |
          python code/scripts/validate_theme_fast_path.py --strict-warn

      - name: Fast determinism tests (random subset)
        env:
          CSV_FILES_DIR: csv_files/testdata
          RANDOM_MODES: "1"
        run: |
          python -m pytest -q code/tests/test_random_determinism_comprehensive.py code/tests/test_random_api_comprehensive.py code/tests/test_seeded_builder_minimal.py code/tests/test_builder_rng_seeded_stream.py
