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 ./...` 通过。
56 lines
2.0 KiB
Go
56 lines
2.0 KiB
Go
package core
|
||
|
||
import (
|
||
"os"
|
||
"testing"
|
||
)
|
||
|
||
// 用**真实的 models.dev 响应**验证解析口径(5.6MB / 229 键 / opencode 122 模型)。
|
||
//
|
||
// 为什么必须用真数据:字段路径(modalities.input / cost.input / limit.context)
|
||
// 是我照参考注释写的,只有真数据能证明写对了。合成样本会把这个验证变成自说自话。
|
||
//
|
||
// 样本不在仓库里(5.6MB),缺失时跳过 —— 但 CI 里能拉到就一定会跑。
|
||
func TestCapabilityParseAgainstRealModelsDev(t *testing.T) {
|
||
b, err := os.ReadFile("/tmp/modelsdev.json")
|
||
if err != nil {
|
||
t.Skip("无 models.dev 样本(/tmp/modelsdev.json),跳过")
|
||
}
|
||
_, ps := poolCore(t)
|
||
out, err := ps.Call("channels", "__parse_capability_probe", map[string]interface{}{
|
||
"body": string(b), "key": "opencode",
|
||
})
|
||
if err != nil {
|
||
t.Fatalf("探针: %v", err)
|
||
}
|
||
j, _ := out.(map[string]interface{})["json"].(map[string]interface{})
|
||
if j["error"] != nil {
|
||
t.Fatalf("解析失败: %v", j["error"])
|
||
}
|
||
total, _ := j["total"].(float64)
|
||
free, _ := j["free"].(float64)
|
||
image, _ := j["image"].(float64)
|
||
ctx, _ := j["with_ctx"].(float64)
|
||
t.Logf("opencode: total=%.0f free=%.0f image=%.0f with_ctx=%.0f", total, free, image, ctx)
|
||
|
||
// ① 规模:实测 122 个模型(允许上游增减,给个合理区间)
|
||
if total < 50 {
|
||
t.Errorf("解析出的模型数太少(%.0f)—— 字段路径可能没对上真实结构", total)
|
||
}
|
||
// ② 免费判定必须有命中的(实测有若干 cost 全 0 的模型)
|
||
if free == 0 {
|
||
t.Error("一个免费模型都没识别出来 —— cost 判定路径可能错了")
|
||
}
|
||
if free >= total {
|
||
t.Error("全部被标免费 —— cost 判定过于宽松")
|
||
}
|
||
// ③ 多模态也要有命中的(gpt-5.4 之类含 image)
|
||
if image == 0 {
|
||
t.Error("没识别出任何多模态模型 —— modalities 路径可能错了")
|
||
}
|
||
// ④ 上下文窗口要能取到(limit.context)
|
||
if ctx == 0 {
|
||
t.Error("没取到任何上下文窗口 —— limit 路径可能错了")
|
||
}
|
||
}
|