"""Role routing: resolve_role maps (run_provider, role) → (provider, model) across stacks."""

import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).resolve().parent.parent))

import config
from config import PROVIDERS, resolve_role


def test_default_quick_routes_to_minimax(monkeypatch):
    monkeypatch.setitem(config.ROLE_ROUTING, "quick", "minimax")
    assert resolve_role("claude", "quick") == ("minimax", PROVIDERS["minimax"]["quick"])


def test_default_judge_routes_to_claude(monkeypatch):
    monkeypatch.setitem(config.ROLE_ROUTING, "judge", "claude")
    assert resolve_role("minimax", "judge") == ("claude", PROVIDERS["claude"]["judge"])


def test_empty_routing_keeps_run_provider(monkeypatch):
    monkeypatch.setitem(config.ROLE_ROUTING, "fast", "")
    assert resolve_role("claude", "fast") == ("claude", PROVIDERS["claude"]["fast"])
    assert resolve_role("minimax", "fast") == ("minimax", PROVIDERS["minimax"]["fast"])


def test_explicit_model_syntax(monkeypatch):
    monkeypatch.setitem(config.ROLE_ROUTING, "guide", "claude:claude-opus-4-8")
    assert resolve_role("minimax", "guide") == ("claude", "claude-opus-4-8")


def test_unknown_target_falls_back_to_run_provider(monkeypatch):
    monkeypatch.setitem(config.ROLE_ROUTING, "quick", "gibtsnicht")
    assert resolve_role("claude", "quick") == ("claude", PROVIDERS["claude"]["quick"])


def test_unknown_role_yields_empty_model():
    provider, model = resolve_role("claude", "nope")
    assert provider == "claude"
    assert model == ""
