fix(tools): preserve PATH for argument-vector commands

This commit is contained in:
chengyongru authored and chengyongru committed 2026-09-30 13:09:30 +08:00
1 parent 99ba062a97
commit 54d85059a5
2 files changed
+29 -2

No files matched your search

+5 -2
View File
@@ -475,8 +475,11 @@ class ExecTool(Tool):
effective_timeout = self._resolve_timeout(timeout) effective_timeout = self._resolve_timeout(timeout)
env = self._build_env() env = self._build_env()
if self.path_prepend or self.path_append: if isinstance(command, list):
if _IS_WINDOWS or 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", "")) env["PATH"] = self._compose_path(env.get("PATH", ""))
else: else:
command = self._wrap_path_export(command, env) command = self._wrap_path_export(command, env)
+24
View File
@@ -6,6 +6,7 @@ platform-specific binaries (all subprocess calls are mocked).
""" """
import asyncio import asyncio
import os
import shutil import shutil
import sys import sys
from unittest.mock import AsyncMock, MagicMock, patch from unittest.mock import AsyncMock, MagicMock, patch
@@ -103,6 +104,29 @@ class TestBuildEnvWindows:
assert env["SYSTEMROOT"] == r"D:\Windows" 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 # _spawn
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------