Skip to content

fix(brief): eliminate heredoc-in-command-substitution bash 3.2 bug at the root - #585

Closed
saucetech wants to merge 1 commit into
kunchenguid:mainfrom
saucetech:fm/fix-fm-brief-bash32
Closed

saucetech wants to merge 1 commit into
kunchenguid:mainfrom
saucetech:fm/fix-fm-brief-bash32

Conversation

@saucetech

Copy link
Copy Markdown

Summary

  • bin/fm-brief.sh had four VAR=$(cat <<EOF ... EOF) heredoc-in-command-substitution sites. Bash 3.2's lexer loses quote-tracking through a heredoc body nested inside $(...), so a single unescaped apostrophe anywhere in that text breaks parsing of the entire rest of the script (bash -n fails). PR fix(brief): remove apostrophe breaking bash -n and guard bash 3.2 set -u in spawn #173 previously worked around this by rewording the one sentence that happened to trip it, leaving the fragile pattern in place at all four sites. This PR fixes the root cause: each heredoc is now defined inside a small local function whose stdout is captured instead (DOD=$(dod_text)), keeping the heredoc lexically outside any $(...) and making it structurally immune to the bug regardless of body content.
  • bin/fm-spawn.sh's batch-dispatch shared_args[@] expansion was already fixed by the same prior PR (fix(brief): remove apostrophe breaking bash -n and guard bash 3.2 set -u in spawn #173) with the portable ${shared_args[@]+"${shared_args[@]}"} idiom. No code change needed there; verified clean under stock macOS Bash 3.2.57.
  • Extended the existing macos-stock-bash CI job (added in fix: restore fleet snapshots on stock macOS Bash #578) to cover both scripts going forward: bash -n on each, plus running tests/fm-brief.test.sh and tests/fm-spawn-batch.test.sh under real stock Bash 3.2.57, so this class of regression is caught on the actual target shell instead of only the Linux runners' modern bash.

Test plan

  • bash -n bin/fm-brief.sh and bash -n bin/fm-spawn.sh under /bin/bash 3.2.57 (this machine's stock bash) and under a modern bash
  • tests/fm-brief.test.sh (11/11) and tests/fm-spawn-batch.test.sh (3/3) pass under both bash versions
  • Reproduced the original bug in isolation ($(cat <<EOF ... apostrophe ... EOF) fails to parse under 3.2 with both quoted and unquoted heredoc delimiters) and confirmed the post-fix script still parses even with an apostrophe re-injected into the DOD text
  • Diffed generated scaffolds (ship in all three delivery modes, scout, --herdr-lab, secondmate) between the pre-fix and post-fix script under bash 3.2.57 - byte-identical after normalizing incidental scratch-path differences
  • bin/fm-lint.sh (pinned ShellCheck 0.11.0) - clean
  • Simulated the added macos-stock-bash CI job steps locally in a sanitized stock-Bash environment - all pass

No-mistakes gate note: review/document/lint all completed cleanly through the local no-mistakes gate. The test step's single lump finding covered 4 pre-existing failures in tests/fm-backlog-handoff.test.sh, tests/fm-pi-watch-extension.test.sh, tests/fm-secondmate-lifecycle-e2e.test.sh, and tests/fm-turnend-guard.test.sh - none touch the files changed in this PR. Two were resolved by upgrading this sandbox's stale global tasks-axi (0.1.2 -> 0.2.3, matching what CI installs fresh); the remaining two are a Node v23.7.0 ExperimentalWarning runtime artifact in this sandbox, unrelated to firstmate code, so that gate step was skipped with documented reasoning rather than editing test files. The gate's automated push step then failed with a GitHub permissions error (the local git identity lacks write access to kunchenguid/firstmate), so this PR was opened manually via a fork per captain direction instead of through the gate's own push/PR steps.

… the root

PR kunchenguid#173 worked around bash 3.2's here-doc-inside-$(...) quote-tracking bug in
fm-brief.sh by rewording the one DOD line that happened to trip it, leaving
the fragile VAR=$(cat <<EOF ... EOF) pattern in place in four spots. Any future
apostrophe added to those bodies breaks `bash -n` on the whole script again.
Wrap each heredoc in a local function and capture its stdout instead
(DOD=$(dod_text)), which keeps the heredoc lexically outside any $(...) and
is immune to the bug regardless of body content. Output is byte-identical
across ship (all three delivery modes), scout, --herdr-lab, and secondmate
scaffolds - verified by diffing against the pre-fix scaffolds.

bin/fm-spawn.sh's batch-dispatch shared_args[@] expansion was already fixed
by kunchenguid#173 with the portable ${arr[@]+"${arr[@]}"} idiom; confirmed clean under
stock macOS Bash 3.2.57 today. Extended the macos-stock-bash CI job (added in
kunchenguid#578) to cover both scripts going forward: bash -n on each, plus the existing
tests/fm-brief.test.sh and tests/fm-spawn-batch.test.sh suites, so this class
of regression is caught on real stock Bash instead of only the Linux runners'
modern bash.
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: closing this as stale. It has been waiting on a contributor update for 14+ days with no author push or comment. Reopen if you want to pick it back up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants