fix(douyu): 修正扫码前待确认角色误判
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user