W22: coverage metric + network tests + Tool stream feedback + stdin pipe + session path + dependency check (W22.1-W22.6)
Some checks failed
Some checks failed
- W22.1: gcovr 覆盖率度量 + CI coverage job(40% 阈值 warning) - W22.2: network_plugin 单元测试(parse_headers_json/extract_host_port/SSE/异常保护) - W22.3: Tool Calling 流式反馈(chat_stream + "[工具调用]/[工具结果]" 状态行) - W22.4: --prompt stdin pipe(--prompt - 从 stdin 读取) - W22.5: session 路径健壮化(static 缓存 + mkdir + fallback) - W22.6: 插件依赖拓扑静态校验(validate_dependencies 循环/缺失检测) Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -306,11 +306,55 @@ std::vector<int> PluginLoader::topological_sort() const
|
||||
return sorted;
|
||||
}
|
||||
|
||||
int PluginLoader::validate_dependencies() const
|
||||
{
|
||||
int error_count = 0;
|
||||
|
||||
// 构建名称到ID的映射
|
||||
std::unordered_map<std::string, int> name_to_id;
|
||||
for (const auto& [id, plugin] : plugins_) {
|
||||
name_to_id[plugin.name] = id;
|
||||
}
|
||||
|
||||
// 检查1:缺失依赖(deps 引用的插件未加载)
|
||||
for (const auto& [id, plugin] : plugins_) {
|
||||
for (const auto& dep_name : plugin.dependencies) {
|
||||
if (name_to_id.find(dep_name) == name_to_id.end()) {
|
||||
if (host_api_) {
|
||||
host_api_->log(DSTALK_LOG_ERROR,
|
||||
"[plugin_loader] Plugin '%s': dependency '%s' not found (plugin not loaded)",
|
||||
plugin.name.c_str(), dep_name.c_str());
|
||||
}
|
||||
error_count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 检查2:循环依赖(拓扑排序失败)
|
||||
try {
|
||||
topological_sort();
|
||||
} catch (const std::runtime_error&) {
|
||||
if (host_api_) {
|
||||
host_api_->log(DSTALK_LOG_ERROR,
|
||||
"[plugin_loader] Circular dependency detected among loaded plugins");
|
||||
}
|
||||
error_count++;
|
||||
}
|
||||
|
||||
return error_count > 0 ? -1 : 0;
|
||||
}
|
||||
|
||||
int PluginLoader::initialize_all(const dstalk_host_api_t* host_api)
|
||||
{
|
||||
if (!host_api) return -1;
|
||||
host_api_ = host_api;
|
||||
|
||||
// 依赖合法性校验(log 错误但不 crash,继续初始化流程)
|
||||
if (validate_dependencies() != 0) {
|
||||
host_api->log(DSTALK_LOG_WARN,
|
||||
"[plugin_loader] Dependency validation failed; initialization may be incomplete");
|
||||
}
|
||||
|
||||
try {
|
||||
std::vector<int> order = topological_sort();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user