fix(douyu): 修正绑定状态与换绑冷却判定

This commit is contained in:
yml
2026-11-22 02:10:29 +08:00
parent 21956d952c
commit fa75ce66ee
9 changed files with 636 additions and 104 deletions
+64 -5
View File
@@ -5,7 +5,9 @@ from __future__ import annotations
from datetime import UTC, datetime
from typing import Any
from core.douyu import DouyuActivityClient
import pytest
from core.douyu import DouyuActivityClient, DouyuActivityError
from web.backend.models import Account
from web.backend.services.account_binding import (
BIND_BOUND,
@@ -195,7 +197,8 @@ def test_existing_pending_role_is_baseline_not_new_scan_result():
)
def test_existing_action_alias_pending_is_stale_without_transition():
def test_existing_action_alias_pending_is_confirmable_without_transition():
"""2026-11-22 成功 HAR:已有 bindAct=0 角色可直接确认。"""
role = "忧郁情潇藏心中"
baseline = _role_candidate(ACT_ALIAS, role, need_bind_act=True)
legacy = _role_candidate(LEGACY_ALIAS, role, need_bind_act=False)
@@ -218,9 +221,23 @@ def test_existing_action_alias_pending_is_stale_without_transition():
actionable_aliases=[ACT_ALIAS],
)
assert decision["confirmable"] is False
assert decision["reason"] == "same_role_stale_pending"
assert selected is None
assert decision["confirmable"] is True
assert decision["reason"] == "existing_actionable_pending"
assert selected is not None
assert selected["act_alias"] == ACT_ALIAS
def test_actionable_pending_without_baseline_is_confirmable():
role = "只为爱杰宝"
activity = _role_candidate(ACT_ALIAS, role, need_bind_act=True)
decision = binding_pending_decision(
activity,
actionable_aliases=[ACT_ALIAS],
)
assert decision["confirmable"] is True
assert decision["reason"] == "existing_actionable_pending"
def test_same_role_after_activity_bind_transition_is_pending():
@@ -323,6 +340,22 @@ def test_task_result_helpers_use_shared_same_role_transition_rule():
assert binding_role_from_result(same_role_scanned) == "少和我较劲"
def test_task_result_helpers_accept_existing_action_alias_pending():
activity = _role_candidate(ACT_ALIAS, "只为爱杰宝", need_bind_act=True)
result = {
**binding_snapshot(activity),
"act_alias": ACT_ALIAS,
"action_act_aliases": [ACT_ALIAS],
"before_bind_info": activity,
"baseline_role_name": "只为爱杰宝",
"bind_ready_for_confirm": True,
"bind_confirmed": False,
}
assert pending_binding_role_from_result(result) == "只为爱杰宝"
assert binding_role_from_result(result) == "只为爱杰宝"
def test_confirmed_new_role_replaces_account_current_role():
account = Account(
username="replace-role",
@@ -507,3 +540,29 @@ def test_qr_and_confirm_requests_follow_latest_har(monkeypatch):
"actAlias": (None, ACT_ALIAS),
"ctn": (None, "ctn"),
}
def test_confirm_bind_preserves_platform_cooldown_error_code(monkeypatch):
"""2026-11-22 失败 HAR:actBind 必须保留 -200001,不能只留中文消息。"""
client = DouyuActivityClient("acf_ccn=ctn")
monkeypatch.setattr(
client,
"acf_ccn",
lambda *, refresh_subscribe=True: "ctn",
)
payload = {
"error": -200001,
"msg": "该平台账号未到可换绑时间,请使用其他平台账号",
"data": None,
}
monkeypatch.setattr(
client,
"_request_json",
lambda *_args, **_kwargs: payload,
)
with pytest.raises(DouyuActivityError) as exc_info:
client.confirm_bind(ACT_ALIAS)
assert exc_info.value.code == -200001
assert exc_info.value.payload == payload