feat:修复部分模型请求问题(v4l)
This commit is contained in:
@@ -11,6 +11,7 @@ from typing import Any, Awaitable, Callable, Dict, List, Optional, Sequence
|
||||
|
||||
import asyncio
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
|
||||
@@ -610,6 +611,33 @@ class TestSDK:
|
||||
assert plugin.configs == [{"plugin_enabled": True}]
|
||||
assert plugin.updates == [("model", {"models": []}, "", [{"plugin_enabled": True}])]
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_host_logs_runner_ready_plugin_failures(self, caplog):
|
||||
"""Host 收到 runner.ready 时应明确记录插件注册失败。"""
|
||||
from src.plugin_runtime.host.supervisor import PluginRunnerSupervisor
|
||||
from src.plugin_runtime.protocol.envelope import Envelope, MessageType
|
||||
|
||||
supervisor = PluginRunnerSupervisor(plugin_dirs=[], runner_spawn_timeout_sec=1)
|
||||
envelope = Envelope(
|
||||
request_id=1,
|
||||
message_type=MessageType.REQUEST,
|
||||
method="runner.ready",
|
||||
plugin_id="",
|
||||
payload={
|
||||
"loaded_plugins": ["ok_plugin"],
|
||||
"failed_plugins": ["bad_plugin"],
|
||||
"inactive_plugins": ["disabled_plugin"],
|
||||
},
|
||||
)
|
||||
|
||||
with caplog.at_level(logging.INFO, logger="plugin_runtime.host.runner_manager"):
|
||||
response = await supervisor._handle_runner_ready(envelope)
|
||||
|
||||
assert response.payload["accepted"] is True
|
||||
assert "插件注册失败: bad_plugin" in caplog.text
|
||||
assert "插件未激活: disabled_plugin" in caplog.text
|
||||
assert "Runner 插件初始化完成: loaded=1 failed=1 inactive=1" in caplog.text
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_runner_bootstraps_capabilities_before_on_load(self, monkeypatch):
|
||||
"""on_load 期间的 capability 调用应在 bootstrap 后生效。"""
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from types import SimpleNamespace
|
||||
from typing import Any
|
||||
import importlib.util
|
||||
import sys
|
||||
|
||||
@@ -220,3 +221,77 @@ def test_mute_plugin_exports_allowed_groups_as_component_allowed_session() -> No
|
||||
assert mute_components[0]["chat_scope"] == "group"
|
||||
assert mute_components[0]["allowed_session"] == ["qq:10001", "raw-group-id"]
|
||||
assert "allowed_session" not in mute_components[0]["metadata"]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_mute_tool_queries_target_message_with_current_chat_id() -> None:
|
||||
module_path = "plugins/MutePlugin/plugin.py"
|
||||
spec = importlib.util.spec_from_file_location("mute_plugin_under_test_msg_id", module_path)
|
||||
assert spec is not None
|
||||
assert spec.loader is not None
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
sys.modules[spec.name] = module
|
||||
spec.loader.exec_module(module)
|
||||
module.MutePluginConfig.model_rebuild()
|
||||
|
||||
capability_calls: list[dict[str, Any]] = []
|
||||
api_calls: list[dict[str, Any]] = []
|
||||
|
||||
async def fake_call_capability(name: str, **kwargs: Any) -> dict[str, Any]:
|
||||
capability_calls.append({"name": name, **kwargs})
|
||||
return {
|
||||
"success": True,
|
||||
"result": {
|
||||
"success": True,
|
||||
"message": {
|
||||
"message_info": {
|
||||
"user_info": {
|
||||
"user_id": "35529667",
|
||||
"user_cardname": "目标用户",
|
||||
"user_nickname": "目标昵称",
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
async def fake_api_call(api_name: str, **kwargs: Any) -> dict[str, Any]:
|
||||
api_calls.append({"name": api_name, **kwargs})
|
||||
if api_name == "adapter.napcat.group.get_group_member_info":
|
||||
return {"success": True, "result": {"data": {"role": "member"}}}
|
||||
return {"status": "ok", "retcode": 0}
|
||||
|
||||
plugin = module.MutePlugin()
|
||||
plugin.set_plugin_config({"components": {"enable_smart_mute": True}})
|
||||
plugin._set_context(
|
||||
SimpleNamespace(
|
||||
call_capability=fake_call_capability,
|
||||
api=SimpleNamespace(call=fake_api_call),
|
||||
logger=SimpleNamespace(info=lambda *args, **kwargs: None, warning=lambda *args, **kwargs: None),
|
||||
)
|
||||
)
|
||||
|
||||
success, message = await plugin.handle_mute_tool(
|
||||
stream_id="current-session-id",
|
||||
group_id="766798517",
|
||||
msg_id="2046083292",
|
||||
duration=3600,
|
||||
reason="测试",
|
||||
)
|
||||
|
||||
assert success is True
|
||||
assert message == "成功禁言 目标用户"
|
||||
assert capability_calls == [
|
||||
{
|
||||
"name": "message.get_by_id",
|
||||
"message_id": "2046083292",
|
||||
"chat_id": "current-session-id",
|
||||
}
|
||||
]
|
||||
assert api_calls[-1] == {
|
||||
"name": "adapter.napcat.group.set_group_ban",
|
||||
"version": "1",
|
||||
"group_id": "766798517",
|
||||
"user_id": "35529667",
|
||||
"duration": 3600,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user