test(agent): use python3 in ExecTool workspace scope tests (#5064)
* test(agent): use python3 in ExecTool workspace scope tests (fixes #5062) * test(agent): use python on Windows and python3 on POSIX in ExecTool workspace scope tests (fixes #5062) * test(agent): share Python command fixture --------- Co-authored-by: chengyongru <chengyongru.ai@gmail.com>
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from types import SimpleNamespace
|
from types import SimpleNamespace
|
||||||
from unittest.mock import AsyncMock, MagicMock, patch
|
from unittest.mock import AsyncMock, MagicMock, patch
|
||||||
@@ -13,6 +14,12 @@ from nanobot.bus.queue import MessageBus
|
|||||||
from nanobot.providers.base import LLMProvider
|
from nanobot.providers.base import LLMProvider
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def cmd_python() -> str:
|
||||||
|
"""Return the Python command name available to ExecTool tests."""
|
||||||
|
return "python" if os.name == "nt" else "python3"
|
||||||
|
|
||||||
|
|
||||||
def make_provider(
|
def make_provider(
|
||||||
default_model: str = "test-model",
|
default_model: str = "test-model",
|
||||||
*,
|
*,
|
||||||
|
|||||||
@@ -257,7 +257,10 @@ async def test_filesystem_write_tool_full_scope_allows_outside_project(tmp_path:
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_exec_tool_uses_scope_project_as_default_cwd(tmp_path: Path) -> None:
|
async def test_exec_tool_uses_scope_project_as_default_cwd(
|
||||||
|
tmp_path: Path,
|
||||||
|
cmd_python: str,
|
||||||
|
) -> None:
|
||||||
project = tmp_path / "project"
|
project = tmp_path / "project"
|
||||||
project.mkdir()
|
project.mkdir()
|
||||||
tool = ExecTool(working_dir=str(tmp_path), restrict_to_workspace=False, timeout=5)
|
tool = ExecTool(working_dir=str(tmp_path), restrict_to_workspace=False, timeout=5)
|
||||||
@@ -270,7 +273,7 @@ async def test_exec_tool_uses_scope_project_as_default_cwd(tmp_path: Path) -> No
|
|||||||
try:
|
try:
|
||||||
result = await tool.execute(
|
result = await tool.execute(
|
||||||
command=(
|
command=(
|
||||||
'python -c "from pathlib import Path; '
|
f'{cmd_python} -c "from pathlib import Path; '
|
||||||
"Path('scoped-marker.txt').write_text('ok')\""
|
"Path('scoped-marker.txt').write_text('ok')\""
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@@ -282,7 +285,10 @@ async def test_exec_tool_uses_scope_project_as_default_cwd(tmp_path: Path) -> No
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_exec_full_scope_allows_explicit_cwd_outside_project(tmp_path: Path) -> None:
|
async def test_exec_full_scope_allows_explicit_cwd_outside_project(
|
||||||
|
tmp_path: Path,
|
||||||
|
cmd_python: str,
|
||||||
|
) -> None:
|
||||||
project = tmp_path / "project"
|
project = tmp_path / "project"
|
||||||
outside = tmp_path / "outside"
|
outside = tmp_path / "outside"
|
||||||
project.mkdir()
|
project.mkdir()
|
||||||
@@ -297,7 +303,7 @@ async def test_exec_full_scope_allows_explicit_cwd_outside_project(tmp_path: Pat
|
|||||||
try:
|
try:
|
||||||
result = await tool.execute(
|
result = await tool.execute(
|
||||||
command=(
|
command=(
|
||||||
'python -c "from pathlib import Path; '
|
f'{cmd_python} -c "from pathlib import Path; '
|
||||||
"Path('outside-marker.txt').write_text('ok')\""
|
"Path('outside-marker.txt').write_text('ok')\""
|
||||||
),
|
),
|
||||||
working_dir=str(outside),
|
working_dir=str(outside),
|
||||||
|
|||||||
Reference in New Issue
Block a user