mirror of
https://gitcode.com/JianFeeeee/ModelRouter.git
synced 2026-11-07 09:47:23 +00:00
按发布纪律回流。这四笔原本**误提交在 main** 上(我的操作失误): 纪律要求修复先在 release/v2.0.x 提交、再回流 main。已迁移: ① release 上 cherry-pick 这四笔(干净落地); ② main reset 回 9bec158(那四笔未推送,无远端影响); ③ 内容对齐回 main —— 等价于只捡拾修复、不带版本号。 内容: - channels-qoder 适配器:10605(排队) 与 110(额度耗尽) 分开说,厂商码留在插件域 - channels-cline 适配器:解析英文句子里的等待时长(内核按额度耗尽冷却而非 30s 猛敲) - auto_claim:按 covers_today 记账(Qoder 10:00 刷新前不得算已处理)+ 间隔 2 小时 - isFree:改为按平台声明权威来源(cline 用远端 free[]/命名约定,opencode 用 cost) 校验:git diff release/v2.0.x = 0 行;go build 通过。
89 lines
3.7 KiB
Go
89 lines
3.7 KiB
Go
package core
|
||
|
||
import (
|
||
"strings"
|
||
"testing"
|
||
|
||
"llmsproxy/internal/lua"
|
||
)
|
||
|
||
// qoderReason 调真实的 transform_error 钩子(不自己重算)。
|
||
func qoderReason(t *testing.T, vm *lua.VM, status int, body string) string {
|
||
t.Helper()
|
||
reason, ok, err := vm.TransformError("channels-qoder", status, body)
|
||
if err != nil {
|
||
t.Fatalf("transform_error 调用失败: %v", err)
|
||
}
|
||
if !ok {
|
||
t.Fatalf("channels-qoder 适配器未装载或未定义 transform_error(body=%s)", body)
|
||
}
|
||
return reason
|
||
}
|
||
|
||
// Qoder 的错误信封是**双层编码**的,且两个业务码语义**相反**:
|
||
//
|
||
// 10605 排队 → 暂时受阻,等一下就好
|
||
// 110 额度 → 当天耗尽,重试无用(参考实测:原先归成通用服务端错误 → 白重试 5 次)
|
||
//
|
||
// 通用 openai 适配器只能看到外层,产出 `10605: {"isQueued":true,…}` ——
|
||
// 用户看不懂是排队还是额度用完。故用**插件自装的 channels-qoder**,
|
||
// 厂商码值留在插件域(内核零厂商名)。
|
||
func TestQoderAdapterParsesQueueAndBilling(t *testing.T) {
|
||
c, _ := poolCore(t)
|
||
vm := c.VM()
|
||
|
||
// ① 排队:外层 code=10605 + 内层 JSON 字符串(参考实测的真实形状)
|
||
out := qoderReason(t, vm, 403,
|
||
`{"code":"10605","message":"{\"isQueued\":true,\"queueCount\":12,\"retryAfterSeconds\":30}"}`)
|
||
if !strings.Contains(out, "排队") {
|
||
t.Errorf("10605 必须说成排队,实得 %q", out)
|
||
}
|
||
// 等待时长与队列长度要从**内层**取到(只读顶层永远拿不到)
|
||
if !strings.Contains(out, "30") {
|
||
t.Errorf("应从内层取到 retryAfterSeconds=30,实得 %q", out)
|
||
}
|
||
if !strings.Contains(out, "12") {
|
||
t.Errorf("应从内层取到 queueCount=12,实得 %q", out)
|
||
}
|
||
|
||
// ② SSE 错误帧形态:**内层没有 code 字段**,只有排队标志。
|
||
// ⚠️ 参考第一版要求「必须命中 code 才算排队」,导致这一形态被判成非排队、
|
||
// SSE 通道的修复静默失效(探针显示 sleep=0)。这里必须能识别。
|
||
out2 := qoderReason(t, vm, 200,
|
||
`{"message":"{\"isQueued\":true,\"queueCount\":3,\"retryAfterSeconds\":8}"}`)
|
||
if !strings.Contains(out2, "排队") {
|
||
t.Errorf("内层无 code 也必须识别为排队(这是参考踩过的坑),实得 %q", out2)
|
||
}
|
||
if !strings.Contains(out2, "8") {
|
||
t.Errorf("应取到内层 retryAfterSeconds=8,实得 %q", out2)
|
||
}
|
||
|
||
// ③ 额度耗尽:必须与排队**分开说**,且明确"重试无用"
|
||
out3 := qoderReason(t, vm, 403, `{"code":"110","message":"Billing daily count exceeded"}`)
|
||
if !strings.Contains(out3, "额度") {
|
||
t.Errorf("110 必须说成额度耗尽,实得 %q", out3)
|
||
}
|
||
if strings.Contains(out3, "排队") {
|
||
t.Errorf("110 绝不能被说成排队(两者语义相反),实得 %q", out3)
|
||
}
|
||
if !strings.Contains(out3, "重试无用") {
|
||
t.Errorf("额度耗尽要明确告知重试无用,实得 %q", out3)
|
||
}
|
||
|
||
// ④ 泛词不能误伤:正文里讨论"配额/余额"不该被当成额度错误
|
||
//(关键词必须窄 —— 宽词会把模型正常输出误判成故障)
|
||
out4 := qoderReason(t, vm, 500,
|
||
`{"error":{"message":"the response discusses quota and balance concepts"}}`)
|
||
if strings.Contains(out4, "额度已用尽") {
|
||
t.Errorf("泛词 quota/balance 不得误伤(关键词必须窄),实得 %q", out4)
|
||
}
|
||
|
||
// ⑤ 与通用 openai 适配器对比:证明**通用器确实做不到**这件事
|
||
//(否则这个专用适配器就没有存在理由)
|
||
gen, okGen, _ := vm.TransformError("openai", 403,
|
||
`{"code":"10605","message":"{\"isQueued\":true,\"retryAfterSeconds\":30}"}`)
|
||
if okGen && strings.Contains(gen, "排队") {
|
||
t.Error("通用 openai 适配器不该能识别排队 —— 若能,则专用适配器无必要")
|
||
}
|
||
}
|