from __future__ import annotations import importlib import json import sys from pathlib import Path PROJECT_ROOT = Path(__file__).resolve().parents[1] if str(PROJECT_ROOT) not in sys.path: sys.path.insert(0, str(PROJECT_ROOT)) _core = importlib.import_module("agent_call.core") ValidationError = _core.ValidationError queue_name = _core.queue_name routing_key = _core.routing_key def check(profile_path: str | Path) -> list[str]: path = Path(profile_path) try: profile = json.loads(path.read_text(encoding="utf-8")) except (OSError, json.JSONDecodeError) as exc: return [f"profile load failed: {type(exc).__name__}"] problems: list[str] = [] if profile.get("mode") != "mock": problems.append("mock profile must declare mode=mock") for component, provider in profile.get("provider_modes", {}).items(): if component in {"llm", "tts", "asr", "sip", "oss"} and provider == "real": problems.append(f"mock profile enables real provider: {component}") for tenant in profile.get("tenants", []): try: route = routing_key(tenant["tenant_key"]) queue_name(tenant["tenant_key"]) except (KeyError, TypeError, ValidationError) as exc: problems.append(f"tenant route invalid: {type(exc).__name__}") continue if len(route.encode("utf-8")) > 255: problems.append("tenant route exceeds broker limit") if not profile.get("cells"): problems.append("no execution cells configured") return problems def main() -> int: problems = check( sys.argv[1] if len(sys.argv) > 1 else "docs/contracts/mock-profile.json" ) if problems: for problem in problems: print(f"ERROR {problem}") return 1 print("mock profile clean") return 0 if __name__ == "__main__": raise SystemExit(main())