fix(douyu): 修正扫码前待确认角色误判
This commit is contained in:
@@ -59,7 +59,7 @@
|
||||
| 来源 | 典型值 | 职责 | 不能做什么 |
|
||||
| --- | --- | --- | --- |
|
||||
| 活动动作 alias | `20260120QYOOB` | 当前精英宝典二维码、待确认和最终确认的权威动作通道 | 不能被 legacy 的旧角色覆盖 |
|
||||
| legacy 最新态 | `cjm` | 补充最新换绑/扫码角色,常更早暴露新角色 | 不能单独代表当前活动已确认;不能压掉活动 alias pending |
|
||||
| legacy 最新态 | `cjm` | 补充最新换绑/扫码角色,常更早暴露新角色 | 不能单独代表当前活动已确认;不能覆盖活动 alias 当前状态 |
|
||||
| 历史查询 alias | `20250213NQCYX` 等配置值 | 兼容旧活动查询 | 不作为当前动作主通道 |
|
||||
|
||||
`query_act_aliases` 是“要查哪些来源”的集合;`action_act_aliases` 是“哪些来源可以
|
||||
@@ -73,8 +73,8 @@
|
||||
| `bindAccount=1` | 已绑定腾讯账号 |
|
||||
| `bindRole=1` | 已选中游戏角色 |
|
||||
| `bindAct=1` | 最终活动绑定已生效,这是唯一 `bound` 信号 |
|
||||
| `bindAct=0 + bindRole=1` | 角色已选中但未确认,是 `pending` |
|
||||
| `needBindAct=1` | 当前活动要求继续执行确认 |
|
||||
| `bindAct=0 + bindRole=1` | 接口观察态是角色已选中但未确认;是否属于本轮扫码仍需 baseline 迁移 |
|
||||
| `needBindAct=1` | 当前活动允许继续绑定;这是长期能力标志,不等于本轮刚扫码 |
|
||||
| `needBindRole=1` | 当前流程仍需要角色选择/角色信息 |
|
||||
| `changeRoleWaitTime` | 换绑倒计时;只有 `bindAct=1` 时才可能是真实冷却 |
|
||||
| `canChangeTime` | 可换绑绝对时间;未确认绑定不能据此拦截 |
|
||||
@@ -87,28 +87,33 @@
|
||||
单个候选按以下顺序解释,详细结果由 `binding_pending_decision()` 返回:
|
||||
|
||||
1. 没有角色名:不可确认;
|
||||
2. 动作 alias 上 `bindAct=0 + needBindAct=1 + roleName`:可确认,原因
|
||||
`existing_actionable_pending`;
|
||||
3. 没有扫码前 baseline:可确认,原因 `first_role_without_baseline`;
|
||||
4. 角色名与 baseline 不同:可确认,原因 `role_changed`;
|
||||
5. 角色名相同,但同 alias 仍返回 `needBindAct=1`:可确认,即使当前
|
||||
`bindAct=1`,原因 `same_alias_after_bound_transition`;
|
||||
6. 动作 alias 上 `bindAct=1 + needBindAct=1 + 同名角色`:可确认;
|
||||
7. 角色名相同且接口不再要求绑定:视为已经绑定,原因 `already_bound`;
|
||||
8. 其他同名角色:视为旧残留,原因 `same_role_stale`。
|
||||
2. 没有扫码前 baseline:不可确认。当前 `bindAct=1` 返回 `already_bound`,
|
||||
其他情况返回 `pending_without_baseline`;
|
||||
3. 角色名与 baseline 不同:可确认,原因 `role_changed`;
|
||||
4. 角色名相同但缺少完整 baseline 快照:不可确认;
|
||||
5. 同 alias 从 `bindAct=1` 变为 `bindAct=0`:可确认,原因
|
||||
`same_alias_after_bound_transition`;
|
||||
6. 同 alias 从 `needBindAct=0` 变为 `needBindAct=1`,且当前 `bindAct=0`:
|
||||
可确认,原因 `same_alias_after_pending_transition`;
|
||||
7. 当前仍是 `bindAct=1`:视为已经绑定,原因 `already_bound`;
|
||||
8. 其他同名角色:视为旧残留。baseline 本身是 pending 时原因
|
||||
`same_role_stale_pending`,否则为 `same_role_stale`。
|
||||
|
||||
规则 2 是 2026-11-21 线上修复:动作 alias 已经存在同名 pending 时,它仍是可执行
|
||||
确认的 pending,不应因为“角色名没变化”一直灰掉确认按钮。
|
||||
2026-11-22 生产历史证明:账号早已 `bind_ok confirmed`,但活动 alias 长期同时返回
|
||||
`bindAct=1 + needBindAct=1`。因此 `needBindAct=1` 不能单独证明本轮扫码,同名角色
|
||||
必须看到扫码前后的真实状态迁移,否则确认按钮会把历史角色误报为新 pending。
|
||||
|
||||
规则 5、6 解决“重新绑定同名角色”:业务不要求每次都必须选择一个不同的角色。
|
||||
只要官方动作 alias 仍要求绑定,同名角色也必须能进入确认流程。
|
||||
二维码预检只建立 baseline,生成二维码后固定进入 `waiting_scan`;只有轮询观察到
|
||||
上述状态迁移或新角色后才进入 `role_ready`。旧任务如果已经是无迁移的
|
||||
`role_ready`,`refresh_binding()` 会记录 `binding_stale_role_ignored` 并自动回到
|
||||
未开始状态,不要求人工改库。
|
||||
|
||||
### 完整流程
|
||||
|
||||
```text
|
||||
查询所有 query_act_aliases
|
||||
-> 找当前 bindAct=1(bound)
|
||||
-> 找动作 alias 上的可确认 pending
|
||||
-> 保存扫码前 baseline,不能把静态 pending 直接当成本轮结果
|
||||
-> 生成二维码
|
||||
-> 持久化 baseline、候选来源、判定原因
|
||||
-> binding_poll 每轮先查 legacy(cjm)
|
||||
@@ -307,12 +312,15 @@ docker compose logs douyu-login | grep '确认前状态'
|
||||
`QYOOB.bindAct=0 + needBindAct=1`。旧逻辑只接受“角色名变化”或“同 alias 从
|
||||
`bindAct=1` 转为 pending”,把已经存在的活动 pending 误判成旧残留。
|
||||
|
||||
修复:动作 alias 已存在同名 pending 时直接视为可确认,原因
|
||||
初次修复:动作 alias 已存在同名 pending 时直接视为可确认,原因
|
||||
`existing_actionable_pending`;二维码预检也会立即收敛为 `role_ready`。
|
||||
|
||||
回归:`tests/test_douyu_binding_state.py`、`tests/test_douyu_account_probe.py`、
|
||||
`tests/test_douyu_task_concurrency.py`。
|
||||
|
||||
> 2026-11-22 更正:该修复把长期静态的 `needBindAct=1` 当成了新扫码结果,已废弃。
|
||||
> 当前规则见上方“pending 判定顺序”。
|
||||
|
||||
### 2026-11-21:扫码成功但轮询超时、确认按钮不稳定
|
||||
|
||||
生产失败任务中大量出现 `role_timeout`,但 `result` 实际已经带回角色,且部分
|
||||
@@ -329,16 +337,29 @@ docker compose logs douyu-login | grep '确认前状态'
|
||||
相同的角色名。旧判定先看 `bindAct=1` 并直接返回 `already_bound`,导致用户重新
|
||||
绑定同名角色时任务一直等待。
|
||||
|
||||
修复:只要动作 alias 仍返回 `needBindAct=1`,同名角色也进入可确认状态;候选选择
|
||||
仍先选真正变化的新角色,再选择同名可确认角色,避免活动 alias 的旧快照压掉
|
||||
`cjm` 上的新角色。
|
||||
初次修复:只要动作 alias 仍返回 `needBindAct=1`,同名角色也进入可确认状态。
|
||||
|
||||
> 2026-11-22 更正:该结论不成立。`needBindAct=1` 在该活动里可以长期存在;同名角色
|
||||
> 必须依赖扫码前后状态迁移。候选选择仍优先真正变化的新角色,但不会再接受静态
|
||||
> 同名 pending。
|
||||
|
||||
### 2026-11-22:历史绑定记录证明静态 pending 会误报
|
||||
|
||||
生产账号 `2212`、`24372` 的 `bind_ok` 历史分别确认于 2026-10-22 和 2026-11-15,
|
||||
但二维码预检仍长期看到同名角色和 `bindAct=1 + needBindAct=1`。旧逻辑把该状态
|
||||
写成 `role_ready`,随后客服页和履约页都显示“待确认角色”,实际用户尚未扫码。
|
||||
|
||||
修复:共享判定器要求 baseline 和状态迁移;二维码预检不再提前推进 `role_ready`;
|
||||
客服页、履约工作台和账号探针统一消费同一判定结果;账号探针仅在活动 alias 明确
|
||||
未绑定、legacy alias 为 `bindRole=1 + bindAct=0` 时保留只读观察到的 pending。
|
||||
|
||||
### 历史固定规则
|
||||
|
||||
- 不要把 `bindRole=1` 当成已绑定;
|
||||
- 不要把未确认时的换绑倒计时当成冷却;
|
||||
- 不要用 `cjm` 的旧角色覆盖活动 alias pending;
|
||||
- 不要要求每次绑定都必须换一个不同的角色,同名重绑是正常流程;
|
||||
- 不要用 `cjm` 的旧角色覆盖活动 alias 当前状态;
|
||||
- 不要要求每次绑定都必须换一个不同的角色,但同名重绑必须有扫码前后状态迁移;
|
||||
- 不要把 `needBindAct=1` 单独当成本轮扫码结果;
|
||||
- 不要在页面层重新实现 `bindAct/needBindAct` 判断;
|
||||
- 不要把原始 `bind_summary` 当业务文案,它只用于排障。
|
||||
|
||||
@@ -350,3 +371,4 @@ docker compose logs douyu-login | grep '确认前状态'
|
||||
| 2026-11-21 | 补充 `storehome` 单账号全量商品资格、`storedetail`/`batchExchangeLimit` 边界和抓包证据入口 |
|
||||
| 2026-11-21 | 补充同名重绑、轮询退避、直接绑定识别和角色接口原始响应留档 |
|
||||
| 2026-11-21 | 按最新 HAR 更新鱼翅余额/充值二维码/支付状态、积分 multipart、到期批次和积分流水协议 |
|
||||
| 2026-11-22 | 修正同名待确认误判:静态 `needBindAct` 不再作为扫码证据,二维码预检统一等待状态迁移 |
|
||||
|
||||
@@ -89,7 +89,7 @@ def test_role_resolver_uses_legacy_pending_role_when_current_is_empty():
|
||||
assert result["source_alias"] == "cjm"
|
||||
|
||||
|
||||
def test_role_resolver_prefers_existing_pending_on_action_alias_same_role():
|
||||
def test_role_resolver_does_not_treat_stale_same_role_as_new_pending():
|
||||
role = "忧郁情潇藏心中"
|
||||
client = RoleClient(
|
||||
{
|
||||
@@ -100,10 +100,9 @@ def test_role_resolver_prefers_existing_pending_on_action_alias_same_role():
|
||||
|
||||
result = resolve_elite_role(client, CONFIG)
|
||||
|
||||
assert result["status"] == ROLE_PENDING
|
||||
assert result["role_name"] == role
|
||||
assert result["source_alias"] == "current-alias"
|
||||
assert result["decision"]["reason"] == "existing_actionable_pending"
|
||||
assert result["status"] == ROLE_UNKNOWN
|
||||
assert result["role_name"] == ""
|
||||
assert result["pending_role_name"] == ""
|
||||
|
||||
|
||||
def test_role_resolver_partial_failure_does_not_claim_unbound():
|
||||
|
||||
@@ -195,7 +195,7 @@ def test_existing_pending_role_is_baseline_not_new_scan_result():
|
||||
)
|
||||
|
||||
|
||||
def test_existing_action_alias_pending_is_confirmable_even_same_role():
|
||||
def test_existing_action_alias_pending_is_stale_without_transition():
|
||||
role = "忧郁情潇藏心中"
|
||||
baseline = _role_candidate(ACT_ALIAS, role, need_bind_act=True)
|
||||
legacy = _role_candidate(LEGACY_ALIAS, role, need_bind_act=False)
|
||||
@@ -209,20 +209,18 @@ def test_existing_action_alias_pending_is_confirmable_even_same_role():
|
||||
baseline_info=baseline,
|
||||
actionable_aliases=[ACT_ALIAS],
|
||||
)
|
||||
selected = picker._pick_bind_info(
|
||||
selected = picker._pick_pending_role_info(
|
||||
[legacy, activity],
|
||||
prefer_aliases=[LEGACY_ALIAS, ACT_ALIAS],
|
||||
baseline_role_name=role,
|
||||
baseline_is_bound_act=False,
|
||||
baseline_info=baseline,
|
||||
prefer_pending=True,
|
||||
prefer_aliases=[LEGACY_ALIAS, ACT_ALIAS],
|
||||
actionable_aliases=[ACT_ALIAS],
|
||||
)
|
||||
|
||||
assert decision["confirmable"] is True
|
||||
assert decision["reason"] == "existing_actionable_pending"
|
||||
assert selected is not None
|
||||
assert selected["act_alias"] == ACT_ALIAS
|
||||
assert decision["confirmable"] is False
|
||||
assert decision["reason"] == "same_role_stale_pending"
|
||||
assert selected is None
|
||||
|
||||
|
||||
def test_same_role_after_activity_bind_transition_is_pending():
|
||||
@@ -238,7 +236,7 @@ def test_same_role_after_activity_bind_transition_is_pending():
|
||||
)
|
||||
|
||||
|
||||
def test_same_bound_role_with_need_bind_act_is_confirmable():
|
||||
def test_same_bound_role_with_need_bind_act_is_not_confirmable_without_transition():
|
||||
role = "少和我较劲"
|
||||
baseline = _role_candidate(
|
||||
ACT_ALIAS,
|
||||
@@ -261,11 +259,11 @@ def test_same_bound_role_with_need_bind_act_is_confirmable():
|
||||
actionable_aliases=[ACT_ALIAS],
|
||||
)
|
||||
|
||||
assert decision["confirmable"] is True
|
||||
assert decision["reason"] == "same_alias_after_bound_transition"
|
||||
assert decision["confirmable"] is False
|
||||
assert decision["reason"] == "already_bound"
|
||||
|
||||
|
||||
def test_pending_candidate_picker_uses_action_alias_same_role():
|
||||
def test_pending_candidate_picker_ignores_unchanged_same_role():
|
||||
old_role = "少和我较劲"
|
||||
baseline = _role_candidate(ACT_ALIAS, old_role, bound_act=True)
|
||||
legacy = _role_candidate(LEGACY_ALIAS, old_role, bound_act=False)
|
||||
@@ -279,6 +277,23 @@ def test_pending_candidate_picker_uses_action_alias_same_role():
|
||||
baseline_info=baseline,
|
||||
)
|
||||
|
||||
assert selected is None
|
||||
|
||||
|
||||
def test_pending_candidate_picker_accepts_same_alias_state_transition():
|
||||
role = "少和我较劲"
|
||||
baseline = _role_candidate(ACT_ALIAS, role, bound_act=True, need_bind_act=False)
|
||||
after_scan = _role_candidate(ACT_ALIAS, role, bound_act=False, need_bind_act=True)
|
||||
|
||||
selected = _RolePicker()._pick_pending_role_info(
|
||||
[after_scan],
|
||||
prefer_aliases=[ACT_ALIAS],
|
||||
baseline_role_name=role,
|
||||
baseline_is_bound_act=True,
|
||||
baseline_info=baseline,
|
||||
actionable_aliases=[ACT_ALIAS],
|
||||
)
|
||||
|
||||
assert selected is not None
|
||||
assert selected["act_alias"] == ACT_ALIAS
|
||||
|
||||
|
||||
@@ -700,8 +700,16 @@ def test_deadline_poll_still_checks_role_once_before_timeout(db, monkeypatch):
|
||||
task.result = {
|
||||
"url": "https://example.test/qr",
|
||||
"query_act_aliases": ["bind-act"],
|
||||
"baseline_role_name": "",
|
||||
"baseline_is_bound_act": False,
|
||||
"baseline_role_name": "old-role",
|
||||
"baseline_is_bound_act": True,
|
||||
"before_bind_info": {
|
||||
"act_alias": "bind-act",
|
||||
"role_name": "old-role",
|
||||
"is_bound_act": True,
|
||||
"is_bound_role": True,
|
||||
"need_bind_act": True,
|
||||
"need_bind_role": True,
|
||||
},
|
||||
"bind_polling": True,
|
||||
}
|
||||
db.commit()
|
||||
@@ -711,7 +719,14 @@ def test_deadline_poll_still_checks_role_once_before_timeout(db, monkeypatch):
|
||||
"get_bind_qr",
|
||||
close_db=False,
|
||||
)
|
||||
info = {"act_alias": "bind-act", "role_name": "new-role"}
|
||||
info = {
|
||||
"act_alias": "bind-act",
|
||||
"role_name": "new-role",
|
||||
"is_bound_act": False,
|
||||
"is_bound_role": True,
|
||||
"need_bind_act": True,
|
||||
"need_bind_role": True,
|
||||
}
|
||||
snapshot = {
|
||||
"role_name": "new-role",
|
||||
"area_name": "微信",
|
||||
@@ -732,7 +747,6 @@ def test_deadline_poll_still_checks_role_once_before_timeout(db, monkeypatch):
|
||||
monkeypatch.setattr(runner, "_fetch_bind_info_candidates", lambda *_args: [info])
|
||||
monkeypatch.setattr(runner, "_pick_bind_info", lambda *_args, **_kwargs: info)
|
||||
monkeypatch.setattr(runner, "_bind_snapshot", lambda _info: snapshot)
|
||||
monkeypatch.setattr(runner, "_is_pending_role", lambda *_args, **_kwargs: True)
|
||||
monkeypatch.setattr(
|
||||
runner,
|
||||
"_format_bind_summary",
|
||||
@@ -751,7 +765,7 @@ def test_deadline_poll_still_checks_role_once_before_timeout(db, monkeypatch):
|
||||
assert task.result["bind_ready_for_confirm"] is True
|
||||
|
||||
|
||||
def test_qr_preflight_accepts_existing_action_alias_pending_same_role(
|
||||
def test_qr_preflight_treats_existing_action_alias_pending_as_baseline(
|
||||
db, monkeypatch
|
||||
):
|
||||
_, account, task = _fixtures(db, status="running")
|
||||
@@ -807,18 +821,23 @@ def test_qr_preflight_accepts_existing_action_alias_pending_same_role(
|
||||
)
|
||||
|
||||
db.refresh(task)
|
||||
assert task.status == "success"
|
||||
assert task.status == "running"
|
||||
assert task.result["url"] == "https://example.test/qr"
|
||||
assert task.result["pending_role_name"] == role
|
||||
assert task.result["bind_ready_for_confirm"] is True
|
||||
assert task.result["bind_decision"]["alias"] == "20260120QYOOB"
|
||||
assert task.result["bind_decision"]["reason"] == "existing_actionable_pending"
|
||||
assert task.result["bind_phase"] == "waiting_scan"
|
||||
assert task.result["bind_ready_for_confirm"] is False
|
||||
assert "pending_role_name" not in task.result
|
||||
action_decision = next(
|
||||
item
|
||||
for item in task.result["bind_candidate_decisions"]
|
||||
if item["alias"] == "20260120QYOOB"
|
||||
)
|
||||
assert action_decision["reason"] == "same_role_stale_pending"
|
||||
|
||||
|
||||
def test_qr_preflight_accepts_same_bound_role_that_still_needs_binding(
|
||||
def test_qr_preflight_keeps_bound_role_waiting_for_new_scan_transition(
|
||||
db, monkeypatch
|
||||
):
|
||||
"""用户重新绑定同名角色时,bindAct=1 不应阻断可确认状态。"""
|
||||
"""历史 bindAct=1 + needBindAct=1 不能直接进入待确认。"""
|
||||
_, account, task = _fixtures(db, status="running")
|
||||
role = "你哥奢皇"
|
||||
legacy = {
|
||||
@@ -873,15 +892,17 @@ def test_qr_preflight_accepts_same_bound_role_that_still_needs_binding(
|
||||
)
|
||||
|
||||
db.refresh(task)
|
||||
assert task.status == "success"
|
||||
assert task.status == "running"
|
||||
assert task.result["url"] == "https://example.test/qr"
|
||||
assert task.result["pending_role_name"] == role
|
||||
assert task.result["bind_ready_for_confirm"] is True
|
||||
assert task.result["bind_decision"]["alias"] == "20260120QYOOB"
|
||||
assert (
|
||||
task.result["bind_decision"]["reason"]
|
||||
== "same_alias_after_bound_transition"
|
||||
assert task.result["bind_phase"] == "waiting_scan"
|
||||
assert task.result["bind_ready_for_confirm"] is False
|
||||
assert "pending_role_name" not in task.result
|
||||
action_decision = next(
|
||||
item
|
||||
for item in task.result["bind_candidate_decisions"]
|
||||
if item["alias"] == "20260120QYOOB"
|
||||
)
|
||||
assert action_decision["reason"] == "already_bound"
|
||||
|
||||
|
||||
def test_binding_poll_accepts_existing_action_alias_pending_same_role(
|
||||
@@ -917,8 +938,8 @@ def test_binding_poll_accepts_existing_action_alias_pending_same_role(
|
||||
"url": "https://example.test/qr",
|
||||
"query_act_aliases": ["cjm", "20260120QYOOB"],
|
||||
"baseline_role_name": role,
|
||||
"baseline_is_bound_act": False,
|
||||
"before_bind_info": activity,
|
||||
"baseline_is_bound_act": True,
|
||||
"before_bind_info": {**activity, "is_bound_act": True},
|
||||
"bind_polling": True,
|
||||
}
|
||||
db.commit()
|
||||
@@ -952,13 +973,13 @@ def test_binding_poll_accepts_existing_action_alias_pending_same_role(
|
||||
assert task.result["role_name"] == role
|
||||
assert task.result["bind_ready_for_confirm"] is True
|
||||
assert task.result["bind_decision"]["alias"] == "20260120QYOOB"
|
||||
assert task.result["bind_decision"]["reason"] == "existing_actionable_pending"
|
||||
assert task.result["bind_decision"]["reason"] == "same_alias_after_bound_transition"
|
||||
assert {
|
||||
row["alias"]: row["reason"]
|
||||
for row in task.result["bind_candidate_decisions"]
|
||||
} == {
|
||||
"cjm": "same_role_stale",
|
||||
"20260120QYOOB": "existing_actionable_pending",
|
||||
"20260120QYOOB": "same_alias_after_bound_transition",
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -2193,8 +2193,17 @@ class TestBindingAndCompletion(_Base):
|
||||
status="success",
|
||||
result={
|
||||
"url": "https://example.com/qr",
|
||||
"act_alias": "20260120QYOOB",
|
||||
"role_name": "测试角色",
|
||||
"need_bind_act": True,
|
||||
"baseline_role_name": "测试角色",
|
||||
"baseline_is_bound_act": True,
|
||||
"before_bind_info": {
|
||||
"act_alias": "20260120QYOOB",
|
||||
"role_name": "测试角色",
|
||||
"is_bound_act": True,
|
||||
"need_bind_act": True,
|
||||
},
|
||||
"bind_ready_for_confirm": True,
|
||||
},
|
||||
created_by=self.admin_id,
|
||||
|
||||
@@ -296,8 +296,8 @@ def binding_pending_decision(
|
||||
"""解释一个绑定候选是否可进入确认阶段。
|
||||
|
||||
角色名不是唯一事实,也不能要求每次都必须换新角色。用户重新绑定同名角色
|
||||
时,判断还要对比扫码前后的活动绑定状态。活动 alias 只要仍要求
|
||||
``needBindAct=1``,即使当前 ``bindAct=1``,同名角色也可以进入确认流程。
|
||||
时,必须观察到二维码生成后的状态变化。``needBindAct=1`` 在本活动里是
|
||||
持续存在的“仍允许绑定”标志,不能单独证明存在新的扫码结果。
|
||||
"""
|
||||
result: dict[str, Any] = {
|
||||
"alias": str((info or {}).get("act_alias") or ""),
|
||||
@@ -309,6 +309,7 @@ def binding_pending_decision(
|
||||
"baseline_alias": str((baseline_info or {}).get("act_alias") or ""),
|
||||
"baseline_role_name": str(baseline_role_name or "").strip(),
|
||||
"baseline_is_bound_act": bool(baseline_is_bound_act),
|
||||
"baseline_need_bind_act": False,
|
||||
"baseline_is_pending": False,
|
||||
"same_alias": False,
|
||||
"role_changed": False,
|
||||
@@ -340,15 +341,13 @@ def binding_pending_decision(
|
||||
return result
|
||||
baseline = baseline_role_name.strip()
|
||||
if not baseline:
|
||||
if result["actionable_alias"] and snapshot["need_bind_act"]:
|
||||
result.update(
|
||||
{
|
||||
"confirmable": True,
|
||||
"reason": "existing_actionable_pending",
|
||||
}
|
||||
)
|
||||
return result
|
||||
result.update({"confirmable": True, "reason": "first_role_without_baseline"})
|
||||
# 2026-11-22:没有 baseline 无法证明这是本轮扫码产生的新角色。
|
||||
# 历史库中 bound + needBindAct 会长期并存,不能再次冒充 pending。
|
||||
result["reason"] = (
|
||||
"already_bound"
|
||||
if snapshot["is_bound_act"]
|
||||
else "pending_without_baseline"
|
||||
)
|
||||
return result
|
||||
if role_name.casefold() != baseline.casefold():
|
||||
result.update({"confirmable": True, "reason": "role_changed"})
|
||||
@@ -361,15 +360,16 @@ def binding_pending_decision(
|
||||
return result
|
||||
|
||||
baseline_snapshot = binding_snapshot(baseline_info)
|
||||
result["baseline_need_bind_act"] = bool(
|
||||
baseline_snapshot["need_bind_act"]
|
||||
)
|
||||
result["baseline_is_pending"] = bool(
|
||||
baseline_snapshot["role_name"]
|
||||
and not baseline_snapshot["is_bound_act"]
|
||||
and baseline_snapshot["need_bind_act"]
|
||||
)
|
||||
if (
|
||||
result["same_alias"]
|
||||
and baseline_snapshot["is_bound_act"]
|
||||
and snapshot["need_bind_act"]
|
||||
if result["same_alias"] and (
|
||||
baseline_snapshot["is_bound_act"] and not snapshot["is_bound_act"]
|
||||
):
|
||||
result.update(
|
||||
{
|
||||
@@ -378,18 +378,27 @@ def binding_pending_decision(
|
||||
}
|
||||
)
|
||||
return result
|
||||
if result["actionable_alias"] and snapshot["need_bind_act"]:
|
||||
if (
|
||||
result["same_alias"]
|
||||
and not snapshot["is_bound_act"]
|
||||
and snapshot["need_bind_act"]
|
||||
and not baseline_snapshot["need_bind_act"]
|
||||
):
|
||||
result.update(
|
||||
{
|
||||
"confirmable": True,
|
||||
"reason": "existing_actionable_pending",
|
||||
"reason": "same_alias_after_pending_transition",
|
||||
}
|
||||
)
|
||||
return result
|
||||
if snapshot["is_bound_act"]:
|
||||
result["reason"] = "already_bound"
|
||||
return result
|
||||
result["reason"] = "same_role_stale"
|
||||
result["reason"] = (
|
||||
"same_role_stale_pending"
|
||||
if result["baseline_is_pending"] and snapshot["need_bind_act"]
|
||||
else "same_role_stale"
|
||||
)
|
||||
return result
|
||||
|
||||
|
||||
|
||||
@@ -344,6 +344,41 @@ def resolve_elite_role(
|
||||
),
|
||||
bind_infos=candidates_info,
|
||||
)
|
||||
if pending_info is None:
|
||||
# 2026-11-22:二维码流程没有扫码前基线时不能把同名活动态当 pending;
|
||||
# 但账号探针是只读观察,若活动 alias 明确未绑定、legacy alias 已返回
|
||||
# bindRole=1/bindAct=0,则仍可确认存在一个“已选角、未生效”的待确认角色。
|
||||
action_unbound = any(
|
||||
str(info.get("act_alias") or "") in action_aliases
|
||||
and derive_from_bind_info(info) == BIND_UNBOUND
|
||||
for info in candidates_info
|
||||
)
|
||||
if action_unbound:
|
||||
for alias in ordered_aliases:
|
||||
if alias in action_aliases:
|
||||
continue
|
||||
pending_info = next(
|
||||
(
|
||||
info
|
||||
for info in candidates_info
|
||||
if str(info.get("act_alias") or "") == alias
|
||||
and derive_from_bind_info(info) == BIND_PENDING
|
||||
and str(info.get("role_name") or "").strip()
|
||||
),
|
||||
None,
|
||||
)
|
||||
if pending_info is not None:
|
||||
pending_decision = binding_pending_decision(
|
||||
pending_info,
|
||||
actionable_aliases=action_aliases,
|
||||
)
|
||||
pending_decision.update(
|
||||
{
|
||||
"confirmable": True,
|
||||
"reason": "legacy_pending_after_action_unbound",
|
||||
}
|
||||
)
|
||||
break
|
||||
if pending_info is not None:
|
||||
result = _role_result(
|
||||
status=ROLE_PENDING,
|
||||
|
||||
@@ -178,9 +178,9 @@ class BindMixin:
|
||||
规则:
|
||||
1. 必须有角色名
|
||||
2. 角色名相对 baseline 变化,说明出现了新角色
|
||||
3. 角色名相同但活动状态从已绑定转为 needBindAct,说明用户本次
|
||||
扫码选择了同名角色,仍算 pending
|
||||
4. 无 baseline 且有角色,视为首次绑定的待确认角色
|
||||
3. 角色名相同但观察到绑定状态迁移,说明用户本次扫码选择了
|
||||
同名角色,仍算 pending
|
||||
4. 没有扫码前基线时不能把历史 pending 当成本次扫码结果
|
||||
"""
|
||||
return is_pending_binding_role(
|
||||
bind_info,
|
||||
@@ -1386,42 +1386,9 @@ class BindMixin:
|
||||
)
|
||||
),
|
||||
}
|
||||
if pending_decision["confirmable"]:
|
||||
pending_snapshot = self._bind_snapshot(pending_before)
|
||||
pending_role = str(pending_snapshot["role_name"] or "")
|
||||
pending_alias = str(pending_before.get("act_alias") or "")
|
||||
pending_summary = (
|
||||
f"act={pending_alias or '-'} "
|
||||
f"{self._format_bind_summary(pending_before, pending=True)}"
|
||||
)
|
||||
result.update(
|
||||
{
|
||||
**pending_snapshot,
|
||||
"act_alias": pending_alias,
|
||||
"query_act_alias": pending_alias,
|
||||
"pending_role_name": pending_role,
|
||||
"bind_ready_for_confirm": True,
|
||||
"bind_confirmed": False,
|
||||
"bind_phase": "role_ready",
|
||||
"bind_polling": False,
|
||||
"bind_summary": pending_summary,
|
||||
}
|
||||
)
|
||||
account.updated_at = qr_generated_at
|
||||
self._push_log(
|
||||
"success",
|
||||
"生成二维码前已发现活动 alias 待确认角色 "
|
||||
f"act={pending_alias or '-'} role={pending_role or '-'} "
|
||||
f"reason={pending_decision['reason']}",
|
||||
)
|
||||
self._mark_task(
|
||||
db,
|
||||
task,
|
||||
"success",
|
||||
f"已识别现有待确认角色: {pending_role},待确认绑定",
|
||||
result,
|
||||
)
|
||||
return
|
||||
# 2026-11-22:二维码生成前的 pending 只能作为 baseline,不能直接
|
||||
# 推进 role_ready。官方活动 alias 会长期保留 needBindAct=1,必须在
|
||||
# 二维码生成后观察到绑定状态变化,才能证明这是本轮扫码结果。
|
||||
account.updated_at = datetime.now(UTC)
|
||||
task.queue_lane = "binding_poll"
|
||||
task.next_run_at = qr_generated_at + timedelta(
|
||||
|
||||
Reference in New Issue
Block a user