Skip to content

Commit 8f4e6df

Browse files
committed
test: Mock subprocess execution in test_call_tool_with_stderr for stable CI
1 parent cfe2d77 commit 8f4e6df

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

tests/test_server.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,22 @@ async def test_disallowed_command(monkeypatch):
300300
@pytest.mark.asyncio
301301
async def test_call_tool_with_stderr(monkeypatch):
302302
"""Test command execution with stderr output"""
303+
304+
async def mock_create_subprocess_shell(
305+
cmd, stdin=None, stdout=None, stderr=None, env=None, cwd=None
306+
):
307+
# Return mock process with stderr for ls command
308+
if "ls" in cmd:
309+
return MockProcess(
310+
stdout=b"",
311+
stderr=b"ls: cannot access '/nonexistent/directory': No such file or directory\n",
312+
returncode=2,
313+
)
314+
return MockProcess(stdout=b"", stderr=b"", returncode=0)
315+
316+
monkeypatch.setattr(
317+
asyncio, "create_subprocess_shell", mock_create_subprocess_shell
318+
)
303319
monkeypatch.setenv("ALLOW_COMMANDS", "ls")
304320
result = await call_tool(
305321
"shell_execute",

0 commit comments

Comments
 (0)