name: Anti-Smuggle Gate
on: [push, pull_request]

jobs:
  gate:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Install Lean + elan
        run: |
          curl -sL https://raw.githubusercontent.com/leanprover/elan/master/elan-init.sh | sh -s -- -y
          echo "$HOME/.elan/bin" >> $GITHUB_PATH

      - name: Setup Python
        uses: actions/setup-python@v5
        with:
          python-version: "3.11"

      - name: Install deps
        run: pip install sympy numpy pyyaml

      - name: Restore lake cache
        uses: actions/cache@v4
        with:
          path: .lake
          key: lake-${{ hashFiles('lake-manifest.json') }}

      - name: Layer 0 — Determinism
        run: python3 scripts/check_determinism.py

      - name: Layer 1 — Build Gate
        run: lake build

      - name: Layer 2 — Pipeline Emission
        run: |
          python3 python/build_pist_matrices_250.py --predictions data/rrc_pist_predictions_250_v1.json
          python3 python/build_manifold.py --predictions data/rrc_pist_predictions_250_v1.json
          lake build
          lake exe rrc-emit-fixture 2>/dev/null | python3 -c 'import json,sys; d=json.load(sys.stdin); assert d["bundle_receipt_valid"]; assert d["avm_canaries_passed"]; print(f"OK: {d[\"summary\"][\"total\"]} rows, {d[\"summary\"][\"passed_alignment\"]} passed")'

      - name: Layer 3 — CAS/SMT Grounding
        run: python3 scripts/verify_with_sympy.py

      - name: Layer 4 — Vacuity Gate
        run: python3 scripts/anti_smuggle_check.py --ci
