lumbda/tests/integration/test-bash-script-syntax.sh
russell@unturf.com 1665893321
factory + quantum + sweep-doctrine: AGPLv3 share-back from foxhop ecdsa
29 new files publish factory infra (V2 autoscaler with live VRAM
sampling + EWMA peak tracking, HUGE solo-dispatch, two-tier DLQ/rDLQ
classifier + retry), general quantum circuit primitives (Cuccaro
ripple-carry adder, Clifford gate library, Clifford tableau simulator,
mod-arith family, dialog GCD reversible inverse, Karatsuba multiplier,
Solinas fast reduction), and a TCRAUDT reducer harness. Originally
developed in ~/git/www.foxhop.net/ecdsa/ for secp256k1 attack-surface
research; published upstream as obligated by AGPLv3.

Parametrization contract at factory/CONTRACT.md. Consumers export
LUMBDA_REPO_DIR + LUMBDA_QUEUE_DIR + LUMBDA_BACKEND_CMD + LUMBDA_EMITTER_CMD
then exec factory scripts. No fork-and-modify; single source of truth
upstream.

Integration tests gate 7 V2 defect classes that wedged a live factory
on 2026-06-12 (skewed-demand starve, zero-floor reservation,
multi-tier greedy, +-25%% damping, cold-start ramp, DLQ surge halve,
post-damp CPU ceiling) + 28 DLQ classifier cases (auto-retry vs
escalate partition) + bash -n syntax lint across every script.

GPU backend stays in consumer trees; rationale in
factory/GPU-BACKEND-NOTE.md. Bend wire protocol + gpu-worker.lsp
already upstream at examples/cuda-fanout/.

make factory-lint                bash -n on every factory/*.sh
make test-integration            V2 reducer + DLQ classifier + syntax gate
make sweep-doctrine              TCRAUDT reducer gate (serial)
make sweep-doctrine-parallel     xargs -P fan-out

Verified on neoblanka: factory-lint 12 scripts PASS; test-integration
14 V2 cases + 28 DLQ classifier cases + 12 syntax cases all PASS.
2026-06-14 10:37:35 -04:00

85 lines
3.3 KiB
Bash
Executable file

#!/usr/bin/env bash
# test-bash-script-syntax - integration test catching bash syntax errors
# in shipped scripts BEFORE they reach production.
#
# Real catch: 2026-06-12 12:00 UTC `bend-emit-pool.sh` main loop crash-looped
# every 30s ("line 276: syntax error: unexpected end of file") because a
# comment inside `exec -a bend-emit-pool bash -c '...'` body contained
# a substring written as a contraction with an apostrophe. A single-quote
# inside that bash -c body closed our outer wrapper early. Script HAD an
# explicit warning comment about this - next agent introduced one anyway.
#
# Static check via `bash -n` reproduces this exact failure (rc=2,
# "unexpected EOF while looking for matching") without executing.
# Running this gate in CI would have failed our commit pre-production.
#
# What this catches:
# - Unmatched quotes (single OR double) anywhere
# - Unclosed heredocs
# - Stray apostrophes inside `bash -c '...'` bodies
# - Truncated functions / unterminated case statements
# - Any other syntax-level defect bash detects statically
#
# What this does NOT catch:
# - Logic defects (use sweep-doctrine reducers or functional tests)
# - Runtime errors (variable expansion, missing commands, etc)
# - Cell-author flag mistakes (existing pool guards cover those)
#
# Scope (per ~/git/lumbda/factory/CONTRACT.md):
# - Always scans $LUMBDA_FACTORY_DIR/*.sh + $LUMBDA_FACTORY_DIR/tests/integration/*.sh
# - If $LUMBDA_DOMAIN_DIR is set, also scans $LUMBDA_DOMAIN_DIR/scripts/*.sh
#
# Exit: 0 if every .sh parses clean; non-zero with a per-file report otherwise.
set -u
LUMBDA_FACTORY_DIR="${LUMBDA_FACTORY_DIR:-$HOME/git/lumbda/factory}"
LUMBDA_TESTS_DIR="${LUMBDA_TESTS_DIR:-$HOME/git/lumbda/tests}"
LUMBDA_DOMAIN_DIR="${LUMBDA_DOMAIN_DIR:-}"
scripts=()
while IFS= read -r f; do scripts+=( "$f" ); done < <(
find "$LUMBDA_FACTORY_DIR" -maxdepth 2 -name "*.sh" -type f 2>/dev/null
find "$LUMBDA_TESTS_DIR/integration" -maxdepth 1 -name "*.sh" -type f 2>/dev/null
find "$LUMBDA_TESTS_DIR/sweep-doctrine" -maxdepth 1 -name "*.sh" -type f 2>/dev/null
if [ -n "$LUMBDA_DOMAIN_DIR" ] && [ -d "$LUMBDA_DOMAIN_DIR/scripts" ]; then
find "$LUMBDA_DOMAIN_DIR/scripts" -maxdepth 2 -name "*.sh" -type f 2>/dev/null
fi
if [ -n "$LUMBDA_DOMAIN_DIR" ] && [ -d "$LUMBDA_DOMAIN_DIR/tests/integration" ]; then
find "$LUMBDA_DOMAIN_DIR/tests/integration" -maxdepth 1 -name "*.sh" -type f 2>/dev/null
fi
)
if [ "${#scripts[@]}" -eq 0 ]; then
echo "ERROR: no .sh files found under $LUMBDA_FACTORY_DIR${LUMBDA_DOMAIN_DIR:+ or $LUMBDA_DOMAIN_DIR/scripts}"
exit 1
fi
echo "[bash-syntax] checking ${#scripts[@]} script(s)"
errfile=$(mktemp /tmp/bash-n-err.XXXXXX)
trap 'rm -f "$errfile"' EXIT
fail_count=0
for s in "${scripts[@]}"; do
if bash -n "$s" 2>"$errfile"; then
: # pass - loud only on failure
else
fail_count=$((fail_count + 1))
echo "FAIL $s:"
sed 's/^/ /' "$errfile"
fi
done
if [ "$fail_count" -gt 0 ]; then
echo ""
echo "[bash-syntax] FAIL - $fail_count script(s) failed bash -n"
echo "Common cause: apostrophe inside an exec -a NAME bash -c ..."
echo "wrapper closes our outer single-quote early. Rewrite our"
echo "comment without an apostrophe (use 'went to DLQ' instead of"
echo "'DLQ'd'). See bend-emit-pool.sh feb0408 for post-mortem."
exit 1
fi
echo "[bash-syntax] PASS - all ${#scripts[@]} script(s) parse clean"
exit 0