Skip to content
This repository was archived by the owner on Aug 17, 2026. It is now read-only.

Commit 34e2747

Browse files
committed
chore(scripts): install-local.sh smoke-test before binary swap (anomalyco#258) (#19)
Add a smoke-test step that runs BEFORE the freshly-built binary replaces the brew Cellar binary. Catches the class of regression where the build succeeds at the bundler layer but the produced binary crashes at module-load / plugin-resolution / config-read — the surface that silently shipped a U.length crash 2026-05-27 (PR #14-17 era) and went undetected for ~1h because already-running tabs kept their mmap'd old binary. Two layers, both cheap (~0.7s total on a healthy binary): 1. `--version` — catches module-load + top-level import crashes 2. `debug info` — catches plugin-resolution + config-load regressions (exercises the same module graph the TUI mount path does) If either layer fails — non-zero exit, OR exit 0 with TypeError / ReferenceError / SyntaxError / fatal-error / U.length / 'Cannot read prop' on stderr — the install aborts and the working brew binary stays put. The build output is preserved at $SRC_BIN for inspection. `--skip-smoke` flag provided for emergency overrides (rebuild loops on a known-broken state where the new binary is wanted despite a smoke fail). `timeout` wrapper detection: macOS doesn't ship coreutils by default, so `timeout`/`gtimeout` are detected at runtime; absent both, the smoke runs unwrapped (the commands themselves exit fast, so the wrapper is belt-and-suspenders, not load-bearing). Verified locally with three integration cases against the in-script smoke block: - Healthy gruntcode binary → proceeds to install - Crashing fake-bin → refused + exit 1, install aborted - Stealth crash (exit 0 + TypeError on stderr) → refused + exit 1 - `--skip-smoke` → smoke skipped, install proceeds Help text + doc-comment header updated; new `Smoke-test (pre-install verification)` section explains what the smoke does + how to disable. Closes anomalyco#258.
1 parent a924001 commit 34e2747

1 file changed

Lines changed: 93 additions & 2 deletions

File tree

‎scripts/install-local.sh‎

Lines changed: 93 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# without waiting for CI to publish a tagged release.
55
#
66
# Usage:
7-
# bash scripts/install-local.sh [version-label]
7+
# bash scripts/install-local.sh [version-label] [--ahead-ok] [--skip-smoke]
88
#
99
# Version label
1010
# -------------
@@ -32,6 +32,19 @@
3232
# "you're building something CI hasn't released, the DB is now ahead of brew"
3333
# trap. Pass `--ahead-ok` to suppress the warning when intentional.
3434
#
35+
# Smoke-test (pre-install verification)
36+
# -------------------------------------
37+
# Before stomping the Cellar binary we exercise the freshly-built binary with
38+
# two cheap commands:
39+
# 1. `--version` — must exit 0 with a parseable version string
40+
# 2. `debug info` — must exit 0 with a clean stderr (no TypeError /
41+
# ReferenceError / SyntaxError / fatal-error / U.length)
42+
# If either fails, the install aborts and the working brew binary stays put.
43+
# Catches the class of regression where the build succeeds at the bundler
44+
# layer but the produced binary crashes at module-load / plugin-resolution /
45+
# config-read — surfaces caught 2026-05-27 (PR #14-17 era) that previously
46+
# would have gone live silently. Pass `--skip-smoke` to override.
47+
#
3548
# Pairs with the standard release flow: tag a release for distribution, but
3649
# install locally immediately so Nik isn't blocked on CI for his own bin.
3750

@@ -41,12 +54,14 @@ ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
4154

4255
# --- parse args --------------------------------------------------------------
4356
AHEAD_OK=0
57+
SKIP_SMOKE=0
4458
EXPLICIT_LABEL=""
4559
for arg in "$@"; do
4660
case "$arg" in
4761
--ahead-ok) AHEAD_OK=1 ;;
62+
--skip-smoke) SKIP_SMOKE=1 ;;
4863
-h|--help)
49-
sed -n '2,40p' "${BASH_SOURCE[0]}" | sed 's/^# \{0,1\}//'
64+
sed -n '2,50p' "${BASH_SOURCE[0]}" | sed 's/^# \{0,1\}//'
5065
exit 0
5166
;;
5267
*) EXPLICIT_LABEL="$arg" ;;
@@ -128,6 +143,82 @@ if [ -z "$SRC_BIN" ] || [ ! -x "$SRC_BIN" ]; then
128143
exit 1
129144
fi
130145

