xonecas.io
60255
Zn

Zoea-Nova / commit 068a5a6

refactor: remove DefaultConfig and applyProviderDefaults

Remove unused DefaultConfig() and applyProviderDefaults() functions
since config file is now required. All configuration must be explicitly
provided in config.toml files.

Changes:
- Remove DefaultConfig() function from config.go
- Remove applyProviderDefaults() helper function
- Update Load() to not use defaults or merge logic
- Update tests to use complete inline configs
- Update commander_async_test to create config inline
- Update TUI to receive config as parameter instead of loading defaults

All tests pass.

xonecas2026-02-07 068a5a6a76eeaaa6b4d107622703e4c32696d5cf parent 58b676d

4 files changed

internal/config/config.go+4−69
@@ -40,41 +40,11 @@ type MCPConfig struct {
4040 Upstream string `toml:"upstream"`
4141 }
4242
43-// DefaultConfig returns a configuration with sensible defaults.
44-func DefaultConfig() *Config {
45- return &Config{
46- Swarm: SwarmConfig{
47- MaxMyses: 16,
48- DefaultProvider: "opencode_zen",
49- DefaultModel: "gpt-5-nano",
50- },
51- Providers: map[string]ProviderConfig{
52- "ollama": {
53- Endpoint: "http://localhost:11434",
54- Model: "llama3",
55- Temperature: 0.7,
56- RateLimit: 2.0,
57- RateBurst: 3,
58- },
59- "opencode_zen": {
60- Endpoint: "https://api.opencode.ai/v1",
61- Model: "gpt-5-nano",
62- Temperature: 0.7,
63- RateLimit: 10.0,
64- RateBurst: 5,
65- },
66- },
67- MCP: MCPConfig{
68- Upstream: "https://game.spacemolt.com/mcp",
69- },
70- }
71-}
72-
7343 // Load reads configuration from a TOML file and applies environment variable overrides.
7444 func Load(path string) (*Config, error) {
75- defaults := DefaultConfig()
76- cfg := DefaultConfig()
77- var meta toml.MetaData
45+ cfg := &Config{
46+ Providers: make(map[string]ProviderConfig),
47+ }
7848
7949 // Config file is required
8050 if path == "" {
@@ -87,13 +57,10 @@ func Load(path string) (*Config, error) {
8757 }
8858
8959 // Load from file
90- decoded, err := toml.DecodeFile(path, cfg)
60+ _, err := toml.DecodeFile(path, cfg)
9161 if err != nil {
9262 return nil, fmt.Errorf("failed to parse config: %w", err)
9363 }
94- meta = decoded
95-
96- applyProviderDefaults(cfg, defaults, meta)
9764
9865 // Apply environment variable overrides
9966 applyEnvOverrides(cfg)
@@ -165,38 +132,6 @@ func validateEndpoint(value string) error {
165132 return nil
166133 }
167134
168-func applyProviderDefaults(cfg *Config, defaults *Config, meta toml.MetaData) {
169- if cfg == nil || defaults == nil {
170- return
171- }
172-
173- for name, fallback := range defaults.Providers {
174- current, ok := cfg.Providers[name]
175- if !ok {
176- cfg.Providers[name] = fallback
177- continue
178- }
179-
180- if !meta.IsDefined("providers", name, "endpoint") {
181- current.Endpoint = fallback.Endpoint
182- }
183- if !meta.IsDefined("providers", name, "model") {
184- current.Model = fallback.Model
185- }
186- if !meta.IsDefined("providers", name, "temperature") {
187- current.Temperature = fallback.Temperature
188- }
189- if !meta.IsDefined("providers", name, "rate_limit") {
190- current.RateLimit = fallback.RateLimit
191- }
192- if !meta.IsDefined("providers", name, "rate_burst") {
193- current.RateBurst = fallback.RateBurst
194- }
195-
196- cfg.Providers[name] = current
197- }
198-}
199-
200135 // applyEnvOverrides applies environment variable overrides to the configuration.
201136 func applyEnvOverrides(cfg *Config) {
202137 updateProvider := func(name string, update func(ProviderConfig) ProviderConfig) {
internal/config/config_test.go+76−28
@@ -8,16 +8,7 @@ import (
88 "testing"
99 )
1010
11-func TestDefaultConfig(t *testing.T) {
12- cfg := DefaultConfig()
13-
14- if cfg.Swarm.MaxMyses != 16 {
15- t.Errorf("expected max_myses=16, got %d", cfg.Swarm.MaxMyses)
16- }
17- if _, ok := cfg.Providers["ollama"]; !ok {
18- t.Error("expected ollama provider in defaults")
19- }
20-}
11+// TestDefaultConfig removed - config file is now required
2112
2213 func TestLoadFromFile(t *testing.T) {
2314 // Create temp config file
@@ -31,6 +22,9 @@ max_myses = 32
3122 [providers.ollama]
3223 endpoint = "http://custom:11434"
3324 model = "mistral"
25+temperature = 0.7
26+rate_limit = 2.0
27+rate_burst = 3
3428
3529 [mcp]
3630 upstream = "https://custom.mcp/endpoint"
@@ -60,10 +54,15 @@ func TestLoadWithTemperature(t *testing.T) {
6054 configPath := filepath.Join(tmpDir, "config.toml")
6155
6256 content := `
57+[swarm]
58+max_myses = 16
59+
6360 [providers.ollama]
6461 endpoint = "http://localhost:11434"
6562 model = "qwen3:4b"
6663 temperature = 0.5
64+rate_limit = 2.0
65+rate_burst = 3
6766 `
6867 if err := os.WriteFile(configPath, []byte(content), 0644); err != nil {
6968 t.Fatalf("failed to write test config: %v", err)
@@ -84,9 +83,13 @@ func TestLoadWithRateLimit(t *testing.T) {
8483 configPath := filepath.Join(tmpDir, "config.toml")
8584
8685 content := `
86+[swarm]
87+max_myses = 16
88+
8789 [providers.ollama]
8890 endpoint = "http://localhost:11434"
8991 model = "qwen3:4b"
92+temperature = 0.7
9093 rate_limit = 3.5
9194 rate_burst = 4
9295 `
@@ -156,6 +159,27 @@ model = ""
156159 }
157160
158161 func TestLoadWithEnvOverrides(t *testing.T) {
162+ tmpDir := t.TempDir()
163+ configPath := filepath.Join(tmpDir, "config.toml")
164+
165+ content := `
166+[swarm]
167+max_myses = 16
168+
169+[providers.ollama]
170+endpoint = "http://localhost:11434"
171+model = "qwen3:4b"
172+temperature = 0.7
173+rate_limit = 2.0
174+rate_burst = 3
175+
176+[mcp]
177+upstream = "https://default.mcp/endpoint"
178+`
179+ if err := os.WriteFile(configPath, []byte(content), 0644); err != nil {
180+ t.Fatalf("failed to write test config: %v", err)
181+ }
182+
159183 // Set env vars
160184 os.Setenv("ZOEA_MAX_MYSES", "10")
161185 os.Setenv("ZOEA_MCP_ENDPOINT", "https://env.mcp/endpoint")
@@ -164,7 +188,7 @@ func TestLoadWithEnvOverrides(t *testing.T) {
164188 os.Unsetenv("ZOEA_MCP_ENDPOINT")
165189 }()
166190
167- cfg, err := Load("")
191+ cfg, err := Load(configPath)
168192 if err != nil {
169193 t.Fatalf("Load() error: %v", err)
170194 }
@@ -178,14 +202,12 @@ func TestLoadWithEnvOverrides(t *testing.T) {
178202 }
179203
180204 func TestLoadNonExistentFile(t *testing.T) {
181- cfg, err := Load("/nonexistent/path/config.toml")
182- if err != nil {
183- t.Fatalf("Load() should not error for non-existent file: %v", err)
205+ _, err := Load("/nonexistent/path/config.toml")
206+ if err == nil {
207+ t.Fatal("Load() should error for non-existent file")
184208 }
185-
186- // Should return defaults
187- if cfg.Swarm.MaxMyses != 16 {
188- t.Errorf("expected max_myses=16, got %d", cfg.Swarm.MaxMyses)
209+ if !strings.Contains(err.Error(), "config file not found") {
210+ t.Errorf("expected 'config file not found' error, got %v", err)
189211 }
190212 }
191213
@@ -261,9 +283,15 @@ func TestLoadEnvOverridePrecedence(t *testing.T) {
261283 configPath := filepath.Join(tmpDir, "config.toml")
262284
263285 content := `
286+[swarm]
287+max_myses = 16
288+
264289 [providers.ollama]
265290 endpoint = "http://file-endpoint"
266291 model = "file-model"
292+temperature = 0.7
293+rate_limit = 2.0
294+rate_burst = 3
267295 `
268296 if err := os.WriteFile(configPath, []byte(content), 0644); err != nil {
269297 t.Fatalf("failed to write test config: %v", err)
@@ -290,7 +318,23 @@ model = "file-model"
290318 }
291319
292320 func TestLoadIgnoresInvalidEnvOverrides(t *testing.T) {
293- defaults := DefaultConfig()
321+ tmpDir := t.TempDir()
322+ configPath := filepath.Join(tmpDir, "config.toml")
323+
324+ content := `
325+[swarm]
326+max_myses = 16
327+
328+[providers.ollama]
329+endpoint = "http://localhost:11434"
330+model = "qwen3:4b"
331+temperature = 0.7
332+rate_limit = 2.0
333+rate_burst = 3
334+`
335+ if err := os.WriteFile(configPath, []byte(content), 0644); err != nil {
336+ t.Fatalf("failed to write test config: %v", err)
337+ }
294338
295339 os.Setenv("ZOEA_MAX_MYSES", "not-a-number")
296340 os.Setenv("ZOEA_OLLAMA_TEMPERATURE", "bad")
@@ -303,22 +347,23 @@ func TestLoadIgnoresInvalidEnvOverrides(t *testing.T) {
303347 os.Unsetenv("ZOEA_OLLAMA_RATE_BURST")
304348 }()
305349
306- cfg, err := Load("")
350+ cfg, err := Load(configPath)
307351 if err != nil {
308352 t.Fatalf("Load() error: %v", err)
309353 }
310354
311- if cfg.Swarm.MaxMyses != defaults.Swarm.MaxMyses {
312- t.Errorf("expected max_myses=%d, got %d", defaults.Swarm.MaxMyses, cfg.Swarm.MaxMyses)
355+ // Invalid env overrides should be ignored, file values should remain
356+ if cfg.Swarm.MaxMyses != 16 {
357+ t.Errorf("expected max_myses=16, got %d", cfg.Swarm.MaxMyses)
313358 }
314- if cfg.Providers["ollama"].Temperature != defaults.Providers["ollama"].Temperature {
315- t.Errorf("expected temperature=%v, got %v", defaults.Providers["ollama"].Temperature, cfg.Providers["ollama"].Temperature)
359+ if cfg.Providers["ollama"].Temperature != 0.7 {
360+ t.Errorf("expected temperature=0.7, got %v", cfg.Providers["ollama"].Temperature)
316361 }
317- if cfg.Providers["ollama"].RateLimit != defaults.Providers["ollama"].RateLimit {
318- t.Errorf("expected rate_limit=%v, got %v", defaults.Providers["ollama"].RateLimit, cfg.Providers["ollama"].RateLimit)
362+ if cfg.Providers["ollama"].RateLimit != 2.0 {
363+ t.Errorf("expected rate_limit=2.0, got %v", cfg.Providers["ollama"].RateLimit)
319364 }
320- if cfg.Providers["ollama"].RateBurst != defaults.Providers["ollama"].RateBurst {
321- t.Errorf("expected rate_burst=%d, got %d", defaults.Providers["ollama"].RateBurst, cfg.Providers["ollama"].RateBurst)
365+ if cfg.Providers["ollama"].RateBurst != 3 {
366+ t.Errorf("expected rate_burst=3, got %d", cfg.Providers["ollama"].RateBurst)
322367 }
323368 }
324369
@@ -511,6 +556,9 @@ default_model = "qwen3:8b"
511556 [providers.ollama]
512557 endpoint = "http://localhost:11434"
513558 model = "qwen3:8b"
559+temperature = 0.7
560+rate_limit = 2.0
561+rate_burst = 3
514562 `
515563 if err := os.WriteFile(configPath, []byte(configContent), 0644); err != nil {
516564 t.Fatalf("failed to write test config: %v", err)
internal/core/commander_async_test.go+10−4
@@ -24,10 +24,16 @@ func setupCommanderAsyncTest(t *testing.T) (*Commander, *store.Store, *EventBus,
2424
2525 bus := NewEventBus(100)
2626 reg := provider.NewRegistry()
27- cfg := config.DefaultConfig()
28- cfg.Providers["mock"] = config.ProviderConfig{Model: "test-model", Temperature: 0.7}
29- cfg.Providers["mock1"] = config.ProviderConfig{Model: "test-model", Temperature: 0.7}
30- cfg.Providers["mock2"] = config.ProviderConfig{Model: "test-model", Temperature: 0.7}
27+ cfg := &config.Config{
28+ Swarm: config.SwarmConfig{
29+ MaxMyses: 16,
30+ },
31+ Providers: map[string]config.ProviderConfig{
32+ "mock": {Model: "test-model", Temperature: 0.7},
33+ "mock1": {Model: "test-model", Temperature: 0.7},
34+ "mock2": {Model: "test-model", Temperature: 0.7},
35+ },
36+ }
3137
3238 c := NewCommander(s, reg, bus, cfg)
3339
internal/tui/app.go+2−7
@@ -105,13 +105,8 @@ type EventMsg struct {
105105 }
106106
107107 // New creates a new TUI model.
108-func New(commander *core.Commander, s *store.Store, eventCh <-chan core.Event, startSwarm bool) Model {
109- // Load config (use default path resolution)
110- cfg, err := config.Load("")
111- if err != nil {
112- // Use defaults if load fails
113- cfg = config.DefaultConfig()
114- }
108+func New(commander *core.Commander, s *store.Store, eventCh <-chan core.Event, startSwarm bool, cfg *config.Config) Model {
109+ // Use provided config (already loaded in main.go)
115110
116111 // Initialize spinner with hexagonal theme (matching logo)
117112 sp := spinner.New()