Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:**

Expand Down
8 changes: 7 additions & 1 deletion pkg/cmd/outpost_attempt.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"context"
"encoding/json"
"fmt"
"os"

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -200,7 +206,7 @@ func newOutpostAttemptGetCmd() *outpostAttemptGetCmd {
Use: "get <attempt-id>",
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
Expand Down
48 changes: 48 additions & 0 deletions pkg/cmd/outpost_attempt_test.go
Original file line number Diff line number Diff line change
@@ -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")
}
4 changes: 2 additions & 2 deletions pkg/outpost/mcp/tool_attempts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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"}},
Expand Down
27 changes: 27 additions & 0 deletions pkg/outpost/mcp/tool_attempts_test.go
Original file line number Diff line number Diff line change
@@ -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")
}