test_walk_engine_pagination.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. from content_agent.business_modules.walk_engine import run_bounded_walk
  2. from tests.p6_walk_helpers import FakeWalkPlatformClient, build_initial_walk_context
  3. def test_walk_engine_pagination_uses_explicit_cursor(tmp_path):
  4. context = build_initial_walk_context(tmp_path)
  5. # M3: mock judgment scores 60 (review/pending); pagination requires a pooled
  6. # success query, so promote the seed decision to pool to exercise paging.
  7. _override_decisions(context, "ADD_TO_CONTENT_POOL", "success")
  8. client = FakeWalkPlatformClient()
  9. result = run_bounded_walk(platform_client=client, **context)
  10. page_calls = [
  11. call for call in client.search_calls
  12. if call.get("search_query_generation_method") == "query_next_page"
  13. ]
  14. assert page_calls[0]["page_cursor"] == "10"
  15. assert any(row["walk_action"] == "fetch_next_page" for row in result["walk_actions"])
  16. def test_walk_engine_pagination_skips_without_cursor(tmp_path):
  17. context = build_initial_walk_context(tmp_path)
  18. context["discovered_content_items"][0]["next_cursor"] = ""
  19. client = FakeWalkPlatformClient()
  20. run_bounded_walk(platform_client=client, **context)
  21. assert not [
  22. call for call in client.search_calls
  23. if call.get("search_query_generation_method") == "query_next_page"
  24. ]
  25. def _override_decisions(context, action, effect_status):
  26. for decision in context["rule_decisions"]:
  27. decision["decision_action"] = action
  28. decision["search_query_effect_status"] = effect_status
  29. def test_pagination_requires_success_effect_status(tmp_path):
  30. context = build_initial_walk_context(tmp_path)
  31. _override_decisions(context, "KEEP_CONTENT_FOR_REVIEW", "pending")
  32. client = FakeWalkPlatformClient()
  33. result = run_bounded_walk(platform_client=client, **context)
  34. assert not [
  35. call for call in client.search_calls
  36. if call.get("search_query_generation_method") == "query_next_page"
  37. ]
  38. assert not [row for row in result["walk_actions"] if row["edge_id"] == "query_next_page"]
  39. def test_rule_blocked_query_does_not_page_even_with_cursor(tmp_path):
  40. context = build_initial_walk_context(tmp_path)
  41. _override_decisions(context, "REJECT_CONTENT", "rule_blocked")
  42. assert context["discovered_content_items"][0]["has_more"]
  43. client = FakeWalkPlatformClient()
  44. result = run_bounded_walk(platform_client=client, **context)
  45. assert not [
  46. call for call in client.search_calls
  47. if call.get("search_query_generation_method") == "query_next_page"
  48. ]
  49. assert not [row for row in result["walk_actions"] if row["edge_id"] == "query_next_page"]
  50. def test_missing_decision_does_not_page(tmp_path):
  51. context = build_initial_walk_context(tmp_path)
  52. context["rule_decisions"] = []
  53. client = FakeWalkPlatformClient()
  54. result = run_bounded_walk(platform_client=client, **context)
  55. assert not [
  56. call for call in client.search_calls
  57. if call.get("search_query_generation_method") == "query_next_page"
  58. ]
  59. assert not [row for row in result["walk_actions"] if row["edge_id"] == "query_next_page"]
  60. def test_success_query_with_cursor_pages_once(tmp_path):
  61. context = build_initial_walk_context(tmp_path)
  62. # M3: mock judgment now lands in review/pending; pagination requires a pooled
  63. # success query, so promote the seed decision to pool.
  64. _override_decisions(context, "ADD_TO_CONTENT_POOL", "success")
  65. client = FakeWalkPlatformClient()
  66. result = run_bounded_walk(platform_client=client, **context)
  67. page_actions = [
  68. row for row in result["walk_actions"]
  69. if row["edge_id"] == "query_next_page" and row["walk_status"] == "success"
  70. ]
  71. assert len(page_actions) == 1
  72. assert page_actions[0]["raw_payload"]["rule_pack_execution"] == {
  73. "executed": True,
  74. "executed_rule_pack_id": "douyin_content_discovery_rule_pack_v1",
  75. "reason": "content_decision_reused_for_walk_gate",
  76. }