From 6530eb41adbb05cb6d690915a3d9a767150c7b23 Mon Sep 17 00:00:00 2001 From: Teknium <127238744+teknium1@users.noreply.github.com> Date: Mon, 7 Sep 2026 02:39:45 -0700 Subject: [PATCH] test: verify API Runs continuation consumers over loopback HTTP --- evals/api_delegation_http_probe.py | 24 ++++++++++++++++++- .../test_api_delegation_delivery_contract.py | 9 +++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/evals/api_delegation_http_probe.py b/evals/api_delegation_http_probe.py index af4f54717a..4158287de7 100644 --- a/evals/api_delegation_http_probe.py +++ b/evals/api_delegation_http_probe.py @@ -51,7 +51,9 @@ async def probe(): adapter._create_agent = create_agent app = web.Application() app.router.add_post("/v1/chat/completions", adapter._handle_chat_completions) + app.router.add_post("/v1/runs", adapter._handle_runs) records = [] + runs = [] async with TestClient(TestServer(app)) as client: for stream in (False, True): for explicit in (False, True): @@ -71,7 +73,27 @@ async def probe(): calls_after = len(captured) response = await client.post("/v1/chat/completions", headers={"Authorization": "Bearer fixture-api-key", "X-Hermes-Session-Id": "parent"}, json={"messages": [{"role": "user", "content": "read result"}]}) await response.read() - result = {"requests": records, "delivery_error": delivery_error, "unsolicited_calls": calls_after-calls_before, "resumed_history": captured[-1]["history"], "durable_child_rows": len(db.get_messages("child"))} + resumed_history = captured[-1]["history"] + snapshot = [{"role": "user", "content": "caller snapshot"}] + adapter._response_store.put("resp-seed", {"conversation_history": snapshot, "session_id": "parent"}) + db.create_session("declared", source="api_server", session_key="fixture-key") + db.append_message("declared", "assistant", "DECLARED_HISTORY") + for name, body, extra_headers in ( + ("session", {"session_id": "parent"}, {}), + ("caller_history", {"session_id": "parent", "conversation_history": snapshot}, {}), + ("response_chain", {"previous_response_id": "resp-seed"}, {}), + ("declared_key", {}, {"X-Hermes-Session-Key": "fixture-key"}), + ): + count = len(captured) + response = await client.post("/v1/runs", headers={"Authorization": "Bearer fixture-api-key", **extra_headers}, json={"input": "continue", **body}) + await response.read() + async def wait_for_run(): + while len(captured) == count: + await asyncio.sleep(0.01) + if response.status == 202: + await asyncio.wait_for(wait_for_run(), 10) + runs.append({"name": name, "status": response.status, "runtime": captured[-1] if len(captured) > count else None}) + result = {"requests": records, "runs": runs, "delivery_error": delivery_error, "unsolicited_calls": calls_after-calls_before, "resumed_history": resumed_history, "durable_child_rows": len(db.get_messages("child"))} db.close() return result diff --git a/tests/gateway/test_api_delegation_delivery_contract.py b/tests/gateway/test_api_delegation_delivery_contract.py index b77d75baf2..6ada9a6442 100644 --- a/tests/gateway/test_api_delegation_delivery_contract.py +++ b/tests/gateway/test_api_delegation_delivery_contract.py @@ -41,6 +41,15 @@ async def test_detached_dispatch_requires_a_declared_consumer(monkeypatch): assert result["unsolicited_calls"] == 0 assert result["durable_child_rows"] == 1 assert sum(m["content"] == "DELIVERY_RESULT" for m in result["resumed_history"]) == 1 + runs = {r["name"]: r for r in result["runs"]} + assert all(r["status"] == 202 for r in runs.values()) + for name in ("caller_history", "response_chain"): + assert runs[name]["runtime"]["target"] is None + assert runs[name]["runtime"]["history"] == [{"role": "user", "content": "caller snapshot"}] + assert runs["session"]["runtime"]["target"] == "child" + assert runs["session"]["runtime"]["history"] == result["resumed_history"] + assert runs["declared_key"]["runtime"]["target"] == "declared" + assert runs["declared_key"]["runtime"]["history"][0]["content"] == "DECLARED_HISTORY" @pytest.mark.asyncio