mirror of
https://gitcode.com/JianFeeeee/ModelRouter.git
synced 2026-11-12 04:07:25 +00:00
fix(plugins): 新内置插件要能落地 —— SeedBundled 改为按文件补齐,deploy.sh 补插件同步
真实事故:channels.lua(多平台账号接入插件)在仓库里、在 2.0 二进制里 (go:embed),生产却完全看不到它 —— /api/plugins 只有 billing/quota/usage。 根因是两处叠加: 1. SeedBundled 只在 plugin_dir **不存在**时才写内置插件。生产 plugin_dir 从 首次安装起就存在,于是后来加入二进制的新插件永远不会落盘。目录存在不等于 内容是最新的 —— 这个假设把"新增内置插件"整条路径堵死了。 改为**按文件补齐**:只在该文件缺失时才 seed,已存在的一律不动(运维自己改 过、或运行时新增的插件必须跨升级存活 —— 与适配器同一条规则)。 2. deploy.sh 完全不处理 plugins(只同步 adapters/)。即使内核修好了,部署脚本 也没有把插件内容与仓库对齐的动作。新增 sync_plugins:备份、只补缺、对已有 文件零改动、末尾逐个校验内嵌插件都在目标目录,摘要里打印插件目录。 测试(internal/lua/vm_test.go): - TestSeedBundledFillsMissingFilesInExistingDir:构造确切事故条件(目录已存在、 只有部分插件),断言缺失的被补齐、运维自己的 billing.lua 不被覆盖、补齐后 channels 确实出现在插件表里。 - TestSeedBundledIdempotent:二次 seed 不覆盖已就位文件。 deploy.sh 通过 bash -n;go test ./internal/lua/ 全绿。
This commit is contained in:
@ -744,11 +744,21 @@ func writeBundledPlugins(dir string) error {
|
||||
if e.IsDir() || filepath.Ext(e.Name()) != ".lua" {
|
||||
continue
|
||||
}
|
||||
dst := filepath.Join(dir, e.Name())
|
||||
// Per-file seeding: a plugin already present is left ALONE. That is what
|
||||
// makes an operator's own copy (or a locally edited one) survive an
|
||||
// upgrade, and it is also why a newly embedded plugin still arrives —
|
||||
// absence of THAT file, not of the directory, is the trigger.
|
||||
if _, err := os.Stat(dst); err == nil {
|
||||
continue
|
||||
} else if !os.IsNotExist(err) {
|
||||
return err
|
||||
}
|
||||
data, err := bundledAdapters.ReadFile(bundledPluginsDir + "/" + e.Name())
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
if err := os.WriteFile(filepath.Join(dir, e.Name()), data, 0644); err != nil {
|
||||
if err := os.WriteFile(dst, data, 0644); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user