Files
Agent-System-Backend/internal/runtime/model_test.go
T
weichenandCursor bead03374e
ci / vet-and-test (pull_request) Successful in 39s
Rewind tracked files and fall back before the first token
Why: workspace writes had no checkpoint, and a 5xx before any output stopped the turn instead of trying the next configured model.
Evidence: GOWORK=off go test ./internal/runtime/ ./internal/runmgr/ ./internal/tools/ ./internal/settings/ ./internal/server/ ./internal/app/
Impact: models.chat.fallbacks defaults to empty, so existing runs keep their model. Rewind restores only tracked writes and appends a system note. Usage records the model that served.
Refs: feature/durable-rewind
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-03 17:31:56 +00:00

61 lines
2.2 KiB
Go

package runtime
import (
"testing"
core "agent-system-core"
)
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)
}
}