import json, sys
from pathlib import Path
ROOT=Path(__file__).resolve().parents[1]
sys.path.insert(0,str(ROOT/"reference"/"python"))
from zeon_sdk import DestinationRegistry, SemanticRouter

router=SemanticRouter(DestinationRegistry.from_json(ROOT/"examples"/"destinations.json"))
vectors=json.loads((ROOT/"tests"/"conformance-vectors.json").read_text(encoding="utf-8"))["vectors"]
failures=[]
for v in vectors:
    req=json.loads((ROOT/"examples"/v["request"]).read_text(encoding="utf-8"))
    result=router.route(req)
    expected=v["expected_action"]
    action_ok=result["action"] in expected if isinstance(expected,list) else result["action"]==expected
    selected_ok=v["expected_selected"]=="*" or (result["selected"] and result["selected"][0]==v["expected_selected"])
    print(v["id"], "PASS" if action_ok and selected_ok else "FAIL", result["action"], result["selected"])
    if not(action_ok and selected_ok): failures.append(v["id"])
raise SystemExit(1 if failures else 0)
