From 97f18c3339b4257d9f544e1c840c4c61d8e77444 Mon Sep 17 00:00:00 2001 From: Varun Nuthalapati Date: Thu, 28 May 2026 23:20:49 -0700 Subject: [PATCH] fix: skip bash syntax validation on Windows _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. --- src/webwright/models/base.py | 3 +++ tests/unit/test_bash_validation.py | 39 ++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 tests/unit/test_bash_validation.py diff --git a/src/webwright/models/base.py b/src/webwright/models/base.py index 7728bb8..03d225d 100644 --- a/src/webwright/models/base.py +++ b/src/webwright/models/base.py @@ -6,6 +6,7 @@ import mimetypes import os import subprocess +import sys from pathlib import Path from typing import Annotated, Any @@ -121,6 +122,8 @@ def parse_json_output(raw: str, *, action_field: str = "bash_command") -> dict[s def _validate_bash_command(command: str) -> None: + if sys.platform == "win32": + return result = subprocess.run( ["/bin/bash", "-n"], input=command, diff --git a/tests/unit/test_bash_validation.py b/tests/unit/test_bash_validation.py new file mode 100644 index 0000000..4051728 --- /dev/null +++ b/tests/unit/test_bash_validation.py @@ -0,0 +1,39 @@ +import sys +from unittest.mock import MagicMock, patch + +import pytest + +from webwright.models.base import _validate_bash_command + + +def _make_proc(returncode: int, stderr: str = "") -> MagicMock: + proc = MagicMock() + proc.returncode = returncode + proc.stderr = stderr + proc.stdout = "" + return proc + + +def test_valid_command_passes_on_posix(monkeypatch) -> None: + monkeypatch.setattr(sys, "platform", "linux") + with patch("subprocess.run", return_value=_make_proc(0)): + _validate_bash_command("echo hello") + + +def test_invalid_syntax_raises_on_posix(monkeypatch) -> None: + monkeypatch.setattr(sys, "platform", "linux") + with patch("subprocess.run", return_value=_make_proc(1, "syntax error near unexpected token")): + with pytest.raises(ValueError, match="Invalid bash_command syntax"): + _validate_bash_command("if then fi done ;;;") + + +def test_validation_skipped_on_windows(monkeypatch) -> None: + monkeypatch.setattr(sys, "platform", "win32") + _validate_bash_command("if then fi done ;;;") + + +def test_validation_skipped_on_windows_does_not_call_subprocess(monkeypatch) -> None: + monkeypatch.setattr(sys, "platform", "win32") + with patch("subprocess.run") as mock_run: + _validate_bash_command("echo hi") + mock_run.assert_not_called()