Skip to content

Commit 3186c3e

Browse files
committed
style: fix ruff lint and format issues in integration tests
1 parent d344f81 commit 3186c3e

File tree

6 files changed

+212
-138
lines changed

6 files changed

+212
-138
lines changed

tests/integration/conftest.py

Lines changed: 52 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,17 @@ def pytest_configure(config: pytest.Config) -> None:
5555

5656
from agentanycast._generated.agentanycast.v1 import ( # noqa: E402
5757
a2a_models_pb2 as a2a_pb2,
58-
agent_card_pb2 as card_pb2,
58+
)
59+
from agentanycast._generated.agentanycast.v1 import ( # noqa: E402
5960
node_service_pb2 as ns_pb2,
61+
)
62+
from agentanycast._generated.agentanycast.v1 import ( # noqa: E402
6063
node_service_pb2_grpc as ns_grpc,
61-
registry_service_pb2 as reg_pb2,
64+
)
65+
from agentanycast._generated.agentanycast.v1 import ( # noqa: E402
6266
registry_service_pb2_grpc as reg_grpc,
6367
)
6468

65-
6669
# ── Docker Compose gRPC fixtures ────────────────────────────────────
6770

6871

@@ -150,43 +153,59 @@ def _sub():
150153

151154
def send_task_to_peer(sender_client, peer_id: str, text: str = "hello") -> str:
152155
"""Send a text task from sender to peer, return task_id."""
153-
resp = sender_client.SendTask(ns_pb2.SendTaskRequest(
154-
peer_id=peer_id,
155-
message=a2a_pb2.Message(
156-
role=a2a_pb2.MESSAGE_ROLE_USER,
157-
parts=[a2a_pb2.Part(text_part=a2a_pb2.TextPart(text=text))],
158-
),
159-
))
156+
resp = sender_client.SendTask(
157+
ns_pb2.SendTaskRequest(
158+
peer_id=peer_id,
159+
message=a2a_pb2.Message(
160+
role=a2a_pb2.MESSAGE_ROLE_USER,
161+
parts=[a2a_pb2.Part(text_part=a2a_pb2.TextPart(text=text))],
162+
),
163+
)
164+
)
160165
return resp.task.task_id
161166

162167

163168
def complete_task(client, task_id: str, result_text: str = "done") -> None:
164169
"""Transition task to WORKING then COMPLETED."""
165-
client.UpdateTaskStatus(ns_pb2.UpdateTaskStatusRequest(
166-
task_id=task_id, status=a2a_pb2.TASK_STATUS_WORKING,
167-
))
168-
client.CompleteTask(ns_pb2.CompleteTaskRequest(
169-
task_id=task_id,
170-
artifacts=[a2a_pb2.Artifact(
171-
artifact_id=unique_id("art"),
172-
name="result",
173-
parts=[a2a_pb2.Part(text_part=a2a_pb2.TextPart(text=result_text))],
174-
)],
175-
))
170+
client.UpdateTaskStatus(
171+
ns_pb2.UpdateTaskStatusRequest(
172+
task_id=task_id,
173+
status=a2a_pb2.TASK_STATUS_WORKING,
174+
)
175+
)
176+
client.CompleteTask(
177+
ns_pb2.CompleteTaskRequest(
178+
task_id=task_id,
179+
artifacts=[
180+
a2a_pb2.Artifact(
181+
artifact_id=unique_id("art"),
182+
name="result",
183+
parts=[a2a_pb2.Part(text_part=a2a_pb2.TextPart(text=result_text))],
184+
)
185+
],
186+
)
187+
)
176188

177189

178190
def fail_task(client, task_id: str, error_message: str = "test error") -> None:
179191
"""Transition task to WORKING then FAILED."""
180-
client.UpdateTaskStatus(ns_pb2.UpdateTaskStatusRequest(
181-
task_id=task_id, status=a2a_pb2.TASK_STATUS_WORKING,
182-
))
183-
client.FailTask(ns_pb2.FailTaskRequest(
184-
task_id=task_id, error_message=error_message,
185-
))
192+
client.UpdateTaskStatus(
193+
ns_pb2.UpdateTaskStatusRequest(
194+
task_id=task_id,
195+
status=a2a_pb2.TASK_STATUS_WORKING,
196+
)
197+
)
198+
client.FailTask(
199+
ns_pb2.FailTaskRequest(
200+
task_id=task_id,
201+
error_message=error_message,
202+
)
203+
)
186204

187205

