"""Shared paths and loaders for Hermes chat capability contracts.""" from __future__ import annotations import importlib.util import sys from pathlib import Path from types import SimpleNamespace import yaml ROOT = Path(__file__).parents[2] HERMES = ROOT / "services" / "hermes" VAULT = ROOT / "services" / "vault" def _documents(path: Path) -> list[dict]: return [doc for doc in yaml.safe_load_all(path.read_text()) if doc] def _load_broker_module(name: str, filename: str, monkeypatch): """Load one broker with its mounted routing-catalog dependency.""" catalog_path = HERMES / "scripts" / "routing_catalog.py" catalog_spec = importlib.util.spec_from_file_location( "routing_catalog", catalog_path ) assert catalog_spec and catalog_spec.loader catalog = importlib.util.module_from_spec(catalog_spec) catalog_spec.loader.exec_module(catalog) monkeypatch.setitem(sys.modules, "routing_catalog", catalog) monkeypatch.setitem(sys.modules, "httpx", SimpleNamespace()) broker_path = HERMES / "scripts" / filename spec = importlib.util.spec_from_file_location(name, broker_path) assert spec and spec.loader module = importlib.util.module_from_spec(spec) spec.loader.exec_module(module) return module