test_policy_replay_data.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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. # M3: mock judgment scores relevance 60 + zero platform_heat = 60 → review band.
  21. assert replay["matched_threshold"] == "60<=score<=69"
  22. assert replay["effect_mapping_id"] == "map_keep_for_review_pending"
  23. assert replay["matched_scoring_rules"] == ["score_relevance_high"]
  24. policy_run = runtime.policy_runs[0]
  25. assert policy_run["policy_bundle_hash"] == state["policy_bundle"]["policy_bundle_hash"]
  26. assert policy_run["raw_payload"]["dispatch"]["dispatch_id"] == "dispatch_content"
  27. assert policy_run["raw_payload"]["runtime_status_contract"]["query_effect_status"] == [
  28. "success",
  29. "pending",
  30. "failed",
  31. "rule_blocked",
  32. ]
  33. assert policy_run["decision_summary"]["effect_status_counts"]