fix(cron): use path.as_posix() for .sh scripts on Windows - #44350
fix(cron): use path.as_posix() for .sh scripts on Windows#44350franchaise wants to merge 1 commit into
Conversation
On Windows, passing a pathlib Path to bash via str(path) produces backslash separators (C:\Users\...). Bash interprets these as escape sequences, mangling the path and causing exit code 127. Switch to path.as_posix() so .sh cron scripts always receive forward-slash paths regardless of platform. Fixes NousResearch#43073
teknium1
left a comment
There was a problem hiding this comment.
Thanks for the focused Windows cron fix. The production hunk addresses a defect still present on current main: cron/scheduler.py:2092 passes str(path) to bash for .sh/.bash scripts.
Problems
- The proposed regression assertion cannot fail on a POSIX host.
hermes_envcreates a host-nativePath(tests/cron/test_cron_no_agent.py:21), so its argument already has/before this change; the added assertions at lines 366-367 of the PR diff therefore pass with the oldstr(path)implementation. - The linked #46332 reports a separate Windows failure: current
cron/scheduler.py:2083still usesshutil.which("bash"), which can select the WSL launcher ahead of Git Bash. This PR fixes path formatting but not that resolver case.
Suggested changes
- Make the path-format regression meaningful on native Windows, using an actual Windows
Pathand a captured subprocess argv; skip outsidewin32unless extracting a testable cross-platform helper. - Keep Git-Bash-versus-WSL selection as a focused follow-up for #46332.
Automated hermes-sweeper review.
| assert ok is True | ||
| assert output == "ok" | ||
|
|
||
| # Second argument is the script path. |
There was a problem hiding this comment.
On a POSIX runner, script_path is already a Path with / separators, so this assertion also passes before the production change. Please make this a native-Windows regression using a real Windows path (or extract and test a platform-independent conversion helper).
|
Reconciliation (2026-08-03): this PR's change ( |
On Windows, cron
.shand.bashscripts were passed to bash usingstr(path), which produced backslash-separated paths. Bash (especially Git Bash / WSL) interprets backslashes as escape characters, so the script path could be mangled and fail to execute.This change passes
path.as_posix()for shell scripts so the argument is a forward-slash path regardless of host OS.cron/scheduler.py: usepath.as_posix()when invoking.sh/.bashscriptstests/cron/test_cron_no_agent.py: add regression testtest_run_job_script_sh_uses_posix_pathsCloses #43073