diff --git a/pkg/config/config.go b/pkg/config/config.go index a06edbbeb..eac993eb9 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -1363,7 +1363,7 @@ func isValidName(name string) bool { } // Avoid certain reserved names that shouldn't be used as identifiers - reserved := map[string]bool{"", ".", "..", "nil"} + reserved := map[string]bool{"": true, ".": true, "..": true, "nil": true} if reserved[name] || strings.TrimSpace(name) != name { return false } diff --git a/pkg/config/validation_test.go b/pkg/config/validation_test.go new file mode 100644 index 000000000..59811e3fb --- /dev/null +++ b/pkg/config/validation_test.go @@ -0,0 +1,106 @@ +package config + +import ( + "testing" +) + +func TestConfigValidation_Comprehensive(t *testing.T) { + // Test valid configuration + validConfig := &Config{ + Agents: AgentsConfig{ + Defaults: AgentDefaults{ + Workspace: "~/test-workspace", + Model: "test-model", + }, + }, + Channels: ChannelsConfig{ + Telegram: TelegramConfig{ + Enabled: false, // Disabled, so no token required + }, + }, + Gateway: GatewayConfig{ + Host: "localhost", + Port: 8080, + }, + ModelList: []ModelConfig{ + { + ModelName: "test-model", + Model: "openai/gpt-test", + }, + }, + } + + if err := validConfig.Validate(); err != nil { + t.Errorf("Valid config should not produce validation error, but got: %v", err) + } + + // Test invalid configuration - missing workspace + invalidConfig := &Config{ + Agents: AgentsConfig{ + Defaults: AgentDefaults{ + Workspace: "", // Missing required field + }, + }, + Channels: ChannelsConfig{ + Telegram: TelegramConfig{ + Enabled: false, + }, + }, + Gateway: GatewayConfig{ + Host: "localhost", + Port: 8080, + }, + ModelList: []ModelConfig{ + { + ModelName: "test-model", + Model: "openai/gpt-test", + }, + }, + } + + if err := invalidConfig.Validate(); err == nil { + t.Error("Invalid config (missing workspace) should produce validation error, but didn't get one") + } + + if err := invalidConfig.Validate(); err != nil && + (err.Error() == "" || err.Error() == "workspace is required" || + err.Error() == "agents config validation failed: defaults: workspace is required") { + // Expected error condition + } else if err != nil { + t.Logf("Got expected error for invalid config: %v", err) + } +} + +func TestConfigValidation_ChannelRequirements(t *testing.T) { + // Test telegram with enabled but no token + invalidTelegramConfig := &Config{ + Agents: AgentsConfig{ + Defaults: AgentDefaults{ + Workspace: "~/test-workspace", + Model: "test-model", + }, + }, + Channels: ChannelsConfig{ + Telegram: TelegramConfig{ + Enabled: true, // Enabled but no token + Token: "", // Missing required token + }, + }, + Gateway: GatewayConfig{ + Host: "localhost", + Port: 8080, + }, + ModelList: []ModelConfig{ + { + ModelName: "test-model", + Model: "openai/gpt-test", + }, + }, + } + + if err := invalidTelegramConfig.Validate(); err == nil { + t.Error("Invalid telegram config (missing token) should produce validation error, but didn't get one") + } else { + t.Logf("Got expected error for invalid telegram config: %v", err) + } +}