fix: FR-4 payload 上下文补组装/种子名单唯一命中/规则流水升序等(B4 评审 P1-1、P2-2~5、P3×7)

This commit is contained in:
2026-09-06 17:40:13 +08:00
parent e8e5f7e981
commit 03f8b63780
10 changed files with 153 additions and 16 deletions
+27
View File
@@ -236,6 +236,33 @@ def test_aml_and_event_rule_both_fire(env):
assert len(pub.messages) == 2
(_, aml_payload), = [m for m in pub.messages if m[1]["alert_type"] == "aml"]
assert "compliance" in aml_payload["notify_role"]
# FR-4 payload 完整性(B4 评审 P1-1):客户上下文 = L0 摘要 + 近 30 天统计
ev_alert = next(
a for a in (repo.get_alert(aid) for aid in result["alert_ids"])
if a["alert_type"] == "large_amount"
)
ctx = ev_alert["payload"]["customer_context"]
assert ctx["l0"]["display_name"] == "李四" and ctx["l0"]["age"] == 35
assert ctx["trades_30d"]["count"] >= 1
def test_second_trade_same_day_appends_to_same_alert(env):
"""B4 评审 P2-3:同日第二笔 → 追加同一事件单,triggered_rules/risk_score/L3 联动。"""
core, repo, _, engine = env
with engine.begin() as conn:
_seed_trade(conn, "T1", "600000")
_seed_trade(conn, "T2", "200000", at=datetime(2026, 9, 6, 14, 1, 0))
r1 = process_trade_event(_trade("T1", "600000"), core_ro=core, risk_repo=repo)
r2 = process_trade_event(
_trade("T2", "200000", at=datetime(2026, 9, 6, 14, 1, 0)), core_ro=core, risk_repo=repo
)
assert r2["alert_ids"] == [r1["alert_ids"][0]] # 同日仅一张事件类单
alert = repo.get_alert(r1["alert_ids"][0])
assert len(alert["payload"]["events"]) == 2
assert alert["triggered_rules"] == ["RISK-001", "RISK-002"] # T2 仅命中累计,追加合并
assert alert["risk_score"] == 70 # 取 max
assert _counts(engine, "audit_log", "decision='alert_appended'") == 1
assert repo.get_l3("C1")["last_alert_id"] == alert["alert_id"] # L3 联动最新
def test_probe_window_uses_trade_time_not_wall_clock(env):