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/免费池的既有改动,另批提交)。
107 lines
3.3 KiB
Go
107 lines
3.3 KiB
Go
package provider
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
|
|
"modelrouter/internal/config"
|
|
)
|
|
|
|
// TestSourceStatus_CarriesModelKind is the fix for a UI bug where the chat
|
|
// test page listed image models next to chat ones.
|
|
//
|
|
// The root cause was structural, not a missing filter: SourceStatus.Models was
|
|
// a flat []string, so by the time the UI had the list there was nothing left to
|
|
// tell "gpt-image-2" from "claude-sonnet-5.5". Picking the former sent the
|
|
// request to /api/chat, which cannot serve it, and the failure said nothing
|
|
// about the real reason.
|
|
//
|
|
// Models stays a []string for callers that only need names; ModelKinds is the
|
|
// additive field that carries the missing dimension.
|
|
func TestSourceStatus_CarriesModelKind(t *testing.T) {
|
|
src := config.Source{
|
|
Name: "vela",
|
|
BaseURL: "https://example.invalid",
|
|
Adapter: "openai",
|
|
APIKey: "sk-test",
|
|
Endpoint: "/chat/completions",
|
|
Models: []config.Model{
|
|
{ID: "claude-sonnet-5.5"}, // kind omitted -> chat default
|
|
{ID: "gpt-image-2", Kind: "image"}, // image
|
|
{ID: "seedream-5.0", Kind: "image"},
|
|
},
|
|
}
|
|
p := newTestProvider(t, src)
|
|
|
|
kinds := p.ModelsWithKind()
|
|
if len(kinds) != 3 {
|
|
t.Fatalf("want 3 entries, got %d", len(kinds))
|
|
}
|
|
|
|
// Order must mirror Models() so the UI can zip the two lists.
|
|
names := p.Models()
|
|
for i := range kinds {
|
|
if kinds[i].ID != names[i] {
|
|
t.Errorf("index %d: ModelKinds has %q but Models has %q — the lists must stay aligned",
|
|
i, kinds[i].ID, names[i])
|
|
}
|
|
}
|
|
|
|
want := map[string]string{
|
|
"claude-sonnet-5.5": "chat",
|
|
"gpt-image-2": "image",
|
|
"seedream-5.0": "image",
|
|
}
|
|
for _, k := range kinds {
|
|
if got := want[k.ID]; k.Kind != got {
|
|
t.Errorf("%s: kind = %q, want %q", k.ID, k.Kind, got)
|
|
}
|
|
}
|
|
}
|
|
|
|
// TestModelKinds_CountsImageModelsInARealCatalog: the number of image models is
|
|
// what decides whether the UI needs the split at all, so assert against a
|
|
// catalog with both kinds rather than a hand-picked pair.
|
|
func TestModelKinds_CountsImageModelsInARealCatalog(t *testing.T) {
|
|
src := config.Source{
|
|
Name: "vela", BaseURL: "https://example.invalid", Adapter: "openai", APIKey: "k",
|
|
Models: []config.Model{
|
|
{ID: "a"}, {ID: "b"}, {ID: "c"}, {ID: "d"},
|
|
{ID: "img1", Kind: "image"}, {ID: "img2", Kind: "image"},
|
|
},
|
|
}
|
|
p := newTestProvider(t, src)
|
|
var images int
|
|
for _, k := range p.ModelsWithKind() {
|
|
if k.Kind == "image" {
|
|
images++
|
|
}
|
|
}
|
|
if images != 2 {
|
|
t.Errorf("image models = %d, want 2", images)
|
|
}
|
|
}
|
|
|
|
// TestSourceStatusJSON_ModelKindsOmittedWhenEmpty pins the backward-compat
|
|
// promise: an older UI parsing this JSON must not break on a new field, and a
|
|
// source with no model list must not gain a "model_kinds": null.
|
|
func TestSourceStatusJSON_ModelKindsOmittedWhenEmpty(t *testing.T) {
|
|
b, err := json.Marshal(SourceStatus{Name: "x", Models: []string{"a"}})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
var m map[string]interface{}
|
|
if err := json.Unmarshal(b, &m); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, present := m["model_kinds"]; present {
|
|
t.Errorf("model_kinds present when empty: %s — should be omitted for older UIs", b)
|
|
}
|
|
if _, present := m["models"]; !present {
|
|
t.Errorf("models field disappeared: %s", b)
|
|
}
|
|
}
|
|
|
|
// newTestProvider (defined in provider_test.go) spins up a real Lua VM, which
|
|
// is heavier than these tests need, but reusing it keeps one construction path
|
|
// for the whole package. |