test_decode_contracts.py 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. from __future__ import annotations
  2. from datetime import datetime, timezone
  3. from uuid import uuid4
  4. from decode_content.contracts import (
  5. BUSINESS_STAGES,
  6. CREATION_STAGES,
  7. DIM_ATTRIBUTE_BY_TYPE,
  8. KNOWLEDGE_TYPES,
  9. SCOPE_TYPES,
  10. WHAT_KINDS,
  11. compute_contract_hash,
  12. iter_contract_artifacts,
  13. load_decode_contracts,
  14. )
  15. from decode_content.models import ContractSnapshot
  16. def test_load_decode_contracts_covers_skill_prompts_and_cache():
  17. contract = load_decode_contracts()
  18. assert "判颗" in contract.phase1
  19. assert "作用域" in contract.phase2
  20. assert "payload" in contract.phase3.lower()
  21. assert contract.schema_for_particle_type("how")["$id"] == "ingest-payload-how.schema.json"
  22. assert any(src["relative_path"].startswith("prompts/") for src in contract.prompt_sources())
  23. assert contract.scope_tree_sources()
  24. assert len(contract.content_hash) == 64
  25. assert compute_contract_hash(contract) == contract.content_hash
  26. def test_contract_constants_record_formal_business_terms():
  27. assert KNOWLEDGE_TYPES == ("how", "what", "why")
  28. assert BUSINESS_STAGES == ("灵感", "选题", "脚本", "视觉呈现", "拍摄表达")
  29. assert CREATION_STAGES == ("定向", "构思", "结构", "成文", "打磨")
  30. assert WHAT_KINDS == ("子集", "多维关系", "序列")
  31. assert SCOPE_TYPES == ("substance", "form", "feeling", "effect", "intent")
  32. assert DIM_ATTRIBUTE_BY_TYPE == {"how": "how", "what": "what", "why": "why"}
  33. def test_contract_artifacts_can_feed_repository():
  34. snapshots = iter_contract_artifacts()
  35. assert snapshots[0].contract_name == "创作知识提取-skill"
  36. assert snapshots[0].contract_type == "skill"
  37. assert snapshots[0].content_hash and len(snapshots[0].content_hash) == 64
  38. assert snapshots[0].snapshot["constants"]["dim_attribute_by_type"]["how"] == "how"
  39. assert any(s.contract_type == "prompt_phase" for s in snapshots)
  40. assert any(s.contract_type == "schema" for s in snapshots)
  41. assert any(s.contract_type == "prompt" for s in snapshots)
  42. def test_contract_snapshot_accepts_contract_artifact_timestamps():
  43. now = datetime.now(timezone.utc)
  44. snapshot = ContractSnapshot.model_validate(
  45. {
  46. "id": uuid4(),
  47. "contract_name": "创作知识提取-skill",
  48. "contract_type": "skill",
  49. "version_label": "test",
  50. "content_hash": "a" * 64,
  51. "source_path": "创作知识提取-skill",
  52. "snapshot": {},
  53. "created_at": now,
  54. "updated_at": now,
  55. }
  56. )
  57. assert snapshot.updated_at == now