BuddyMath / tests /verify_imports.py
dotandru's picture
Fix: Clean production deployment with sse-starlette
9d29c62
Raw
History Blame Contribute Delete
6.55 kB
"""
V231.17 - Lightweight verification script
Tests imports, syntax, and function signatures WITHOUT needing Google API key.
"""
import sys, os
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
os.chdir(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
passed = 0
failed = 0
def check(name, condition, detail=""):
global passed, failed
if condition:
print(f" โœ… {name}")
passed += 1
else:
print(f" โŒ {name} - {detail}")
failed += 1
print("=" * 60)
print("๐Ÿ”ฌ BuddyMath V231.17 - Local Verification")
print("=" * 60)
# =========== 1. IMPORTS ===========
print("\n๐Ÿ“ฆ 1. Import Tests:")
try:
import json
check("json (stdlib)", True)
except Exception as e:
check("json (stdlib)", False, str(e))
try:
import json_repair
check("json_repair", True)
except Exception as e:
check("json_repair", False, str(e))
try:
import micro_prompts
check("micro_prompts imports", True)
except Exception as e:
check("micro_prompts imports", False, str(e))
try:
import problem_understanding
check("problem_understanding imports", True)
except Exception as e:
check("problem_understanding imports", False, str(e))
try:
import topic_taxonomy
check("topic_taxonomy imports", True)
except Exception as e:
check("topic_taxonomy imports", False, str(e))
try:
import validators
check("validators imports", True)
except Exception as e:
check("validators imports", False, str(e))
try:
import prompts
check("prompts imports", True)
except Exception as e:
check("prompts imports", False, str(e))
# =========== 2. MICRO_PROMPTS ===========
print("\n๐Ÿ“ 2. micro_prompts.py Tests:")
try:
# Test that json is available inside micro_prompts
result = micro_prompts.get_general_prompt({"test": "data"})
check("get_general_prompt() works (json.dumps OK)", isinstance(result, str) and len(result) > 20)
except NameError as e:
check("get_general_prompt() works", False, f"NameError: {e}")
except Exception as e:
check("get_general_prompt() works", False, str(e))
try:
# Test CIRCLE_EQUATION micro-prompt
result = micro_prompts.get_micro_prompt("CIRCLE_EQUATION", {"center": "(3,5)", "radius": "5"})
check("CIRCLE_EQUATION micro-prompt", isinstance(result, str) and "ืžืขื’ืœ" in result)
except Exception as e:
check("CIRCLE_EQUATION micro-prompt", False, str(e))
try:
tokens = micro_prompts.get_prompt_token_count("CIRCLE_EQUATION")
check(f"Token count for CIRCLE_EQUATION = {tokens}", tokens > 0)
except Exception as e:
check("Token count", False, str(e))
# =========== 3. PROBLEM UNDERSTANDING ===========
print("\n๐Ÿง  3. problem_understanding.py Tests:")
try:
prompt = problem_understanding.get_problem_understanding_prompt(
"ืžืฆื ืžืฉื•ื•ืืช ืžืขื’ืœ", {"function_equations": [], "points": ["A"]}
)
check("Understanding prompt generation", isinstance(prompt, str) and len(prompt) > 50)
except Exception as e:
check("Understanding prompt generation", False, str(e))
try:
# Test JSON parsing with LaTeX - THE BUG WE FIXED
test_json_with_latex = '{"problem_type": "GEOMETRY", "sub_questions": [{"id": "ื", "topic": "CIRCLE"}]}'
result = problem_understanding.parse_understanding(test_json_with_latex)
check("parse_understanding (clean JSON)", result["problem_type"] == "GEOMETRY")
except Exception as e:
check("parse_understanding (clean JSON)", False, str(e))
try:
# Test with escaped LaTeX that breaks standard json.loads
test_bad_json = '{"type": "GEOMETRY", "eq": "\\Delta MOA"}'
result = problem_understanding.parse_understanding(test_bad_json)
check("parse_understanding (LaTeX JSON - json_repair)", "type" in result)
except Exception as e:
check("parse_understanding (LaTeX JSON)", False, str(e))
try:
valid = problem_understanding.validate_understanding({
"problem_type": "CIRCLE",
"sub_questions": [{"id": "ื", "question": "test", "topic": "CIRCLE"}],
"solving_order": ["ื"]
})
check("validate_understanding", valid == True)
except Exception as e:
check("validate_understanding", False, str(e))
# =========== 4. STRATEGY MANAGER ===========
print("\n๐ŸŽฏ 4. strategy_manager.py Tests:")
try:
from strategy_manager import StrategyManager
check("StrategyManager class imports", True)
except Exception as e:
check("StrategyManager class imports", False, str(e))
try:
import inspect
sig = inspect.signature(StrategyManager.solve_with_strategy)
params = list(sig.parameters.keys())
check(f"solve_with_strategy params: {params}", "image_data" in params)
except Exception as e:
check("solve_with_strategy signature", False, str(e))
try:
sig = inspect.signature(StrategyManager._call_llm)
params = list(sig.parameters.keys())
check(f"_call_llm params: {params}", "image_data" in params and "category" in params)
except Exception as e:
check("_call_llm signature", False, str(e))
# =========== 5. ORCHESTRATOR (without API key) ===========
print("\n๐Ÿ—๏ธ 5. orchestrator.py Tests:")
try:
# Read the file and check for the kwarg fix
with open("orchestrator.py", "r", encoding="utf-8") as f:
orch_code = f.read()
check("orchestrator.py reads image_bytes from kwargs",
"image_bytes" in orch_code and "kwargs.get('image_bytes'" in orch_code)
except Exception as e:
check("orchestrator.py kwarg check", False, str(e))
try:
check("orchestrator.py passes image_data to smart_solve",
"image_data=image_data" in orch_code)
except Exception as e:
check("orchestrator image_data pass-through", False, str(e))
try:
check("orchestrator.py has V273.0+ version",
"V273.0" in orch_code)
except Exception as e:
check("orchestrator version", False, str(e))
# =========== 6. MAIN.PY ===========
print("\n๐ŸŒ 6. main.py Tests:")
try:
with open("main.py", "r", encoding="utf-8") as f:
main_code = f.read()
check("main.py sends image_bytes to solve_problem",
"image_bytes=image_bytes" in main_code)
except Exception as e:
check("main.py image_bytes check", False, str(e))
# =========== SUMMARY ===========
print("\n" + "=" * 60)
total = passed + failed
print(f"๐Ÿ“Š Results: {passed}/{total} passed, {failed}/{total} failed")
if failed == 0:
print("๐ŸŽ‰ ALL TESTS PASSED! Ready for deploy.")
else:
print(f"โš ๏ธ {failed} test(s) FAILED - fix before deploy!")
print("=" * 60)