fix(fulfillment): 恢复 cjm 新角色客户确认
- 回滚 QYOOB-only 门禁,扫到新角色即进入 role_ready - 客户页 readiness 与平台任务 role_ready 对齐,避免确认接口 409 - 绑定证据 baseline 不再冒充本次扫码 - 新增人工确认绑定接口与按钮(角色、备注、操作人事件) - 补充客户确认、证据口径和人工确认回归测试
This commit is contained in:
@@ -2837,7 +2837,7 @@ class TestBindingAndCompletion(_Base):
|
||||
assert evidence["legacyLatest"]["roleName"] == "新扫角色"
|
||||
assert evidence["selectedAlias"] == "cjm"
|
||||
assert evidence["selectedActionable"] is False
|
||||
assert evidence["targetRole"] == ""
|
||||
assert evidence["targetRole"] == "新扫角色"
|
||||
assert evidence["scannedRole"] == "新扫角色"
|
||||
assert evidence["confirmable"] is False
|
||||
assert evidence["samePair"] is False
|
||||
@@ -2910,10 +2910,134 @@ class TestBindingAndCompletion(_Base):
|
||||
assert evidence["samePair"] is True
|
||||
assert evidence["actionCurrent"]["roleName"] == "同对角色"
|
||||
assert evidence["legacyLatest"]["roleName"] == "同对角色"
|
||||
assert evidence["targetRole"] == ""
|
||||
assert evidence["targetRole"] == "同对角色"
|
||||
assert evidence["confirmable"] is False
|
||||
|
||||
def test_cjm_only_pending_keeps_order_waiting_action_alias(self):
|
||||
def test_binding_evidence_does_not_treat_baseline_as_scanned(self):
|
||||
task = self._allocated()
|
||||
account = self.session.get(Account, task.account_id)
|
||||
account.game_name = "兔稚儿"
|
||||
account.role_bind_status = "bound"
|
||||
qr_task = DouyuTask(
|
||||
batch_id="evidence-baseline-only",
|
||||
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": "cjm",
|
||||
"role_name": "",
|
||||
"current_role_name": "兔稚儿",
|
||||
"baseline_role_name": "兔稚儿",
|
||||
"baseline_is_bound_act": True,
|
||||
"action_act_aliases": ["20260120QYOOB"],
|
||||
"bind_ready_for_confirm": False,
|
||||
"bind_confirmed": False,
|
||||
"bind_phase": "waiting_scan",
|
||||
"bind_decision": {
|
||||
"alias": "cjm",
|
||||
"role_name": "",
|
||||
"reason": "no_role",
|
||||
"confirmable": False,
|
||||
"actionable_alias": False,
|
||||
},
|
||||
"before_bind_info": {
|
||||
"act_alias": "20260120QYOOB",
|
||||
"role_name": "兔稚儿",
|
||||
"is_bound_act": True,
|
||||
"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()
|
||||
|
||||
detail = service.get_task_detail(self.session, task.id)
|
||||
evidence = detail["task"]["bindingEvidence"]
|
||||
|
||||
assert evidence is not None
|
||||
assert evidence["scannedRole"] == ""
|
||||
assert evidence["samePair"] is False
|
||||
assert evidence["baselineRole"] == "兔稚儿"
|
||||
assert evidence["accountCurrentRole"] == "兔稚儿"
|
||||
assert evidence["actionCurrent"]["roleName"] == "兔稚儿"
|
||||
assert evidence["decisionReason"] == "no_role"
|
||||
|
||||
def test_manual_confirm_binding_marks_bound_without_scan(self):
|
||||
task = self._allocated()
|
||||
account = self.session.get(Account, task.account_id)
|
||||
account.game_name = "兔稚儿"
|
||||
account.role_bind_status = "bound"
|
||||
qr_task = DouyuTask(
|
||||
batch_id="manual-confirm-qr",
|
||||
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={"bind_phase": "waiting_scan", "bind_polling": 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()
|
||||
|
||||
detail = service.manual_confirm_binding_sync(
|
||||
self.session,
|
||||
task_id=task.id,
|
||||
current=self.admin,
|
||||
role_name="兔稚儿",
|
||||
note="客户已在精英宝典完成绑定",
|
||||
)
|
||||
|
||||
self.session.refresh(task)
|
||||
self.session.refresh(qr_task)
|
||||
assert detail["task"]["bindingStatus"] == "bound"
|
||||
assert detail["task"]["executionStatus"] == "bound"
|
||||
assert task.binding_status == "bound"
|
||||
assert task.execution_status == "bound"
|
||||
assert qr_task.status == "stopped"
|
||||
assert "人工确认绑定" in qr_task.message
|
||||
assert qr_task.result["manual_confirmed"] is True
|
||||
assert qr_task.result["manual_confirmed_role"] == "兔稚儿"
|
||||
event = (
|
||||
self.session.query(PlatformFulfillmentEvent)
|
||||
.filter_by(task_id=task.id, event_type="binding_manually_confirmed")
|
||||
.one()
|
||||
)
|
||||
assert event.detail_json["roleName"] == "兔稚儿"
|
||||
assert event.detail_json["note"] == "客户已在精英宝典完成绑定"
|
||||
assert event.detail_json["operatorId"] == self.admin_id
|
||||
|
||||
# 幂等:重复确认不再重复写事件。
|
||||
service.manual_confirm_binding_sync(
|
||||
self.session,
|
||||
task_id=task.id,
|
||||
current=self.admin,
|
||||
role_name="兔稚儿",
|
||||
note="重复确认",
|
||||
)
|
||||
assert (
|
||||
self.session.query(PlatformFulfillmentEvent)
|
||||
.filter_by(task_id=task.id, event_type="binding_manually_confirmed")
|
||||
.count()
|
||||
== 1
|
||||
)
|
||||
|
||||
def test_cjm_only_new_role_enters_role_ready_for_customer_confirm(self):
|
||||
task = self._allocated()
|
||||
qr_task = DouyuTask(
|
||||
batch_id="cjm-only-pending",
|
||||
@@ -2969,35 +3093,39 @@ class TestBindingAndCompletion(_Base):
|
||||
task.execution_status = "waiting_bind"
|
||||
self.session.commit()
|
||||
|
||||
# 客户页 readiness 与确认接口必须读同一层事实:
|
||||
# 平台任务还在 qr_pending 时不能显示“可确认”。
|
||||
assert views.customer_binding_out(self.session, task.id)["bindReadyForConfirm"] is False
|
||||
|
||||
service.refresh_binding(self.session, task_id=task.id)
|
||||
|
||||
self.session.refresh(task)
|
||||
detail = service.get_task_detail(self.session, task.id)
|
||||
evidence = detail["task"]["bindingEvidence"]
|
||||
assert task.binding_status == "qr_pending"
|
||||
assert task.execution_status == "waiting_bind"
|
||||
assert evidence["targetRole"] == ""
|
||||
assert task.binding_status == "role_ready"
|
||||
assert task.execution_status == "role_ready"
|
||||
assert evidence["targetRole"] == "cjm新角色"
|
||||
assert evidence["confirmable"] is True
|
||||
assert views.customer_binding_out(self.session, task.id)["bindReadyForConfirm"] is True
|
||||
assert evidence["legacyLatest"]["roleName"] == "cjm新角色"
|
||||
assert evidence["actionCurrent"]["roleName"] == "旧角色"
|
||||
|
||||
# 兼容部署前已经 role_ready 的订单:确认入口也要拦住 cjm-only 角色。
|
||||
# cjm-only 的新角色也必须能进入客户确认:确认执行器会在 actBind 前
|
||||
# 重新查询 QYOOB,动作通道未同步时返回可重试失败,而不是把客户卡死。
|
||||
task.binding_status = "role_ready"
|
||||
task.execution_status = "role_ready"
|
||||
self.session.commit()
|
||||
with pytest.raises(HTTPException) as exc_info:
|
||||
service.confirm_binding_sync(
|
||||
self.session,
|
||||
task_id=task.id,
|
||||
current=self.admin,
|
||||
)
|
||||
assert exc_info.value.status_code == 409
|
||||
assert "动作通道" in str(exc_info.value.detail)
|
||||
assert (
|
||||
service.confirm_binding_sync(
|
||||
self.session,
|
||||
task_id=task.id,
|
||||
current=self.admin,
|
||||
)
|
||||
confirm_task = (
|
||||
self.session.query(DouyuTask)
|
||||
.filter_by(task_type="confirm_bind")
|
||||
.count()
|
||||
== 0
|
||||
.one()
|
||||
)
|
||||
assert confirm_task.result["expected_role_name"] == "cjm新角色"
|
||||
|
||||
def _same_pair_qr_task(self, task, include_legacy: bool = True):
|
||||
candidates = [
|
||||
|
||||
Reference in New Issue
Block a user