modify: json 解析优化

This commit is contained in:
2026-08-22 03:53:31 +08:00
parent 440efa716f
commit 8b13ed17e6
9 changed files with 603 additions and 44 deletions
+7 -1
View File
@@ -86,6 +86,12 @@ class FakeWorkerManager:
data = payload["data"]
return {"result": data.get("a", 0) + data.get("b", 0)}
async def call_raw(self, worker_type, subject, payload, timeout=3.0, retries=1, cacheable=False):
# 网关透传路径:payload 为预序列化字节,回复原始字节
self.call_payloads.append((worker_type, subject, orjson.loads(payload)))
data = orjson.loads(payload)["data"]
return orjson.dumps({"result": data.get("a", 0) + data.get("b", 0)})
async def call_stream(self, worker_type, subject, payload, timeout=300.0, idle_timeout=10.0):
if self.stream_error == "no_worker":
raise RuntimeError(f"类型 '{worker_type}' 没有可用 Worker。")
@@ -203,7 +209,7 @@ def test_non_stream_compat():
f"status={r.status_code} body={r.text}")
check("非流式调用未进入 call_stream", len(fwm.stream_payloads) == 0)
check("非流式调用仍走 call()", len(fwm.call_payloads) == 2)
check("非流式调用仍走 call_raw", len(fwm.call_payloads) == 2)
def run():