test_decode_contracts.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. from __future__ import annotations
  2. from decode_content.contracts import (
  3. BUSINESS_STAGES,
  4. CREATION_STAGES,
  5. DIM_ATTRIBUTE_BY_TYPE,
  6. KNOWLEDGE_TYPES,
  7. SCOPE_TYPES,
  8. WHAT_KINDS,
  9. compute_contract_hash,
  10. iter_contract_artifacts,
  11. load_decode_contracts,
  12. )
  13. def test_load_decode_contracts_covers_skill_prompts_and_cache():
  14. contract = load_decode_contracts()
  15. assert "判颗" in contract.phase1
  16. assert "作用域" in contract.phase2
  17. assert "payload" in contract.phase3.lower()
  18. assert contract.schema_for_particle_type("how")["$id"] == "ingest-payload-how.schema.json"
  19. assert any(src["relative_path"].startswith("prompts/") for src in contract.prompt_sources())
  20. assert contract.scope_tree_sources()
  21. assert len(contract.content_hash) == 64
  22. assert compute_contract_hash(contract) == contract.content_hash
  23. def test_contract_constants_record_formal_business_terms():
  24. assert KNOWLEDGE_TYPES == ("how", "what", "why")
  25. assert BUSINESS_STAGES == ("灵感", "选题", "脚本")
  26. assert CREATION_STAGES == ("定向", "构思", "结构", "成文", "打磨")
  27. assert WHAT_KINDS == ("子集", "多维关系", "序列")
  28. assert SCOPE_TYPES == ("substance", "form", "feeling", "effect", "intent")
  29. assert DIM_ATTRIBUTE_BY_TYPE == {"how": "how", "what": "what", "why": "why"}
  30. def test_contract_artifacts_can_feed_repository():
  31. snapshots = iter_contract_artifacts()
  32. assert snapshots[0].contract_name == "创作知识提取-skill"
  33. assert snapshots[0].contract_type == "skill"
  34. assert snapshots[0].content_hash and len(snapshots[0].content_hash) == 64
  35. assert snapshots[0].snapshot["constants"]["dim_attribute_by_type"]["how"] == "how"
  36. assert any(s.contract_type == "prompt_phase" for s in snapshots)
  37. assert any(s.contract_type == "schema" for s in snapshots)
  38. assert any(s.contract_type == "prompt" for s in snapshots)