diff --git a/nanobot/agent/tools/shell.py b/nanobot/agent/tools/shell.py index cfdbcbdb6..89bc4a81f 100644 --- a/nanobot/agent/tools/shell.py +++ b/nanobot/agent/tools/shell.py @@ -611,7 +611,7 @@ class ExecTool(Tool): quote = stripped[0] end = stripped.find(quote, 1) - if end == -1 or end + 1 >= len(stripped) or not stripped[end + 1].isspace(): + if end == -1 or (end + 1 < len(stripped) and not stripped[end + 1].isspace()): return command executable = stripped[1:end] diff --git a/tests/tools/test_exec_platform.py b/tests/tools/test_exec_platform.py index 44a3f8b59..06dad564c 100644 --- a/tests/tools/test_exec_platform.py +++ b/tests/tools/test_exec_platform.py @@ -302,6 +302,21 @@ class TestSpawnWindows: powershell_command = mock_exec.call_args[0][-1] assert f"\n& {command}\n" in powershell_command + @pytest.mark.asyncio + async def test_powershell_invokes_quoted_windows_executable_without_arguments(self): + """A quoted executable path is still a command when it has no arguments.""" + env = {"PATH": ""} + command = r'"D:\Program Files\Git\cmd\git.exe"' + with ( + patch("nanobot.agent.tools.shell._IS_WINDOWS", True), + patch("asyncio.create_subprocess_exec", new_callable=AsyncMock) as mock_exec, + ): + mock_exec.return_value = AsyncMock() + await ExecTool._spawn(command, r"C:\work", env) + + powershell_command = mock_exec.call_args[0][-1] + assert f"\n& {command}\n" in powershell_command + @pytest.mark.asyncio async def test_prefers_pwsh_when_available(self): env = {"PATH": ""}