146+
# --- smoke-test --------------------------------------------------------------
147+
# Verify the new binary actually loads + executes a short command path before
148+
# we stomp the working brew Cellar binary. Catches the class of regression
149+
# where a JS-level crash (e.g. U.length on undefined) is silently produced by
150+
# the build but only surfaces when a NEW tab tries to mount the TUI — by which
151+
# time the old binary is already gone and Nik has no working gruntcode.
152+
#
153+
# Two layers, both cheap:
154+
# 1. --version catches module-load + top-level import crashes
155+
# 2. debug info catches plugin-resolution + config-load regressions
156+
# (touches the same module graph the TUI mount does)
157+
#
158+
# Pass --skip-smoke for emergencies (rebuild loop on a known-broken state
159+
# where you intentionally want the new binary installed despite a smoke fail).
160+
if [ "$SKIP_SMOKE" -eq 1 ]; then
161+
echo "→ Smoke-test SKIPPED (--skip-smoke)"
162+
else
163+
echo "→ Smoke-testing new binary at $SRC_BIN..."
164+
SMOKE_LOG=$(mktemp -t gruntcode-smoke.XXXXXX)
165+
SMOKE_FAILED=0
166+
167+
# `timeout` is a GNU coreutils binary; on macOS it's `gtimeout` (via `brew
168+
# install coreutils`) or not present at all. Both --version and `debug info`
169+
# exit in <1s on a healthy binary, so a hang here would indicate a real
170+
# regression worth catching — but we only insist on the wrapper if it's
171+
# available. On macOS without coreutils we run unwrapped + rely on the
172+
# commands being fast.
173+
if command -v timeout >/dev/null 2>&1; then
174+
TIMEOUT_BIN="timeout 10"
175+
elif command -v gtimeout >/dev/null 2>&1; then
176+
TIMEOUT_BIN="gtimeout 10"
177+
else
178+
TIMEOUT_BIN=""
179+
fi
180+
181+
# Layer 1: --version. Exits 0 immediately if module-load succeeds.
182+
if ! $TIMEOUT_BIN "$SRC_BIN" --version >"$SMOKE_LOG" 2>&1; then
183+
SMOKE_FAILED=1
184+
echo " ✗ \`--version\` failed" >&2
185+
else
186+
SMOKE_VERSION=$(cat "$SMOKE_LOG")
187+
echo " ✓ --version → $SMOKE_VERSION"
188+
fi
189+
190+
# Layer 2: debug info. Exercises plugin-resolution + config load.
191+
if [ "$SMOKE_FAILED" -eq 0 ]; then
192+
if ! $TIMEOUT_BIN "$SRC_BIN" debug info >"$SMOKE_LOG" 2>&1; then
193+
SMOKE_FAILED=1
194+
echo " ✗ \`debug info\` failed" >&2
195+
elif grep -qE '(TypeError|ReferenceError|SyntaxError|fatal error|Cannot read prop|U\.length)' "$SMOKE_LOG"; then
196+
# Catch JS-level crash markers that may print on otherwise-zero-exit
197+
# paths — e.g. an unhandled rejection in a plugin load can still produce
198+
# exit 0 but with `TypeError` on stderr.
199+
SMOKE_FAILED=1
200+
echo " ✗ \`debug info\` exited 0 but stderr looks crashy:" >&2
201+
sed 's/^/ /' "$SMOKE_LOG" >&2
202+
else
203+
echo " ✓ debug info clean"
204+
fi
205+
fi
206+
207+
if [ "$SMOKE_FAILED" -ne 0 ]; then
208+
echo >&2
209+
echo "✗ Smoke-test FAILED. Refusing to replace the Cellar binary." >&2
210+
echo " Build output preserved at: $SRC_BIN" >&2
211+
echo " Last smoke log:" >&2
212+
sed 's/^/ /' "$SMOKE_LOG" >&2
213+
echo >&2
214+
echo " Rebuild after fixing the regression, or pass --skip-smoke to override." >&2
215+
exit 1
216+
fi
217+
218+
rm -f "$SMOKE_LOG"
219+
echo " Smoke OK — proceeding to install."
220+
fi
221+
131222
# --- install -----------------------------------------------------------------
132223
CELLAR_BIN=$(find /opt/homebrew/Cellar/gruntcode -name gruntcode -type f 2>/dev/null | sort -r | head -1)
133224
if [ -z "$CELLAR_BIN" ]; then

0 commit comments

Comments
 (0)