From 9604e12c84f475bd012678af7616f934a04de097 Mon Sep 17 00:00:00 2001 From: Han Ngo Date: Wed, 2 Dec 2026 16:20:48 +0700 Subject: [PATCH 1/5] fix(wrap): restore bash 3.2 parse and runtime compatibility Fixes bash 3.2 parse and runtime regressions in wrap-session.sh and report-lint.sh: - Remove unmatched apostrophes and backticks from comments inside command substitutions in _session_transcript_json (bash 3.2 parse_comsub tracked them as quotes, causing a syntax error at line 740). - Use POSIX balanced parentheses on case clauses inside the acted command substitution. - Move the multi-line jq program in _session_summary_text into a quoted heredoc variable and add a shellcheck dialect header. - Guard empty built_items array expansion in report-lint.sh under set -u for bash 3.2. - Add always-on tests/test-bash32-parse.sh to run /bin/bash -n over every shipped shell file on macOS (skips when /bin/bash is not 3.2) so the fast PR lane catches 3.2 parse errors. --- lib/wrap/report-lint.sh | 2 +- lib/wrap/wrap-session.sh | 16 +++++---- tests/test-bash32-parse.sh | 68 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+), 7 deletions(-) create mode 100755 tests/test-bash32-parse.sh diff --git a/lib/wrap/report-lint.sh b/lib/wrap/report-lint.sh index 7df65e3d..d08e8c38 100755 --- a/lib/wrap/report-lint.sh +++ b/lib/wrap/report-lint.sh @@ -281,7 +281,7 @@ else # session does not build is REPORTED here and nowhere else; a board row is the operator's # call, never a side effect of the wrap. _v_idx=0 - for _v_item in "${built_items[@]}"; do + for _v_item in ${built_items[@]+"${built_items[@]}"}; do _v_idx=$((_v_idx + 1)) case "$_v_item" in REPORTED\ *) diff --git a/lib/wrap/wrap-session.sh b/lib/wrap/wrap-session.sh index d8de71fc..427a6204 100644 --- a/lib/wrap/wrap-session.sh +++ b/lib/wrap/wrap-session.sh @@ -1,3 +1,4 @@ +# shellcheck shell=bash # wrap-session.sh -- the session verb: one read-only gather for commands/wrap.md. # Sourced by lib/wrap/wrap.sh. stdout is exactly one JSON document; diagnostics stay on stderr. @@ -608,13 +609,13 @@ _session_transcript_json() { unknown="$(mktemp "${TMPDIR:-/tmp}/kit.XXXXXX")" acted="$( { printf '%s\n' "$raw" | grep -av "$(printf '^\001BARE')" # \037 (unit separator), not a tab: IFS would fold a run of tabs and shift empty fields. - # A relative `cd` target is already joined onto its record's cwd; a target that does not + # A relative cd target is already joined onto the record cwd; a target that does not # land in a git repo with a GitHub origin is UNKNOWN, never credited to another repo. while IFS="$(printf '\037')" read -r _ dir slug n branch; do [ -n "$dir$slug$n$branch" ] || continue if [ -z "$slug" ]; then d="$(printf '%s' "$dir" | sed "s#^~/#$HOME/#")" - case "$d" in /*) ;; *) d="" ;; esac + case "$d" in (/*) ;; (*) d="" ;; esac while [ -n "$d" ] && [ "$d" != "/" ] && [ ! -d "$d" ]; do d="$(dirname "$d")"; done main="" [ -n "$d" ] && [ "$d" != "/" ] && main="$(_session_main_checkout "$d" 2>/dev/null)" @@ -627,7 +628,7 @@ _session_transcript_json() { if [ -z "$n" ] && [ -n "$branch" ] && [ "$(_gh_state)" = ok ]; then n="$(gh pr list --repo "$slug" --head "$branch" --state all --limit 1 --json number --jq '.[0].number // empty' 2>/dev/null)" # merged-ok: names the PR a branch-only merge acted on, read live after; never a deletion proof fi - case "$n" in ''|*[!0-9]*) continue ;; esac + case "$n" in (''|*[!0-9]*) continue ;; esac printf 'https://github.com/%s/pull/%s\n' "$slug" "$n" done </dev/null)" || continue - # Only a checkout the current user owns; another user's repo is never gathered from transcript text. + # Only a checkout owned by the current user; a repo owned by another user is never gathered from transcript text. [ -n "$main" ] && [ "$main" != "$HOME" ] && [ -O "$main" ] && printf '%s\n' "$main" done < -- the compact view of one wrap-session/1 document: every field # commands/wrap.md reads, one fact per line, so the report never re-reads the JSON. _session_summary_text() { - printf '%s' "$1" | jq -r ' + local prog + IFS= read -r -d '' prog <<'EOF_SESSION_SUMMARY_JQ' || true def v: if . == null then "-" else tostring end; def sha: if . == null then "-" else .[0:12] end; "wrap-session/1 generated_at=\(.generated_at) epoch=\(.generated_at_epoch) repos=\(.summary.repos) open_own_prs=\(.summary.open_own_prs) pending_prs=\(.summary.pending_prs) named_prs=\(.summary.named_prs) foreign_activity_repos=\(.summary.foreign_activity_repos)", @@ -771,7 +773,9 @@ _session_summary_text() { " sweep " + ((.rows // []) | group_by(.verdict) | map("\(.[0].verdict)=\(length)") | join(" ") | if . == "" then "rows=0" else . end) + (if .error then " error=\"\(.error)\"" else "" end), ((.rows // [])[] | select(.verdict != "keep") | " \(.verdict) \(.kind) \(.branch // .path | v) \(.reason)")) else " sweep text-fallback (read-only, no fetch): see --json" end) - end)' 2>/dev/null + end) +EOF_SESSION_SUMMARY_JQ + printf '%s' "$1" | jq -r "$prog" 2>/dev/null } # _session_repo_json -- one repo object. Every child read degrades into a field, diff --git a/tests/test-bash32-parse.sh b/tests/test-bash32-parse.sh new file mode 100755 index 00000000..02115e92 --- /dev/null +++ b/tests/test-bash32-parse.sh @@ -0,0 +1,68 @@ +#!/usr/bin/env bash +# always: checks every shipped shell file parses under macOS /bin/bash 3.2 +# test-bash32-parse.sh -- every shell file the kit ships (bin/, hooks/, lib/, +# scripts/, install.sh) must parse cleanly under Apple's stock /bin/bash 3.2. +# +# CI on macOS prepends Homebrew bash 5 to PATH, so `#!/usr/bin/env bash` runs +# under bash 5 there, while end-user Macs without Homebrew bash run `/bin/bash` +# (3.2). A 3.2-only parse error therefore ships undetected unless `/bin/bash -n` +# runs explicitly. Skips cleanly with exit 0 when `/bin/bash` is not 3.2 +# (for example, Ubuntu CI where `/bin/bash` is 5.x). +set -uo pipefail +KIT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +cd "$KIT_DIR" || exit 1 + +BASH32="/bin/bash" +if [ ! -x "$BASH32" ]; then + echo "SKIP: $BASH32 not found; bash 3.2 parse check runs on macOS" + exit 0 +fi + +ver="$("$BASH32" -c 'printf "%s.%s" "${BASH_VERSINFO[0]:-0}" "${BASH_VERSINFO[1]:-0}"' 2>/dev/null || true)" +if [ "$ver" != "3.2" ]; then + echo "SKIP: $BASH32 is ${ver:-unknown}, not 3.2; bash 3.2 parse check runs on macOS" + exit 0 +fi + +checked=0 +failed=0 +failed_files="" + +while IFS= read -r f; do + [ -n "$f" ] || continue + [ -f "$f" ] && [ ! -L "$f" ] || continue + is_shell=0 + case "$f" in + *.sh) is_shell=1 ;; + *) + IFS= read -r first_line < "$f" 2>/dev/null || first_line="" + case "$first_line" in + '#!'*bash*|'#!'*/sh|'#!'*' sh'|'#!'*' sh '*) is_shell=1 ;; + esac + ;; + esac + [ "$is_shell" -eq 1 ] || continue + checked=$((checked + 1)) + if ! err="$("$BASH32" -n "$f" 2>&1)"; then + failed=$((failed + 1)) + failed_files="${failed_files}${f} +" + echo "FAIL: $f" + printf '%s\n' "$err" | sed 's/^/ /' + fi +done < <(git ls-files --cached --others --exclude-standard -- install.sh bin hooks lib scripts | LC_ALL=C sort -u) + +if [ "$checked" -eq 0 ]; then + echo "FAIL: no shipped shell files found to check" >&2 + exit 1 +fi + +if [ "$failed" -gt 0 ]; then + echo "" + echo "test-bash32-parse: $failed of $checked shipped shell file(s) failed /bin/bash ($ver) -n:" + printf '%s' "$failed_files" | sed 's/^/ - /' + exit 1 +fi + +echo "test-bash32-parse: all $checked shipped shell files parsed cleanly under /bin/bash $ver" +exit 0 From c8c06eb0fb47b35e611987744e335e9c927246f8 Mon Sep 17 00:00:00 2001 From: Han Ngo Date: Wed, 2 Dec 2026 16:28:10 +0700 Subject: [PATCH 2/5] docs(verification): record proof for bash 3.2 hotfix --- docs/verification/l312-bash32-hotfix.md | 136 ++++++++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 docs/verification/l312-bash32-hotfix.md diff --git a/docs/verification/l312-bash32-hotfix.md b/docs/verification/l312-bash32-hotfix.md new file mode 100644 index 00000000..b38c4768 --- /dev/null +++ b/docs/verification/l312-bash32-hotfix.md @@ -0,0 +1,136 @@ +# Verification: l312-bash32-hotfix + +Headless bash 3.2 compatibility hotfix for `lib/wrap/wrap-session.sh` and `lib/wrap/report-lint.sh`, plus an always-on `/bin/bash -n` parse guard (`tests/test-bash32-parse.sh`) that runs in the fast PR lane on macOS: no visible UI surface. + +## Cause + +`lib/wrap/wrap-session.sh` (merged in PR 1257) failed to parse under Apple's stock `/bin/bash` 3.2 (`line 740: syntax error near unexpected token '('`). Under bash 3.2, `parse_comsub` inside `"$( ... )"` tracks quotes before stripping comments: the unmatched apostrophes in `# ... its record's cwd` (line 611, inside `acted="$( ... )"`) and `# ... another user's repo` (line 655, inside `repos_json="$( ... )"`) left a phantom single quote open until line 736's `jq -r '`, which closed it and exposed line 740 as unquoted bash syntax. Running the wrap pipeline under a bash 3.2 PATH shim exposed two more 3.2-only runtime failures: unparenthesized `case` clauses inside `acted="$( ... )"` in `lib/wrap/wrap-session.sh` (lines 617 and 630), and an unguarded empty array expansion `"${built_items[@]}"` under `set -u` in `lib/wrap/report-lint.sh` (line 284). CI missed these because `.github/workflows/test.yml` prepends Homebrew bash 5 to `PATH` on `macos-latest`, so `#!/usr/bin/env bash` never ran under `/bin/bash` 3.2. + +## Green runs + +### 1. Bash 3.2 parse check over every shipped shell file + +```text +Command: bash tests/test-bash32-parse.sh && /bin/bash tests/test-bash32-parse.sh +Exit: 0 +Output: +test-bash32-parse: all 272 shipped shell files parsed cleanly under /bin/bash 3.2 +test-bash32-parse: all 272 shipped shell files parsed cleanly under /bin/bash 3.2 +Verdict: PASS +``` + +### 2. Output parity on `wrap session --summary` before and after (bash 5 and `/bin/bash` 3.2 shim) + +Captured `wrap session --summary --prs acme/widgets#12 --transcript ` and direct `_session_summary_text` output on `origin/master` (under bash 5) before editing, then diffed against post-fix output under bash 5 and under `/bin/bash` 3.2 with `bash` shimmed to `/bin/bash` first on `PATH` (timestamps normalized for `generated_at`, `epoch`, and `read_at`). + +```text +Command: diff -u before.direct.summary after.direct.bash5.summary && diff -u before.direct.summary after.direct.bash32.summary && diff -u <(norm before.summary) <(norm after.bash5.summary) && diff -u <(norm before.summary) <(norm after.bash32.summary) +Exit: 0 +Output: +DIRECT BASH5 DIFF: IDENTICAL (0 diffs) +DIRECT BASH32 DIFF: IDENTICAL (0 diffs) +E2E BASH5 DIFF: IDENTICAL (0 diffs) +E2E BASH32 DIFF: IDENTICAL (0 diffs) +Verdict: PASS +``` + +### 3. Wrap suites on bash 5 and `/bin/bash` 3.2 (with `PATH` shimmed to `/bin/bash`) + +```text +Command: bash tests/test-wrap-session.sh && PATH="$SHIM:$PATH" /bin/bash tests/test-wrap-session.sh && bash tests/test-wrap-report-lint.sh && PATH="$SHIM:$PATH" /bin/bash tests/test-wrap-report-lint.sh +Exit: 0 +Output: +test-wrap-session: all 159 passed +test-wrap-session: all 159 passed +test-wrap-report-lint: all 184 passed +test-wrap-report-lint: all 184 passed +Verdict: PASS +``` + +### 4. Fast PR lane selection on an unrelated diff (`# always:` header) + +```text +Command: bash tests/run-all.sh --changed "$base" --list | grep -Fx "tests/test-bash32-parse.sh" +Exit: 0 +Output: +docs-only diff selected 19 suites +tests/test-bash32-parse.sh +CONFIRMED: test-bash32-parse.sh runs in fast PR lane on any diff +Verdict: PASS +``` + +### 5. All 15 suites selected by `tests/run-all.sh --changed origin/master --list`, plus shellcheck, owners, secret-scan, and feature-registry + +```text +Command: for s in $(bash tests/run-all.sh --changed origin/master --list); do KIT_CONFIG_OPERATOR=/tmp/no-operator-config bash "$s"; done +Exit: 0 +Output: +tests/test-bash32-parse.sh ok (2s) +tests/test-board-registry-env.sh ok (0s) +tests/test-board-states.sh ok (4s) +tests/test-boundary-lint.sh ok (3s) +tests/test-config-registry.sh ok (20s) +tests/test-harvest-sweep.sh ok (20s) +tests/test-kit-contract.sh ok (4s) +tests/test-meta-hard-claims.sh ok (3s) +tests/test-no-personal-paths.sh ok (2s) +tests/test-no-scattered-ids.sh ok (2s) +tests/test-operator-pin.sh ok (5s) +tests/test-shared-lookups.sh ok (2s) +tests/test-wrap-flick.sh ok (5s) +tests/test-wrap-report-lint.sh ok (17s) +tests/test-wrap-session.sh ok (50s) +SUMMARY: 15/15 passed, 0 failed +Verdict: PASS +``` + +```text +Command: shellcheck --norc -S warning lib/wrap/wrap-session.sh lib/wrap/report-lint.sh tests/test-bash32-parse.sh && bash scripts/check-owners.sh && bash scripts/secret-scan.sh && bash lib/registry/feature-registry.sh check +Exit: 0 +Output: +owners: 14 paths, all have a row +secret-scan: 2317 tracked files, no secret found +feature-registry: docs/reference/FEATURES.md is fresh +Verdict: PASS +``` + +## Negative control + +### 1. Reverting `lib/wrap/wrap-session.sh` to `origin/master` fails `tests/test-bash32-parse.sh` + +```text +Command: bash tests/test-bash32-parse.sh +Exit: 1 +Output: +FAIL: lib/wrap/wrap-session.sh + lib/wrap/wrap-session.sh: line 740: syntax error near unexpected token `(' + lib/wrap/wrap-session.sh: line 740: ` "config " + (.config | to_entries | map("\(.key)=\(.value | v)") | join(" ")),' + +test-bash32-parse: 1 of 272 shipped shell file(s) failed /bin/bash (3.2) -n: + - lib/wrap/wrap-session.sh +Verdict: RED, as expected +``` + +Broke via `bash scripts/negctl.sh "bash tests/test-bash32-parse.sh" "git checkout origin/master -- lib/wrap/wrap-session.sh"` (changed: `lib/wrap/wrap-session.sh`). Restored with `git checkout`; the tree is clean and the test is green again (exit 0). + +### 2. Reverting `lib/wrap/report-lint.sh` to `origin/master` fails under `/bin/bash` 3.2 + +```text +Command: printf '## Wrap: t\n\n✅ **Needs you:** NOTHING (walked: own replies 6)\n\n**Built:** NOTHING: no candidates\n\n**Seam:** NOTHING: no seam configured\n\n**What happened**\n- One fact.\n' | KIT_CONFIG_OPERATOR=/dev/null /bin/bash lib/wrap/report-lint.sh +Exit: 1 +Output: +lib/wrap/report-lint.sh: line 392: built_items[@]: unbound variable +Verdict: RED, as expected +``` + +Broke via `bash scripts/negctl.sh "" "git checkout origin/master -- lib/wrap/report-lint.sh"` (changed: `lib/wrap/report-lint.sh`). Restored with `git checkout`; the tree is clean and the check is green again (exit 0). + +## Rollback + +Revert the merge commit on `master` (or restore `lib/wrap/wrap-session.sh` and `lib/wrap/report-lint.sh` and remove `tests/test-bash32-parse.sh` and this proof file): + +```bash +git revert +``` + +No external state, secrets, hooks, gates, or workflow files are modified by this change. From b0682059a6334348d303eb3de28b853d523cf4d2 Mon Sep 17 00:00:00 2001 From: Han Ngo Date: Wed, 2 Dec 2026 16:48:47 +0700 Subject: [PATCH 3/5] test(wrap): add bash 3.2 runtime stage to test-bash32-parse Stage 1 (/bin/bash -n) cannot parse command substitutions inside double quotes or catch runtime empty-array errors under set -u. Stage 2 now runs bin/wrap session --json/--summary with a transcript fixture and lib/wrap/report-lint.sh on an empty built list under /bin/bash 3.2 (with bash shimmed to /bin/bash first on PATH) and asserts real output and clean stderr, and prints a clear RUNNING or SKIP status line. --- tests/test-bash32-parse.sh | 93 +++++++++++++++++++++++++++++++++----- 1 file changed, 81 insertions(+), 12 deletions(-) diff --git a/tests/test-bash32-parse.sh b/tests/test-bash32-parse.sh index 02115e92..3dceee1c 100755 --- a/tests/test-bash32-parse.sh +++ b/tests/test-bash32-parse.sh @@ -1,33 +1,38 @@ #!/usr/bin/env bash -# always: checks every shipped shell file parses under macOS /bin/bash 3.2 +# always: checks every shipped shell file parses and wrap runtime paths work under macOS /bin/bash 3.2 # test-bash32-parse.sh -- every shell file the kit ships (bin/, hooks/, lib/, -# scripts/, install.sh) must parse cleanly under Apple's stock /bin/bash 3.2. +# scripts/, install.sh) must parse cleanly under Apple's stock /bin/bash 3.2, +# and runtime-only 3.2 traps ("$(...)" bodies, empty arrays under set -u) must +# pass when executed under /bin/bash 3.2. # # CI on macOS prepends Homebrew bash 5 to PATH, so `#!/usr/bin/env bash` runs # under bash 5 there, while end-user Macs without Homebrew bash run `/bin/bash` -# (3.2). A 3.2-only parse error therefore ships undetected unless `/bin/bash -n` -# runs explicitly. Skips cleanly with exit 0 when `/bin/bash` is not 3.2 -# (for example, Ubuntu CI where `/bin/bash` is 5.x). +# (3.2). Both stages therefore invoke `/bin/bash` explicitly and shim `bash` to +# `/bin/bash` first on PATH for child processes. Skips cleanly with exit 0 when +# `/bin/bash` is not 3.2 (for example, Ubuntu CI where `/bin/bash` is 5.x). set -uo pipefail KIT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" cd "$KIT_DIR" || exit 1 BASH32="/bin/bash" if [ ! -x "$BASH32" ]; then - echo "SKIP: $BASH32 not found; bash 3.2 parse check runs on macOS" + echo "test-bash32-parse: SKIP ($BASH32 not found; bash 3.2 check runs on macOS)" exit 0 fi ver="$("$BASH32" -c 'printf "%s.%s" "${BASH_VERSINFO[0]:-0}" "${BASH_VERSINFO[1]:-0}"' 2>/dev/null || true)" if [ "$ver" != "3.2" ]; then - echo "SKIP: $BASH32 is ${ver:-unknown}, not 3.2; bash 3.2 parse check runs on macOS" + echo "test-bash32-parse: SKIP ($BASH32 is ${ver:-unknown}, not 3.2; bash 3.2 check runs on macOS)" exit 0 fi +echo "test-bash32-parse: RUNNING under $BASH32 ($ver)" + checked=0 failed=0 -failed_files="" +failed_items="" +# --------------------------------------------------------------- Stage 1: parse while IFS= read -r f; do [ -n "$f" ] || continue [ -f "$f" ] && [ ! -L "$f" ] || continue @@ -45,7 +50,7 @@ while IFS= read -r f; do checked=$((checked + 1)) if ! err="$("$BASH32" -n "$f" 2>&1)"; then failed=$((failed + 1)) - failed_files="${failed_files}${f} + failed_items="${failed_items}parse: ${f} " echo "FAIL: $f" printf '%s\n' "$err" | sed 's/^/ /' @@ -57,12 +62,76 @@ if [ "$checked" -eq 0 ]; then exit 1 fi +# ------------------------------------------------------------- Stage 2: runtime +# A command substitution inside double quotes ("$(...)") is not parsed by bash 3.2 +# until it runs, and empty-array expansion under set -u is a runtime error. Run +# the wrap paths that carry those constructs with /bin/bash 3.2 first on PATH and +# assert both stderr cleanliness and real output. +tmp="$(mktemp -d "${TMPDIR:-/tmp}/test-bash32.XXXXXX")" || exit 1 +trap 'rm -rf "$tmp"' EXIT + +export KIT_CONFIG_OPERATOR="$tmp/no-operator-config" +mkdir -p "$tmp/bin" "$tmp/r/sub" +ln -s "$BASH32" "$tmp/bin/bash" +printf '#!/bin/sh\nexit 1\n' > "$tmp/bin/gh" +chmod +x "$tmp/bin/gh" + +git init -q "$tmp/r" 2>/dev/null +git -C "$tmp/r" -c user.name=t -c user.email=t@t commit -q --allow-empty -m "chore: init" 2>/dev/null +git -C "$tmp/r" remote add origin https://github.com/acme/merged.git + +jq -cn --arg cwd "$tmp/r" \ + '{type:"assistant",timestamp:"2026-11-27T03:00:00Z",cwd:$cwd,gitBranch:"feat/x",message:{content:[{type:"tool_use",id:"m1",name:"Bash",input:{command:"gh pr merge 42 --squash"}},{type:"tool_use",id:"m2",name:"Bash",input:{command:"cd sub && gh pr merge 9 --squash"}}]}}' \ + > "$tmp/t.jsonl" + +rc_json=0 +PATH="$tmp/bin:$PATH" "$BASH32" bin/wrap session --json --transcript "$tmp/t.jsonl" "$tmp/r" \ + > "$tmp/out.json" 2> "$tmp/json.err" || rc_json=$? +if [ "$rc_json" -ne 0 ] \ + || grep -qE 'syntax error|unbound variable' "$tmp/json.err" \ + || ! jq -e '.transcript != null and (.transcript.acted_prs | index("acme/merged#42") != null) and (.transcript.acted_prs | index("acme/merged#9") != null)' "$tmp/out.json" >/dev/null 2>&1; then + failed=$((failed + 1)) + failed_items="${failed_items}runtime: bin/wrap session --json --transcript +" + echo "FAIL: runtime bin/wrap session --json --transcript under $BASH32 ($ver) (exit $rc_json)" + [ -s "$tmp/json.err" ] && sed 's/^/ stderr: /' "$tmp/json.err" + echo " transcript: $(jq -c '.transcript // null' "$tmp/out.json" 2>/dev/null || echo 'invalid json')" +fi + +rc_sum=0 +PATH="$tmp/bin:$PATH" "$BASH32" bin/wrap session --summary --transcript "$tmp/t.jsonl" "$tmp/r" \ + > "$tmp/out.summary" 2> "$tmp/sum.err" || rc_sum=$? +if [ "$rc_sum" -ne 0 ] \ + || grep -qE 'syntax error|unbound variable' "$tmp/sum.err" \ + || ! grep -q '^transcript .*acted_prs=acme/merged#42,acme/merged#9' "$tmp/out.summary"; then + failed=$((failed + 1)) + failed_items="${failed_items}runtime: bin/wrap session --summary --transcript +" + echo "FAIL: runtime bin/wrap session --summary --transcript under $BASH32 ($ver) (exit $rc_sum)" + [ -s "$tmp/sum.err" ] && sed 's/^/ stderr: /' "$tmp/sum.err" + grep '^transcript ' "$tmp/out.summary" 2>/dev/null | sed 's/^/ summary: /' +fi + +rc_lint=0 +printf '## Wrap: t\n\n✅ **Needs you:** NOTHING (walked: own replies 6)\n\n**Built:** NOTHING: no candidates\n\n**Seam:** NOTHING: no seam configured\n\n**What happened**\n- One fact.\n' \ + | PATH="$tmp/bin:$PATH" "$BASH32" lib/wrap/report-lint.sh > "$tmp/lint.out" 2> "$tmp/lint.err" || rc_lint=$? +if [ "$rc_lint" -ne 0 ] \ + || [ -s "$tmp/lint.err" ] \ + || ! grep -q '^report-lint: clean' "$tmp/lint.out"; then + failed=$((failed + 1)) + failed_items="${failed_items}runtime: lib/wrap/report-lint.sh (empty built_items) +" + echo "FAIL: runtime lib/wrap/report-lint.sh under $BASH32 ($ver) (exit $rc_lint)" + [ -s "$tmp/lint.err" ] && sed 's/^/ stderr: /' "$tmp/lint.err" + [ -s "$tmp/lint.out" ] && sed 's/^/ stdout: /' "$tmp/lint.out" +fi + if [ "$failed" -gt 0 ]; then echo "" - echo "test-bash32-parse: $failed of $checked shipped shell file(s) failed /bin/bash ($ver) -n:" - printf '%s' "$failed_files" | sed 's/^/ - /' + echo "test-bash32-parse: FAILED ($failed failure(s) under $BASH32 $ver; $checked files parsed):" + printf '%s' "$failed_items" | sed 's/^/ - /' exit 1 fi -echo "test-bash32-parse: all $checked shipped shell files parsed cleanly under /bin/bash $ver" +echo "test-bash32-parse: PASS under $BASH32 ($ver) ($checked shipped shell files parsed; wrap session and report-lint runtime verified)" exit 0 From b89405edfd28ddd03e7bb0cf57c466152cb3f3c6 Mon Sep 17 00:00:00 2001 From: Han Ngo Date: Wed, 2 Dec 2026 16:52:45 +0700 Subject: [PATCH 4/5] docs(verification): record bash 3.2 runtime stage and negative controls --- docs/verification/l312-bash32-hotfix.md | 103 ++++++++++++++---------- 1 file changed, 60 insertions(+), 43 deletions(-) diff --git a/docs/verification/l312-bash32-hotfix.md b/docs/verification/l312-bash32-hotfix.md index b38c4768..08024963 100644 --- a/docs/verification/l312-bash32-hotfix.md +++ b/docs/verification/l312-bash32-hotfix.md @@ -1,21 +1,33 @@ # Verification: l312-bash32-hotfix -Headless bash 3.2 compatibility hotfix for `lib/wrap/wrap-session.sh` and `lib/wrap/report-lint.sh`, plus an always-on `/bin/bash -n` parse guard (`tests/test-bash32-parse.sh`) that runs in the fast PR lane on macOS: no visible UI surface. +Headless bash 3.2 compatibility hotfix for `lib/wrap/wrap-session.sh` and `lib/wrap/report-lint.sh`, plus an always-on `/bin/bash` 3.2 parse and runtime guard (`tests/test-bash32-parse.sh`) that runs in the fast PR lane on macOS: no visible UI surface. ## Cause -`lib/wrap/wrap-session.sh` (merged in PR 1257) failed to parse under Apple's stock `/bin/bash` 3.2 (`line 740: syntax error near unexpected token '('`). Under bash 3.2, `parse_comsub` inside `"$( ... )"` tracks quotes before stripping comments: the unmatched apostrophes in `# ... its record's cwd` (line 611, inside `acted="$( ... )"`) and `# ... another user's repo` (line 655, inside `repos_json="$( ... )"`) left a phantom single quote open until line 736's `jq -r '`, which closed it and exposed line 740 as unquoted bash syntax. Running the wrap pipeline under a bash 3.2 PATH shim exposed two more 3.2-only runtime failures: unparenthesized `case` clauses inside `acted="$( ... )"` in `lib/wrap/wrap-session.sh` (lines 617 and 630), and an unguarded empty array expansion `"${built_items[@]}"` under `set -u` in `lib/wrap/report-lint.sh` (line 284). CI missed these because `.github/workflows/test.yml` prepends Homebrew bash 5 to `PATH` on `macos-latest`, so `#!/usr/bin/env bash` never ran under `/bin/bash` 3.2. +`lib/wrap/wrap-session.sh` (merged in PR 1257) failed to parse under Apple's stock `/bin/bash` 3.2 (`line 740: syntax error near unexpected token '('`). Under bash 3.2, `parse_comsub` inside `"$( ... )"` tracks quotes before stripping comments: the unmatched apostrophes in `# ... its record's cwd` (line 611, inside `acted="$( ... )"`) and `# ... another user's repo` (line 655, inside `repos_json="$( ... )"`) left a phantom single quote open until line 736's `jq -r '`, which closed it and exposed line 740 as unquoted bash syntax. Running the wrap pipeline under a `/bin/bash` 3.2 PATH shim exposed two more 3.2-only runtime failures that `/bin/bash -n` alone cannot see: unparenthesized `case` clauses inside `acted="$( ... )"` in `lib/wrap/wrap-session.sh` (lines 617 and 630, which cause `wrap session` to exit 0 with `.transcript == null`), and an unguarded empty array expansion `"${built_items[@]}"` under `set -u` in `lib/wrap/report-lint.sh` (line 284). CI missed both classes because `.github/workflows/test.yml` prepends Homebrew bash 5 to `PATH` on `macos-latest`, so `#!/usr/bin/env bash` never ran under `/bin/bash` 3.2. `tests/test-bash32-parse.sh` now closes both halves: Stage 1 parses every shipped shell file with `/bin/bash -n`, and Stage 2 executes `bin/wrap session --json/--summary --transcript` and `lib/wrap/report-lint.sh` under `/bin/bash` 3.2 with `bash` shimmed to `/bin/bash` first on `PATH`, asserting both clean stderr and expected output. ## Green runs -### 1. Bash 3.2 parse check over every shipped shell file +### 1. Bash 3.2 parse and runtime guard (`tests/test-bash32-parse.sh`) ```text Command: bash tests/test-bash32-parse.sh && /bin/bash tests/test-bash32-parse.sh Exit: 0 Output: -test-bash32-parse: all 272 shipped shell files parsed cleanly under /bin/bash 3.2 -test-bash32-parse: all 272 shipped shell files parsed cleanly under /bin/bash 3.2 +test-bash32-parse: RUNNING under /bin/bash (3.2) +test-bash32-parse: PASS under /bin/bash (3.2) (272 shipped shell files parsed; wrap session and report-lint runtime verified) +test-bash32-parse: RUNNING under /bin/bash (3.2) +test-bash32-parse: PASS under /bin/bash (3.2) (272 shipped shell files parsed; wrap session and report-lint runtime verified) +Verdict: PASS +``` + +When `/bin/bash` is not 3.2 (simulated against Homebrew bash 5.3), the suite prints a clear skip line and exits 0: + +```text +Command: bash -c 't="$(mktemp)"; trap "rm -f \"\$t\"" EXIT; sed "s|BASH32=\"/bin/bash\"|BASH32=\"$(which bash)\"|" tests/test-bash32-parse.sh > "$t"; bash "$t"' +Exit: 0 +Output: +test-bash32-parse: SKIP (/opt/homebrew/bin/bash is 5.3, not 3.2; bash 3.2 check runs on macOS) Verdict: PASS ``` @@ -34,7 +46,7 @@ E2E BASH32 DIFF: IDENTICAL (0 diffs) Verdict: PASS ``` -### 3. Wrap suites on bash 5 and `/bin/bash` 3.2 (with `PATH` shimmed to `/bin/bash`) +### 3. Wrap suites on bash 5 and `/bin/bash` 3.2 (with `PATH` shimmed to `/bin/bash`, rebased onto `origin/master`) ```text Command: bash tests/test-wrap-session.sh && PATH="$SHIM:$PATH" /bin/bash tests/test-wrap-session.sh && bash tests/test-wrap-report-lint.sh && PATH="$SHIM:$PATH" /bin/bash tests/test-wrap-report-lint.sh @@ -59,71 +71,76 @@ CONFIRMED: test-bash32-parse.sh runs in fast PR lane on any diff Verdict: PASS ``` -### 5. All 15 suites selected by `tests/run-all.sh --changed origin/master --list`, plus shellcheck, owners, secret-scan, and feature-registry +### 5. Lints, operator-pin, owners, secret-scan, and feature-registry ```text -Command: for s in $(bash tests/run-all.sh --changed origin/master --list); do KIT_CONFIG_OPERATOR=/tmp/no-operator-config bash "$s"; done +Command: shellcheck --norc -S warning lib/wrap/wrap-session.sh lib/wrap/report-lint.sh tests/test-bash32-parse.sh && bash tests/test-operator-pin.sh && bash scripts/check-owners.sh && bash scripts/secret-scan.sh && bash lib/registry/feature-registry.sh check Exit: 0 Output: -tests/test-bash32-parse.sh ok (2s) -tests/test-board-registry-env.sh ok (0s) -tests/test-board-states.sh ok (4s) -tests/test-boundary-lint.sh ok (3s) -tests/test-config-registry.sh ok (20s) -tests/test-harvest-sweep.sh ok (20s) -tests/test-kit-contract.sh ok (4s) -tests/test-meta-hard-claims.sh ok (3s) -tests/test-no-personal-paths.sh ok (2s) -tests/test-no-scattered-ids.sh ok (2s) -tests/test-operator-pin.sh ok (5s) -tests/test-shared-lookups.sh ok (2s) -tests/test-wrap-flick.sh ok (5s) -tests/test-wrap-report-lint.sh ok (17s) -tests/test-wrap-session.sh ok (50s) -SUMMARY: 15/15 passed, 0 failed +operator-pin: 4 passed, 0 failed +owners: 14 paths, all have a row +secret-scan: 2319 tracked files, no secret found +feature-registry: docs/reference/FEATURES.md is fresh Verdict: PASS ``` +## Negative control + +### 1. Reverting only the two `case` clauses in `lib/wrap/wrap-session.sh` turns Stage 2 RED while Stage 1 stays green + ```text -Command: shellcheck --norc -S warning lib/wrap/wrap-session.sh lib/wrap/report-lint.sh tests/test-bash32-parse.sh && bash scripts/check-owners.sh && bash scripts/secret-scan.sh && bash lib/registry/feature-registry.sh check -Exit: 0 +Command: /bin/bash tests/test-bash32-parse.sh +Exit: 1 Output: -owners: 14 paths, all have a row -secret-scan: 2317 tracked files, no secret found -feature-registry: docs/reference/FEATURES.md is fresh -Verdict: PASS + stderr: or see the jq manpage, or online docs at https://jqlang.org + transcript: null +FAIL: runtime bin/wrap session --summary --transcript under /bin/bash (3.2) (exit 0) + stderr: lib/wrap/wrap-session.sh: command substitution: line 645: syntax error near unexpected token `newline' + stderr: lib/wrap/wrap-session.sh: command substitution: line 645: ` case "$d" in /*' + stderr: jq: invalid JSON text passed to --argjson +test-bash32-parse: FAILED (2 failure(s) under /bin/bash 3.2; 272 files parsed): + - runtime: bin/wrap session --json --transcript + - runtime: bin/wrap session --summary --transcript +Verdict: RED, as expected ``` -## Negative control +Broke via `bash scripts/negctl.sh "/bin/bash tests/test-bash32-parse.sh" "perl -pi -e 's/case \"\\\$d\" in \\(\\/\\*\\) ;; \\(\\*\\) d=\"\" ;; esac/case \"\\\$d\" in \\/*) ;; *) d=\"\" ;; esac/; s/case \"\\\$n\" in \\('\'''\''\\|\\*\\[!0-9\\]\\*\\) continue ;; esac/case \"\\\$n\" in '\'''\''|*[!0-9]*) continue ;; esac/' lib/wrap/wrap-session.sh"` (changed: `lib/wrap/wrap-session.sh`). Restored with `git checkout`; the tree is clean and the suite is green again (exit 0). -### 1. Reverting `lib/wrap/wrap-session.sh` to `origin/master` fails `tests/test-bash32-parse.sh` +### 2. Reverting only `lib/wrap/report-lint.sh` turns Stage 2 RED on `built_items[@]: unbound variable` ```text -Command: bash tests/test-bash32-parse.sh +Command: /bin/bash tests/test-bash32-parse.sh Exit: 1 Output: -FAIL: lib/wrap/wrap-session.sh - lib/wrap/wrap-session.sh: line 740: syntax error near unexpected token `(' - lib/wrap/wrap-session.sh: line 740: ` "config " + (.config | to_entries | map("\(.key)=\(.value | v)") | join(" ")),' +test-bash32-parse: RUNNING under /bin/bash (3.2) +FAIL: runtime lib/wrap/report-lint.sh under /bin/bash (3.2) (exit 1) + stderr: lib/wrap/report-lint.sh: line 392: built_items[@]: unbound variable -test-bash32-parse: 1 of 272 shipped shell file(s) failed /bin/bash (3.2) -n: - - lib/wrap/wrap-session.sh +test-bash32-parse: FAILED (1 failure(s) under /bin/bash 3.2; 272 files parsed): + - runtime: lib/wrap/report-lint.sh (empty built_items) Verdict: RED, as expected ``` -Broke via `bash scripts/negctl.sh "bash tests/test-bash32-parse.sh" "git checkout origin/master -- lib/wrap/wrap-session.sh"` (changed: `lib/wrap/wrap-session.sh`). Restored with `git checkout`; the tree is clean and the test is green again (exit 0). +Broke via `bash scripts/negctl.sh "/bin/bash tests/test-bash32-parse.sh" "git checkout origin/master -- lib/wrap/report-lint.sh"` (changed: `lib/wrap/report-lint.sh`). Restored with `git checkout`; the tree is clean and the suite is green again (exit 0). -### 2. Reverting `lib/wrap/report-lint.sh` to `origin/master` fails under `/bin/bash` 3.2 +### 3. Reverting `lib/wrap/wrap-session.sh` to `origin/master` turns Stage 1 and Stage 2 RED ```text -Command: printf '## Wrap: t\n\n✅ **Needs you:** NOTHING (walked: own replies 6)\n\n**Built:** NOTHING: no candidates\n\n**Seam:** NOTHING: no seam configured\n\n**What happened**\n- One fact.\n' | KIT_CONFIG_OPERATOR=/dev/null /bin/bash lib/wrap/report-lint.sh +Command: /bin/bash tests/test-bash32-parse.sh Exit: 1 Output: -lib/wrap/report-lint.sh: line 392: built_items[@]: unbound variable + lib/wrap/wrap-session.sh: line 740: ` "config " + (.config | to_entries | map("\(.key)=\(.value | v)") | join(" ")),' +FAIL: runtime bin/wrap session --json --transcript under /bin/bash (3.2) (exit 1) + stderr: lib/wrap/wrap-session.sh: line 740: syntax error near unexpected token `(' + stderr: FATAL: lib/wrap/wrap-session.sh missing or unreadable +test-bash32-parse: FAILED (3 failure(s) under /bin/bash 3.2; 272 files parsed): + - parse: lib/wrap/wrap-session.sh + - runtime: bin/wrap session --json --transcript + - runtime: bin/wrap session --summary --transcript Verdict: RED, as expected ``` -Broke via `bash scripts/negctl.sh "" "git checkout origin/master -- lib/wrap/report-lint.sh"` (changed: `lib/wrap/report-lint.sh`). Restored with `git checkout`; the tree is clean and the check is green again (exit 0). +Broke via `bash scripts/negctl.sh "/bin/bash tests/test-bash32-parse.sh" "git checkout origin/master -- lib/wrap/wrap-session.sh"` (changed: `lib/wrap/wrap-session.sh`). Restored with `git checkout`; the tree is clean and the suite is green again (exit 0). ## Rollback From 9d1e5d08a74aaf64027532c38a7a435005f0a482 Mon Sep 17 00:00:00 2001 From: Han Ngo Date: Wed, 2 Dec 2026 16:53:46 +0700 Subject: [PATCH 5/5] docs(registry): refresh FEATURES.md for test-bash32-parse --- docs/reference/FEATURES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/reference/FEATURES.md b/docs/reference/FEATURES.md index 063b2f25..96595bf0 100644 --- a/docs/reference/FEATURES.md +++ b/docs/reference/FEATURES.md @@ -50,7 +50,7 @@ GENERATED , do not hand-edit. Regenerate: `bash lib/registry/feature-registry.sh | `/kit:verify` | `[H/I]` | Re-run the test levels (kit:task-verifier + kit:integration-verifier + kit:acceptance-verifier, plus kit:system-verifier only with --full) … | SPEC-002, SPEC-003, SPEC-006 +57 | test-board-digest.sh, test-board-hermes.sh, test-board-lock-required.sh +35 | | `/kit:visual-team` | `[H/I]` | Parallel multi-lens critique of a visual/UI design. Dispatches 5 design lenses, merges findings, reports a verdict. Report-only, downstream… | SPEC-016, SPEC-018, SPEC-019 +12 | test-command-emit-sweep.sh, test-meta-review-verifiers.sh, test-meta-spec-depth.sh +1 | | `/kit:wayfind` | `[H]` | Plan a chunk of work too big for one agent session as a shared decision map: map.md + typed decision tickets in the mega-goal folder, resol… | SPEC-206, SPEC-207, SPEC-217 +2 | - | -| `/kit:wrap` | `[H/I]` | The session-scoped landing step after ship: flips board rows, merges green PRs, checks deploys, tidies worktrees, prints the skim-first rep… | SPEC-020, SPEC-060, SPEC-072 +75 | test-bin-forwarders.sh, test-board-lock-required.sh, test-board-work.sh +55 | +| `/kit:wrap` | `[H/I]` | The session-scoped landing step after ship: flips board rows, merges green PRs, checks deploys, tidies worktrees, prints the skim-first rep… | SPEC-020, SPEC-060, SPEC-072 +75 | test-bash32-parse.sh, test-bin-forwarders.sh, test-board-lock-required.sh +56 | ## Agents