Skip to content

fix(tasks): stop expanding possibly-empty arrays bare under set -u - #278

Merged
krisztian-gajdar merged 1 commit into
mainfrom
fix/bash32-empty-array-expansion
Sep 14, 2026
Merged

krisztian-gajdar merged 1 commit into
mainfrom
fix/bash32-empty-array-expansion

Conversation

@krisztian-gajdar

@krisztian-gajdar krisztian-gajdar commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

Summary

macOS ships bash 3.2.57, where "${ARR[@]}" on an empty array is a hard error under set -u rather than an empty expansion:

$ /bin/bash -c 'set -euo pipefail; A=(); printf "%s\n" "${A[@]}"'
/bin/bash: A[@]: unbound variable

serve.bash declares UV_BUNDLE_ARGS=(), fills it only for cuda13 bundles, and expands it bare, so mise run serve with any other bundle fails on a stock macOS shell before the server starts. SERVER_ARGS=("$@") on the two lines below it is the same shape with a different trigger: empty whenever the task is run with no arguments. test.bash carries the same shape twice (ARGS, model_node_ids).

The portable form

${ARR[@]+"${ARR[@]}"} expands to nothing when the array is empty and is identical otherwise. "${ARR[@]:-}" is not a substitute, because it injects one empty argument.

The guard

tools/ci/tests/test_bash_empty_array_expansion.py scans every task script under set -u and keys on the arrays that can actually be empty: declared literally empty, or seeded from the script's own arguments. Two positive controls stop it passing vacuously, and a second test pins the detector against the crashing shape and its fixed form, quoted and unquoted, including an unsafe expansion sitting beside a guarded one.

Verification

  • bash -n on both scripts under 3.2.57; the empty-array crash and the guarded form reproduced directly on 3.2.57 (output above).
  • pytest -q tools/ci/tests: 314 passed, including the two new tests.
  • ruff format --check and ruff check --select E,F,I,UP,B clean on the new test.

Summary by CodeRabbit

  • Bug Fixes

    • Fixed task commands so empty optional arguments no longer produce unintended empty parameters.
    • Preserved correct argument handling when dependency, server, model-selection, and test arguments are provided.
  • Tests

    • Added regression coverage to detect unsafe expansion of potentially empty Bash arrays.
    • Added checks for quoted, unquoted, guarded, adjacent, and argument-populated array expansions.

@krisztian-gajdar
krisztian-gajdar requested a review from a team as a code owner September 14, 2026 17:40
@coderabbitai

coderabbitai Bot commented Sep 14, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Team

Run ID: d89176ca-dbd5-439c-a953-81db232f2fac

📥 Commits

Reviewing files that changed from the base of the PR and between 0560f01 and 1cf8aac.

📒 Files selected for processing (3)
  • tools/ci/tests/test_bash_empty_array_expansion.py
  • tools/mise_tasks/serve.bash
  • tools/mise_tasks/test.bash

Included review availability: Your plan provides up to 10 included reviews per hour; 6 remain after this review.


📝 Walkthrough

Walkthrough

The pull request adds regression coverage for unsafe empty-array expansion in strict-mode Bash task scripts. It also updates the serve and test tasks to conditionally expand optional arrays.

Changes

Bash array safety

Layer / File(s) Summary
Empty-array expansion regression coverage
tools/ci/tests/test_bash_empty_array_expansion.py
The new tests scan strict-mode task scripts for unsafe expansions and verify guarded, quoted, unquoted, adjacent, and argument-seeded cases.
Task script expansion guards
tools/mise_tasks/serve.bash, tools/mise_tasks/test.bash
The tasks conditionally expand optional arrays so empty arrays do not add arguments. Populated array elements remain quoted and preserved.

Suggested reviewers: mamayer19

Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to 97792

The task scripts now omit empty optional argument arrays safely while preserving populated arguments. No unresolved merge-readiness risk was identified.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: preventing bare expansion of possibly empty Bash arrays under set -u in task scripts.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/bash32-empty-array-expansion

Comment @coderabbitai help to get the list of available commands.

macOS bash 3.2.57 treats "${ARR[@]}" on an empty array as an unbound
variable under set -u, so serve.bash failed before the server started for
any non-cuda13 bundle. Use the portable ${ARR[@]+"${ARR[@]}"} form in
serve.bash and test.bash, and add a test that scans every task script for
the class.
@krisztian-gajdar

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Sep 14, 2026

Copy link
Copy Markdown
⚠️ Action not completed

Already reviewed the last commit. Use @coderabbitai full review to rerun a review of the entire changeset.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@krisztian-gajdar
krisztian-gajdar force-pushed the fix/bash32-empty-array-expansion branch from 1cf8aac to 9779263 Compare September 14, 2026 18:09
@krisztian-gajdar
krisztian-gajdar merged commit e0084c7 into main Sep 14, 2026
19 checks passed
@krisztian-gajdar
krisztian-gajdar deleted the fix/bash32-empty-array-expansion branch September 14, 2026 21:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant