From dfe9fbde6ec7cb91b961fb190ce62c793313ad6a Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 30 Nov 2026 12:32:39 -0400 Subject: [PATCH] fix(connection): send an explicit empty --description connection upsert and connection update dropped --description "" from the request, so the stored description was kept while the command reported success. Send the field whenever the flag was given. Co-Authored-By: Claude Sonnet 5.5 --- pkg/cmd/connection_description_test.go | 65 ++++++++++++++++++++++++++ pkg/cmd/connection_update.go | 3 +- pkg/cmd/connection_upsert.go | 4 +- 3 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 pkg/cmd/connection_description_test.go diff --git a/pkg/cmd/connection_description_test.go b/pkg/cmd/connection_description_test.go new file mode 100644 index 00000000..e3ead122 --- /dev/null +++ b/pkg/cmd/connection_description_test.go @@ -0,0 +1,65 @@ +package cmd + +import ( + "encoding/json" + "io" + "net/http" + "net/http/httptest" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + "github.com/hookdeck/hookdeck-cli/pkg/config" + "github.com/hookdeck/hookdeck-cli/pkg/hookdeck" +) + +// `--description ""` is how a stored description is cleared, so it has to reach +// the API, while omitting the flag has to leave the stored one alone. +func TestConnectionUpsertDescription(t *testing.T) { + stored := storedUpsertConnection() + stored.Description = strPtr("old description") + + t.Run("explicit empty value is sent", func(t *testing.T) { + body := captureConnectionUpsertBody(t, stored, + "gateway", "connection", "upsert", "my-conn", "--description", "") + + require.Contains(t, body, "description") + assert.Equal(t, "", body["description"]) + }) + + t.Run("omitted flag is not sent", func(t *testing.T) { + body := captureConnectionUpsertBody(t, stored, + "gateway", "connection", "upsert", "my-conn") + + assert.NotContains(t, body, "description") + }) +} + +func TestConnectionUpdateEmptyDescriptionIsSent(t *testing.T) { + var body map[string]interface{} + server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method == http.MethodPut { + raw, err := io.ReadAll(r.Body) + require.NoError(t, err) + require.NoError(t, json.Unmarshal(raw, &body)) + } + w.Header().Set("Content-Type", "application/json") + _ = json.NewEncoder(w).Encode(hookdeck.Connection{ID: "web_1"}) + })) + t.Cleanup(server.Close) + config.ResetAPIClientForTesting() + t.Cleanup(config.ResetAPIClientForTesting) + + old := Config + t.Cleanup(func() { Config = old }) + Config = config.Config{APIBaseURL: server.URL, LogLevel: "info"} + Config.Profile.APIKey = "sk_test_123456789012" + + cu := newConnectionUpdateCmd() + require.NoError(t, cu.cmd.ParseFlags([]string{"--description", ""})) + require.NoError(t, cu.runConnectionUpdateCmd(cu.cmd, []string{"web_1"})) + + require.NotNil(t, body, "the command made no PUT request") + assert.Equal(t, map[string]interface{}{"description": ""}, body) +} diff --git a/pkg/cmd/connection_update.go b/pkg/cmd/connection_update.go index 2a656199..4b5abb08 100644 --- a/pkg/cmd/connection_update.go +++ b/pkg/cmd/connection_update.go @@ -99,7 +99,8 @@ func (cu *connectionUpdateCmd) runConnectionUpdateCmd(cmd *cobra.Command, args [ hasChanges = true } - if cu.description != "" { + // An explicit --description "" clears the stored description. + if cmd.Flags().Changed("description") { req.Description = &cu.description hasChanges = true } diff --git a/pkg/cmd/connection_upsert.go b/pkg/cmd/connection_upsert.go index a4d10374..110c3546 100644 --- a/pkg/cmd/connection_upsert.go +++ b/pkg/cmd/connection_upsert.go @@ -483,7 +483,9 @@ func (cu *connectionUpsertCmd) buildUpsertRequest(existing *hookdeck.Connection, Name: &cu.name, } - if cu.description != "" { + // An explicit --description "" clears the stored description; only an + // omitted flag leaves it alone. + if cu.description != "" || (cu.cmd != nil && cu.cmd.Flags().Changed("description")) { req.Description = &cu.description }