Skip to content

fix(bin): repair fm-brief.sh parse error and harden set -u array expansion#205

Open
Ballestar wants to merge 5 commits into
kunchenguid:mainfrom
Ballestar:fm/fm-brief-fix-q6
Open

fix(bin): repair fm-brief.sh parse error and harden set -u array expansion#205
Ballestar wants to merge 5 commits into
kunchenguid:mainfrom
Ballestar:fm/fm-brief-fix-q6

Conversation

@Ballestar

Copy link
Copy Markdown

What Changed

  • Fixed a parse error in bin/fm-brief.sh caused by a lone apostrophe inside the definition-of-done heredoc, so the brief scaffold script runs again.
  • Made the empty-array expansions in bin/fm-pr-merge.sh and bin/fm-spawn.sh set -u-safe so they no longer fail under nounset.
  • Added tests/fm-brief.test.sh covering the ship-brief DOD output (with its assertion aligned to the brief's actual "Follow the no-mistakes guidance for the mechanics" wording) and registered it in the CONTRIBUTING.md test registry.

Risk Assessment

✅ Low: Two narrowly-scoped, correct set -u-safe array-expansion fixes plus a new regression test whose assertions all match the actual script output and available test helpers; the prior wording-mismatch finding is resolved.

Testing

Completed 1 recorded test check.

Pipeline

Updates from git push no-mistakes

⏭️ **intent** - skipped

✅ No issues found.

🔧 **Rebase** - 1 issue found → auto-fixed ✅
  • ⚠️ bin/fm-brief.sh - merge conflict rebasing onto origin/main

🔧 Fix applied.
✅ Re-checked - no issues remain.

🔧 **Review** - 1 issue found → auto-fixed ✅
  • 🚨 tests/fm-brief.test.sh:38 - The new regression test asserts the fixed string "Follow the guidance from no-mistakes itself for the mechanics", but bin/fm-brief.sh:211 actually renders "Follow the no-mistakes guidance for the mechanics". assert_grep uses grep -F (literal), so test_ship_brief_no_mistakes_dod will fail on this line, breaking the very code path it is meant to protect. Update the assertion string to match the brief's actual wording ("Follow the no-mistakes guidance for the mechanics").

🔧 Fix: align fm-brief test assertion with main DOD wording
✅ Re-checked - no issues remain.

✅ **Test** - passed

✅ No issues found.

  • command -v tmux >/dev/null || { echo "tmux is required for e2e tests" >&2; exit 1; }; tmux -V; rc=0; for t in tests/*.test.sh; do echo "== $t =="; bash "$t" || rc=1; done; exit "$rc"
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

Ballestar added 5 commits July 2, 2026 18:30
…D heredoc

A lone single quote inside the no-mistakes Definition-of-done block, built
with DOD=$(cat <<EOF ... EOF), broke bash's $() scanner: it hunted past the
closing EOF) for a matching quote, so `bash -n bin/fm-brief.sh` failed with
"unexpected EOF while looking for matching '" and no brief could be
scaffolded at all. Quoting the heredoc delimiter does not help because the
$() scanner still counts the quote.

Reword the possessive "no-mistakes' own guidance" to "the guidance from
no-mistakes itself" so the block carries no lone apostrophe. The change is
minimal and leaves the brief's wording, escaped backticks, and the scout
and secondmate code paths untouched.

Add tests/fm-brief.test.sh as a regression guard: a bash -n parse check, a
check that the no-mistakes DOD renders the guidance line with literal
backticks and no leftover apostrophe phrasing, and a check that the scout
and secondmate paths still scaffold well-formed briefs.

Upstream kunchenguid#166.
Expanding "${arr[@]}" on an empty array under `set -u` throws "unbound
variable" on bash < 4.4 (notably macOS system bash 3.2), while it is a
no-op on bash 4.4+. Two sites expanded arrays that can legitimately be
empty:

- bin/fm-pr-merge.sh: merge_args is empty when the caller passes an
  explicit merge method, so the extra-args path failed on bash 3.2.
- bin/fm-spawn.sh: shared_args is empty when no --harness/--model/
  --effort/--backend flags are passed, so batch dispatch failed on
  bash 3.2.

Both block the no-mistakes test step (which runs `bash tests/*.test.sh`
locally) on macOS, and are pre-existing failures on main. Use the portable
"${arr[@]+"${arr[@]}"}" idiom, which expands to nothing when the array is
empty or unset and to the elements otherwise, under set -u on all bash
versions. Behavior on bash 4.4+ is unchanged.

Found while running the suite for the fm-brief parse fix; the two affected
tests (fm-pr-merge extra-args, fm-spawn-batch dispatch) now pass on bash
3.2 as well as on CI's bash 5.x.
@kunchenguid

Copy link
Copy Markdown
Owner

Thanks for the PR! It looks like this branch has a merge conflict with the base branch right now. When you get a chance, could you rebase onto (or merge in) the latest base branch, resolve the conflict, and push? Once GitHub shows the PR as mergeable again, it'll be picked back up for review.

Noted for firstmate#205 at 2e77a4aa.

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