name: Box-First Guard (Advisory)

on:
  pull_request:
  push:

jobs:
  advisory-guards:
    name: Advisory Box-First Checks
    runs-on: ubuntu-latest
    continue-on-error: true  # informational for now
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Install ripgrep
        run: sudo apt-get update && sudo apt-get install -y ripgrep

      - name: Disallow direct env reads in jit (except config/runtime)
        run: |
          set -e
          echo "Checking for std::env::var direct reads under src/jit (excluding config.rs and rt.rs)"
          # find occurrences outside config.rs and rt.rs
          if rg -n "std::env::var\(" src/jit | rg -v 'src/jit/(config|rt)\.rs'; then
            echo "[GUARD] Found direct env reads outside jit::config/rt (advisory)."
            exit 1
          else
            echo "[OK] No direct env reads outside jit::config/rt"
          fi

      - name: Report direct env reads (global advisory)
        run: |
          echo "[ADVISORY] Listing direct std::env::var reads outside config aggregators..."
          rg -n "std::env::var\(" src \
            | rg -v 'src/jit/config\.rs|src/config/env\.rs' \
            || true
          echo "[NOTE] Above is advisory; prefer using config::env or jit::config for critical flags."

      - name: Prevent reintroducing removed modular builder feature (advisory)
        run: |
          set -e
          if rg -n "mir_modular_builder" Cargo.toml src || true; then
            echo "[GUARD] Found 'mir_modular_builder' mention (advisory). This feature was removed."
            exit 1
          else
            echo "[OK] No 'mir_modular_builder' mentions found"
          fi

      - name: Enforce single B1 ABI switch point (advisory)
        run: |
          set -e
          echo "Checking unexpected B1 mentions"
          # allow occurrences in known switch points
          if rg -n "B1" src | rg -v 'abi_param_for_kind|returns.*types::B1|jit-b1-abi'; then
            echo "[GUARD] Found unexpected B1 usage (advisory)."
            exit 1
          else
            echo "[OK] No unexpected B1 usage"
          fi

      - name: Print reminder for stats.jsonl (advisory)
        run: |
          echo "[NOTE] Consider emitting stats.jsonl with {function, abi_mode, reason} at least once per run."
