mirror of
https://github.com/HKUDS/nanobot.git
synced 2026-05-20 16:42:25 +00:00
fix(exec): detach stdin for shell commands
This commit is contained in:
parent
38a5f09f02
commit
3eebe08dba
@ -266,6 +266,7 @@ class ExecTool(Tool):
|
|||||||
# the raw command string to COMSPEC without re-quoting.
|
# the raw command string to COMSPEC without re-quoting.
|
||||||
return await asyncio.create_subprocess_shell(
|
return await asyncio.create_subprocess_shell(
|
||||||
command,
|
command,
|
||||||
|
stdin=asyncio.subprocess.DEVNULL,
|
||||||
stdout=asyncio.subprocess.PIPE,
|
stdout=asyncio.subprocess.PIPE,
|
||||||
stderr=asyncio.subprocess.PIPE,
|
stderr=asyncio.subprocess.PIPE,
|
||||||
cwd=cwd,
|
cwd=cwd,
|
||||||
@ -274,6 +275,7 @@ class ExecTool(Tool):
|
|||||||
bash = shutil.which("bash") or "/bin/bash"
|
bash = shutil.which("bash") or "/bin/bash"
|
||||||
return await asyncio.create_subprocess_exec(
|
return await asyncio.create_subprocess_exec(
|
||||||
bash, "-l", "-c", command,
|
bash, "-l", "-c", command,
|
||||||
|
stdin=asyncio.subprocess.DEVNULL,
|
||||||
stdout=asyncio.subprocess.PIPE,
|
stdout=asyncio.subprocess.PIPE,
|
||||||
stderr=asyncio.subprocess.PIPE,
|
stderr=asyncio.subprocess.PIPE,
|
||||||
cwd=cwd,
|
cwd=cwd,
|
||||||
|
|||||||
@ -5,6 +5,7 @@ strategy, and sandbox behaviour per platform — without actually running
|
|||||||
platform-specific binaries (all subprocess calls are mocked).
|
platform-specific binaries (all subprocess calls are mocked).
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import asyncio
|
||||||
import sys
|
import sys
|
||||||
from unittest.mock import AsyncMock, patch
|
from unittest.mock import AsyncMock, patch
|
||||||
|
|
||||||
@ -108,6 +109,9 @@ class TestSpawnUnix:
|
|||||||
assert "-c" in args
|
assert "-c" in args
|
||||||
assert "echo hi" in args
|
assert "echo hi" in args
|
||||||
|
|
||||||
|
kwargs = mock_exec.call_args[1]
|
||||||
|
assert kwargs["stdin"] == asyncio.subprocess.DEVNULL
|
||||||
|
|
||||||
|
|
||||||
class TestSpawnWindows:
|
class TestSpawnWindows:
|
||||||
|
|
||||||
@ -124,6 +128,9 @@ class TestSpawnWindows:
|
|||||||
args = mock_shell.call_args[0]
|
args = mock_shell.call_args[0]
|
||||||
assert "dir" in args
|
assert "dir" in args
|
||||||
|
|
||||||
|
kwargs = mock_shell.call_args[1]
|
||||||
|
assert kwargs["stdin"] == asyncio.subprocess.DEVNULL
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_passes_cwd_and_env(self):
|
async def test_passes_cwd_and_env(self):
|
||||||
env = {"PATH": "/usr/bin"}
|
env = {"PATH": "/usr/bin"}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user