mirror of
https://github.com/Comfy-Org/comfy-swift-sdk.git
synced 2026-11-04 23:47:26 +00:00
[PR #40] [MERGED] refactor(ws): extract reifyFrame helper for duplicated frame reification #42
Labels
No labels
enhancement
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Comfy-Org/comfy-swift-sdk#42
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Comfy-Org/comfy-swift-sdk/pull/40
Author: @mattmillerai
Created: 7/11/2026
Status: ✅ Merged
Merged: 7/21/2026
Merged by: @mattmillerai
Base:
main← Head:matt/be-2860-reify-frame-helper📝 Commits (3)
a3ef60frefactor(ws): extract reifyFrame helper for duplicated frame reificationf15ac0ffix(ws): guard reifyFrame against top-level JSON scalar bodiesb29f9f9test(ws): cover reifyFrame scalar-body guard against uncatchable crash📊 Changes
2 files changed (+94 additions, -12 deletions)
View changed files
📝
Sources/ComfySwiftSDK/Internal/WebSocketSession.swift(+19 -12)➕
Tests/ComfySwiftSDKTests/ReifyFrameTests.swift(+75 -0)📄 Description
ELI-5
Two spots in the WebSocket read loop did the exact same little dance: take a
frame body that had been decoded into an untyped
Any, turn it back into JSONbytes, then decode those bytes into a real typed struct. This PR pulls that
repeated dance into one small helper (
reifyFrame) and calls it from bothspots, so the round-trip logic lives in one place instead of two.
What changed
private static func reifyFrame<T: Decodable>(_ raw: AnyDecodable?) -> T?to
WebSocketSession. It unwraps the frame body, round-trips it throughJSONSerialization+JSONDecoder, and returnsnilon any failure.executed(ExecutedFrameData) andexecution_error(
ExecutionErrorFrameData) frame handlers to call it, replacing the twocopies of the inline round-trip.
Why
The two handlers each open-coded the same
envelope.data?.value→JSONSerialization.data(withJSONObject:)→JSONDecoder().decode(T.self)reification. Extracting it removes the duplication and gives the round-trip a
single named home.
Behavior-preserving
This is a pure refactor. The helper reproduces the original
try?-fallbacksemantics exactly: absent body or any failed step yields
nil, and each callerkeeps its existing
if letfallback behavior. TherunReadLoopstate machineand its local buffers are left untouched (the broader "decompose the switch"
idea was intentionally out of scope — the loop stays the single owner of its
buffers).
Testing
swift buildclean.paths are exercised via the integration/smoke suites.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.