test: consolidate repetitive cases across the suite
This commit is contained in:
1 parent
c406024b59
commit
6eccc2859a
31 files changed
+745
-1315
No files matched your search
@@ -99,8 +99,16 @@ def test_opus_4_8_omits_temperature_adaptive() -> None:
|
||||
assert "temperature" not in kw
|
||||
|
||||
|
||||
def test_opus_4_8_high_uses_adaptive_effort() -> None:
|
||||
kw = _build(_make_provider("claude-opus-4-8"), "high", max_tokens=4096)
|
||||
@pytest.mark.parametrize(
|
||||
"model",
|
||||
[
|
||||
pytest.param("claude-opus-4-8", id="opus_4_8_high_uses_adaptive_effort"),
|
||||
pytest.param("claude-fable-5", id="fable_high_uses_adaptive_effort"),
|
||||
pytest.param("claude-sonnet-5", id="sonnet_5_high_uses_adaptive_effort"),
|
||||
],
|
||||
)
|
||||
def test_adaptive_models_use_high_effort(model) -> None:
|
||||
kw = _build(_make_provider(model), "high", max_tokens=4096)
|
||||
assert "temperature" not in kw
|
||||
assert kw["thinking"] == {"type": "adaptive"}
|
||||
assert kw["output_config"] == {"effort": "high"}
|
||||
@@ -116,13 +124,6 @@ def test_fable_omits_temperature_adaptive() -> None:
|
||||
assert "temperature" not in kw
|
||||
|
||||
|
||||
def test_fable_high_uses_adaptive_effort() -> None:
|
||||
kw = _build(_make_provider("claude-fable-5"), "high", max_tokens=4096)
|
||||
assert "temperature" not in kw
|
||||
assert kw["thinking"] == {"type": "adaptive"}
|
||||
assert kw["output_config"] == {"effort": "high"}
|
||||
|
||||
|
||||
def test_fable_omits_temperature_none() -> None:
|
||||
kw = _build(_make_provider("claude-fable-5"), None)
|
||||
assert "temperature" not in kw
|
||||
@@ -134,13 +135,6 @@ def test_sonnet_5_omits_temperature_adaptive() -> None:
|
||||
assert kw["thinking"] == {"type": "adaptive"}
|
||||
|
||||
|
||||
def test_sonnet_5_high_uses_adaptive_effort() -> None:
|
||||
kw = _build(_make_provider("claude-sonnet-5"), "high", max_tokens=4096)
|
||||
assert "temperature" not in kw
|
||||
assert kw["thinking"] == {"type": "adaptive"}
|
||||
assert kw["output_config"] == {"effort": "high"}
|
||||
|
||||
|
||||
def test_sonnet_5_omits_temperature_none() -> None:
|
||||
kw = _build(_make_provider("anthropic/claude-sonnet-5"), "none")
|
||||
assert "temperature" not in kw
|
||||
|
||||
@@ -469,35 +469,26 @@ async def test_gemini_flash_forwards_aspect_ratio_and_image_size() -> None:
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_gemini_flash_2_5_drops_image_size() -> None:
|
||||
@pytest.mark.parametrize(
|
||||
"aspect_ratio, model",
|
||||
[
|
||||
pytest.param("4:3", "gemini-2.5-flash-image", id="5_drops_image_size"),
|
||||
pytest.param("16:9", "gemini-2.0-flash-preview-image-generation", id="0_drops_image_size"),
|
||||
],
|
||||
)
|
||||
async def test_gemini_flash_omits_unsupported_image_size(aspect_ratio, model) -> None:
|
||||
fake = FakeClient(_gemini_flash_image_response())
|
||||
client = GeminiImageGenerationClient(api_key="AIza-test", client=fake) # type: ignore[arg-type]
|
||||
|
||||
await client.generate(
|
||||
prompt="draw a cat",
|
||||
model="gemini-2.5-flash-image",
|
||||
aspect_ratio="4:3",
|
||||
model=model,
|
||||
aspect_ratio=aspect_ratio,
|
||||
image_size="1K",
|
||||
)
|
||||
|
||||
image_config = fake.calls[0]["json"]["generationConfig"]["imageConfig"]
|
||||
assert image_config == {"aspectRatio": "4:3"}
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_gemini_flash_2_0_drops_image_size() -> None:
|
||||
fake = FakeClient(_gemini_flash_image_response())
|
||||
client = GeminiImageGenerationClient(api_key="AIza-test", client=fake) # type: ignore[arg-type]
|
||||
|
||||
await client.generate(
|
||||
prompt="draw a cat",
|
||||
model="gemini-2.0-flash-preview-image-generation",
|
||||
aspect_ratio="16:9",
|
||||
image_size="1K",
|
||||
)
|
||||
|
||||
image_config = fake.calls[0]["json"]["generationConfig"]["imageConfig"]
|
||||
assert image_config == {"aspectRatio": "16:9"}
|
||||
assert image_config == {"aspectRatio": aspect_ratio}
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -876,15 +867,27 @@ async def test_openai_multiple_images() -> None:
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_openai_aspect_ratio_to_size() -> None:
|
||||
@pytest.mark.parametrize(
|
||||
"expected_size, model, aspect_ratio",
|
||||
[
|
||||
pytest.param("1024x1024", "dall-e-3", "1:1", id="aspect_ratio_to_size"),
|
||||
pytest.param("1024x1024", "dall-e-2", "16:9", id="dalle2_uses_square_size_for_non_square_ratios"),
|
||||
pytest.param("1536x1024", "gpt-image-1", "16:9", id="gpt_image_uses_supported_landscape_size"),
|
||||
],
|
||||
)
|
||||
async def test_openai_aspect_ratio_uses_model_supported_size(
|
||||
expected_size,
|
||||
model,
|
||||
aspect_ratio,
|
||||
) -> None:
|
||||
fake = FakeClient(FakeResponse({"data": [{"b64_json": RAW_B64}]}))
|
||||
client = OpenAIImageGenerationClient(
|
||||
api_key="sk-openai-test",
|
||||
client=fake, # type: ignore[arg-type]
|
||||
)
|
||||
|
||||
await client.generate(prompt="draw", model="dall-e-3", aspect_ratio="1:1")
|
||||
assert fake.calls[0]["json"]["size"] == "1024x1024"
|
||||
await client.generate(prompt="draw", model=model, aspect_ratio=aspect_ratio)
|
||||
assert fake.calls[0]["json"]["size"] == expected_size
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -902,32 +905,6 @@ async def test_openai_dalle3_uses_supported_orientation_sizes() -> None:
|
||||
assert fake.calls[1]["json"]["size"] == "1792x1024"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_openai_dalle2_uses_square_size_for_non_square_ratios() -> None:
|
||||
fake = FakeClient(FakeResponse({"data": [{"b64_json": RAW_B64}]}))
|
||||
client = OpenAIImageGenerationClient(
|
||||
api_key="sk-openai-test",
|
||||
client=fake, # type: ignore[arg-type]
|
||||
)
|
||||
|
||||
await client.generate(prompt="draw", model="dall-e-2", aspect_ratio="16:9")
|
||||
|
||||
assert fake.calls[0]["json"]["size"] == "1024x1024"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_openai_gpt_image_uses_supported_landscape_size() -> None:
|
||||
fake = FakeClient(FakeResponse({"data": [{"b64_json": RAW_B64}]}))
|
||||
client = OpenAIImageGenerationClient(
|
||||
api_key="sk-openai-test",
|
||||
client=fake, # type: ignore[arg-type]
|
||||
)
|
||||
|
||||
await client.generate(prompt="draw", model="gpt-image-1", aspect_ratio="16:9")
|
||||
|
||||
assert fake.calls[0]["json"]["size"] == "1536x1024"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_openai_gpt_image_uses_supported_orientation_sizes() -> None:
|
||||
fake = FakeClient(FakeResponse({"data": [{"b64_json": RAW_B64}]}))
|
||||
@@ -1098,7 +1075,14 @@ async def test_openai_default_size_when_no_aspect_ratio() -> None:
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_openai_ignores_explicit_size_unsupported_by_model_family() -> None:
|
||||
@pytest.mark.parametrize(
|
||||
"expected_size, image_size",
|
||||
[
|
||||
pytest.param("1792x1024", "1536x1024", id="ignores_explicit_size_unsupported_by_model_family"),
|
||||
pytest.param("1024x1024", "1024x1024", id="uses_explicit_image_size"),
|
||||
],
|
||||
)
|
||||
async def test_openai_validates_explicit_size_for_model_family(expected_size, image_size) -> None:
|
||||
fake = FakeClient(FakeResponse({"data": [{"b64_json": RAW_B64}]}))
|
||||
client = OpenAIImageGenerationClient(
|
||||
api_key="sk-openai-test",
|
||||
@@ -1109,30 +1093,11 @@ async def test_openai_ignores_explicit_size_unsupported_by_model_family() -> Non
|
||||
prompt="draw",
|
||||
model="dall-e-3",
|
||||
aspect_ratio="16:9",
|
||||
image_size="1536x1024",
|
||||
image_size=image_size,
|
||||
)
|
||||
|
||||
body = fake.calls[0]["json"]
|
||||
assert body["size"] == "1792x1024"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_openai_uses_explicit_image_size() -> None:
|
||||
fake = FakeClient(FakeResponse({"data": [{"b64_json": RAW_B64}]}))
|
||||
client = OpenAIImageGenerationClient(
|
||||
api_key="sk-openai-test",
|
||||
client=fake, # type: ignore[arg-type]
|
||||
)
|
||||
|
||||
await client.generate(
|
||||
prompt="draw",
|
||||
model="dall-e-3",
|
||||
aspect_ratio="16:9",
|
||||
image_size="1024x1024",
|
||||
)
|
||||
|
||||
body = fake.calls[0]["json"]
|
||||
assert body["size"] == "1024x1024"
|
||||
assert body["size"] == expected_size
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -1180,7 +1145,14 @@ async def test_custom_generate_success() -> None:
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_custom_generate_preserves_provider_size_hint() -> None:
|
||||
@pytest.mark.parametrize(
|
||||
"expected_size, image_size",
|
||||
[
|
||||
pytest.param("2K", "2K", id="preserves_provider_size_hint"),
|
||||
pytest.param("1024x1024", "1K", id="maps_one_k_to_openai_dimension"),
|
||||
],
|
||||
)
|
||||
async def test_custom_generate_maps_size_hint(expected_size, image_size) -> None:
|
||||
fake = FakeClient(FakeResponse({"data": [{"b64_json": RAW_B64}]}))
|
||||
client = CustomImageGenerationClient(
|
||||
api_key="sk-custom-test",
|
||||
@@ -1191,28 +1163,10 @@ async def test_custom_generate_preserves_provider_size_hint() -> None:
|
||||
await client.generate(
|
||||
prompt="a cat on the moon",
|
||||
model="custom-image-model",
|
||||
image_size="2K",
|
||||
image_size=image_size,
|
||||
)
|
||||
|
||||
assert fake.calls[0]["json"]["size"] == "2K"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_custom_generate_maps_one_k_to_openai_dimension() -> None:
|
||||
fake = FakeClient(FakeResponse({"data": [{"b64_json": RAW_B64}]}))
|
||||
client = CustomImageGenerationClient(
|
||||
api_key="sk-custom-test",
|
||||
api_base="https://custom.example/v1",
|
||||
client=fake, # type: ignore[arg-type]
|
||||
)
|
||||
|
||||
await client.generate(
|
||||
prompt="a cat on the moon",
|
||||
model="custom-image-model",
|
||||
image_size="1K",
|
||||
)
|
||||
|
||||
assert fake.calls[0]["json"]["size"] == "1024x1024"
|
||||
assert fake.calls[0]["json"]["size"] == expected_size
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
||||
@@ -1426,8 +1426,32 @@ def test_non_dashscope_minimal_not_retranslated() -> None:
|
||||
assert kw["reasoning_effort"] == "minimal"
|
||||
|
||||
|
||||
def test_dashscope_no_extra_body_when_reasoning_effort_none() -> None:
|
||||
kw = _build_kwargs_for("dashscope", "qwen-turbo", reasoning_effort=None)
|
||||
@pytest.mark.parametrize(
|
||||
"provider_name, model",
|
||||
[
|
||||
pytest.param("dashscope", "qwen-turbo", id="dashscope_no_extra_body_when_reasoning_effort_none"),
|
||||
pytest.param("minimax", "MiniMax-M2.7", id="minimax_no_extra_body_when_reasoning_effort_none"),
|
||||
pytest.param(
|
||||
"byteplus",
|
||||
"doubao-seed-2-0-pro",
|
||||
id="byteplus_no_extra_body_when_reasoning_effort_none",
|
||||
),
|
||||
pytest.param("deepseek", "deepseek-chat", id="deepseek_no_extra_body_when_reasoning_effort_none"),
|
||||
pytest.param("moonshot", "kimi-k2.5", id="kimi_k25_no_extra_body_when_reasoning_effort_none"),
|
||||
pytest.param(
|
||||
"openrouter",
|
||||
"moonshotai/kimi-k2.5",
|
||||
id="kimi_k25_thinking_disabled_with_openrouter_prefix",
|
||||
),
|
||||
pytest.param(
|
||||
"openrouter",
|
||||
"qwen/qwen3.6-flash",
|
||||
id="qwen_no_extra_body_when_reasoning_effort_omitted",
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_provider_omits_extra_body_without_reasoning_effort(provider_name, model) -> None:
|
||||
kw = _build_kwargs_for(provider_name, model, reasoning_effort=None)
|
||||
assert "extra_body" not in kw
|
||||
|
||||
|
||||
@@ -1441,11 +1465,6 @@ def test_minimax_reasoning_split_disabled_for_minimal() -> None:
|
||||
assert kw["extra_body"] == {"reasoning_split": False}
|
||||
|
||||
|
||||
def test_minimax_no_extra_body_when_reasoning_effort_none() -> None:
|
||||
kw = _build_kwargs_for("minimax", "MiniMax-M2.7", reasoning_effort=None)
|
||||
assert "extra_body" not in kw
|
||||
|
||||
|
||||
def test_volcengine_thinking_enabled() -> None:
|
||||
kw = _build_kwargs_for("volcengine", "doubao-seed-2-0-pro", reasoning_effort="high")
|
||||
assert kw["extra_body"] == {"thinking": {"type": "enabled"}}
|
||||
@@ -1468,11 +1487,6 @@ def test_byteplus_thinking_disabled_for_minimal() -> None:
|
||||
assert kw["extra_body"] == {"thinking": {"type": "disabled"}}
|
||||
|
||||
|
||||
def test_byteplus_no_extra_body_when_reasoning_effort_none() -> None:
|
||||
kw = _build_kwargs_for("byteplus", "doubao-seed-2-0-pro", reasoning_effort=None)
|
||||
assert "extra_body" not in kw
|
||||
|
||||
|
||||
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")
|
||||
@@ -1485,12 +1499,6 @@ def test_deepseek_thinking_disabled_for_minimal() -> None:
|
||||
assert kw["extra_body"] == {"thinking": {"type": "disabled"}}
|
||||
|
||||
|
||||
def test_deepseek_no_extra_body_when_reasoning_effort_none() -> None:
|
||||
"""Without reasoning_effort the thinking param must not be injected."""
|
||||
kw = _build_kwargs_for("deepseek", "deepseek-chat", reasoning_effort=None)
|
||||
assert "extra_body" not in kw
|
||||
|
||||
|
||||
def test_deepseek_backfills_reasoning_content_on_legacy_tool_call_messages() -> None:
|
||||
"""Session messages from before thinking mode was enabled may have assistant
|
||||
messages with tool_calls but no reasoning_content. DeepSeek V4 rejects these
|
||||
@@ -1753,27 +1761,49 @@ def test_openai_no_thinking_extra_body() -> None:
|
||||
assert "extra_body" not in kw
|
||||
|
||||
|
||||
def test_kimi_k25_thinking_enabled() -> None:
|
||||
"""kimi-k2.5 with reasoning_effort set should opt in to thinking."""
|
||||
kw = _build_kwargs_for("moonshot", "kimi-k2.5", reasoning_effort="medium")
|
||||
assert kw.get("extra_body") == {"thinking": {"type": "enabled"}}
|
||||
@pytest.mark.parametrize(
|
||||
"provider_name, model, effort, thinking_type",
|
||||
[
|
||||
pytest.param("moonshot", "kimi-k2.5", "medium", "enabled", id="kimi_k25_thinking_enabled"),
|
||||
pytest.param(
|
||||
"moonshot",
|
||||
"kimi-k2.5",
|
||||
"minimal",
|
||||
"disabled",
|
||||
id="kimi_k25_thinking_disabled_for_minimal",
|
||||
),
|
||||
pytest.param("moonshot", "kimi-k2.6", "medium", "enabled", id="kimi_k26_thinking_enabled"),
|
||||
pytest.param("moonshot", "kimi-k2.7-code", "medium", "enabled", id="kimi_k27_code_thinking_enabled"),
|
||||
pytest.param(
|
||||
"moonshot",
|
||||
"k2.6-code-preview",
|
||||
"high",
|
||||
"enabled",
|
||||
id="kimi_k26_code_preview_thinking_enabled",
|
||||
),
|
||||
pytest.param(
|
||||
"deepseek",
|
||||
"deepseek-v4-pro",
|
||||
"none",
|
||||
"disabled",
|
||||
id="deepseek_thinking_disabled_for_none_string",
|
||||
),
|
||||
pytest.param(
|
||||
"moonshot",
|
||||
"kimi-k2.5",
|
||||
"none",
|
||||
"disabled",
|
||||
id="kimi_k25_thinking_disabled_for_none_string",
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_provider_thinking_type_mapping(provider_name, model, effort, thinking_type) -> None:
|
||||
kw = _build_kwargs_for(provider_name, model, reasoning_effort=effort)
|
||||
assert kw.get("extra_body") == {"thinking": {"type": thinking_type}}
|
||||
# Moonshot rejects both 'reasoning_effort' and 'thinking' (#3939)
|
||||
assert "reasoning_effort" not in kw
|
||||
|
||||
|
||||
def test_kimi_k25_thinking_disabled_for_minimal() -> None:
|
||||
"""reasoning_effort='minimal' maps to thinking disabled for kimi-k2.5."""
|
||||
kw = _build_kwargs_for("moonshot", "kimi-k2.5", reasoning_effort="minimal")
|
||||
assert kw.get("extra_body") == {"thinking": {"type": "disabled"}}
|
||||
assert "reasoning_effort" not in kw
|
||||
|
||||
|
||||
def test_kimi_k25_no_extra_body_when_reasoning_effort_none() -> None:
|
||||
"""Without reasoning_effort the thinking param must not be injected."""
|
||||
kw = _build_kwargs_for("moonshot", "kimi-k2.5", reasoning_effort=None)
|
||||
assert "extra_body" not in kw
|
||||
|
||||
|
||||
def test_kimi_k3_uses_native_defaults() -> None:
|
||||
"""K3 omits fixed sampling params and uses the non-deprecated token limit field."""
|
||||
kw = _build_kwargs_for("moonshot", "kimi-k3", reasoning_effort=None)
|
||||
@@ -1811,56 +1841,28 @@ def test_kimi_k3_omits_disabled_reasoning_effort() -> None:
|
||||
assert "extra_body" not in kw
|
||||
|
||||
|
||||
def test_kimi_k25_thinking_enabled_with_openrouter_prefix() -> None:
|
||||
"""OpenRouter-style model names like moonshotai/kimi-k2.5 must trigger thinking.
|
||||
|
||||
OR drops upstream-provider `thinking` fields, so the same intent also has
|
||||
to go through OR's `reasoning.effort` shape (#3851 follow-up).
|
||||
"""
|
||||
kw = _build_kwargs_for("openrouter", "moonshotai/kimi-k2.5", reasoning_effort="medium")
|
||||
@pytest.mark.parametrize(
|
||||
"model, effort",
|
||||
[
|
||||
pytest.param("moonshotai/kimi-k2.5", "medium", id="k25_thinking_enabled_with_openrouter_prefix"),
|
||||
pytest.param("moonshotai/kimi-k2.6", "medium", id="k26_thinking_enabled_with_openrouter_prefix"),
|
||||
pytest.param(
|
||||
"moonshotai/kimi-k2.7-code",
|
||||
"high",
|
||||
id="k27_code_thinking_enabled_with_openrouter_prefix",
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_openrouter_kimi_thinking_mapping(model, effort) -> None:
|
||||
kw = _build_kwargs_for("openrouter", model, reasoning_effort=effort)
|
||||
assert kw.get("extra_body") == {
|
||||
"thinking": {"type": "enabled"},
|
||||
"reasoning": {"effort": "medium"},
|
||||
"reasoning": {"effort": effort},
|
||||
}
|
||||
# Even via OR, reasoning_effort wire kwarg is dropped for kimi models
|
||||
assert "reasoning_effort" not in kw
|
||||
|
||||
|
||||
def test_kimi_k26_thinking_enabled() -> None:
|
||||
"""kimi-k2.6 with reasoning_effort set should opt in to thinking."""
|
||||
kw = _build_kwargs_for("moonshot", "kimi-k2.6", reasoning_effort="medium")
|
||||
assert kw.get("extra_body") == {"thinking": {"type": "enabled"}}
|
||||
assert "reasoning_effort" not in kw
|
||||
|
||||
|
||||
def test_kimi_k26_thinking_enabled_with_openrouter_prefix() -> None:
|
||||
"""OpenRouter-style names like moonshotai/kimi-k2.6 must trigger thinking
|
||||
via both upstream `thinking` and OR's `reasoning.effort`."""
|
||||
kw = _build_kwargs_for("openrouter", "moonshotai/kimi-k2.6", reasoning_effort="medium")
|
||||
assert kw.get("extra_body") == {
|
||||
"thinking": {"type": "enabled"},
|
||||
"reasoning": {"effort": "medium"},
|
||||
}
|
||||
assert "reasoning_effort" not in kw
|
||||
|
||||
|
||||
def test_kimi_k27_code_thinking_enabled() -> None:
|
||||
"""Kimi K2.7 Code supports native thinking controls."""
|
||||
kw = _build_kwargs_for("moonshot", "kimi-k2.7-code", reasoning_effort="medium")
|
||||
assert kw.get("extra_body") == {"thinking": {"type": "enabled"}}
|
||||
assert "reasoning_effort" not in kw
|
||||
|
||||
|
||||
def test_kimi_k27_code_thinking_enabled_with_openrouter_prefix() -> None:
|
||||
"""OpenRouter-routed Kimi K2.7 Code should carry both thinking shapes."""
|
||||
kw = _build_kwargs_for("openrouter", "moonshotai/kimi-k2.7-code", reasoning_effort="high")
|
||||
assert kw.get("extra_body") == {
|
||||
"thinking": {"type": "enabled"},
|
||||
"reasoning": {"effort": "high"},
|
||||
}
|
||||
assert "reasoning_effort" not in kw
|
||||
|
||||
|
||||
def test_kimi_k27_code_thinking_none_omits_disabled() -> None:
|
||||
"""Kimi K2.7 Code is always-thinking; disabled thinking is invalid upstream."""
|
||||
kw = _build_kwargs_for("moonshot", "kimi-k2.7-code", reasoning_effort="none")
|
||||
@@ -1891,19 +1893,6 @@ def test_moonshot_kimi_k27_code_temperature_override() -> None:
|
||||
assert kw["temperature"] == 1.0
|
||||
|
||||
|
||||
def test_kimi_k25_thinking_disabled_with_openrouter_prefix() -> None:
|
||||
"""OpenRouter names must NOT trigger thinking without reasoning_effort."""
|
||||
kw = _build_kwargs_for("openrouter", "moonshotai/kimi-k2.5", reasoning_effort=None)
|
||||
assert "extra_body" not in kw
|
||||
|
||||
|
||||
def test_kimi_k26_code_preview_thinking_enabled() -> None:
|
||||
"""k2.6-code-preview also supports thinking; should behave like k2.5."""
|
||||
kw = _build_kwargs_for("moonshot", "k2.6-code-preview", reasoning_effort="high")
|
||||
assert kw.get("extra_body") == {"thinking": {"type": "enabled"}}
|
||||
assert "reasoning_effort" not in kw
|
||||
|
||||
|
||||
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")
|
||||
@@ -1920,20 +1909,6 @@ def test_kimi_k2_thinking_series_no_thinking_injection() -> None:
|
||||
# reasoning_effort="none" — treated as thinking disabled
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
def test_deepseek_thinking_disabled_for_none_string() -> None:
|
||||
"""reasoning_effort='none' must send thinking.type=disabled and skip reasoning_effort field."""
|
||||
kw = _build_kwargs_for("deepseek", "deepseek-v4-pro", reasoning_effort="none")
|
||||
assert kw.get("extra_body") == {"thinking": {"type": "disabled"}}
|
||||
assert "reasoning_effort" not in kw
|
||||
|
||||
|
||||
def test_kimi_k25_thinking_disabled_for_none_string() -> None:
|
||||
"""reasoning_effort='none' maps to thinking disabled for kimi-k2.5."""
|
||||
kw = _build_kwargs_for("moonshot", "kimi-k2.5", reasoning_effort="none")
|
||||
assert kw.get("extra_body") == {"thinking": {"type": "disabled"}}
|
||||
assert "reasoning_effort" not in kw
|
||||
|
||||
|
||||
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")
|
||||
@@ -1956,13 +1931,6 @@ def test_qwen_thinking_disabled_via_model_level_mapping() -> None:
|
||||
assert kw["extra_body"] == {"enable_thinking": False, "reasoning": {"effort": "none"}}
|
||||
|
||||
|
||||
def test_qwen_no_extra_body_when_reasoning_effort_omitted() -> None:
|
||||
"""Without reasoning_effort the model-level mapping must not inject extra_body
|
||||
on its own — the provider default applies."""
|
||||
kw = _build_kwargs_for("openrouter", "qwen/qwen3.6-flash", reasoning_effort=None)
|
||||
assert "extra_body" not in kw
|
||||
|
||||
|
||||
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")
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
import pytest
|
||||
|
||||
from nanobot.providers.openai_compat_provider import (
|
||||
OpenAICompatProvider,
|
||||
_is_local_endpoint,
|
||||
@@ -26,62 +28,43 @@ class TestIsLocalEndpoint:
|
||||
def test_no_spec_no_base(self):
|
||||
assert _is_local_endpoint(None, None) is False
|
||||
|
||||
def test_localhost(self):
|
||||
assert _is_local_endpoint(None, "http://localhost:1234/v1") is True
|
||||
|
||||
def test_localhost_https(self):
|
||||
assert _is_local_endpoint(None, "https://localhost:8080/v1") is True
|
||||
|
||||
def test_loopback_127(self):
|
||||
assert _is_local_endpoint(None, "http://127.0.0.1:11434/v1") is True
|
||||
|
||||
def test_private_192_168(self):
|
||||
assert _is_local_endpoint(None, "http://192.168.8.188:1234/v1") is True
|
||||
|
||||
def test_private_10(self):
|
||||
assert _is_local_endpoint(None, "http://10.0.0.5:8000/v1") is True
|
||||
|
||||
def test_private_172_16(self):
|
||||
assert _is_local_endpoint(None, "http://172.16.0.1:1234/v1") is True
|
||||
|
||||
def test_private_172_31(self):
|
||||
assert _is_local_endpoint(None, "http://172.31.255.255:1234/v1") is True
|
||||
|
||||
def test_not_private_172_32(self):
|
||||
assert _is_local_endpoint(None, "http://172.32.0.1:1234/v1") is False
|
||||
|
||||
def test_docker_internal(self):
|
||||
assert _is_local_endpoint(None, "http://host.docker.internal:11434/v1") is True
|
||||
|
||||
def test_ipv6_loopback(self):
|
||||
assert _is_local_endpoint(None, "http://[::1]:1234/v1") is True
|
||||
|
||||
def test_public_api(self):
|
||||
assert _is_local_endpoint(None, "https://api.openai.com/v1") is False
|
||||
|
||||
def test_openrouter(self):
|
||||
assert _is_local_endpoint(None, "https://openrouter.ai/api/v1") is False
|
||||
@pytest.mark.parametrize(
|
||||
"expected, api_base",
|
||||
[
|
||||
pytest.param(True, "http://localhost:1234/v1", id="localhost"),
|
||||
pytest.param(True, "https://localhost:8080/v1", id="localhost_https"),
|
||||
pytest.param(True, "http://127.0.0.1:11434/v1", id="loopback_127"),
|
||||
pytest.param(True, "http://192.168.8.188:1234/v1", id="private_192_168"),
|
||||
pytest.param(True, "http://10.0.0.5:8000/v1", id="private_10"),
|
||||
pytest.param(True, "http://172.16.0.1:1234/v1", id="private_172_16"),
|
||||
pytest.param(True, "http://172.31.255.255:1234/v1", id="private_172_31"),
|
||||
pytest.param(False, "http://172.32.0.1:1234/v1", id="not_private_172_32"),
|
||||
pytest.param(True, "http://host.docker.internal:11434/v1", id="docker_internal"),
|
||||
pytest.param(True, "http://[::1]:1234/v1", id="ipv6_loopback"),
|
||||
pytest.param(False, "https://api.openai.com/v1", id="public_api"),
|
||||
pytest.param(False, "https://openrouter.ai/api/v1", id="openrouter"),
|
||||
pytest.param(True, "http://LOCALHOST:1234/v1", id="case_insensitive"),
|
||||
pytest.param(True, "http://192.168.1.1:8080/v1/", id="trailing_slash"),
|
||||
pytest.param(
|
||||
False,
|
||||
"https://notlocalhost.example/v1",
|
||||
id="public_hostname_containing_localhost_is_not_local",
|
||||
),
|
||||
pytest.param(
|
||||
False,
|
||||
"https://api10.example.com/v1",
|
||||
id="public_hostname_containing_private_ip_prefix_is_not_local",
|
||||
),
|
||||
pytest.param(True, "192.168.1.1:8080/v1", id="url_without_scheme"),
|
||||
],
|
||||
)
|
||||
def test_endpoint_locality(self, expected, api_base):
|
||||
assert _is_local_endpoint(None, api_base) is expected
|
||||
|
||||
def test_spec_overrides_public_url(self):
|
||||
"""spec.is_local=True takes precedence even with a public-looking URL."""
|
||||
assert _is_local_endpoint(_make_spec(is_local=True), "https://api.example.com/v1") is True
|
||||
|
||||
def test_case_insensitive(self):
|
||||
assert _is_local_endpoint(None, "http://LOCALHOST:1234/v1") is True
|
||||
|
||||
def test_trailing_slash(self):
|
||||
assert _is_local_endpoint(None, "http://192.168.1.1:8080/v1/") is True
|
||||
|
||||
def test_public_hostname_containing_localhost_is_not_local(self):
|
||||
assert _is_local_endpoint(None, "https://notlocalhost.example/v1") is False
|
||||
|
||||
def test_public_hostname_containing_private_ip_prefix_is_not_local(self):
|
||||
assert _is_local_endpoint(None, "https://api10.example.com/v1") is False
|
||||
|
||||
def test_url_without_scheme(self):
|
||||
assert _is_local_endpoint(None, "192.168.1.1:8080/v1") is True
|
||||
|
||||
|
||||
class TestLocalKeepaliveConfig:
|
||||
"""Verify that local endpoints get keepalive_expiry=0."""
|
||||
|
||||
|
||||
@@ -4,6 +4,8 @@ from __future__ import annotations
|
||||
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
|
||||
from nanobot.config.schema import ProvidersConfig
|
||||
from nanobot.providers.openai_compat_provider import OpenAICompatProvider
|
||||
from nanobot.providers.registry import PROVIDERS, find_by_name
|
||||
@@ -54,37 +56,35 @@ def test_mistral_keyword_match_covers_model_families() -> None:
|
||||
assert config.get_provider_name(model) == "mistral", model
|
||||
|
||||
|
||||
def test_reasoning_effort_low_remaps_to_none_omitted() -> None:
|
||||
"""Mistral rejects low/medium efforts: low should map to "none" (omitted)."""
|
||||
@pytest.mark.parametrize(
|
||||
"model, effort",
|
||||
[
|
||||
pytest.param("mistral-medium-3-5", "low", id="low_remaps_to_none_omitted"),
|
||||
pytest.param("mistral-vibe-cli-latest", "minimal", id="minimal_remaps_to_none_omitted"),
|
||||
],
|
||||
)
|
||||
def test_mistral_omits_low_reasoning_effort(model, effort) -> None:
|
||||
p = _mistral_provider()
|
||||
kwargs = p._build_kwargs(
|
||||
messages=[{"role": "user", "content": "hi"}],
|
||||
tools=None,
|
||||
model="mistral-medium-3-5",
|
||||
model=model,
|
||||
max_tokens=64,
|
||||
temperature=0.5,
|
||||
reasoning_effort="low",
|
||||
reasoning_effort=effort,
|
||||
tool_choice=None,
|
||||
)
|
||||
assert "reasoning_effort" not in kwargs
|
||||
|
||||
|
||||
def test_reasoning_effort_minimal_remaps_to_none_omitted() -> None:
|
||||
p = _mistral_provider()
|
||||
kwargs = p._build_kwargs(
|
||||
messages=[{"role": "user", "content": "hi"}],
|
||||
tools=None,
|
||||
model="mistral-vibe-cli-latest",
|
||||
max_tokens=64,
|
||||
temperature=0.5,
|
||||
reasoning_effort="minimal",
|
||||
tool_choice=None,
|
||||
)
|
||||
assert "reasoning_effort" not in kwargs
|
||||
|
||||
|
||||
def test_reasoning_effort_medium_remaps_to_high() -> None:
|
||||
"""Mistral has no 'medium' tier: bump up to 'high'."""
|
||||
@pytest.mark.parametrize(
|
||||
"effort",
|
||||
[
|
||||
pytest.param("medium", id="medium_remaps_to_high"),
|
||||
pytest.param("high", id="high_passes_through"),
|
||||
],
|
||||
)
|
||||
def test_mistral_uses_high_reasoning_effort(effort) -> None:
|
||||
p = _mistral_provider()
|
||||
kwargs = p._build_kwargs(
|
||||
messages=[{"role": "user", "content": "hi"}],
|
||||
@@ -92,21 +92,7 @@ def test_reasoning_effort_medium_remaps_to_high() -> None:
|
||||
model="mistral-medium-3-5",
|
||||
max_tokens=64,
|
||||
temperature=0.5,
|
||||
reasoning_effort="medium",
|
||||
tool_choice=None,
|
||||
)
|
||||
assert kwargs["reasoning_effort"] == "high"
|
||||
|
||||
|
||||
def test_reasoning_effort_high_passes_through() -> None:
|
||||
p = _mistral_provider()
|
||||
kwargs = p._build_kwargs(
|
||||
messages=[{"role": "user", "content": "hi"}],
|
||||
tools=None,
|
||||
model="mistral-medium-3-5",
|
||||
max_tokens=64,
|
||||
temperature=0.5,
|
||||
reasoning_effort="high",
|
||||
reasoning_effort=effort,
|
||||
tool_choice=None,
|
||||
)
|
||||
assert kwargs["reasoning_effort"] == "high"
|
||||
|
||||
@@ -20,6 +20,8 @@ from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
import pytest
|
||||
|
||||
from nanobot.config.schema import ProvidersConfig
|
||||
from nanobot.providers.openai_compat_provider import OpenAICompatProvider
|
||||
from nanobot.providers.registry import PROVIDERS
|
||||
@@ -183,10 +185,15 @@ def test_mimo_via_openrouter_reasoning_effort_medium_enables_thinking():
|
||||
}
|
||||
|
||||
|
||||
def test_mimo_via_openrouter_bare_slug_also_matches():
|
||||
"""Bare "mimo-v2.5-pro" (no publisher prefix) must also match the
|
||||
allowlist, since gateways sometimes accept either form."""
|
||||
provider = _openrouter_provider("mimo-v2.5-pro")
|
||||
@pytest.mark.parametrize(
|
||||
"model",
|
||||
[
|
||||
pytest.param("mimo-v2.5-pro", id="mimo_via_openrouter_bare_slug_also_matches"),
|
||||
pytest.param("moonshotai/kimi-k2.5", id="kimi_via_openrouter_also_injects_reasoning_effort"),
|
||||
],
|
||||
)
|
||||
def test_openrouter_thinking_allowlist_accepts_model_slugs(model):
|
||||
provider = _openrouter_provider(model)
|
||||
kwargs = provider._build_kwargs(
|
||||
messages=_simple_messages(),
|
||||
tools=None, model=None, max_tokens=100,
|
||||
@@ -198,40 +205,18 @@ def test_mimo_via_openrouter_bare_slug_also_matches():
|
||||
}
|
||||
|
||||
|
||||
def test_mimo_flash_via_openrouter_does_not_inject_thinking():
|
||||
"""mimo-v2-flash has no thinking mode per Xiaomi docs; the allowlist
|
||||
excludes it, so neither the upstream `thinking` field nor OR's
|
||||
`reasoning.effort` should be injected on the gateway path."""
|
||||
provider = _openrouter_provider("xiaomi/mimo-v2-flash")
|
||||
@pytest.mark.parametrize(
|
||||
"model",
|
||||
[
|
||||
pytest.param("xiaomi/mimo-v2-flash", id="mimo_flash_via_openrouter_does_not_inject_thinking"),
|
||||
pytest.param("openai/gpt-4o", id="non_mimo_model_via_openrouter_unaffected"),
|
||||
],
|
||||
)
|
||||
def test_openrouter_non_thinking_models_omit_extra_body(model):
|
||||
provider = _openrouter_provider(model)
|
||||
kwargs = provider._build_kwargs(
|
||||
messages=_simple_messages(),
|
||||
tools=None, model=None, max_tokens=100,
|
||||
temperature=0.7, reasoning_effort="none", tool_choice=None,
|
||||
)
|
||||
assert "extra_body" not in kwargs
|
||||
|
||||
|
||||
def test_non_mimo_model_via_openrouter_unaffected():
|
||||
"""Sanity: a non-MiMo, non-Kimi model through OpenRouter is untouched."""
|
||||
provider = _openrouter_provider("openai/gpt-4o")
|
||||
kwargs = provider._build_kwargs(
|
||||
messages=_simple_messages(),
|
||||
tools=None, model=None, max_tokens=100,
|
||||
temperature=0.7, reasoning_effort="none", tool_choice=None,
|
||||
)
|
||||
assert "extra_body" not in kwargs
|
||||
|
||||
|
||||
def test_kimi_via_openrouter_also_injects_reasoning_effort():
|
||||
"""Kimi has the same gateway problem as MiMo: OR drops the upstream
|
||||
`thinking` field. The same OR-reasoning injection should fire."""
|
||||
provider = _openrouter_provider("moonshotai/kimi-k2.5")
|
||||
kwargs = provider._build_kwargs(
|
||||
messages=_simple_messages(),
|
||||
tools=None, model=None, max_tokens=100,
|
||||
temperature=0.7, reasoning_effort="none", tool_choice=None,
|
||||
)
|
||||
assert kwargs["extra_body"] == {
|
||||
"thinking": {"type": "disabled"},
|
||||
"reasoning": {"effort": "none"},
|
||||
}
|
||||
Reference in new issue
Block a user