fix: make h2 patch repair failures diagnosable

This commit is contained in:
thanhnv
2026-07-18 12:04:32 +07:00
parent 61a8253679
commit 659ed09839
7 changed files with 120 additions and 9 deletions
@@ -150,6 +150,15 @@ class FakeResp:
def read(self):
return json.dumps(self.payload).encode()
class EmptyResp:
headers = {"Content-Type": "application/json"}
def __enter__(self):
return self
def __exit__(self, exc_type, exc, tb):
return False
def read(self):
return b""
def fake_urlopen(req, timeout):
seen.append((req.full_url, dict(req.header_items()), json.loads(req.data.decode())))
if req.full_url.endswith("/v1/responses"):
@@ -207,6 +216,14 @@ for fn, bad in (
assert exc.code == 2, exc.code
else:
raise AssertionError(f"{fn.__name__} accepted malformed provider payload")
try:
with contextlib.redirect_stderr(io.StringIO()):
mc.decode_provider_json(EmptyResp(), "openai-compatible")
except SystemExit as exc:
assert exc.code == 2, exc.code
else:
raise AssertionError("empty provider response was accepted")
print("ok")
PY
[[ $? -eq 0 ]] && pass "cloud/gateway provider responses parse real usage and reject malformed payloads" || fail "cloud/gateway provider parser coverage failed"