From 8794b94cfc5eaeaa4ad9c872f6d363c68efe7dc7 Mon Sep 17 00:00:00 2001 From: Remco Beckers Date: Fri, 19 Dec 2025 12:41:49 +0100 Subject: [PATCH 1/3] STAC-23271 Remove dashboard feature flag --- cmd/sts.go | 6 +- cmd/sts_test.go | 169 +++++++++--------------------------------------- 2 files changed, 30 insertions(+), 145 deletions(-) diff --git a/cmd/sts.go b/cmd/sts.go index 7e343384..6d22e070 100644 --- a/cmd/sts.go +++ b/cmd/sts.go @@ -32,6 +32,7 @@ func STSCommand(cli *di.Deps) *cobra.Command { cmd.AddCommand(TopologySyncCommand(cli)) cmd.AddCommand(AgentCommand(cli)) cmd.AddCommand(UserSessionCommand(cli)) + cmd.AddCommand(DashboardCommand(cli)) // Experimental commands for otel mapping if os.Getenv("STS_EXPERIMENTAL_OTEL_MAPPING") != "" { @@ -39,10 +40,5 @@ func STSCommand(cli *di.Deps) *cobra.Command { cmd.AddCommand(OtelRelationtMappingCommand(cli)) } - // Only add dashboard command if experimental feature is enabled - if os.Getenv("STS_EXPERIMENTAL_DASHBOARD") != "" { - cmd.AddCommand(DashboardCommand(cli)) - } - return cmd } diff --git a/cmd/sts_test.go b/cmd/sts_test.go index 1e1fd235..86ff483c 100644 --- a/cmd/sts_test.go +++ b/cmd/sts_test.go @@ -1,36 +1,14 @@ package cmd import ( - "os" "testing" - "github.com/spf13/cobra" "github.com/stackvista/stackstate-cli/internal/di" "github.com/stretchr/testify/assert" ) const dashboardCommand = "dashboard" -// Helper function to manage STS_EXPERIMENTAL_DASHBOARD environment variable -func withDashboardEnv(value string, fn func()) { - originalValue := os.Getenv("STS_EXPERIMENTAL_DASHBOARD") - defer func() { - if originalValue == "" { - _ = os.Unsetenv("STS_EXPERIMENTAL_DASHBOARD") - } else { - _ = os.Setenv("STS_EXPERIMENTAL_DASHBOARD", originalValue) - } - }() - - if value == "" { - _ = os.Unsetenv("STS_EXPERIMENTAL_DASHBOARD") - } else { - _ = os.Setenv("STS_EXPERIMENTAL_DASHBOARD", value) - } - - fn() -} - func TestSTSCommand(t *testing.T) { cli := di.NewMockDeps(t) cmd := STSCommand(&cli.Deps) @@ -42,135 +20,46 @@ func TestSTSCommand(t *testing.T) { } func TestSTSCommandContainsExpectedSubcommands(t *testing.T) { - withDashboardEnv("", func() { - cli := di.NewMockDeps(t) - cmd := STSCommand(&cli.Deps) - - expectedCommands := []string{ - "context", - "version", - "script", - "settings", - "stackpack", - "monitor", - "service-token", - "health", - "license", - "graph", - "rbac", - "topic", - "topology-sync", - "agent", - "user-session", - } + cli := di.NewMockDeps(t) + cmd := STSCommand(&cli.Deps) - // Verify expected commands are present - for _, expectedCmd := range expectedCommands { - found := false - for _, subCmd := range cmd.Commands() { - if subCmd.Use == expectedCmd { - found = true - break - } - } - assert.True(t, found, "Expected command '%s' not found", expectedCmd) - } + expectedCommands := []string{ + "context", + "version", + "script", + "settings", + "stackpack", + "monitor", + "service-token", + "health", + "license", + "graph", + "rbac", + "topic", + "topology-sync", + "agent", + "user-session", + "dashboard", + } - // Verify dashboard command is NOT present when env var is not set - dashboardFound := false + // Verify expected commands are present + for _, expectedCmd := range expectedCommands { + found := false for _, subCmd := range cmd.Commands() { - if subCmd.Use == dashboardCommand { - dashboardFound = true + if subCmd.Use == expectedCmd { + found = true break } } - assert.False(t, dashboardFound, "Dashboard command should not be present when STS_EXPERIMENTAL_DASHBOARD is not set") - }) -} - -func TestSTSCommandDashboardExperimentalFeature(t *testing.T) { - tests := []struct { - name string - envVarValue string - shouldIncludeDashboard bool - }{ - { - name: "Dashboard command not included when env var is empty", - envVarValue: "", - shouldIncludeDashboard: false, - }, - { - name: "Dashboard command included when env var is set to 'true'", - envVarValue: "true", - shouldIncludeDashboard: true, - }, - { - name: "Dashboard command included when env var is set to any non-empty value", - envVarValue: "any-value", - shouldIncludeDashboard: true, - }, - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - withDashboardEnv(tt.envVarValue, func() { - cli := di.NewMockDeps(t) - cmd := STSCommand(&cli.Deps) - - // Check if dashboard command is present - dashboardFound := false - for _, subCmd := range cmd.Commands() { - if subCmd.Use == dashboardCommand { - dashboardFound = true - break - } - } - - if tt.shouldIncludeDashboard { - assert.True(t, dashboardFound, "Dashboard command should be present when STS_EXPERIMENTAL_DASHBOARD='%s'", tt.envVarValue) - } else { - assert.False(t, dashboardFound, "Dashboard command should not be present when STS_EXPERIMENTAL_DASHBOARD='%s'", tt.envVarValue) - } - }) - }) + assert.True(t, found, "Expected command '%s' not found", expectedCmd) } } func TestSTSCommandStructure(t *testing.T) { - withDashboardEnv("1", func() { - cli := di.NewMockDeps(t) - cmd := STSCommand(&cli.Deps) - - // Verify the command has the expected number of subcommands (15 regular + 1 dashboard) - assert.Len(t, cmd.Commands(), 16, "Expected 16 subcommands when dashboard is enabled") - - // Verify that dashboard command is included and properly configured - var dashboardCmd *cobra.Command - for _, subCmd := range cmd.Commands() { - if subCmd.Use == dashboardCommand { - dashboardCmd = subCmd - break - } - } - assert.NotNil(t, dashboardCmd, "Dashboard command should be present") - assert.Equal(t, dashboardCommand, dashboardCmd.Use) - assert.NotEmpty(t, dashboardCmd.Short) - }) -} - -func TestSTSCommandWithoutDashboard(t *testing.T) { - withDashboardEnv("", func() { - cli := di.NewMockDeps(t) - cmd := STSCommand(&cli.Deps) - - // Verify the command has the expected number of subcommands (15 regular, no dashboard) - assert.Len(t, cmd.Commands(), 15, "Expected 15 subcommands when dashboard is disabled") + cli := di.NewMockDeps(t) + cmd := STSCommand(&cli.Deps) - // Double-check that no command has "dashboard" as its Use field - for _, subCmd := range cmd.Commands() { - assert.NotEqual(t, dashboardCommand, subCmd.Use, "Dashboard command should not be present") - } - }) + assert.Len(t, cmd.Commands(), 16, "Expected 16 subcommands") } func TestSTSCommandUsageTemplate(t *testing.T) { From b9558b0755f0dbcafc09cf768ccc012264227487 Mon Sep 17 00:00:00 2001 From: Remco Beckers Date: Fri, 19 Dec 2025 16:26:52 +0100 Subject: [PATCH 2/3] STAC-23271 Fix yaml parsing --- cmd/dashboard/dashboard_describe.go | 2 +- cmd/dashboard/dashboard_edit.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/dashboard/dashboard_describe.go b/cmd/dashboard/dashboard_describe.go index 6664a778..55609d90 100644 --- a/cmd/dashboard/dashboard_describe.go +++ b/cmd/dashboard/dashboard_describe.go @@ -48,7 +48,7 @@ func RunDashboardDescribeCommand(args *DescribeArgs) di.CmdWithApiFn { return common.NewResponseError(err, resp) } - yamlData, err := yaml.Marshal(dashboard) + yamlData, err := yaml.Marshal(dashboard.DashboardReadFullSchema) if err != nil { return common.NewExecutionError(fmt.Errorf("failed to marshal dashboard: %v", err)) } diff --git a/cmd/dashboard/dashboard_edit.go b/cmd/dashboard/dashboard_edit.go index bf1a000b..26a554f7 100644 --- a/cmd/dashboard/dashboard_edit.go +++ b/cmd/dashboard/dashboard_edit.go @@ -61,7 +61,7 @@ func RunDashboardEditCommand(args *EditArgs) di.CmdWithApiFn { } // Convert dashboard to pretty JSON for editing - originalYAML, err := yaml.Marshal(dashboard) + originalYAML, err := yaml.Marshal(dashboard.DashboardReadFullSchema) if err != nil { return common.NewExecutionError(fmt.Errorf("failed to marshal dashboard to YAML: %v", err)) } From 478355260e200fd48eeabb714a04f687bf0aa5b5 Mon Sep 17 00:00:00 2001 From: Remco Beckers Date: Fri, 19 Dec 2025 16:53:33 +0100 Subject: [PATCH 3/3] STAC-23271 Remove unused const --- cmd/sts_test.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/cmd/sts_test.go b/cmd/sts_test.go index 86ff483c..63bab6ea 100644 --- a/cmd/sts_test.go +++ b/cmd/sts_test.go @@ -7,8 +7,6 @@ import ( "github.com/stretchr/testify/assert" ) -const dashboardCommand = "dashboard" - func TestSTSCommand(t *testing.T) { cli := di.NewMockDeps(t) cmd := STSCommand(&cli.Deps)