test: cover exec login default public path
maintainer edit: add a regression test for the public ExecTool.execute path so omitted login stays non-login by default, and update the Unix environment docstring to match the new explicit login behavior.
This commit is contained in:
@@ -541,8 +541,9 @@ class ExecTool(Tool):
|
|||||||
def _build_env(self) -> dict[str, str]:
|
def _build_env(self) -> dict[str, str]:
|
||||||
"""Build a minimal environment for subprocess execution.
|
"""Build a minimal environment for subprocess execution.
|
||||||
|
|
||||||
On Unix, only HOME/LANG/TERM are passed; ``bash -l`` sources the
|
On Unix, only HOME/LANG/TERM are passed by default. If callers request
|
||||||
user's profile which sets PATH and other essentials.
|
``login=True``, bash/zsh may source the user's profile and add PATH or
|
||||||
|
other variables.
|
||||||
|
|
||||||
On Windows, ``cmd.exe`` has no login-profile mechanism, so a curated
|
On Windows, ``cmd.exe`` has no login-profile mechanism, so a curated
|
||||||
set of system variables (including PATH) is forwarded. API keys and
|
set of system variables (including PATH) is forwarded. API keys and
|
||||||
|
|||||||
@@ -400,6 +400,29 @@ class TestExecuteEndToEnd:
|
|||||||
assert "hello world" in result
|
assert "hello world" in result
|
||||||
assert "Exit code: 0" in result
|
assert "Exit code: 0" in result
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_execute_defaults_to_non_login_shell(self):
|
||||||
|
"""The public execute path must not silently request a login shell."""
|
||||||
|
mock_proc = AsyncMock()
|
||||||
|
mock_proc.communicate.return_value = (b"ok\n", b"")
|
||||||
|
mock_proc.returncode = 0
|
||||||
|
captured_login = []
|
||||||
|
|
||||||
|
async def capture_spawn(cmd, cwd, env, shell_program=None, login=None, *, stdin=None):
|
||||||
|
captured_login.append(login)
|
||||||
|
return mock_proc
|
||||||
|
|
||||||
|
with (
|
||||||
|
patch("nanobot.agent.tools.shell._IS_WINDOWS", False),
|
||||||
|
patch.object(ExecTool, "_spawn", side_effect=capture_spawn),
|
||||||
|
patch.object(ExecTool, "_guard_command", return_value=None),
|
||||||
|
):
|
||||||
|
tool = ExecTool()
|
||||||
|
await tool.execute(command="echo ok")
|
||||||
|
await tool.execute(command="echo ok", login=True)
|
||||||
|
|
||||||
|
assert captured_login == [False, True]
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# _extract_absolute_paths - UNC path support
|
# _extract_absolute_paths - UNC path support
|
||||||
|
|||||||
Reference in New Issue
Block a user