Skip to content

Commit 5d95b03

Browse files
committed
initial simple tests for AgentOps
1 parent ec52a80 commit 5d95b03

3 files changed

Lines changed: 104 additions & 1 deletion

File tree

tests/sdk/conftest.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"blueprint": "bp_123",
2222
"object": "obj_123",
2323
"scorer": "scorer_123",
24+
"agent": "agent_123",
2425
}
2526

2627
# Test URL constants
@@ -96,6 +97,14 @@ class MockScorerView:
9697
type: str = "test_scorer"
9798

9899

100+
@dataclass
101+
class MockAgentView:
102+
"""Mock AgentView for testing."""
103+
104+
id: str = "agent_123"
105+
name: str = "test-agent"
106+
107+
99108
def create_mock_httpx_client(methods: dict[str, Any] | None = None) -> AsyncMock:
100109
"""
101110
Create a mock httpx.AsyncClient with proper context manager setup.
@@ -186,6 +195,12 @@ def scorer_view() -> MockScorerView:
186195
return MockScorerView()
187196

188197

198+
@pytest.fixture
199+
def agent_view() -> MockAgentView:
200+
"""Create a mock AgentView."""
201+
return MockAgentView()
202+
203+
189204
@pytest.fixture
190205
def mock_httpx_response() -> Mock:
191206
"""Create a mock httpx.Response."""

tests/sdk/test_agent.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
"""Comprehensive tests for sync Agent class."""
2+
3+
from __future__ import annotations
4+
5+
from unittest.mock import Mock
6+
7+
from tests.sdk.conftest import MockAgentView
8+
from runloop_api_client.sdk import Agent
9+
10+
11+
class TestAgent:
12+
"""Tests for Agent class."""
13+
14+
def test_init(self, mock_client: Mock) -> None:
15+
"""Test Agent initialization."""
16+
agent = Agent(mock_client, "agent_123")
17+
assert agent.id == "agent_123"
18+
19+
def test_repr(self, mock_client: Mock) -> None:
20+
"""Test Agent string representation."""
21+
agent = Agent(mock_client, "agent_123")
22+
assert repr(agent) == "<Agent id='agent_123'>"
23+
24+
def test_get_info(self, mock_client: Mock, agent_view: MockAgentView) -> None:
25+
"""Test get_info method."""
26+
mock_client.agents.retrieve.return_value = agent_view
27+
28+
agent = Agent(mock_client, "agent_123")
29+
result = agent.get_info(
30+
extra_headers={"X-Custom": "value"},
31+
extra_query={"param": "value"},
32+
extra_body={"key": "value"},
33+
timeout=30.0,
34+
)
35+
36+
assert result == agent_view
37+
mock_client.agents.retrieve.assert_called_once_with(
38+
"agent_123",
39+
extra_headers={"X-Custom": "value"},
40+
extra_query={"param": "value"},
41+
extra_body={"key": "value"},
42+
timeout=30.0,
43+
)

tests/sdk/test_ops.py

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,18 @@
1414
MockScorerView,
1515
MockSnapshotView,
1616
MockBlueprintView,
17+
MockAgentView,
1718
create_mock_httpx_response,
1819
)
19-
from runloop_api_client.sdk import Devbox, Scorer, Snapshot, Blueprint, StorageObject
20+
from runloop_api_client.sdk import Agent, Devbox, Scorer, Snapshot, Blueprint, StorageObject
2021
from runloop_api_client.sdk.sync import (
2122
DevboxOps,
2223
ScorerOps,
2324
RunloopSDK,
2425
SnapshotOps,
2526
BlueprintOps,
2627
StorageObjectOps,
28+
AgentOps,
2729
)
2830
from runloop_api_client.lib.polling import PollingConfig
2931

@@ -653,13 +655,56 @@ def test_list_multiple(self, mock_client: Mock) -> None:
653655
mock_client.scenarios.scorers.list.assert_called_once()
654656

655657

658+
class TestAgentClient:
659+
"""Tests for AgentClient class."""
660+
661+
def test_create(self, mock_client: Mock, agent_view: MockAgentView) -> None:
662+
"""Test create method."""
663+
mock_client.agents.create.return_value = agent_view
664+
665+
client = AgentOps(mock_client)
666+
agent = client.create(
667+
name="test-agent",
668+
metadata={"key": "value"},
669+
)
670+
671+
assert isinstance(agent, Agent)
672+
assert agent.id == "agent_123"
673+
mock_client.agents.create.assert_called_once()
674+
675+
def test_from_id(self, mock_client: Mock) -> None:
676+
"""Test from_id method."""
677+
client = AgentOps(mock_client)
678+
agent = client.from_id("agent_123")
679+
680+
assert isinstance(agent, Agent)
681+
assert agent.id == "agent_123"
682+
683+
def test_list(self, mock_client: Mock, agent_view: MockAgentView) -> None:
684+
"""Test list method."""
685+
page = SimpleNamespace(agents=[agent_view])
686+
mock_client.agents.list.return_value = page
687+
688+
client = AgentOps(mock_client)
689+
agents = client.list(
690+
limit=10,
691+
starting_after="agent_000",
692+
)
693+
694+
assert len(agents) == 1
695+
assert isinstance(agents[0], Agent)
696+
assert agents[0].id == "agent_123"
697+
mock_client.agents.list.assert_called_once()
698+
699+
656700
class TestRunloopSDK:
657701
"""Tests for RunloopSDK class."""
658702

659703
def test_init(self) -> None:
660704
"""Test RunloopSDK initialization."""
661705
sdk = RunloopSDK(bearer_token="test-token")
662706
assert sdk.api is not None
707+
assert isinstance(sdk.agent, AgentOps)
663708
assert isinstance(sdk.devbox, DevboxOps)
664709
assert isinstance(sdk.scorer, ScorerOps)
665710
assert isinstance(sdk.snapshot, SnapshotOps)

0 commit comments

Comments
 (0)