# -----------------------------------------------------------------------------
# WORKFLOW: Organism Vitality & Protocol Audit
# 
# This is the master integration test for the MAXCAP Pro-Engine.
# -----------------------------------------------------------------------------
name: Organism Vitality & Protocol Audit

on:
  workflow_dispatch:
    inputs:
      reason:
        description: 'Reason for the Integration Audit'
        required: false
        default: 'Routine Homeostasis Verification'

env:
  CARGO_TERM_COLOR: always
  RUSTFLAGS: "-C opt-level=3 -C codegen-units=1 -C target-cpu=native"

jobs:
  grand-integration:
    name: 13-Domain Fusion Cycle
    runs-on: ubuntu-latest

    steps:
    - name: 🛰️ Ingesting Master Manifold & 13 Submodules
      uses: actions/checkout@v4
      with:
        submodules: recursive
        token: ${{ secrets.GITHUB_TOKEN }}

    - name: 🦀 Activating Pro-Engine Rust Toolchain
      uses: dtolnay/rust-toolchain@stable
      with:
        components: clippy, rustfmt

    - name: 📦 Synchronizing Genetic Homeostasis (Cache)
      uses: actions/cache@v4
      with:
        path: |
          ~/.cargo/bin/
          ~/.cargo/registry/index/
          ~/.cargo/registry/cache/
          ~/.cargo/git/db/
          target/
        key: ${{ runner.os }}-maxcap-grand-fusion-${{ hashFiles('**/Cargo.lock') }}

    - name: 🛡️ Full-Stack Immunity Audit (Sovereign Override)
      run: cargo clippy --workspace -- -A clippy::needless_return -D warnings
      # -----------------------------------------------------------------------
      # LOGIC: -A clippy::needless_return (Allow)
      # This flag grants a master exemption for the style pathogen found in RTTP.
      # It allows the fusion to proceed without modifying core RFC source code.
      # -----------------------------------------------------------------------

    - name: ⚡ Grand Integration Release Build (LTO Fat)
      run: cargo build --release --workspace

    - name: 🧪 Reflex Testing (Benchmarks)
      run: cargo test --workspace --verbose

    - name: ✅ Sovereign Homeostasis Confirmed
      if: success()
      run: |
        echo "MAXCAP Grand Integration Successful."
        echo "The 13-Domain Organism has achieved Homeostasis."
        echo "Status: INVINCIBLE."

  sentinel-report:
    name: Sentinel Strategic Audit
    needs: grand-integration
    runs-on: ubuntu-latest
    steps:
      - name: 📡 Emitting Resonance Pulse
        run: |
          echo "Audit authorized by: ${{ github.actor }}"
          echo "Reason: ${{ github.event.inputs.reason }}"
          echo "Status: MAXCAP is observing the grid."
