Skip to content

fix(task): append forwarded args to inline bash -c tasks on windows#10321

Merged
jdx merged 1 commit into
jdx:mainfrom
JamBalaya56562:fix/windows-bash-c-arg-shift
Jun 12, 2026
Merged

fix(task): append forwarded args to inline bash -c tasks on windows#10321
jdx merged 1 commit into
jdx:mainfrom
JamBalaya56562:fix/windows-bash-c-arg-shift

Conversation

@JamBalaya56562

@JamBalaya56562 JamBalaya56562 commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Problem

On Windows, an inline task with an explicit POSIX shell (e.g. shell = "bash -c") passed forwarded args as separate argv to bash -c <script> arg1 …. bash then assigned the user's first forwarded arg to $0, so it was silently swallowed:

[tasks.args_repro]
shell = "bash -c"
run = 'echo "using shell $0"'

mise run args_repro -- myarg printed using shell myarg instead of using shell bash myarg.

Fix

Inline TOML scripts are documented to append forwarded args to the command string (only file/shebang tasks get real positional params), which the Unix branch already did. For Windows POSIX shells, fall through to the same shared shell_words::join append after the cmd.exe verbatim early-return, so $0 stays bash and the args reach the command — matching Unix behavior.

Non-POSIX, non-cmd shells (e.g. pwsh -Command) keep passing args as separate argv, since shell_words uses POSIX quoting that PowerShell would not parse back into the original argument.

