mirror of
https://gitcode.com/JianFeeeee/ModelRouter.git
synced 2026-11-07 09:47:23 +00:00
按发布纪律回流。**注意这是内容对齐而非 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 ./...` 通过。
103 lines
4.3 KiB
Go
103 lines
4.3 KiB
Go
package lua
|
||
|
||
import (
|
||
"encoding/json"
|
||
"strings"
|
||
"testing"
|
||
)
|
||
|
||
// TRAE 不是 OpenAI 兼容:参考 trae.ts:30 明确「载荷必须转换 —— 映射为 SOLO
|
||
// 格式(function、config_name 等字段),不能透传」。此前我们把 trae 声明成
|
||
// adapter=openai 直发,端点对了、载荷全错。
|
||
//
|
||
// 本测试走**真实路径**:装插件(插件自己装 channels-trae 适配器)→ 用
|
||
// vm.Transform 调那个**已安装**的适配器。这比在插件 VM 里 load 一份副本更
|
||
// 可信:副本拿不到内核注入的共享前导,且无法发现"装了但没生效"。
|
||
func TestChannelsTraeSoloAdapter(t *testing.T) {
|
||
vm, ps, _ := runtimePlugins(t)
|
||
src, err := bundledAdapters.ReadFile("plugins/channels.lua")
|
||
if err != nil {
|
||
t.Fatal(err)
|
||
}
|
||
if err := ps.LoadSource("channels", string(src)); err != nil {
|
||
t.Fatal(err)
|
||
}
|
||
// 插件应在加载时自装 TRAE SOLO 适配器(名字 channels-trae,避开内置 trae)
|
||
names := map[string]bool{}
|
||
for _, a := range vm.ListAdapters() {
|
||
names[a.Name] = true
|
||
}
|
||
if !names["channels-trae"] {
|
||
t.Fatalf("插件未装 channels-trae 适配器;已装: %v", names)
|
||
}
|
||
if owner := ps.AdapterOwnerOf("channels-trae"); owner != "channels" {
|
||
t.Errorf("归属应为 channels,实得 %q", owner)
|
||
}
|
||
// 内置 trae(供运维的 trae-local-api 反代用)必须**不被顶掉**
|
||
if !names["trae"] {
|
||
t.Error("内置 trae 适配器被顶掉了(它仍服务运维自建的本地反代)")
|
||
}
|
||
|
||
in := `{"model":"glm-5.2","messages":[` +
|
||
`{"role":"system","content":"you are helpful"},` +
|
||
`{"role":"user","content":"hi"},` +
|
||
`{"role":"assistant","content":"ok","tool_calls":[` +
|
||
`{"id":"c1","type":"function","function":{"name":"f","arguments":"{}"}},` +
|
||
`{"id":"c2","type":"function","function":{"name":"","arguments":"{}"}}]}` +
|
||
`],"tools":[{"type":"function","function":{"name":"f","description":"d",` +
|
||
`"parameters":{"type":"object","properties":{"a":{"type":"string"}}}}}],` +
|
||
`"tool_choice":{"type":"function","function":{"name":"f"}},` +
|
||
`"stream":false,"extra_body":{"x":1}}`
|
||
out, err := vm.Transform("channels-trae", "transform_request", in)
|
||
if err != nil {
|
||
t.Fatalf("Transform: %v", err)
|
||
}
|
||
t.Logf("SOLO 载荷: %s", out)
|
||
|
||
for _, want := range []struct{ desc, needle string }{
|
||
{"规则2 stream 必须强制 true(非流式由服务端聚合)", `"stream":true`},
|
||
{"规则3 model → config_name + model 双字段", `"config_name":"glm-5.2"`},
|
||
{"规则4 function 通道(缺省 solo_work_lite)", `"function":"solo_work_lite"`},
|
||
{"规则1 content 字符串 → parts 数组", `"text":"hi"`},
|
||
{"规则6 tool_calls 的 function → function_call", `"function_call"`},
|
||
{"规则7 parameters 必须是 JSON 字符串(SOLO 要求)", `{\"properties\"`},
|
||
{"规则5 tool_choice 为 function 时归一成 name 字符串", `"tool_choice":"f"`},
|
||
} {
|
||
if !strings.Contains(out, want.needle) {
|
||
t.Errorf("%s\n 缺 %s\n 实际: %s", want.desc, want.needle, out)
|
||
}
|
||
}
|
||
// 反向断言
|
||
if strings.Contains(out, `"extra_body"`) {
|
||
t.Errorf("内核私有字段 extra_body 未剥离:%s", out)
|
||
}
|
||
if strings.Contains(out, `"id":"c2"`) {
|
||
t.Errorf("无 name 的 tool_call 应被剔除(孤儿会让整条会话被拒):%s", out)
|
||
}
|
||
// 必须是合法 JSON,且 model/config_name 同值、stream 为 true
|
||
var parsed map[string]interface{}
|
||
if err := json.Unmarshal([]byte(out), &parsed); err != nil {
|
||
t.Fatalf("转换结果不是合法 JSON: %v\n%s", err, out)
|
||
}
|
||
if parsed["model"] != "glm-5.2" || parsed["config_name"] != "glm-5.2" {
|
||
t.Errorf("model/config_name 应同为 glm-5.2:%v / %v", parsed["model"], parsed["config_name"])
|
||
}
|
||
if parsed["stream"] != true {
|
||
t.Errorf("stream 应为 true,实得 %v", parsed["stream"])
|
||
}
|
||
// tool_choice=none 时必须同时删掉 tools 与 tool_choice 本身
|
||
noneIn := `{"model":"glm-5.2","messages":[{"role":"user","content":"x"}],` +
|
||
`"tools":[{"type":"function","function":{"name":"f","parameters":{"type":"object"}}}],` +
|
||
`"tool_choice":"none"}`
|
||
noneOut, err := vm.Transform("channels-trae", "transform_request", noneIn)
|
||
if err != nil {
|
||
t.Fatalf("Transform(none): %v", err)
|
||
}
|
||
if strings.Contains(noneOut, `"tools"`) {
|
||
t.Errorf("tool_choice=none 时 tools 必须被删:%s", noneOut)
|
||
}
|
||
if strings.Contains(noneOut, `"tool_choice"`) {
|
||
t.Errorf("tool_choice=none 时该字段本身也应被删:%s", noneOut)
|
||
}
|
||
}
|