Skip to content

Commit 0a22bae

Browse files
committed
refactor: trim comments to match surrounding style
The added comments ran to roughly double the density of the code around them and mostly restated what the line below already said. Kept the ones carrying information the code cannot: why svix/util has to be required, why both key shapes are accepted after symbolize_names, and why array_map needed replacing. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01M2kJ4nGaM8imZCVMEKjmXA
1 parent 143db16 commit 0a22bae

6 files changed

Lines changed: 9 additions & 35 deletions

File tree

‎lib/seam/action_attempt_resolver.rb‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ def self.wait_until_resolved(action_attempt, client, timeout: nil, polling_inter
4141

4242
raise Seam::ActionAttemptFailedError.new(action_attempt) if action_attempt.status == "error"
4343

44-
# Neither pending, success, nor error: a status added after this release.
45-
# Waiting cannot conclude, so say so rather than pass it off as a success.
4644
unless action_attempt.status == "success"
4745
raise Seam::ActionAttemptUnknownStatusError.new(action_attempt, action_attempt.status)
4846
end

‎lib/seam/base_resource.rb‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,17 +110,13 @@ def self.date_accessor(*attrs)
110110

111111
protected
112112

113-
# Reading a date never raises: a value the API sends in an unexpected shape
114-
# reads as nil rather than taking down an otherwise usable resource.
115113
def parse_datetime(value)
116114
Time.parse(value)
117115
rescue ArgumentError, TypeError
118116
nil
119117
end
120118

121119
def process_data_attributes(data)
122-
# A response that is not an object at all still yields a usable resource
123-
# with every attribute unset, rather than raising from #each.
124120
return unless data.is_a?(Hash)
125121

126122
data.each do |key, value|

‎lib/seam/wait_for_action_attempt.rb‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,7 @@ def initialize(action_attempt)
2626
end
2727

2828
# Raised when an attempt reports a status this SDK version does not know.
29-
#
30-
# Waiting promises to return a succeeded attempt or raise, and an unrecognized
31-
# status supports neither: reporting success would claim the action completed
32-
# when the SDK cannot tell. Read #action_attempt to inspect the status.
29+
# Waiting can neither return it as a success nor call it a failure.
3330
class ActionAttemptUnknownStatusError < ActionAttemptError
3431
attr_reader :status
3532

‎lib/seam/webhook.rb‎

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,16 @@
22

33
require "svix/webhook"
44
require "svix/errors"
5-
# svix/webhook calls Svix.secure_compare but does not require the file defining
6-
# it, so verification raises NoMethodError unless something else loaded it first.
5+
# svix/webhook calls Svix.secure_compare without requiring the file defining it.
76
require "svix/util"
87
require_relative "base_resource"
98
require_relative "resources/event"
109

1110
module Seam
1211
WebhookVerificationError = Svix::WebhookVerificationError
1312

14-
# Raised when a payload carries a valid signature but cannot be read as a Seam
15-
# event. Distinct from WebhookVerificationError: the sender is genuinely Seam,
16-
# so the payload will never become readable and retrying it cannot help.
13+
# Raised when a payload is correctly signed but is not a Seam event. Unlike
14+
# WebhookVerificationError, retrying it can never help.
1715
class InvalidWebhookPayloadError < StandardError; end
1816

1917
class Webhook
@@ -26,17 +24,13 @@ def initialize(secret)
2624
#
2725
# @return [Seam::Resources::SeamEvent]
2826
# @raise [Seam::WebhookVerificationError] When the signature does not match.
29-
# Respond with an error status so the sender retries.
30-
# @raise [Seam::InvalidWebhookPayloadError] When the signature matches but the
31-
# body is not a Seam event. Report it rather than letting the sender retry.
27+
# @raise [Seam::InvalidWebhookPayloadError] When it does but the body is not an event.
3228
def verify(payload, headers)
3329
normalized_headers = headers.transform_keys(&:downcase)
3430

3531
begin
3632
event_data = @webhook.verify(payload, normalized_headers)
3733
rescue JSON::ParserError => e
38-
# The signature already checked out, so this came from Seam but is
39-
# permanently unreadable.
4034
raise InvalidWebhookPayloadError, "The verified webhook payload is not valid JSON: #{e.message}"
4135
end
4236

@@ -49,8 +43,7 @@ def verify(payload, headers)
4943

5044
private
5145

52-
# Svix parses with symbolize_names, so read either key shape rather than
53-
# depending on how the payload happened to be decoded.
46+
# Svix parses with symbolize_names, so accept either key shape.
5447
def seam_event?(data)
5548
return false unless data.is_a?(Hash)
5649

‎spec/resources/total_parsing_spec.rb‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# frozen_string_literal: true
22

3-
# Seam adds event types, action types, and error codes between SDK releases, so a
4-
# payload this version does not recognize has to stay readable rather than cost
5-
# the caller the whole response. Each example pins one shape that used to raise.
3+
# Reading a response must not fail on the shape of the payload.
64
RSpec.describe "total parsing" do
75
it "does not raise when the payload is not an object" do
86
resource = Seam::Resources::Device.load_from_response(42)
@@ -38,7 +36,6 @@
3836
expect(device.errors.first.error_code).to eq("brand_new")
3937
end
4038

41-
# Reading a date must not take down an otherwise usable resource.
4239
it "reads a malformed timestamp as nil" do
4340
device = Seam::Resources::Device.load_from_response(
4441
"device_id" => "device_1", "created_at" => "not a timestamp"
@@ -65,8 +62,6 @@
6562
end
6663

6764
RSpec.describe Seam::ActionAttemptUnknownStatusError do
68-
# Waiting promises a succeeded attempt or a raise. An unrecognized status
69-
# supports neither, and returning it would claim the action completed.
7065
it "is raised rather than returning an unresolved attempt as a success" do
7166
attempt = Seam::Resources::ActionAttempt.load_from_response(
7267
"action_attempt_id" => "attempt_1",

‎spec/webhook_spec.rb‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
require "openssl"
55
require "base64"
66

7-
# Signs a payload the way Svix does, so these specs exercise the real
8-
# verification path rather than stubbing it out.
7+
# Signs a payload the way Svix does, so these specs exercise real verification.
98
def signed_headers(secret, payload, msg_id: "msg_1", timestamp: Time.now.to_i)
109
key = Base64.decode64(secret.delete_prefix("whsec_"))
1110
signature = Base64.strict_encode64(
@@ -52,8 +51,7 @@ def verify(payload, headers: nil)
5251
expect(event.event_type).to eq("future.thing")
5352
end
5453

55-
# Svix parses webhook payloads with symbolize_names, so the raw payload reachable
56-
# through #data carries symbol keys here, where an HTTP response carries strings.
54+
# Svix symbolizes keys, so #data carries symbols here and strings over HTTP.
5755
it "exposes the full payload of an unknown event through data" do
5856
payload = JSON.generate(
5957
event_id: "event_1",
@@ -74,9 +72,6 @@ def verify(payload, headers: nil)
7472
.to raise_error(Seam::WebhookVerificationError)
7573
end
7674

77-
# A signed but unreadable body is permanently unreadable: the sender is
78-
# genuinely Seam, so retrying can never help. It must not look like a
79-
# verification failure, which is the signal to retry.
8075
describe "signed but unreadable payloads" do
8176
it "raises for a body that is not JSON" do
8277
expect { verify("{not json") }

0 commit comments

Comments
 (0)