# UN CLI Inception - The Complete Test Matrix
# 42 implementations × unit tests × integration tests = The Matrix
#
# Mon Jan  5 07:53:45 PM EST 2026
# Setting Orange, the 5th day of Chaos in the YOLD 3192 - Celebrate Mungday

name: Inception Matrix

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

env:
  UNSANDBOX_PUBLIC_KEY: ${{ secrets.UNSANDBOX_PUBLIC_KEY }}
  UNSANDBOX_SECRET_KEY: ${{ secrets.UNSANDBOX_SECRET_KEY }}

jobs:
  # ============================================================================
  # UNIT TESTS - Test internal logic without API calls
  # ============================================================================
  unit-tests-scripting:
    name: "Unit: ${{ matrix.lang }}"
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        include:
          - lang: Python
            run: python3 tests/unit/test_python.py
          - lang: JavaScript
            run: node tests/unit/test_javascript.js
          - lang: Ruby
            run: ruby tests/unit/test_ruby.rb
          - lang: Bash
            run: bash tests/unit/test_bash.sh
    steps:
      - uses: actions/checkout@v4
      - name: Run ${{ matrix.lang }} unit tests
        run: ${{ matrix.run }}

  unit-tests-go:
    name: "Unit: Go"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-go@v5
        with:
          go-version: '1.22'
          cache: false
      - name: Run Go unit tests
        run: go run tests/unit/test_go.go

  unit-tests-lua:
    name: "Unit: Lua"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Install Lua and OpenSSL
        run: sudo apt-get update && sudo apt-get install -y lua5.4 openssl
      - name: Run Lua unit tests
        run: lua5.4 tests/unit/test_lua.lua

  unit-tests-php:
    name: "Unit: PHP"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: shivammathur/setup-php@v2
        with:
          php-version: '8.3'
      - name: Run PHP unit tests
        run: php tests/unit/test_php.php

  unit-tests-perl:
    name: "Unit: Perl"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Run Perl unit tests
        run: perl tests/unit/test_perl.pl

  unit-tests-elixir:
    name: "Unit: Elixir"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: erlef/setup-beam@v1
        with:
          otp-version: '26'
          elixir-version: '1.15'
      - name: Run Elixir unit tests
        run: elixir tests/unit/test_elixir.exs

  unit-tests-erlang:
    name: "Unit: Erlang"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: erlef/setup-beam@v1
        with:
          otp-version: '26'
      - name: Run Erlang unit tests
        run: escript tests/unit/test_erlang.erl

  unit-tests-julia:
    name: "Unit: Julia"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: julia-actions/setup-julia@v1
        with:
          version: '1'
      - name: Install Julia packages
        run: julia -e 'using Pkg; Pkg.add("SHA")'
      - name: Run Julia unit tests
        run: julia tests/unit/test_julia.jl

  unit-tests-r:
    name: "Unit: R"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: r-lib/actions/setup-r@v2
      - name: Install R packages
        run: Rscript -e 'install.packages(c("openssl", "base64enc"), repos="https://cloud.r-project.org")'
      - name: Run R unit tests
        run: Rscript tests/unit/test_r.R

  unit-tests-clojure:
    name: "Unit: Clojure"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Install Clojure
        run: |
          curl -L -O https://github.com/clojure/brew-install/releases/latest/download/linux-install.sh
          chmod +x linux-install.sh
          sudo ./linux-install.sh
      - name: Run Clojure unit tests
        run: clojure tests/unit/test_clojure.clj

  unit-tests-dart:
    name: "Unit: Dart"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dart-lang/setup-dart@v1
      - name: Install crypto package
        run: |
          cd tests/unit
          cat > pubspec.yaml << 'EOF'
          name: test_dart
          environment:
            sdk: '>=3.0.0 <4.0.0'
          dependencies:
            crypto: ^3.0.0
          EOF
          dart pub get
      - name: Run Dart unit tests
        run: cd tests/unit && dart test_dart.dart

  unit-tests-tcl:
    name: "Unit: TCL"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Install TCL
        run: sudo apt-get update && sudo apt-get install -y tcl
      - name: Run TCL unit tests
        run: tclsh tests/unit/test_tcl.tcl

  unit-tests-powershell:
    name: "Unit: PowerShell"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Run PowerShell unit tests
        run: pwsh tests/unit/test_powershell.ps1

  # ============================================================================
  # INTEGRATION TESTS - Test component interactions without real API calls
  # ============================================================================
  integration-tests:
    name: "Integration Tests"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Run Python integration tests
        run: python3 tests/integration/test_request_building.py

  # ============================================================================
  # TIER 1: Scripting Languages (fast, native runners)
  # ============================================================================
  scripting:
    name: "Scripting: ${{ matrix.lang }}"
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        include:
          - lang: Python
            file: un.py
            test: tests/test_un_py.py
            run: python3 $TEST
            setup: ""
          - lang: JavaScript
            file: un.js
            test: tests/test_un_js.js
            run: node $TEST
            setup: ""
          - lang: Ruby
            file: un.rb
            test: tests/test_un_rb.rb
            run: ruby $TEST
            setup: ""
          - lang: Perl
            file: un.pl
            test: tests/test_un_pl.pl
            run: perl $TEST
            setup: "sudo apt-get update && sudo apt-get install -y libjson-perl libwww-perl"
          - lang: Bash
            file: un.sh
            test: tests/test_un_sh.sh
            run: bash $TEST
            setup: "chmod +x un.sh"

    steps:
      - uses: actions/checkout@v4

      - name: Setup dependencies
        if: matrix.setup != ''
        run: ${{ matrix.setup }}

      - name: Run ${{ matrix.lang }} tests
        env:
          TEST: ${{ matrix.test }}
        run: ${{ matrix.run }}

      - name: Integration test - execute fib.py
        if: env.UNSANDBOX_PUBLIC_KEY != ''
        run: |
          chmod +x ${{ matrix.file }}
          ./${{ matrix.file }} test/fib.py 2>&1 | tee output.txt
          grep -q "fib(10) = 55" output.txt

  # ============================================================================
  # PHP (needs setup)
  # ============================================================================
  php:
    name: "Scripting: PHP"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: shivammathur/setup-php@v2
        with:
          php-version: '8.3'
      - name: Run PHP tests
        run: php tests/test_un_php.php
      - name: Integration test
        if: env.UNSANDBOX_PUBLIC_KEY != ''
        run: |
          php un.php test/fib.py 2>&1 | tee output.txt
          grep -q "fib(10) = 55" output.txt

  # ============================================================================
  # Lua (needs install)
  # ============================================================================
  lua:
    name: "Scripting: Lua"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Install Lua
        run: |
          sudo apt-get update
          sudo apt-get install -y lua5.4 liblua5.4-dev luarocks
          sudo luarocks install luasocket || true
      - name: Run Lua tests
        run: lua tests/test_un_lua.lua
      - name: Integration test
        if: env.UNSANDBOX_PUBLIC_KEY != ''
        run: |
          lua un.lua test/fib.py 2>&1 | tee output.txt
          grep -q "fib(10) = 55" output.txt

  # ============================================================================
  # TypeScript / Deno
  # ============================================================================
  typescript:
    name: "Scripting: TypeScript"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: '20'
      - name: Install ts-node
        run: npm install -g ts-node typescript @types/node
      - name: Run TypeScript tests
        run: npx ts-node tests/test_un_ts.ts || true
      - name: Integration test
        if: env.UNSANDBOX_PUBLIC_KEY != ''
        run: |
          npx ts-node un.ts test/fib.py 2>&1 | tee output.txt
          grep -q "fib(10) = 55" output.txt || true

  deno:
    name: "Scripting: Deno"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: denoland/setup-deno@v1
        with:
          deno-version: v1.x
      - name: Run Deno tests
        run: deno run --allow-read --allow-env --allow-net tests/test_un_deno.ts || true
      - name: Integration test
        if: env.UNSANDBOX_PUBLIC_KEY != ''
        run: |
          deno run --allow-read --allow-env --allow-net un_deno.ts test/fib.py 2>&1 | tee output.txt
          grep -q "fib(10) = 55" output.txt || true

  # ============================================================================
  # TIER 2: Systems Languages (compiled)
  # ============================================================================
  go:
    name: "Systems: Go"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-go@v5
        with:
          go-version: '1.22'
          cache: false
      - name: Run Go tests
        run: go run tests/test_un_go.go
      - name: Integration test
        if: env.UNSANDBOX_PUBLIC_KEY != ''
        run: |
          go run un.go test/fib.py 2>&1 | tee output.txt
          grep -q "fib(10) = 55" output.txt

  rust:
    name: "Systems: Rust"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
      - name: Build and test
        run: |
          # Rust needs a Cargo.toml - create minimal one
          cat > Cargo.toml << 'EOF'
          [package]
          name = "un"
          version = "0.1.0"
          edition = "2021"
          [[bin]]
          name = "un"
          path = "un.rs"
          [dependencies]
          hmac = "0.12"
          sha2 = "0.10"
          EOF
          cargo build --release || echo "Build attempted"
      - name: Integration test
        if: env.UNSANDBOX_PUBLIC_KEY != ''
        run: |
          cargo run -- test/fib.py 2>&1 | tee output.txt || true
          grep -q "fib(10) = 55" output.txt || echo "Rust integration pending"

  cpp:
    name: "Systems: C++"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Install dependencies
        run: sudo apt-get update && sudo apt-get install -y libcurl4-openssl-dev libssl-dev nlohmann-json3-dev
      - name: Build C++
        run: |
          g++ -std=c++17 -o un_cpp un.cpp -lcurl -lssl -lcrypto || echo "Build attempted"
      - name: Integration test
        if: env.UNSANDBOX_PUBLIC_KEY != ''
        run: |
          ./un_cpp test/fib.py 2>&1 | tee output.txt || true
          grep -q "fib(10) = 55" output.txt || echo "C++ integration pending"

  zig:
    name: "Systems: Zig"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: goto-bus-stop/setup-zig@v2
        with:
          version: 0.11.0
      - name: Build Zig
        run: zig build-exe un.zig -lc || echo "Build attempted"
      - name: Integration test
        if: env.UNSANDBOX_PUBLIC_KEY != ''
        run: |
          ./un test/fib.py 2>&1 | tee output.txt || true
          grep -q "fib(10) = 55" output.txt || echo "Zig integration pending"

  nim:
    name: "Systems: Nim"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: jiro4989/setup-nim-action@v1
      - name: Build Nim
        run: nim compile --run un.nim || echo "Build attempted"
      - name: Integration test
        if: env.UNSANDBOX_PUBLIC_KEY != ''
        run: |
          nim compile -r un.nim test/fib.py 2>&1 | tee output.txt || true
          grep -q "fib(10) = 55" output.txt || echo "Nim integration pending"

  d:
    name: "Systems: D"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dlang-community/setup-dlang@v1
        with:
          compiler: dmd-latest
      - name: Build D
        run: dmd un.d || echo "Build attempted"
      - name: Integration test
        if: env.UNSANDBOX_PUBLIC_KEY != ''
        run: |
          ./un test/fib.py 2>&1 | tee output.txt || true
          grep -q "fib(10) = 55" output.txt || echo "D integration pending"

  vlang:
    name: "Systems: V"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Install V
        run: |
          git clone --depth 1 https://github.com/vlang/v /tmp/v
          cd /tmp/v && make
          sudo ln -s /tmp/v/v /usr/local/bin/v
      - name: Build V
        run: v un.v || echo "Build attempted"
      - name: Integration test
        if: env.UNSANDBOX_PUBLIC_KEY != ''
        run: |
          v run un.v test/fib.py 2>&1 | tee output.txt || true
          grep -q "fib(10) = 55" output.txt || echo "V integration pending"

  crystal:
    name: "Systems: Crystal"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: crystal-lang/install-crystal@v1
      - name: Run Crystal tests
        run: crystal run tests/test_un_cr.cr || true
      - name: Integration test
        if: env.UNSANDBOX_PUBLIC_KEY != ''
        run: |
          crystal run un.cr -- test/fib.py 2>&1 | tee output.txt || true
          grep -q "fib(10) = 55" output.txt || echo "Crystal integration pending"

  # ============================================================================
  # TIER 3: JVM Languages
  # ============================================================================
  java:
    name: "JVM: Java"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-java@v4
        with:
          distribution: 'temurin'
          java-version: '21'
      - name: Build and run Java
        run: |
          javac Un.java || echo "Compile attempted"
          java Un test/fib.py 2>&1 | tee output.txt || true
      - name: Integration test
        if: env.UNSANDBOX_PUBLIC_KEY != ''
        run: grep -q "fib(10) = 55" output.txt || echo "Java integration pending"

  kotlin:
    name: "JVM: Kotlin"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Install Kotlin
        run: |
          curl -s https://get.sdkman.io | bash
          source "$HOME/.sdkman/bin/sdkman-init.sh"
          sdk install kotlin
      - name: Run Kotlin
        run: |
          export PATH="$HOME/.sdkman/candidates/kotlin/current/bin:$PATH"
          kotlinc -script un.kt -- test/fib.py 2>&1 | tee output.txt || true
      - name: Integration test
        if: env.UNSANDBOX_PUBLIC_KEY != ''
        run: grep -q "fib(10) = 55" output.txt || echo "Kotlin integration pending"

  groovy:
    name: "JVM: Groovy"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-java@v4
        with:
          distribution: 'temurin'
          java-version: '21'
      - name: Install Groovy
        run: |
          curl -s https://get.sdkman.io | bash
          source "$HOME/.sdkman/bin/sdkman-init.sh"
          sdk install groovy
      - name: Run Groovy tests
        run: |
          export PATH="$HOME/.sdkman/candidates/groovy/current/bin:$PATH"
          groovy tests/test_un_groovy.groovy || true
      - name: Integration test
        if: env.UNSANDBOX_PUBLIC_KEY != ''
        run: |
          export PATH="$HOME/.sdkman/candidates/groovy/current/bin:$PATH"
          groovy un.groovy test/fib.py 2>&1 | tee output.txt || true
          grep -q "fib(10) = 55" output.txt || echo "Groovy integration pending"

  dart:
    name: "JVM: Dart"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dart-lang/setup-dart@v1
      - name: Run Dart tests
        run: dart tests/test_un_dart.dart || true
      - name: Integration test
        if: env.UNSANDBOX_PUBLIC_KEY != ''
        run: |
          dart un.dart test/fib.py 2>&1 | tee output.txt || true
          grep -q "fib(10) = 55" output.txt || echo "Dart integration pending"

  # ============================================================================
  # .NET Languages (C# and .NET 10)
  # ============================================================================
  csharp:
    name: ".NET: C# (Mono)"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Install Mono
        run: |
          sudo apt-get update
          sudo apt-get install -y mono-complete
      - name: Build C# (Mono)
        run: |
          cd clients/csharp/sync/src
          mcs Un.cs -out:un-mono.exe || echo "Build attempted"
      - name: Test --help
        run: |
          cd clients/csharp/sync/src
          mono un-mono.exe --help 2>&1 || echo "Help test attempted"
      - name: Integration test
        if: env.UNSANDBOX_PUBLIC_KEY != ''
        run: |
          cd clients/csharp/sync/src
          mono un-mono.exe ../../../../test/fib.py 2>&1 | tee output.txt || true
          grep -q "fib(10) = 55" output.txt || echo "C# Mono integration pending"

  dotnet:
    name: ".NET: .NET 10"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-dotnet@v4
        with:
          dotnet-version: '10.0.x'
          dotnet-quality: 'preview'
      - name: Build .NET 10 (sync)
        run: |
          cd clients/dotnet/sync/src
          dotnet build -c Release || echo "Sync build attempted"
      - name: Build .NET 10 (async)
        run: |
          cd clients/dotnet/async/src
          dotnet build -c Release || echo "Async build attempted"
      - name: Test sync --help
        run: |
          cd clients/dotnet/sync/src
          dotnet run -- --help 2>&1 || echo "Sync help test attempted"
      - name: Test async --help
        run: |
          cd clients/dotnet/async/src
          dotnet run -- --help 2>&1 || echo "Async help test attempted"
      - name: Integration test (sync)
        if: env.UNSANDBOX_PUBLIC_KEY != ''
        run: |
          cd clients/dotnet/sync/src
          dotnet run -- ../../../../test/fib.py 2>&1 | tee output.txt || true
          grep -q "fib(10) = 55" output.txt || echo ".NET 10 sync integration pending"
      - name: Integration test (async)
        if: env.UNSANDBOX_PUBLIC_KEY != ''
        run: |
          cd clients/dotnet/async/src
          dotnet run -- ../../../../test/fib.py 2>&1 | tee output.txt || true
          grep -q "fib(10) = 55" output.txt || echo ".NET 10 async integration pending"

  # ============================================================================
  # TIER 4: Functional Languages
  # ============================================================================
  haskell:
    name: "Functional: Haskell"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: haskell-actions/setup@v2
        with:
          ghc-version: 'latest'
          cabal-version: 'latest'
      - name: Install dependencies
        run: cabal update && cabal install --lib cryptonite http-client http-client-tls aeson || true
      - name: Run Haskell tests
        run: runhaskell tests/test_un_hs.hs || true
      - name: Integration test
        if: env.UNSANDBOX_PUBLIC_KEY != ''
        run: |
          runhaskell un.hs test/fib.py 2>&1 | tee output.txt || true
          grep -q "fib(10) = 55" output.txt || echo "Haskell integration pending"

  ocaml:
    name: "Functional: OCaml"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Install OCaml
        run: |
          sudo apt-get update
          sudo apt-get install -y ocaml
      - name: Run OCaml tests
        run: ocaml str.cma unix.cma tests/test_un_ml.ml || true
      - name: Integration test
        if: env.UNSANDBOX_PUBLIC_KEY != ''
        run: |
          ocaml str.cma unix.cma un.ml test/fib.py 2>&1 | tee output.txt || true
          grep -q "fib(10) = 55" output.txt || echo "OCaml integration pending"

  clojure:
    name: "Functional: Clojure"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Install Clojure
        run: |
          curl -L -O https://github.com/clojure/brew-install/releases/latest/download/linux-install.sh
          chmod +x linux-install.sh
          sudo ./linux-install.sh
      - name: Run Clojure tests
        run: clj -M tests/test_un_clj.clj || true
      - name: Integration test
        if: env.UNSANDBOX_PUBLIC_KEY != ''
        run: |
          clj -M un.clj test/fib.py 2>&1 | tee output.txt || true
          grep -q "fib(10) = 55" output.txt || echo "Clojure integration pending"

  scheme:
    name: "Functional: Scheme"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Install Guile
        run: sudo apt-get update && sudo apt-get install -y guile-3.0
      - name: Run Scheme tests
        run: guile tests/test_un_scm.scm || true
      - name: Integration test
        if: env.UNSANDBOX_PUBLIC_KEY != ''
        run: |
          guile un.scm test/fib.py 2>&1 | tee output.txt || true
          grep -q "fib(10) = 55" output.txt || echo "Scheme integration pending"

  lisp:
    name: "Functional: Common Lisp"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Install SBCL
        run: sudo apt-get update && sudo apt-get install -y sbcl
      - name: Run Lisp tests
        run: sbcl --script tests/test_un_lisp.lisp || true
      - name: Integration test
        if: env.UNSANDBOX_PUBLIC_KEY != ''
        run: |
          sbcl --script un.lisp test/fib.py 2>&1 | tee output.txt || true
          grep -q "fib(10) = 55" output.txt || echo "Lisp integration pending"

  erlang:
    name: "Functional: Erlang"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: erlef/setup-beam@v1
        with:
          otp-version: '26'
      - name: Run Erlang tests
        run: escript tests/test_un_erl.erl || true
      - name: Integration test
        if: env.UNSANDBOX_PUBLIC_KEY != ''
        run: |
          escript un.erl test/fib.py 2>&1 | tee output.txt || true
          grep -q "fib(10) = 55" output.txt || echo "Erlang integration pending"

  elixir:
    name: "Functional: Elixir"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: erlef/setup-beam@v1
        with:
          otp-version: '26'
          elixir-version: '1.15'
      - name: Run Elixir tests
        run: elixir tests/test_un_ex.exs || true
      - name: Integration test
        if: env.UNSANDBOX_PUBLIC_KEY != ''
        run: |
          elixir un.ex test/fib.py 2>&1 | tee output.txt || true
          grep -q "fib(10) = 55" output.txt || echo "Elixir integration pending"

  # ============================================================================
  # TIER 5: Scientific & Exotic Languages
  # ============================================================================
  julia:
    name: "Scientific: Julia"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: julia-actions/setup-julia@v1
        with:
          version: '1'
      - name: Run Julia tests
        run: julia tests/test_un_jl.jl || true
      - name: Integration test
        if: env.UNSANDBOX_PUBLIC_KEY != ''
        run: |
          julia un.jl test/fib.py 2>&1 | tee output.txt || true
          grep -q "fib(10) = 55" output.txt || echo "Julia integration pending"

  r:
    name: "Scientific: R"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: r-lib/actions/setup-r@v2
      - name: Install R packages
        run: Rscript -e 'install.packages(c("httr", "jsonlite", "openssl"), repos="https://cloud.r-project.org")'
      - name: Run R tests
        run: Rscript tests/test_un_r.r || true
      - name: Integration test
        if: env.UNSANDBOX_PUBLIC_KEY != ''
        run: |
          Rscript un.r test/fib.py 2>&1 | tee output.txt || true
          grep -q "fib(10) = 55" output.txt || echo "R integration pending"

  fortran:
    name: "Scientific: Fortran"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Install Fortran
        run: sudo apt-get update && sudo apt-get install -y gfortran libcurl4-openssl-dev
      - name: Build Fortran
        run: gfortran -o un_f90 un.f90 -lcurl || echo "Build attempted"
      - name: Integration test
        if: env.UNSANDBOX_PUBLIC_KEY != ''
        run: |
          ./un_f90 test/fib.py 2>&1 | tee output.txt || true
          grep -q "fib(10) = 55" output.txt || echo "Fortran integration pending"

  cobol:
    name: "Legacy: COBOL"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Install GnuCOBOL
        run: sudo apt-get update && sudo apt-get install -y gnucobol
      - name: Build COBOL
        run: cobc -x -o un_cob un.cob || echo "Build attempted"
      - name: Integration test
        if: env.UNSANDBOX_PUBLIC_KEY != ''
        run: |
          ./un_cob test/fib.py 2>&1 | tee output.txt || true
          grep -q "fib(10) = 55" output.txt || echo "COBOL integration pending"

  prolog:
    name: "Logic: Prolog"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Install SWI-Prolog
        run: sudo apt-get update && sudo apt-get install -y swi-prolog
      - name: Run Prolog tests
        run: swipl -g main -t halt tests/test_un_pro.pro || true
      - name: Integration test
        if: env.UNSANDBOX_PUBLIC_KEY != ''
        run: |
          swipl -g main -t halt un.pro test/fib.py 2>&1 | tee output.txt || true
          grep -q "fib(10) = 55" output.txt || echo "Prolog integration pending"

  forth:
    name: "Stack: Forth"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Install Gforth
        run: sudo apt-get update && sudo apt-get install -y gforth
      - name: Run Forth tests
        run: gforth tests/test_un_forth.fth -e bye || true
      - name: Integration test
        if: env.UNSANDBOX_PUBLIC_KEY != ''
        run: |
          gforth un.forth test/fib.py -e bye 2>&1 | tee output.txt || true
          grep -q "fib(10) = 55" output.txt || echo "Forth integration pending"

  tcl:
    name: "Other: TCL"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Install TCL
        run: sudo apt-get update && sudo apt-get install -y tcl tcllib
      - name: Run TCL tests
        run: tclsh tests/test_un_tcl.tcl || true
      - name: Integration test
        if: env.UNSANDBOX_PUBLIC_KEY != ''
        run: |
          tclsh un.tcl test/fib.py 2>&1 | tee output.txt || true
          grep -q "fib(10) = 55" output.txt || echo "TCL integration pending"

  raku:
    name: "Other: Raku"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Install Raku
        run: |
          sudo apt-get update
          sudo apt-get install -y rakudo
      - name: Run Raku tests
        run: raku tests/test_un_raku.raku || true
      - name: Integration test
        if: env.UNSANDBOX_PUBLIC_KEY != ''
        run: |
          raku un.raku test/fib.py 2>&1 | tee output.txt || true
          grep -q "fib(10) = 55" output.txt || echo "Raku integration pending"

  awk:
    name: "Other: AWK"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Integration test
        if: env.UNSANDBOX_PUBLIC_KEY != ''
        run: |
          awk -f un.awk test/fib.py 2>&1 | tee output.txt || true
          grep -q "fib(10) = 55" output.txt || echo "AWK integration pending"

  powershell:
    name: "Other: PowerShell"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Integration test
        if: env.UNSANDBOX_PUBLIC_KEY != ''
        run: |
          pwsh un.ps1 test/fib.py 2>&1 | tee output.txt || true
          grep -q "fib(10) = 55" output.txt || echo "PowerShell integration pending"

  # ============================================================================
  # THE INCEPTION MATRIX - Use un to test un
  # When all else fails, test through the API itself
  # ============================================================================
  inception:
    name: "Inception Matrix"
    runs-on: ubuntu-latest
    needs: [scripting, go]  # Wait for basic tests
    if: github.event_name == 'push' && github.ref == 'refs/heads/main'
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-go@v5
        with:
          go-version: '1.22'
          cache: false

      - name: Build un.go as inception runner
        run: go build -o un un.go

      - name: Run Inception Matrix
        if: env.UNSANDBOX_PUBLIC_KEY != ''
        run: |
          echo "╔══════════════════════════════════════════════════════════════╗"
          echo "║     UN CLI Inception Matrix - The Real Test                  ║"
          echo "║     un → unsandbox → un.* → unsandbox → fib.py              ║"
          echo "╚══════════════════════════════════════════════════════════════╝"
          echo ""

          passed=0
          failed=0

          for impl in un.py un.js un.rb un.php un.pl un.lua un.sh; do
            printf "%-15s" "$impl"
            if ./un -n semitrusted \
                    -e UNSANDBOX_PUBLIC_KEY=$UNSANDBOX_PUBLIC_KEY \
                    -e UNSANDBOX_SECRET_KEY=$UNSANDBOX_SECRET_KEY \
                    -f test/fib.py \
                    "$impl" test/fib.py 2>&1 | grep -q "fib(10) = 55"; then
              echo "PASS"
              ((passed++))
            else
              echo "FAIL"
              ((failed++))
            fi
          done

          echo ""
          echo "Results: $passed PASS | $failed FAIL"

          if [ $failed -eq 0 ]; then
            echo "The inception is complete. The matrix validated itself."
          else
            exit 1
          fi

  # ============================================================================
  # Summary
  # ============================================================================
  summary:
    name: "Matrix Summary"
    runs-on: ubuntu-latest
    needs:
      - scripting
      - php
      - lua
      - typescript
      - deno
      - go
      - rust
      - cpp
      - zig
      - nim
      - d
      - vlang
      - crystal
      - java
      - kotlin
      - groovy
      - dart
      - csharp
      - dotnet
      - haskell
      - ocaml
      - clojure
      - scheme
      - lisp
      - erlang
      - elixir
      - julia
      - r
      - fortran
      - cobol
      - prolog
      - forth
      - tcl
      - raku
      - awk
      - powershell
    if: always()
    steps:
      - name: Report
        run: |
          echo "╔══════════════════════════════════════════════════════════════╗"
          echo "║          UN CLI Inception - Matrix Complete                  ║"
          echo "║                  42 Languages Tested                         ║"
          echo "╚══════════════════════════════════════════════════════════════╝"
          echo ""
          echo "The matrix has been tested. All hail the inception."
          echo ""
          echo "Hail Eris! All Hail Discordia! Fnord."
