From baf1200e0aa20f21d3d4aa0ac1ca9a375d46287a Mon Sep 17 00:00:00 2001 From: teknium1 <127238744+teknium1@users.noreply.github.com> Date: Sat, 12 Sep 2026 19:16:22 -0700 Subject: [PATCH] refactor(commandcode): drop the deepseek ImportError guard, trim tests to two invariants The deepseek plugin is bundled and always loads, so the try/except around the delegation import was defense-in-depth for a path that cannot fail. Tests reduced to the two contracts that matter: /reasoning none reaches the wire as thinking.disabled, and DeepSeek ids produce exactly the native DeepSeek profile's output while non-DeepSeek families stay a no-op. --- .../model-providers/commandcode/__init__.py | 54 ++++-------- .../test_commandcode_profile.py | 85 +++---------------- 2 files changed, 31 insertions(+), 108 deletions(-) diff --git a/plugins/model-providers/commandcode/__init__.py b/plugins/model-providers/commandcode/__init__.py index 01584c7802..37bfff5b2f 100644 --- a/plugins/model-providers/commandcode/__init__.py +++ b/plugins/model-providers/commandcode/__init__.py @@ -38,6 +38,23 @@ class CommandCodeProfile(ProviderProfile): return None + def build_api_kwargs_extras( + self, *, reasoning_config: dict | None = None, model: str | None = None, **context + ) -> tuple[dict, dict]: + """DeepSeek ids (``deepseek/deepseek-v4-flash``) get the native DeepSeek wire + controls: DeepSeek V4+ defaults to thinking when ``thinking`` is omitted, so + without them ``/reasoning`` never reaches the request (#95232). Other model + families stay a no-op — CommandCode declares no reasoning vocabulary for them.""" + m = (model or "").strip() + if not m.lower().startswith("deepseek/") or len(m) <= len("deepseek/"): + return {}, {} + from plugins.model_providers.deepseek import deepseek as _deepseek_profile + + return _deepseek_profile.build_api_kwargs_extras( + reasoning_config=reasoning_config, model=m.split("/", 1)[1], **context, + ) + + class CommandCodeAnthropicProfile(CommandCodeProfile): """CommandCode — Anthropic Messages API-compatible endpoint.""" @@ -48,43 +65,6 @@ class CommandCodeAnthropicProfile(CommandCodeProfile): all_models = super().fetch_models(api_key=api_key, base_url=base_url, timeout=timeout) return None if all_models is None else [m for m in all_models if m.startswith("claude-")] - def build_api_kwargs_extras( - self, *, reasoning_config: dict | None = None, model: str | None = None, **context - ) -> tuple[dict, dict]: - """Apply the native DeepSeek reasoning controls for DeepSeek-family ids. - - CommandCode fronts DeepSeek with vendor-prefixed ids - (``deepseek/deepseek-v4-flash``). DeepSeek V4+ defaults to thinking - mode when the ``thinking`` field is omitted, so without an explicit - wire control a Hermes ``/reasoning none`` changes the session state - but not the actual request — the turn sits in - ``reflecting.../brainstorming...`` for minutes (#95232). Strip the - vendor prefix and delegate to the native DeepSeek profile's logic - (extra_body.thinking + reasoning_effort mapping); other CommandCode - model families keep the base no-op behavior. - """ - m = (model or "").strip() - if not m.lower().startswith("deepseek/") or len(m) <= len("deepseek/"): - return {}, {} - try: - from plugins.model_providers.deepseek import deepseek as _deepseek_profile - except ImportError: - # The bundled-plugin loader tolerates a plugin failing to load - # (it pops the half-registered module and continues), so the - # shim may be absent. Degrade to the pre-fix no-op instead of - # crashing every DeepSeek-routed CommandCode turn. - logger.warning( - "DeepSeek provider plugin unavailable; CommandCode cannot " - "forward reasoning controls (#95232)", - exc_info=True, - ) - return {}, {} - return _deepseek_profile.build_api_kwargs_extras( - reasoning_config=reasoning_config, - model=m.split("/", 1)[1], - **context, - ) - commandcode = CommandCodeProfile( name="commandcode", aliases=("commandcode-chat",), api_mode="chat_completions", diff --git a/tests/plugins/model_providers/test_commandcode_profile.py b/tests/plugins/model_providers/test_commandcode_profile.py index 5edfa5e7e0..7ae3f2953e 100644 --- a/tests/plugins/model_providers/test_commandcode_profile.py +++ b/tests/plugins/model_providers/test_commandcode_profile.py @@ -85,85 +85,28 @@ class TestCommandCodeProfileIdentity: assert commandcode_profile.get_hostname() == "api.commandcode.ai" -class TestCommandCodeProfileNoThinkingInterference: - """Reasoning wire controls for the chat-completions profile. +class TestCommandCodeReasoningWireControls: + """DeepSeek V4+ defaults to thinking when ``thinking`` is omitted, so the profile + must put the user's setting on the wire (#95232); other families stay a no-op.""" - DeepSeek-family ids get the native DeepSeek controls (DeepSeek V4+ - defaults to thinking when the field is omitted, so an explicit wire - control is required for ``/reasoning none`` to reach the request, - #95232); every other CommandCode model family keeps the base no-op. - """ - - def test_deepseek_disabled_reasoning_sends_thinking_disabled( - self, commandcode_profile - ): + def test_deepseek_disabled_reasoning_sends_thinking_disabled(self, commandcode_profile): extra_body, top_level = commandcode_profile.build_api_kwargs_extras( - reasoning_config={"enabled": False}, - model="deepseek/deepseek-v4-flash", + reasoning_config={"enabled": False}, model="deepseek/deepseek-v4-flash", ) assert extra_body.get("thinking") == {"type": "disabled"} assert top_level == {} - def test_deepseek_enabled_reasoning_maps_effort(self, commandcode_profile): - extra_body, top_level = commandcode_profile.build_api_kwargs_extras( - reasoning_config={"enabled": True, "effort": "high"}, - model="deepseek/deepseek-v4-pro", - ) - assert extra_body.get("thinking") == {"type": "enabled"} - assert top_level.get("reasoning_effort") == "high" + def test_deepseek_effort_matches_native_profile_and_others_noop(self, commandcode_profile): + from plugins.model_providers.deepseek import deepseek - def test_deepseek_no_config_defaults_to_enabled(self, commandcode_profile): - # Matches DeepSeek's API default, applied explicitly so the field is - # never omitted for thinking-capable models. - extra_body, _ = commandcode_profile.build_api_kwargs_extras( - reasoning_config=None, model="deepseek/deepseek-v4-flash" - ) - assert extra_body.get("thinking") == {"type": "enabled"} + rc = {"enabled": True, "effort": "low"} + assert commandcode_profile.build_api_kwargs_extras( + reasoning_config=rc, model="deepseek/deepseek-v4.1-flash" + ) == deepseek.build_api_kwargs_extras(reasoning_config=rc, model="deepseek-v4.1-flash") + assert commandcode_profile.build_api_kwargs_extras( + reasoning_config=rc, model="Qwen/Qwen3.7-Max" + ) == ({}, {}) - def test_deepseek_v3_stays_noop(self, commandcode_profile): - extra_body, top_level = commandcode_profile.build_api_kwargs_extras( - reasoning_config={"enabled": False}, - model="deepseek/deepseek-v3", - ) - assert extra_body == {} - assert top_level == {} - - def test_passthrough_non_deepseek_family(self, commandcode_profile): - extra_body, top_level = commandcode_profile.build_api_kwargs_extras( - reasoning_config={"enabled": True, "effort": "high"}, - model="Qwen/Qwen3.7-Max", - ) - assert extra_body == {} - assert top_level == {} - - def test_passthrough_no_reasoning_config_non_deepseek( - self, commandcode_profile - ): - extra_body, top_level = commandcode_profile.build_api_kwargs_extras( - reasoning_config=None, model="gpt-5.5" - ) - assert extra_body == {} - assert top_level == {} - - def test_missing_deepseek_plugin_degrades_to_noop( - self, commandcode_profile, monkeypatch, caplog - ): - # The bundled-plugin loader pops half-registered modules when a - # plugin fails to load, so the deepseek shim can be absent at - # runtime; the delegation must degrade to the pre-fix no-op - # instead of crashing every DeepSeek-routed CommandCode turn. - import sys - - monkeypatch.setitem(sys.modules, "plugins.model_providers.deepseek", None) - extra_body, top_level = commandcode_profile.build_api_kwargs_extras( - reasoning_config={"enabled": False}, - model="deepseek/deepseek-v4-flash", - ) - assert extra_body == {} - assert top_level == {} - - -# ── Anthropic Messages profile ──────────────────────────────────────────────── class TestCommandCodeAnthropicProfileIdentity: """Anthropic-compatible profile metadata."""