test_canon_sync.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #!/usr/bin/env python3
  2. """Guard against drift between the embedded prompt-quality-canon copies.
  3. The canon is embedded in three places — workflow-builder references,
  4. agent-builder references, and the agent-builder asset emitted into built
  5. agents — with no in-file sync note, because the loaded files are LLM-facing
  6. and a maintenance comment there is paid on every load. This test is the
  7. sync mechanism instead: all three copies must be byte-identical.
  8. Run with: python3 -m pytest test_canon_sync.py
  9. (or plain `python3 test_canon_sync.py` for a lightweight self-check).
  10. """
  11. import sys
  12. from pathlib import Path
  13. SKILLS_DIR = Path(__file__).resolve().parents[3]
  14. CANON_COPIES = [
  15. SKILLS_DIR / "bmad-workflow-builder" / "references" / "prompt-quality-canon.md",
  16. SKILLS_DIR / "bmad-agent-builder" / "references" / "prompt-quality-canon.md",
  17. SKILLS_DIR / "bmad-agent-builder" / "assets" / "prompt-quality-canon.md",
  18. ]
  19. def test_all_copies_exist():
  20. missing = [str(p) for p in CANON_COPIES if not p.is_file()]
  21. assert not missing, f"canon copy missing: {missing}"
  22. def test_all_copies_identical():
  23. contents = {p: p.read_bytes() for p in CANON_COPIES if p.is_file()}
  24. reference = CANON_COPIES[0]
  25. diverged = [
  26. str(p)
  27. for p, body in contents.items()
  28. if body != contents.get(reference)
  29. ]
  30. assert not diverged, (
  31. "canon copies have drifted from "
  32. f"{reference}: {diverged} — sync all copies together"
  33. )
  34. if __name__ == "__main__":
  35. test_all_copies_exist()
  36. test_all_copies_identical()
  37. print(f"ok: {len(CANON_COPIES)} canon copies present and identical")