Skip to content

feat(responses): a canned reply can carry an error status, and the history records it as error - #169

Merged
VicSheCodes merged 1 commit into
mainfrom
canned-reply-with-an-error-status
Oct 26, 2026
Merged

VicSheCodes merged 1 commit into
mainfrom
canned-reply-with-an-error-status

Conversation

@VicSheCodes

Copy link
Copy Markdown
Collaborator

Why

A router test needs a node that answers an error status with a body that the simulator cannot build today, for example a 503 whose body holds both result and error. mode: "error" builds its own error envelope, and the canned body of a responses entry took a 2xx status only. A test in smart-router-automation checks that such a reply reaches the caller unchanged, and it waits on this change.

What changed

  • provider_simulator/control_api.py: the canned body of a responses entry takes a status from 200 to 299, as before, and an error status from 400 to 599. A 1xx (not a final reply), a 3xx (neither a success nor an error) and a status that is not an int are still refused with HTTP 400.
  • provider_simulator/listeners/base.py: the history row of a canned reply follows its status: success inside 2xx, error outside it. The body is never read for the label. JSON-RPC and GraphQL serve the canned reply, so both follow the rule.
  • The docstrings of jsonrpc.py, graphql.py and Listener.build_body_override, the comment above the status check, and docs/using_the_simulator.md state the rule.
  • tests/test_simulator_per_method_overrides.py: a canned body with status 400, 503 or 599 is accepted, sent with that status and the exact body, and recorded as error. Status 199, 300, 399, 600 and the text "503" are refused with HTTP 400. These two tests replace the test that refused a 500.
  • tests/test_listener_graphql.py: a canned GraphQL body is labelled by its status and not by its body: a 200 that holds errors reads success, and a 503 reads error.

How to verify

pytest tests/test_simulator_per_method_overrides.py tests/test_listener_graphql.py -v

Results

  • The new cases failed before the change: the control API refused 400, 503 and 599, and a canned GraphQL 503 was recorded as success.
  • Each new check fails on a broken copy of the code: a label that always reads success fails 4 cases, and a status range of 200 to 599 fails the 300 and 399 cases.
  • Whole suite, locally: 2546 passed. The last CI run on main had 2538; the difference is the 8 new cases. One warning came from a WebSocket test that closes a connection: a server thread hit "bad file descriptor" while it printed an error. That test does not reach the changed code, and the warning did not come back in three reruns of its class.
  • black, ruff and mypy: clean.

…story records it as error

A router test needs a node that answers an error status with a body that
mode "error" cannot build, for example a 503 whose body holds both result
and error. The canned body of a responses entry took a 2xx status only.

The control API now accepts a canned status from 400 to 599 beside 2xx.
A 1xx, a 3xx and a status that is not an int are still refused with 400.
The history row of a canned reply follows its status: success inside 2xx,
error outside it. The body is never read for the label. JSON-RPC and
GraphQL serve the canned reply, so both follow the rule.

Tests: a JSON-RPC canned body with status 400, 503 or 599 is accepted,
sent as given and recorded as error; status 199, 300, 399, 600 and the
text "503" are refused; a canned GraphQL body is labelled by its status,
not by its body. The new cases failed before the change. A label that
always reads success fails 4 of them, and a range of 200 to 599 fails the
300 and 399 cases.
@VicSheCodes
VicSheCodes requested a review from idanhen1 as a code owner October 26, 2026 19:25
@VicSheCodes VicSheCodes added the no-ticket PR intentionally closes no Jira ticket label Oct 26, 2026
@VicSheCodes VicSheCodes self-assigned this Oct 26, 2026
@VicSheCodes
VicSheCodes merged commit fd5fb88 into main Oct 26, 2026
7 of 8 checks passed
@VicSheCodes
VicSheCodes deleted the canned-reply-with-an-error-status branch October 26, 2026 21:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-ticket PR intentionally closes no Jira ticket

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant