Refine WebUI commands and data skills
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
from unittest import TestCase
|
||||
|
||||
from src.agent_tools import build_tool_context, default_tool_registry, execute_tool
|
||||
from src.agent_types import AgentPermissions, AgentRuntimeConfig
|
||||
|
||||
|
||||
class PythonExecToolTests(TestCase):
|
||||
def test_python_exec_runs_inline_code_with_shell_permission(self) -> None:
|
||||
with tempfile.TemporaryDirectory() as tmp_dir:
|
||||
config = AgentRuntimeConfig(
|
||||
cwd=Path(tmp_dir),
|
||||
permissions=AgentPermissions(allow_shell_commands=True),
|
||||
)
|
||||
context = build_tool_context(config)
|
||||
result = execute_tool(
|
||||
default_tool_registry(),
|
||||
'python_exec',
|
||||
{'code': 'print("hello from python")'},
|
||||
context,
|
||||
)
|
||||
|
||||
self.assertTrue(result.ok)
|
||||
self.assertIn('exit_code=0', result.content)
|
||||
self.assertIn('hello from python', result.content)
|
||||
self.assertEqual(result.metadata.get('action'), 'python_exec')
|
||||
self.assertEqual(result.metadata.get('mode'), 'code')
|
||||
|
||||
def test_python_exec_is_blocked_without_shell_permission(self) -> None:
|
||||
with tempfile.TemporaryDirectory() as tmp_dir:
|
||||
config = AgentRuntimeConfig(cwd=Path(tmp_dir))
|
||||
context = build_tool_context(config)
|
||||
result = execute_tool(
|
||||
default_tool_registry(),
|
||||
'python_exec',
|
||||
{'code': 'print("blocked")'},
|
||||
context,
|
||||
)
|
||||
|
||||
self.assertFalse(result.ok)
|
||||
self.assertIn('--allow-shell', result.content)
|
||||
self.assertEqual(result.metadata.get('error_kind'), 'permission_denied')
|
||||
|
||||
def test_python_exec_runs_workspace_script_with_args(self) -> None:
|
||||
with tempfile.TemporaryDirectory() as tmp_dir:
|
||||
root = Path(tmp_dir)
|
||||
script = root / 'tool_script.py'
|
||||
script.write_text(
|
||||
'import sys\nprint("|".join(sys.argv[1:]))\n',
|
||||
encoding='utf-8',
|
||||
)
|
||||
config = AgentRuntimeConfig(
|
||||
cwd=root,
|
||||
permissions=AgentPermissions(allow_shell_commands=True),
|
||||
)
|
||||
context = build_tool_context(config)
|
||||
result = execute_tool(
|
||||
default_tool_registry(),
|
||||
'python_exec',
|
||||
{'script_path': 'tool_script.py', 'args': ['a', 'b']},
|
||||
context,
|
||||
)
|
||||
|
||||
self.assertTrue(result.ok)
|
||||
self.assertIn('a|b', result.content)
|
||||
self.assertEqual(result.metadata.get('mode'), 'script')
|
||||
|
||||
Reference in New Issue
Block a user