Skip to content

fix: restore stock macOS Bash 3.2 brief scaffolding - #1093

Merged
kunchenguid merged 4 commits into
kunchenguid:mainfrom
karotkriss:fm/fm-brief-bash32-upstream-fix
Jul 28, 2026
Merged

kunchenguid merged 4 commits into
kunchenguid:mainfrom
karotkriss:fm/fm-brief-bash32-upstream-fix

Conversation

@karotkriss

@karotkriss karotkriss commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

Intent

Restore stock macOS Bash 3.2 (/bin/bash 3.2.57) brief scaffolding in bin/fm-brief.sh with a structural parser-safe implementation and durable cross-version regression coverage. The core fix replaces every command-substitution-wrapped here-document (VAR=$(cat <<EOF ... EOF), which breaks Bash 3.2's parser) with 'IFS= read -r -d "" VAR <<EOF || true', eliminating the whole defect class while keeping generated briefs byte-identical to prior output.

This revision hardens the regression guard and is the only change since the last green run. The prior hand-rolled scanner (a Perl state machine) mis-parsed a case-pattern ) as closing a command substitution, so a here-document nested in a command substitution via a case arm slipped past unflagged even though that form genuinely fails 'bash -n' on stock macOS Bash 3.2.57. Deliberate decisions a reviewer should not flag as mistakes: (1) Replace the hand-rolled scanner with a real Bash parser rather than adding another special case; the guard in tests/tools/heredoc-guard walks mvdan.cc/sh's syntax tree and rejects any here-document nested beneath a command substitution regardless of intervening valid shell (case patterns, nested parens, quoting). (2) The parser is pinned (mvdan.cc/sh v3.7.0, Go 1.19 floor) and vendored so the check builds offline with -mod=vendor and stays auditable; it has no transitive dependencies, which is why tests/tools/heredoc-guard/vendor is committed. (3) The test skips with a gate line when no Go toolchain is present (matching the repo's existing optional-tool test pattern) and is enforced on CI; the stock macOS Bash 3.2.57 full-surface 'bash -n' sweep remains the independent end-to-end layer, so the class-level guarantee holds either way. (4) The guard is a deliberate conservative structural over-approximation: it rejects the fragile here-document-in-command-substitution shape even when a given body is currently benign, which is intended class-level coverage rather than a bug. (5) Regression coverage now includes the exact case-pattern bypass and ordinary safe case syntax, plus a genuinely inert quoted here-document body that must not be flagged. All existing fm-brief tests, lint, the doc-audience check, and the shell-inventory/CI-parity checks pass; brief output remains byte-identical so no crewmate runtime is affected.

What Changed

  • Replace command-substitution-wrapped here-documents in brief scaffolding with Bash 3.2-safe read assignments while preserving generated output byte-for-byte.
  • Add a pinned, vendored Bash parser guard that rejects here-documents nested inside command substitutions, including case-arm variants.
  • Expose the canonical shell inventory through fm-lint.sh --list-files and use it for the full stock macOS Bash syntax sweep in CI.

Risk Assessment

✅ Low: The change is well-bounded, structurally removes the Bash 3.2 parser hazard, preserves generated output, and adds durable parser-backed and macOS coverage.

Testing

After inspecting the target diff and confirming this Linux runner has Bash 5.3 rather than macOS Bash 3.2, both focused test scripts passed, the pinned vendored parser built offline and correctly classified all manual fixtures, six real CLI scaffold paths matched the base commit byte-for-byte, the test confirmed the canonical inventory feeds the macOS 3.2 CI sweep, and the worktree remained clean.

Evidence: Brief scaffolding E2E and byte-identity transcript