refactor: remove redundant comments and docstrings (#6527)

* refactor: remove redundant comments and docstrings

* fix(signal): annotate async context manager as a generator
This commit is contained in:
chengyongru authored and GitHub committed 2026-10-30 13:07:03 +08:00
1 parent cb3ba45317
commit a4d2430140
922 files changed
+406 -7738

No files matched your search

@@ -1,11 +1,3 @@
"""Tests for OpenAICompatProvider spec-driven behavior.
Validates that:
- OpenRouter (no strip) keeps model names intact.
- AiHubMix strips provider prefixes declared by its spec.
- Standard providers pass model names through as-is.
"""
from __future__ import annotations
import asyncio
@@ -191,7 +183,6 @@ def _fake_chat_stream_legacy_function_call_chunks():
@pytest.mark.asyncio
async def test_openai_compat_chat_stream_forwards_reasoning_deltas_deepseek_style() -> None:
"""DeepSeek Chat Completions exposes ``delta.reasoning_content`` while streaming."""
mock_chat = AsyncMock(return_value=_fake_chat_stream_reasoning_chunks())
spec = find_by_name("deepseek")
thinking: list[str] = []
@@ -480,7 +471,6 @@ async def test_openrouter_user_headers_override_default_attribution() -> None:
@pytest.mark.asyncio
async def test_openrouter_keeps_model_name_intact() -> None:
"""OpenRouter gateway keeps the full model name (gateway does its own routing)."""
mock_create = AsyncMock(return_value=_fake_chat_response())
spec = find_by_name("openrouter")
@@ -505,7 +495,6 @@ async def test_openrouter_keeps_model_name_intact() -> None:
@pytest.mark.asyncio
async def test_aihubmix_strips_model_prefix() -> None:
"""AiHubMix strips provider prefixes declared by its spec."""
mock_create = AsyncMock(return_value=_fake_chat_response())
spec = find_by_name("aihubmix")
@@ -530,7 +519,6 @@ async def test_aihubmix_strips_model_prefix() -> None:
@pytest.mark.asyncio
async def test_standard_provider_passes_model_through() -> None:
"""Standard provider (e.g. deepseek) passes model name through as-is."""
mock_create = AsyncMock(return_value=_fake_chat_response())
spec = find_by_name("deepseek")
@@ -554,7 +542,6 @@ async def test_standard_provider_passes_model_through() -> None:
@pytest.mark.asyncio
async def test_openai_compat_preserves_extra_content_on_tool_calls() -> None:
"""Gemini extra_content (thought signatures) must survive parse→serialize round-trip."""
mock_create = AsyncMock(return_value=_fake_tool_call_response())
spec = find_by_name("gemini")
@@ -603,7 +590,6 @@ def test_openai_compat_parse_preserves_array_tool_arguments() -> None:
def test_openai_model_passthrough() -> None:
"""OpenAI models pass through unchanged."""
spec = find_by_name("openai")
with patch("nanobot.providers.openai_compat_provider.AsyncOpenAI"):
provider = OpenAICompatProvider(
@@ -1361,10 +1347,6 @@ async def test_openai_compat_stream_watchdog_returns_error_on_stall(monkeypatch)
assert "stream stalled" in result.content
# ---------------------------------------------------------------------------
# Provider-specific thinking parameters (extra_body)
# ---------------------------------------------------------------------------
def _build_kwargs_for(provider_name: str, model: str, reasoning_effort=None):
spec = find_by_name(provider_name)
with patch("nanobot.providers.openai_compat_provider.AsyncOpenAI"):
@@ -1402,21 +1384,18 @@ def test_dashscope_thinking_enabled_with_reasoning_effort() -> None:
def test_dashscope_thinking_disabled_for_minimal() -> None:
"""'minimal' → wire 'minimum' + thinking off on DashScope."""
kw = _build_kwargs_for("dashscope", "qwen3-plus", reasoning_effort="minimal")
assert kw["reasoning_effort"] == "minimum"
assert kw["extra_body"] == {"enable_thinking": False}
def test_dashscope_thinking_disabled_for_minimum_alias() -> None:
"""Native 'minimum' spelling must also disable thinking, not enable it."""
kw = _build_kwargs_for("dashscope", "qwen3-plus", reasoning_effort="minimum")
assert kw["reasoning_effort"] == "minimum"
assert kw["extra_body"] == {"enable_thinking": False}
def test_non_dashscope_minimal_not_retranslated() -> None:
"""DashScope-specific translation must not leak to other providers."""
kw = _build_kwargs_for("openai", "gpt-5", reasoning_effort="minimal")
assert kw["reasoning_effort"] == "minimal"
@@ -1505,7 +1484,6 @@ def test_byteplus_thinking_disabled_for_minimal() -> None:
def test_deepseek_thinking_enabled() -> None:
"""DeepSeek V4 requires extra_body.thinking when reasoning_effort is set."""
kw = _build_kwargs_for("deepseek", "deepseek-v4-pro", reasoning_effort="high")
assert kw["extra_body"] == {"thinking": {"type": "enabled"}}
@@ -1522,7 +1500,6 @@ def test_deepseek_thinking_enabled() -> None:
def test_deepseek_reasoning_effort_controls(
effort: str | None, wire_effort: str | None, thinking_type: str | None,
) -> None:
"""DeepSeek's minimal alias enables low-effort thinking; none disables it."""
kw = _build_kwargs_for("deepseek", "deepseek-flash", reasoning_effort=effort)
if wire_effort is None:
assert "reasoning_effort" not in kw
@@ -1562,7 +1539,6 @@ def test_deepseek_backfills_reasoning_content_on_legacy_tool_call_messages() ->
def test_backfill_does_not_touch_messages_when_thinking_explicitly_off() -> None:
"""When thinking is explicitly disabled, legacy messages must NOT be altered."""
spec = find_by_name("deepseek")
with patch("nanobot.providers.openai_compat_provider.AsyncOpenAI"):
p = OpenAICompatProvider(api_key="k", default_model="deepseek-v4-pro", spec=spec)
@@ -1585,7 +1561,6 @@ def test_backfill_does_not_touch_messages_when_thinking_explicitly_off() -> None
def test_deepseek_v4_backfills_incomplete_reasoning_history_when_effort_implicit() -> None:
"""DeepSeek-V4 reasons natively: backfill even without explicit reasoning_effort."""
spec = find_by_name("deepseek")
with patch("nanobot.providers.openai_compat_provider.AsyncOpenAI"):
p = OpenAICompatProvider(api_key="k", default_model="deepseek-v4-pro", spec=spec)
@@ -1618,7 +1593,6 @@ def test_deepseek_v4_backfills_incomplete_reasoning_history_when_effort_implicit
def test_deepseek_flash_backfills_missing_tool_history_reasoning(
model: str, effort: str | None, history_reasoning: str | None,
) -> None:
"""Default thinking rejects tool-call history without reasoning_content."""
provider = OpenAICompatProvider(
api_key="k", default_model=model, spec=find_by_name("deepseek"),
)
@@ -1694,7 +1668,6 @@ def test_deepseek_chat_keeps_tool_history_when_effort_implicit() -> None:
def test_deepseek_coerces_list_content_to_string() -> None:
"""DeepSeek chat endpoint expects message.content to be a string."""
spec = find_by_name("deepseek")
with patch("nanobot.providers.openai_compat_provider.AsyncOpenAI"):
p = OpenAICompatProvider(api_key="k", default_model="deepseek-chat", spec=spec)
@@ -1731,7 +1704,6 @@ def test_deepseek_coerces_list_content_to_string() -> None:
def test_deepseek_vision_preserves_multimodal_content(
model: str, prefixed: bool, with_text: bool, responses: bool,
) -> None:
"""DeepSeek vision models must preserve images on both API surfaces."""
if prefixed:
model = f"deepseek/{model}"
spec = find_by_name("deepseek")
@@ -1789,7 +1761,6 @@ def test_deepseek_pro_remains_text_only(responses: bool) -> None:
def test_non_deepseek_keeps_list_content() -> None:
"""Only DeepSeek should force string content; OpenAI-compatible providers keep blocks."""
spec = find_by_name("openai")
with patch("nanobot.providers.openai_compat_provider.AsyncOpenAI"):
p = OpenAICompatProvider(api_key="k", default_model="gpt-4o", spec=spec)
@@ -1813,7 +1784,6 @@ def test_non_deepseek_keeps_list_content() -> None:
def test_openai_no_thinking_extra_body() -> None:
"""Non-thinking providers should never get extra_body for thinking."""
kw = _build_kwargs_for("openai", "gpt-4o", reasoning_effort="medium")
assert "extra_body" not in kw
@@ -1867,7 +1837,6 @@ def kimi_k3_model(request: pytest.FixtureRequest) -> str:
def test_kimi_k3_uses_native_defaults(kimi_k3_model: str) -> None:
"""K3 omits fixed sampling params and uses the non-deprecated token limit field."""
kw = _build_kwargs_for("moonshot", kimi_k3_model, reasoning_effort=None)
assert "temperature" not in kw
@@ -1879,7 +1848,6 @@ def test_kimi_k3_uses_native_defaults(kimi_k3_model: str) -> None:
@pytest.mark.parametrize("effort", ["low", "high", "max"])
def test_kimi_k3_preserves_supported_reasoning_effort(kimi_k3_model: str, effort: str) -> None:
"""K3 uses top-level reasoning_effort, never the K2.x thinking body."""
kw = _build_kwargs_for("moonshot", kimi_k3_model, reasoning_effort=effort)
assert kw["reasoning_effort"] == effort
@@ -1888,7 +1856,6 @@ def test_kimi_k3_preserves_supported_reasoning_effort(kimi_k3_model: str, effort
def test_kimi_k3_normalizes_legacy_enabled_reasoning_effort(kimi_k3_model: str) -> None:
"""Switching a K2.x preset to K3 must not send unsupported effort values."""
kw = _build_kwargs_for("moonshot", kimi_k3_model, reasoning_effort="medium")
assert kw["reasoning_effort"] == "max"
@@ -1897,7 +1864,6 @@ def test_kimi_k3_normalizes_legacy_enabled_reasoning_effort(kimi_k3_model: str)
@pytest.mark.parametrize("effort", ["none", "minimal"])
def test_kimi_k3_omits_disabled_reasoning_effort(kimi_k3_model: str, effort: str) -> None:
"""K3 cannot disable reasoning, so disabled effort falls back to its default."""
kw = _build_kwargs_for("moonshot", kimi_k3_model, reasoning_effort=effort)
assert "reasoning_effort" not in kw
@@ -1923,7 +1889,6 @@ def test_openrouter_kimi_thinking_mapping(model, effort) -> None:
"thinking": {"type": "enabled"},
"reasoning": {"effort": effort},
}
# Even via OR, reasoning_effort wire kwarg is dropped for kimi models
assert "reasoning_effort" not in kw
@@ -1935,7 +1900,6 @@ def test_kimi_k27_code_thinking_none_omits_disabled() -> None:
def test_kimi_k27_code_thinking_none_with_openrouter_prefix_omits_disabled() -> None:
"""OpenRouter-routed Kimi K2.7 Code should not request disabled thinking."""
kw = _build_kwargs_for("openrouter", "moonshotai/kimi-k2.7-code", reasoning_effort="none")
assert "extra_body" not in kw
assert "reasoning_effort" not in kw
@@ -1946,35 +1910,26 @@ def test_kimi_k27_code_thinking_none_with_openrouter_prefix_omits_disabled() ->
def test_moonshot_kimi_k25_k26_omit_temperature(
model: str, reasoning_effort: str | None,
) -> None:
"""Moonshot chooses the valid temperature from the K2.5/K2.6 thinking mode."""
kw = _build_kwargs_for("moonshot", model, reasoning_effort=reasoning_effort)
assert "temperature" not in kw
def test_moonshot_kimi_k27_code_temperature_override() -> None:
"""Moonshot registry should force temperature 1.0 for Kimi K2.7 Code."""
kw = _build_kwargs_for("moonshot", "kimi-k2.7-code", reasoning_effort=None)
assert kw["temperature"] == 1.0
def test_kimi_k2_series_no_thinking_injection() -> None:
"""kimi-k2 (non-thinking) models must NOT receive extra_body.thinking."""
kw = _build_kwargs_for("moonshot", "kimi-k2", reasoning_effort="high")
assert "extra_body" not in kw
def test_kimi_k2_thinking_series_no_thinking_injection() -> None:
"""kimi-k2-thinking series models must NOT receive extra_body.thinking."""
kw = _build_kwargs_for("moonshot", "kimi-k2-thinking", reasoning_effort="high")
assert "extra_body" not in kw
# ---------------------------------------------------------------------------
# reasoning_effort="none" — treated as thinking disabled
# ---------------------------------------------------------------------------
def test_dashscope_thinking_disabled_for_none_string() -> None:
"""reasoning_effort='none' disables thinking and must not emit reasoning_effort on DashScope."""
kw = _build_kwargs_for("dashscope", "qwen3.6-plus", reasoning_effort="none")
assert kw.get("extra_body") == {"enable_thinking": False}
assert "reasoning_effort" not in kw
@@ -1996,7 +1951,6 @@ def test_qwen_thinking_disabled_via_model_level_mapping() -> None:
def test_deepseek_no_backfill_when_reasoning_effort_none_string() -> None:
"""reasoning_effort='none' must NOT trigger reasoning_content backfill (thinking inactive)."""
spec = find_by_name("deepseek")
with patch("nanobot.providers.openai_compat_provider.AsyncOpenAI"):
p = OpenAICompatProvider(api_key="k", default_model="deepseek-v4-pro", spec=spec)