Make the mock server faithful to the backend: rate-limit headers + no_data 404s#9
Merged
Merged
Conversation
|
The author of this PR, MarketDataDev03, is not an activated member of this organization on Codecov. |
MarketDataDev01
approved these changes
Jun 1, 2026
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.
Make the mock server faithful to the backend: rate-limit headers +
no_data404sSummary
Two divergences between
examples/mock-serverand the real backend (../api/)were surfaced in review. Both are fixed here so consumer demos exercise the same
wire behavior a real consumer sees.
Rate-limit headers were never emitted. The mock only set
cf-rayandContent-Type, soclient.getRateLimits()always returnednullagainst itand the §10.3 exhausted-credits preflight path could not be exercised without
hand-scripting all four headers on every step. The real backend attaches
X-Api-Ratelimit-{Limit,Remaining,Reset,Consumed}to every response viaupdate_user_quota(api/.../common/util/user_quotas_helper.py:162).Unknown routes returned the wrong envelope. The mock answered
404 {"s":"error","errmsg":"..."}. The backend'scustom_404(
api/.../marketDataApi/views.py:50) returns404 {"s":"no_data"}. Thismatters because the SDK parses
{"s":"error"}into a thrownParseErrorwhile
{"s":"no_data"}is a successful empty response — so the mock made ano-data path look like a failure.
Changes
examples/mock-server/server.py_default_ratelimit_headers()— emits all fourx-api-ratelimit-*headers (all-or-nothing, matching
RateLimitHeaders.parse),reset24h out.(via
setdefault, so a step can override e.g.x-api-ratelimit-remaining: 0).404 {"s":"no_data"}(and inherit the rate-limitheaders, just like the backend's
custom_404).examples/mock-server/README.mdno_data) and document the rate-limitheaders + how to script the exhausted-credits case.
Exhausted-credits scenario
The headers are scriptable, so driving the preflight is one step:
{"steps": [{"status": 200, "body": "{\"s\":\"ok\"}", "headers": {"x-api-ratelimit-remaining": "0", "x-api-ratelimit-reset": "9999999999"}}]}The step's
remaining: 0wins; the other three headers auto-fill.Verification
Ran the server (
uvicorn server:app) and hit it withcurl:GET /status/(default) →200with all fourx-api-ratelimit-*headerspresent →
getRateLimits()now returns a real snapshot instead ofnull.GET /v1/stocks/quotes/AAPL/(unknown route) →404 {"s":"no_data"}withrate-limit headers attached.
x-api-ratelimit-remaining: 0→ step value wins, other threeheaders auto-fill.
python -m py_compile server.py→ clean.Regression check
{"s":"error"}body inexamples/consumer-test/is scripted explicitlyvia
Step.of(...); none relied on the default 404 envelope, so the switch tono_datadoes not affect them.ResponseFeaturesAppalready scripted its own404 {"s":"no_data"}, which isnow consistent with the default.
Scope
Mock-server / examples only. No changes to the SDK's
src/mainor its JUnitsuite (the
CapturingClientstub already covers these scenarios at the wirelevel).