diff --git a/nanobot/agent/tools/shell.py b/nanobot/agent/tools/shell.py index 59b6bfb8c..98524d662 100644 --- a/nanobot/agent/tools/shell.py +++ b/nanobot/agent/tools/shell.py @@ -475,8 +475,11 @@ class ExecTool(Tool): effective_timeout = self._resolve_timeout(timeout) env = self._build_env() - if self.path_prepend or self.path_append: - if _IS_WINDOWS or isinstance(command, list): + if isinstance(command, list): + parent_path = os.environ.get("PATH", env.get("PATH", "")) + env["PATH"] = self._compose_path(parent_path) + elif self.path_prepend or self.path_append: + if _IS_WINDOWS: env["PATH"] = self._compose_path(env.get("PATH", "")) else: command = self._wrap_path_export(command, env) diff --git a/tests/tools/test_exec_platform.py b/tests/tools/test_exec_platform.py index 06dad564c..1396c645f 100644 --- a/tests/tools/test_exec_platform.py +++ b/tests/tools/test_exec_platform.py @@ -6,6 +6,7 @@ platform-specific binaries (all subprocess calls are mocked). """ import asyncio +import os import shutil import sys from unittest.mock import AsyncMock, MagicMock, patch @@ -103,6 +104,29 @@ class TestBuildEnvWindows: assert env["SYSTEMROOT"] == r"D:\Windows" +# --------------------------------------------------------------------------- +# argument-vector PATH +# --------------------------------------------------------------------------- + +class TestArgumentVectorPath: + + def test_uses_parent_path_for_executable_lookup(self): + parent_path = os.pathsep.join(("parent-bin", "system-bin")) + with ( + patch("nanobot.agent.tools.shell._IS_WINDOWS", False), + patch.dict( + "os.environ", + {"PATH": parent_path, "NANOBOT_SECRET_TOKEN": "super-secret-value"}, + clear=True, + ), + ): + prepared = ExecTool()._prepare_command(["rg", "--version"]) + + assert not isinstance(prepared, str) + assert prepared.env["PATH"] == parent_path + assert "NANOBOT_SECRET_TOKEN" not in prepared.env + + # --------------------------------------------------------------------------- # _spawn # ---------------------------------------------------------------------------