#!/usr/bin/env bash
# PIPELINE PARITY: mirrors the cargo fmt/clippy/test/doc jobs AND the
# `leaf-deps` job in .github/workflows/ci.yml. When editing this file, verify it
# still matches the CI pipeline; do not bypass it with --no-verify.
#
# DOCUMENTED EXCEPTIONS — two CI jobs are deliberately NOT run here:
#   - `msrv` (build+test on dtolnay/rust-toolchain@1.85): installing a second
#     toolchain on every push is too heavy for a fast hook, so the MSRV floor is
#     guarded CI-only (issue #9, gate item #10). The declared floor lives in
#     Cargo.toml's `rust-version`, which the hook respects implicitly. Run the
#     MSRV build locally with: rustup toolchain install 1.85 &&
#     cargo +1.85 test --all-features
#   - `python` (maturin build + pytest for the PyO3 face): building the
#     extension module on every push is too heavy/fragile for a fast hook (same
#     rationale kyln uses to keep its p4d suite out of the hook). Run it locally
#     with: maturin develop -m content-addressable-py/Cargo.toml && pytest
# The `doc` and `leaf-deps` jobs ARE mirrored below (rustdoc is cheap;
# `leaf-deps` only reads `cargo metadata`, so it is fast and offline — true
# parity, not an exception).
set -euo pipefail

echo "==> cargo fmt --check"
cargo fmt -- --check

echo "==> cargo clippy --all-targets --all-features -- -D warnings"
cargo clippy --all-targets --all-features -- -D warnings

echo "==> cargo test (default features — proves the unstable-merkle feature stays off)"
cargo test

# --all-features compiles + tests the default-OFF `unstable-merkle` feature
# (src/merkle.rs / MerkleNode), mirroring the CI `test` job.
echo "==> cargo test --all-features (exercises the unstable-merkle feature)"
cargo test --all-features

# Mirrors the CI `doc` job: `-D warnings` turns broken intra-doc links into a
# hard failure so doc rot can't return (issue #9 — API-surface hygiene).
echo "==> RUSTDOCFLAGS=-D warnings cargo doc --no-deps --all-features"
RUSTDOCFLAGS="-D warnings" cargo doc --no-deps --all-features

# Mirrors the CI `leaf-deps` job: assert the published core crate's resolved
# dependency closure is registry-only (no path/git deps) so it stays a true,
# publishable leaf (issue #13). Reads only `cargo metadata` — fast and offline.
echo "==> ./scripts/check-leaf-deps.sh (published core is a true leaf)"
"$(git rev-parse --show-toplevel)/scripts/check-leaf-deps.sh"

echo "pre-push checks passed."
