BuddyMath / tests /verify_swiss_watch.py
dotandru's picture
Fix: Clean production deployment with sse-starlette
9d29c62
Raw
History Blame Contribute Delete
2.59 kB
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()