|
|
@@ -67,6 +67,15 @@ EFFECT_STATUSES = {"success", "pending", "failed", "rule_blocked"}
|
|
|
WALK_STATUSES = {"success", "pending", "failed", "skipped", "rule_blocked"}
|
|
|
V4_SCORECARD_SCHEMA_VERSION = "v4_scorecard.v1"
|
|
|
V4_GEMINI_QUERY_RELEVANCE_SCHEMA_VERSION = "v4_gemini_query_relevance.v1"
|
|
|
+V4_SCORE_THRESHOLD_FALLBACK = {
|
|
|
+ "pool_total": 70,
|
|
|
+ "pool_query": 70,
|
|
|
+ "review_total": 55,
|
|
|
+ "review_query": 55,
|
|
|
+ "walk_query": 70,
|
|
|
+ "walk_platform": 65,
|
|
|
+ "walk_total": 70,
|
|
|
+}
|
|
|
V4_LEGACY_FIELD_BLOCKLIST = {
|
|
|
"fit_senior_50plus",
|
|
|
"fit_confidence",
|
|
|
@@ -898,6 +907,22 @@ def _v4_score_values(decision: dict[str, Any]) -> tuple[Any, Any, Any]:
|
|
|
)
|
|
|
|
|
|
|
|
|
+def _v4_score_thresholds(decision: dict[str, Any]) -> dict[str, Any]:
|
|
|
+ scorecard = decision.get("scorecard") or {}
|
|
|
+ thresholds = scorecard.get("score_thresholds")
|
|
|
+ if not isinstance(thresholds, dict):
|
|
|
+ return dict(V4_SCORE_THRESHOLD_FALLBACK)
|
|
|
+ return {**V4_SCORE_THRESHOLD_FALLBACK, **thresholds}
|
|
|
+
|
|
|
+
|
|
|
+def _v4_walk_threshold_message(thresholds: dict[str, Any]) -> str:
|
|
|
+ return (
|
|
|
+ f"query>={thresholds['walk_query']}/"
|
|
|
+ f"platform>={thresholds['walk_platform']}/"
|
|
|
+ f"score>={thresholds['walk_total']}"
|
|
|
+ )
|
|
|
+
|
|
|
+
|
|
|
def _check_v4_score_contract(data: dict[str, Any], findings: list[dict[str, Any]]) -> None:
|
|
|
for decision in data.get("rule_decisions.jsonl", []):
|
|
|
if not _is_v4_contract_record(decision):
|
|
|
@@ -974,19 +999,20 @@ def _check_v4_walk_gate_contract(data: dict[str, Any], findings: list[dict[str,
|
|
|
)
|
|
|
continue
|
|
|
query_score, platform_score, total_score = _v4_score_values(decision)
|
|
|
+ thresholds = _v4_score_thresholds(decision)
|
|
|
expected_allow_walk = (
|
|
|
_is_number(query_score)
|
|
|
and _is_number(platform_score)
|
|
|
and _is_number(total_score)
|
|
|
- and query_score >= 70
|
|
|
- and platform_score >= 65
|
|
|
- and total_score >= 70
|
|
|
+ and query_score >= thresholds["walk_query"]
|
|
|
+ and platform_score >= thresholds["walk_platform"]
|
|
|
+ and total_score >= thresholds["walk_total"]
|
|
|
)
|
|
|
if replay_data["allow_walk"] != expected_allow_walk:
|
|
|
_fail(
|
|
|
findings,
|
|
|
"v4_allow_walk_threshold_mismatch",
|
|
|
- f"decision {decision.get('decision_id')} allow_walk does not match query>=70/platform>=65/score>=70",
|
|
|
+ f"decision {decision.get('decision_id')} allow_walk does not match {_v4_walk_threshold_message(thresholds)}",
|
|
|
)
|
|
|
|
|
|
|
|
|
@@ -1218,14 +1244,20 @@ def _check_v4_action_thresholds(data: dict[str, Any], findings: list[dict[str, A
|
|
|
if not (_is_number(query_score) and _is_number(total_score)):
|
|
|
continue
|
|
|
action = decision.get("decision_action")
|
|
|
+ thresholds = _v4_score_thresholds(decision)
|
|
|
if action == "ADD_TO_CONTENT_POOL":
|
|
|
- ok = query_score >= 70 and total_score >= 70
|
|
|
+ ok = query_score >= thresholds["pool_query"] and total_score >= thresholds["pool_total"]
|
|
|
elif action == "KEEP_CONTENT_FOR_REVIEW":
|
|
|
- ok = query_score >= 55 and total_score >= 55 and not (
|
|
|
- query_score >= 70 and total_score >= 70
|
|
|
+ ok = (
|
|
|
+ query_score >= thresholds["review_query"]
|
|
|
+ and total_score >= thresholds["review_total"]
|
|
|
+ and not (
|
|
|
+ query_score >= thresholds["pool_query"]
|
|
|
+ and total_score >= thresholds["pool_total"]
|
|
|
+ )
|
|
|
)
|
|
|
elif action == "REJECT_CONTENT":
|
|
|
- ok = query_score < 55 or total_score < 55
|
|
|
+ ok = query_score < thresholds["review_query"] or total_score < thresholds["review_total"]
|
|
|
else:
|
|
|
continue
|
|
|
if not ok:
|