Skip to content

Commit f15629c

Browse files
committed
add more deets to agent list test
1 parent 5d95b03 commit f15629c

2 files changed

Lines changed: 64 additions & 5 deletions

File tree

tests/sdk/conftest.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ class MockAgentView:
103103

104104
id: str = "agent_123"
105105
name: str = "test-agent"
106+
create_time_ms: int = 1234567890000
107+
is_public: bool = False
108+
source: Any = None
106109

107110

108111
def create_mock_httpx_client(methods: dict[str, Any] | None = None) -> AsyncMock:

tests/sdk/test_ops.py

Lines changed: 61 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -680,9 +680,32 @@ def test_from_id(self, mock_client: Mock) -> None:
680680
assert isinstance(agent, Agent)
681681
assert agent.id == "agent_123"
682682

683-
def test_list(self, mock_client: Mock, agent_view: MockAgentView) -> None:
683+
def test_list(self, mock_client: Mock) -> None:
684684
"""Test list method."""
685-
page = SimpleNamespace(agents=[agent_view])
685+
# Create three agent views with different data
686+
agent_view_1 = MockAgentView(
687+
id="agent_001",
688+
name="first-agent",
689+
create_time_ms=1234567890000,
690+
is_public=False,
691+
source=None,
692+
)
693+
agent_view_2 = MockAgentView(
694+
id="agent_002",
695+
name="second-agent",
696+
create_time_ms=1234567891000,
697+
is_public=True,
698+
source={"type": "git", "git": {"repository": "https://github.com/example/repo"}},
699+
)
700+
agent_view_3 = MockAgentView(
701+
id="agent_003",
702+
name="third-agent",
703+
create_time_ms=1234567892000,
704+
is_public=False,
705+
source={"type": "npm", "npm": {"package_name": "example-package"}},
706+
)
707+
708+
page = SimpleNamespace(agents=[agent_view_1, agent_view_2, agent_view_3])
686709
mock_client.agents.list.return_value = page
687710

688711
client = AgentOps(mock_client)
@@ -691,9 +714,42 @@ def test_list(self, mock_client: Mock, agent_view: MockAgentView) -> None:
691714
starting_after="agent_000",
692715
)
693716

694-
assert len(agents) == 1
695-
assert isinstance(agents[0], Agent)
696-
assert agents[0].id == "agent_123"
717+
# Verify we got three agents
718+
assert len(agents) == 3
719+
assert all(isinstance(agent, Agent) for agent in agents)
720+
721+
# Verify the agent IDs
722+
assert agents[0].id == "agent_001"
723+
assert agents[1].id == "agent_002"
724+
assert agents[2].id == "agent_003"
725+
726+
# Test that get_info() retrieves the cached AgentView for the first agent
727+
info = agents[0].get_info()
728+
assert info.id == "agent_001"
729+
assert info.name == "first-agent"
730+
assert info.create_time_ms == 1234567890000
731+
assert info.is_public is False
732+
assert info.source is None
733+
734+
# Test that get_info() retrieves the cached AgentView for the second agent
735+
info = agents[1].get_info()
736+
assert info.id == "agent_002"
737+
assert info.name == "second-agent"
738+
assert info.create_time_ms == 1234567891000
739+
assert info.is_public is True
740+
assert info.source == {"type": "git", "git": {"repository": "https://github.com/example/repo"}}
741+
742+
# Test that get_info() retrieves the cached AgentView for the third agent
743+
info = agents[2].get_info()
744+
assert info.id == "agent_003"
745+
assert info.name == "third-agent"
746+
assert info.create_time_ms == 1234567892000
747+
assert info.is_public is False
748+
assert info.source == {"type": "npm", "npm": {"package_name": "example-package"}}
749+
750+
# Verify that agents.retrieve was NOT called (because we're using cached data)
751+
mock_client.agents.retrieve.assert_not_called()
752+
697753
mock_client.agents.list.assert_called_once()
698754

699755

0 commit comments

Comments
 (0)