test_policy_replay_data.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. from __future__ import annotations
  2. from content_agent.run_service import RunService
  3. from content_agent.schemas import RunStartRequest
  4. from tests.test_p0d_p0g import _SpyRuntimeStore
  5. from tests.p1_helpers import FakeQueryVariantClient, REAL_SOURCE_FIXTURE
  6. def test_rule_decisions_and_policy_run_record_include_replay_metadata(tmp_path):
  7. runtime = _SpyRuntimeStore(tmp_path / "runtime")
  8. service = RunService(
  9. runtime=runtime,
  10. query_variant_client=FakeQueryVariantClient(),
  11. )
  12. state = service.start_run(
  13. RunStartRequest(platform_mode="mock", source=str(REAL_SOURCE_FIXTURE))
  14. )
  15. decision = service.read_jsonl(state["run_id"], "rule_decisions.jsonl")[0]
  16. replay = decision["decision_replay_data"]
  17. assert replay["policy_bundle_hash"] == state["policy_bundle"]["policy_bundle_hash"]
  18. assert replay["dispatch_id"] == "dispatch_content"
  19. assert replay["rule_pack_id"] == "douyin_content_discovery_rule_pack_v1"
  20. assert replay["strategy_version"] == "V4"
  21. # M11 re-baseline:mock 首条(总分 55.67)由"淘汰"升为"复看(pending)"→ effect_mapping 改 keep。
  22. assert replay["effect_mapping_id"] == "map_keep_for_review_pending"
  23. assert replay["allow_walk"] is False
  24. assert replay["walk_gate_snapshot"]["query_relevance_score"] == 80
  25. policy_run = runtime.policy_runs[0]
  26. assert policy_run["policy_bundle_hash"] == state["policy_bundle"]["policy_bundle_hash"]
  27. assert policy_run["raw_payload"]["dispatch"]["dispatch_id"] == "dispatch_content"
  28. assert policy_run["raw_payload"]["runtime_status_contract"]["query_effect_status"] == [
  29. "success",
  30. "pending",
  31. "failed",
  32. "rule_blocked",
  33. ]
  34. assert policy_run["decision_summary"]["effect_status_counts"]