fix(huya): 区分当前绑定与待确认角色

This commit is contained in:
yml
2026-11-14 09:33:51 +08:00
parent 269a8d1b11
commit 5b117e7641
6 changed files with 572 additions and 55 deletions
+8 -8
View File
@@ -1071,11 +1071,11 @@ class TestCollabCkProbe(TestCollabBase):
assert inner["is_use_outer_act_id"] == 0
assert inner["scene"] == "undefined"
def test_verify_queries_second_path_for_latest_role(self):
"""外层返回旧角色时,必须取第二路(outerActId=空)的最新角色。"""
def test_verify_uses_outer_current_role_instead_of_inner_pending_role(self):
"""待绑定状态取外层当前角色;内层新角色不能覆盖外部单绑定快照。"""
order = self._row_with_ck(uid="1199647239697")
class StaleThenLatestClient:
class CurrentThenPendingClient:
def __init__(self):
self.calls: list[dict] = []
@@ -1085,7 +1085,7 @@ class TestCollabCkProbe(TestCollabBase):
return FakeBindResp(nick="冰点", role="软芙乎")
return FakeBindResp(nick="冰点", role="唉哟酪酪")
client = StaleThenLatestClient()
client = CurrentThenPendingClient()
collab.verify_ck(self.db, self.user, order, client=client)
@@ -1094,11 +1094,11 @@ class TestCollabCkProbe(TestCollabBase):
assert inner["outer_act_id"] == ""
assert inner["gid"] == collab.PROBE_GID == 3203
assert inner["scene"] == "undefined"
# 快照落的是第二路的最新角色,而不是外层旧角色
assert order.bind_game_role == "唉哟酪酪"
# 2026-11-14 HAR:外层是当前绑定,内层是待确认新角色。
assert order.bind_game_role == "软芙乎"
assert order.bind_game_account == "冰点"
assert "唉哟酪酪" in order.ck_check_message
assert "软芙乎" not in order.ck_check_message
assert "软芙乎" in order.ck_check_message
assert "唉哟酪酪" not in order.ck_check_message
def test_verify_marks_invalid_when_status_is_not_200(self):
order = self._row_with_ck()
+153
View File
@@ -733,6 +733,74 @@ def test_query_all_combines_points_elite_and_role(monkeypatch):
)
def test_query_all_saves_current_role_and_reports_pending(monkeypatch):
shop_client = _StubClient(
redeem=_redeem(REDEEM_OPENED_HEX), order_pages=[[PAID_ELITE_ORDER]]
)
runner, marks, _logs = _runner(monkeypatch, shop_client, activity_client=object())
current = {
"role_name": "巫师基尔斯84",
"role_id": "current-role",
"game_role": {
"role_name": "巫师基尔斯84",
"role_id": "current-role",
"plat_name": "苹果(iOS)",
"area_name": "微信",
},
"channel": "苹果(iOS) / 微信",
"is_bind_account": 1,
"is_bind_role": 1,
"change_bind_time": 0,
"change_bind_day": 7,
"game_title": "和平精英",
}
pending = {
"role_name": "落地盒子怪cc",
"role_id": "pending-role",
"game_role": {
"role_name": "落地盒子怪cc",
"role_id": "pending-role",
"plat_name": "安卓(android)",
"area_name": "微信",
},
"channel": "安卓(android) / 微信",
"is_bind_account": 1,
"is_bind_role": 1,
"change_bind_time": 0,
"change_bind_day": 0,
"game_title": "和平精英",
}
monkeypatch.setattr(
runner,
"_probe_bind_status",
lambda **kwargs: (
_FakeBindStatus(),
{
"current_role": current,
"pending_role": pending,
"has_pending_role": True,
"outer_bind_role": current,
"inner_bind_role": pending,
},
),
raising=False,
)
account = HuyaAccount(uid=str(UID), cookie=COOKIE)
runner._execute_query_all(
None, None, account, {"uid": UID, "cookie": COOKIE}, {"bind_act_id": "9271"}
)
status, message, result = marks[-1]
assert status == "success"
assert result["current_role_name"] == "巫师基尔斯84"
assert result["pending_role_name"] == "落地盒子怪cc"
assert result["pending_game_channel"] == "安卓(android) / 微信"
assert "角色 巫师基尔斯84,待确认 落地盒子怪cc" in message
assert account.game_name == "巫师基尔斯84"
assert account.game_channel == "苹果(iOS) / 微信"
def test_query_all_reports_not_opened_and_checks_order_state(monkeypatch):
shop_client = _StubClient(redeem=_redeem(REDEEM_NOT_OPENED_HEX))
runner, marks, _logs = _runner(monkeypatch, shop_client, activity_client=object())
@@ -1085,6 +1153,91 @@ def test_inner_bind_probe_keeps_gid_and_empties_outer_act_id(monkeypatch):
assert calls[1]["gid"] == 3203
def test_bind_probe_separates_current_and_pending_roles(monkeypatch):
"""待绑定状态两路都返回角色时,当前角色是外层,内层只能作为待确认候选。"""
current = _FakeBindResponse(
role_name="巫师基尔斯84",
is_need_act_check=1,
)
current.accountData.gameRole.platName = "苹果(iOS)"
current.accountData.gameRole.areaName = "微信"
pending = _FakeBindResponse(
role_name="落地盒子怪cc",
is_need_act_check=0,
)
pending.accountData.gameRole.platName = "安卓(android)"
pending.accountData.gameRole.areaName = "微信"
responses = [current, pending]
client = _CkProbeClient(None)
def fake_check(**_kwargs):
return responses.pop(0)
monkeypatch.setattr(client, "check_user_bind_game_account", fake_check)
runner, _marks = _task_runner(monkeypatch, "query_game_name")
status, detail = runner._resolve_bind_status(
client,
UID,
COOKIE,
b_act_id_int=0,
outer_act_id="17096",
gid=3203,
is_use_outer_act_id=0,
scene="undefined",
)
assert status.accountData.gameRole.roleName == "巫师基尔斯84"
assert detail["current_role"]["role_name"] == "巫师基尔斯84"
assert detail["current_role"]["channel"] == "苹果(iOS) / 微信"
assert detail["pending_role"]["role_name"] == "落地盒子怪cc"
assert detail["pending_role"]["channel"] == "安卓(android) / 微信"
assert detail["has_pending_role"] is True
def test_query_game_name_saves_current_role_and_reports_pending(monkeypatch):
"""查询角色时当前绑定写账号,待确认只进任务结果,不能覆盖 game_name。"""
current = _FakeBindResponse(
role_name="巫师基尔斯84",
is_need_act_check=1,
)
current.accountData.gameRole.platName = "苹果(iOS)"
current.accountData.gameRole.areaName = "微信"
pending = _FakeBindResponse(
role_name="落地盒子怪cc",
is_need_act_check=0,
)
pending.accountData.gameRole.platName = "安卓(android)"
pending.accountData.gameRole.areaName = "微信"
responses = [current, pending]
client = _CkProbeClient(None)
def fake_check(**_kwargs):
return responses.pop(0)
monkeypatch.setattr(client, "check_user_bind_game_account", fake_check)
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_gid": "3203", "outer_act_id": "17096"},
)
status, message, result = marks[-1]
assert status == "success"
assert message == "当前已绑定: 巫师基尔斯84;待确认: 落地盒子怪cc"
assert result["current_role_name"] == "巫师基尔斯84"
assert result["pending_role_name"] == "落地盒子怪cc"
assert result["pending_game_channel"] == "安卓(android) / 微信"
assert result["bind_ready_for_confirm"] is True
assert account.game_name == "巫师基尔斯84"
assert account.game_channel == "苹果(iOS) / 微信"
def test_confirm_bind_uses_latest_har_protocol(monkeypatch):
"""确认绑定复用抓包里的 gid=3203 / bActId=0 / outerActId=17096。"""
client = _BindConfirmClient()