From 24de6e5a7120e2106cc7d46cf9ee97f11701dd68 Mon Sep 17 00:00:00 2001 From: Claude Code Bot Date: Wed, 18 Nov 2026 14:27:45 -0800 Subject: [PATCH] fix(swm-macos-runner): put Homebrew first in the job PATH Jobs inherit run-job.sh's environment, and the guest's default PATH has /bin ahead of /opt/homebrew/bin. On the probe PR, nine dotfiles test files failed on this runner but pass on macos-latest: a bare `bash` was /bin/bash 3.2 (`mapfile: command not found`, `${owner,,}: bad substitution`). The same order would also keep python3 on the Command Line Tools 3.9 after the image installs Homebrew python. run-job.sh now exports a Homebrew-first PATH, as on macos-latest. The runner dir is overridable (SWM_RUNNER_DIR) so a new test can run the script against a stub run.sh. That test fails without the PATH line. Advances #252 --- scripts/swm-macos-runner/guest/run-job.sh | 5 +- .../swm-macos-runner/tests/test-run-job.sh | 46 +++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100755 scripts/swm-macos-runner/tests/test-run-job.sh diff --git a/scripts/swm-macos-runner/guest/run-job.sh b/scripts/swm-macos-runner/guest/run-job.sh index 7b54429..03029fb 100755 --- a/scripts/swm-macos-runner/guest/run-job.sh +++ b/scripts/swm-macos-runner/guest/run-job.sh @@ -1,10 +1,13 @@ #!/bin/bash # Guest entrypoint: read the JIT config from stdin (never argv), then run the runner for one job. set -euo pipefail +# Jobs inherit this PATH. Homebrew first, as on macos-latest: else bash is 3.2 +# and python3 is CLT 3.9. +export PATH="/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin" jit="$(cat)" if [[ -z "${jit}" ]]; then echo "run-job: JIT config on stdin is empty" >&2 exit 2 fi -cd /Users/admin/actions-runner +cd "${SWM_RUNNER_DIR:-/Users/admin/actions-runner}" exec ./run.sh --jitconfig "${jit}" diff --git a/scripts/swm-macos-runner/tests/test-run-job.sh b/scripts/swm-macos-runner/tests/test-run-job.sh new file mode 100755 index 0000000..68b2b3b --- /dev/null +++ b/scripts/swm-macos-runner/tests/test-run-job.sh @@ -0,0 +1,46 @@ +#!/bin/bash +# Tests guest/run-job.sh against a stub run.sh in a temp runner dir. +set -u +here="$(cd "$(dirname "$0")" && pwd)" +job="${here}/../guest/run-job.sh" +t="$(mktemp -d "${TMPDIR:-/tmp}/runjob.XXXXXX")" +trap 'rm -r "${t}"' EXIT +pass=0 +fail=0 +check() { # label command... + local label="$1" + shift + if "$@"; then + pass=$((pass + 1)) + echo " PASS: ${label}" + else + fail=$((fail + 1)) + echo " FAIL: ${label}" + fi +} + +# The stub records the PATH and arguments the runner would get. +cat >"${t}/run.sh" <<'EOF' +#!/bin/bash +printf 'PATH=%s\n' "${PATH}" >"${OUT}" +printf 'ARG=%s\n' "$@" >>"${OUT}" +EOF +chmod +x "${t}/run.sh" + +out="${t}/out" +printf 'jit-blob' | env -i PATH=/usr/bin:/bin OUT="${out}" SWM_RUNNER_DIR="${t}" /bin/bash "${job}" +rc=$? +check "exit 0 with a JIT config" test "${rc}" = 0 +check "Homebrew bin comes first in the job PATH" grep -q '^PATH=/opt/homebrew/bin:' "${out}" +check "system dirs stay in the job PATH" grep -q ':/usr/bin:/bin:' "${out}" +check "JIT config passed as --jitconfig" grep -qx 'ARG=--jitconfig' "${out}" +check "JIT config value passed" grep -qx 'ARG=jit-blob' "${out}" + +rm -f "${out}" +env -i PATH=/usr/bin:/bin OUT="${out}" SWM_RUNNER_DIR="${t}" /bin/bash "${job}" /dev/null +rc=$? +check "empty stdin exits 2" test "${rc}" = 2 +check "empty stdin never starts the runner" test ! -e "${out}" + +echo "run-job: ${pass} passed, ${fail} failed" +[[ "${fail}" == 0 ]]