from data_query_agent.models import IncomingMessage from data_query_agent.service import DataQueryService def message(*, chat_id: str = "allowed", chat_type: str = "group", mentioned: bool = True) -> IncomingMessage: return IncomingMessage( message_id="m1", chat_id=chat_id, chat_type=chat_type, sender_open_id="any-group-member", text="查询昨天 DAU", message_type="text", mentioned_bot=mentioned, ) def test_authorizes_any_member_who_mentions_bot_in_allowed_group() -> None: service = object.__new__(DataQueryService) service.settings = type("Settings", (), {"allowed_chat_ids": frozenset({"allowed"})})() assert service._authorized(message()) is True assert service._authorized(message(chat_id="other")) is False assert service._authorized(message(mentioned=False)) is False assert service._authorized(message(chat_type="p2p")) is False