From 52705e496fedf54fe6de8f4f514b352e95e2e28c Mon Sep 17 00:00:00 2001 From: AKAZIK-py <200184714+AKAZIK-py@users.noreply.github.com> Date: Fri, 31 Jul 2026 11:53:17 +0800 Subject: [PATCH] test(moa): cover call_llm(stream=True) completed-response unwrap at the outermost seam --- tests/agent/test_auxiliary_relay.py | 49 +++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/tests/agent/test_auxiliary_relay.py b/tests/agent/test_auxiliary_relay.py index dd18782f0b2fe..d2b41a82d400f 100644 --- a/tests/agent/test_auxiliary_relay.py +++ b/tests/agent/test_auxiliary_relay.py @@ -298,3 +298,52 @@ def test_auxiliary_stream_unwraps_completed_response(relay_turn): assert run("moa_aggregator") is completed + + +def test_call_llm_stream_unwraps_completed_response(relay_turn, monkeypatch): + """Outermost seam: ``call_llm(stream=True)`` — decorated with + ``@_relay_auxiliary_call`` in production, so the Relay context is always + set — with an Anthropic-shaped client that ignores ``stream=True`` and + returns a completed response (the MoA aggregator on kimi-coding / + MiniMax / ZAI / any /anthropic gateway). Must return the raw response for + the consumer's ``hasattr(stream, "choices")`` handling, not crash with + ``TypeError: 'types.SimpleNamespace' object is not iterable``.""" + _relay, _turn = relay_turn + captured = {} + completed = SimpleNamespace( + choices=[ + SimpleNamespace( + message=SimpleNamespace(content="aggregated"), + finish_reason="stop", + ) + ], + model="kimi-k3", + ) + + def fake_create(**kwargs): + captured.update(kwargs) + return completed + + client = SimpleNamespace( + base_url="https://api.kimi.com/coding/v1", + chat=SimpleNamespace(completions=SimpleNamespace(create=fake_create)), + ) + monkeypatch.setattr( + auxiliary_client, + "_get_cached_client", + lambda *args, **kwargs: (client, "kimi-k3"), + ) + + result = auxiliary_client.call_llm( + "moa_aggregator", + provider="kimi-coding", + model="kimi-k3", + api_key="sk-test", + messages=[{"role": "user", "content": "q"}], + stream=True, + stream_options={"include_usage": True}, + ) + + assert result is completed + assert captured["stream"] is True + assert captured["stream_options"] == {"include_usage": True}