test_p8_drift_guards.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. from pathlib import Path
  2. CURRENT_CONTRACT_ROOTS = [
  3. Path("content_agent"),
  4. Path("tests"),
  5. Path("sql"),
  6. Path("product_documents"),
  7. ]
  8. def test_p8_learning_contract_has_no_legacy_action_or_effect_status():
  9. text = _joined_text(CURRENT_CONTRACT_ROOTS)
  10. assert "HOLD_CONTENT_" + "PENDING" not in text
  11. assert "weak_" + "effective" not in text
  12. assert "search_query_effect_status" + '="block' + 'ed"' not in text
  13. assert "search_query_effect_status" + ":'block" + "ed'" not in text
  14. def test_p8_learning_contract_has_no_old_walk_strategy_name():
  15. text = _joined_text(CURRENT_CONTRACT_ROOTS)
  16. assert "douyin_available_" + "walk_strategy_v1" not in text
  17. assert "douyin_available_" + "walk_strategy.v1.json" not in text
  18. def test_p8_recommendations_do_not_emit_auto_mutation_fields():
  19. text = _joined_text([Path("content_agent/business_modules/learning_review.py")])
  20. assert "requires_human_approval" in text
  21. assert "auto_" + "apply" not in text
  22. assert "rule_pack_" + "patch" not in text
  23. assert "walk_strategy_" + "patch" not in text
  24. assert "budget_" + "patch" not in text
  25. assert "publish_job_" + "patch" not in text
  26. def test_p8_default_tests_do_not_wire_real_external_sources():
  27. text = _joined_text([Path("tests")])
  28. assert "CONTENTFIND_OPENROUTER_" + "API_KEY=" not in text
  29. assert "CONTENT_SUPPLY_DB_" + "PASSWORD=" not in text
  30. assert "CRAWAPI_" + "COOKIE=" not in text
  31. assert "publish_jobs_real_" + "client" not in text
  32. def _joined_text(roots: list[Path]) -> str:
  33. chunks = []
  34. for root in roots:
  35. paths = [root] if root.is_file() else list(root.rglob("*"))
  36. for path in paths:
  37. if path.is_file() and path.suffix in {".py", ".sql", ".md", ".json"}:
  38. chunks.append(path.read_text(encoding="utf-8"))
  39. return "\n".join(chunks)