From f60fd876c6eadae43188e8bd3e0aa74a46202fc9 Mon Sep 17 00:00:00 2001 From: worldmozara Date: Wed, 29 Jul 2026 00:46:08 +0800 Subject: [PATCH] test: update for kind-based dispatch and remove ResponsesChatClient references --- tests/test_agent/test_responses_bridge.py | 46 +---------------------- tests/test_runtime/test_client_factory.py | 30 ++++++++------- 2 files changed, 18 insertions(+), 58 deletions(-) diff --git a/tests/test_agent/test_responses_bridge.py b/tests/test_agent/test_responses_bridge.py index f3a2ee9..eb0a069 100644 --- a/tests/test_agent/test_responses_bridge.py +++ b/tests/test_agent/test_responses_bridge.py @@ -1,7 +1,4 @@ -from __future__ import annotations - import msgspec -import pytest from plyngent.agent.responses_bridge import ( chat_messages_to_responses_input, @@ -11,8 +8,7 @@ from plyngent.agent.responses_bridge import ( responses_status_to_finish_reason, tool_items_to_response_tools, ) -from plyngent.agent.responses_client import ResponsesChatClient -from plyngent.lmproto.openai.model import Response, ResponsesCreateParam +from plyngent.lmproto.openai.model import Response from plyngent.lmproto.openai_compatible.model import ( AssistantChatMessage, AssistantFunctionTool, @@ -158,43 +154,3 @@ def test_provider_tools_merged_after_local_functions() -> None: assert tools[0].name == "local_tool" assert tools[1]["type"] == "web_search" assert tools[2]["vector_store_ids"] == ["vs_1"] - - -@pytest.mark.asyncio -async def test_responses_chat_client_non_stream(monkeypatch: pytest.MonkeyPatch) -> None: - from plyngent.lmproto.openai.client import OpenAIClient - from plyngent.lmproto.openai_compatible.config import OpenAIConfig - - platform = OpenAIClient(OpenAIConfig(access_key_or_token="sk", base_url="https://example/v1")) - - body = { - "id": "resp_x", - "object": "response", - "created_at": 1, - "model": "gpt-test", - "status": "completed", - "output": [ - { - "id": "msg_1", - "type": "message", - "role": "assistant", - "status": "completed", - "content": [{"type": "output_text", "text": "hello", "annotations": []}], - } - ], - "usage": {"input_tokens": 3, "output_tokens": 1, "total_tokens": 4}, - } - - async def fake_responses(param: ResponsesCreateParam, *, stream: bool = False): - assert stream is False - assert param.model == "gpt-test" - assert param.store is False - return msgspec.convert(body, Response) - - monkeypatch.setattr(platform, "responses", fake_responses) - client = ResponsesChatClient(platform) - result = await client.chat_completions( - ChatCompletionsParam(model="gpt-test", messages=[UserChatMessage(content="hi")]), - stream=False, - ) - assert result.choices[0].message.content == "hello" diff --git a/tests/test_runtime/test_client_factory.py b/tests/test_runtime/test_client_factory.py index b1d4a35..09c2438 100644 --- a/tests/test_runtime/test_client_factory.py +++ b/tests/test_runtime/test_client_factory.py @@ -20,24 +20,22 @@ def test_openai_provider_defaults_base_url() -> None: config = provider_to_openai_config(provider) assert config.access_key_or_token == "sk-test" assert config.base_url == "https://api.openai.com/v1" - from plyngent.agent.responses_client import ResponsesChatClient + from plyngent.lmproto.openai import OpenAIClient client = create_client(provider) - assert isinstance(client, ResponsesChatClient) - assert hasattr(client, "chat_completions") - assert client._provider_tools == [{"type": "web_search"}] + assert isinstance(client, OpenAIClient) + assert client.kind == "responses" def test_openai_provider_tools_passed_to_wrapper() -> None: - from plyngent.agent.responses_client import ResponsesChatClient + from plyngent.lmproto.openai import OpenAIClient provider = OpenAIProvider( access_key_or_token="sk-test", provider_tools=[{"type": "web_search"}], ) client = create_client(provider) - assert isinstance(client, ResponsesChatClient) - assert client._provider_tools == [{"type": "web_search"}] + assert isinstance(client, OpenAIClient) def test_openai_compatible_requires_url() -> None: @@ -76,9 +74,12 @@ def test_deepseek_ignores_legacy_convention_extra() -> None: def test_anthropic_not_implemented() -> None: + from plyngent.lmproto.anthropic import AnthropicClient + provider = AnthropicProvider(access_key_or_token="sk-test") - with pytest.raises(ProviderNotSupportedError, match="anthropic"): - _ = create_client(provider) + client = create_client(provider) + assert isinstance(client, AnthropicClient) + assert client.kind == "messages" def test_model_level_preset_url_overrides_parent() -> None: @@ -91,7 +92,7 @@ def test_model_level_preset_url_overrides_parent() -> None: }, ) openai_client = create_client(provider, model="gpt") - assert openai_client.__class__.__name__ == "ResponsesChatClient" + assert openai_client.kind == "responses" assert provider_to_openai_config(provider, model="gpt").base_url == "https://api.openai.com/v1" compat_client = create_client(provider, model="qwen") @@ -99,11 +100,14 @@ def test_model_level_preset_url_overrides_parent() -> None: assert provider_to_openai_config(provider, model="qwen").base_url == "https://gateway.example/v1" -def test_model_level_anthropic_preset_not_implemented() -> None: +def test_model_level_anthropic_preset() -> None: + from plyngent.lmproto.anthropic import AnthropicClient + provider = OpenAICompatibleProvider( access_key_or_token="sk-test", url="https://gateway.example/v1", models={"claude": ModelConfig(preset="anthropic", url="https://api.anthropic.com/v1")}, ) - with pytest.raises(ProviderNotSupportedError, match="anthropic"): - _ = create_client(provider, model="claude") + client = create_client(provider, model="claude") + assert isinstance(client, AnthropicClient) + assert client.kind == "messages"