修复(履约绑定): 修复候选快照丢失与全链路绑定校验一致性
This commit is contained in:
@@ -673,6 +673,87 @@ def resolve_binding_candidates(
|
||||
}
|
||||
|
||||
|
||||
def hydrate_bind_candidates_from_result(
|
||||
result: dict[str, Any] | None,
|
||||
) -> list[dict[str, Any]]:
|
||||
"""补全历史结果 ``bind_candidates`` 中缺失的状态标记和区服字段。"""
|
||||
if not isinstance(result, dict):
|
||||
return []
|
||||
raw_candidates = [
|
||||
dict(item)
|
||||
for item in (result.get("bind_candidates") or [])
|
||||
if isinstance(item, dict)
|
||||
]
|
||||
if not raw_candidates:
|
||||
return []
|
||||
|
||||
decisions_by_alias: dict[str, dict[str, Any]] = {}
|
||||
for decision in result.get("bind_candidate_decisions") or []:
|
||||
if not isinstance(decision, dict):
|
||||
continue
|
||||
alias = str(decision.get("alias") or decision.get("act_alias") or "").strip()
|
||||
if alias and alias not in decisions_by_alias:
|
||||
decisions_by_alias[alias] = decision
|
||||
|
||||
bind_info = result.get("bind_info")
|
||||
bind_info_dict = bind_info if isinstance(bind_info, dict) else {}
|
||||
bind_info_alias = str(
|
||||
bind_info_dict.get("act_alias") or result.get("act_alias") or ""
|
||||
).strip()
|
||||
|
||||
hydrated: list[dict[str, Any]] = []
|
||||
for candidate in raw_candidates:
|
||||
alias = str(candidate.get("act_alias") or candidate.get("alias") or "").strip()
|
||||
role_name = str(candidate.get("role_name") or "").strip()
|
||||
|
||||
decision = decisions_by_alias.get(alias)
|
||||
if decision is not None and (
|
||||
not role_name
|
||||
or not str(decision.get("role_name") or "").strip()
|
||||
or str(decision.get("role_name") or "").strip().casefold()
|
||||
== role_name.casefold()
|
||||
):
|
||||
for key in (
|
||||
"is_bound_act",
|
||||
"is_bound_role",
|
||||
"need_bind_act",
|
||||
"need_bind_role",
|
||||
"actionable_alias",
|
||||
"confirmable",
|
||||
"reason",
|
||||
):
|
||||
if key not in candidate and key in decision:
|
||||
candidate[key] = decision[key]
|
||||
|
||||
if (
|
||||
bind_info_dict
|
||||
and alias
|
||||
and alias == bind_info_alias
|
||||
and (
|
||||
not role_name
|
||||
or not str(bind_info_dict.get("role_name") or "").strip()
|
||||
or str(bind_info_dict.get("role_name") or "").strip().casefold()
|
||||
== role_name.casefold()
|
||||
)
|
||||
):
|
||||
snap = binding_snapshot(bind_info_dict)
|
||||
for key in ("area_name", "plat_name", "partition_name"):
|
||||
if not candidate.get(key) and snap.get(key):
|
||||
candidate[key] = snap[key]
|
||||
for key in (
|
||||
"is_bound_act",
|
||||
"is_bound_role",
|
||||
"need_bind_act",
|
||||
"need_bind_role",
|
||||
"is_bound_account",
|
||||
):
|
||||
if key not in candidate and key in snap:
|
||||
candidate[key] = snap[key]
|
||||
|
||||
hydrated.append(candidate)
|
||||
return hydrated
|
||||
|
||||
|
||||
def pending_binding_role_from_result(result: dict[str, Any] | None) -> str:
|
||||
"""从执行器结果中提取“本次扫码产生的待确认角色”。
|
||||
|
||||
@@ -702,11 +783,7 @@ def pending_binding_role_from_result(result: dict[str, Any] | None) -> str:
|
||||
require_expected_role = bool(result.get("expected_role_required"))
|
||||
if require_expected_role and not expected_role_name:
|
||||
return ""
|
||||
raw_candidates = [
|
||||
dict(item)
|
||||
for item in (result.get("bind_candidates") or [])
|
||||
if isinstance(item, dict)
|
||||
]
|
||||
raw_candidates = hydrate_bind_candidates_from_result(result)
|
||||
if raw_candidates:
|
||||
resolution = resolve_binding_candidates(
|
||||
raw_candidates,
|
||||
|
||||
Reference in New Issue
Block a user