Fix MessagingConfig code review issues (gt-mrqiz, gt-ngoe6, gt-akc4m)

- Add Type field for schema consistency (gt-mrqiz)
- Fix error message inconsistency: all validation errors now wrap sentinel (gt-ngoe6)
- Add missing tests: wrong type, future version, malformed JSON (gt-akc4m)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Steve Yegge
2025-12-28 15:31:09 -08:00
parent 3e863c1431
commit e8d4fcda0b
3 changed files with 46 additions and 5 deletions

View File

@@ -1,6 +1,7 @@
package config
import (
"os"
"path/filepath"
"testing"
"time"
@@ -575,6 +576,9 @@ func TestMessagingConfigRoundTrip(t *testing.T) {
t.Fatalf("LoadMessagingConfig: %v", err)
}
if loaded.Type != "messaging" {
t.Errorf("Type = %q, want 'messaging'", loaded.Type)
}
if loaded.Version != CurrentMessagingVersion {
t.Errorf("Version = %d, want %d", loaded.Version, CurrentMessagingVersion)
}
@@ -618,6 +622,7 @@ func TestMessagingConfigValidation(t *testing.T) {
{
name: "valid config with lists",
config: &MessagingConfig{
Type: "messaging",
Version: 1,
Lists: map[string][]string{
"oncall": {"mayor/", "gastown/witness"},
@@ -625,6 +630,22 @@ func TestMessagingConfigValidation(t *testing.T) {
},
wantErr: false,
},
{
name: "wrong type",
config: &MessagingConfig{
Type: "wrong",
Version: 1,
},
wantErr: true,
},
{
name: "future version rejected",
config: &MessagingConfig{
Type: "messaging",
Version: 999,
},
wantErr: true,
},
{
name: "list with no recipients",
config: &MessagingConfig{
@@ -694,6 +715,21 @@ func TestLoadMessagingConfigNotFound(t *testing.T) {
}
}
func TestLoadMessagingConfigMalformedJSON(t *testing.T) {
dir := t.TempDir()
path := filepath.Join(dir, "messaging.json")
// Write malformed JSON
if err := os.WriteFile(path, []byte("{not valid json"), 0644); err != nil {
t.Fatalf("writing test file: %v", err)
}
_, err := LoadMessagingConfig(path)
if err == nil {
t.Fatal("expected error for malformed JSON")
}
}
func TestLoadOrCreateMessagingConfig(t *testing.T) {
// Test creating default when not found
config, err := LoadOrCreateMessagingConfig("/nonexistent/path.json")