test_legacy_cleanup_contract.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. from __future__ import annotations
  2. from pathlib import Path
  3. FORMAL_SOURCE_ROOTS = [
  4. Path("app"),
  5. Path("pipeline"),
  6. Path("acquisition"),
  7. Path("decode_content"),
  8. Path("core"),
  9. ]
  10. LEGACY_RUNTIME_TOKENS = [
  11. "CK_SQLITE_PATH",
  12. "data/app.db",
  13. "/data/queries",
  14. "/api/creation-search",
  15. "creation_knowledge.api",
  16. "from acquisition import store",
  17. "import acquisition.store",
  18. "from creation_knowledge",
  19. "import creation_knowledge",
  20. ]
  21. LEGACY_QUERY_TOKENS = [
  22. "from acquisition.query",
  23. "import acquisition.query",
  24. "tactic2_form_llm",
  25. "tactic3_suggest",
  26. "tactic4_llm",
  27. "tactic_multiaxis",
  28. "tactic1",
  29. "tactic2",
  30. "tactic3",
  31. "tactic4",
  32. "build_query_demo",
  33. "build_family6",
  34. "query_gen.txt",
  35. "form_query_gen.txt",
  36. "data/queries/demo.json",
  37. ]
  38. def _active_source_files():
  39. for root in FORMAL_SOURCE_ROOTS:
  40. for path in root.rglob("*"):
  41. if path.is_file() and path.suffix in {".py", ".js", ".jsx", ".ts", ".tsx"}:
  42. yield path
  43. def test_formal_sources_do_not_depend_on_archived_legacy_runtime():
  44. offenders: list[str] = []
  45. for path in _active_source_files():
  46. text = path.read_text(encoding="utf-8")
  47. for token in LEGACY_RUNTIME_TOKENS:
  48. if token in text:
  49. offenders.append(f"{path}:{token}")
  50. assert offenders == []
  51. def test_formal_sources_do_not_depend_on_legacy_query_tactics():
  52. offenders: list[str] = []
  53. script_roots = [Path("scripts")]
  54. for root in FORMAL_SOURCE_ROOTS + script_roots:
  55. for path in root.rglob("*"):
  56. if path.is_file() and path.suffix in {".py", ".js", ".jsx", ".ts", ".tsx"}:
  57. text = path.read_text(encoding="utf-8")
  58. for token in LEGACY_QUERY_TOKENS:
  59. if token in text:
  60. offenders.append(f"{path}:{token}")
  61. assert offenders == []
  62. def test_legacy_debug_decompose_entry_is_explicitly_labeled():
  63. text = Path("scripts/decompose.py").read_text(encoding="utf-8")
  64. assert "LEGACY/debug" in text[:500]
  65. assert "正式云端 pipeline 入口" in text[:500]
  66. assert "web/frameworks" in text
  67. assert "web/payloads" in text