Files
Agent-System-Backend/internal/runtime/model_test.go
T
weichen f1302ed5b3 Enable canonical versioned Go module consumption
Why: Allow consumers to download an immutable module revision without nested source checkouts or local path replacements.

Evidence: SELF package tests and the prior canonical-path rejection are recorded in the Dev dependency-workspace task card; remote consumption is replayed against the committed candidate.

Impact: Change the module identity and its Go imports while preserving API behavior. Existing historical submodule revisions remain buildable.

Refs: Versioned dependencies U1/U3; feature/dependency-workspace
2026-10-13 15:47:16 +00:00

61 lines
2.2 KiB
Go

package runtime
import (
"testing"
core "git-ssh.u1680832.nyat.app/weichen/Agent-System-Core.git"
)
func effOf(kv map[string]any) core.EffectiveSettings { return core.EffectiveSettings(kv) }
// 三层覆盖链解析:defaults → user → project 由 settings 服务合并(server 集成测试覆盖);
// 此处验证解析器对「设置层结果 + 画像层」的最后一级覆盖与回落。
func TestResolveChatModelLayers(t *testing.T) {
eff := effOf(map[string]any{"models": map[string]any{"chat": map[string]any{
"model": "model-settings", "baseUrl": "https://s.example", "apiKey": "k0",
}}})
prof := core.AgentProfile{}
// 仅设置层。
got := ResolveChatModel(prof, eff)
if got.Model != "model-settings" || got.Base != "https://s.example" || got.Key != "k0" {
t.Fatalf("settings layer: %+v", got)
}
// 画像覆盖模型(端点沿用设置层)。
prof.Model.Chat = "model-profile"
got = ResolveChatModel(prof, eff)
if got.Model != "model-profile" || got.Base != "https://s.example" {
t.Fatalf("profile layer should override model only: %+v", got)
}
}
func TestResolveLightweightFallback(t *testing.T) {
eff := effOf(map[string]any{"models": map[string]any{
"chat": map[string]any{"model": "main-m", "baseUrl": "https://main", "apiKey": "k"},
"lightweight": map[string]any{"model": ""},
}})
got := ResolveLightweightModel(core.AgentProfile{}, eff)
if got.Model != "main-m" || got.Base != "https://main" {
t.Fatalf("lightweight should fall back to chat: %+v", got)
}
// 轻量档只配模型名:模型用轻量、端点回落主档。
eff["models"].(map[string]any)["lightweight"] = map[string]any{"model": "lite-m"}
got = ResolveLightweightModel(core.AgentProfile{Model: core.ModelRoute{Lightweight: "prof-lite"}}, eff)
if got.Model != "prof-lite" || got.Base != "https://main" {
t.Fatalf("profile lightweight + chat endpoint: %+v", got)
}
}
func TestChatFallbacksDefaultEmpty(t *testing.T) {
if got := ChatFallbacks(effOf(nil)); got != nil {
t.Fatalf("default %#v", got)
}
eff := effOf(map[string]any{"models": map[string]any{"chat": map[string]any{
"fallbacks": " backup , primary ,backup",
}}})
got := ChatFallbacks(eff)
if len(got) != 2 || got[0] != "backup" || got[1] != "primary" {
t.Fatalf("%#v", got)
}
}