-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_agent.py
More file actions
198 lines (165 loc) · 6.31 KB
/
Copy pathtest_agent.py
File metadata and controls
198 lines (165 loc) · 6.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
"""Synchronous SDK smoke tests for Agent operations."""
from __future__ import annotations
import pytest
from runloop_api_client.sdk import RunloopSDK
from tests.smoketests.utils import unique_name
from runloop_api_client.types.shared_params import AgentSource
pytestmark = [pytest.mark.smoketest]
THIRTY_SECOND_TIMEOUT = 30
TWO_MINUTE_TIMEOUT = 120
class TestAgentLifecycle:
"""Test basic agent lifecycle operations."""
@pytest.mark.timeout(THIRTY_SECOND_TIMEOUT)
def test_agent_create_basic(self, sdk_client: RunloopSDK) -> None:
"""Test creating a basic agent."""
name = unique_name("sdk-agent-test-basic")
agent = sdk_client.agent.create(
name=name,
source={
"type": "npm",
"npm": {
"package_name": "@runloop/hello-world-agent",
},
},
)
try:
assert agent is not None
assert agent.id is not None
assert len(agent.id) > 0
# Verify agent information
info = agent.get_info()
assert info.id == agent.id
assert info.name == name
finally:
# TODO: Add agent cleanup once delete endpoint is implemented
# Currently agents don't have a delete method - they persist after tests
# Once implemented, add: agent.delete()
pass
@pytest.mark.timeout(THIRTY_SECOND_TIMEOUT)
def test_agent_get_info(self, sdk_client: RunloopSDK) -> None:
"""Test retrieving agent information."""
name = unique_name("sdk-agent-test-info")
agent = sdk_client.agent.create(
name=name,
source={
"type": "npm",
"npm": {
"package_name": "@runloop/hello-world-agent",
},
},
)
try:
info = agent.get_info()
assert info.id == agent.id
assert info.name == name
assert info.create_time_ms > 0
assert isinstance(info.is_public, bool)
finally:
# TODO: Add agent cleanup once delete endpoint is implemented
pass
class TestAgentListing:
"""Test agent listing and retrieval operations."""
@pytest.mark.timeout(THIRTY_SECOND_TIMEOUT)
def test_list_agents(self, sdk_client: RunloopSDK) -> None:
"""Test listing agents."""
agents = sdk_client.agent.list(limit=10)
assert isinstance(agents, list)
# List might be empty, that's okay
assert len(agents) >= 0
@pytest.mark.timeout(THIRTY_SECOND_TIMEOUT)
def test_get_agent_by_id(self, sdk_client: RunloopSDK) -> None:
"""Test retrieving agent by ID."""
# Create an agent
created = sdk_client.agent.create(
name=unique_name("sdk-agent-test-retrieve"),
source={
"type": "npm",
"npm": {
"package_name": "@runloop/hello-world-agent",
},
},
)
try:
# Retrieve it by ID
retrieved = sdk_client.agent.from_id(created.id)
assert retrieved.id == created.id
# Verify it's the same agent
info = retrieved.get_info()
assert info.id == created.id
finally:
# TODO: Add agent cleanup once delete endpoint is implemented
pass
@pytest.mark.timeout(THIRTY_SECOND_TIMEOUT)
def test_list_multiple_agents(self, sdk_client: RunloopSDK) -> None:
"""Test listing multiple agents after creation."""
source_config: AgentSource = {
"type": "npm",
"npm": {
"package_name": "@runloop/hello-world-agent",
},
}
# Create multiple agents
agent1 = sdk_client.agent.create(name=unique_name("sdk-agent-test-list-1"), source=source_config)
agent2 = sdk_client.agent.create(name=unique_name("sdk-agent-test-list-2"), source=source_config)
agent3 = sdk_client.agent.create(name=unique_name("sdk-agent-test-list-3"), source=source_config)
try:
# List agents
agents = sdk_client.agent.list(limit=100)
assert isinstance(agents, list)
assert len(agents) >= 3
# Verify our agents are in the list
agent_ids = [a.id for a in agents]
assert agent1.id in agent_ids
assert agent2.id in agent_ids
assert agent3.id in agent_ids
finally:
# TODO: Add agent cleanup once delete endpoint is implemented
# Should delete: agent1, agent2, agent3
pass
class TestAgentCreationVariations:
"""Test different agent creation scenarios."""
@pytest.mark.timeout(THIRTY_SECOND_TIMEOUT)
def test_agent_with_source_npm(self, sdk_client: RunloopSDK) -> None:
"""Test creating an agent with npm source."""
name = unique_name("sdk-agent-test-npm")
agent = sdk_client.agent.create(
name=name,
source={
"type": "npm",
"npm": {
"package_name": "@runloop/example-agent",
},
},
)
try:
assert agent.id is not None
info = agent.get_info()
assert info.name == name
assert info.source is not None
assert info.source.type == "npm"
finally:
# TODO: Add agent cleanup once delete endpoint is implemented
pass
@pytest.mark.timeout(THIRTY_SECOND_TIMEOUT)
def test_agent_with_source_git(self, sdk_client: RunloopSDK) -> None:
"""Test creating an agent with git source."""
name = unique_name("sdk-agent-test-git")
agent = sdk_client.agent.create(
name=name,
source={
"type": "git",
"git": {
"repository": "https://github.com/runloop/example-agent",
"ref": "main",
},
},
)
try:
assert agent.id is not None
info = agent.get_info()
assert info.name == name
assert info.source is not None
assert info.source.type == "git"
finally:
# TODO: Add agent cleanup once delete endpoint is implemented
pass