import pytest

from a2a_agent.config import AgentConfig
from a2a_agent.config import DeviceRole
from a2a_agent.runtime import resolve_device_name


def test_resolve_device_name_accepts_alias() -> None:
    config = AgentConfig(
        devices={"windows-cursor": DeviceRole(role="cursor")},
        aliases={"회사 PC": "windows-cursor"},
    )

    assert resolve_device_name(config, "회사 PC") == "windows-cursor"


def test_resolve_device_name_accepts_registered_device() -> None:
    config = AgentConfig(
        devices={"windows-pc": DeviceRole(role="opencode")},
        aliases={"데스크탑 PC": "windows-pc"},
    )

    assert resolve_device_name(config, "windows-pc") == "windows-pc"


def test_resolve_device_name_rejects_unknown_when_devices_are_registered() -> None:
    config = AgentConfig(
        devices={"windows-pc": DeviceRole(role="opencode")},
    )

    with pytest.raises(RuntimeError, match="unknown device or alias"):
        resolve_device_name(config, "회사 PC")
