Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

ci: parse every tracked shell script under real bash 3.2 (#5810)

garrytan4b128410d926
diff --git a/.github/workflows/macos-validation.yml b/.github/workflows/macos-validation.yml
index 76215303ca..bb224866cf 100644
--- a/.github/workflows/macos-validation.yml
+++ b/.github/workflows/macos-validation.yml
@@ -15,6 +15,8 @@ name: macOS 26 validation
# #5449 PGLite checkpoint harness on a >= 2 GiB store, asserting the WAL bound.
# #5286 the published signed darwin-arm64 release binary: codesign --verify
# --strict and --version against the release tag.
+# #5810 every tracked *.sh parses under /bin/bash (GNU bash 3.2), and
+# `bun run verify` passes with `bash` resolving to /bin/bash.
on:
schedule:
@@ -83,3 +85,16 @@ jobs:
out="$(./gbrain-darwin-arm64 --version)"
echo "binary reports: $out"
case "$out" in *"${tag#v}"*) ;; *) echo "::error::binary version '$out' does not match release $tag"; exit 1 ;; esac
+ - name: "#5810 shell scripts and bun run verify under /bin/bash 3.2"
+ if: ${{ !cancelled() }}
+ env:
+ GBRAIN_BASH32: /bin/bash
+ GBRAIN_BASH32_REQUIRE: '1'
+ run: |
+ mkdir -p "$RUNNER_TEMP/bash32"
+ ln -sf /bin/bash "$RUNNER_TEMP/bash32/bash"
+ export PATH="$RUNNER_TEMP/bash32:$PATH"
+ bash --version | head -1
+ bun run check:bash32
+ git fetch --no-tags --depth=1 origin +refs/heads/master:refs/remotes/origin/master
+ bun run verify
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index 0d4f3594a5..ba1ece37d5 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -204,6 +204,16 @@ jobs:
# default regardless of per-test third-arg timeouts. Runs directly
# (not via verify's CHECKS array) to avoid a package.json edit.
- run: bash scripts/check-bun-test-timeout.sh
+ # #5810: every tracked *.sh must parse under bash 3.2 (macOS /bin/bash).
+ # The real parser runs in the digest-pinned bash:3.2 image; REQUIRE
+ # turns a missing Docker into a failure instead of a skip, and makes the
+ # test's real-parser fixture cases mandatory.
+ - name: Shell scripts parse under bash 3.2
+ env:
+ GBRAIN_BASH32_REQUIRE: '1'
+ run: |
+ bun run check:bash32
+ bun test --timeout 60000 test/scripts/check-bash32.test.ts
serial-tests:
if: ${{ github.event_name != 'workflow_dispatch' || inputs.native_only != true }}
diff --git a/docs/TESTING.md b/docs/TESTING.md
index dd21200673..d409bf1ee1 100644
--- a/docs/TESTING.md
+++ b/docs/TESTING.md
@@ -829,7 +829,9 @@ itself stays simulated because a runner never reboots), runs the checkpoint
harness above on a store of at least 2 GiB with the WAL-bound assertion
(#5449), and verifies the latest published signed `darwin-arm64` release
binary with `codesign --verify --strict` and `--version` against its release
-tag (#5286). Maintainers with triage or write access apply the label; an
+tag (#5286). It also runs the bash 3.2 parse guard under the
+runner's `/bin/bash`, then `bun run verify` (#5810), so a script or guard that
+only works under bash 4 or later fails there. Maintainers with triage or write access apply the label; an
outside contributor whose change touches macOS-specific persistence, locking
or release code asks for it in the pull request. Scheduled and dispatched runs
use the default branch's workflow file, so the label is the way to get this
@@ -991,7 +993,7 @@ per-file rules. They do not cache passing results. Candidate scanner failures
fail the guard, and matching files retain the same allowlists and diagnostics.
`scripts/guards-manifest.tsv` is THE single registry of `scripts/check-*`
-guards (currently 66), each classified `scanner` (greps/parses repo sources —
+guards (currently 67), each classified `scanner` (greps/parses repo sources —
must eventually carry fixtures), `buildfresh`, or `repostate` (build/freshness
guards are exempt-with-reason, not fixture-tested).
`scripts/guard-self-test.sh` (`bun run check:guard-self-test`, wired into
@@ -1161,6 +1163,29 @@ retire another phrase, add a row to `RETIRED`. Fixtures:
scanned location); every pattern and the exemptions are driven in
`test/scripts/check-retired-phrases.test.ts`.
+#### Bash 3.2 parse guard
+
+macOS ships GNU bash 3.2.57 as `/bin/bash`, and its parser rejects shapes
+bash 5 accepts. The one that broke every Mac (#5810) is a heredoc inside
+`$(...)` whose body holds an odd quote. `scripts/check-bash32.sh`
+(`bun run check:bash32`) runs the real 3.2 parser, `bash -n`, over every
+tracked `*.sh` except the guard fixtures under `test/fixtures/guards/`. It
+uses the first parser available: `GBRAIN_BASH32=<path>` (a bash 3.x binary),
+`/bin/bash` when it is bash 3.x (stock macOS), or the digest-pinned `bash:3.2`
+Docker image (`GBRAIN_BASH32=docker` forces the image). With none it prints
+one skip line and exits 0; `GBRAIN_BASH32_REQUIRE=1` makes that exit 2. Each
+failure prints `FAIL: <file:line>`, `Why:` (macOS `/bin/bash` is 3.2), `Fix:`
+(read heredoc text with `IFS= read -r -d '' VAR <<'EOF' || true`) and `See:`.
+To reproduce one file by hand:
+`docker run --rm -v "$PWD":/w -w /w bash:3.2 bash -n <file>`.
+
+The guard checks parsing only. It is not in `bun run verify`, which must not
+need Docker. The `test.yml` verify job runs it with `GBRAIN_BASH32_REQUIRE=1`
+together with `test/scripts/check-bash32.test.ts`, whose real-parser cases
+feed it the `test/fixtures/guards/check-bash32.sh/{bad,good}` trees. The
+macOS 26 job runs it under `/bin/bash` and then runs `bun run verify` there,
+which covers bash-4 runtime features the parser cannot see.
+
### Placeholder assertions
`scripts/check-test-placeholders.mjs` (`bun run check:test-placeholders`, in
diff --git a/docs/architecture/key-files/tooling-and-tests.md b/docs/architecture/key-files/tooling-and-tests.md
index 33798460fd..a43bce80ae 100644
--- a/docs/architecture/key-files/tooling-and-tests.md
+++ b/docs/architecture/key-files/tooling-and-tests.md
@@ -36,6 +36,7 @@ Current behavior and load-bearing invariants; history belongs in Git and CHANGEL
- `scripts/check-progress-to-stdout.sh` — CI guard against regressing to `\r`-on-stdout progress. Wired into `bun run test` via `scripts/check-progress-to-stdout.sh && bun test` in package.json.
- `scripts/check-retired-phrases.sh` — the retired-phrase guard (`bun run check:retired-phrases`, in `bun run verify`): greps `CLAUDE.md`, `AGENTS.md`, `CONTRIBUTING.md`, `docs/` and `skills/` for contributor-workflow phrases refactor wave 1 retired (the `RETIRED` table: pattern + the current instruction) and prints `FAIL: <file:line>` / `Why:` / `Fix:` / `See: docs/TESTING.md#retired-phrase-guard` per hit. Historical records (`docs/designs/`, `docs/test-audit/`, `docs/incidents/`, `docs/plans/`, `docs/proposals/`, `docs/research/`, `docs/issues/`, `docs/superpowers/`, `docs/migrations/`, `skills/migrations/`, the `docs/architecture/wave-1-*` porting kit) are exempt; `CHANGELOG.md` is not scanned. `GBRAIN_GUARD_ROOT` seam; fixtures `test/fixtures/guards/check-retired-phrases.sh/` (one `bad-<location>` tree per scanned location); pinned by `test/scripts/check-retired-phrases.test.ts`.
+- `scripts/check-bash32.sh` — the bash 3.2 parse guard (`bun run check:bash32`): runs the real GNU bash 3.2 parser (`bash -n`) over every tracked `*.sh` except `test/fixtures/guards/`, because macOS `/bin/bash` is 3.2 and rejects shapes bash 5 accepts (a heredoc inside `$(...)` with an odd quote). Parser order: `GBRAIN_BASH32` (a bash 3.x binary; `docker` forces the image), `/bin/bash` when it is 3.x, then the digest-pinned `bash:3.2` image. No parser prints one skip line and exits 0; `GBRAIN_BASH32_REQUIRE=1` makes it exit 2. Prints `FAIL: <file:line>` / `Why:` / `Fix:` / `See: docs/TESTING.md#bash-32-parse-guard`. Parse only, not in `bun run verify`; run by the `test.yml` verify job (image) and `macos-validation.yml` (`/bin/bash`, followed by `bun run verify`). `GBRAIN_GUARD_ROOT` seam; fixtures `test/fixtures/guards/check-bash32.sh/{bad,good}`; pinned by `test/scripts/check-bash32.test.ts`.
- `scripts/check-source-id-projection.sh` — CI grep guard for the multi-source bug class. Greps `src/core/postgres-engine.ts` + `src/core/pglite-engine.ts` for `SELECT.*FROM pages` projections matching the `rowToPage` feeder shape (id + slug + type + title) and fails if `source_id` is missing. `Page.source_id` is required at the type level; a projection dropping the column produces `Page` rows with `source_id: undefined` while TypeScript's `: string` lies about it. Wired into `bun run verify`.
diff --git a/package.json b/package.json
index 8d49c826c2..86db6e856b 100644
--- a/package.json
+++ b/package.json
@@ -140,6 +140,7 @@
"check:schema-migrations": "bash scripts/check-schema-migrations-fresh.sh",
"check:schema-fresh": "bash scripts/check-schema-fresh.sh",
"check:retired-phrases": "bash scripts/check-retired-phrases.sh",
+ "check:bash32": "bash scripts/check-bash32.sh",
"check:schema-migration-order": "bun scripts/check-schema-migration-order.ts",
"check:compile-autoload": "bash scripts/check-compile-autoload.sh",
"check:structural-manifest": "bash scripts/check-structural-manifest.sh",
diff --git a/scripts/check-bash32.sh b/scripts/check-bash32.sh
new file mode 100755
index 0000000000..57876f4ffd
--- /dev/null
+++ b/scripts/check-bash32.sh
@@ -0,0 +1,115 @@
+#!/usr/bin/env bash
+# CI guard: every tracked shell script parses under bash 3.2.
+#
+# macOS still ships GNU bash 3.2.57 as /bin/bash, and its parser rejects
+# shapes bash 5 accepts: a heredoc inside $(...) whose body has an odd quote
+# made check-retired-phrases.sh unparseable there, so `bun run verify` failed
+# on every Mac (#5810). This guard runs the real 3.2 parser (`bash -n`) over
+# every tracked *.sh except the guard fixtures under test/fixtures/guards/.
+# It checks parsing only; runtime bash-4 features are covered by the macOS 26
+# job running `bun run verify` under /bin/bash.
+#
+# Parser, first available:
+# GBRAIN_BASH32=<path> a bash 3.x binary
+# /bin/bash when it is bash 3.x (stock macOS)
+# Docker image bash:3.2 (GNU bash 3.2.57, digest-pinned)
+# GBRAIN_BASH32=docker forces the image. Without a parser the guard prints
+# one skip line and exits 0, unless GBRAIN_BASH32_REQUIRE=1 (CI), which
+# turns that into exit 2.
+#
+# Run: bun run check:bash32
+# Wired into CI by test.yml (verify job) and macos-validation.yml; not in
+# `bun run verify`, which must not need Docker.
+# Seams: GBRAIN_GUARD_ROOT scans a fixture tree with find instead of
+# git ls-files; GBRAIN_BASH32_DOCKER names the docker CLI.
+
+set -uo pipefail
+
+ROOT="${GBRAIN_GUARD_ROOT:-$(git rev-parse --show-toplevel 2>/dev/null || pwd)}"
+cd "$ROOT" || exit 2
+ROOT="$(pwd -P)"
+
+IMAGE='bash:3.2@sha256:0fd7cb8499c63a3c9345e7088a9cd83bb69f6e895e83833859aff838a0312091'
+DOCKER="${GBRAIN_BASH32_DOCKER:-docker}"
+REQUIRE="${GBRAIN_BASH32_REQUIRE:-0}"
+
+FILES=()
+if [ -n "${GBRAIN_GUARD_ROOT:-}" ]; then
+ while IFS= read -r -d '' f; do FILES+=("${f#./}"); done < <(find . -type f -name '*.sh' -print0)
+else
+ while IFS= read -r -d '' f; do FILES+=("$f"); done < <(git ls-files -z '*.sh')
+fi
+SCAN=()
+for f in ${FILES[@]+"${FILES[@]}"}; do
+ case "$f" in test/fixtures/guards/*) continue ;; esac
+ SCAN+=("$f")
+done
+if [ "${#SCAN[@]}" -eq 0 ]; then
+ echo "✓ bash 3.2 parse: no shell scripts under $ROOT"
+ exit 0
+fi
+
+is_bash3() {
+ [ -x "$1" ] && [ "$("$1" -c 'echo "${BASH_VERSINFO[0]}"' 2>/dev/null)" = "3" ]
+}
+
+unavailable() {
+ if [ "$REQUIRE" = "1" ]; then
+ echo "✗ bash 3.2 parse: $1, and GBRAIN_BASH32_REQUIRE=1 forbids skipping" >&2
+ exit 2
+ fi
+ echo "- bash 3.2 parse: skipped ($1; install Docker or set GBRAIN_BASH32 to a bash 3.2 binary)"
+ exit 0
+}
+
+PARSER="${GBRAIN_BASH32:-}"
+if [ -z "$PARSER" ] && is_bash3 /bin/bash; then PARSER=/bin/bash; fi
+if [ -n "$PARSER" ] && [ "$PARSER" != "docker" ]; then
+ if ! is_bash3 "$PARSER"; then
+ echo "✗ bash 3.2 parse: GBRAIN_BASH32=$PARSER is not an executable bash 3.x" >&2
+ exit 2
+ fi
+ label="$PARSER ($("$PARSER" -c 'echo "$BASH_VERSION"'))"
+ out=""
+ status=0
+ for f in "${SCAN[@]}"; do
+ err=$("$PARSER" -n "$f" 2>&1) || { status=1; out="$out$err
+"; }
+ done
+else
+ command -v "$DOCKER" >/dev/null 2>&1 || unavailable "no bash 3.x at /bin/bash and no docker CLI"
+ "$DOCKER" info >/dev/null 2>&1 || unavailable "the Docker daemon is not reachable"
+ label="$IMAGE"
+ out=$("$DOCKER" run --rm -v "$ROOT":/w:ro -w /w "$IMAGE" bash -c \
+ 'rc=0; for f; do bash -n "$f" 2>&1 || rc=1; done; exit $rc' _ "${SCAN[@]}" 2>&1)
+ status=$?
+ if [ "$status" -gt 1 ]; then
+ printf '%s\n' "$out" >&2
+ unavailable "docker run $IMAGE failed (exit $status)"
+ fi
+fi
+
+if [ "$status" -eq 0 ]; then
+ echo "✓ bash 3.2 parse: ${#SCAN[@]} script(s) parse under $label"
+ exit 0
+fi
+
+errors=0
+while IFS= read -r line; do
+ [ -n "$line" ] || continue
+ errors=$((errors + 1))
+ case "$line" in
+ *": line "[0-9]*": "*)
+ file="${line%%: line *}"
+ rest="${line#*: line }"
+ echo "FAIL: $file:${rest%%:*} does not parse under bash 3.2: ${rest#*: }" >&2
+ ;;
+ *) echo "FAIL: $line" >&2 ;;
+ esac
+done <<< "$out"
+echo "Why: macOS /bin/bash is GNU bash 3.2; a script it cannot parse fails on every Mac (bun run verify included)." >&2
+echo "Fix: read heredoc text with IFS= read -r -d '' VAR <<'EOF' || true instead of VAR=\$(cat <<'EOF' ... EOF), or rewrite the shape bash 3.2 rejects." >&2
+echo "See: docs/TESTING.md#bash-32-parse-guard" >&2
+echo "" >&2
+echo "✗ bash 3.2 parse: $errors error line(s) under $label" >&2
+exit 1
diff --git a/scripts/guards-manifest.tsv b/scripts/guards-manifest.tsv
index 28d067d7c2..c8a84a3027 100644
--- a/scripts/guards-manifest.tsv
+++ b/scripts/guards-manifest.tsv
@@ -73,6 +73,7 @@ check-layering.ts scanner yes EO10 layering (TS AST, every import form): src/cor
check-schema-migrations-fresh.sh buildfresh exempt regenerates src/core/schema-migrations/registry.generated.ts + diffs; generator enforces filename/version/name cross-check and duplicate versions (unit: test/scripts/build-schema-migrations.test.ts)
check-schema-fresh.sh buildfresh exempt W2: regenerates the schema chain (fragments -> schema.sql regions -> schema-embedded -> PGLite template) into a temp dir and diffs every output; names the source to edit (unit: test/scripts/build-schema.test.ts)
check-retired-phrases.sh scanner yes W7 (refactor wave 1): retired contributor-workflow phrases (migrations array, two-engine SQL rule, CLI switch case, region policy, hand-synced PGLite schema) fail in CLAUDE.md, AGENTS.md, CONTRIBUTING.md, docs/, skills/; historical records and the porting kit exempt; GBRAIN_GUARD_ROOT seam; bad-<location> fixtures
+check-bash32.sh scanner todo #5810: every tracked *.sh parses under bash 3.2 (real parser: GBRAIN_BASH32, stock macOS /bin/bash, or the digest-pinned bash:3.2 image); not in verify CHECKS or this self-test, which must not need Docker; its bad/good fixtures run in test/scripts/check-bash32.test.ts, mandatory in the test.yml verify-job step (GBRAIN_BASH32_REQUIRE=1)
check-schema-migration-order.ts repostate exempt EO10: a migration origin/master lacks must be numbered above its latest version; reads the base ref from git (unit: test/scripts/build-schema-migrations.test.ts)
check-structural-manifest.sh buildfresh exempt regenerate+diff of structural-suites.tsv (classify-tests.ts); the diff IS the self-test
check-opencode-pin.sh repostate exempt pin-stamp drift check (OPENCODE-CLI-PIN.md stamps vs heavy-tests opencode-door env); own bun guard tests in test/check-bootstrap-guards.test.ts
diff --git a/test/fixtures/guards/check-bash32.sh/bad/scripts/heredoc-in-subst.sh b/test/fixtures/guards/check-bash32.sh/bad/scripts/heredoc-in-subst.sh
new file mode 100644
index 0000000000..65985119de
--- /dev/null
+++ b/test/fixtures/guards/check-bash32.sh/bad/scripts/heredoc-in-subst.sh
@@ -0,0 +1,8 @@
+#!/usr/bin/env bash
+# Known-bad: bash 5 parses this, bash 3.2 does not. The heredoc sits inside
+# $(...) and its body carries an odd apostrophe, the #5810 shape.
+TABLE=$(cat <<'EOF'
+row-one it's the current instruction
+EOF
+)
+printf '%s\n' "$TABLE"
diff --git a/test/fixtures/guards/check-bash32.sh/good/scripts/heredoc-read.sh b/test/fixtures/guards/check-bash32.sh/good/scripts/heredoc-read.sh
new file mode 100644
index 0000000000..93ae5922b0
--- /dev/null
+++ b/test/fixtures/guards/check-bash32.sh/good/scripts/heredoc-read.sh
@@ -0,0 +1,6 @@
+#!/usr/bin/env bash
+# Known-good: the same table read with read -d '', which bash 3.2 parses.
+IFS= read -r -d '' TABLE <<'EOF' || true
+row-one it's the current instruction
+EOF
+printf '%s' "$TABLE"
diff --git a/test/scripts/check-bash32.test.ts b/test/scripts/check-bash32.test.ts
new file mode 100644
index 0000000000..169e5a8f66
--- /dev/null
+++ b/test/scripts/check-bash32.test.ts
@@ -0,0 +1,131 @@
+/**
+ * scripts/check-bash32.sh — every tracked shell script parses under bash 3.2.
+ *
+ * Protects: `bun run verify` on stock macOS, whose /bin/bash is GNU bash
+ * 3.2.57 (#5810: a heredoc inside $(...) with an odd apostrophe parsed under
+ * bash 5 and broke every Mac).
+ * Fails when: the real 3.2 parser stops flagging the #5810 shape, a guard
+ * fixture leaks into the scan, a failure loses its FAIL file:line / Why / Fix
+ * / See lines, or a missing parser stops being a one-line skip (exit 2 under
+ * GBRAIN_BASH32_REQUIRE=1).
+ * Seams: GBRAIN_GUARD_ROOT (fixture tree), GBRAIN_BASH32 (parser binary; a
+ * shim here), GBRAIN_BASH32_DOCKER (docker CLI). The real-parser cases run
+ * when bash 3.2 is reachable without a network pull (stock /bin/bash, or the
+ * pinned image already present) and are mandatory under
+ * GBRAIN_BASH32_REQUIRE=1, which the CI step sets.
+ */
+import { afterEach, beforeEach, describe, expect, it } from 'bun:test';
+import { spawnSync } from 'node:child_process';
+import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+import { join, resolve } from 'node:path';
+
+const REPO = resolve(import.meta.dir, '..', '..');
+const SCRIPT = join(REPO, 'scripts/check-bash32.sh');
+const FIXTURES = join(REPO, 'test/fixtures/guards/check-bash32.sh');
+const IMAGE = /^IMAGE='([^']+)'$/m.exec(readFileSync(SCRIPT, 'utf8'))![1]!;
+
+let root: string;
+beforeEach(() => {
+ root = mkdtempSync(join(tmpdir(), 'bash32-guard-'));
+});
+afterEach(() => {
+ rmSync(root, { recursive: true, force: true });
+});
+
+function write(rel: string, content: string, mode = 0o644): string {
+ const abs = join(root, rel);
+ mkdirSync(resolve(abs, '..'), { recursive: true });
+ writeFileSync(abs, content, { mode });
+ return abs;
+}
+
+/** A parser shim that reports bash 3 and rejects any file named bad*.sh. */
+function shim(major = 3): string {
+ return write('bin/bash32', `#!/bin/sh
+if [ "$1" = "-c" ]; then
+ case "$2" in *BASH_VERSINFO*) echo ${major} ;; *) echo "${major}.2.57(1)-shim" ;; esac
+ exit 0
+fi
+case "$2" in *bad*.sh) echo "$2: line 4: unexpected EOF while looking for matching \\\`''" >&2; exit 2 ;; esac
+exit 0
+`, 0o755);
+}
+
+function run(guardRoot: string, env: Record<string, string> = {}) {
+ return spawnSync('bash', [SCRIPT], {
+ encoding: 'utf8',
+ env: { ...process.env, GBRAIN_BASH32: '', GBRAIN_BASH32_REQUIRE: '', GBRAIN_GUARD_ROOT: guardRoot, ...env },
+ });
+}
+
+describe('check-bash32.sh reporting (parser shim)', () => {
+ it('passes a tree whose scripts all parse and counts only scanned scripts', () => {
+ write('tree/scripts/a.sh', 'echo a\n');
+ write('tree/b.sh', 'echo b\n');
+ write('tree/test/fixtures/guards/g/bad/x-bad.sh', 'echo fixture\n');
+ const r = run(join(root, 'tree'), { GBRAIN_BASH32: shim() });
+ expect(r.status).toBe(0);
+ expect(r.stdout).toContain('✓ bash 3.2 parse: 2 script(s) parse under');
+ });
+
+ it('fails with FAIL file:line, Why, Fix and See, and never scans guard fixtures', () => {
+ write('tree/scripts/ok.sh', 'echo ok\n');
+ write('tree/scripts/bad-table.sh', 'echo bad\n');
+ write('tree/test/fixtures/guards/g/bad/also-bad.sh', 'echo fixture\n');
+ const r = run(join(root, 'tree'), { GBRAIN_BASH32: shim() });
+ expect(r.status).toBe(1);
+ expect(r.stderr).toContain('FAIL: scripts/bad-table.sh:4 does not parse under bash 3.2: unexpected EOF');
+ expect(r.stderr).not.toContain('also-bad.sh');
+ expect(r.stderr).toMatch(/^Why: {2}macOS \/bin\/bash is GNU bash 3\.2/m);
+ expect(r.stderr).toContain("Fix: read heredoc text with IFS= read -r -d '' VAR <<'EOF' || true");
+ expect(r.stderr).toContain('See: docs/TESTING.md#bash-32-parse-guard');
+ });
+
+ it('refuses an explicit GBRAIN_BASH32 that is not bash 3.x', () => {
+ write('tree/a.sh', 'echo a\n');
+ const r = run(join(root, 'tree'), { GBRAIN_BASH32: shim(5) });
+ expect(r.status).toBe(2);
+ expect(r.stderr).toContain('is not an executable bash 3.x');
+ });
+
+ it('prints one skip line without a parser, and exits 2 when the parser is required', () => {
+ write('tree/a.sh', 'echo a\n');
+ const noDocker = { GBRAIN_BASH32: 'docker', GBRAIN_BASH32_DOCKER: join(root, 'missing-docker') };
+ const skipped = run(join(root, 'tree'), noDocker);
+ expect(skipped.status).toBe(0);
+ expect(skipped.stdout.trim().split('\n')).toEqual([
+ '- bash 3.2 parse: skipped (no bash 3.x at /bin/bash and no docker CLI; install Docker or set GBRAIN_BASH32 to a bash 3.2 binary)',
+ ]);
+ const required = run(join(root, 'tree'), { ...noDocker, GBRAIN_BASH32_REQUIRE: '1' });
+ expect(required.status).toBe(2);
+ expect(required.stderr).toContain('GBRAIN_BASH32_REQUIRE=1 forbids skipping');
+ });
+});
+
+function realParserReachable(): boolean {
+ if (process.env.GBRAIN_BASH32_REQUIRE === '1') return true;
+ const native = spawnSync('/bin/bash', ['-c', 'echo "${BASH_VERSINFO[0]}"'], { encoding: 'utf8' });
+ if (native.stdout?.trim() === '3') return true;
+ return spawnSync('docker', ['image', 'inspect', IMAGE], { stdio: 'ignore' }).status === 0;
+}
+
+describe.skipIf(!realParserReachable())('check-bash32.sh under the real bash 3.2 parser', () => {
+ it('flags a heredoc inside $(...) with an odd apostrophe (the #5810 shape)', () => {
+ const r = run(join(FIXTURES, 'bad'));
+ expect(r.status).toBe(1);
+ expect(r.stderr).toContain('FAIL: scripts/heredoc-in-subst.sh:');
+ expect(r.stderr).toContain("unexpected EOF while looking for matching `''");
+ }, 60_000);
+
+ it('passes the same table read with read -d', () => {
+ const r = run(join(FIXTURES, 'good'));
+ expect(r.status).toBe(0);
+ }, 60_000);
+
+ it('passes every tracked script in this repository', () => {
+ const r = spawnSync('bash', [SCRIPT], { encoding: 'utf8', cwd: REPO, env: { ...process.env, GBRAIN_GUARD_ROOT: '' } });
+ expect(r.stderr).toBe('');
+ expect(r.status).toBe(0);
+ }, 60_000);
+});
diff --git a/test/scripts/run-verify-parallel.test.ts b/test/scripts/run-verify-parallel.test.ts
index c7aba80661..e5a445e49b 100644
--- a/test/scripts/run-verify-parallel.test.ts
+++ b/test/scripts/run-verify-parallel.test.ts
@@ -78,6 +78,8 @@ describe("guard registration ⇒ execution coverage", () => {
"duplicates check:admin-build's vite+tsc build; embed freshness covered there",
"check-image-decoders-embedded.sh":
"runs its own bun build --compile — too heavy for per-verify cadence",
+ "check-bash32.sh":
+ "needs Docker or a native bash 3.2: runs as a test.yml verify-job step (bash:3.2 image) and in macos-validation.yml (/bin/bash), never in verify",
"check-test-discriminates.sh":
"manual per-PR discrimination helper (#3665): reverts named source files and re-runs bun test to prove the test fails without the fix — cannot know which hunk is 'the fix' on an arbitrary diff, so deliberately not in verify/CI (manifest row says the same)",
};