diff --git a/pkg/config/config.go b/pkg/config/config.go index a9e0e61..938a17c 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -533,9 +533,17 @@ func (c *Config) Validate() error { } } + archNames := make(map[string]bool) for i, ad := range c.ArchitectureDiagrams { if ad.Name == "" { problems = append(problems, fmt.Sprintf("architectureDiagrams[%d].name is required", i)) + } else { + lowerName := strings.ToLower(ad.Name) + if archNames[lowerName] { + problems = append(problems, fmt.Sprintf("architectureDiagrams[%d].name %q is a duplicate (diagram names must be unique case-insensitively)", i, ad.Name)) + } else { + archNames[lowerName] = true + } } if ad.Path == "" { problems = append(problems, fmt.Sprintf("architectureDiagrams[%d].path is required", i)) diff --git a/pkg/config/config_test.go b/pkg/config/config_test.go index 62b781d..c55bf57 100644 --- a/pkg/config/config_test.go +++ b/pkg/config/config_test.go @@ -402,6 +402,69 @@ func TestLoadReportsMissingAndMalformedFiles(t *testing.T) { } } +func TestConfigValidateArchitectureDiagrams(t *testing.T) { + tmpDir := t.TempDir() + mmdFile := filepath.Join(tmpDir, "diagram.mmd") + if err := os.WriteFile(mmdFile, []byte("flowchart LR\n a-->b"), 0644); err != nil { + t.Fatal(err) + } + + validService := Service{ + Name: "Test Service", + Category: "Backend", + Description: "Test", + Repository: Repository{Provider: "github", URL: "https://github.com/test/repo"}, + Ownership: Ownership{Team: "platform"}, + } + + tests := []struct { + name string + diagrams []ArchDiagramRef + wantErr bool + errMsg string + }{ + { + name: "valid diagrams", + diagrams: []ArchDiagramRef{ + {Name: "Checkout Flow", Path: mmdFile}, + {Name: "Payment Flow", Path: mmdFile}, + }, + wantErr: false, + }, + { + name: "duplicate diagram name exact match", + diagrams: []ArchDiagramRef{ + {Name: "Checkout Flow", Path: mmdFile}, + {Name: "Checkout Flow", Path: mmdFile}, + }, + wantErr: true, + errMsg: "is a duplicate", + }, + { + name: "duplicate diagram name case-insensitive", + diagrams: []ArchDiagramRef{ + {Name: "Checkout Flow", Path: mmdFile}, + {Name: "checkout flow", Path: mmdFile}, + }, + wantErr: true, + errMsg: "is a duplicate", + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + cfg := Config{Version: 1, Service: validService, ArchitectureDiagrams: tt.diagrams} + err := cfg.Validate() + if (err != nil) != tt.wantErr { + t.Errorf("Validate() error = %v, wantErr %v", err, tt.wantErr) + } + if err != nil && !contains(err.Error(), tt.errMsg) { + t.Errorf("Validate() error message = %v, want to contain %v", err.Error(), tt.errMsg) + } + }) + } +} + func contains(s, substr string) bool { return len(s) >= len(substr) && (s == substr || len(substr) == 0 || (len(s) > 0 && len(substr) > 0 && stringContains(s, substr)))