diff --git a/changelog.d/2791-deploy-guard-target-sha.md b/changelog.d/2791-deploy-guard-target-sha.md new file mode 100644 index 00000000..e0ae3a74 --- /dev/null +++ b/changelog.d/2791-deploy-guard-target-sha.md @@ -0,0 +1 @@ +- **Termux native worker deploy: `--target-sha` no longer breaks the rollout guard (#2791).** `run_guard` built the guard's environment with `${TARGET_SHA:+A2A_WORKER_TARGET_REVISION=…} node …`; an assignment produced by an expansion is not an assignment to bash, so every run with `--target-sha` and a shipped `worker-artifact-rollout-guard.mjs` ran `A2A_WORKER_TARGET_REVISION=…` as the command and failed (rc 127 → exit 20, nothing changed). Found by the first live dry-run on a Termux node; the guard now gets its variables through `env`. New tests (mutation-checked against the old line) cover a shipped guard with `--target-sha`. diff --git a/scripts/a2a-termux-native-worker-deploy.sh b/scripts/a2a-termux-native-worker-deploy.sh index b21f82be..b93373fc 100755 --- a/scripts/a2a-termux-native-worker-deploy.sh +++ b/scripts/a2a-termux-native-worker-deploy.sh @@ -307,8 +307,11 @@ run_guard() { # : the artifact's own rollout guard, when it ships one local root="${1:-$ROOT}" guard out guard="$root/scripts/worker-artifact-rollout-guard.mjs" (( GUARD )) && [[ -f "$guard" ]] || return 0 - out=$(A2A_WORKER_ROOT="$root" ${TARGET_SHA:+A2A_WORKER_TARGET_REVISION="$TARGET_SHA"} \ - node "$guard" --deployed 2>&1) || { say "guard rc!=0: ${out##*$'\n'}"; return 1; } + # The assignments go through `env`: an assignment produced by an expansion is not an assignment to bash, + # so `${TARGET_SHA:+VAR=...} node` ran "VAR=..." as the command (rc 127 on every --target-sha run). + local -a envs=("A2A_WORKER_ROOT=$root") + [[ -n "$TARGET_SHA" ]] && envs+=("A2A_WORKER_TARGET_REVISION=$TARGET_SHA") + out=$(env "${envs[@]}" node "$guard" --deployed 2>&1) || { say "guard rc!=0: ${out##*$'\n'}"; return 1; } python3 - "$out" <<'PY' import json, sys s = sys.argv[1] diff --git a/scripts/a2a-termux-native-worker-deploy.test.sh b/scripts/a2a-termux-native-worker-deploy.test.sh index 00e7488a..f8be42ca 100755 --- a/scripts/a2a-termux-native-worker-deploy.test.sh +++ b/scripts/a2a-termux-native-worker-deploy.test.sh @@ -77,7 +77,7 @@ chmod +x "$TMP/fake-harness.sh" mkdir -p "$TMP/bin" cat > "$TMP/bin/node" <> "$TMP/node.calls" +echo "guard: \$* root=\${A2A_WORKER_ROOT:-} target=\${A2A_WORKER_TARGET_REVISION:-}" >> "$TMP/node.calls" cat "$TMP/guard.out" 2>/dev/null || echo '{"ok":true}' EOF chmod +x "$TMP/bin/node" @@ -163,6 +163,14 @@ ok "dry-run guard runs --deployed against the preview root" \ fresh; echo '{"ok":false}' > "$TMP/guard.out" out=$(deploy --artifact "$ART" --no-guard); rc=$? ok "dry-run --no-guard skips the shipped guard" '[ "$rc" = 0 ] && [ ! -e "$TMP/node.calls" ] && grep -q "guard=off" <<<"$out"' +# A shipped guard together with --target-sha (the way an operator runs a real rollout): the guard gets the target +# revision in its environment. Before this fix the assignment ran as the command (rc 127 on every such run). +fresh; : > "$ART/scripts/worker-artifact-rollout-guard.mjs" +out=$(deploy --artifact "$ART" --target-sha "$NEW_SHA"); rc=$? +ok "dry-run guard + --target-sha: the guard runs and passes" \ + '[ "$rc" = 0 ] && grep -q "DRY-RUN OK" <<<"$out" && ! grep -q "command not found" <<<"$out"' +ok "dry-run guard + --target-sha: the guard sees the target revision" \ + 'grep -q -- "--deployed root=$TMP/stagetmp/.* target=$NEW_SHA\$" "$TMP/node.calls"' rm -f "$ART/scripts/worker-artifact-rollout-guard.mjs" # A symlinked live dist/ (release-dir layout) must not let the preview overlay