fix: 防止分页漏读和上游异常快照误标 orphaned

This commit is contained in:
SmartUp Developer
2026-07-02 14:21:09 +08:00
parent 00af34c487
commit e2129d3796
4 changed files with 349 additions and 9 deletions
+73
View File
@@ -326,3 +326,76 @@ def test_list_accounts_pagination():
assert "page=2" in str(requests_called[1].url)
finally:
client.close()
def test_list_accounts_pagination_single_large_page_does_not_refetch():
from app.services.website_client import Sub2ApiWebsiteClient
requests_called = []
def handler(req: httpx.Request) -> httpx.Response:
requests_called.append(req)
return httpx.Response(200, json={
"total": 2,
"page": 1,
"page_size": 100,
"pages": 1,
"data": [
{"id": "a1", "name": "acc1"},
{"id": "a2", "name": "acc2"},
],
}, request=req)
client = Sub2ApiWebsiteClient(
base_url="https://target.example",
api_prefix="/api/v1/admin",
auth_type="api_key",
auth_config={"key": "admin-key"},
)
client._client = httpx.Client(transport=httpx.MockTransport(handler))
try:
accounts = client.list_accounts("/accounts")
assert accounts == [
{"id": "a1", "name": "acc1"},
{"id": "a2", "name": "acc2"},
]
assert len(requests_called) == 1
assert "page_size=100" in str(requests_called[0].url)
finally:
client.close()
def test_list_accounts_pagination_returns_none_when_any_page_fails():
from app.services.website_client import Sub2ApiWebsiteClient
requests_called = []
def handler(req: httpx.Request) -> httpx.Response:
requests_called.append(req)
if "page=1" in str(req.url):
return httpx.Response(200, json={
"total": 3,
"page": 1,
"page_size": 2,
"pages": 2,
"data": [
{"id": "a1", "name": "acc1"},
{"id": "a2", "name": "acc2"},
],
}, request=req)
return httpx.Response(500, json={"error": "failed"}, request=req)
client = Sub2ApiWebsiteClient(
base_url="https://target.example",
api_prefix="/api/v1/admin",
auth_type="api_key",
auth_config={"key": "admin-key"},
)
client._client = httpx.Client(transport=httpx.MockTransport(handler))
try:
assert client.list_accounts("/accounts") is None
assert len(requests_called) == 2
finally:
client.close()