From 0c88d307e16af3c9fa3de249ba0ec0a38d9dab78 Mon Sep 17 00:00:00 2001 From: Alex Castillo Date: Wed, 18 Nov 2026 04:12:47 -0400 Subject: [PATCH] fix(cli): keep cause and meta when listing a request's ignored events GetRequestIgnoredEvents decoded the response into EventListResponse, which has no cause or meta, so the CLI and the MCP list_ignored action dropped the fields that say why an event was ignored. Decode into a new IgnoredEvent type and print the cause instead of the always-empty status. --- pkg/cmd/request_ignored_events.go | 2 +- pkg/gateway/mcp/tool_events.go | 15 +++++--- pkg/hookdeck/events.go | 21 +++++++++++ pkg/hookdeck/ignored_events_test.go | 54 +++++++++++++++++++++++++++++ pkg/hookdeck/requests.go | 4 +-- 5 files changed, 88 insertions(+), 8 deletions(-) create mode 100644 pkg/hookdeck/ignored_events_test.go diff --git a/pkg/cmd/request_ignored_events.go b/pkg/cmd/request_ignored_events.go index 9a86914a..a1b70d53 100644 --- a/pkg/cmd/request_ignored_events.go +++ b/pkg/cmd/request_ignored_events.go @@ -84,7 +84,7 @@ func (rc *requestIgnoredEventsCmd) runRequestIgnoredEventsCmd(cmd *cobra.Command color := ansi.Color(os.Stdout) for _, e := range resp.Models { - fmt.Printf("%s %s %s\n", color.Green(e.ID), e.Status, e.WebhookID) + fmt.Printf("%s %s %s\n", color.Green(e.ID), e.Cause, e.WebhookID) } return nil } diff --git a/pkg/gateway/mcp/tool_events.go b/pkg/gateway/mcp/tool_events.go index eb2ff8e0..2abd0c78 100644 --- a/pkg/gateway/mcp/tool_events.go +++ b/pkg/gateway/mcp/tool_events.go @@ -286,13 +286,18 @@ func eventsListing(ctx context.Context, client *hookdeck.Client, in mcpcore.Inpu return mcpcore.ErrorResult(err.Error()), nil } + if ignored { + ignoredResult, err := client.GetRequestIgnoredEvents(ctx, requestID, params) + if err != nil { + return mcpcore.ErrorResult(mcpcore.TranslateAPIError(err)), nil + } + return mcpcore.JSONResultEnvelopeForClient(ignoredResult, client) + } + var result *hookdeck.EventListResponse - switch { - case ignored: - result, err = client.GetRequestIgnoredEvents(ctx, requestID, params) - case requestID != "": + if requestID != "" { result, err = client.GetRequestEvents(ctx, requestID, params) - default: + } else { result, err = client.ListEvents(ctx, params) } if err != nil { diff --git a/pkg/hookdeck/events.go b/pkg/hookdeck/events.go index a5e245ad..c314c8bd 100644 --- a/pkg/hookdeck/events.go +++ b/pkg/hookdeck/events.go @@ -32,6 +32,27 @@ type Event struct { TeamID string `json:"team_id"` } +// IgnoredEvent is a record from GET /requests/{id}/ignored_events: an event +// Hookdeck decided not to create. It is not an Event: it has no status, source +// or destination, and cause says why it was ignored. +type IgnoredEvent struct { + ID string `json:"id"` + TeamID string `json:"team_id"` + WebhookID string `json:"webhook_id"` + // Cause is e.g. FILTERED, TRANSFORMATION_FAILED or CLI_DISCONNECTED. + Cause string `json:"cause"` + RequestID string `json:"request_id"` + // Meta depends on the cause: an array, an object or null. + Meta interface{} `json:"meta"` + CreatedAt time.Time `json:"created_at"` +} + +// IgnoredEventListResponse is the response from listing a request's ignored events +type IgnoredEventListResponse struct { + Models []IgnoredEvent `json:"models"` + Pagination PaginationResponse `json:"pagination"` +} + // EventData is the payload on an event, returned by GET /events with // include=data and on a single event. // diff --git a/pkg/hookdeck/ignored_events_test.go b/pkg/hookdeck/ignored_events_test.go new file mode 100644 index 00000000..099093a2 --- /dev/null +++ b/pkg/hookdeck/ignored_events_test.go @@ -0,0 +1,54 @@ +package hookdeck + +import ( + "context" + "encoding/json" + "net/http" + "net/http/httptest" + "net/url" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +// GET /requests/{id}/ignored_events returns IgnoredEvent records: id, team_id, +// webhook_id, cause, request_id, meta, created_at. They have no status, source +// or destination, and the cause is the only field that says why the event was +// ignored. meta is an array, an object or null depending on the cause. +const ignoredEventsPage = `{"models":[ + {"id":"ign_1","team_id":"t","webhook_id":"web_1","cause":"FILTERED","request_id":"req_1","meta":["body"],"created_at":"2026-11-01T10:00:00Z"}, + {"id":"ign_2","team_id":"t","webhook_id":"web_1","cause":"TRANSFORMATION_FAILED","request_id":"req_1","meta":{"error":"boom"},"created_at":"2026-11-01T10:00:01Z"}, + {"id":"ign_3","team_id":"t","webhook_id":"web_2","cause":"CLI_DISCONNECTED","request_id":"req_1","meta":null,"created_at":"2026-11-01T10:00:02Z"} +],"pagination":{"limit":10}}` + +func TestGetRequestIgnoredEventsKeepsCauseAndMeta(t *testing.T) { + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json") + _, _ = w.Write([]byte(ignoredEventsPage)) + })) + t.Cleanup(srv.Close) + base, err := url.Parse(srv.URL) + require.NoError(t, err) + c := &Client{BaseURL: base} + + resp, err := c.GetRequestIgnoredEvents(context.Background(), "req_1", nil) + require.NoError(t, err) + require.Len(t, resp.Models, 3) + + assert.Equal(t, "FILTERED", resp.Models[0].Cause) + assert.Equal(t, []any{"body"}, resp.Models[0].Meta) + assert.Equal(t, "TRANSFORMATION_FAILED", resp.Models[1].Cause) + assert.Equal(t, map[string]any{"error": "boom"}, resp.Models[1].Meta) + assert.Equal(t, "CLI_DISCONNECTED", resp.Models[2].Cause) + assert.Nil(t, resp.Models[2].Meta) + + // What the CLI and MCP print: cause and meta present, no phantom status. + out, err := json.Marshal(resp.Models[0]) + require.NoError(t, err) + var fields map[string]any + require.NoError(t, json.Unmarshal(out, &fields)) + assert.Equal(t, "FILTERED", fields["cause"]) + assert.Contains(t, fields, "meta") + assert.NotContains(t, fields, "status") +} diff --git a/pkg/hookdeck/requests.go b/pkg/hookdeck/requests.go index a0cb8655..d60e1dd5 100644 --- a/pkg/hookdeck/requests.go +++ b/pkg/hookdeck/requests.go @@ -163,7 +163,7 @@ func (c *Client) GetRequestEvents(ctx context.Context, requestID string, params } // GetRequestIgnoredEvents returns the list of ignored events for a request (GET /requests/{id}/ignored_events) -func (c *Client) GetRequestIgnoredEvents(ctx context.Context, requestID string, params map[string]string) (*EventListResponse, error) { +func (c *Client) GetRequestIgnoredEvents(ctx context.Context, requestID string, params map[string]string) (*IgnoredEventListResponse, error) { path, err := apiPath("requests", requestID, "ignored_events") if err != nil { return nil, err @@ -180,7 +180,7 @@ func (c *Client) GetRequestIgnoredEvents(ctx context.Context, requestID string, if err != nil { return nil, err } - var result EventListResponse + var result IgnoredEventListResponse _, err = postprocessJsonResponse(resp, &result) if err != nil { return nil, fmt.Errorf("failed to parse request ignored events response: %w", err)