#!/bin/sh # Judges the same histories with continuum as a federation tag names it and with this # tree, and says where they differ (docs/federation-tests.md: Against released # revisions). Each release that makes a revision of the federation is tagged # federation-., the federation's number and the revision's (federation-1.1 for # revision 1 of federation 1); a later one judges every history under the revisions that # release knows as it did. Run before a release, from a checkout with its tags. # # scripts/federation-check [TAG] # # TAG is the latest federation-. unless given. The histories: of each # revision and kind, generated from CONTINUUM_TEST_SEED on (a random one, said, unless # given), CONTINUUM_TEST_CASES times as many as `write_histories` writes; and those the # attack tests offer. CONTINUUM_FEATURES are the features both are built with, a # transport among them (federation,mycelium unless given); the tag's build is kept in # CONTINUUM_CHECK_TARGET (~/.cache/continuum/federation-check unless given) for the # next run. set -eu cd "$(git rev-parse --show-toplevel)" tag=${1:-$(git tag --list 'federation-[0-9]*.[0-9]*' --sort=-version:refname | head -n 1)} if [ -z "$tag" ]; then echo "federation-check: no federation-. tag to check against" >&2 exit 2 fi features=${CONTINUUM_FEATURES:-federation,mycelium} seed=${CONTINUUM_TEST_SEED:-$(od -An -N4 -tu4 /dev/urandom | tr -d ' ')} cache=${XDG_CACHE_HOME:-$HOME/.cache} target=${CONTINUUM_CHECK_TARGET:-$cache/continuum/federation-check} work=$(mktemp -d) clean() { git worktree remove --force "$work/tagged" >/dev/null 2>&1 || true rm -rf "$work" } trap clean EXIT trap 'exit 130' INT TERM echo "federation-check: $tag against this tree, histories from seed $seed" >&2 echo "federation-check: CONTINUUM_TEST_SEED=$seed reruns them" >&2 CONTINUUM_HISTORIES="$work/histories" CONTINUUM_TEST_SEED=$seed \ cargo test -q --features "$features" --lib write_histories -- --ignored >&2 cargo run -q --features "$features" --bin continuum-party -- judge \ <"$work/histories" >"$work/here" git worktree add -q --detach "$work/tagged" "$tag" (cd "$work/tagged" && CARGO_TARGET_DIR=$target \ cargo run -q --features "$features" --bin continuum-party -- judge) \ <"$work/histories" >"$work/there" # Histories whose root the tag's continuum reads as none, of a revision after it, it # doesn't judge: left out on both sides. awk '/^case /{label=substr($0, 6)} $0 == "root none"{print label}' "$work/there" \ >"$work/unread" keep() { awk -v unread="$work/unread" ' BEGIN { while ((getline line < unread) > 0) skip[line] = 1 } /^case / { label = substr($0, 6) } !(label in skip) ' "$1" } keep "$work/there" >"$work/there.kept" keep "$work/here" >"$work/here.kept" judged=$(grep -c '^case ' "$work/there.kept" || true) left=$(wc -l <"$work/unread" | tr -d ' ') if diff -u --label "$tag" --label "this tree" "$work/there.kept" "$work/here.kept" \ >"$work/differ"; then echo "federation-check: $judged histories judged alike" \ "($left of revisions after $tag left out)" else head -n 200 "$work/differ" echo "federation-check: this tree judges otherwise than $tag (seed $seed): above" >&2 exit 1 fi