解决了部分detail load效率问题和load失败终止pipeline问题

This commit is contained in:
strepsiades
2026-04-02 14:35:28 +08:00
parent bb8ea931b5
commit 74df53889c
14 changed files with 626 additions and 64 deletions
+50
View File
@@ -1,6 +1,8 @@
from __future__ import annotations
import asyncio
import hmac
import hashlib
import logging
import time
@@ -24,9 +26,11 @@ class _FakeAsyncClient:
def __init__(self) -> None:
self.call_times: list[float] = []
self.closed = False
self.last_kwargs: dict | None = None
async def request(self, **kwargs):
self.call_times.append(time.monotonic())
self.last_kwargs = kwargs
return _FakeResponse()
async def aclose(self) -> None:
@@ -114,3 +118,49 @@ async def test_api_client_logs_one_line_request_summary_in_debug_mode(caplog: py
await client.request("GET", "/ping")
assert "🔎 ApiClient request: method=GET endpoint=/ping elapsed=" in caplog.text
@pytest.mark.asyncio
async def test_api_client_get_signature_keeps_list_params_in_signature_source() -> None:
client = ApiClient(
base_url="http://example.com",
uid="uid",
secret="secret",
)
fake_client = _FakeAsyncClient()
client._client = fake_client
await client.request(
"GET",
"/ping",
params={"domains": ["a", "b", "c"], "project_id": "project-1"},
)
assert fake_client.last_kwargs is not None
sent_params = fake_client.last_kwargs["params"]
assert sent_params["domains"] == ["a", "b", "c"]
sign = sent_params["sign"]
sign_source = {k: v for k, v in sent_params.items() if k != "sign"}
items = []
for key, value in sorted(sign_source.items()):
if value is None:
value_str = "null"
elif isinstance(value, bool):
value_str = "true" if value else "false"
elif isinstance(value, str):
value_str = value
elif isinstance(value, (int, float)):
value_str = str(value)
elif isinstance(value, (list, dict)):
value_str = __import__("json").dumps(value, sort_keys=True, separators=(",", ":"), ensure_ascii=False)
else:
value_str = str(value)
items.append(f"{key}={value_str}")
expected_sign = hmac.new(
b"secret",
"&".join(items).encode("utf-8"),
hashlib.sha256,
).hexdigest()
assert sign == expected_sign