Skip to content

feat(runtime): isolate HTTPRuntime target#1121

Open
grdsdev wants to merge 22 commits into
mainfrom
claude/httpruntime-target-085a05
Open

feat(runtime): isolate HTTPRuntime target#1121
grdsdev wants to merge 22 commits into
mainfrom
claude/httpruntime-target-085a05

Conversation

@grdsdev

@grdsdev grdsdev commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Summary

Isolates the zero-dependency HTTPRuntime target out of #1099 into its own branch, plus a few follow-up refinements requested during review, and adds a first-party HTTPRuntimeTestHelpers target for stubbing HTTPRuntime requests under Swift Testing.

HTTPRuntime

  • Adds Sources/HTTPRuntime (HTTP request/response types, URLSessionTransport, multipart form assembly, JSON coding) and Tests/HTTPRuntimeTests, without the OpenAPI codegen tool or generated Storage client from the original PR.
  • Registers HTTPRuntimeTests in the shared Xcode scheme and swift6TestTargets, and adds its spell-check terms.
  • HTTPTransport.send/stream now use typed throws (throws(HTTPError)) instead of any ErrorURLSessionTransport already only ever threw HTTPError.transport, so this tightens the contract to match. Dropped the redundant throws on the private makeURLRequest helper, which never actually threw.
  • Removed HTTPBody.multipart: callers now assemble the multipart body themselves via MultipartFormData.buildToTempFile(), set Content-Type, and pass .file. Keeps the transport from needing to know about multipart assembly.
  • Added HTTPRequestBuilder.addHeader(_:value:), which merges into an existing header (joined with "; ") instead of replacing it — for repeated directives like Prefer. Both setHeader and addHeader resolve the target key case-insensitively (linear scan over the small header set) so differently-cased calls merge instead of duplicating.
  • Dropped the SSE parser (ServerSentEvents.swift) — not needed by Supabase's clients.
  • stream() branches per platform: FoundationNetworking (Linux) lacks URLSession.bytes(for:), so it falls back to a buffered single-chunk delivery there instead of true incremental streaming.

HTTPRuntimeTestHelpers (new)

  • HTTPStub/HTTPStubBody: canned-response definitions, one static factory per HTTP verb (.get/.post/.put/.patch/.delete/.head), body as .empty/.string/.data/.stream.
  • HTTPTransportStub: an actor conforming to HTTPTransport — an ordered, consume-once stub queue with a TaskLocal-backed .current accessor, safe under parallel Swift Testing runs.
  • .http(stubs:): a custom TestTrait/SuiteTrait binding the stub queue to a test's task tree, usable at @Test or @Suite level and composable across nesting (suite-level stubs are consumed before test-level ones).
  • curlCommand(for:): renders an HTTPRequest as a curl command (mirrors Sources/TestHelpers/URLRequestSnapshot.swift's conventions, independently, so this target has no dependency on TestHelpers).
  • assertHTTPRequests { operation } matches: { curlSnapshot }: asserts an inline curl snapshot of whatever requests operation made, via InlineSnapshotTesting.
  • Registers HTTPRuntimeTestHelpersTests in the shared Xcode scheme and swift6TestTargets.
  • Design doc: docs/superpowers/specs/2026-07-11-http-runtime-test-helpers-design.md.

Test plan

  • swift build
  • swift test --filter HTTPRuntimeTests (9 tests)
  • swift test --filter HTTPRuntimeTestHelpersTests (18 tests)
  • ./scripts/spell-check.sh
  • ./scripts/format.sh (no changes)
  • Linux build verified locally via Docker (swift:6.1 image)

grdsdev added 22 commits July 11, 2026 07:36
…e deleted SSE parser after the package-scoping edit

The manual public->package access-control pass left HTTPRuntime non-compiling:
checkStatus still referenced HTTPResponse's now-removed bare status/isSuccess
(now only on .head), MultipartFormData's new builder API members defaulted to
internal instead of package, and ServerSentEvents.swift was deleted outright
rather than rescoped, breaking SSE stream parsing entirely.
Follow-up to the HTTPRuntime target isolation: registers the test
target in the shared Xcode scheme, adds its spell-check terms, and
updates Package.resolved to drop dependencies no longer pulled in by
this trimmed-down package graph.
…ase, add addHeader

- HTTPTransport.send/stream now throw typed HTTPError instead of any Error;
  URLSessionTransport already only ever threw HTTPError.transport, so this
  just tightens the contract. Dropped the redundant `throws` on the private
  makeURLRequest helper, which never actually threw.
- Removed HTTPBody.multipart: callers now build the multipart body themselves
  via MultipartFormData.buildToTempFile(), set Content-Type, and pass .file.
  Keeps HTTPTransport from needing to know about multipart assembly.
- Added HTTPRequestBuilder.addHeader(_:value:), which merges into an existing
  header (joined with "; ") instead of replacing it, for repeated directives
  like Prefer. Both setHeader and addHeader resolve the target key
  case-insensitively so differently-cased calls merge into one header
  instead of creating duplicates.
Supabase's own clients don't need it; downstream consumers can parse
the raw streamed chunks themselves if they want SSE framing.
…sed doc references

- checkStatus now requires a catch-all APIError type instead of falling
  back to a bare unexpectedStatus(status:body:) case, and reports decode
  failures as unexpectedResponse(response:underlyingError:) with the full
  response attached.
- Commented out the still-unused HTTPError.encoding case.
- Dropped doc comments referencing the (now removed) OpenAPI codegen tool.
…uild

- TransferProgress/ProgressHandler were left `public` when the rest of
  HTTPRuntime was scoped down to `package`; the capability-matrix CI
  check flagged them as new, unregistered public API. Scope them to
  `package` like everything else in this target.
- FoundationNetworking (swift-corelibs-foundation on Linux) has no
  async byte-streaming API (`bytes(for:)`/`AsyncBytes`), so
  URLSessionTransport.stream() failed to compile on Linux. Branch on
  `canImport(FoundationNetworking)`: Linux buffers the full response
  via `data(for:)` and yields it as a single chunk instead of
  streaming incrementally; Apple platforms keep the existing
  incremental byte-stream implementation.
…e and dictionary

Adds HTTPRuntimeTestHelpersTests to the shared Xcode scheme in alphabetical order between HelpersTests and HTTPRuntimeTests. Includes dictionary.txt entries for Xcode-related terms and formatting fixes to HTTPRuntimeTestHelpers source files.
@grdsdev
grdsdev requested a review from a team as a code owner July 13, 2026 09:38
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