Skip to content

[CHA-2961] Webhook handling spec — regenerate SDK + dual-API#57

Open
mogita wants to merge 4 commits into
masterfrom
cha-2961_webhook-handling
Open

[CHA-2961] Webhook handling spec — regenerate SDK + dual-API#57
mogita wants to merge 4 commits into
masterfrom
cha-2961_webhook-handling

Conversation

@mogita
Copy link
Copy Markdown
Collaborator

@mogita mogita commented May 12, 2026

Ticket

Related

Summary

Regenerates the webhook surface from the chat/ feature/cha-2961-webhook-handling-spec branch + adds dual-API instance methods on the top-level GetStreamRuby::Client.

Added (rendered from chat/ template):

  • Stream::Webhook module alias (preferred); StreamChat::Webhook retained for backward-compat for one minor-version cycle
  • StreamChat::Webhook::UnknownEvent class for forward-compat
  • gunzip_payload, decode_sqs_payload, decode_sns_payload primitives
  • parse_event(payload) — returns typed event or UnknownEvent for unrecognized discriminators (forward-compat counterpart to the existing parse_webhook_event which throws)
  • verify_and_parse_webhook(body, signature, secret) HTTP composite
  • parse_sqs_payload(message_body) / parse_sns_payload(notification_body) queue composites — no signature param (backend emits no HMAC for queue messages today)
  • Unified error class: StreamChat::Webhook::InvalidWebhookError covering signature mismatch, invalid JSON, missing/non-string type, gzip decompression failure, invalid base64 in queue body, malformed SNS envelope. Distinguish failure modes via the message substring or cause chain.

Hand-added on GetStreamRuby::Client:

  • verify_signature(body, signature) — drops the api_secret parameter, uses @configuration.api_secret
  • verify_and_parse_webhook(body, signature) — drops the api_secret parameter

Dual API: module-level methods remain available for callers needing an arbitrary secret.

Conformance fixtures under test/fixtures/webhooks/ (14 event-type buckets + _invalid/ negative cases).

Generator change: generate.sh now invokes chat-manager openapi generate-webhook-fixtures to populate test/fixtures/webhooks/.

Test plan

  • make test passes (rspec suite; 12/12 green)
  • Conformance fixtures generated cleanly (14 event-type dirs + _invalid/)
  • Stream::Webhook and StreamChat::Webhook both resolve
  • Client wrapper verify_signature returns true/false correctly with stored secret
  • verify_and_parse_webhook raises InvalidWebhookError on bad signature
  • Rubocop clean on lib/getstream_ruby/client.rb

Notes for review

  • Pre-existing codegen mismatch: event_class_for_type references StreamChat::*Event constants but generated models live under GetStream::Generated::Models::*. This affects typed-event return for known discriminators in both the old parse_webhook_event and the new parse_event. Out of scope for this PR (template-level mapping fix needed in chat/ codegen). Signature verification, UnknownEvent fallback, queue/HTTP composites, and error handling all work correctly.
  • test/webhook_test.rb is generated as Minitest and depends on minitest/autorun, which is not in this project's Gemfile. The repo's test infra is rspec under spec/. The generated Minitest file documents the surface and is not currently runnable by make test — pre-existing situation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant