import json from pedagogical_builder import merge_and_verify_explanations, LLMSchemaError def test_golden_merge(): print("šŸš€ Running The Golden Test: V2.5.3 Swiss Watch") # 1. Mock SymPy Truth Nodes (Immutable) sympy_nodes = [ {"step_id": 1, "math": "f(x) = x^2", "logic": "מבנה הפונקציה"}, {"step_id": 2, "math": "f'(x) = 2x", "logic": "גזירה"} ] # 2. Mock LLM Pedagogical Explanations (Skin) llm_explanations = [ {"step_id": 1, "pedagogical_explanation": "נתונה לנו פונקציה ריבועית פשוטה."}, {"step_id": 2, "pedagogical_explanation": "× ×©×Ŗ×ž×© בכלל החזקה כדי למצוא את הנגזרת."} ] try: # 3. Perform the Merge final_nodes = merge_and_verify_explanations(sympy_nodes, llm_explanations) print(" āœ… Merge Success!") assert len(final_nodes) == 2 assert final_nodes[1]["math"] == "f'(x) = 2x" assert final_nodes[1]["pedagogical_explanation"] == "× ×©×Ŗ×ž×© בכלל החזקה כדי למצוא את הנגזרת." except LLMSchemaError as e: print(f" āŒ Merge Failed: {e}") assert False, "Golden Merge should have succeeded" # 4. Test Schema Violations print("\nšŸ›”ļø Testing Schema Enforcement (Swiss Watch Locks):") # Violation A: Length Mismatch try: merge_and_verify_explanations(sympy_nodes, llm_explanations[:1]) assert False, "Should have failed on length mismatch" except LLMSchemaError: print(" āœ… Length Mismatch Guard - PASSED") # Violation B: Unexpected Keys (No Math allowed from LLM) llm_with_math = [ {"step_id": 1, "pedagogical_explanation": "...", "math": "hacked math"}, {"step_id": 2, "pedagogical_explanation": "..."} ] try: merge_and_verify_explanations(sympy_nodes, llm_with_math) assert False, "Should have failed on unexpected keys (math)" except LLMSchemaError: print(" āœ… Key Enforcement Guard - PASSED") # Violation C: Step Order Modified llm_shuffled = [ {"step_id": 2, "pedagogical_explanation": "Step 2"}, {"step_id": 1, "pedagogical_explanation": "Step 1"} ] try: merge_and_verify_explanations(sympy_nodes, llm_shuffled) assert False, "Should have failed on step order" except LLMSchemaError: print(" āœ… Step Order Guard - PASSED") print("\nšŸ† The Golden Test: V2.5.3 Swiss Watch - VERIFIED!") if __name__ == "__main__": test_golden_merge()