File size: 2,758 Bytes
9d29c62 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | # verify_v41_authority.py
import sys
import os
import json
# Add current directory to path
sys.path.append(os.getcwd())
from proof_graph import ProofGraph, ProofStep
from pedagogical_builder import build_pedagogical_response
import curriculum_engine
def test_deterministic_merge():
print("🧪 Testing Deterministic Merge (V4.1)...")
# 1. Create a ProofGraph (The Truth)
steps = [
ProofStep(1, "x + 2 = 5", "שיוויון בסיסי"),
ProofStep(2, "x = 3", "בידוד הנעלם")
]
graph = ProofGraph(steps)
# 2. Mock LLM output with different step counts or "distractions"
llm_output = {
"steps_explanations": [
{"step_id": 1, "pedagogical_explanation": "נתחיל מהמשוואה"},
{"step_id": 2, "pedagogical_explanation": "נחסר 2 משני האגפים"}
],
"teacher_summary": "זה סיכום המורה"
}
# 3. Build response
response = build_pedagogical_response("GENERAL", llm_output, {}, proof_graph=graph)
# 4. Verify math is preserved from ProofGraph
ui_steps = response["sections"][0]["steps"]
if ui_steps[0]["block_math"] == "x + 2 = 5" and ui_steps[1]["block_math"] == "x = 3":
print("✅ Success: Math preserved exactly from ProofGraph.")
else:
print(f"❌ Failure: Math mismatch. Found {ui_steps[0]['block_math']} and {ui_steps[1]['block_math']}")
def test_curriculum_ontology_enforcement():
print("\n🧪 Testing Curriculum Ontology Enforcement (V4.1)...")
# Grade 7 rules
rules = curriculum_engine.get_allowed_math_operators("י׳", level="3") # Example: 3 units might have restrictions
grade7_rules = curriculum_engine.get_allowed_math_operators("ז׳", level="4")
# Create an ILLEGAL ProofGraph for Grade 7 (System of Equations)
illegal_steps = [
ProofStep(1, "x + y = 10", "משוואה ראשונה"),
ProofStep(2, "x - y = 2", "משוואה שנייה"),
ProofStep(3, "2x = 12", "חיבור משוואות", operator_used="SYSTEM_OF_EQUATIONS")
]
illegal_graph = ProofGraph(illegal_steps)
from proof_graph import validate_pedagogical_legality
is_legal, reason = validate_pedagogical_legality(illegal_graph, grade7_rules)
if not is_legal and "SYSTEM_OF_EQUATIONS" in reason or "מערכת משוואות" in reason:
print("✅ Success: Ontology-based guard REJECTED illegal operator for Grade 7.")
else:
print(f"❌ Failure: Guard allowed illegal operator or gave wrong reason: {reason}")
if __name__ == "__main__":
test_deterministic_merge()
test_curriculum_ontology_enforcement()
print("\n✨ V4.1 Truth Authority Logic Verification PASSED!")
|