name: Miri Unit Tests

on:
  workflow_call:

jobs:
  test:
    name: Miri Tests
    runs-on: ubuntu-latest
    steps:
      - name: Checkout the repository
        uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6
        with:
          fetch-depth: 1
      - name: Install Rust toolchain with Miri
        uses: dtolnay/rust-toolchain@e97e2d8cc328f1b50210efc529dca0028893a2d9 # v1
        with:
          components: miri, rust-src
          toolchain: nightly
      - name: Install Protoc
        uses: arduino/setup-protoc@c65c819552d16ad3c9b72d9dfd5ba5237b9c906b # v3
        with:
          repo-token: ${{ github.token }}
      - name: Cache cargo registry, index, and targets
        uses: Swatinem/rust-cache@779680da715d629ac1d338a641029a2f4372abb5 # v2
        with:
          prefix-key: "cargo-miri"
      - name: Download Cargo.lock
        uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7
        with:
          name: lockfile
          path: .
      - name: Run Miri tests
        run: |
          RUST_BACKTRACE=1 \
          MIRIFLAGS="-Zmiri-backtrace=full" \
          cargo +nightly miri test --all --locked --all-features --verbose
        shell: bash
