mirror of
https://gitcode.com/JianFeeeee/ModelRouter.git
synced 2026-11-07 09:47:23 +00:00
产品名早已是 ModelRouter,但仓库标识符仍沿用旧名。这次统一,读写两侧都做兼容, 已部署的机器不会因为顺序问题立刻失效。 - go module `llmsproxy` → `modelrouter`;全仓 import 与 `cmd/modelrouter` 同步。 - `Makefile BINARY=modelrouter`;发行包名、systemd unit、/usr/share 资源、 `/usr/local/bin` 目标全部改为 modelrouter。 - 默认配置目录 `/etc/llmsproxy` → `/etc/modelrouter`。**读取侧回退**:插件与 `storeDir` 仍会检查旧路径,所以"先换二进制、后改 unit"不会立即失效。 - 环境变量 `LLMSPROXY_*`(PLUGIN_DIR / XDISPLAY_BASE / ARCH / LIVE_ZEN / BUILD_DIR)改为 `MODELROUTER_*`;`LLMS_PROXY_MASTER_KEY` → `MODELROUTER_MASTER_KEY`。旧名在读取侧继续接受。 - 桌面端内嵌核心 `bin/llmsproxy` → `bin/modelrouter`,并保留旧文件名回退, 避免升级到一半的 profile 被判成"core binary missing"。 - 新增 `packaging/migrate-to-modelrouter.sh`:**默认 dry-run**,复制而非移动、 旧目录永不删除、支持 `--rollback`;随 release tar 分发并由 core-dist 校验。 - `deploy.sh` 增加改名保护:发现旧 `/etc/llmsproxy` 而新配置不存在时**中止**, 否则会部署出一个"能启动但没有 key、没有源"的空实例。 - 临时目录前缀 `/tmp/llmsproxy-*` → `/tmp/modelrouter-*`;清理逻辑同时回收两代。 兼容别名(`__llmsproxy_*` 全局、`llmsproxy` SDK 别名、旧路径/旧 env)刻意保留, 它们是升级路径而非遗留;docs/plugins.md 已标注为废弃。 本提交未包含:`adapters/opencodezen.lua`、`adapter_opencodezen_test.go`、 `adapter_opencodezen_live_test.go`(OpenCode UA/免费池的既有改动,另批提交)。
111 lines
4.1 KiB
Go
111 lines
4.1 KiB
Go
package core
|
||
|
||
import (
|
||
"encoding/json"
|
||
"fmt"
|
||
"net/http"
|
||
"net/http/httptest"
|
||
"testing"
|
||
|
||
"modelrouter/internal/lua"
|
||
)
|
||
|
||
// 有道每日活动领取是**三步流程**,参考注释点名:无可用活动是**正常业务状态**,
|
||
// 不能显示成"领取失败"(否则用户会去查网络/账号,方向全错)。
|
||
// 本判据钉住决策表的四类结果:inactive / already-claimed / success / failed。
|
||
func TestLobsterActivityClaimDecisionTable(t *testing.T) {
|
||
type c struct {
|
||
name string
|
||
slot string
|
||
ctx string
|
||
wantKind string
|
||
wantCalled bool // 是否应发出 claim 请求
|
||
}
|
||
cases := []c{
|
||
{"槽位不可用→inactive", `{"code":0,"data":{"slotState":"unavailable","activity":{"activityCode":"A1"}}}`, "", "inactive", false},
|
||
{"无 activityCode→inactive", `{"code":0,"data":{"slotState":"available","activity":{}}}`, "", "inactive", false},
|
||
{"今天已领→already-claimed", `{"code":0,"data":{"slotState":"available","activity":{"activityCode":"A1","configRevision":7}}}`,
|
||
`{"code":0,"data":{"state":{"claimedToday":true},"actions":["check_in"]}}`, "already-claimed", false},
|
||
{"无 check_in 动作→inactive", `{"code":0,"data":{"slotState":"available","activity":{"activityCode":"A1","configRevision":7}}}`,
|
||
`{"code":0,"data":{"state":{"claimedToday":false},"actions":["share"]}}`, "inactive", false},
|
||
{"可领→success", `{"code":0,"data":{"slotState":"available","activity":{"activityCode":"A1","configRevision":7}}}`,
|
||
`{"code":0,"data":{"state":{"claimedToday":false},"actions":["check_in"]}}`, "success", true},
|
||
}
|
||
for _, tc := range cases {
|
||
t.Run(tc.name, func(t *testing.T) {
|
||
claimHit := 0
|
||
var claimBody string
|
||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||
w.Header().Set("Content-Type", "application/json")
|
||
switch {
|
||
case r.URL.Path == "/api/client-activities/slot":
|
||
fmt.Fprint(w, tc.slot)
|
||
case r.URL.Path == "/api/client-activities/A1/context":
|
||
if tc.ctx == "" {
|
||
w.WriteHeader(500)
|
||
return
|
||
}
|
||
fmt.Fprint(w, tc.ctx)
|
||
case r.URL.Path == "/api/client-activities/A1/actions/check_in":
|
||
claimHit++
|
||
b := make([]byte, r.ContentLength)
|
||
_, _ = r.Body.Read(b)
|
||
claimBody = string(b)
|
||
fmt.Fprint(w, `{"code":0,"data":{"result":{"creditsGranted":30}}}`)
|
||
default:
|
||
w.WriteHeader(404)
|
||
}
|
||
}))
|
||
defer ts.Close()
|
||
|
||
c := kernelTestCore(t)
|
||
ps := c.Plugins()
|
||
src, err := readBundledChannels(t)
|
||
if err != nil {
|
||
t.Fatal(err)
|
||
}
|
||
if err := ps.LoadSource("channels", src); err != nil {
|
||
t.Fatal(err)
|
||
}
|
||
// 把账号基址指到假上游
|
||
if _, err := ps.Call("channels", "set_endpoints", map[string]interface{}{
|
||
"platform": "lobsterai",
|
||
"lobster_activity_base": map[string]interface{}{"url": ts.URL},
|
||
}); err != nil {
|
||
t.Fatal(err)
|
||
}
|
||
// 存入凭据(claim 需要结构化 credential 对象)
|
||
cred, _ := json.Marshal(map[string]interface{}{"access_token": "AT-1", "uid": "u1"})
|
||
body, _ := json.Marshal(map[string]string{
|
||
"platform": "lobsterai", "credential": string(cred), "account": "t",
|
||
})
|
||
if _, err := ps.InvokeHandler("channels", "complete_login", &lua.HandlerRequest{
|
||
Method: "POST", Role: "admin", Body: string(body),
|
||
}); err != nil {
|
||
t.Fatal(err)
|
||
}
|
||
|
||
out, err := ps.InvokeHandler("channels", "claim_daily", &lua.HandlerRequest{
|
||
Method: "POST", Role: "admin", Body: `{"platform":"lobsterai"}`,
|
||
})
|
||
if err != nil {
|
||
t.Fatalf("claim_daily: %v", err)
|
||
}
|
||
j, _ := out.JSON.(map[string]interface{})
|
||
oc, _ := j["outcome"].(map[string]interface{})
|
||
if oc == nil {
|
||
t.Fatalf("应返回 outcome 判别联合,实得 %v", j)
|
||
}
|
||
if k, _ := oc["kind"].(string); k != tc.wantKind {
|
||
t.Fatalf("kind 应为 %s,实得 %v(%v)", tc.wantKind, oc["kind"], oc["message"])
|
||
}
|
||
if (claimHit > 0) != tc.wantCalled {
|
||
t.Errorf("claim 请求次数 = %d,期望发出=%v", claimHit, tc.wantCalled)
|
||
}
|
||
if tc.wantCalled && claimBody == "" {
|
||
t.Error("claim 请求体不应为空(要带 configRevision 与幂等键)")
|
||
}
|
||
})
|
||
}
|
||
}
|