ghidra-cli 0.1.10

Rust CLI to run Ghidra headless for reverse engineering with Claude Code and other agents
Documentation
name: Test

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

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

env:
  CARGO_TERM_COLOR: always

jobs:
  # Job 1: Unit tests and CLI tests (no Ghidra needed) - ~2 min
  unit-and-cli:
    runs-on: ${{ matrix.os }}
    timeout-minutes: 15
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest, macos-latest, windows-latest]

    steps:
      - uses: actions/checkout@v4

      - name: Install Rust toolchain
        uses: dtolnay/rust-toolchain@stable

      - name: Cache Rust
        uses: Swatinem/rust-cache@v2

      - name: Build
        run: cargo build --verbose

      - name: Build test fixture
        run: rustc --edition 2021 -o tests/fixtures/sample_binary tests/fixtures/sample_binary.rs

      - name: Run unit tests
        run: cargo test --lib --verbose

      - name: Run CLI tests
        run: cargo test --test e2e --test output_format_integration --verbose

  # Job 2: Ghidra setup - installs Ghidra and creates test projects to seed caches.
  # This runs once per OS, then test jobs use the cached artifacts.
  ghidra-setup:
    runs-on: ${{ matrix.os }}
    timeout-minutes: 90
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest, macos-latest, windows-latest]

    steps:
      - uses: actions/checkout@v4

      - name: Install Java 21
        uses: actions/setup-java@v4
        with:
          distribution: 'temurin'
          java-version: '21'

      - name: Install Rust toolchain
        uses: dtolnay/rust-toolchain@stable

      - name: Cache Rust
        uses: Swatinem/rust-cache@v2

      - name: Cache Ghidra installation and config
        id: ghidra-cache
        uses: actions/cache@v4
        with:
          path: |
            ~/.local/share/ghidra-cli
            ~/.config/ghidra-cli
            ~/Library/Application Support/ghidra-cli
            ~/Library/Preferences/ghidra-cli
            ~/AppData/Local/ghidra-cli
            ~/AppData/Roaming/ghidra-cli
          key: ghidra-${{ matrix.os }}-v5

      - name: Cache Ghidra projects
        id: project-cache
        uses: actions/cache@v4
        with:
          path: |
            ~/.cache/ghidra-cli/projects
            ~/Library/Caches/ghidra-cli/projects
            ~/AppData/Local/ghidra-cli/projects
          key: ghidra-projects-${{ matrix.os }}-v4-${{ hashFiles('tests/fixtures/sample_binary.rs') }}

      - name: Build
        run: cargo build --verbose

      - name: Build test fixture
        run: rustc --edition 2021 -o tests/fixtures/sample_binary tests/fixtures/sample_binary.rs

      - name: Setup Ghidra (skip if cached)
        run: |
          DOCTOR_OUTPUT=$(cargo run -- doctor 2>&1 || true)
          echo "$DOCTOR_OUTPUT"
          if echo "$DOCTOR_OUTPUT" | grep -q "analyzeHeadless: OK"; then
            echo "Ghidra already installed (cache hit), skipping setup"
          else
            echo "Ghidra not found, running setup..."
            cargo run -- setup
          fi
        shell: bash
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

      - name: Create test project (skip if cached)
        run: |
          cargo run -- import tests/fixtures/sample_binary --project ci-test --program sample_binary || true
          cargo run -- analyze --project ci-test --program sample_binary || true
        shell: bash
        timeout-minutes: 20

  # Job 3: Read-only integration tests (one bridge)
  readonly-integration:
    needs: ghidra-setup
    if: ${{ !cancelled() }}
    runs-on: ${{ matrix.os }}
    timeout-minutes: 90
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest, macos-latest, windows-latest]

    steps:
      - uses: actions/checkout@v4

      - name: Install Java 21
        uses: actions/setup-java@v4
        with:
          distribution: 'temurin'
          java-version: '21'

      - name: Install Rust toolchain
        uses: dtolnay/rust-toolchain@stable

      - name: Cache Rust
        uses: Swatinem/rust-cache@v2

      - name: Restore Ghidra installation and config
        uses: actions/cache@v4
        with:
          path: |
            ~/.local/share/ghidra-cli
            ~/.config/ghidra-cli
            ~/Library/Application Support/ghidra-cli
            ~/Library/Preferences/ghidra-cli
            ~/AppData/Local/ghidra-cli
            ~/AppData/Roaming/ghidra-cli
          key: ghidra-${{ matrix.os }}-v5

      - name: Restore Ghidra projects
        uses: actions/cache@v4
        with:
          path: |
            ~/.cache/ghidra-cli/projects
            ~/Library/Caches/ghidra-cli/projects
            ~/AppData/Local/ghidra-cli/projects
          key: ghidra-projects-${{ matrix.os }}-v4-${{ hashFiles('tests/fixtures/sample_binary.rs') }}

      - name: Build
        run: cargo build --verbose

      - name: Build test fixture
        run: rustc --edition 2021 -o tests/fixtures/sample_binary tests/fixtures/sample_binary.rs

      - name: Setup Ghidra (fallback if cache missed)
        run: |
          DOCTOR_OUTPUT=$(cargo run -- doctor 2>&1 || true)
          echo "$DOCTOR_OUTPUT"
          if echo "$DOCTOR_OUTPUT" | grep -q "analyzeHeadless: OK"; then
            echo "Ghidra already installed (cache hit)"
          else
            echo "Cache miss, running setup..."
            cargo run -- setup
          fi
        shell: bash
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

      - name: Run read-only integration tests
        run: cargo test --test readonly_tests --test command_tests --verbose -- --nocapture
        timeout-minutes: 80
        env:
          RUST_LOG: info

  # Job 4: Mutation tests (parallel with job 3)
  mutation-integration:
    needs: ghidra-setup
    if: ${{ !cancelled() }}
    runs-on: ${{ matrix.os }}
    timeout-minutes: 90
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest, macos-latest, windows-latest]

    steps:
      - uses: actions/checkout@v4

      - name: Install Java 21
        uses: actions/setup-java@v4
        with:
          distribution: 'temurin'
          java-version: '21'

      - name: Install Rust toolchain
        uses: dtolnay/rust-toolchain@stable

      - name: Cache Rust
        uses: Swatinem/rust-cache@v2

      - name: Restore Ghidra installation and config
        uses: actions/cache@v4
        with:
          path: |
            ~/.local/share/ghidra-cli
            ~/.config/ghidra-cli
            ~/Library/Application Support/ghidra-cli
            ~/Library/Preferences/ghidra-cli
            ~/AppData/Local/ghidra-cli
            ~/AppData/Roaming/ghidra-cli
          key: ghidra-${{ matrix.os }}-v5

      - name: Restore Ghidra projects
        uses: actions/cache@v4
        with:
          path: |
            ~/.cache/ghidra-cli/projects
            ~/Library/Caches/ghidra-cli/projects
            ~/AppData/Local/ghidra-cli/projects
          key: ghidra-projects-${{ matrix.os }}-v4-${{ hashFiles('tests/fixtures/sample_binary.rs') }}

      - name: Build
        run: cargo build --verbose

      - name: Build test fixture
        run: rustc --edition 2021 -o tests/fixtures/sample_binary tests/fixtures/sample_binary.rs

      - name: Setup Ghidra (fallback if cache missed)
        run: |
          DOCTOR_OUTPUT=$(cargo run -- doctor 2>&1 || true)
          echo "$DOCTOR_OUTPUT"
          if echo "$DOCTOR_OUTPUT" | grep -q "analyzeHeadless: OK"; then
            echo "Ghidra already installed (cache hit)"
          else
            echo "Cache miss, running setup..."
            cargo run -- setup
          fi
        shell: bash
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

      - name: Run mutation integration tests
        run: cargo test --test comment_tests --test symbol_tests --test patch_tests --test type_tests --test script_tests --verbose -- --nocapture
        timeout-minutes: 80
        env:
          RUST_LOG: info

  # Job 5: Infrastructure tests (parallel with jobs 3+4)
  infrastructure:
    needs: ghidra-setup
    if: ${{ !cancelled() }}
    runs-on: ${{ matrix.os }}
    timeout-minutes: 90
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest, macos-latest, windows-latest]

    steps:
      - uses: actions/checkout@v4

      - name: Install Java 21
        uses: actions/setup-java@v4
        with:
          distribution: 'temurin'
          java-version: '21'

      - name: Install Rust toolchain
        uses: dtolnay/rust-toolchain@stable

      - name: Cache Rust
        uses: Swatinem/rust-cache@v2

      - name: Restore Ghidra installation and config
        uses: actions/cache@v4
        with:
          path: |
            ~/.local/share/ghidra-cli
            ~/.config/ghidra-cli
            ~/Library/Application Support/ghidra-cli
            ~/Library/Preferences/ghidra-cli
            ~/AppData/Local/ghidra-cli
            ~/AppData/Roaming/ghidra-cli
          key: ghidra-${{ matrix.os }}-v5

      - name: Restore Ghidra projects
        uses: actions/cache@v4
        with:
          path: |
            ~/.cache/ghidra-cli/projects
            ~/Library/Caches/ghidra-cli/projects
            ~/AppData/Local/ghidra-cli/projects
          key: ghidra-projects-${{ matrix.os }}-v4-${{ hashFiles('tests/fixtures/sample_binary.rs') }}

      - name: Build
        run: cargo build --verbose

      - name: Build test fixture
        run: rustc --edition 2021 -o tests/fixtures/sample_binary tests/fixtures/sample_binary.rs

      - name: Setup Ghidra (fallback if cache missed)
        run: |
          DOCTOR_OUTPUT=$(cargo run -- doctor 2>&1 || true)
          echo "$DOCTOR_OUTPUT"
          if echo "$DOCTOR_OUTPUT" | grep -q "analyzeHeadless: OK"; then
            echo "Ghidra already installed (cache hit)"
          else
            echo "Cache miss, running setup..."
            cargo run -- setup
          fi
        shell: bash
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

      - name: Run infrastructure tests
        run: cargo test --test daemon_tests --test reliability_tests --test project_tests --verbose -- --nocapture
        timeout-minutes: 80
        env:
          RUST_LOG: info