Skip to content

The open-source app everyone uses to manage agents at work

fix(runtime): guard empty Bash 3.2 array expansion (#11891)

scotttongdc5b070709b6
diff --git a/scripts/__tests__/provision-worktree-self-heal.test.mjs b/scripts/__tests__/provision-worktree-self-heal.test.mjs
index 34d64167fb..bbe44698d1 100644
--- a/scripts/__tests__/provision-worktree-self-heal.test.mjs
+++ b/scripts/__tests__/provision-worktree-self-heal.test.mjs
@@ -381,6 +381,39 @@ test("runtime provisioning invokes ensure-seeded once and fast-exits after succe
assert.equal(ensureCallsAfterSecond.length, 1);
});
+test("runtime provisioning omits the source override when the base config exists", () => {
+ const baseCwd = makeBaseWorkspace({ helpExit: 0, initExit: 0 });
+ fs.mkdirSync(path.join(baseCwd, ".paperclip"), { recursive: true });
+ fs.writeFileSync(path.join(baseCwd, ".paperclip", "config.json"), "{}\n");
+ const worktreeCwd = makeTempDir("paperclip-provision-runtime-base-config-");
+ fs.mkdirSync(path.join(worktreeCwd, ".paperclip"), { recursive: true });
+ fs.writeFileSync(path.join(worktreeCwd, ".paperclip", "config.json"), "{}\n");
+
+ const result = runRuntimeProvision(baseCwd, worktreeCwd);
+
+ assert.equal(result.status, 0, result.stderr);
+ const ensureCall = readCliInvocations(baseCwd).find(
+ (args) => args[0] === "worktree" && args[1] === "ensure-seeded",
+ );
+ assert.ok(ensureCall, "expected the runtime provisioner to invoke ensure-seeded");
+ assert.ok(!ensureCall.includes("--from-config"));
+});
+
+test("runtime provisioning guards every optional source-config expansion for Bash 3.2", () => {
+ const source = fs.readFileSync(runtimeScript, "utf8");
+ const ensureSeededLines = source
+ .split("\n")
+ .filter((line) => line.includes("worktree ensure-seeded --config"));
+
+ assert.equal(ensureSeededLines.length, 3);
+ for (const line of ensureSeededLines) {
+ assert.ok(
+ line.includes('${source_config_args[@]+"${source_config_args[@]}"}'),
+ `expected Bash 3.2-compatible optional array expansion in: ${line}`,
+ );
+ }
+});
+
test("runtime provisioning seeds a worktree config that has no seed markers", () => {
const baseCwd = makeBaseWorkspace({ helpExit: 0, initExit: 0 });
const worktreeCwd = makeTempDir("paperclip-provision-runtime-unmarked-config-");
diff --git a/scripts/provision-worktree-runtime.sh b/scripts/provision-worktree-runtime.sh
index 99a56fe1e4..a6d925918a 100755
--- a/scripts/provision-worktree-runtime.sh
+++ b/scripts/provision-worktree-runtime.sh
@@ -1,4 +1,5 @@
#!/usr/bin/env bash
+# Keep this script compatible with macOS's system Bash 3.2.
set -euo pipefail
base_cwd="${PAPERCLIP_WORKSPACE_BASE_CWD:?PAPERCLIP_WORKSPACE_BASE_CWD is required}"
@@ -139,7 +140,7 @@ run_ensure_seeded() {
if ensure_base_cli_healthy; then
(
cd "$worktree_cwd" &&
- node "$base_cli_runner_path" "$base_cli_entry_path" worktree ensure-seeded --config "$worktree_config_path" "${source_config_args[@]}"
+ node "$base_cli_runner_path" "$base_cli_entry_path" worktree ensure-seeded --config "$worktree_config_path" ${source_config_args[@]+"${source_config_args[@]}"}
)
return
fi
@@ -147,7 +148,7 @@ run_ensure_seeded() {
if command -v pnpm >/dev/null 2>&1 && pnpm paperclipai --help >/dev/null 2>&1; then
(
cd "$worktree_cwd" &&
- pnpm paperclipai worktree ensure-seeded --config "$worktree_config_path" "${source_config_args[@]}"
+ pnpm paperclipai worktree ensure-seeded --config "$worktree_config_path" ${source_config_args[@]+"${source_config_args[@]}"}
)
return
fi
@@ -155,7 +156,7 @@ run_ensure_seeded() {
if command -v paperclipai >/dev/null 2>&1; then
(
cd "$worktree_cwd" &&
- paperclipai worktree ensure-seeded --config "$worktree_config_path" "${source_config_args[@]}"
+ paperclipai worktree ensure-seeded --config "$worktree_config_path" ${source_config_args[@]+"${source_config_args[@]}"}
)
return
fi