#!/usr/bin/env bash # Fetches the Merkle search tree diff test suite, which is not vendored. # # Upstream is , MIT. It is # 16,384 test cases in 16,384 JSON files and 24MB, and unlike the interop # vectors beside it — 96kB, and vendored under vendor/ — it is far too large # to carry in this repository. So it is cloned, and the conformance runner # fails with a pointer to this script when it is not there. # # # It is cached per machine, not per checkout # # The corpus is immutable upstream test data. Nothing about it varies with the # branch you are on, and this project is worked from several worktrees at once # — each one used to want its own 72MB copy, and each new one failed four tests # until somebody ran this. So it lives under `$XDG_CACHE_HOME/didbot/`, # beside the configuration in `$XDG_CONFIG_HOME/didbot/` and the state in # `$XDG_STATE_HOME/didbot/` that the rest of this project already keeps # there. # # A clone left in a checkout's own `.cache/` from before that is moved here on # the first run rather than re-downloaded. # # # Updating is deliberate # # One clone is shared by every checkout on the machine, so a plain run that # fast-forwarded it would move the corpus under whatever else is reading it. A # corpus that is already there is therefore left alone and reported. Pass # `--update`, or a ref, to change it on purpose. set -euo pipefail UPSTREAM="https://github.com/DavidBuchanan314/mst-test-suite.git" cd "$(dirname "$0")/.." # Where the runner looks. Kept in step with `suite_dir` in # `crates/didbot/tests/conformance/mst_vectors.rs`, and checked against it # by `the_fetch_script_and_the_runner_agree_on_where_the_corpus_is`. cache_home="${XDG_CACHE_HOME:-$HOME/.cache}" dest="$cache_home/didbot/mst-test-suite" # What a checkout used to keep, and may still. legacy=".cache/mst-test-suite" update=0 ref="" for arg in "$@"; do case "$arg" in --update) update=1 ;; -*) echo "unknown option: $arg" >&2; exit 2 ;; *) ref="$arg"; update=1 ;; esac done if [ -d "$legacy/.git" ] && [ ! -d "$dest/.git" ]; then echo "moving $legacy to $dest" mkdir -p "$(dirname "$dest")" mv "$legacy" "$dest" fi if [ -d "$dest/.git" ] && [ "$update" -eq 0 ]; then commit="$(git -C "$dest" rev-parse HEAD)" cases="$(find "$dest/tests" -name '*.json' 2>/dev/null | wc -l)" echo "$dest is at $commit: $cases cases" echo " already there; --update to move it, which every checkout on this machine shares" exit 0 fi ref="${ref:-HEAD}" if [ -d "$dest/.git" ]; then echo "updating $dest to $ref" git -C "$dest" fetch --quiet --depth 1 origin "$ref" else echo "cloning $UPSTREAM into $dest" mkdir -p "$dest" git init --quiet "$dest" git -C "$dest" remote add origin "$UPSTREAM" git -C "$dest" fetch --quiet --depth 1 origin "$ref" fi git -C "$dest" checkout --quiet FETCH_HEAD commit="$(git -C "$dest" rev-parse HEAD)" cases="$(find "$dest/tests" -name '*.json' | wc -l)" echo "$dest is at $commit: $cases cases"