test_walk_strategy_config.py 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import json
  2. from pathlib import Path
  3. from content_agent.integrations.walk_strategy_json import (
  4. REQUIRED_SECTIONS,
  5. WalkStrategyStore,
  6. validate_walk_strategy_config,
  7. )
  8. CONFIG_PATH = Path("product_documents/抖音游走策略/douyin_walk_strategy.v1.json")
  9. def test_walk_strategy_config_loads_only_p6_runtime_source():
  10. store = WalkStrategyStore(Path("."))
  11. strategy = store.load_walk_strategy()
  12. assert strategy["strategy_id"] == "douyin_walk_strategy_v1"
  13. assert strategy["walk_strategy_version"] == "V1.0"
  14. assert strategy["walk_strategy_source_ref"]["file"] == str(CONFIG_PATH)
  15. assert strategy["source_of_truth"] == str(CONFIG_PATH)
  16. def test_walk_strategy_config_sections_and_references_are_closed():
  17. strategy = json.loads(CONFIG_PATH.read_text(encoding="utf-8"))
  18. findings = validate_walk_strategy_config(strategy, root_dir=Path("."))
  19. assert findings == []
  20. assert [section for section in REQUIRED_SECTIONS if section not in strategy] == []
  21. def test_walk_strategy_config_keeps_only_consumed_sections():
  22. # V3 清理受控变化: 13 段收窄到 3 个仍被运行时/校验消费的段;
  23. # 其余 10 段(老预算/停止/重试/触发规则等)已被 walk_graph+walk_policy 取代并删除。
  24. strategy = json.loads(CONFIG_PATH.read_text(encoding="utf-8"))
  25. assert set(REQUIRED_SECTIONS) == {
  26. "walk_edge_catalog",
  27. "walk_rule_pack_binding",
  28. "walk_fact_contract",
  29. }
  30. assert {key for key in strategy if key.startswith("walk_")} == set(REQUIRED_SECTIONS)
  31. def test_walk_strategy_config_uses_clue_id_and_real_rule_packs():
  32. strategy = json.loads(CONFIG_PATH.read_text(encoding="utf-8"))
  33. facts = {row["runtime_file"]: row for row in strategy["walk_fact_contract"]}
  34. assert facts["search_clues.jsonl"]["unique_key"] == [
  35. "run_id",
  36. "policy_run_id",
  37. "clue_id",
  38. ]
  39. # M4 砍包受控变化:4 future 包及其 7 条 binding 已物理删除,仅剩内容包归属。
  40. assert {
  41. (row["rule_pack_id"], row["rule_pack_version"])
  42. for row in strategy["walk_rule_pack_binding"]
  43. } == {
  44. ("douyin_content_discovery_rule_pack_v1", "1.0.0"),
  45. }
  46. def test_walk_strategy_binding_is_loaded_from_walk_strategy():
  47. from content_agent.business_modules.walk_engine import _binding_by_edge_id
  48. from content_agent.integrations.walk_strategy_json import WalkStrategyStore
  49. walk_strategy = WalkStrategyStore().load_walk_strategy()
  50. binding_by_edge = _binding_by_edge_id(walk_strategy)
  51. # M4 砍包受控变化:仅 decision_to_asset 保留 content binding,其余边走 fallback 戳。
  52. assert set(binding_by_edge) == {"decision_to_asset"}
  53. assert binding_by_edge["decision_to_asset"]["rule_pack_id"] == "douyin_content_discovery_rule_pack_v1"