Files
AI-VideoAssistant-Engine-V2/tests/test_tool_executor.py
2026-02-17 10:39:23 +08:00

58 lines
1.6 KiB
Python

import pytest
from core.tool_executor import execute_server_tool
@pytest.mark.asyncio
async def test_code_interpreter_simple_expression():
result = await execute_server_tool(
{
"id": "call_ci_ok",
"function": {
"name": "code_interpreter",
"arguments": '{"code":"sum([1, 2, 3]) + 4"}',
},
}
)
assert result["status"]["code"] == 200
assert result["output"]["result"] == 10
@pytest.mark.asyncio
async def test_code_interpreter_blocks_import_and_io():
result = await execute_server_tool(
{
"id": "call_ci_bad",
"function": {
"name": "code_interpreter",
"arguments": '{"code":"__import__(\\"os\\").system(\\"ls\\")"}',
},
}
)
assert result["status"]["code"] == 422
assert result["status"]["message"] == "invalid_code"
@pytest.mark.asyncio
async def test_current_time_uses_local_system_clock(monkeypatch):
async def _should_not_be_called(_tool_id):
raise AssertionError("fetch_tool_resource should not be called for current_time")
monkeypatch.setattr("core.tool_executor.fetch_tool_resource", _should_not_be_called)
result = await execute_server_tool(
{
"id": "call_time_ok",
"function": {
"name": "current_time",
"arguments": "{}",
},
}
)
assert result["status"]["code"] == 200
assert result["status"]["message"] == "ok"
assert "local_time" in result["output"]
assert "iso" in result["output"]
assert "timestamp" in result["output"]