import hashlib import pytest from tht.pi_skill_projection import ( FRAGMENT_ORDER, PROJECTION_PATH, projection_is_current, render_projection, ) # Approved session-language contract (#35); unrelated workflow fragments stay byte-identical. BASELINE_SHA256 = "a2e6608e1aa07735ef92d96b3a87fca3bfbe3636754330ff6749178c87a37493" def test_modular_pi_skill_renders_the_byte_identical_approved_projection(): rendered = render_projection() assert FRAGMENT_ORDER == ( ("{{EVIDENCE_RUNTIME_SEARCH}}", "evidence/runtime-search.md"), ("{{DISAMBIGUATION_OPEN_AMBIGUITY}}", "disambiguation/open-ambiguity.md"), ("{{DISAMBIGUATION_INSTRUCTIONS}}", "disambiguation/phase-1.md"), ("{{MEMORY_INSTRUCTIONS}}", "memory/phase-2.md"), ("{{DISAMBIGUATION_REWRITING_INSTRUCTIONS}}", "disambiguation/phase-3.md"), ("{{MEMORY_SOLVED_SEARCH_F4}}", "memory/solved-search-f4.md"), ("{{DISAMBIGUATION_SCHEMA_GROUNDING}}", "disambiguation/schema-grounding.md"), ("{{EVIDENCE_FORMULA_PROPOSALS}}", "evidence/formula-proposals.md"), ("{{MEMORY_SOLVED_SEARCH_F6}}", "memory/solved-search-f6.md"), ("{{MEMORY_SOLVED_SEARCH_F7}}", "memory/solved-search-f7.md"), ("{{MEMORY_PROMOTION_F8}}", "memory/phase-8-promotion.md"), ("{{MEMORY_SOLVED_FINALIZATION}}", "memory/solved-finalization.md"), ) assert rendered == render_projection() assert hashlib.sha256(rendered).hexdigest() == BASELINE_SHA256 assert PROJECTION_PATH.read_bytes() == rendered def test_projection_check_detects_stale_output(tmp_path): stale = tmp_path / "SKILL.md" stale.write_bytes(b"stale\n") assert projection_is_current(stale) is False def test_projection_rejects_a_missing_or_repeated_static_placeholder(): with pytest.raises(ValueError, match="exactly once"): render_projection(template=b"{{MEMORY_INSTRUCTIONS}}\n") with pytest.raises(ValueError, match="exactly once"): render_projection( template=( b"{{DISAMBIGUATION_INSTRUCTIONS}}\n" b"{{MEMORY_INSTRUCTIONS}}\n" b"{{MEMORY_INSTRUCTIONS}}\n" ) )