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:
chengyongru
2026-06-27 11:04:31 +08:00
committed by Xubin Ren
parent 4c1f127549
commit 8656549129
2 changed files with 26 additions and 2 deletions
+23
View File
@@ -400,6 +400,29 @@ class TestExecuteEndToEnd:
assert "hello world" 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