31 lines
998 B
Python
31 lines
998 B
Python
"""Tests for exec tool environment isolation."""
|
|||
|
|
|
||
|
|
import pytest
|
||
|
|
|
||
|
|
from nanobot.agent.tools.shell import ExecTool
|
||
|
|
|
||
|
|
|
||
|
|
@pytest.mark.asyncio
|
||
|
|
async def test_exec_does_not_leak_parent_env(monkeypatch):
|
||
|
|
"""Env vars from the parent process must not be visible to commands."""
|
||
|
|
monkeypatch.setenv("NANOBOT_SECRET_TOKEN", "super-secret-value")
|
||
|
|
tool = ExecTool()
|
||
|
|
result = await tool.execute(command="printenv NANOBOT_SECRET_TOKEN")
|
||
|
|
assert "super-secret-value" not in result
|
||
|
|
|
||
|
|
|
||
|
|
@pytest.mark.asyncio
|
||
|
|
async def test_exec_has_working_path():
|
||
|
|
"""Basic commands should be available via the login shell's PATH."""
|
||
|
|
tool = ExecTool()
|
||
|
|
result = await tool.execute(command="echo hello")
|
||
|
|
assert "hello" in result
|
||
|
|
|
||
|
|
|
||
|
|
@pytest.mark.asyncio
|
||
|
|
async def test_exec_path_append():
|
||
|
|
"""The pathAppend config should be available in the command's PATH."""
|
||
|
|
tool = ExecTool(path_append="/opt/custom/bin")
|
||
|
|
result = await tool.execute(command="echo $PATH")
|
||
|
|
assert "/opt/custom/bin" in result
|