Skip to content

Test coverage: RecordingTransport non-JSON (HTML 502) body branch unexercised #100

Description

@TexasCoding

From Wave 5 test-coverage audit, finding F-Q-08. Severity: medium.

Gap

`kalshi/testing/_fixtures.py:62-66` falls back to `body_kind = "text"` when `json.loads` raises (`ValueError` / `UnicodeDecodeError`) — exactly what happens when a Cloudflare/ALB 502 returns `...`. Tests at `tests/test_mock_transport.py` only ever record JSON bodies. The `build_response` path for `body_kind="text"` (`_fixtures.py:91-92`) likewise has zero coverage.

Why it matters

Recording a real session will eventually capture an HTML error page. If the text branch silently corrupts the payload (latin-1 vs utf-8, lost `Content-Type`), the recording becomes a landmine that explodes on first replay. The transport claims to handle this; the tests don't prove it.

Test

Wire a `_make_stub_transport` that returns:
```python
httpx.Response(
502,
content=b"502 Bad Gateway",
headers={"content-type": "text/html"},
)
```
Record once, assert the JSON fixture has `"body_kind": "text"` and the body string round-trips. Replay and assert the client surfaces a `KalshiServerError` with the HTML body in the error message.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions