fix(huya): 查询角色复用协作台账 CK 探针并标记失效
This commit is contained in:
@@ -111,6 +111,90 @@ class _FakeBindStatus:
|
||||
return {"status": self.status, "msg": self.msg}
|
||||
|
||||
|
||||
class _FakeGameAccount:
|
||||
def __init__(self, nick: str):
|
||||
self.nick = nick
|
||||
|
||||
def to_dict(self) -> dict:
|
||||
return {"nick": self.nick}
|
||||
|
||||
|
||||
class _FakeGameRole:
|
||||
def __init__(self, role_name: str, plat_name: str = "", area_name: str = ""):
|
||||
self.roleName = role_name
|
||||
self.platName = plat_name
|
||||
self.areaName = area_name
|
||||
|
||||
def to_dict(self) -> dict:
|
||||
return {
|
||||
"role_name": self.roleName,
|
||||
"plat_name": self.platName,
|
||||
"area_name": self.areaName,
|
||||
}
|
||||
|
||||
|
||||
class _FakeBindAccountData:
|
||||
def __init__(self, nick: str, role_name: str):
|
||||
self.gameAccount = _FakeGameAccount(nick)
|
||||
self.gameRole = _FakeGameRole(role_name, "苹果(iOS)", "手Q")
|
||||
self.isBindAcount = 1
|
||||
self.isBindRole = 1
|
||||
self.isNeedActCheck = 0
|
||||
self.changBindTime = 0
|
||||
|
||||
|
||||
class _FakeBindResponse:
|
||||
def __init__(
|
||||
self,
|
||||
*,
|
||||
status: int = 200,
|
||||
msg: str = "",
|
||||
nick: str = "微信用户",
|
||||
role_name: str = "吃鸡199706",
|
||||
):
|
||||
self.status = status
|
||||
self.msg = msg
|
||||
self.gameName = "和平精英"
|
||||
self.changeBindDay = 7
|
||||
self.accountData = _FakeBindAccountData(nick, role_name)
|
||||
|
||||
def to_dict(self) -> dict:
|
||||
return {
|
||||
"status": self.status,
|
||||
"msg": self.msg,
|
||||
"game_name": self.gameName,
|
||||
"account_data": self.accountData.gameAccount.to_dict(),
|
||||
"game_role": self.accountData.gameRole.to_dict(),
|
||||
}
|
||||
|
||||
|
||||
class _CkProbeClient:
|
||||
def __init__(self, response):
|
||||
self.response = response
|
||||
self.calls: list[dict] = []
|
||||
|
||||
def check_user_bind_game_account(self, **kwargs):
|
||||
self.calls.append(kwargs)
|
||||
return self.response
|
||||
|
||||
|
||||
def _query_game_runner(monkeypatch, client):
|
||||
runner = HuyaBatchRunner(
|
||||
db=None, batch_id="test-batch", task_type="query_game_name"
|
||||
)
|
||||
marks: list[tuple[str, str, dict | None]] = []
|
||||
monkeypatch.setattr(runner, "_http_client", lambda: client, raising=False)
|
||||
monkeypatch.setattr(
|
||||
runner,
|
||||
"_mark_task",
|
||||
lambda _db, _task, status, message, result=None: marks.append(
|
||||
(status, message, result)
|
||||
),
|
||||
raising=False,
|
||||
)
|
||||
return runner, marks
|
||||
|
||||
|
||||
class _StubClient:
|
||||
"""积分中心通道的假客户端:可返回宝典状态/订单列表/赛季配置,并记录调用。"""
|
||||
|
||||
@@ -667,6 +751,81 @@ def test_query_all_keeps_business_error_out_of_ck_expired(monkeypatch):
|
||||
assert "活动已下线" in message
|
||||
|
||||
|
||||
def test_query_game_name_uses_new_probe_params_and_saves_role(monkeypatch):
|
||||
"""查询角色必须复用外部单协作的新探针:HTTP + outer_act_id + 15 秒超时。"""
|
||||
client = _CkProbeClient(_FakeBindResponse())
|
||||
runner, marks = _query_game_runner(monkeypatch, client)
|
||||
account = HuyaAccount(uid=str(UID), cookie=COOKIE)
|
||||
|
||||
runner._execute_query_game_name(
|
||||
None,
|
||||
None,
|
||||
account,
|
||||
{"uid": UID, "cookie": COOKIE},
|
||||
{"bind_act_id": "9271", "outer_act_id": "17096"},
|
||||
)
|
||||
|
||||
status, message, result = marks[-1]
|
||||
assert status == "success"
|
||||
assert message == "角色: 吃鸡199706"
|
||||
assert result["role_name"] == "吃鸡199706"
|
||||
assert result["game_title"] == "和平精英"
|
||||
assert account.status == "game_queried"
|
||||
assert account.game_name == "吃鸡199706"
|
||||
assert account.game_channel == "苹果(iOS) / 手Q"
|
||||
assert client.calls == [
|
||||
{
|
||||
"uid": UID,
|
||||
"cookie": COOKIE,
|
||||
"b_act_id": 9271,
|
||||
"is_use_outer_act_id": 1,
|
||||
"outer_act_id": "17096",
|
||||
"timeout": 15.0,
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
def test_query_game_name_marks_ck_expired_when_probe_has_no_response(monkeypatch):
|
||||
client = _CkProbeClient(None)
|
||||
runner, marks = _query_game_runner(monkeypatch, client)
|
||||
account = HuyaAccount(uid=str(UID), cookie=COOKIE, status="imported")
|
||||
|
||||
runner._execute_query_game_name(
|
||||
None,
|
||||
None,
|
||||
account,
|
||||
{"uid": UID, "cookie": COOKIE},
|
||||
{"bind_act_id": "9271", "outer_act_id": "17096"},
|
||||
)
|
||||
|
||||
status, message, result = marks[-1]
|
||||
assert status == "error"
|
||||
assert "CK 已失效" in message
|
||||
assert result["ck_expired"] is True
|
||||
assert result["ck_expired_reason"] == "角色信息接口无响应"
|
||||
assert account.status == "ck_expired"
|
||||
|
||||
|
||||
def test_query_game_name_does_not_mark_business_error_as_ck_expired(monkeypatch):
|
||||
client = _CkProbeClient(_FakeBindResponse(status=601, msg="活动已下线"))
|
||||
runner, marks = _query_game_runner(monkeypatch, client)
|
||||
account = HuyaAccount(uid=str(UID), cookie=COOKIE, status="imported")
|
||||
|
||||
runner._execute_query_game_name(
|
||||
None,
|
||||
None,
|
||||
account,
|
||||
{"uid": UID, "cookie": COOKIE},
|
||||
{"bind_act_id": "9271", "outer_act_id": "17096"},
|
||||
)
|
||||
|
||||
status, message, result = marks[-1]
|
||||
assert status == "failed"
|
||||
assert message == "活动已下线"
|
||||
assert result.get("ck_expired") is None
|
||||
assert account.status == "imported"
|
||||
|
||||
|
||||
def test_shop_client_falls_back_to_http_when_wss_init_fails(monkeypatch):
|
||||
"""设备态齐全但积分中心端点不回包时(wsLaunch 超时)回退 HTTP,而不是判整批失败。"""
|
||||
cookie = (
|
||||
|
||||
Reference in New Issue
Block a user