test_p7_drift_guards.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import re
  2. from pathlib import Path
  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
  6. CURRENT_CONTRACT_ROOTS = [
  7. Path("content_agent"),
  8. Path("tests"),
  9. Path("sql"),
  10. Path("product_documents"),
  11. ]
  12. def test_current_contract_has_no_deprecated_content_action_or_old_status():
  13. text = _joined_text(CURRENT_CONTRACT_ROOTS)
  14. assert "HOLD_CONTENT_" + "PENDING" not in text
  15. assert "weak_" + "effective" not in text
  16. old_blocked_effect = re.compile(
  17. r"[\"']?search_query_effect_status[\"']?\s*[:=]\s*[\"']blocked[\"']"
  18. )
  19. assert old_blocked_effect.search(text) is None
  20. def test_current_contract_has_no_old_walk_strategy_source_or_id():
  21. text = _joined_text(CURRENT_CONTRACT_ROOTS)
  22. assert "douyin_available_" + "walk_strategy_v1" not in text
  23. assert "douyin_available_" + "walk_strategy.v1.json" not in text
  24. old_path = Path("product_documents/抖音游走策略") / (
  25. "douyin_available_" + "walk_strategy.v1.json"
  26. )
  27. assert not old_path.exists()
  28. def test_current_code_does_not_hardcode_completeness_true():
  29. text = _joined_text([Path("content_agent")])
  30. assert "run_path_complete" + ": True" not in text
  31. assert "run_path_complete" + " = True" not in text
  32. assert "trace_complete" + ": True" not in text
  33. assert "trace_complete" + " = True" not in text
  34. def test_new_run_does_not_emit_old_strategy_name(tmp_path):
  35. service = RunService(
  36. runtime_root=tmp_path / "runtime" / "v1",
  37. query_variant_client=FakeQueryVariantClient(),
  38. )
  39. state = service.start_run(
  40. RunStartRequest(platform_mode="mock", source=str(REAL_SOURCE_FIXTURE))
  41. )
  42. final_output = service.read_json(state["run_id"], "final_output.json")
  43. text = str(final_output)
  44. assert "douyin_available_" + "walk_strategy_v1" not in text
  45. assert final_output["walk_strategy"]["walk_strategy_id"] == "douyin_walk_strategy_v1"
  46. def _joined_text(roots: list[Path]) -> str:
  47. chunks = []
  48. for root in roots:
  49. for path in root.rglob("*"):
  50. if path.is_file() and path.suffix in {".py", ".sql", ".md", ".json"}:
  51. chunks.append(path.read_text(encoding="utf-8"))
  52. return "\n".join(chunks)