test_v4_m1_query_sources_replay.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. from content_agent.business_modules import search_intent, source_seed
  2. from content_agent.integrations.runtime_files import LocalRuntimeFileStore
  3. from content_agent.run_service import RunService
  4. from content_agent.schemas import RunStartRequest
  5. from tests.p1_helpers import FakeQueryVariantClient, REAL_SOURCE_FIXTURE, real_source_payload
  6. def test_v4_m1_direct_query_sources_replay_from_seed_pack(tmp_path):
  7. runtime = LocalRuntimeFileStore(tmp_path / "runtime")
  8. runtime.prepare_run("run_1")
  9. seed = source_seed.run("run_1", "policy_1", real_source_payload(), runtime)
  10. client = FakeQueryVariantClient({"爱国情感": "不应该调用"})
  11. queries = search_intent.run(
  12. "run_1",
  13. "policy_1",
  14. seed["pattern_seed_pack"],
  15. runtime,
  16. client,
  17. strategy_version="V4",
  18. )
  19. assert client.calls == []
  20. # 首轮搜索池三路直连:seed_terms + query_seed_points + 分类叶子元素,不调 LLM 变体。
  21. methods = {row["search_query_generation_method"] for row in queries}
  22. assert {"seed_term", "query_seed_point", "category_leaf_element"} <= methods
  23. assert "llm_variant" not in methods
  24. assert all("llm_variant_of" not in row for row in queries)
  25. assert all(row["pattern_seed_ref"]["query_source_text"] == row["search_query"] for row in queries)
  26. assert all(row["pattern_seed_ref"]["query_source_rank"] >= 1 for row in queries)
  27. assert all(row["raw_payload"]["query_source_refs"] for row in queries)
  28. source_types = {row["pattern_seed_ref"]["query_source_type"] for row in queries}
  29. assert {"seed_term", "query_seed_point", "category_terminal_element"} <= source_types
  30. def test_v4_m1_run_service_does_not_call_query_variant_client(tmp_path):
  31. client = FakeQueryVariantClient({"爱国情感": "不应该调用"})
  32. service = RunService(
  33. runtime_root=tmp_path / "runtime" / "v1",
  34. query_variant_client=client,
  35. )
  36. state = service.start_run(
  37. RunStartRequest(platform_mode="mock", source=str(REAL_SOURCE_FIXTURE), strategy_version="V4")
  38. )
  39. queries = service.read_jsonl(state["run_id"], "search_queries.jsonl")
  40. assert state["status"] == "success"
  41. assert client.calls == []
  42. assert queries
  43. assert "llm_variant" not in {row["search_query_generation_method"] for row in queries}