fix(douyu): unify binding state and scheduler health

This commit is contained in:
yml
2026-11-23 20:16:59 +08:00
parent 0a32f24fa8
commit e6629a9c91
20 changed files with 1336 additions and 158 deletions
+171
View File
@@ -1889,6 +1889,50 @@ class TestBindingAndCompletion(_Base):
assert task.bind_task_id == confirm_task.id
assert event.detail_json["roleName"] == "新角色"
def test_account_bound_does_not_confirm_unconfirmed_confirmation_task(self):
task = self._allocated()
account = self.session.get(Account, task.account_id)
account.role_bind_status = "bound"
account.game_name = "账号当前角色"
task.binding_status = "role_ready"
task.execution_status = "role_ready"
confirm_task = DouyuTask(
batch_id="unconfirmed-confirm-task",
account_id=task.account_id,
account_assigned_to=self.admin_id,
task_type="confirm_bind",
handbook_scope="elite",
status="success",
result={
"role_name": "账号当前角色",
"is_bound_act": True,
"bind_confirmed": False,
"bind_phase": "waiting_role",
},
created_by=self.admin_id,
)
self.session.add(confirm_task)
self.session.commit()
synced = service.sync_task_from_binding_runner(
self.session,
douyu_task_id=confirm_task.id,
)
self.session.refresh(task)
assert synced == 0
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_synced_from_account",
)
.count()
== 0
)
def test_bind_qr_success_does_not_promote_existing_account_binding(self):
task = self._allocated()
account = self.session.get(Account, task.account_id)
@@ -1954,6 +1998,133 @@ class TestBindingAndCompletion(_Base):
== 0
)
def test_standalone_pending_bind_task_links_to_active_fulfillment_task(self):
task = self._allocated()
old_bind_task = DouyuTask(
batch_id="bind-old-pending",
account_id=task.account_id,
account_assigned_to=self.admin_id,
task_type="get_bind_qr",
handbook_scope="elite",
status="success",
result={
"role_name": "旧待确认角色",
"current_role_name": "历史角色",
"baseline_role_name": "历史角色",
"before_bind_info": {
"act_alias": "20260120QYOOB",
"role_name": "历史角色",
"is_bound_act": True,
"need_bind_act": True,
},
"bind_ready_for_confirm": True,
"bind_confirmed": False,
"bind_phase": "role_ready",
},
created_by=self.admin_id,
)
self.session.add(old_bind_task)
self.session.flush()
task.bind_task_id = old_bind_task.id
task.binding_status = "role_ready"
task.execution_status = "role_ready"
latest_bind_task = DouyuTask(
batch_id="account-workbench-new-pending",
account_id=task.account_id,
account_assigned_to=self.admin_id,
task_type="get_bind_qr",
handbook_scope="elite",
status="success",
result={
"role_name": "最新待确认角色",
"current_role_name": "历史角色",
"baseline_role_name": "历史角色",
"before_bind_info": {
"act_alias": "20260120QYOOB",
"role_name": "历史角色",
"is_bound_act": True,
"need_bind_act": True,
},
"bind_ready_for_confirm": True,
"bind_confirmed": False,
"bind_phase": "role_ready",
},
created_by=self.admin_id,
)
self.session.add(latest_bind_task)
self.session.commit()
synced = service.sync_task_from_binding_runner(
self.session,
douyu_task_id=latest_bind_task.id,
)
self.session.refresh(task)
detail = service.get_task_detail(self.session, task.id)
assert synced == 1
assert task.bind_task_id == latest_bind_task.id
assert task.binding_status == "role_ready"
assert detail["task"]["bindTask"]["roleName"] == "最新待确认角色"
event = (
self.session.query(PlatformFulfillmentEvent)
.filter_by(
task_id=task.id,
event_type="binding_pending_task_linked",
)
.one()
)
assert event.detail_json["previousBindTaskId"] == old_bind_task.id
assert event.detail_json["bindTaskId"] == latest_bind_task.id
def test_refresh_binding_attaches_latest_pending_account_workbench_role(self):
task = self._allocated()
old_bind_task = DouyuTask(
batch_id="refresh-old-pending",
account_id=task.account_id,
account_assigned_to=self.admin_id,
task_type="get_bind_qr",
handbook_scope="elite",
status="success",
result={"role_name": "旧待确认角色", "bind_ready_for_confirm": True},
created_by=self.admin_id,
)
latest_bind_task = DouyuTask(
batch_id="refresh-latest-pending",
account_id=task.account_id,
account_assigned_to=self.admin_id,
task_type="get_bind_qr",
handbook_scope="elite",
status="success",
result={
"role_name": "最新待确认角色",
"current_role_name": "历史角色",
"baseline_role_name": "历史角色",
"before_bind_info": {
"act_alias": "20260120QYOOB",
"role_name": "历史角色",
"is_bound_act": True,
"need_bind_act": True,
},
"bind_ready_for_confirm": True,
"bind_confirmed": False,
"bind_phase": "role_ready",
},
created_by=self.admin_id,
)
self.session.add_all([old_bind_task, latest_bind_task])
self.session.flush()
task.bind_task_id = old_bind_task.id
task.binding_status = "role_ready"
task.execution_status = "role_ready"
self.session.commit()
detail = service.refresh_binding(self.session, task_id=task.id)
self.session.refresh(task)
assert task.bind_task_id == latest_bind_task.id
assert detail["task"]["bindTask"]["roleName"] == "最新待确认角色"
assert detail["task"]["bindTask"]["bindReadyForConfirm"] is True
def test_customer_start_mapping_missing_is_idempotent(self, monkeypatch):
task = self.task(mapped=False)
task.issue_code = "mapping_missing"