Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions agentrun/agent_runtime/api/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@
CreateAgentRuntimeEndpointRequest,
CreateAgentRuntimeInput,
CreateAgentRuntimeRequest,
DeleteAgentRuntimeEndpointRequest,
DeleteAgentRuntimeRequest,
GetAgentRuntimeEndpointRequest,
GetAgentRuntimeRequest,
ListAgentRuntimeEndpointsOutput,
ListAgentRuntimeEndpointsRequest,
Expand Down Expand Up @@ -196,7 +193,6 @@ def delete_agent_runtime(
client = self._get_client(config)
response = client.delete_agent_runtime_with_options(
agent_id,
DeleteAgentRuntimeRequest(),
headers=headers or {},
runtime=RuntimeOptions(),
)
Expand Down Expand Up @@ -252,7 +248,6 @@ async def delete_agent_runtime_async(
client = self._get_client(config)
response = await client.delete_agent_runtime_with_options_async(
agent_id,
DeleteAgentRuntimeRequest(),
headers=headers or {},
runtime=RuntimeOptions(),
)
Expand Down Expand Up @@ -783,7 +778,6 @@ def delete_agent_runtime_endpoint(
response = client.delete_agent_runtime_endpoint_with_options(
agent_id,
endpoint_id,
DeleteAgentRuntimeEndpointRequest(),
headers=headers or {},
runtime=RuntimeOptions(),
)
Expand Down Expand Up @@ -844,7 +838,6 @@ async def delete_agent_runtime_endpoint_async(
await client.delete_agent_runtime_endpoint_with_options_async(
agent_id,
endpoint_id,
DeleteAgentRuntimeEndpointRequest(),
headers=headers or {},
runtime=RuntimeOptions(),
)
Expand Down Expand Up @@ -1035,7 +1028,6 @@ def get_agent_runtime_endpoint(
response = client.get_agent_runtime_endpoint_with_options(
agent_id,
endpoint_id,
GetAgentRuntimeEndpointRequest(),
headers=headers or {},
runtime=RuntimeOptions(),
)
Expand Down Expand Up @@ -1096,7 +1088,6 @@ async def get_agent_runtime_endpoint_async(
await client.get_agent_runtime_endpoint_with_options_async(
agent_id,
endpoint_id,
GetAgentRuntimeEndpointRequest(),
headers=headers or {},
runtime=RuntimeOptions(),
)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ dependencies = [
"litellm>=1.79.3",
"alibabacloud-devs20230714>=2.4.1",
"pydash>=8.0.5",
"alibabacloud-agentrun20250910>=5.6.1",
"alibabacloud-agentrun20250910>=5.6.3",
"alibabacloud_tea_openapi>=0.4.2",
"alibabacloud_bailian20231229>=2.6.2",
"agentrun-mem0ai>=0.0.10",
Expand Down
201 changes: 201 additions & 0 deletions tests/unittests/agent_runtime/api/test_control.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
"""
测试 AgentRuntimeControlAPI 对底层 SDK client 的调用是否与 SDK 方法签名匹配。
"""

from unittest.mock import create_autospec, MagicMock, patch

from alibabacloud_agentrun20250910.client import Client as AgentRunClient
from alibabacloud_agentrun20250910.models import (
CreateAgentRuntimeEndpointInput,
CreateAgentRuntimeInput,
GetAgentRuntimeRequest,
ListAgentRuntimeEndpointsRequest,
ListAgentRuntimesRequest,
ListAgentRuntimeVersionsRequest,
UpdateAgentRuntimeEndpointInput,
UpdateAgentRuntimeInput,
)
import pytest

from agentrun.agent_runtime.api.control import AgentRuntimeControlAPI
from agentrun.utils.config import Config


@pytest.fixture
def mock_config():
return Config(
access_key_id="test-ak",
access_key_secret="test-sk",
region_id="cn-hangzhou",
control_endpoint="https://agentrun.cn-hangzhou.aliyuncs.com",
)


@pytest.fixture
def mock_response():
response = MagicMock()
response.body.request_id = "test-request-id"
response.body.data = MagicMock()
return response


@pytest.fixture
def api_and_client(mock_config, mock_response):
api = AgentRuntimeControlAPI(config=mock_config)
mock_client = create_autospec(AgentRunClient, instance=True)

for attr in dir(AgentRunClient):
if "with_options" in attr:
getattr(mock_client, attr).return_value = mock_response

with patch.object(api, "_get_client", return_value=mock_client):
yield api, mock_client


class TestAgentRuntimeControlAPISignatures:

def test_create_agent_runtime(self, api_and_client):
api, client = api_and_client
input_data = MagicMock(spec=CreateAgentRuntimeInput)
api.create_agent_runtime(input_data)
client.create_agent_runtime_with_options.assert_called_once()

def test_delete_agent_runtime(self, api_and_client):
api, client = api_and_client
api.delete_agent_runtime("agent-123")
client.delete_agent_runtime_with_options.assert_called_once()

def test_update_agent_runtime(self, api_and_client):
api, client = api_and_client
input_data = MagicMock(spec=UpdateAgentRuntimeInput)
api.update_agent_runtime("agent-123", input_data)
client.update_agent_runtime_with_options.assert_called_once()

def test_get_agent_runtime(self, api_and_client):
api, client = api_and_client
input_data = MagicMock(spec=GetAgentRuntimeRequest)
api.get_agent_runtime("agent-123", input_data)
client.get_agent_runtime_with_options.assert_called_once()

def test_list_agent_runtimes(self, api_and_client):
api, client = api_and_client
input_data = MagicMock(spec=ListAgentRuntimesRequest)
api.list_agent_runtimes(input_data)
client.list_agent_runtimes_with_options.assert_called_once()

def test_create_agent_runtime_endpoint(self, api_and_client):
api, client = api_and_client
input_data = MagicMock(spec=CreateAgentRuntimeEndpointInput)
api.create_agent_runtime_endpoint("agent-123", input_data)
client.create_agent_runtime_endpoint_with_options.assert_called_once()

def test_delete_agent_runtime_endpoint(self, api_and_client):
api, client = api_and_client
api.delete_agent_runtime_endpoint("agent-123", "endpoint-456")
client.delete_agent_runtime_endpoint_with_options.assert_called_once()

def test_update_agent_runtime_endpoint(self, api_and_client):
api, client = api_and_client
input_data = MagicMock(spec=UpdateAgentRuntimeEndpointInput)
api.update_agent_runtime_endpoint(
"agent-123", "endpoint-456", input_data
)
client.update_agent_runtime_endpoint_with_options.assert_called_once()

def test_get_agent_runtime_endpoint(self, api_and_client):
api, client = api_and_client
api.get_agent_runtime_endpoint("agent-123", "endpoint-456")
client.get_agent_runtime_endpoint_with_options.assert_called_once()

def test_list_agent_runtime_endpoints(self, api_and_client):
api, client = api_and_client
input_data = MagicMock(spec=ListAgentRuntimeEndpointsRequest)
api.list_agent_runtime_endpoints("agent-123", input_data)
client.list_agent_runtime_endpoints_with_options.assert_called_once()

def test_list_agent_runtime_versions(self, api_and_client):
api, client = api_and_client
input_data = MagicMock(spec=ListAgentRuntimeVersionsRequest)
api.list_agent_runtime_versions("agent-123", input_data)
client.list_agent_runtime_versions_with_options.assert_called_once()


class TestAgentRuntimeControlAPIAsyncSignatures:

@pytest.mark.asyncio
async def test_create_agent_runtime_async(self, api_and_client):
api, client = api_and_client
input_data = MagicMock(spec=CreateAgentRuntimeInput)
await api.create_agent_runtime_async(input_data)
client.create_agent_runtime_with_options_async.assert_called_once()

@pytest.mark.asyncio
async def test_delete_agent_runtime_async(self, api_and_client):
api, client = api_and_client
await api.delete_agent_runtime_async("agent-123")
client.delete_agent_runtime_with_options_async.assert_called_once()

@pytest.mark.asyncio
async def test_update_agent_runtime_async(self, api_and_client):
api, client = api_and_client
input_data = MagicMock(spec=UpdateAgentRuntimeInput)
await api.update_agent_runtime_async("agent-123", input_data)
client.update_agent_runtime_with_options_async.assert_called_once()

@pytest.mark.asyncio
async def test_get_agent_runtime_async(self, api_and_client):
api, client = api_and_client
input_data = MagicMock(spec=GetAgentRuntimeRequest)
await api.get_agent_runtime_async("agent-123", input_data)
client.get_agent_runtime_with_options_async.assert_called_once()

@pytest.mark.asyncio
async def test_list_agent_runtimes_async(self, api_and_client):
api, client = api_and_client
input_data = MagicMock(spec=ListAgentRuntimesRequest)
await api.list_agent_runtimes_async(input_data)
client.list_agent_runtimes_with_options_async.assert_called_once()

@pytest.mark.asyncio
async def test_create_agent_runtime_endpoint_async(self, api_and_client):
api, client = api_and_client
input_data = MagicMock(spec=CreateAgentRuntimeEndpointInput)
await api.create_agent_runtime_endpoint_async("agent-123", input_data)
client.create_agent_runtime_endpoint_with_options_async.assert_called_once()

@pytest.mark.asyncio
async def test_delete_agent_runtime_endpoint_async(self, api_and_client):
api, client = api_and_client
await api.delete_agent_runtime_endpoint_async(
"agent-123", "endpoint-456"
)
client.delete_agent_runtime_endpoint_with_options_async.assert_called_once()

@pytest.mark.asyncio
async def test_update_agent_runtime_endpoint_async(self, api_and_client):
api, client = api_and_client
input_data = MagicMock(spec=UpdateAgentRuntimeEndpointInput)
await api.update_agent_runtime_endpoint_async(
"agent-123", "endpoint-456", input_data
)
client.update_agent_runtime_endpoint_with_options_async.assert_called_once()

@pytest.mark.asyncio
async def test_get_agent_runtime_endpoint_async(self, api_and_client):
api, client = api_and_client
await api.get_agent_runtime_endpoint_async("agent-123", "endpoint-456")
client.get_agent_runtime_endpoint_with_options_async.assert_called_once()

@pytest.mark.asyncio
async def test_list_agent_runtime_endpoints_async(self, api_and_client):
api, client = api_and_client
input_data = MagicMock(spec=ListAgentRuntimeEndpointsRequest)
await api.list_agent_runtime_endpoints_async("agent-123", input_data)
client.list_agent_runtime_endpoints_with_options_async.assert_called_once()

@pytest.mark.asyncio
async def test_list_agent_runtime_versions_async(self, api_and_client):
api, client = api_and_client
input_data = MagicMock(spec=ListAgentRuntimeVersionsRequest)
await api.list_agent_runtime_versions_async("agent-123", input_data)
client.list_agent_runtime_versions_with_options_async.assert_called_once()
Empty file.
114 changes: 114 additions & 0 deletions tests/unittests/credential/api/test_control.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
"""
测试 CredentialControlAPI 对底层 SDK client 的调用是否与 SDK 方法签名匹配。
"""

from unittest.mock import create_autospec, MagicMock, patch

from alibabacloud_agentrun20250910.client import Client as AgentRunClient
from alibabacloud_agentrun20250910.models import (
CreateCredentialInput,
ListCredentialsRequest,
UpdateCredentialInput,
)
import pytest

from agentrun.credential.api.control import CredentialControlAPI
from agentrun.utils.config import Config


@pytest.fixture
def mock_config():
return Config(
access_key_id="test-ak",
access_key_secret="test-sk",
region_id="cn-hangzhou",
control_endpoint="https://agentrun.cn-hangzhou.aliyuncs.com",
)


@pytest.fixture
def mock_response():
response = MagicMock()
response.body.request_id = "test-request-id"
response.body.data = MagicMock()
return response


@pytest.fixture
def api_and_client(mock_config, mock_response):
api = CredentialControlAPI(config=mock_config)
mock_client = create_autospec(AgentRunClient, instance=True)

for attr in dir(AgentRunClient):
if "with_options" in attr:
getattr(mock_client, attr).return_value = mock_response

with patch.object(api, "_get_client", return_value=mock_client):
yield api, mock_client


class TestCredentialControlAPISignatures:

def test_create_credential(self, api_and_client):
api, client = api_and_client
input_data = MagicMock(spec=CreateCredentialInput)
api.create_credential(input_data)
client.create_credential_with_options.assert_called_once()

def test_delete_credential(self, api_and_client):
api, client = api_and_client
api.delete_credential("test-cred")
client.delete_credential_with_options.assert_called_once()

def test_update_credential(self, api_and_client):
api, client = api_and_client
input_data = MagicMock(spec=UpdateCredentialInput)
api.update_credential("test-cred", input_data)
client.update_credential_with_options.assert_called_once()

def test_get_credential(self, api_and_client):
api, client = api_and_client
api.get_credential("test-cred")
client.get_credential_with_options.assert_called_once()

def test_list_credentials(self, api_and_client):
api, client = api_and_client
input_data = MagicMock(spec=ListCredentialsRequest)
api.list_credentials(input_data)
client.list_credentials_with_options.assert_called_once()


class TestCredentialControlAPIAsyncSignatures:

@pytest.mark.asyncio
async def test_create_credential_async(self, api_and_client):
api, client = api_and_client
input_data = MagicMock(spec=CreateCredentialInput)
await api.create_credential_async(input_data)
client.create_credential_with_options_async.assert_called_once()

@pytest.mark.asyncio
async def test_delete_credential_async(self, api_and_client):
api, client = api_and_client
await api.delete_credential_async("test-cred")
client.delete_credential_with_options_async.assert_called_once()

@pytest.mark.asyncio
async def test_update_credential_async(self, api_and_client):
api, client = api_and_client
input_data = MagicMock(spec=UpdateCredentialInput)
await api.update_credential_async("test-cred", input_data)
client.update_credential_with_options_async.assert_called_once()

@pytest.mark.asyncio
async def test_get_credential_async(self, api_and_client):
api, client = api_and_client
await api.get_credential_async("test-cred")
client.get_credential_with_options_async.assert_called_once()

@pytest.mark.asyncio
async def test_list_credentials_async(self, api_and_client):
api, client = api_and_client
input_data = MagicMock(spec=ListCredentialsRequest)
await api.list_credentials_async(input_data)
client.list_credentials_with_options_async.assert_called_once()
Loading
Loading