mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-11-17 04:11:35 +00:00
Change-detectors, tautologies, source-reading tests, redundant duplicates, mock-echo tests and dead/unrunnable tests. Per-test rationale in the lane ledger (category + reason for every removal).
106 lines
3.9 KiB
Python
106 lines
3.9 KiB
Python
"""Tests for transport auto-detection in agent.auxiliary_client.
|
|
|
|
Auxiliary clients must pick the correct wire protocol (OpenAI
|
|
chat.completions vs native Anthropic Messages) based on the endpoint,
|
|
regardless of which resolve_provider_client branch built them.
|
|
|
|
Regression target (April 2026): Kimi Coding Plan's ``api.kimi.com/coding``
|
|
endpoint only speaks Anthropic Messages — sending ``kimi-for-coding`` over
|
|
chat.completions returns 404 "resource_not_found_error". The named
|
|
``kimi-coding`` provider branch in resolve_provider_client used to build a
|
|
plain OpenAI client, so title generation / vision / compression /
|
|
web_extract all failed on Kimi Coding Plan users.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def _clean_env(monkeypatch):
|
|
for key in (
|
|
"OPENAI_API_KEY", "OPENAI_BASE_URL",
|
|
"ANTHROPIC_API_KEY", "ANTHROPIC_TOKEN",
|
|
"KIMI_API_KEY", "KIMI_CODING_API_KEY", "KIMI_BASE_URL",
|
|
):
|
|
monkeypatch.delenv(key, raising=False)
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# URL detection helper
|
|
# ---------------------------------------------------------------------------
|
|
|
|
@pytest.mark.parametrize("url,expected,label", [
|
|
("https://api.kimi.com/coding/v1", True, "Kimi Coding Plan /v1"),
|
|
("https://api.kimi.com/coding", True, "Kimi Coding Plan no /v1"),
|
|
("https://api.moonshot.ai/v1", False, "Moonshot legacy"),
|
|
("https://api.minimax.io/anthropic", True, "MiniMax /anthropic"),
|
|
("https://litellm.example.com/v1/anthropic", True, "/anthropic suffix"),
|
|
("https://litellm.example.com/anthropic/v1", True, "/anthropic/v1 base"),
|
|
("https://litellm.example.com/anthropic/v1/models", False, "/anthropic/v1 subpath"),
|
|
("https://api.anthropic.com", True, "native Anthropic"),
|
|
("https://api.anthropic.com/v1", True, "native Anthropic /v1"),
|
|
("https://openrouter.ai/api/v1", False, "OpenRouter"),
|
|
("https://api.openai.com/v1", False, "OpenAI"),
|
|
("https://inference-api.nousresearch.com/v1", False, "Nous"),
|
|
("", False, "empty"),
|
|
(None, False, "None"),
|
|
])
|
|
def test_endpoint_speaks_anthropic_messages(url, expected, label):
|
|
from agent.auxiliary_client import _endpoint_speaks_anthropic_messages
|
|
assert _endpoint_speaks_anthropic_messages(url) is expected, (
|
|
f"{label}: {url!r} should be {expected}"
|
|
)
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# _maybe_wrap_anthropic decision table
|
|
# ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Integration: resolve_provider_client for named kimi-coding provider
|
|
# ---------------------------------------------------------------------------
|
|
|
|
def test_resolve_provider_client_kimi_coding_wraps_anthropic(monkeypatch, tmp_path):
|
|
"""End-to-end: resolve_provider_client('kimi-coding', 'kimi-for-coding')
|
|
must return AnthropicAuxiliaryClient because /coding speaks Anthropic.
|
|
|
|
This is the primary regression guard: the bug that caused title
|
|
generation 404s on every Kimi Coding Plan user after the "main model
|
|
for every user" aux design shipped.
|
|
"""
|
|
from agent.auxiliary_client import (
|
|
resolve_provider_client,
|
|
AnthropicAuxiliaryClient,
|
|
)
|
|
|
|
monkeypatch.setenv("HERMES_HOME", str(tmp_path))
|
|
# sk-kimi- prefix triggers /coding endpoint auto-detection
|
|
monkeypatch.setenv("KIMI_API_KEY", "sk-kimi-faketesttoken123")
|
|
|
|
client, model = resolve_provider_client("kimi-coding", "kimi-for-coding")
|
|
assert client is not None, "Should resolve a client"
|
|
assert isinstance(client, AnthropicAuxiliaryClient), (
|
|
"Kimi Coding Plan endpoint (api.kimi.com/coding) speaks Anthropic "
|
|
"Messages — aux client MUST be AnthropicAuxiliaryClient, got "
|
|
f"{type(client).__name__}"
|
|
)
|
|
assert "kimi.com/coding" in str(client.base_url)
|