morphit/scripts/run-smokes-chunk.sh

46 lines
2.5 KiB
Bash
Executable file

#!/usr/bin/env bash
set -u
START="${1:-1}"; END="${2:-9999}"
repo="$(cd "$(dirname "$0")/.." && pwd)"; cd "$repo"
# Resolve tsx portably (workspace first, then PATH) — mirrors scripts/run-smokes.sh.
# (Previously this hardcoded an absolute sandbox path, which broke on every
# other machine and leaked the build environment's directory layout.)
if [ -x "$repo/node_modules/.bin/tsx" ]; then
TSX="$repo/node_modules/.bin/tsx"
elif command -v tsx >/dev/null 2>&1; then
TSX="$(command -v tsx)"
else
echo "ERROR: tsx not found. Run 'npm install' from the repo root." >&2
exit 2
fi
mapfile -t SMOKES < <(grep -E '^[[:space:]]*"[^"]+"' scripts/run-smokes.sh | sed -E 's/^[[:space:]]*"([^"]+)".*/\1/')
total=0; failed=0
# Mirror run-smokes.sh: per-smoke wall-clock, overridable for slow hosts.
SMOKE_TIMEOUT="${MORPHIT_SMOKE_TIMEOUT:-240}"
SMOKE_OUT="$(mktemp -t morphit-smoke.XXXXXX.out)"
trap 'rm -f "$SMOKE_OUT"' EXIT
idx=0
for entry in "${SMOKES[@]}"; do
idx=$((idx+1))
if [ "$idx" -lt "$START" ] || [ "$idx" -gt "$END" ]; then continue; fi
dir="${entry%:*}"; name="${entry##*:}"
path="$repo/$dir/scripts/$name.ts"
if [ ! -f "$path" ]; then echo " ✗ [$idx] $name (missing)"; failed=$((failed+1)); continue; fi
# Prefer a workspace-local tsconfig.smoke.json (cp448) — apps/web ships its
# own so $blurt/$indexer resolve to WEB, not the indexer. Mirror run-smokes.sh
# exactly; hardcoding the repo-root config mis-resolves those per-app aliases.
if [ -f "$repo/$dir/tsconfig.smoke.json" ]; then CFG="$repo/$dir/tsconfig.smoke.json"; else CFG="$repo/tsconfig.smoke.json"; fi
if (cd "$repo/$dir" && timeout --signal=TERM --kill-after=5 "$SMOKE_TIMEOUT" "$TSX" --tsconfig "$CFG" "scripts/$name.ts" >"$SMOKE_OUT" 2>&1); then
# Anchor count extraction at ^✓ all N (see run-smokes.sh): a greedy
# `.*all ` matches the "all " inside assemble-INSTALL / local-INSTALL
# and captures empty, mis-reporting those two as "no canonical line".
n=$(grep "^✓ all" "$SMOKE_OUT" | sed "s/^✓ all \([0-9]*\).*/\1/")
if [ -z "$n" ] || [ "$n" -eq 0 ] 2>/dev/null; then
failed=$((failed+1)); echo " ✗ [$idx] $name (no canonical line)"; tail -4 "$SMOKE_OUT" | sed 's/^/ /'
else total=$((total+n)); fi
else
failed=$((failed+1)); echo " ✗ [$idx] $name"; tail -10 "$SMOKE_OUT" | sed 's/^/ /'
fi
done
echo "──────────────────────────────────────────────────────"
echo "Chunk [$START..$END]: $total scenarios, $failed runners failed"