"""Keep Chapter 13's EventBus lesson aligned with provider factories."""

from __future__ import annotations

import importlib.util
import sys
from pathlib import Path

ROOT = Path(__file__).resolve().parents[2]
CHAPTER = ROOT / "docs" / "teaching" / "13-swap-providers-and-transports"


def _load_probe():
    path = CHAPTER / "event_bus_probe.py"
    spec = importlib.util.spec_from_file_location("teaching_ch13_event_bus_probe", path)
    assert spec is not None and spec.loader is not None
    module = importlib.util.module_from_spec(spec)
    sys.modules[spec.name] = module
    spec.loader.exec_module(module)
    return module


def test_event_bus_probe_covers_both_provider_catalogs(capsys) -> None:
    probe = _load_probe()
    rows = probe.catalog_rows()

    assert rows == [
        ("stt", "cartesia", True),
        ("stt", "deepgram", True),
        ("stt", "elevenlabs", True),
        ("stt", "openai", True),
        ("stt", "openai-realtime", True),
        ("tts", "cartesia", True),
        ("tts", "deepgram", True),
        ("tts", "elevenlabs", True),
        ("tts", "openai", True),
    ]

    probe.main()
    output = capsys.readouterr().out
    assert "stt      openai           yes" in output
    assert "tts      openai           yes" in output
