testing: owned-fake stub HttpClient seam (comms-e5vm.1) - #8
Merged
Merged
Conversation
Build a reusable test HttpClient on @effect/platform HttpClient.make(req => Effect<response>) that fakes the HttpClient PORT the zulip adapter declares in R — no socket, no Bun.serve, no real FetchHttpClient. Responses are keyed by method+path with sticky defaults and one-per- request sequence queues (the event-pump GET /events chain), built as web Responses wrapped via HttpClientResponse.fromWeb so they round-trip .status/.text/.arrayBuffer/.headers. Requests are serialized to a web Request the same way FetchHttpClient serializes them, then captured for url/method/headers/body assertions. Drop-in for Effect.provideService(HttpClient.HttpClient, stub.client).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds a reusable owned-fake
HttpClientfor tests, built on@effect/platform'sHttpClient.make(req => Effect<response>). It fakes theHttpClient.HttpClientport the zulip adapter declares inR(http.ts:338,adapter.ts:370) — no socket, noBun.serve, no realFetchHttpClient.Today every zulip test provides the real
FetchHttpClient.layerpointed at a fakeBun.serve. That fakes Zulip's wire (a thing we don't own) over a real socket — not the port we own. This stub closes that gap.How
packages/testing/stub-http-client.tsexposesmakeStubHttpClient: Effect<StubHttpClient>:respond(method, path, res)sets a sticky default;respondSequence(method, path, [...])queues responses consumed one-per-request, falling back to the sticky default once drained — the seam the event-pump needs (aGET /eventschain advancinglast_event_id).Responses and wrapped withHttpClientResponse.fromWeb, so they round-trip.status/.text/.arrayBuffer/.headersexactly as a fetched response would. Bodies pin to Zulip envelope shapes (cross-checked against the vendored Zulip source).Requestthe same wayFetchHttpClientserializes them, then captured — so a form-urlencoded or multipart body is recorded byte-for-byte as the wire would have seen it.capturedexposes url / method / headers / body.Effect.provideService(HttpClient.HttpClient, stub.client)replacesFetchHttpClient.layerwith no other change.Effect-native throughout:
Ref-backed registry (HashMapwith aData.structroute key) + capture log, register/inspect as Effects.Scope
Strictly the seam (comms-e5vm.1). Not the effectTest harness (comms-30hq), not migrating any tests onto the stub (comms-e5vm.2, which this unblocks). No adapter changes.
13 focused tests cover keying, sequence + drain-fallback, capture (method/url/headers/form-body/query-string), status passthrough, unregistered-route 404,
Uint8Arraydownload bodies, the no-socket guarantee (unroutable host still resolves), and drop-in service provision.