From 4003c6a2737e3e40106c58251bfe28cfdbfb2dd7 Mon Sep 17 00:00:00 2001 From: Defame1297 Date: Thu, 13 Aug 2026 19:47:42 +0000 Subject: [PATCH] fix(kyberforge): make bats dispatcher bash-3.2 safe run-bats.sh's new bounded parallel dispatcher used nproc/wait -n, which are bash 4.3+/GNU-only and silently drop the concurrency cap on macOS's stock bash 3.2 (the wait -n error is swallowed by `|| true`). Its sibling tests/run-tests.sh, changed in the same PR and explicitly bash-3.2-safe, already solves this with getconf + a batched wait. Ported that same pattern here for consistency and to actually meet the compatibility goal. Refs: #95 --- tests/run-bats.sh | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/tests/run-bats.sh b/tests/run-bats.sh index 9059661..8aff317 100755 --- a/tests/run-bats.sh +++ b/tests/run-bats.sh @@ -39,11 +39,12 @@ fi SCRATCH_ROOT="$(mktemp -d)" trap 'rm -rf "$SCRATCH_ROOT"' EXIT -# A failing test is the normal case a CI runner must handle, and a failing -# background job makes `wait`/`wait -n` return non-zero -- under `set -e` that -# would abort the script right here, before the per-file report below ever -# runs. Every wait in this dispatcher is therefore explicitly guarded. -JOBS="$(nproc 2>/dev/null || echo 4)" +# Batches (not a rolling pool) because a bounded rolling pool needs `wait -n`, +# which is bash 4.3+ and this script is explicitly bash-3.2-safe like +# run-tests.sh; plain `wait` -- waiting for every job in the current batch -- +# is available since ancient bash. `getconf` over `nproc` for the same +# reason: `nproc` doesn't exist on macOS. +JOBS="$(getconf _NPROCESSORS_ONLN 2>/dev/null || echo 4)" running=0 i=0 for f in "${TEST_FILES[@]}"; do @@ -51,11 +52,11 @@ for f in "${TEST_FILES[@]}"; do ( "$BATS" "$f" >"$SCRATCH_ROOT/$i.log" 2>&1; echo $? >"$SCRATCH_ROOT/$i.status" ) & running=$((running + 1)) if [[ "$running" -ge "$JOBS" ]]; then - wait -n || true - running=$((running - 1)) + wait + running=0 fi done -wait || true +wait FAIL=0 TOTAL_OK=0