test_walk_failed_no_budget.py 1.4 KB

1234567891011121314151617181920212223242526272829
  1. """失败的游走 query 不消耗预算(标签/作者跳失败都不扣边预算 + 不累计总闸)。"""
  2. from content_agent.business_modules.walk_engine import run_bounded_walk
  3. from content_agent.integrations.walk_graph_json import WalkGraphStore
  4. from tests.p6_walk_helpers import FakeWalkPlatformClient, build_initial_walk_context, set_v4_allow_walk
  5. def test_failed_tag_walk_does_not_consume_budget(tmp_path):
  6. context = build_initial_walk_context(tmp_path)
  7. set_v4_allow_walk(context["rule_decisions"][0], True)
  8. # fail_tag:所有标签搜索都失败;作者游走仍成功(其 raw_payload 带 budget 快照)。
  9. result = run_bounded_walk(platform_client=FakeWalkPlatformClient(fail_tag=True), **context)
  10. tag_failed = [
  11. row for row in result["walk_actions"]
  12. if row["edge_id"] == "hashtag_to_query" and row["walk_status"] == "failed"
  13. ]
  14. assert tag_failed, "应有失败的标签游走"
  15. author_success = [
  16. row for row in result["walk_actions"]
  17. if row["edge_id"] == "author_to_works" and row["walk_status"] == "success"
  18. ]
  19. assert author_success, "作者游走应成功并带 budget 快照"
  20. tag_cap = WalkGraphStore().load_policy()["edge_budgets_by_id"]["hashtag_to_query"]["max_total_actions"]
  21. snap = author_success[0]["raw_payload"]["remaining_budget_snapshot"]
  22. # 标签全失败 → 一次都不扣 → 标签预算仍满额(failed 不消耗)。
  23. assert snap["hashtag_to_query"] == tag_cap