From 63acfc4f2ffe79155fde695fa955714b5577d541 Mon Sep 17 00:00:00 2001 From: Xubin Ren Date: Tue, 7 Apr 2026 16:58:47 +0000 Subject: [PATCH] test: fix trailing-space mismatch and add regression tests for normal models - Fix assertion in streaming dict fallback test (trailing space in data not reflected in expected value). - Add two regression tests proving that models with reasoning_content (e.g. DeepSeek-R1) and standard models (no reasoning fields) are completely unaffected by the reasoning fallback. Made-with: Cursor --- tests/providers/test_stepfun_reasoning.py | 44 ++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/tests/providers/test_stepfun_reasoning.py b/tests/providers/test_stepfun_reasoning.py index 0c39d9342..05e5416d4 100644 --- a/tests/providers/test_stepfun_reasoning.py +++ b/tests/providers/test_stepfun_reasoning.py @@ -121,7 +121,7 @@ def test_parse_chunks_dict_stepfun_reasoning_fallback() -> None: { "choices": [{ "finish_reason": None, - "delta": {"content": None, "reasoning": "step 2. "}, + "delta": {"content": None, "reasoning": "step 2."}, }], }, { @@ -138,6 +138,48 @@ def test_parse_chunks_dict_stepfun_reasoning_fallback() -> None: assert result.reasoning_content == "Thinking step 1... step 2." +# ── Regression: normal models unaffected ──────────────────────────────────── + + +def test_parse_dict_normal_model_with_reasoning_content_unaffected() -> None: + """Models that use reasoning_content (e.g. DeepSeek-R1) are not affected.""" + with patch("nanobot.providers.openai_compat_provider.AsyncOpenAI"): + provider = OpenAICompatProvider() + + response = { + "choices": [{ + "message": { + "content": "The answer is 42.", + "reasoning_content": "Let me think step by step...", + }, + "finish_reason": "stop", + }], + } + + result = provider._parse(response) + + assert result.content == "The answer is 42." + assert result.reasoning_content == "Let me think step by step..." + + +def test_parse_dict_standard_model_no_reasoning_unaffected() -> None: + """Standard models (no reasoning fields at all) work exactly as before.""" + with patch("nanobot.providers.openai_compat_provider.AsyncOpenAI"): + provider = OpenAICompatProvider() + + response = { + "choices": [{ + "message": {"content": "Hello!"}, + "finish_reason": "stop", + }], + } + + result = provider._parse(response) + + assert result.content == "Hello!" + assert result.reasoning_content is None + + def test_parse_chunks_dict_reasoning_precedence() -> None: """reasoning_content takes precedence over reasoning in dict chunks.""" chunks = [