From 3183e43dc184303cbef6a00f8cece16e1d20bce3 Mon Sep 17 00:00:00 2001 From: mateo-berri <277851410+mateo-berri@users.noreply.github.com> Date: Fri, 30 Oct 2026 17:35:51 -0700 Subject: [PATCH] test(guardrails): cover Presidio's refusal when a word or null line comes before a Gemini stream The first read then holds the unreadable line behind one Presidio can pass, so the check has to look at every frame in it. --- tests/unit/proxy/guardrails/guardrail_hooks/test_presidio.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/unit/proxy/guardrails/guardrail_hooks/test_presidio.py b/tests/unit/proxy/guardrails/guardrail_hooks/test_presidio.py index 3368be45292..6feb34f2711 100644 --- a/tests/unit/proxy/guardrails/guardrail_hooks/test_presidio.py +++ b/tests/unit/proxy/guardrails/guardrail_hooks/test_presidio.py @@ -2622,6 +2622,8 @@ async def test_apply_to_output_streaming_anthropic_sse_bytes_led_by_a_non_object await anext(stream) +_GEMINI_TEXT_FRAME: Final = b'data: {"candidates": [{"content": {"parts": [{"text": "4111"}]}}]}\n\n' + STREAMS_WITH_A_NON_OBJECT_LINE_AND_NO_ANTHROPIC_FRAME: Final = { "lone-line": (b"data: 5\n\n",), "then-an-object-of-no-known-type": (b"data: 5\n\n", b'data: {"foo": 1}\n\n', b'data: {"text": "4111"}\n\n'), @@ -2632,6 +2634,9 @@ STREAMS_WITH_A_NON_OBJECT_LINE_AND_NO_ANTHROPIC_FRAME: Final = { "dict-type": (b'data: {"type": {"a": 1}}\n\n', b'data: {"text": "4111"}\n\n'), "error-frame-with-a-list-type": (b'event: error\ndata: {"type": []}\n\n', b'data: {"text": "4111"}\n\n'), "cut-character-at-the-end": (b'data: [5]\xe2',), + "word-then-non-object-before-gemini": (b"data: hello\n\n", b"data: 5\n\n", _GEMINI_TEXT_FRAME), + "null-then-non-object-before-gemini": (b"data: null\n\n", b"data: 5\n\n", _GEMINI_TEXT_FRAME), + "word-then-list-type-before-gemini": (b"data: hello\n\n", b'data: {"type": []}\n\n', _GEMINI_TEXT_FRAME), }