test_walk_profile_degradation.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. """V3-M4: profile 驱动的平台退化 + walk_actions 指纹基线。
  2. 视频号 author_to_works 在 platform_profiles 标 blocked → loop 产显式 skip、不调平台、
  3. 不抛错,游走退化为"搜索→内容→tag 回灌"。real_id45 指纹快照由实跑钉死,
  4. 是 M5 并发改造"结果与串行一致"的对照基线。
  5. """
  6. from __future__ import annotations
  7. import json
  8. from pathlib import Path
  9. from tests.gemini_helpers import FakeGeminiVideoClient
  10. from tests.replay_harness import replay_case
  11. _FINGERPRINT_PATH = Path("tests/fixtures/snapshots/real_id45/walk_actions_fingerprint.json")
  12. def _fingerprint(walk_actions):
  13. # wa_id 含随机 run_id 不能跨次钉死;其确定性由 sha1(run:policy:edge:target:suffix)算法保证。
  14. return sorted(
  15. [row["edge_id"], row["from_node_id"], row["to_node_id"], row["walk_action"], row["walk_status"], row["budget_tier"], row.get("reason_code") or ""]
  16. for row in walk_actions
  17. )
  18. def test_replay_id45_walk_actions_fingerprint_is_stable(tmp_path):
  19. # 同输入必须产出同 walk_actions 集合(M5 并发一致性的对照基线;快照由实跑钉死)。
  20. artifacts = replay_case("real_id45", runtime_root=tmp_path / "rt")
  21. walk_actions = artifacts.files["walk_actions.jsonl"]
  22. expected = json.loads(_FINGERPRINT_PATH.read_text(encoding="utf-8"))
  23. assert _fingerprint(walk_actions) == expected
  24. assert len({row["walk_action_id"] for row in walk_actions}) == len(walk_actions)
  25. def test_shipinhao_author_edge_blocked_emits_explicit_skip(tmp_path):
  26. artifacts = replay_case(
  27. "sph_caihong",
  28. runtime_root=tmp_path / "rt",
  29. gemini_video_client=FakeGeminiVideoClient(),
  30. )
  31. assert artifacts.state["status"] == "success"
  32. walk_actions = artifacts.files["walk_actions.jsonl"]
  33. author_actions = [row for row in walk_actions if row["edge_id"] == "author_to_works"]
  34. assert author_actions
  35. assert all(row["walk_status"] == "skipped" for row in author_actions)
  36. assert all(row["reason_code"] == "edge_blocked_by_platform_profile" for row in author_actions)
  37. # 退化不是漏抓:无作者作品内容混入。
  38. assert not [
  39. item for item in artifacts.files["discovered_content_items.jsonl"]
  40. if item.get("previous_discovery_step") == "author_works"
  41. ]