Tests

  • e2e/tasks/test_task_shell — Unix assertion that mise run shell -- myarg yields using shell bash myarg.
  • e2e-win/task.Tests.ps1 — Windows test reproducing the arg-swallow bug (skips when Git Bash / MSYS bash.exe isn't on PATH).

Refs #9355.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Fixed argument forwarding for shell tasks so extra arguments are preserved and do not disrupt shell parameter handling across platforms.
  • Tests

    • Added a Windows end-to-end test covering argument forwarding to bash-style tasks.
    • Updated existing shell task test with additional assertions for forwarded arguments.

@coderabbitai

coderabbitai Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 9eb0a2b5-769b-4d28-a51c-0df7ac6304ed

📥 Commits

Reviewing files that changed from the base of the PR and between 86e3e72 and 31cc5ea.

📒 Files selected for processing (3)
  • e2e-win/task.Tests.ps1
  • e2e/tasks/test_task_shell
  • src/task/task_executor.rs
🚧 Files skipped from review as they are similar to previous changes (2)
  • e2e/tasks/test_task_shell
  • src/task/task_executor.rs

📝 Walkthrough

Walkthrough

This PR fixes how forwarded CLI arguments are passed to bash subshell tasks. The task executor now distinguishes POSIX shells (e.g. bash -c) from non-POSIX shells (e.g. pwsh -Command), forwarding arguments differently for each: non-POSIX shells receive script and args as separate argv elements, while POSIX shells append args into the command string. New Windows and updated Unix e2e tests verify the behavior.

Changes

Task shell argument forwarding

Layer / File(s) Summary
POSIX vs non-POSIX shell argument forwarding
src/task/task_executor.rs
TaskExecutor::get_cmd_program_and_args now branches on shell type: non-POSIX shells pass script and forwarded args as separate argv elements; POSIX shells append forwarded args into the inline -c command string using shell_words::join. Removes prior Unix-only inline command construction.
e2e test coverage for shell argument forwarding
e2e-win/task.Tests.ps1, e2e/tasks/test_task_shell
Windows e2e test verifies bash task with forwarded args preserves $0 behavior and correctly appends the arg. Unix e2e test updated to assert forwarded args are appended without shifting $0 in the bash -c context.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • jdx/mise#10301: Adjusts src/task/task_executor.rs Windows shell handling with cmd_verbatim for cmd.exe /c|/k quoting preservation alongside this PR's POSIX vs non-POSIX shell distinction.

Poem

A rabbit hops through POSIX shells with glee, 🐰
Arguments nudged where they ought to be,
On Windows and Unix the pipeline hums,
$0 stays steady while the extra arg comes,
A tiny hop fixes how cmds agree.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title directly and accurately describes the main fix: appending forwarded arguments to inline bash -c tasks on Windows, which matches the core change in task_executor.rs and the test additions.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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

@greptile-apps

greptile-apps Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a Windows-only argument-forwarding bug where inline TOML tasks using a POSIX shell (shell = "bash -c") would pass forwarded args as separate argv to bash -c, causing the first arg to silently become $0 (swallowing it). The fix makes Windows POSIX shells fall through to the same shell_words::join-append path that Unix already used, while non-POSIX non-cmd shells (e.g. pwsh -Command) retain the separate-argv path.

  • src/task/task_executor.rs: The #[cfg(windows)] block now returns early only for cmd.exe and non-POSIX shells; POSIX shells fall through to the shared append path, aligning Windows and Unix behavior for inline scripts.
  • e2e-win/task.Tests.ps1 / e2e/tasks/test_task_shell: New tests on both platforms verify mise run shell -- myarg yields using shell bash myarg, proving $0 stays the shell name and the forwarded arg is not swallowed.

Confidence Score: 5/5

The change is a narrow, well-tested fix to a Windows-only arg-forwarding path with no impact on Unix behavior.

The logic in task_executor.rs is correct and both platforms have dedicated test coverage.

e2e-win/task.Tests.ps1 follows the same CWD-vs-TestDrive file-writing pattern as other tests; verify CI runner CWD matches TestDrive.

Important Files Changed

Filename Overview
src/task/task_executor.rs Refactors get_cmd_program_and_args on Windows: POSIX shells now fall through to the shared shell_words::join append path instead of pushing args as separate argv, eliminating the $0-swallow bug; non-POSIX non-cmd shells keep the old separate-argv path.
e2e/tasks/test_task_shell Adds a Unix assertion that mise run shell -- myarg outputs using shell bash myarg, confirming forwarded args are appended to the inline command string rather than passed as separate positional parameters.
e2e-win/task.Tests.ps1 New Pester test reproduces the Windows $0-swallow bug with bash -c; skips gracefully when bash.exe is not on PATH. The config file is written to the relative CWD path but the cleanup targets $TestDrive\mise.args_repro.toml, following the same pre-existing pattern as other tests in this file.

Reviews (2): Last reviewed commit: "fix(task): append forwarded args to inli..." | Re-trigger Greptile

Comment thread e2e-win/task.Tests.ps1
On Windows, an inline task with an explicit POSIX shell (e.g.
`shell = "bash -c"`) passed forwarded args as separate argv to
`bash -c <script> arg1 ...`, so bash assigned the user's first arg to `$0`
and it was silently swallowed.

Inline TOML scripts are documented to append forwarded args to the command
string (only file/shebang tasks get real positional params), which the Unix
branch already did. For Windows POSIX shells, fall through to the same shared
`shell_words::join` append after the cmd.exe verbatim early-return, so `$0`
stays "bash" and the args reach the command, matching Unix.

Non-POSIX non-cmd shells (e.g. `pwsh -Command`) keep passing args as separate
argv, since `shell_words` uses POSIX quoting that PowerShell would not parse
back into the original argument.

Adds a Unix e2e assertion (`e2e/tasks/test_task_shell`) and a Windows e2e test
(`e2e-win/task.Tests.ps1`).

Refs jdx#9355.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@JamBalaya56562 JamBalaya56562 force-pushed the fix/windows-bash-c-arg-shift branch from 86e3e72 to 31cc5ea Compare June 12, 2026 00:17
@jdx jdx merged commit 234284e into jdx:main Jun 12, 2026
33 checks passed
@JamBalaya56562 JamBalaya56562 deleted the fix/windows-bash-c-arg-shift branch June 12, 2026 02:06
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.

2 participants