# justfile for content-addressable.
#
# `just check` runs the full local gate (fmt + clippy + test + doc + leaf), the
# same steps enforced by .githooks/pre-push and .github/workflows/ci.yml. The
# `leaf` step (issue #13) guards the published core's leaf invariant. The CI-only
# `msrv` (1.85) and `python` (PyO3) jobs are intentionally not in `check` — see
# the pre-push hook header for the rationale. Run the MSRV build with `just msrv`.

# Run the full local check suite: format, lint, test, doc, leaf guard.
check: fmt clippy test doc leaf

# Verify the three package version declarations agree (root Cargo.toml,
# content-addressable-py/Cargo.toml, pyproject.toml) via the canonical tool. With
# a tag it also asserts the tag is v<version>. This is the SINGLE source of the
# SemVer<->PEP 440 mapping (no second copy in YAML/shell); the CI release gate
# calls this same recipe. Kept out of `check` so a push never requires Python
# (same posture as the CI-only `msrv`/`python` jobs — see the pre-push header).
#   just verify-release            # drift guard: the three versions agree
#   just verify-release v0.1.0     # release: also assert the tag matches
verify-release tag="":
    #!/usr/bin/env bash
    set -euo pipefail
    if [ -n "{{ tag }}" ]; then
      python3 scripts/verify_release.py --tag "{{ tag }}"
    else
      python3 scripts/verify_release.py
    fi

# Verify formatting (does not modify files).
fmt:
    cargo fmt -- --check

# Lint with all warnings denied. `--all-features` compiles the default-OFF
# `unstable-merkle` feature so its lints are checked too.
clippy:
    cargo clippy --all-targets --all-features -- -D warnings

# Run all tests (unit + doctests). Plain `cargo test` includes doctests, which
# `--all-targets` would skip. The `--all-features` pass exercises the default-OFF
# `unstable-merkle` feature; the plain pass proves it stays off by default.
test:
    cargo test
    cargo test --all-features

# Build the docs with broken intra-doc links denied (mirrors the CI `doc` job).
doc:
    RUSTDOCFLAGS="-D warnings" cargo doc --no-deps --all-features

# Assert the published core crate is a true leaf — its resolved dependency
# closure must be registry-only (no path/git/workspace edges) so any repo can
# depend on it without cycles (issue #13). Mirrors the CI `leaf-deps` job and
# the pre-push hook; reads only `cargo metadata`, so it is fast and offline.
leaf:
    ./scripts/check-leaf-deps.sh

# Build + test on the pinned MSRV (1.85). Mirrors the CI-only `msrv` job; run it
# manually since installing a second toolchain is too heavy for the push hook.
msrv:
    rustup toolchain install 1.85 --profile minimal
    cargo +1.85 build --all-targets --all-features
    cargo +1.85 test --all-features

# Apply rustfmt in place.
fmt-fix:
    cargo fmt

# Install the repo-local git hooks (pre-push).
install-hooks:
    git config core.hooksPath .githooks
    @echo "git hooks installed (core.hooksPath = .githooks)"
