Commit 63751476 authored by kzangeli's avatar kzangeli
Browse files

doubts: add #69 (HttpCtrl Set Stub Reply double-encodes string body) — RESOLVED

The HttpCtrl `set_stub_reply` double-encode doubt had no entry in the file.
Add it as #69 (adjacent to #68, the other HttpCtrl distop stub-body doubt),
marked RESOLVED: the conditional auto-serialise landed on develop via the
housekeeping bundle !278 and, redundantly, the standalone !282.

Doc-only; no behaviour change.
parent a585469c
Loading
Loading
Loading
Loading
+46 −0
Original line number Diff line number Diff line
@@ -2110,6 +2110,52 @@ str/bytes" failure rather than a mysterious half-response
and broker-side "transport failure".


## 69. HttpCtrl vendored 0.3.1 — `Set Stub Reply` double-encodes a string body

**Hit:** DistOps tests that call `Set Stub Reply <method> <url> <status> <body>`
with a body produced by `Convert JSON To String` (a Python `str` already
holding serialised JSON) — including `D011_02_exc_01` and structurally
similar tests across the suite. The broker forwards correctly and the stub
matches, but the wire body it receives is `'"[{\"id\":\"X\"}]"'` — a JSON
string wrapping the intended array. The broker's response parser sees a
`String` where it expects an `Array`, the merge can't proceed, and the
entity-level assertion (`$.speed`, etc.) fails.

**Why:** in `libraries/robotframework-httpctrl/src/HttpCtrl/__init__.py`,
`set_stub_reply` used to wrap every body in `json.dumps()`:

```python
response = Response(int(status), None, json.dumps(body), None, None)
```

That was presumably added to fix the **opposite** problem (`Set Stub Reply`
receiving a Python `dict` and sending it raw — the `D010_01_aux` / MR !273
case; see #68's "Independent HttpCtrl bug" note). The fork over-corrected:
dict callers were served correctly, but callers passing an already-serialised
JSON string got it double-encoded.

**Impact / broker:** none — the broker is correct; the wire body was mangled
upstream of it.

**Status:** RESOLVED — auto-serialise only non-`str`/`bytes` bodies:

```python
if not isinstance(body, (str, bytes)) and body is not None:
    body = json.dumps(body)
response = Response(int(status), None, body, None, None)
```

This handles both callers: dicts/lists get auto-serialised (the original
intent of the fork's patch), str/bytes pass through unchanged. Landed on
develop via the housekeeping bundle **!278** and, redundantly, the standalone
**!282** (the fix had been duplicated across both branches — !278 merged
first, so !282 reduced to the explanatory comment + docstring). The
`D010_01_aux` test-side work-around (`Evaluate json.dumps($entity_body)`,
landed via !273) stays harmless — a string `json.dumps`'d to itself is
unchanged — so !273 needs no follow-up. Verified: `D011_02_exc_01` passes and
the DistOps subset PASS count rose ~9 vs the pre-fix baseline.


## 70. `D003_01_exc` — Append-Attrs fragment sent as `application/json` with no Link header, so attribute names don't expand to the CSR's

**Hit:** `D003_01_exc Append Entity Attribute` fails the