test(proxy/batch): stop the bypass stub raising into a broad except

`raise AssertionError("compression ran despite bypass")` never reached anyone. handle_batch_create
wraps its whole body in `except Exception`, which swallows it, logs, records a failed request, and
returns a 500 — so the message was misleading to read and contributed nothing to the guard.

`assert response is passthrough_response` was always what caught a regression here; verified by
deleting the guard and watching exactly that line fail on both header forms.

Now records the invocation instead, matching the two sibling stubs in this file and the standing rule
for code under a broad except. The zero-request stats short-circuit a reverted path at the
total_requests==0 check, so the upload stub stays reachable and still blocks a real call.
This commit is contained in:
inix-x 2026-07-27 12:48:04 +08:00
parent 712414bd71
commit 22a624bf38

View file

@ -1314,9 +1314,14 @@ async def test_handle_batch_create_bypass_skips_compression_entirely(
called.append("upload")
return "file-2"
# Records rather than raising. handle_batch_create wraps its whole body in
# `except Exception`, which swallows an AssertionError and books a 500 — so
# that message never reached anyone, and `called` below is the real guard.
# The zero-request stats short-circuit the reverted path at the
# total_requests==0 check, before it can reach the upload.
async def fail_compress(content, request_id): # noqa: ANN001
called.append("compress")
raise AssertionError("compression ran despite bypass")
return [], {"total_requests": 0}
monkeypatch.setattr(handler, "_download_openai_file", fail_download)
monkeypatch.setattr(handler, "_upload_openai_file", fail_upload)