#!/usr/bin/env bash
set -euo pipefail

if [[ -z "${IN_NIX_SHELL:-}" ]] && command -v nix >/dev/null 2>&1; then
  exec nix develop -c "$0" "$@"
fi

export LIBCLANG_PATH=${LIBCLANG_PATH:-/nix/store/0zn99g048j67syaq97rczq5z0j8dsvc8-clang-21.1.2-lib/lib}

echo "[verify] formatting..."
if ! find . \
  -path ./target -prune -o \
  -name '*.rs' -print0 | xargs -0 rustfmt --check; then
  echo "[verify] rustfmt drift detected; continuing with runtime tests" >&2
fi

echo "[verify] running FlareDB server tests..."
cargo test -p flaredb-server --tests

echo "[verify] running FlareDB raft tests..."
cargo test -p flaredb-raft

echo "[verify] done."
