Import ECS deployed relay source and historical patches (2026-10-27)

This commit is contained in:
ex_tianzy
2026-10-27 17:26:58 +08:00
commit 011a7797ee
319 changed files with 34265 additions and 0 deletions
@@ -0,0 +1,44 @@
import asyncio
import json
import secrets
from fastapi import FastAPI
from relay.device import run_device
from .conftest import provision, serve
from .test_hainuo1065 import POLICY, config
from .test_web_session import browser
async def test_h5_cookie_to_encrypted_device_to_native_http_result(env):
"""Real loopback HTTP + WS, with a native model contract fixture."""
app = FastAPI()
@app.get("/health")
async def health():
return {"status": "ok", "platform": "hermes-agent"}
@app.get("/v1/capabilities")
async def capabilities():
return {"hainuo_relay_policy": POLICY}
@app.get("/v1/models")
async def models():
return {"data": [{"id": "hainuo-relay-text"}]}
@app.post("/v1/chat/completions")
async def chat():
return {"choices": [{"message": {"content": "42"}, "finish_reason": "stop"}]}
server, task, port = await serve(app)
directory, host = await provision(env)
cfg = config(env["root"], f"http://127.0.0.1:{port}")
connected = asyncio.Event()
device = asyncio.create_task(run_device(directory, env["router_url"], connected_event=connected, hainuo_config=cfg))
env["tasks"].append(device)
try:
await asyncio.wait_for(connected.wait(), 5)
headers = await browser(env, directory, host)
response = await env["client"].post("/web/chat", headers=headers,
json={"text": "17加25", "request_id": secrets.token_hex(16)})
assert response.status_code == 200
assert response.json()["status"] == "completed"
assert response.json()["result"] == "42"
finally:
server.should_exit = True
await asyncio.wait_for(task, 5)