#!/usr/bin/env bash # Row 125 (#1619) gate on the candidate worktree. Slot work: run only on Sage's go. # gate.sh # 1. each candidate test file alone; 2. every package's tests; 3. the script suites (test-task uses # Docker, under project dewey-r125). Logs kept; summary.txt has one line per run, totals by awk. set -uo pipefail WT=$(realpath -e "${1:?worktree}") || exit 2 OUT=$(realpath -m "${2:?outdir}") MANIFEST=$(realpath -e "${3:?manifest}") || exit 2 export TMPDIR=$HOME/dewey-scratch/tmp/lt COMPOSE_PROJECT_NAME=dewey-r125 mkdir -p "$TMPDIR" "$OUT" || { echo "abort: cannot create $TMPDIR or $OUT"; exit 2; } cd "$WT" || exit 2 cleanup() { if command -v docker >/dev/null 2>&1; then n=$(docker ps -aq --filter label=com.docker.compose.project=dewey-r125 | wc -l) echo "containers left under dewey-r125: $n" >> "$OUT/summary.txt" if docker network inspect dewey-r125_default >/dev/null 2>&1; then docker network rm dewey-r125_default >/dev/null 2>&1 || echo "could not remove network dewey-r125_default" >> "$OUT/summary.txt" fi fi sha256sum --quiet -c "$MANIFEST" || echo "MANIFEST MISMATCH after gate" >> "$OUT/summary.txt" } trap cleanup EXIT sha256sum --quiet -c "$MANIFEST" || { echo "abort: candidate differs from $MANIFEST"; exit 2; } git -C "$WT" rev-parse HEAD > "$OUT/base.txt" || exit 2 : > "$OUT/summary.txt" run() { # run local name=$1; shift setsid -w timeout -k 10 1800 "$@" > "$OUT/$name.log" 2>&1 < /dev/null; local rc=$? echo "$name rc=$rc :: $(awk '/^ℹ (tests|pass|fail|skipped) [0-9]+$/ {printf "%s %s ", $2, $3}' "$OUT/$name.log")" >> "$OUT/summary.txt" } for f in $(grep -E '\.test\.mjs$' <(awk '{print $2}' "$MANIFEST")); do run "single-$(echo "$f" | tr / _)" node --test --test-reporter=spec "$f"; done for p in packages/*/; do p=${p%/}; [ -d "$p/tests" ] && run "pkg-${p#packages/}" node --test "$p/tests/"; done for s in scripts/test-*.sh; do run "$(basename "$s" .sh)" bash "$s"; done echo DONE >> "$OUT/summary.txt" # Totals over the package runs only (the singles repeat them). awk '/^pkg-/ { for (i = 1; i <= NF; i++) if ($i ~ /^(tests|pass|fail|skipped)$/) t[$i] += $(i+1) } END { printf "package totals: tests %d pass %d fail %d skipped %d\n", t["tests"], t["pass"], t["fail"], t["skipped"] }' "$OUT/summary.txt" >> "$OUT/summary.txt" grep -q ' rc=[1-9]' "$OUT/summary.txt" && exit 1 || exit 0