| import json |
| import re |
| import logging |
| import asyncio |
| from strategy_manager import StrategyManager |
| from pedagogical_builder import build_pedagogical_response |
| from orchestrator import verify_math_consistency |
|
|
| |
| logging.basicConfig(level=logging.INFO) |
| logger = logging.getLogger(__name__) |
|
|
| async def test_v5_pipeline(): |
| print("๐ Starting V5.0 Pipeline Verification Test") |
| |
| |
| raw_response = """ |
| Here is the structured solution for you: |
| { |
| "confidence_score": 0.95, |
| "uncertainty_flag": false, |
| "is_valid": true, |
| "blocks": [ |
| {"type": "text", "content": "ืืื ื ืคืชืืจ ืืช ืืืฉืืืื ืื ืคืืื ืืื!"}, |
| {"type": "math", "content": "x^2 - 4 = 0"}, |
| {"type": "text", "content": "ื ืขืืืจ ืืืฃ:"}, |
| {"type": "math", "content": "x^2 = 4"}, |
| {"type": "text", "content": "ืื ืืฆืื ืฉืืจืฉ:"}, |
| {"type": "math", "content": "x = \\\\pm 2"} |
| ] |
| } |
| """ |
| |
| |
| sm = StrategyManager(None) |
| parsed = sm._parse_v5_json(raw_response) |
| |
| print("โ
Step 1: Prefix Leakage Protection - PASSED") |
| print(f"๐ Parsed block count: {len(parsed.get('blocks', []))}") |
| |
| assert len(parsed['blocks']) == 6, "Block count mismatch" |
| assert sm._validate_v5_schema(parsed), "Schema validation failed" |
| print("โ
Step 2: Schema Validation - PASSED") |
|
|
| |
| response = build_pedagogical_response( |
| topic_id="GENERAL", |
| llm_output=parsed, |
| data_anchor={} |
| ) |
| |
| steps = response['sections'][0]['steps'] |
| print(f"๐ Pedagogical steps count: {len(steps)}") |
| |
| assert len(steps) == 9, f"Pedagogical mapping failed, expected 9 steps, got {len(steps)}" |
| print("โ
Step 3: Pedagogical Mapping - PASSED") |
|
|
| |
| |
| blocks = parsed.get("blocks", []) |
| math_blocks = [b for b in blocks if b.get("type") == "math"] |
| llm_fn = math_blocks[-1]["content"] if math_blocks else "None" |
| |
| print(f"โ๏ธ Extracted final result for verification: {llm_fn}") |
| assert llm_fn == "x = \\pm 2", "Anchor protection extraction failed" |
| |
| anchor_fn = "x^2 = 4" |
| is_identical, scale = verify_math_consistency(anchor_fn, "2") |
| print(f"โ๏ธ Symbolic verification (x^2=4 vs 2): {is_identical}, scale: {scale}") |
| |
| print("\n๐ V5.0 End-to-End Pipeline Verified!") |
|
|
| if __name__ == "__main__": |
| asyncio.run(test_v5_pipeline()) |
|
|