Skip to content

UTS: migrate rest/unit mock HTTP to the handler idiom and fix /time response shape - #534

Open
owenpearson wants to merge 3 commits into
mainfrom
fix/uts-mock-http-migration
Open

owenpearson wants to merge 3 commits into
mainfrom
fix/uts-mock-http-migration

Conversation

@owenpearson

@owenpearson owenpearson commented Sep 21, 2026 •

Copy link
Copy Markdown
Member

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, and mock_http.captured_requests) with the onRequest/onConnectionAttempt handler idiom plus a LOCAL captured_requests array (with local request_count/captured_hosts where needed), matching the contract in helpers/mock_http.md and the already-migrated blocks in fallback.md. In the same pass:

  • Error-body fixtures repaired to the full { "error": { "message", "code", "statusCode" } } shape, including the CloudFront fixture whose error was a bare string and the RSC15l/http-4xx-no-fallback-5 handler, which asserts error.statusCode == status_code and previously sent a body with no statusCode. (Left as is: the unasserted 404 {"error": {"code": 40400}} fall-through branches in the REC3 tests, to avoid widening the REC3 overlap with UTS: rest/unit housekeeping fixes #538, and the illustrative bodies in helpers/mock_http.md.)
  • The two pinned-fallback-host tests (RSC15f/successful-fallback-cached-0, RSC15f/cached-fallback-expires-1) now dispatch on req.url.host and bind assertions to the observed fallback host rather than a hard-coded name, resolving the 1/5-flaky pin against RSC15a's random ordering.
  • Mock-contract cross-references retargeted from rest_client.md to helpers/mock_http.md at fallback.md:10 and request.md:10,16; dropped the fallback.md:12-15 block requesting capabilities the contract deliberately omits.

#524 — fix the /time response shape

/time returns a single-element ARRAY [server_time_ms], not {"time": N}. There were 51 object-shaped sites: the 48 tabulated in #524 across six rest/unit specs, plus 3 in uts/docs/writing-test-specs.md. Corrected at every site, contract file first (helpers/mock_http.md, then writing-test-specs.md, then the specs), including rest_client.md's msgpack site which becomes msgpack_encode([1234567890000]). Migrated handlers from #523 emit the array shape so the two fixes converge; no object-shaped /time fixture and no queue_* / mock_http.captured_requests call remains anywhere under uts/ (the only matches left are the "Common Mistakes to Avoid" entries in writing-test-specs.md that ban them). The 13 sites that were already array-shaped (logging.md ×5, time.md ×4, fallback.md ×3, and the msgpack body at auth/token_renewal.md:567) are unchanged.

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 redirect
  • uts/rest/unit/rest_client.md — 12 queue sites + msgpack /time + array shape; RSC13/request-timeout-enforced-0 now sets fallbackHosts: [] (RSC15m) so the request timeout is observed on the primary host instead of being followed by fallback retries the test never answers
  • uts/rest/unit/request_endpoint.md — local captured_requests + array shape
  • uts/rest/unit/helpers/mock_http.md — 4 /time sites
  • uts/rest/unit/auth/authorize.md — 1 /time site
  • uts/docs/writing-test-specs.md — 3 /time sites in the authoring guide

Judgment calls

Merge order

This is PR 1 of 7 and should merge FIRST. It conflicts with the spec-point-references PR on auth/authorize.md and with the housekeeping PR on fallback.md/rest_client.md.

No features.md change is required or made.

Closes #523
Closes #524

🤖 Generated with Claude Code

…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>
owenpearson and others added 2 commits November 27, 2026 13:14
RSC15l/http-4xx-no-fallback-5 asserts error.statusCode == status_code,
but its mocked body carried only a code. TI1 does not make the HTTP
status authoritative over the payload, so an SDK that reads statusCode
from the body could not satisfy the assertion. Both RSC15l handler
fixtures now carry the full message/code/statusCode triple.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A request timeout is a qualifying error (RSC15l), so with the default
fallback domains the client retries on a fallback host after the
primary times out. The test answers only the first request, leaving
each retry to time out in turn, and the primary's timeout is masked by
the retries. Configure fallbackHosts: [] (RSC15m) so the timeout is
observed on the primary host alone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch was successfully deployed

1 active deployment
staging/pull/534 — e4aeee1a Deployed Nov 27, 2026 by github-actions[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant