UTS: migrate rest/unit mock HTTP to the handler idiom and fix /time response shape - #534
Open
owenpearson wants to merge 1 commit into
Open
owenpearson wants to merge 1 commit into
owenpearson wants to merge 1 commit into
Conversation
…esponse shape
Migrates fallback.md, request.md, rest_client.md and request_endpoint.md off the
undefined queue-based mock API onto the onRequest/onConnectionAttempt handler idiom
with local captured_requests, repairs error-body fixtures to the full
message/code/statusCode shape, and corrects the /time mock body from {"time": N} to
the array [N] throughout.
Closes #523
Closes #524
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This was referenced Sep 21, 2026
This branch was successfully deployed
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.
Fixes two coupled UTS test-spec defects in
uts/rest/unit/, reported as #523 and #524.#523 — migrate the queue-based mock idiom to the handler idiom
Replaces every use of the undefined/banned queue API (
queue_response,queue_responses,queue_response_for_host,queue_response_for_url,queue_timeout,queue_delayed_response, andmock_http.captured_requests) with theonRequest/onConnectionAttempthandler idiom plus a LOCALcaptured_requestsarray (with localrequest_count/captured_hostswhere needed), matching the contract inhelpers/mock_http.mdand the already-migrated blocks infallback.md. In the same pass:{ "error": { "message", "code", "statusCode" } }shape, including the CloudFront fixture whoseerrorwas a bare string.RSC15f/successful-fallback-cached-0,RSC15f/cached-fallback-expires-1) now dispatch onreq.url.hostand bind assertions to the observed fallback host rather than a hard-coded name, resolving the 1/5-flaky pin against RSC15a's random ordering.rest_client.mdtohelpers/mock_http.mdatfallback.md:10andrequest.md:10,16; dropped thefallback.md:12-15block requesting capabilities the contract deliberately omits.#524 — fix the
/timeresponse shape/timereturns a single-element ARRAY[server_time_ms], not{"time": N}. Corrected at every site, contract file first (helpers/mock_http.md, thenwriting-test-specs.md, then the specs), includingrest_client.md's msgpack site which becomesmsgpack_encode([1234567890000]). Migrated handlers from #523 emit the array shape so the two fixes converge; no object-shaped/timefixture remains anywhere underuts/.Files changed
uts/rest/unit/fallback.md— full migration + error-body repair + host-pin fix + array shape (+707/-… lines)uts/rest/unit/request.md— RSC19d/HP + RSC19b/c/e/f migration, array shape, non-array redirectuts/rest/unit/rest_client.md— 12 queue sites + msgpack/time+ array shapeuts/rest/unit/request_endpoint.md— localcaptured_requests+ array shapeuts/rest/unit/helpers/mock_http.md— 4/timesitesuts/rest/unit/auth/authorize.md— 1/timesiteuts/docs/writing-test-specs.md— 3/timesites in the authoring guideJudgment calls
rest/unit/fallback.mdis half-migrated: it uses aqueue_responsemock API thathelpers/mock_http.mddoes not define andwriting-test-specs.mdbans, which makes four of its tests unsatisfiable #523 (a)): The unmigratedRSC15l/qualifying-errors-trigger-fallback-0block covered HTTP 500–504 (retry), 400/401/404 (no retry), and timeout. Every one of those scenarios is fully covered by the migrated blocks at the former:215-402(connection-refused-fallback-0,dns-error-fallback-1,connection-timeout-fallback-2,request-timeout-fallback-3,http-5xx-triggers-fallback-4,http-4xx-no-fallback-5), under distinct Test IDs. Confirmed fully redundant, so the duplicate block was deleted rather than migrated. This removes thequalifying-errors-trigger-fallback-0Test ID (its scenarios survive under the other IDs)./timeis mocked as{"time": N}in 48 places across sixrest/unitspecs; the endpoint returns[server_time_ms], so a typed SDK cannot derive those tests as written #524 (4)): TheRSC19d/non-array-response-handling-7test exercised a non-array response but fetched it from/time, which can only return an array. Repointed it at a channel-status path (/channels/test) that genuinely returns a JSON object, and replaced the hedgedASSERT items.length == 1 OR items["time"] == … # Implementation may varywith a single definite assertion (items.length == 1anditems[0]["channelId"] == "test").rest/unit/fallback.mdis half-migrated: it uses aqueue_responsemock API thathelpers/mock_http.mddoes not define andwriting-test-specs.mdbans, which makes four of its tests unsatisfiable #523 (b)): Both status-code tables include a 500 row; 500 is a qualifying error that triggers fallback retries. The handler now answers every attempt with the same status so the final response carries the expected code, and the per-iteration mock is constructed inside the loop (the previousreset()form no longer applies).RSC19e/fallback-on-server-error-3): Retained its single-entryfallbackHosts: ["fallback.ably-realtime.com"]and host assertion — perrest/unit/fallback.mdis half-migrated: it uses aqueue_responsemock API thathelpers/mock_http.mddoes not define andwriting-test-specs.mdbans, which makes four of its tests unsatisfiable #523 this is a legitimate configured fallback, not an instance of the pinning defect.Merge order
This is PR 1 of 7 and should merge FIRST. It conflicts with the spec-point-references PR on
auth/authorize.mdand with the housekeeping PR onfallback.md/rest_client.md.No
features.mdchange is required or made.Closes #523
Closes #524
🤖 Generated with Claude Code