from __future__ import annotations import pytest from yuxi.channels.policy.directory import BaseDirectoryAdapter class TestBaseDirectoryAdapter: @pytest.mark.asyncio async def test_search_peers_default_returns_empty(self): class ConcreteAdapter(BaseDirectoryAdapter): async def list_peers(self, config: dict, account_id: str = "default") -> list[dict]: return [] async def list_groups(self, config: dict, account_id: str = "default") -> list[dict]: return [] adapter = ConcreteAdapter() result = await adapter.search_peers("test query") assert result == [] @pytest.mark.asyncio async def test_custom_search_peers_override(self): class CustomAdapter(BaseDirectoryAdapter): async def list_peers(self, config: dict, account_id: str = "default") -> list[dict]: return [] async def list_groups(self, config: dict, account_id: str = "default") -> list[dict]: return [] def search_peers(self, query: str) -> list[dict]: return [{"id": "1", "name": query}] adapter = CustomAdapter() result = adapter.search_peers("alice") assert result == [{"id": "1", "name": "alice"}] @pytest.mark.asyncio async def test_list_peers_contract(self): class Adapter(BaseDirectoryAdapter): async def list_peers(self, config: dict, account_id: str = "default") -> list[dict]: return [{"id": "p1", "name": "User1"}] async def list_groups(self, config: dict, account_id: str = "default") -> list[dict]: return [{"id": "g1", "name": "Group1"}] adapter = Adapter() peers = await adapter.list_peers({}) assert isinstance(peers, list) assert len(peers) == 1 assert peers[0]["id"] == "p1" groups = await adapter.list_groups({}) assert isinstance(groups, list) assert len(groups) == 1 assert groups[0]["id"] == "g1" def test_cannot_instantiate_abstract(self): with pytest.raises(TypeError): BaseDirectoryAdapter()