fix(tools): preserve PATH for argument-vector commands
This commit is contained in:
1 parent
99ba062a97
commit
54d85059a5
2 files changed
+29
-2
No files matched your search
@@ -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)
|
||||
|
||||
@@ -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
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
Reference in new issue
Block a user