Skip to content

Commit c879e7d

Browse files
committed
add more deets to agent list test
1 parent 3f966d8 commit c879e7d

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
@@ -93,6 +93,9 @@ class MockAgentView:
9393

9494
id: str = "agent_123"
9595
name: str = "test-agent"
96+
create_time_ms: int = 1234567890000
97+
is_public: bool = False
98+
source: Any = None
9699

97100

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

tests/sdk/test_clients.py

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

502-
def test_list(self, mock_client: Mock, agent_view: MockAgentView) -> None:
502+
def test_list(self, mock_client: Mock) -> None:
503503
"""Test list method."""
504-
page = SimpleNamespace(agents=[agent_view])
504+
# Create three agent views with different data
505+
agent_view_1 = MockAgentView(
506+
id="agent_001",
507+
name="first-agent",
508+
create_time_ms=1234567890000,
509+
is_public=False,
510+
source=None,
511+
)
512+
agent_view_2 = MockAgentView(
513+
id="agent_002",
514+
name="second-agent",
515+
create_time_ms=1234567891000,
516+
is_public=True,
517+
source={"type": "git", "git": {"repository": "https://github.com/example/repo"}},
518+
)
519+
agent_view_3 = MockAgentView(
520+
id="agent_003",
521+
name="third-agent",
522+
create_time_ms=1234567892000,
523+
is_public=False,
524+
source={"type": "npm", "npm": {"package_name": "example-package"}},
525+
)
526+
527+
page = SimpleNamespace(agents=[agent_view_1, agent_view_2, agent_view_3])
505528
mock_client.agents.list.return_value = page
506529

507530
client = AgentOps(mock_client)
@@ -510,9 +533,42 @@ def test_list(self, mock_client: Mock, agent_view: MockAgentView) -> None:
510533
starting_after="agent_000",
511534
)
512535

513-
assert len(agents) == 1
514-
assert isinstance(agents[0], Agent)
515-
assert agents[0].id == "agent_123"
536+
# Verify we got three agents
537+
assert len(agents) == 3
538+
assert all(isinstance(agent, Agent) for agent in agents)
539+
540+
# Verify the agent IDs
541+
assert agents[0].id == "agent_001"
542+
assert agents[1].id == "agent_002"
543+
assert agents[2].id == "agent_003"
544+
545+
# Test that get_info() retrieves the cached AgentView for the first agent
546+
info = agents[0].get_info()
547+
assert info.id == "agent_001"
548+
assert info.name == "first-agent"
549+
assert info.create_time_ms == 1234567890000
550+
assert info.is_public is False
551+
assert info.source is None
552+
553+
# Test that get_info() retrieves the cached AgentView for the second agent
554+
info = agents[1].get_info()
555+
assert info.id == "agent_002"
556+
assert info.name == "second-agent"
557+
assert info.create_time_ms == 1234567891000
558+
assert info.is_public is True
559+
assert info.source == {"type": "git", "git": {"repository": "https://github.com/example/repo"}}
560+
561+
# Test that get_info() retrieves the cached AgentView for the third agent
562+
info = agents[2].get_info()
563+
assert info.id == "agent_003"
564+
assert info.name == "third-agent"
565+
assert info.create_time_ms == 1234567892000
566+
assert info.is_public is False
567+
assert info.source == {"type": "npm", "npm": {"package_name": "example-package"}}
568+
569+
# Verify that agents.retrieve was NOT called (because we're using cached data)
570+
mock_client.agents.retrieve.assert_not_called()
571+
516572
mock_client.agents.list.assert_called_once()
517573

518574

0 commit comments

Comments
 (0)