188206
def wait_task_status(client, task_id: str, status, timeout: float = 15):
189207
"""Poll until task reaches the given status."""
208+
190209
def _check():
191210
resp = client.GetTask(ns_pb2.GetTaskRequest(task_id=task_id))
192211
return resp.task.status == status
@@ -207,10 +226,12 @@ def connect_nodes(client_a, client_b):
207226
peer_id_b = resp_b.node_info.peer_id
208227
addrs_b = list(resp_b.node_info.listen_addresses)
209228

210-
client_a.ConnectPeer(ns_pb2.ConnectPeerRequest(
211-
peer_id=peer_id_b,
212-
addresses=addrs_b,
213-
))
229+
client_a.ConnectPeer(
230+
ns_pb2.ConnectPeerRequest(
231+
peer_id=peer_id_b,
232+
addresses=addrs_b,
233+
)
234+
)
214235
return peer_id_a, peer_id_b
215236

216237

tests/integration/test_anycast.py

Lines changed: 38 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,12 @@
2727

2828
from agentanycast._generated.agentanycast.v1 import ( # noqa: E402
2929
node_service_pb2 as ns_pb2,
30+
)
31+
from agentanycast._generated.agentanycast.v1 import ( # noqa: E402
3032
registry_service_pb2 as reg_pb2,
3133
)
3234

33-
from .conftest import unique_id, wait_for # noqa: E402
35+
from .conftest import unique_id # noqa: E402
3436

3537

3638
class TestAnycastSkillRouting:
@@ -45,19 +47,25 @@ def test_anycast_skill_routing(self, grpc_registry, grpc_node_a, grpc_node_b) ->
4547
peer_id_b = resp_b.node_info.peer_id
4648

4749
# Register the skill at the relay for node B.
48-
grpc_registry.RegisterSkills(reg_pb2.RegisterSkillsRequest(
49-
peer_id=peer_id_b,
50-
skills=[reg_pb2.SkillInfo(
51-
skill_id=skill_id,
52-
description=f"Test skill {skill_id}",
53-
)],
54-
agent_name=f"Anycast Agent ({skill_id})",
55-
))
50+
grpc_registry.RegisterSkills(
51+
reg_pb2.RegisterSkillsRequest(
52+
peer_id=peer_id_b,
53+
skills=[
54+
reg_pb2.SkillInfo(
55+
skill_id=skill_id,
56+
description=f"Test skill {skill_id}",
57+
)
58+
],
59+
agent_name=f"Anycast Agent ({skill_id})",
60+
)
61+
)
5662

5763
# Discover via the registry.
58-
resp = grpc_registry.DiscoverBySkill(reg_pb2.DiscoverBySkillRequest(
59-
skill_id=skill_id,
60-
))
64+
resp = grpc_registry.DiscoverBySkill(
65+
reg_pb2.DiscoverBySkillRequest(
66+
skill_id=skill_id,
67+
)
68+
)
6169
assert len(resp.agents) >= 1
6270
peer_ids = [a.peer_id for a in resp.agents]
6371
assert peer_id_b in peer_ids
@@ -77,20 +85,26 @@ def test_anycast_tag_filtering(self, grpc_registry) -> None:
7785

7886
# Register three agents with same skill but different tags.
7987
for peer_id, lang in [(peer_en, "en"), (peer_zh, "zh"), (peer_ja, "ja")]:
80-
grpc_registry.RegisterSkills(reg_pb2.RegisterSkillsRequest(
81-
peer_id=peer_id,
82-
skills=[reg_pb2.SkillInfo(
83-
skill_id=skill_id,
84-
tags={"lang": lang},
85-
)],
86-
agent_name=f"Agent-{lang}",
87-
))
88+
grpc_registry.RegisterSkills(
89+
reg_pb2.RegisterSkillsRequest(
90+
peer_id=peer_id,
91+
skills=[
92+
reg_pb2.SkillInfo(
93+
skill_id=skill_id,
94+
tags={"lang": lang},
95+
)
96+
],
97+
agent_name=f"Agent-{lang}",
98+
)
99+
)
88100

89101
# Filter by lang=zh.
90-
resp = grpc_registry.DiscoverBySkill(reg_pb2.DiscoverBySkillRequest(
91-
skill_id=skill_id,
92-
tags={"lang": "zh"},
93-
))
102+
resp = grpc_registry.DiscoverBySkill(
103+
reg_pb2.DiscoverBySkillRequest(
104+
skill_id=skill_id,
105+
tags={"lang": "zh"},
106+
)
107+
)
94108
peer_ids = [a.peer_id for a in resp.agents]
95109
assert peer_zh in peer_ids
96110
assert peer_en not in peer_ids

tests/integration/test_api.py

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,13 @@ def test_list_agents(self, grpc_registry) -> None:
4040
peer_id = unique_id("12D3KooW-api")
4141
skill_id = unique_id("api-skill")
4242

