Files
stack/scripts/test-queue.sh
T
2026-10-21 13:28:40 -05:00

86 lines
3.8 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
# Suite for packages/queue (issue #1508). Every test runs in scratch
# repositories under the system temp directory; nothing touches this
# checkout's .git, lock, witness or queue files.
#
# scripts/test-queue.sh full run
# NO_COLOR=1 scripts/test-queue.sh plain output
#
# Once HEAD holds docs/plans/queue.json (the genesis commit), the suite also
# runs `verify` and `render --check` on the live queue through
# `scripts/mosaic queue`. Each takes the queue lock for a moment and writes
# nothing. Before genesis, or in a checkout that is not the queue's
# canonicalRoot (an export or a review clone), it skips them and says why;
# `scripts/mosaic queue help` still runs, reading no queue file and taking no
# lock.
set -uo pipefail
cd "$(dirname "$0")/.."
SANDBOX="$(mktemp -d)"
trap 'rm -rf "$SANDBOX"' EXIT
PASS=0
FAIL=0
if [ -t 1 ] && [ -z "${NO_COLOR:-}" ]; then
C_OK=$'\033[0;32m'; C_FAIL=$'\033[0;31m'; C_RESET=$'\033[0m'
else
C_OK=""; C_FAIL=""; C_RESET=""
fi
check() {
if [ "$2" = "0" ]; then PASS=$((PASS+1)); echo "${C_OK}OK${C_RESET} $1"; else FAIL=$((FAIL+1)); echo "${C_FAIL}FAIL${C_RESET} $1"; fi
}
echo "toolchain: node $(node --version), $(git --version)"
echo
# --- syntax ---
for f in packages/queue/src/*.mjs packages/queue/tests/*.mjs packages/queue/tests/fixtures/*.mjs packages/queue/tests/fixtures/*.sh scripts/queue-commit.sh scripts/git-hooks/pre-commit scripts/mosaic; do
case "$f" in
*.sh|scripts/mosaic) bash -n "$f" >/dev/null 2>&1 ;;
*/pre-commit) sh -n "$f" >/dev/null 2>&1 ;;
*) node --check "$f" >/dev/null 2>&1 ;;
esac
check "syntax: $f" $?
done
[ -x scripts/queue-commit.sh ] && [ -x scripts/git-hooks/pre-commit ] && [ -x scripts/mosaic ]
check "queue-commit.sh, the guard and scripts/mosaic are executable" $?
node -e 'const p=require("./packages/queue/package.json"); process.exit(p.dependencies||p.devDependencies?1:0)' >/dev/null 2>&1
check "packages/queue declares no dependencies" $?
# --- the package tests ---
lane_concurrency=()
if [ -n "${MOSAIC_TEST_CONCURRENCY:-}" ]; then
[ "$MOSAIC_TEST_CONCURRENCY" = 2 ] || exit 2
lane_concurrency=(--test-concurrency=2)
fi
env -u NODE_TEST_CONTEXT node --test "${lane_concurrency[@]}" --test-reporter=spec packages/queue/tests/ > "$SANDBOX/tests.log" 2>&1
rc=$?
grep -E '^ℹ (tests|pass|fail) ' "$SANDBOX/tests.log"
if [ "$rc" != 0 ]; then grep -E '^✖|Error' "$SANDBOX/tests.log" | head -40; fi
check "node --test packages/queue/tests/" "$rc"
# --- the dispatch, then the live queue once genesis is committed ---
scripts/mosaic queue help > "$SANDBOX/help.out" 2>&1 && grep -q '^usage: queue list' "$SANDBOX/help.out"
check "scripts/mosaic queue help" $?
if ! git cat-file -e HEAD:docs/plans/queue.json 2>/dev/null; then
echo "skip queue verify and render --check: HEAD has no docs/plans/queue.json (before the genesis commit)"
else
CANON="$(git show HEAD:docs/plans/queue.json | node -e 'let s="";process.stdin.on("data",(d)=>{s+=d}).on("end",()=>{const r=JSON.parse(s).canonicalRoot;if(typeof r==="string")process.stdout.write(r)})' 2>/dev/null)"
TOP="$(realpath "$(git rev-parse --show-toplevel)")"
if [ -z "$CANON" ]; then
check "HEAD's docs/plans/queue.json names a canonicalRoot" 1
elif [ "$TOP" != "$CANON" ]; then
# The queue refuses outside its canonical root (8.3), so an export or
# a review clone can't run these two. Say so instead of failing them.
echo "skip queue verify and render --check: this checkout ($TOP) is not the queue's canonical root ($CANON)"
else
scripts/mosaic queue verify
check "scripts/mosaic queue verify (live queue)" $?
scripts/mosaic queue render --check
check "scripts/mosaic queue render --check (live queue)" $?
fi
fi
echo
echo "queue suite: $PASS passed, $FAIL failed"
[ "$FAIL" = 0 ]