feat: 实现动态插件系统 (6阶段完成)
- 阶段1: 消息类型序列化 (Serialize/Deserialize, &'static str → String) - 阶段2: FFI 边界类型 + Plugin SDK (plugin_abi, showen-plugin-sdk crate) - 阶段3: PluginLoader + DynamicPlugin (libloading 动态加载 .so) - 阶段4: 版本管理 + 错误策略 (VersionManager, PluginState, 自动回退) - 阶段5: 远程仓库客户端 (HTTP 下载 + tar.gz 安装) - 阶段6: 示例插件 + HTTP 管理 API + 全目录 README 文档 54/54 测试通过,0 warnings。 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -77,14 +77,18 @@ fn message_label(message: &Message) -> String {
|
||||
}
|
||||
|
||||
struct TestPlugin {
|
||||
id: &'static str,
|
||||
deps: Vec<&'static str>,
|
||||
id: String,
|
||||
deps: Vec<String>,
|
||||
events: Arc<Mutex<Vec<String>>>,
|
||||
}
|
||||
|
||||
impl TestPlugin {
|
||||
fn new(id: &'static str, deps: Vec<&'static str>, events: Arc<Mutex<Vec<String>>>) -> Self {
|
||||
Self { id, deps, events }
|
||||
fn new(id: &str, deps: Vec<&str>, events: Arc<Mutex<Vec<String>>>) -> Self {
|
||||
Self {
|
||||
id: id.to_string(),
|
||||
deps: deps.into_iter().map(|s| s.to_string()).collect(),
|
||||
events,
|
||||
}
|
||||
}
|
||||
|
||||
fn record(&self, entry: impl Into<String>) {
|
||||
@@ -93,20 +97,20 @@ impl TestPlugin {
|
||||
}
|
||||
|
||||
impl Plugin for TestPlugin {
|
||||
fn id(&self) -> &'static str {
|
||||
self.id
|
||||
fn id(&self) -> &str {
|
||||
&self.id
|
||||
}
|
||||
|
||||
fn info(&self) -> PluginInfo {
|
||||
PluginInfo {
|
||||
name: self.id,
|
||||
version: "test",
|
||||
description: "test plugin",
|
||||
name: self.id.clone(),
|
||||
version: "test".to_string(),
|
||||
description: "test plugin".to_string(),
|
||||
platform: Platform::Any,
|
||||
}
|
||||
}
|
||||
|
||||
fn dependencies(&self) -> Vec<&'static str> {
|
||||
fn dependencies(&self) -> Vec<String> {
|
||||
self.deps.clone()
|
||||
}
|
||||
|
||||
@@ -168,8 +172,8 @@ fn routes_plugin_broadcast_and_manager_messages() {
|
||||
|
||||
sender
|
||||
.send(Envelope {
|
||||
from: "alpha",
|
||||
to: Destination::Plugin("beta"),
|
||||
from: "alpha".to_string(),
|
||||
to: Destination::Plugin("beta".to_string()),
|
||||
message: Message::Custom {
|
||||
kind: "direct".to_string(),
|
||||
payload: "hello".to_string(),
|
||||
@@ -178,7 +182,7 @@ fn routes_plugin_broadcast_and_manager_messages() {
|
||||
.expect("direct message should send");
|
||||
sender
|
||||
.send(Envelope {
|
||||
from: "alpha",
|
||||
from: "alpha".to_string(),
|
||||
to: Destination::Broadcast,
|
||||
message: Message::Custom {
|
||||
kind: "broadcast".to_string(),
|
||||
@@ -188,14 +192,14 @@ fn routes_plugin_broadcast_and_manager_messages() {
|
||||
.expect("broadcast message should send");
|
||||
sender
|
||||
.send(Envelope {
|
||||
from: "alpha",
|
||||
from: "alpha".to_string(),
|
||||
to: Destination::Manager,
|
||||
message: Message::PluginReady("alpha"),
|
||||
message: Message::PluginReady("alpha".to_string()),
|
||||
})
|
||||
.expect("manager message should send");
|
||||
sender
|
||||
.send(Envelope {
|
||||
from: "test",
|
||||
from: "test".to_string(),
|
||||
to: Destination::Manager,
|
||||
message: Message::Shutdown,
|
||||
})
|
||||
@@ -301,14 +305,14 @@ fn wifi_result_sent_to_manager_is_broadcast_to_plugins() {
|
||||
|
||||
sender
|
||||
.send(Envelope {
|
||||
from: "wifi",
|
||||
from: "wifi".to_string(),
|
||||
to: Destination::Manager,
|
||||
message: Message::WifiResult("connected".to_string()),
|
||||
})
|
||||
.expect("wifi result should send");
|
||||
sender
|
||||
.send(Envelope {
|
||||
from: "test",
|
||||
from: "test".to_string(),
|
||||
to: Destination::Manager,
|
||||
message: Message::Shutdown,
|
||||
})
|
||||
@@ -379,8 +383,8 @@ fn all_plugin_ids_must_be_unique() {
|
||||
|
||||
let mut ids = HashSet::new();
|
||||
for plugin in plugins {
|
||||
let id = plugin.id();
|
||||
assert!(ids.insert(id), "duplicate plugin id detected: '{}'", id);
|
||||
let id = plugin.id().to_string();
|
||||
assert!(ids.insert(id.clone()), "duplicate plugin id detected: '{}'", id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user