fix(fulfillment): 修正直播账号履约绑定与取消流程
- 按活动 alias 与 cjm 双角色快照建立绑定 baseline,避免旧角色被误判为本次扫码 - 确认绑定任务固化目标角色,禁止回退确认旧角色 - 绑定失败状态优先于旧待确认标记,并支持客服重置客户角色资料 - 取消任务改为终态幂等操作,停止关联批次并默认释放账号和租约 - 补充双角色选择、重置绑定和取消释放账号测试
This commit is contained in:
@@ -12,11 +12,42 @@ from web.backend.services.account_binding import (
|
||||
BIND_UNBOUND,
|
||||
binding_snapshot,
|
||||
derive_from_bind_info,
|
||||
is_pending_binding_role,
|
||||
is_role_change_cooling,
|
||||
role_change_available_at,
|
||||
)
|
||||
from web.backend.services.douyu_runner_bind import BindMixin
|
||||
|
||||
ACT_ALIAS = "20260120QYOOB"
|
||||
LEGACY_ALIAS = "cjm"
|
||||
ROLE_CONFIG = {
|
||||
"legacy_act_alias": LEGACY_ALIAS,
|
||||
"confirm_act_alias": ACT_ALIAS,
|
||||
"bind_act_alias": ACT_ALIAS,
|
||||
}
|
||||
|
||||
|
||||
class _RolePicker(BindMixin):
|
||||
pass
|
||||
|
||||
|
||||
def _role_candidate(
|
||||
alias: str,
|
||||
role_name: str,
|
||||
*,
|
||||
bound_act: bool = False,
|
||||
) -> dict[str, Any]:
|
||||
return {
|
||||
"act_alias": alias,
|
||||
"role_name": role_name,
|
||||
"area_name": "微信",
|
||||
"plat_name": "安卓(android)",
|
||||
"is_bound_account": True,
|
||||
"is_bound_role": True,
|
||||
"is_bound_act": bound_act,
|
||||
"need_bind_act": True,
|
||||
"need_bind_role": True,
|
||||
}
|
||||
|
||||
|
||||
def _payload(
|
||||
@@ -118,6 +149,92 @@ def test_scanned_role_is_pending_until_act_bind():
|
||||
assert snapshot["game_channel"] == "微信 / 苹果(iOS)"
|
||||
|
||||
|
||||
def test_existing_pending_role_is_baseline_not_new_scan_result():
|
||||
old_role = "狗鼻子弗尼亚bd"
|
||||
candidates = [
|
||||
_role_candidate(LEGACY_ALIAS, old_role),
|
||||
_role_candidate(ACT_ALIAS, old_role),
|
||||
]
|
||||
picker = _RolePicker()
|
||||
|
||||
baseline = picker._pick_baseline_bind_info(candidates, ROLE_CONFIG)
|
||||
|
||||
assert baseline is not None
|
||||
assert baseline["act_alias"] == ACT_ALIAS
|
||||
assert baseline["role_name"] == old_role
|
||||
assert not is_pending_binding_role(
|
||||
candidates[0],
|
||||
baseline_role_name=old_role,
|
||||
baseline_is_bound_act=False,
|
||||
)
|
||||
assert not is_pending_binding_role(
|
||||
candidates[1],
|
||||
baseline_role_name=old_role,
|
||||
baseline_is_bound_act=False,
|
||||
)
|
||||
|
||||
|
||||
def test_new_role_wins_when_cjm_and_activity_snapshots_differ():
|
||||
old_role = "狗鼻子弗尼亚bd"
|
||||
new_role = "我是火星人2222"
|
||||
candidates = [
|
||||
_role_candidate(LEGACY_ALIAS, old_role),
|
||||
_role_candidate(ACT_ALIAS, new_role),
|
||||
]
|
||||
picker = _RolePicker()
|
||||
|
||||
selected = picker._pick_bind_info(
|
||||
candidates,
|
||||
baseline_role_name=old_role,
|
||||
baseline_is_bound_act=False,
|
||||
prefer_pending=True,
|
||||
prefer_aliases=[LEGACY_ALIAS, ACT_ALIAS],
|
||||
)
|
||||
target = picker._pick_target_role_info(candidates, ROLE_CONFIG)
|
||||
|
||||
assert selected is not None
|
||||
assert selected["act_alias"] == ACT_ALIAS
|
||||
assert selected["role_name"] == new_role
|
||||
assert target is not None
|
||||
assert target["role_name"] == new_role
|
||||
|
||||
|
||||
def test_changed_cjm_role_wins_over_old_bound_activity_role():
|
||||
old_role = "狗鼻子弗尼亚bd"
|
||||
new_role = "我是火星人2222"
|
||||
candidates = [
|
||||
_role_candidate(LEGACY_ALIAS, new_role),
|
||||
_role_candidate(ACT_ALIAS, old_role, bound_act=True),
|
||||
]
|
||||
picker = _RolePicker()
|
||||
|
||||
target = picker._pick_target_role_info(candidates, ROLE_CONFIG)
|
||||
|
||||
assert target is not None
|
||||
assert target["act_alias"] == LEGACY_ALIAS
|
||||
assert target["role_name"] == new_role
|
||||
|
||||
|
||||
def test_expected_role_never_falls_back_to_old_activity_role():
|
||||
old_role = "狗鼻子弗尼亚bd"
|
||||
new_role = "我是火星人2222"
|
||||
candidates = [
|
||||
_role_candidate(LEGACY_ALIAS, new_role),
|
||||
_role_candidate(ACT_ALIAS, old_role),
|
||||
]
|
||||
picker = _RolePicker()
|
||||
|
||||
selected = picker._pick_role_info_for_aliases(
|
||||
candidates,
|
||||
[ACT_ALIAS, LEGACY_ALIAS],
|
||||
required_role_name=new_role,
|
||||
)
|
||||
|
||||
assert selected is not None
|
||||
assert selected["act_alias"] == LEGACY_ALIAS
|
||||
assert selected["role_name"] == new_role
|
||||
|
||||
|
||||
def test_act_bind_is_the_single_final_bound_signal():
|
||||
can_change_time = 1_795_449_600
|
||||
parsed = _parse(
|
||||
|
||||
Reference in New Issue
Block a user