From 232c8ded26239185788b4934e3032991acaf37d8 Mon Sep 17 00:00:00 2001 From: Roy Osherove <575051+royosherove@users.noreply.github.com> Date: Sun, 11 Oct 2026 12:52:51 +0000 Subject: [PATCH] fix(bootstrap): define the warn helper (#128) deploy/bootstrap.sh calls warn at three top-level lines (cfn-bootstrap install, user runtime dir wait, pack shell profile). The script defines only step, ok, fail and info. Under set -euo pipefail, the missing command stops the bootstrap at the first warning. Add warn() next to the other log helpers. Add tests/test-bootstrap-helpers.sh. The test reads the top-level script (it skips heredoc bodies) and makes sure that each log helper the script calls is also defined. The test fails on main and passes with the fix. Crew: Drew (Kiro Crew Issue Radar) --- deploy/bootstrap.sh | 1 + tests/test-bootstrap-helpers.sh | 70 +++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 tests/test-bootstrap-helpers.sh diff --git a/deploy/bootstrap.sh b/deploy/bootstrap.sh index 630b045..b6c53be 100755 --- a/deploy/bootstrap.sh +++ b/deploy/bootstrap.sh @@ -80,6 +80,7 @@ step() { ok() { echo "[OK] $(date -u '+%H:%M:%S') $1"; } fail() { echo "[FAIL] $(date -u '+%H:%M:%S') $1"; } info() { echo "[INFO] $(date -u '+%H:%M:%S') $1"; } +warn() { echo "[WARN] $(date -u '+%H:%M:%S') $1"; } usage() { cat <&2 + exit 1 +fi + +RED='\033[0;31m'; GREEN='\033[0;32m'; BOLD='\033[1m'; NC='\033[0m' +PASS=0; FAIL=0 + +pass() { printf "${GREEN} \xE2\x9C\x93${NC} %s\n" "$1"; PASS=$((PASS + 1)); } +fail() { printf "${RED} \xE2\x9C\x97${NC} %s\n" "$1"; FAIL=$((FAIL + 1)); } + +printf "${BOLD}deploy/bootstrap.sh log helpers${NC}\n" + +# Print the top-level lines of the script. Lines inside a heredoc body are +# removed, because a heredoc body is data or a script for a different shell. +top_level() { + awk ' + delim != "" { if ($0 == delim) delim = ""; next } + { + print + if (match($0, /<<-?[ \t]*["\047]?[A-Za-z_][A-Za-z0-9_]*["\047]?/)) { + d = substr($0, RSTART, RLENGTH) + sub(/^<<-?[ \t]*/, "", d) + gsub(/["\047]/, "", d) + delim = d + } + } + ' "$BOOTSTRAP" +} + +TOP="$(top_level)" + +for helper in step ok fail info warn; do + defined=0 + called=0 + if grep -Eq "^${helper}\(\)" <<<"$TOP"; then defined=1; fi + # A call is the helper name at the start of a command: line start, or + # after "&&", "||", ";" or "then"/"else"/"do". + if grep -Eq "(^|&&|\|\||;|then|else|do)[[:space:]]*${helper}[[:space:]]+[\"\$]" <<<"$TOP"; then + called=1 + fi + if [[ $called -eq 0 ]]; then + pass "$helper is not called at top level" + elif [[ $defined -eq 1 ]]; then + pass "$helper is called and defined at top level" + else + fail "$helper is called at top level but not defined" + fi +done + +echo "" +echo "Passed: $PASS Failed: $FAIL" +[[ $FAIL -eq 0 ]]