Skip to content

fix: skip bash syntax validation on Windows - #30

Open
nuthalapativarun wants to merge 1 commit into
microsoft:mainfrom
nuthalapativarun:fix/windows-bash-validation
Open

fix: skip bash syntax validation on Windows#30
nuthalapativarun wants to merge 1 commit into
microsoft:mainfrom
nuthalapativarun:fix/windows-bash-validation

Conversation

@nuthalapativarun

Copy link
Copy Markdown

Problem

_validate_bash_command in base.py calls /bin/bash -n to syntax-check each agent action. On Windows, /bin/bash does not exist, so subprocess.run raises FileNotFoundError. This propagates as an unhandled exception on every agent step, preventing Webwright from running on Windows at all.

Fix

Guard the subprocess.run call with sys.platform == "win32" and return early. On Windows the command is passed through without syntax validation; on POSIX the existing behavior is preserved exactly.

Changes

  • src/webwright/models/base.py — added import sys; added a if sys.platform == "win32": return guard at the top of _validate_bash_command
  • tests/unit/test_bash_validation.py — four new tests: valid command on POSIX, invalid syntax raises ValueError on POSIX, validation is skipped on Windows, and subprocess.run is never called on Windows

Not affected

  • POSIX behavior — unchanged; /bin/bash -n is still called and errors still raise ValueError
  • Any other function in base.py — not touched

_validate_bash_command calls /bin/bash -n, which is absent on Windows.
This causes FileNotFoundError (or exit code 1) on every agent step,
raising FormatError for every valid command. Guard the subprocess call
with a sys.platform check and return early on win32.
@Ganesh-Biogen

Copy link
Copy Markdown

Confirming this PR is needed, and reporting a second Windows blocker that sits immediately behind it.

Environment: Windows Server 2016, Python 3.13, Git Bash, environment.shell set to C:\Program Files\Git\bin\bash.exe.

With this PR applied, _validate_bash_command no longer raises FileNotFoundError — but every command then fails at execution with returncode 127:

/usr/bin/bash: Files\Git\bin\bash.exe: No such file or directory
The agent loops on this until it hits step_limit.

Cause. environments/local_workspace.py runs commands as:

subprocess.run(command, shell=True, executable=self.config.shell, ...)
On Windows, subprocess with shell=True builds the command line as /c "". /c is cmd.exe syntax; bash expects -c. Minimal repro, using an 8.3 short path to rule out the space in Program Files:

python -c "import subprocess;print(subprocess.run('ls', shell=True,
executable=r'C:\PROGRA~1\Git\bin\bash.exe', capture_output=True, text=True))"

CompletedProcess(args='ls', returncode=126, stdout='', stderr='/c: /c: Is a directory\n')
bash resolves /c as the MSYS path to the C:\ drive root. So executable= cannot drive bash on Windows at all, independently of the syntax check this PR fixes.

Suggested fix — invoke the shell directly instead of via shell=True:

result = subprocess.run(
[self.config.shell, "-c", command],
text=True,
...
This does not change POSIX behaviour. CPython's POSIX _execute_child already does exactly this:

if shell:
args = [unix_shell, "-c"] + args
if executable:
args[0] = executable
It also removes the need for short paths, since list2cmdline quotes arguments containing spaces.

With this PR plus that change, the harness runs end-to-end on Windows and completes tasks normally.

Happy to open a separate PR for the local_workspace.py change if that's preferred.

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