From 6828239485ce944d0ce3fdd5401b16c67714d1ec Mon Sep 17 00:00:00 2001 From: Theo Bennett Date: Mon, 24 Aug 2026 00:18:12 +0600 Subject: [PATCH 1/2] feat: add validation for unique architecture diagram names in config --- pkg/config/config.go | 8 +++++ pkg/config/config_test.go | 63 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) 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))) From b1a020b05b6e4eb0fcdfa720a2ae49bc7b0a58bc Mon Sep 17 00:00:00 2001 From: Theo Bennett Date: Tue, 25 Aug 2026 18:47:57 +0600 Subject: [PATCH 2/2] feat: enhance dry run functionality for release and sync commands --- cmd/release.go | 8 ++++---- cmd/sync.go | 31 +++++++++++++++++-------------- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/cmd/release.go b/cmd/release.go index 545c62a..c5a8f69 100644 --- a/cmd/release.go +++ b/cmd/release.go @@ -29,7 +29,7 @@ var releaseCmd = &cobra.Command{ Short: "Record a release on the service timeline", Long: `Records a single release event at the moment a tag is created, for pipelines that cut releases as a CI/CD step. Run this from a tag-triggered job; it resolves the version, release notes and commit range from git and posts one timeline event. -Requires the UIGRAPH_TOKEN environment variable.`, +Requires the UIGRAPH_TOKEN environment variable, except for a dry run, which reaches no gateway.`, Args: cobra.NoArgs, RunE: runRelease, } @@ -46,14 +46,14 @@ func init() { releaseCmd.Flags().StringVar(&enterpriseEnv, "enterprise", "", "Record the release on the UiGraph gateway ("+enterpriseGatewayURL+"); pass --enterprise=DEV for "+enterpriseDevGatewayURL) releaseCmd.Flags().Lookup("enterprise").NoOptDefVal = "DEFAULT" releaseCmd.MarkFlagsMutuallyExclusive("api-url", "enterprise") - releaseCmd.Flags().BoolVar(&dryRun, "dry-run", false, "Print the event without sending it to the gateway") + releaseCmd.Flags().BoolVar(&dryRun, "dry-run", false, "Print the event without sending it to the gateway (no token or gateway URL needed)") } func runRelease(cmd *cobra.Command, args []string) error { ctx := cmd.Context() token := os.Getenv("UIGRAPH_TOKEN") - if token == "" { + if token == "" && !dryRun { fmt.Fprintln(os.Stderr, "Error: UIGRAPH_TOKEN environment variable is required") os.Exit(1) } @@ -71,7 +71,7 @@ func runRelease(cmd *cobra.Command, args []string) error { if apiURL == "" { apiURL = os.Getenv("UIGRAPH_GATEWAY_URL") } - if apiURL == "" { + if apiURL == "" && !dryRun { fmt.Fprintln(os.Stderr, "Error: gateway URL is required (set --enterprise, --api-url or UIGRAPH_GATEWAY_URL environment variable)") os.Exit(1) } diff --git a/cmd/sync.go b/cmd/sync.go index 548095f..b8601e0 100644 --- a/cmd/sync.go +++ b/cmd/sync.go @@ -35,7 +35,8 @@ var syncCmd = &cobra.Command{ Use: "sync", Short: "Sync service and APIs to UiGraph Gateway", Long: `Reads .uigraph.yaml, captures git metadata, and syncs service, API groups, architecture diagrams, test packs/test cases, and database schemas (when configured) to the gateway. -This command is designed to run in CI/CD environments and requires UIGRAPH_TOKEN environment variable.`, +This command is designed to run in CI/CD environments and requires UIGRAPH_TOKEN environment variable. +A dry run reaches no gateway, so it needs neither UIGRAPH_TOKEN nor a gateway URL.`, Args: cobra.NoArgs, RunE: runSync, } @@ -46,7 +47,7 @@ func init() { syncCmd.Flags().StringVar(&enterpriseEnv, "enterprise", "", "Sync to the UiGraph gateway ("+enterpriseGatewayURL+"); pass --enterprise=DEV for "+enterpriseDevGatewayURL) syncCmd.Flags().Lookup("enterprise").NoOptDefVal = "DEFAULT" syncCmd.MarkFlagsMutuallyExclusive("api-url", "enterprise") - syncCmd.Flags().BoolVar(&dryRun, "dry-run", false, "Print payloads without sending to gateway") + syncCmd.Flags().BoolVar(&dryRun, "dry-run", false, "Print payloads without sending to gateway (no token or gateway URL needed)") syncCmd.Flags().BoolVar(&verbose, "verbose", false, "Log every MLflow and gateway request with its duration") } @@ -107,7 +108,7 @@ func runSync(cmd *cobra.Command, args []string) error { // 1. Authenticate using UIGRAPH_TOKEN token := os.Getenv("UIGRAPH_TOKEN") - if token == "" { + if token == "" && !dryRun { fmt.Fprintln(os.Stderr, "Error: UIGRAPH_TOKEN environment variable is required") os.Exit(1) } @@ -125,7 +126,7 @@ func runSync(cmd *cobra.Command, args []string) error { if apiURL == "" { apiURL = os.Getenv("UIGRAPH_GATEWAY_URL") } - if apiURL == "" { + if apiURL == "" && !dryRun { fmt.Fprintln(os.Stderr, "Error: gateway URL is required (set --enterprise, --api-url or UIGRAPH_GATEWAY_URL environment variable)") os.Exit(1) } @@ -909,18 +910,20 @@ func runSync(cmd *cobra.Command, args []string) error { watermarks := map[string]time.Time{} deletedProjects := map[string]bool{} - states, err := client.ListMLProjects(ctx, true) - if err != nil { - exitGatewayErrorErr("read last ML sync time", err) - } - for _, state := range states { - if state.DeletedAt != nil { - deletedProjects[state.Name] = true + if !dryRun { + states, err := client.ListMLProjects(ctx, true) + if err != nil { + exitGatewayErrorErr("read last ML sync time", err) } - if state.SyncedAt == nil { - continue + for _, state := range states { + if state.DeletedAt != nil { + deletedProjects[state.Name] = true + } + if state.SyncedAt == nil { + continue + } + watermarks[state.Name] = *state.SyncedAt } - watermarks[state.Name] = *state.SyncedAt } orderedML := make([]config.MLProjectRef, 0, len(cfg.ML))