Files
ModelRouter/internal/lua/plugin_unload_test.go
JianFeeeee 9bec158d2e chore(main): 回流 release/v2.0.x(v2.0.12)—— 内容对齐,main 无独有内容
按发布纪律回流。**注意这是内容对齐而非 merge**,理由与依据:

1. 纪律禁止 merge 回主干,因为 merge 会把发布分支的**版本号变更**带进 main。
   本项目版本号**只由 `git describe --tags` 推导**(Makefile VERSION),
   仓库里没有任何文件存放版本号 ⇒ 回流不存在版本污染风险。
2. 逐项核对确认 **main 是 release 的内容严格子集**:
   - `main` 独有的**文件**:0 个;
   - `internal/lua/plugins.go` / `internal/core/kernel_actions.go` 等内核文件
     main 独有行数:0;
   - `deploy.sh` 那 14 行只是 emoji 清理(release 刻意去掉了 emoji);
   - `channels.lua` 那 333 行是**旧版内容**(旧 exports 表、旧模型名单)。
   - main 独有的 9 个提交按 patch-id **全部已在 release 中等效存在**
     (`git cherry` 逐条列出均为 `-`,即已合入)。
3. 故回流 = 把 release 的内容带到 main,等价于"只捡拾修复、不带版本号",
   且不会丢任何 main 独有的修复。

本次带回 v2.0.12 的全部内容(37 个提交):
- 源串行 + 按模型节流(照 model-gate)
- 已失效模型存储 + 远端目录闸门
- 余额分档选号
- 模型能力元数据(models.dev,isFree 权威判定)
- **凭据续期修复**(此前恒报 ok:true 却一个请求都不发)
- 通用件 TTL 缓存 + 串行锁;account_test/account_adopt/account_delete 修正
- 内核级:出站授权持久化重启后不生效、`__llmsproxy_plugin_dir` ground truth

校验:`git diff release/v2.0.x` = 0 行;`go build -tags luajit ./...` 通过。
2026-10-14 16:52:58 +08:00

53 lines
1.7 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package lua
import (
"os/exec"
"testing"
"time"
)
// TestOnUnloadReapsPluginProcesses 验收通用卸载钩子。
//
// 内核职责是"调度插件"——卸载是调度的一部分,而插件可能持有外部资源(进程、
// 文件句柄、远端会话)。内核不知道也不需要知道这些资源是什么;它只要在关闭
// 状态前给插件一次自清理的机会(on_unload),资源归属就始终在插件侧。
// 本测试用"插件起一个进程、卸载时杀掉"来证明这条链路真的闭合。
func TestOnUnloadReapsPluginProcesses(t *testing.T) {
_, ps, _ := runtimePlugins(t)
code := `
local plugin = { name = "reaper", version = "1.0" }
plugin.exports = { "touch" }
local pid = nil
function plugin.touch()
local h = io.popen("sh -c 'sleep 300 & echo $!'")
pid = h:read("*l"); h:close()
return { status = 200, json = { pid = pid } }
end
function plugin.on_unload()
if pid then os.execute("kill -9 " .. pid .. " 2>/dev/null") end
end
return plugin`
if err := ps.LoadSource("reaper", code); err != nil {
t.Fatal(err)
}
out, err := ps.Call("reaper", "touch", map[string]interface{}{})
if err != nil {
t.Fatal(err)
}
m := out.(map[string]interface{})
js := m["json"].(map[string]interface{})
pid := js["pid"].(string)
time.Sleep(300 * time.Millisecond)
if err := exec.Command("kill", "-0", pid).Run(); err != nil {
t.Fatalf("进程应存活: %v", err)
}
if err := ps.Unload("reaper"); err != nil {
t.Fatalf("unload: %v", err)
}
time.Sleep(500 * time.Millisecond)
if err := exec.Command("kill", "-0", pid).Run(); err == nil {
exec.Command("kill", "-9", pid).Run()
t.Fatal("unload 后进程仍存活 —— on_unload 未被调用")
}
}