修复(履约绑定): 修复候选快照丢失与全链路绑定校验一致性
This commit is contained in:
@@ -5491,3 +5491,254 @@ class TestBindingAndCompletion(_Base):
|
||||
task_id=task.id,
|
||||
current=self.admin,
|
||||
)
|
||||
|
||||
def test_empty_baseline_stripped_bind_candidates_reconciles_to_role_ready(self):
|
||||
"""历史无 baseline 且 bind_candidates 被裁剪的扫码任务,刷新/对账后应收敛为待确认。"""
|
||||
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="stripped-pending-qr",
|
||||
account_id=task.account_id,
|
||||
account_assigned_to=self.admin_id,
|
||||
task_type="get_bind_qr",
|
||||
handbook_scope="elite",
|
||||
status="success",
|
||||
message="已识别角色: 欧美真心,待确认绑定",
|
||||
platform_task_id=task.id,
|
||||
result={
|
||||
"act_alias": "20260120QYOOB",
|
||||
"action_act_aliases": ["20260120QYOOB"],
|
||||
"baseline_role_name": "",
|
||||
"baseline_is_bound_act": False,
|
||||
"before_bind_info": {},
|
||||
"expected_role_name": "欧美真心",
|
||||
"expected_role_required": True,
|
||||
"role_name": "欧美真心",
|
||||
"area_name": "手Q",
|
||||
"plat_name": "苹果(iOS)",
|
||||
"bind_ready_for_confirm": True,
|
||||
"bind_confirmed": False,
|
||||
"bind_phase": "role_ready",
|
||||
"url": "https://livelink.example/qr",
|
||||
"bind_info": {
|
||||
"act_alias": "20260120QYOOB",
|
||||
"role_name": "欧美真心",
|
||||
"area_name": "手Q",
|
||||
"plat_name": "苹果(iOS)",
|
||||
"is_bound_act": False,
|
||||
"is_bound_role": True,
|
||||
"need_bind_act": True,
|
||||
"need_bind_role": True,
|
||||
},
|
||||
"bind_decision": {
|
||||
"alias": "20260120QYOOB",
|
||||
"role_name": "欧美真心",
|
||||
"actionable_alias": True,
|
||||
"confirmable": True,
|
||||
"reason": "existing_actionable_pending",
|
||||
},
|
||||
"bind_candidates": [
|
||||
{
|
||||
"act_alias": "cjm",
|
||||
"role_name": "欧美真心",
|
||||
"is_bound_act": False,
|
||||
},
|
||||
{
|
||||
"act_alias": "20260120QYOOB",
|
||||
"role_name": "欧美真心",
|
||||
"is_bound_act": False,
|
||||
},
|
||||
],
|
||||
"bind_candidate_decisions": [
|
||||
{
|
||||
"alias": "20260120QYOOB",
|
||||
"role_name": "欧美真心",
|
||||
"is_bound_act": False,
|
||||
"is_bound_role": True,
|
||||
"need_bind_act": True,
|
||||
"need_bind_role": True,
|
||||
"actionable_alias": True,
|
||||
"confirmable": True,
|
||||
"reason": "existing_actionable_pending",
|
||||
}
|
||||
],
|
||||
},
|
||||
created_by=self.admin_id,
|
||||
)
|
||||
self.session.add(qr_task)
|
||||
self.session.flush()
|
||||
task.bind_task_id = qr_task.id
|
||||
task.binding_status = "qr_pending"
|
||||
task.execution_status = "waiting_bind"
|
||||
self.session.commit()
|
||||
|
||||
reconciled = service.reconcile_binding_observations(self.session)
|
||||
self.session.commit()
|
||||
detail = service.get_task_detail(self.session, task.id)
|
||||
item = detail["task"]
|
||||
|
||||
assert reconciled >= 1
|
||||
assert item["bindingStatus"] == "role_ready"
|
||||
assert item["executionStatus"] == "role_ready"
|
||||
assert item["bindTask"]["roleName"] == "欧美真心"
|
||||
assert item["bindTask"]["bindReadyForConfirm"] is True
|
||||
assert item["bindingEvidence"]["scannedRole"] == "欧美真心"
|
||||
assert item["bindingEvidence"]["baselineRole"] == ""
|
||||
assert item["bindingEvidence"]["confirmable"] is True
|
||||
assert item["bindingEvidence"]["actionPending"]["needBindAct"] is True
|
||||
assert item["bindingEvidence"]["actionPending"]["channel"] == "手Q / 苹果(iOS)"
|
||||
|
||||
def test_current_confirm_bind_with_mismatched_customer_role_is_rejected(self):
|
||||
"""即使 bind_task_id 已指向 confirm_bind,确认出非客户目标角色也必须拒绝。"""
|
||||
task = self._allocated()
|
||||
task.customer_role_name = "客户指定角色"
|
||||
confirm_task = DouyuTask(
|
||||
batch_id="current-mismatched-confirm",
|
||||
account_id=task.account_id,
|
||||
account_assigned_to=self.admin_id,
|
||||
task_type="confirm_bind",
|
||||
handbook_scope="elite",
|
||||
status="success",
|
||||
platform_task_id=task.id,
|
||||
result={
|
||||
"act_alias": "20260120QYOOB",
|
||||
"action_act_aliases": ["20260120QYOOB"],
|
||||
"role_name": "账号旧角色",
|
||||
"area_name": "手Q",
|
||||
"plat_name": "苹果(iOS)",
|
||||
"bind_confirmed": True,
|
||||
"bind_phase": "confirmed",
|
||||
},
|
||||
created_by=self.admin_id,
|
||||
)
|
||||
self.session.add(confirm_task)
|
||||
self.session.flush()
|
||||
task.bind_task_id = confirm_task.id
|
||||
task.binding_status = "confirming"
|
||||
task.execution_status = "binding_confirming"
|
||||
self.session.commit()
|
||||
|
||||
synced = service.sync_task_from_binding_runner(
|
||||
self.session,
|
||||
douyu_task_id=confirm_task.id,
|
||||
)
|
||||
|
||||
self.session.refresh(task)
|
||||
rejection = (
|
||||
self.session.query(PlatformFulfillmentEvent)
|
||||
.filter_by(task_id=task.id, event_type="binding_sync_rejected")
|
||||
.one()
|
||||
)
|
||||
assert synced >= 0
|
||||
assert task.binding_status != "bound"
|
||||
assert rejection.detail_json["reason"] == "target_mismatch"
|
||||
|
||||
def test_save_customer_profile_immediately_reconciles_existing_qr_candidates(self):
|
||||
"""先出码扫码、后提交客户资料时,保存资料应立即把订单收敛到 role_ready。"""
|
||||
task = self._allocated()
|
||||
task.customer_role_name = ""
|
||||
qr_task = DouyuTask(
|
||||
batch_id="profile-late-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": "20260120QYOOB",
|
||||
"action_act_aliases": ["20260120QYOOB"],
|
||||
"expected_role_name": "",
|
||||
"expected_role_required": True,
|
||||
"role_name": "后补角色",
|
||||
"area_name": "手Q",
|
||||
"plat_name": "苹果(iOS)",
|
||||
"bind_ready_for_confirm": True,
|
||||
"bind_confirmed": False,
|
||||
"bind_phase": "role_ready",
|
||||
"url": "https://livelink.example/qr",
|
||||
"bind_candidates": [
|
||||
{
|
||||
"act_alias": "20260120QYOOB",
|
||||
"role_name": "后补角色",
|
||||
"area_name": "手Q",
|
||||
"plat_name": "苹果(iOS)",
|
||||
"is_bound_act": False,
|
||||
"is_bound_role": True,
|
||||
"need_bind_act": True,
|
||||
"need_bind_role": True,
|
||||
}
|
||||
],
|
||||
},
|
||||
created_by=self.admin_id,
|
||||
)
|
||||
self.session.add(qr_task)
|
||||
self.session.flush()
|
||||
task.bind_task_id = qr_task.id
|
||||
task.binding_status = "qr_pending"
|
||||
task.execution_status = "waiting_bind"
|
||||
self.session.commit()
|
||||
|
||||
out = service.save_customer_profile(
|
||||
self.session,
|
||||
task_id=task.id,
|
||||
customer_role_name="后补角色",
|
||||
platform="qq",
|
||||
system="ios",
|
||||
home_images=[{"url": "https://img.example/1.png"}],
|
||||
)
|
||||
|
||||
self.session.refresh(task)
|
||||
assert task.binding_status == "role_ready"
|
||||
assert task.execution_status == "role_ready"
|
||||
assert out["bindingStatus"] == "role_ready"
|
||||
assert out["roleName"] == "后补角色"
|
||||
assert out["bindReadyForConfirm"] is True
|
||||
|
||||
def test_unlinked_workbench_qr_with_wrong_role_is_not_attached(self):
|
||||
"""工作台无归属扫码任务若角色与客户目标不一致,绝不能挂到订单上。"""
|
||||
task = self._allocated()
|
||||
task.customer_role_name = "客户目标角色"
|
||||
task.binding_status = "qr_pending"
|
||||
task.execution_status = "waiting_bind"
|
||||
workbench_qr = DouyuTask(
|
||||
batch_id="workbench-wrong-role",
|
||||
account_id=task.account_id,
|
||||
account_assigned_to=self.admin_id,
|
||||
task_type="get_bind_qr",
|
||||
handbook_scope="elite",
|
||||
status="success",
|
||||
result={
|
||||
"act_alias": "20260120QYOOB",
|
||||
"action_act_aliases": ["20260120QYOOB"],
|
||||
"role_name": "工作台别的号角色",
|
||||
"area_name": "微信",
|
||||
"plat_name": "安卓(android)",
|
||||
"bind_ready_for_confirm": True,
|
||||
"bind_confirmed": False,
|
||||
"bind_phase": "role_ready",
|
||||
"bind_candidates": [
|
||||
{
|
||||
"act_alias": "20260120QYOOB",
|
||||
"role_name": "工作台别的号角色",
|
||||
"is_bound_act": False,
|
||||
"is_bound_role": True,
|
||||
"need_bind_act": True,
|
||||
"need_bind_role": True,
|
||||
}
|
||||
],
|
||||
},
|
||||
created_by=self.admin_id,
|
||||
)
|
||||
self.session.add(workbench_qr)
|
||||
self.session.commit()
|
||||
|
||||
reconciled = service.reconcile_binding_observations(self.session)
|
||||
|
||||
self.session.refresh(task)
|
||||
assert reconciled == 0
|
||||
assert task.binding_status == "qr_pending"
|
||||
assert task.bind_task_id is None
|
||||
|
||||
Reference in New Issue
Block a user