43-
grpc_registry.RegisterSkills(reg_pb2.RegisterSkillsRequest(
44-
peer_id=peer_id,
45-
skills=[reg_pb2.SkillInfo(skill_id=skill_id, description="API test")],
46-
agent_name=agent_name,
47-
))
43+
grpc_registry.RegisterSkills(
44+
reg_pb2.RegisterSkillsRequest(
45+
peer_id=peer_id,
46+
skills=[reg_pb2.SkillInfo(skill_id=skill_id, description="API test")],
47+
agent_name=agent_name,
48+
)
49+
)
4850

4951
resp = httpx.get(f"{RELAY_API}/api/v1/agents", timeout=10)
5052
assert resp.status_code == 200
@@ -60,16 +62,20 @@ def test_filter_by_skill(self, grpc_registry) -> None:
6062
peer_match = unique_id("12D3KooW-match")
6163
peer_other = unique_id("12D3KooW-other")
6264

63-
grpc_registry.RegisterSkills(reg_pb2.RegisterSkillsRequest(
64-
peer_id=peer_match,
65-
skills=[reg_pb2.SkillInfo(skill_id=skill_id)],
66-
agent_name="Match Agent",
67-
))
68-
grpc_registry.RegisterSkills(reg_pb2.RegisterSkillsRequest(
69-
peer_id=peer_other,
70-
skills=[reg_pb2.SkillInfo(skill_id=unique_id("other-skill"))],
71-
agent_name="Other Agent",
72-
))
65+
grpc_registry.RegisterSkills(
66+
reg_pb2.RegisterSkillsRequest(
67+
peer_id=peer_match,
68+
skills=[reg_pb2.SkillInfo(skill_id=skill_id)],
69+
agent_name="Match Agent",
70+
)
71+
)
72+
grpc_registry.RegisterSkills(
73+
reg_pb2.RegisterSkillsRequest(
74+
peer_id=peer_other,
75+
skills=[reg_pb2.SkillInfo(skill_id=unique_id("other-skill"))],
76+
agent_name="Other Agent",
77+
)
78+
)
7379

7480
resp = httpx.get(
7581
f"{RELAY_API}/api/v1/agents",

tests/integration/test_bridge.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727

2828
from agentanycast._generated.agentanycast.v1 import ( # noqa: E402
2929
agent_card_pb2 as card_pb2,
30+
)
31+
from agentanycast._generated.agentanycast.v1 import ( # noqa: E402
3032
node_service_pb2 as ns_pb2,
3133
)
3234

@@ -40,12 +42,14 @@ def test_bridge_card_endpoint(self, grpc_node_a) -> None:
4042
"""GET /.well-known/agent.json returns a valid AgentCard JSON."""
4143
# First set a card on node-a so the endpoint has something to return.
4244
card_name = unique_id("bridge-agent")
43-
grpc_node_a.SetAgentCard(ns_pb2.SetAgentCardRequest(
44-
card=card_pb2.AgentCard(
45-
name=card_name,
46-
skills=[card_pb2.Skill(id="bridge-test", description="Bridge test skill")],
47-
),
48-
))
45+
grpc_node_a.SetAgentCard(
46+
ns_pb2.SetAgentCardRequest(
47+
card=card_pb2.AgentCard(
48+
name=card_name,
49+
skills=[card_pb2.Skill(id="bridge-test", description="Bridge test skill")],
50+
),
51+
)
52+
)
4953

5054
resp = httpx.get(f"{NODE_A_BRIDGE}/.well-known/agent.json", timeout=10)
5155
assert resp.status_code == 200
@@ -57,12 +61,14 @@ def test_bridge_card_endpoint(self, grpc_node_a) -> None:
5761
def test_bridge_inbound_endpoint(self, grpc_node_a) -> None:
5862
"""POST /a2a endpoint should accept requests (or return a structured error)."""
5963
# Ensure there's a card set.
60-
grpc_node_a.SetAgentCard(ns_pb2.SetAgentCardRequest(
61-
card=card_pb2.AgentCard(
62-
name=unique_id("bridge-inbound"),
63-
skills=[card_pb2.Skill(id="inbound-test", description="Inbound test")],
64-
),
65-
))
64+
grpc_node_a.SetAgentCard(
65+
ns_pb2.SetAgentCardRequest(
66+
card=card_pb2.AgentCard(
67+
name=unique_id("bridge-inbound"),
68+
skills=[card_pb2.Skill(id="inbound-test", description="Inbound test")],
69+
),
70+
)
71+
)
6672

6773
# Send a minimal A2A JSON-RPC request.
6874
payload = {

0 commit comments

Comments
 (0)