diff --git a/REFERENCE.md b/REFERENCE.md index f02aaed5..ebcbc7d0 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -2769,7 +2769,7 @@ hookdeck outpost attempt list --event-id evt_abc123 --include response_data --ou ``` ### hookdeck outpost attempt get -Get a delivery attempt, including the destination's response. +Get a delivery attempt. Pass --include response_data to fetch the destination's response. **Usage:** diff --git a/pkg/cmd/outpost_attempt.go b/pkg/cmd/outpost_attempt.go index d22d3fa2..f819ed95 100644 --- a/pkg/cmd/outpost_attempt.go +++ b/pkg/cmd/outpost_attempt.go @@ -2,6 +2,7 @@ package cmd import ( "context" + "encoding/json" "fmt" "os" @@ -58,6 +59,11 @@ func printOutpostAttempt(attempt *hookdeck.OutpostAttempt) { } fmt.Println() fmt.Printf(" Time: %s\n", attempt.Time.Format("2006-01-02 15:04:05")) + if len(attempt.ResponseData) > 0 { + if response, err := json.MarshalIndent(attempt.ResponseData, " ", " "); err == nil { + fmt.Printf(" Response: %s\n", string(response)) + } + } } type outpostAttemptListCmd struct { @@ -200,7 +206,7 @@ func newOutpostAttemptGetCmd() *outpostAttemptGetCmd { Use: "get ", Args: validators.ExactArgs(1), Short: ShortGet(ResourceAttempt), - Long: `Get a delivery attempt, including the destination's response.`, + Long: `Get a delivery attempt. Pass --include response_data to fetch the destination's response.`, PreRunE: ac.validateFlags, RunE: ac.run, Example: ` # Get an attempt with the response body diff --git a/pkg/cmd/outpost_attempt_test.go b/pkg/cmd/outpost_attempt_test.go new file mode 100644 index 00000000..8c7d09c9 --- /dev/null +++ b/pkg/cmd/outpost_attempt_test.go @@ -0,0 +1,48 @@ +package cmd + +import ( + "io" + "os" + "testing" + + "github.com/hookdeck/hookdeck-cli/pkg/hookdeck" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func TestPrintOutpostAttemptResponse(t *testing.T) { + for _, tc := range []struct { + name string + response map[string]interface{} + wantResponse bool + }{ + {name: "included", response: map[string]interface{}{"body": "boom", "status": 500}, wantResponse: true}, + {name: "not included"}, + {name: "empty", response: map[string]interface{}{}}, + } { + t.Run(tc.name, func(t *testing.T) { + original := os.Stdout + r, w, err := os.Pipe() + require.NoError(t, err) + defer r.Close() + defer func() { os.Stdout = original }() + os.Stdout = w + printOutpostAttempt(&hookdeck.OutpostAttempt{ID: "att_test", ResponseData: tc.response}) + require.NoError(t, w.Close()) + os.Stdout = original + output, err := io.ReadAll(r) + require.NoError(t, err) + if tc.wantResponse { + assert.Contains(t, string(output), " Response: {\n") + assert.Contains(t, string(output), `"body": "boom"`) + assert.Contains(t, string(output), `"status": 500`) + } else { + assert.NotContains(t, string(output), "Response:") + } + }) + } +} + +func TestOutpostAttemptGetHelpResponse(t *testing.T) { + assert.Contains(t, newOutpostAttemptGetCmd().cmd.Long, "--include response_data") +} diff --git a/pkg/outpost/mcp/tool_attempts.go b/pkg/outpost/mcp/tool_attempts.go index bee770db..d3865880 100644 --- a/pkg/outpost/mcp/tool_attempts.go +++ b/pkg/outpost/mcp/tool_attempts.go @@ -11,7 +11,7 @@ import ( var attemptsActions = mcpcore.ActionSet{ {Name: "list", Desc: "list delivery attempts"}, - {Name: "get", Desc: "get one attempt, including the response data"}, + {Name: "get", Desc: "get one attempt; add include response_data for the destination's response"}, } var attemptsSpec = mcpcore.ToolSpec{ @@ -26,7 +26,7 @@ var attemptsSpec = mcpcore.ToolSpec{ "destination_type": {Type: "string", Desc: "Filter by destination type (list). " + descListValue, Actions: []string{"list"}}, "topic": {Type: "string", Desc: "Filter by topic(s) (list). " + descListValue, Actions: []string{"list"}}, "status": {Type: "string", Desc: "Filter by outcome: success or failed (list).", Enum: []string{"success", "failed"}, Actions: []string{"list"}}, - "include": {Type: "array", Desc: `Embed related records in the response: "event", "destination".`, Items: &mcpcore.Prop{Type: "string"}, Actions: []string{"list", "get"}}, + "include": {Type: "array", Desc: `Embed related records in the response: "event", "event.data", "response_data", "destination".`, Items: &mcpcore.Prop{Type: "string"}, Actions: []string{"list", "get"}}, "time_after": {Type: "string", Desc: descTimeAfter + " (list)", Actions: []string{"list"}}, "time_before": {Type: "string", Desc: descTimeBefore + " (list)", Actions: []string{"list"}}, "limit": {Type: "integer", Desc: "Max results (list)", Actions: []string{"list"}}, diff --git a/pkg/outpost/mcp/tool_attempts_test.go b/pkg/outpost/mcp/tool_attempts_test.go new file mode 100644 index 00000000..a0d1a3a2 --- /dev/null +++ b/pkg/outpost/mcp/tool_attempts_test.go @@ -0,0 +1,27 @@ +package mcp + +import ( + "encoding/json" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func TestAttemptsResponseDiscoverable(t *testing.T) { + session := connect(t, ServerOptions{Client: newTestClient(t, "https://example.com")}) + tool := listTools(t, session)["outpost_attempts_read"] + require.NotNil(t, tool) + raw, err := json.Marshal(tool.InputSchema) + require.NoError(t, err) + var schema struct { + Properties map[string]struct { + Description string `json:"description"` + } `json:"properties"` + } + require.NoError(t, json.Unmarshal(raw, &schema)) + for _, value := range []string{"event", "event.data", "response_data", "destination"} { + assert.Contains(t, schema.Properties["include"].Description, `"`+value+`"`) + } + assert.Contains(t, schema.Properties["action"].Description, "include response_data") +}