Repository navigation
fix(bin): load backend sibling libraries when sourced under zsh - #6221
Conversation
|
| for rel in "$@"; do | ||
| sibling="$FM_BACKEND_LIB_DIR/$rel" | ||
| fm_backend_source_readable "$sibling" || return 1 |
There was a problem hiding this comment.
Real adapters load incompletely
Under zsh, this new check can pass for every sibling file, but the real adapters still use BASH_SOURCE to locate those files when sourcing them. Zsh does not populate BASH_SOURCE, so an adapter can look in the wrong directory. fm_backend_source can then report success and mark the adapter as loaded even though required shared functions are missing. The new stub test does not exercise the real adapter imports.
Knowledge Base Used: Agent backends and harnesses
| mkdir -p "$stub/backends" | ||
| printf 'command -v dirname > "%s"\n' "$probe" > "$stub/backends/orca.sh" | ||
| : > "$stub/fm-composer-lib.sh" | ||
| zsh -c "cd '$ROOT' && source bin/fm-backend.sh && FM_BACKEND_LIB_DIR='$stub' && fm_backend_source orca" >/dev/null 2>&1 \ |
There was a problem hiding this comment.
fm_backend_source kept each backend's sibling list in one space-separated string and iterated it unquoted. zsh does not word-split an unquoted expansion, so the readability check saw the whole list as one path and refused every backend with more than one sibling. Hold the list in the function's positional parameters instead, which needs no word splitting in Bash 3.2, Bash 5, or zsh. The existing zsh case in tests/fm-backend.test.sh covers it wherever zsh is installed.
The suite injected shell values into its generated Node scripts with the
${value@Q} transformation, which needs Bash 4.4. Stock macOS Bash 3.2
reports a bad substitution, so every case failed before it asserted
anything. Build each JavaScript string literal with JSON.stringify
through a small helper instead, which works on any Bash and is a valid
literal for any value.
Under zsh the adapters locate their siblings through BASH_SOURCE, so a successful fm_backend_source is not a full load. Assert only what the contract states, and pass js_string values after -- so node never reads a leading-dash value as its own option.
d3a85bb to
ffb67ec
Compare
|
Speaking as Kun's firstmate: this is merged. Thank you @guanchengh-lgtm — really appreciate you taking the time on this. contract-class: restore — tip VISION: One captain/interface — aligns. Authority — aligns. Scripts/judgment — aligns. Restart — n/a. Delegation — n/a. Fleet/vendor — aligns (backend adapters load under zsh name/sibling precheck). Scope — aligns. Squash merge |
Intent
Context: a worker building another fix ran 63 changed-selection test suites of the firstmate repository. Seven failed the same way on the base commit, so they are not caused by its change: fm-muse-harness, fm-timeout-lib, fm-harness-precedence, fm-calm-claude-mod, fm-backend zsh source, fm-control-relaunch and fm-git-strip-ai-trailers. Real-herdr and live test families were not run. The Outside Voice verified all seven fail every time on a clean default branch on macOS with Bash 3.2 and zsh, while upstream CI passes them because it runs Bash 5 on Linux without zsh. Two of the causes are ours to fix and need a fix: fm_backend_source in bin/fm-backend.sh depends on word splitting, which zsh does not do, so sourcing a backend under zsh fails (a regression against a contract the repository tests on purpose); and the fm-calm-claude-mod test uses the Bash 4.4 expansion
${var@Q}, which fails on older Bash with a bad substitution.What Changed
fm_backend_sourceinbin/fm-backend.shnow passes each backend's sibling library list through the positional parameters (set --/"$@") and no longer uses an unquoted space-separated string. Under zsh, which does not word-split, the old string was read as one path, so the call failed. The loop local is nowsibling, notpath, because zsh tiespathtoPATH, and a local namedpathwould clobberPATHwhile the adapter loads.tests/fm-backend.test.shlimits the zsh check to backend name matching and the sibling precheck. It also adds a stub-adapter case that confirmsPATHstill resolves external commands whilefm_backend_sourceloads a backend under zsh.tests/fm-calm-claude-mod.test.shreplaces the Bash 4.4${var@Q}expansions in its generated Node scripts with ajs_stringhelper (it usesJSON.stringifyin Node). The suite now runs on stock macOS Bash 3.2 without a bad-substitution error.🤖 Generated with Claude Code
Risk Assessment
✅ Low: The change is small and well-bounded. Moving the sibling list into function-local positional parameters makes the list split the same way under bash and zsh. The rename removes the clobbering of the zsh
pathvariable, which is tied to PATH. No adapter or sibling library reads the inherited positional parameters at top level. The tests replace${var@Q}with a JSON-encoded node literal that works on Bash 3.2, and the new zsh PATH check tests real behavior.Testing
I sourced bin/fm-backend.sh in real zsh and in real macOS Bash 3.2, at both the base commit and the head commit. At base, zsh rejected tmux, herdr, zellij and cmux. At head, zsh loaded all five backends, rejected the bogus name, and kept PATH working. Bash behavior did not change. On Bash 3.2, both changed suites pass at head. The base calm-claude-mod suite fails with "bad substitution". I removed all temporary files.
pathlocal does not clobber PATHEvidence: zsh/bash fm_backend_source base vs head
Source: zsh/bash fm_backend_source base vs head
Evidence: Changed suites on Bash 3.2 (head) and calm suite base comparison
Source: Changed suites on Bash 3.2 (head) and calm suite base comparison
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
✅ **Review** - passed
✅ No issues found.
✅ **Test** - passed
✅ No issues found.
pathlocal does not clobber PATHzsh -c "source bin/fm-backend.sh && fm_backend_source <tmux|herdr|zellij|orca|cmux|bogus>; command -v dirname"at base 549e07f3 (git archive copy) and headbash -c "source bin/fm-backend.sh && fm_backend_source <each>"on /bin/bash 3.2.57 at base and head/bin/bash tests/fm-backend.test.sh(head)/bin/bash tests/fm-calm-claude-mod.test.sh(head)base copy of tests/fm-calm-claude-mod.test.sh run on /bin/bash 3.2 (temp file, removed)✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.