igneum/tools/ci/whole-body-check.sh
igneum-labs db6475def5 Build tools: whole-body blocks (the edited-while-running class, with its check), the igneum-pow pairing line, move-hand.sh restart with its readbacks
Three classes from the 0.3.17 night. (1) bash reads a script incrementally: tools/build-remote.sh was edited while a four-minute remote
build ran, the running copy continued at shifted bytes and died with a syntax error after the build had succeeded on the box; the
four long-running tools (build-remote, cross-remote, workers-remote, move-hand) now keep their body in one brace block ending in exit,
parsed whole before a line runs; tools/ci/whole-body-check.sh (in the gate, self-test with a block-less copy) holds the shape.
(2) A fork build pairs with the igneum-pow of the igneum worktree it sits in: a fork at 12153428 under a master worktree failed in
kaspa-pow four minutes in (no chain_program_shadow; master's igneum-pow predates release-0.3.17's); build-remote.sh says the
pairing on its first line ('pairs with igneum 6f8d7a7e (detached): igneum-pow 0.2.0') and the JSONL line carries pairs_with.
The first version of that line used '[ -n ... ] && echo' inside an assignment's $( ) and set -e ended the script on the false
status; fixed. (3) move-hand.sh restart <hand> [--digest <hex>] [--go]: after binary installed a release, restart ONE unit and read
it back (first exec line, commit string in the running binary, digest against the wanted one, igneum_getNodeInfo powEngine over the
node's loopback EVM RPC); the digest readers tolerate a missing line.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-07 03:12:51 +00:00

29 lines
2.4 KiB
Bash
Executable file

#!/usr/bin/env bash
# The edited-while-running class (7 October 2026, 03:0x UTC): bash reads a script incrementally, so editing tools/build-remote.sh while a
# four-minute remote build was in flight made the running copy continue at shifted bytes and die with a syntax error after the build
# had succeeded on the box (the artefacts were never fetched). Rule: a long-running tool's body sits in ONE brace block that ends with
# `exit`, which bash parses entirely before running a line of it, so a later edit cannot reach a running copy. This check reads the
# tools listed below and fails when the line after the library source is not `{ # whole-body` or the file does not end `exit 0` `}`.
#
# tools/ci/whole-body-check.sh # exit 1 with the file and the reason
# tools/ci/whole-body-check.sh --self-test # the real tools pass; a copy with the block removed fails
set -euo pipefail
cd "$(dirname "$0")/../.."
TOOLS=(tools/build-remote.sh tools/cross-remote.sh tools/workers-remote.sh infra/build-server/hands/move-hand.sh)
check() { # <file>
local f="$1" src
src=$(grep -nE '^\. "\$HERE/(\.\./)+(infra/build-server/)?lib\.sh"' "$f" | head -1 | cut -d: -f1)
[ -n "$src" ] || { echo "whole-body: $f: no library source line to anchor the block"; return 1; }
local opener; opener=$(sed -n "$((src + 1)),\$p" "$f" | grep -vE '^\s*$' | head -1) # the next non-blank line
[ "$opener" = '{ # whole-body: bash parses this block entirely before running a line of it, so an edit to this file while a run is in' ] || { echo "whole-body: $f: the first line after the library source is not the whole-body block opener"; return 1; }
[ "$(tail -2 "$f" | head -1)" = 'exit 0' ] && [ "$(tail -1 "$f")" = '}' ] || { echo "whole-body: $f: the file does not end with 'exit 0' and '}'"; return 1; }
echo "whole-body: $f: body in one block (after line $src to the end)"
}
if [ "${1:-}" = --self-test ]; then
t=$(mktemp -d); trap 'rm -rf "$t"' EXIT
for f in "${TOOLS[@]}"; do check "$f" >/dev/null || { echo "whole-body self-test: the real $f FAILED"; exit 1; }; done
grep -vE '^\{ # whole-body|^ # flight cannot reach|^exit 0$|^\}$' tools/cross-remote.sh > "$t/no-block.sh"
if check "$t/no-block.sh" >/dev/null 2>&1; then echo "whole-body self-test: a copy without the block PASSED (blind)"; exit 1; fi
echo "whole-body self-test: the real tools pass; a copy without the block fails"; exit 0
fi
fail=0; for f in "${TOOLS[@]}"; do check "$f" || fail=1; done; exit $fail