agent-core-qa 0.8.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
agent_core_qa/client.py
ADDED
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
"""DaemonClient — thin HTTP wrapper for the agent_core daemon.
|
|
2
|
+
|
|
3
|
+
Tool-shaped: stateless across calls, no connection pooling beyond what
|
|
4
|
+
httpx does internally, no retry, no session caching.
|
|
5
|
+
|
|
6
|
+
Transport discovery (Preflight Step 0, Task 3):
|
|
7
|
+
The daemon's HTTPHost (Starlette+Uvicorn) mounts only MCPHostable
|
|
8
|
+
endpoint paths — there is NO /bus/publish or /bus/inbox route.
|
|
9
|
+
Endpoints that implement MCPHostable (i.e. ClaudeCodeMCPEndpoint)
|
|
10
|
+
are mounted at /mcp/<name>/ and expose a FastMCP Streamable HTTP
|
|
11
|
+
server. StubEndpoint is NOT MCPHostable — it has no HTTP surface.
|
|
12
|
+
|
|
13
|
+
To publish an envelope from the QA runner, we call the `send` MCP
|
|
14
|
+
tool on a ClaudeCodeMCPEndpoint (e.g. the `qa` agent endpoint). The
|
|
15
|
+
tool stamps from_=<agent-name> and dispatches to `stub`. The stub's
|
|
16
|
+
auto_ack=True calls bus.ack() (marks it handled in persistence) but
|
|
17
|
+
does NOT publish an Acknowledgment envelope back to the sender.
|
|
18
|
+
|
|
19
|
+
Round-trip proof: the `send` tool call returns
|
|
20
|
+
{"status": "published", "id": <envelope_id>} synchronously after
|
|
21
|
+
the bus has dispatched and stub has delivered+acked. The bus is
|
|
22
|
+
single-threaded and dispatches in-process, so delivery is complete
|
|
23
|
+
before the tool returns. We then call `list_pending` on the same
|
|
24
|
+
agent endpoint to confirm the queue count=0 (nothing waiting).
|
|
25
|
+
|
|
26
|
+
Transport: fastmcp.Client connected to
|
|
27
|
+
http://<host>:<port>/mcp/<agent>/ (Streamable HTTP). Async methods
|
|
28
|
+
because fastmcp.Client is an async context manager.
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
from __future__ import annotations
|
|
32
|
+
|
|
33
|
+
import asyncio
|
|
34
|
+
import json
|
|
35
|
+
import socket
|
|
36
|
+
import time
|
|
37
|
+
import urllib.parse
|
|
38
|
+
from collections.abc import Callable
|
|
39
|
+
from typing import Any
|
|
40
|
+
|
|
41
|
+
try:
|
|
42
|
+
from fastmcp.client import Client as _FastMCPClient
|
|
43
|
+
|
|
44
|
+
_HAS_FASTMCP = True
|
|
45
|
+
except ImportError: # pragma: no cover
|
|
46
|
+
_HAS_FASTMCP = False
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
class _FakeTCPResponse:
|
|
50
|
+
"""Mimics a minimal httpx.Response for callers of health_check().
|
|
51
|
+
|
|
52
|
+
Used when health_check() falls back to a TCP-connect check because
|
|
53
|
+
the daemon has no dedicated HTTP liveness route. status_code=200
|
|
54
|
+
means the port is accepting connections; status_code=503 means it
|
|
55
|
+
isn't (or the connect timed out).
|
|
56
|
+
"""
|
|
57
|
+
|
|
58
|
+
def __init__(self, *, status_code: int, text: str = ""):
|
|
59
|
+
self.status_code = status_code
|
|
60
|
+
self.text = text
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
class _MCPToolResult:
|
|
64
|
+
"""Thin wrapper around a fastmcp tool-call result.
|
|
65
|
+
|
|
66
|
+
Mimics the httpx.Response API used by callers so scenario code reads
|
|
67
|
+
the same regardless of whether the underlying transport is raw HTTP
|
|
68
|
+
or MCP-over-HTTP. status_code=200 means the tool call succeeded;
|
|
69
|
+
status_code=500 means the tool raised.
|
|
70
|
+
"""
|
|
71
|
+
|
|
72
|
+
def __init__(self, *, status_code: int, data: Any = None, text: str = ""):
|
|
73
|
+
self.status_code = status_code
|
|
74
|
+
self._data = data
|
|
75
|
+
self.text = text
|
|
76
|
+
|
|
77
|
+
def json(self) -> Any:
|
|
78
|
+
return self._data
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
class DaemonClient:
|
|
82
|
+
"""HTTP client for the agent_core daemon.
|
|
83
|
+
|
|
84
|
+
Targets the daemon's HTTP API (default http://127.0.0.1:8787 for the
|
|
85
|
+
Phase 3.5 test instance). One client per scenario; no shared state.
|
|
86
|
+
|
|
87
|
+
Transport: MCP tools over FastMCP Streamable HTTP at /mcp/<agent>/.
|
|
88
|
+
send_envelope() and poll_envelopes() are async — call them with
|
|
89
|
+
`await` from async test functions (pytest-asyncio asyncio_mode=auto).
|
|
90
|
+
|
|
91
|
+
Preflight finding: the daemon's HTTPHost (Starlette+Uvicorn) has no
|
|
92
|
+
dedicated liveness HTTP route — it only mounts MCP endpoint paths.
|
|
93
|
+
health_check() therefore uses a TCP-connect check on the bind port
|
|
94
|
+
rather than a GET to a specific path. A successful TCP connect means
|
|
95
|
+
the daemon process is up and its HTTP server is accepting connections.
|
|
96
|
+
"""
|
|
97
|
+
|
|
98
|
+
def __init__(
|
|
99
|
+
self,
|
|
100
|
+
base_url: str,
|
|
101
|
+
*,
|
|
102
|
+
timeout: float = 10.0,
|
|
103
|
+
mcp_agent: str = "qa",
|
|
104
|
+
):
|
|
105
|
+
self.base_url = base_url.rstrip("/")
|
|
106
|
+
self._timeout = timeout
|
|
107
|
+
self._mcp_agent = mcp_agent
|
|
108
|
+
|
|
109
|
+
@property
|
|
110
|
+
def _mcp_url(self) -> str:
|
|
111
|
+
"""URL of the agent's MCP endpoint on the daemon."""
|
|
112
|
+
return f"{self.base_url}/mcp/{self._mcp_agent}/"
|
|
113
|
+
|
|
114
|
+
def health_check(self) -> _FakeTCPResponse:
|
|
115
|
+
"""TCP-connect check on the daemon's bind port.
|
|
116
|
+
|
|
117
|
+
TCP-connect fallback: the daemon's HTTPHost (Starlette+Uvicorn)
|
|
118
|
+
exposes no dedicated liveness route — only MCP endpoint mounts.
|
|
119
|
+
A successful TCP connect on the bind port indicates the HTTP
|
|
120
|
+
server is accepting connections. Returns a response-like object
|
|
121
|
+
with status_code=200 on success or status_code=503 on failure.
|
|
122
|
+
"""
|
|
123
|
+
parsed = urllib.parse.urlparse(self.base_url)
|
|
124
|
+
host = parsed.hostname or "127.0.0.1"
|
|
125
|
+
port = parsed.port or 80
|
|
126
|
+
try:
|
|
127
|
+
conn = socket.create_connection((host, port), timeout=self._timeout)
|
|
128
|
+
conn.close()
|
|
129
|
+
return _FakeTCPResponse(status_code=200, text="TCP connect OK")
|
|
130
|
+
except OSError as exc:
|
|
131
|
+
return _FakeTCPResponse(status_code=503, text=str(exc))
|
|
132
|
+
|
|
133
|
+
async def send_envelope(self, envelope: dict[str, Any]) -> _MCPToolResult:
|
|
134
|
+
"""Call the `send` MCP tool on the agent's ClaudeCodeMCPEndpoint.
|
|
135
|
+
|
|
136
|
+
Transport: fastmcp.Client connected to /mcp/<agent>/ (Streamable
|
|
137
|
+
HTTP). The `send` tool accepts the envelope fields as kwargs and
|
|
138
|
+
publishes to the bus. The bus stamps from_=<agent-name>.
|
|
139
|
+
|
|
140
|
+
The tool returns {"status": "published", "id": <envelope_id>}
|
|
141
|
+
synchronously after the bus dispatches and the recipient endpoint
|
|
142
|
+
delivers+acks. This is the round-trip signal for the stub endpoint
|
|
143
|
+
(stub auto-acks but does NOT publish an Acknowledgment reply).
|
|
144
|
+
|
|
145
|
+
envelope fields consumed:
|
|
146
|
+
to, kind, payload, correlation_id, in_reply_to, metadata,
|
|
147
|
+
urgency, expires_at. The id field is advisory (daemon
|
|
148
|
+
generates a fresh uuid4 hex for each send call).
|
|
149
|
+
"""
|
|
150
|
+
if not _HAS_FASTMCP: # pragma: no cover
|
|
151
|
+
return _MCPToolResult(
|
|
152
|
+
status_code=500,
|
|
153
|
+
text="fastmcp not installed; add fastmcp>=3.0 to agent-core-qa deps",
|
|
154
|
+
)
|
|
155
|
+
|
|
156
|
+
try:
|
|
157
|
+
async with _FastMCPClient(self._mcp_url, timeout=self._timeout) as mcp:
|
|
158
|
+
result = await mcp.call_tool(
|
|
159
|
+
"send",
|
|
160
|
+
arguments={
|
|
161
|
+
"to": envelope["to"],
|
|
162
|
+
"kind": envelope["kind"],
|
|
163
|
+
"payload": envelope.get("payload", {}),
|
|
164
|
+
"correlation_id": envelope.get("correlation_id"),
|
|
165
|
+
"in_reply_to": envelope.get("in_reply_to"),
|
|
166
|
+
"metadata": envelope.get("metadata", {}),
|
|
167
|
+
"urgency": envelope.get("urgency", "green"),
|
|
168
|
+
"expires_at": envelope.get("expires_at"),
|
|
169
|
+
},
|
|
170
|
+
)
|
|
171
|
+
# fastmcp returns a list of content items; unwrap the first text block.
|
|
172
|
+
data: Any = None
|
|
173
|
+
if result and hasattr(result[0], "text"):
|
|
174
|
+
try:
|
|
175
|
+
data = json.loads(result[0].text)
|
|
176
|
+
except (json.JSONDecodeError, AttributeError):
|
|
177
|
+
data = result[0].text if hasattr(result[0], "text") else str(result)
|
|
178
|
+
return _MCPToolResult(status_code=200, data=data, text=str(data))
|
|
179
|
+
except Exception as exc:
|
|
180
|
+
return _MCPToolResult(status_code=500, text=str(exc))
|
|
181
|
+
|
|
182
|
+
async def poll_envelopes(
|
|
183
|
+
self,
|
|
184
|
+
predicate: Callable[[dict[str, Any]], bool],
|
|
185
|
+
*,
|
|
186
|
+
timeout: float = 5.0,
|
|
187
|
+
interval: float = 0.2,
|
|
188
|
+
) -> dict[str, Any] | None:
|
|
189
|
+
"""Poll the agent's pickup queue for an envelope matching predicate.
|
|
190
|
+
|
|
191
|
+
Calls the `list_pending` MCP tool on the agent's
|
|
192
|
+
ClaudeCodeMCPEndpoint in a loop until predicate matches or
|
|
193
|
+
timeout expires. Returns the first matching envelope dict,
|
|
194
|
+
or None if nothing matched within timeout.
|
|
195
|
+
|
|
196
|
+
Note: for the builtin.stub round-trip, stub does NOT publish an
|
|
197
|
+
Acknowledgment envelope back to the sender — it only calls
|
|
198
|
+
bus.ack() (marks the envelope handled in persistence). Therefore
|
|
199
|
+
list_pending on the sender's queue should return count=0 after a
|
|
200
|
+
successful send. Use poll_envelopes only when a true reply
|
|
201
|
+
envelope is expected (e.g. scheduler, discord).
|
|
202
|
+
"""
|
|
203
|
+
if not _HAS_FASTMCP: # pragma: no cover
|
|
204
|
+
return None
|
|
205
|
+
|
|
206
|
+
deadline = time.monotonic() + timeout
|
|
207
|
+
while time.monotonic() < deadline:
|
|
208
|
+
try:
|
|
209
|
+
async with _FastMCPClient(self._mcp_url, timeout=self._timeout) as mcp:
|
|
210
|
+
result = await mcp.call_tool("list_pending", arguments={})
|
|
211
|
+
|
|
212
|
+
data: Any = None
|
|
213
|
+
if result and hasattr(result[0], "text"):
|
|
214
|
+
try:
|
|
215
|
+
data = json.loads(result[0].text)
|
|
216
|
+
except (json.JSONDecodeError, AttributeError):
|
|
217
|
+
# Justified: a malformed tool payload is treated as "no
|
|
218
|
+
# data" and the poll loop retries on the next tick.
|
|
219
|
+
data = None
|
|
220
|
+
if isinstance(data, dict):
|
|
221
|
+
for item in data.get("items", []):
|
|
222
|
+
if predicate(item):
|
|
223
|
+
return item
|
|
224
|
+
except Exception:
|
|
225
|
+
# Justified: this is a best-effort poll loop over a flaky MCP
|
|
226
|
+
# connection; transient errors are swallowed so it keeps retrying
|
|
227
|
+
# until the deadline, then returns None below.
|
|
228
|
+
pass
|
|
229
|
+
await asyncio.sleep(interval)
|
|
230
|
+
return None
|
|
231
|
+
|
|
232
|
+
async def list_pending(self) -> dict[str, Any]:
|
|
233
|
+
"""Return the agent's current pending queue snapshot.
|
|
234
|
+
|
|
235
|
+
Calls the `list_pending` MCP tool. Returns the raw result dict
|
|
236
|
+
{"meta": {...}, "items": [...]} or {"meta": {}, "items": []} on
|
|
237
|
+
failure.
|
|
238
|
+
"""
|
|
239
|
+
if not _HAS_FASTMCP: # pragma: no cover
|
|
240
|
+
return {"meta": {}, "items": []}
|
|
241
|
+
|
|
242
|
+
try:
|
|
243
|
+
async with _FastMCPClient(self._mcp_url, timeout=self._timeout) as mcp:
|
|
244
|
+
result = await mcp.call_tool("list_pending", arguments={})
|
|
245
|
+
|
|
246
|
+
if result and hasattr(result[0], "text"):
|
|
247
|
+
try:
|
|
248
|
+
return json.loads(result[0].text)
|
|
249
|
+
except (json.JSONDecodeError, AttributeError):
|
|
250
|
+
# Justified: a malformed payload falls through to the empty
|
|
251
|
+
# snapshot returned below.
|
|
252
|
+
pass
|
|
253
|
+
except Exception:
|
|
254
|
+
# Justified: list_pending is best-effort; any MCP/transport failure
|
|
255
|
+
# degrades to the documented empty snapshot returned below.
|
|
256
|
+
pass
|
|
257
|
+
return {"meta": {}, "items": []}
|
|
258
|
+
|
|
259
|
+
async def call_tool(
|
|
260
|
+
self,
|
|
261
|
+
tool_name: str,
|
|
262
|
+
arguments: dict[str, Any] | None = None,
|
|
263
|
+
) -> _MCPToolResult:
|
|
264
|
+
"""Call any MCP tool on the agent's ClaudeCodeMCPEndpoint.
|
|
265
|
+
|
|
266
|
+
Generic escape hatch for tools beyond `send` and `list_pending`.
|
|
267
|
+
Used by Scenario 4 to call `compose_brief` and `submit_brief`
|
|
268
|
+
on the `qa` endpoint (which has the briefs tools mounted via
|
|
269
|
+
``briefs_orchestrator`` wiring in the test daemon's config).
|
|
270
|
+
|
|
271
|
+
Returns an _MCPToolResult with status_code=200 on success (the
|
|
272
|
+
tool returned without raising) and status_code=500 on transport
|
|
273
|
+
error or tool exception. The parsed result is available via
|
|
274
|
+
``.json()``; the raw text via ``.text``.
|
|
275
|
+
"""
|
|
276
|
+
if not _HAS_FASTMCP: # pragma: no cover
|
|
277
|
+
return _MCPToolResult(
|
|
278
|
+
status_code=500,
|
|
279
|
+
text="fastmcp not installed; add fastmcp>=3.0 to agent-core-qa deps",
|
|
280
|
+
)
|
|
281
|
+
|
|
282
|
+
try:
|
|
283
|
+
async with _FastMCPClient(self._mcp_url, timeout=self._timeout) as mcp:
|
|
284
|
+
result = await mcp.call_tool(tool_name, arguments=arguments or {})
|
|
285
|
+
|
|
286
|
+
data: Any = None
|
|
287
|
+
if result and hasattr(result[0], "text"):
|
|
288
|
+
try:
|
|
289
|
+
data = json.loads(result[0].text)
|
|
290
|
+
except (json.JSONDecodeError, AttributeError):
|
|
291
|
+
data = result[0].text if hasattr(result[0], "text") else str(result)
|
|
292
|
+
return _MCPToolResult(status_code=200, data=data, text=str(data))
|
|
293
|
+
except Exception as exc:
|
|
294
|
+
return _MCPToolResult(status_code=500, text=str(exc))
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: agent-core-qa
|
|
3
|
+
Version: 0.8.2
|
|
4
|
+
Summary: Release-validation scenario runner for the agent_core daemon (pytest-based)
|
|
5
|
+
Requires-Python: >=3.12
|
|
6
|
+
Requires-Dist: fastmcp>=3.0
|
|
7
|
+
Requires-Dist: httpx>=0.27
|
|
8
|
+
Requires-Dist: pytest-asyncio>=0.23
|
|
9
|
+
Requires-Dist: pytest>=8.0
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
agent_core_qa/__init__.py,sha256=UNMSMWUqpbZl5OzwNpVljg4GcaOWDPJiQNce6v1uMOw,157
|
|
2
|
+
agent_core_qa/client.py,sha256=CqxXRTXPrrz-BziYk-5GWyTSsVBF7u1gWV1svq9Irgc,12469
|
|
3
|
+
agent_core_qa-0.8.2.dist-info/METADATA,sha256=AdM8BKbyEE3JgiHJzT8LXpX7355QHS0RmTZsjqpS0pE,284
|
|
4
|
+
agent_core_qa-0.8.2.dist-info/WHEEL,sha256=lCkmxWfQsSc9CfIClYeavTdQeEX2toPqufh9gI35EQA,87
|
|
5
|
+
agent_core_qa-0.8.2.dist-info/RECORD,,
|