Files
Local-Cursor/internal/backend/server/config/roundtrip_test.go
FuDie0915 db73cf5a39 chore: import Local-Cursor v1.1.8 source snapshot
Includes the current working directory changes. Historical commits and release binaries are excluded to limit Gitea storage.
Source base: d7515973fbfd6dd2001fa156c483455b8081c7cb
2026-11-10 01:24:28 +08:00

59 lines
1.8 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package config
import (
"os"
"path/filepath"
"testing"
)
// 验证用户配置 YAML 往返:Save 后 Load 得到一致的归一化字段,
// 特别是 *bool(persistentMode)与新增的 refreshIntervalSeconds。
func TestConfigRoundTrip(t *testing.T) {
path := filepath.Join(t.TempDir(), "config.yaml")
store := NewStore(path, "")
input := DefaultConfig()
input.HomeMetrics.IncludeCacheWriteInHitRate = true
input.HomeMetrics.RefreshIntervalSeconds = 30
input.HomeMetrics.PersistentMode = boolPtr(false)
input.Routing.Mode = "local"
input.ModelAdapters = []ModelAdapterConfig{} // Normalize 会补默认值
if _, err := store.Save(nil, input); err != nil {
t.Fatalf("save: %v", err)
}
loaded, err := store.Load(nil)
if err != nil {
t.Fatalf("load: %v", err)
}
if loaded.HomeMetrics.IncludeCacheWriteInHitRate != true {
t.Error("includeCacheWriteInHitRate round-trip mismatch")
}
if loaded.HomeMetrics.RefreshIntervalSeconds != 30 {
t.Errorf("refreshIntervalSeconds = %d, want 30", loaded.HomeMetrics.RefreshIntervalSeconds)
}
if loaded.HomeMetrics.PersistentMode == nil || *loaded.HomeMetrics.PersistentMode != false {
t.Error("persistentMode round-trip mismatch: want false")
}
if loaded.Routing.Mode != "local" {
t.Errorf("routing.mode = %q, want local", loaded.Routing.Mode)
}
// 幂等:二次保存后再读仍一致。
if _, err := store.Save(nil, loaded); err != nil {
t.Fatalf("resave: %v", err)
}
reloaded, err := store.Load(nil)
if err != nil {
t.Fatalf("reload: %v", err)
}
if reloaded.HomeMetrics.RefreshIntervalSeconds != 30 {
t.Errorf("second load refreshIntervalSeconds = %d, want 30", reloaded.HomeMetrics.RefreshIntervalSeconds)
}
if _, err := os.Stat(path); err != nil {
t.Fatalf("config file missing: %v", err)
}
}