修复(履约绑定): 禁止预检同对抢跑并补齐角色绑定与日志表格展示
This commit is contained in:
@@ -5742,3 +5742,157 @@ class TestBindingAndCompletion(_Base):
|
||||
assert reconciled == 0
|
||||
assert task.binding_status == "qr_pending"
|
||||
assert task.bind_task_id is None
|
||||
|
||||
def test_waiting_scan_preflight_same_pair_with_different_customer_role_does_not_reuse(
|
||||
self,
|
||||
):
|
||||
"""发码预检阶段 cjm 残留旧角色且与客户提交角色不同时,绝不能提前误标为 bound。"""
|
||||
task = self._allocated()
|
||||
task.customer_role_name = "妳总固执任性"
|
||||
account = self.session.get(Account, task.account_id)
|
||||
account.game_name = "强者不屑质疑"
|
||||
account.role_bind_status = "bound"
|
||||
qr_task = DouyuTask(
|
||||
batch_id="preflight-old-cjm",
|
||||
account_id=task.account_id,
|
||||
account_assigned_to=self.admin_id,
|
||||
task_type="get_bind_qr",
|
||||
handbook_scope="elite",
|
||||
status="running",
|
||||
platform_task_id=task.id,
|
||||
result={
|
||||
"act_alias": "20260120QYOOB",
|
||||
"action_act_aliases": ["20260120QYOOB"],
|
||||
"expected_role_name": "妳总固执任性",
|
||||
"expected_role_required": True,
|
||||
"current_role_name": "强者不屑质疑",
|
||||
"baseline_role_name": "强者不屑质疑",
|
||||
"role_name": "",
|
||||
"bind_ready_for_confirm": False,
|
||||
"bind_confirmed": False,
|
||||
"bind_phase": "waiting_scan",
|
||||
"url": "https://livelink.example/qr",
|
||||
"bind_candidates": [
|
||||
{
|
||||
"act_alias": "cjm",
|
||||
"role_name": "强者不屑质疑",
|
||||
"is_bound_act": False,
|
||||
"is_bound_role": True,
|
||||
"need_bind_act": False,
|
||||
},
|
||||
{
|
||||
"act_alias": "20260120QYOOB",
|
||||
"role_name": "强者不屑质疑",
|
||||
"is_bound_act": True,
|
||||
"is_bound_role": True,
|
||||
"need_bind_act": True,
|
||||
},
|
||||
],
|
||||
},
|
||||
created_by=self.admin_id,
|
||||
)
|
||||
self.session.add(qr_task)
|
||||
self.session.flush()
|
||||
task.bind_task_id = qr_task.id
|
||||
task.binding_status = "preparing"
|
||||
task.execution_status = "waiting_bind"
|
||||
self.session.commit()
|
||||
|
||||
service.sync_task_from_binding_runner(self.session, douyu_task_id=qr_task.id)
|
||||
detail = service.get_task_detail(self.session, task.id)
|
||||
|
||||
self.session.refresh(task)
|
||||
assert task.binding_status == "qr_pending"
|
||||
assert task.execution_status == "waiting_bind"
|
||||
assert detail["task"]["bindingEvidence"]["scannedRole"] == ""
|
||||
assert (
|
||||
self.session.query(PlatformFulfillmentEvent)
|
||||
.filter_by(task_id=task.id, event_type="binding_reused_existing_pair")
|
||||
.count()
|
||||
== 0
|
||||
)
|
||||
|
||||
def test_reconcile_reverts_false_same_pair_reuse_and_promotes_scanned_role(self):
|
||||
"""已被历史同对复用误锁为 bound 但尚未兑换的订单,重启对账后应自动回退并推进真实扫码角色。"""
|
||||
task = self._allocated()
|
||||
task.customer_role_name = "妳总固执任性"
|
||||
account = self.session.get(Account, task.account_id)
|
||||
account.game_name = "强者不屑质疑"
|
||||
account.role_bind_status = "bound"
|
||||
qr_task = DouyuTask(
|
||||
batch_id="false-reuse-qr",
|
||||
account_id=task.account_id,
|
||||
account_assigned_to=self.admin_id,
|
||||
task_type="get_bind_qr",
|
||||
handbook_scope="elite",
|
||||
status="success",
|
||||
platform_task_id=task.id,
|
||||
result={
|
||||
"act_alias": "cjm",
|
||||
"action_act_aliases": ["20260120QYOOB"],
|
||||
"expected_role_name": "妳总固执任性",
|
||||
"expected_role_required": True,
|
||||
"current_role_name": "强者不屑质疑",
|
||||
"baseline_role_name": "强者不屑质疑",
|
||||
"role_name": "妳总固执任性",
|
||||
"area_name": "手Q",
|
||||
"plat_name": "安卓(android)",
|
||||
"bind_ready_for_confirm": True,
|
||||
"bind_confirmed": False,
|
||||
"bind_phase": "role_ready",
|
||||
"url": "https://livelink.example/qr",
|
||||
"bind_candidates": [
|
||||
{
|
||||
"act_alias": "cjm",
|
||||
"role_name": "妳总固执任性",
|
||||
"area_name": "手Q",
|
||||
"plat_name": "安卓(android)",
|
||||
"is_bound_act": False,
|
||||
"is_bound_role": True,
|
||||
"need_bind_act": False,
|
||||
},
|
||||
{
|
||||
"act_alias": "20260120QYOOB",
|
||||
"role_name": "强者不屑质疑",
|
||||
"area_name": "微信",
|
||||
"plat_name": "安卓(android)",
|
||||
"is_bound_act": True,
|
||||
"is_bound_role": True,
|
||||
"need_bind_act": True,
|
||||
},
|
||||
],
|
||||
},
|
||||
created_by=self.admin_id,
|
||||
)
|
||||
self.session.add(qr_task)
|
||||
self.session.flush()
|
||||
task.bind_task_id = qr_task.id
|
||||
task.binding_status = "bound"
|
||||
task.execution_status = "bound"
|
||||
self.session.add(
|
||||
PlatformFulfillmentEvent(
|
||||
task_id=task.id,
|
||||
event_type="binding_reused_existing_pair",
|
||||
actor_type="system",
|
||||
actor_id="",
|
||||
detail_json={
|
||||
"roleName": "强者不屑质疑",
|
||||
"sourceTaskId": qr_task.id,
|
||||
"reason": "same_account_same_role",
|
||||
},
|
||||
)
|
||||
)
|
||||
self.session.commit()
|
||||
|
||||
reconciled = service.reconcile_binding_observations(self.session)
|
||||
|
||||
self.session.refresh(task)
|
||||
assert reconciled >= 1
|
||||
assert task.binding_status == "role_ready"
|
||||
assert task.execution_status == "role_ready"
|
||||
assert (
|
||||
self.session.query(PlatformFulfillmentEvent)
|
||||
.filter_by(task_id=task.id, event_type="binding_false_reuse_reverted")
|
||||
.count()
|
||||
== 1
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user