Remove unused HTML files and hexToRgba function from the web directory
This commit is contained in:
@@ -65,6 +65,93 @@ class _FakeGatewayCapability:
|
||||
return True
|
||||
|
||||
|
||||
class _FakeNapCatQueryService:
|
||||
"""用于驱动 NapCat 入站编解码测试的查询服务替身。"""
|
||||
|
||||
def __init__(self, forward_payloads: Dict[str, Any] | None = None) -> None:
|
||||
"""初始化查询服务替身。
|
||||
|
||||
Args:
|
||||
forward_payloads: 预置的合并转发响应映射。
|
||||
"""
|
||||
self._forward_payloads = forward_payloads or {}
|
||||
|
||||
async def download_binary(self, url: str) -> bytes | None:
|
||||
"""模拟下载远程二进制资源。
|
||||
|
||||
Args:
|
||||
url: 资源地址。
|
||||
|
||||
Returns:
|
||||
bytes | None: 测试中默认不返回二进制内容。
|
||||
"""
|
||||
del url
|
||||
return None
|
||||
|
||||
async def get_message_detail(self, message_id: str) -> Dict[str, Any] | None:
|
||||
"""模拟获取消息详情。
|
||||
|
||||
Args:
|
||||
message_id: 消息 ID。
|
||||
|
||||
Returns:
|
||||
Dict[str, Any] | None: 测试中默认不返回详情。
|
||||
"""
|
||||
del message_id
|
||||
return None
|
||||
|
||||
async def get_forward_message(self, message_id: str) -> Any:
|
||||
"""模拟获取合并转发消息详情。
|
||||
|
||||
Args:
|
||||
message_id: 转发消息 ID。
|
||||
|
||||
Returns:
|
||||
Any: 预置的合并转发消息详情。
|
||||
"""
|
||||
return self._forward_payloads.get(message_id)
|
||||
|
||||
async def get_record_detail(self, file_name: str, file_id: str | None = None) -> Dict[str, Any] | None:
|
||||
"""模拟获取语音详情。
|
||||
|
||||
Args:
|
||||
file_name: 文件名。
|
||||
file_id: 文件 ID。
|
||||
|
||||
Returns:
|
||||
Dict[str, Any] | None: 测试中默认不返回语音详情。
|
||||
"""
|
||||
del file_name
|
||||
del file_id
|
||||
return None
|
||||
|
||||
|
||||
class _FakeNapCatActionService:
|
||||
"""用于驱动 NapCat 查询服务测试的动作服务替身。"""
|
||||
|
||||
def __init__(self, response_data: Any) -> None:
|
||||
"""初始化动作服务替身。
|
||||
|
||||
Args:
|
||||
response_data: 预置的 ``safe_call_action_data`` 返回值。
|
||||
"""
|
||||
self._response_data = response_data
|
||||
|
||||
async def safe_call_action_data(self, action_name: str, params: Dict[str, Any]) -> Any:
|
||||
"""模拟安全调用 OneBot 动作。
|
||||
|
||||
Args:
|
||||
action_name: 动作名称。
|
||||
params: 动作参数。
|
||||
|
||||
Returns:
|
||||
Any: 预置返回值。
|
||||
"""
|
||||
del action_name
|
||||
del params
|
||||
return self._response_data
|
||||
|
||||
|
||||
def _load_napcat_sdk_modules() -> Tuple[Any, Any, Any, Any]:
|
||||
"""动态加载 NapCat 插件测试所需的模块。
|
||||
|
||||
@@ -116,6 +203,28 @@ def _load_napcat_sdk_symbols() -> Tuple[Any, Any, Any, Any]:
|
||||
)
|
||||
|
||||
|
||||
def _load_napcat_inbound_codec_cls() -> Any:
|
||||
"""动态加载 NapCat 入站编解码器类。
|
||||
|
||||
Returns:
|
||||
Any: ``NapCatInboundCodec`` 类对象。
|
||||
"""
|
||||
_load_napcat_sdk_modules()
|
||||
codec_module = import_module(f"{NAPCAT_TEST_MODULE}.codecs.inbound.message_codec")
|
||||
return codec_module.NapCatInboundCodec
|
||||
|
||||
|
||||
def _load_napcat_query_service_cls() -> Any:
|
||||
"""动态加载 NapCat 查询服务类。
|
||||
|
||||
Returns:
|
||||
Any: ``NapCatQueryService`` 类对象。
|
||||
"""
|
||||
_load_napcat_sdk_modules()
|
||||
query_service_module = import_module(f"{NAPCAT_TEST_MODULE}.services.query_service")
|
||||
return query_service_module.NapCatQueryService
|
||||
|
||||
|
||||
def test_napcat_plugin_collects_duplex_message_gateway() -> None:
|
||||
"""NapCat 插件应声明新的双工消息网关组件。"""
|
||||
|
||||
@@ -161,7 +270,7 @@ def test_napcat_plugin_normalizes_legacy_config_values() -> None:
|
||||
|
||||
plugin.set_plugin_config(
|
||||
{
|
||||
"plugin": {"enabled": True, "config_version": ""},
|
||||
"plugin": {"enabled": True, "config_version": constants_module.SUPPORTED_CONFIG_VERSION},
|
||||
"connection": {
|
||||
"access_token": "secret-token",
|
||||
"heartbeat_sec": "45",
|
||||
@@ -220,3 +329,121 @@ async def test_runtime_state_reports_via_gateway_capability() -> None:
|
||||
assert gateway_capability.calls[1]["gateway_name"] == napcat_gateway_name
|
||||
assert gateway_capability.calls[1]["ready"] is False
|
||||
assert gateway_capability.calls[1]["platform"] == "qq"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_inbound_codec_parses_forward_nodes_from_legacy_message_field() -> None:
|
||||
"""入站编解码器应兼容旧版 ``sender + message`` 转发节点结构。"""
|
||||
|
||||
inbound_codec_cls = _load_napcat_inbound_codec_cls()
|
||||
codec = inbound_codec_cls(
|
||||
logger=logging.getLogger("test.napcat_adapter.forward_legacy"),
|
||||
query_service=_FakeNapCatQueryService(
|
||||
forward_payloads={
|
||||
"forward-1": {
|
||||
"messages": [
|
||||
{
|
||||
"sender": {"user_id": "10001", "nickname": "张三", "card": "群名片"},
|
||||
"message_id": "node-1",
|
||||
"message": [{"type": "text", "data": {"text": "第一条转发"}}],
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
),
|
||||
)
|
||||
|
||||
segments, is_at = await codec.convert_segments(
|
||||
{"message": [{"type": "forward", "data": {"id": "forward-1"}}]},
|
||||
"",
|
||||
)
|
||||
|
||||
assert is_at is False
|
||||
assert len(segments) == 1
|
||||
assert segments[0]["type"] == "forward"
|
||||
assert segments[0]["data"][0]["user_id"] == "10001"
|
||||
assert segments[0]["data"][0]["user_nickname"] == "张三"
|
||||
assert segments[0]["data"][0]["user_cardname"] == "群名片"
|
||||
assert segments[0]["data"][0]["content"] == [{"type": "text", "data": "第一条转发"}]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_inbound_codec_parses_nested_inline_forward_content() -> None:
|
||||
"""入站编解码器应支持内联 ``content`` 形式的嵌套合并转发。"""
|
||||
|
||||
inbound_codec_cls = _load_napcat_inbound_codec_cls()
|
||||
codec = inbound_codec_cls(
|
||||
logger=logging.getLogger("test.napcat_adapter.forward_nested"),
|
||||
query_service=_FakeNapCatQueryService(
|
||||
forward_payloads={
|
||||
"forward-outer": {
|
||||
"messages": [
|
||||
{
|
||||
"sender": {"user_id": "10001", "nickname": "张三"},
|
||||
"message_id": "node-outer",
|
||||
"message": [
|
||||
{
|
||||
"type": "forward",
|
||||
"data": {
|
||||
"content": [
|
||||
{
|
||||
"sender": {"user_id": "10002", "nickname": "李四"},
|
||||
"message_id": "node-inner",
|
||||
"message": [{"type": "text", "data": {"text": "内层消息"}}],
|
||||
}
|
||||
]
|
||||
},
|
||||
}
|
||||
],
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
),
|
||||
)
|
||||
|
||||
segments, _ = await codec.convert_segments(
|
||||
{"message": [{"type": "forward", "data": {"id": "forward-outer"}}]},
|
||||
"",
|
||||
)
|
||||
|
||||
assert len(segments) == 1
|
||||
assert segments[0]["type"] == "forward"
|
||||
outer_content = segments[0]["data"][0]["content"]
|
||||
assert len(outer_content) == 1
|
||||
assert outer_content[0]["type"] == "forward"
|
||||
nested_nodes = outer_content[0]["data"]
|
||||
assert nested_nodes[0]["user_id"] == "10002"
|
||||
assert nested_nodes[0]["user_nickname"] == "李四"
|
||||
assert nested_nodes[0]["content"] == [{"type": "text", "data": "内层消息"}]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_query_service_normalizes_forward_payload_list() -> None:
|
||||
"""查询服务应兼容 ``get_forward_msg`` 直接返回节点列表。"""
|
||||
|
||||
query_service_cls = _load_napcat_query_service_cls()
|
||||
query_service = query_service_cls(
|
||||
action_service=_FakeNapCatActionService(
|
||||
[
|
||||
{
|
||||
"sender": {"user_id": "10001", "nickname": "张三"},
|
||||
"message_id": "node-1",
|
||||
"message": [{"type": "text", "data": {"text": "列表返回"}}],
|
||||
}
|
||||
]
|
||||
),
|
||||
logger=logging.getLogger("test.napcat_adapter.query_service"),
|
||||
)
|
||||
|
||||
forward_payload = await query_service.get_forward_message("forward-1")
|
||||
|
||||
assert forward_payload == {
|
||||
"messages": [
|
||||
{
|
||||
"sender": {"user_id": "10001", "nickname": "张三"},
|
||||
"message_id": "node-1",
|
||||
"message": [{"type": "text", "data": {"text": "列表返回"}}],
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user