hermes-agent/tests/agent/test_moa_slot_api_mode.py
Teknium 6b81590c55
test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions
Systematic prune per AGENTS.md test policy, one pass over every major
test tree (gateway, hermes_cli, tools, agent, run_agent, plugins, cli,
cron, tui_gateway, honcho/openviking, root-level):

- DELETE: source-reading tests (read_text/getsource on prod files),
  change-detector tests (exact catalog counts, model-name snapshots,
  config version literals), mock-echo tests (assert a mock returns what
  it was told), assertion-free/trivial tests, near-duplicate
  parametrizations (boundaries + one representative kept), async/sync
  twin duplicates, cosmetic within-file variations.
- KEEP (mandatory): security/redaction/approval guards, message-role
  alternation invariants, prompt-caching/deterministic-call-id
  invariants, issue-number regression tests (deduped), E2E tests.
- 6 test files deleted outright (script-style/no-assert or fully
  redundant); conftest.py, fakes/, fixtures/ untouched.
- tests/acp/conftest.py added: autouse fixture stubs the live
  models.dev/GitHub/Copilot/Anthropic inventory fetches that ACP server
  tests performed on every session create — test_server.py 147s → 3.4s,
  and the tests are now genuinely hermetic.
- Sleep-based slowness shrunk where safe (codex_ttfb_watchdog,
  compression_concurrent_fork, etc.); no wall-clock assertion tightened.

Verification: full hermetic suite via scripts/run_tests.sh —
2439 files, 31,130 tests passed, 0 failed, 0 flaky retries, 315s wall
(baseline: 583s wall, 13,564s subprocess CPU).
2026-07-29 13:10:23 -07:00

207 lines
6.6 KiB
Python

"""Tests for MoA slot_runtime api_mode propagation (issue #54379).
Verify that _slot_runtime passes the resolved api_mode through to call_llm,
so reference slots using providers that require a specific API surface
(e.g. Copilot GPT-5.x → codex_responses) get routed correctly.
"""
from __future__ import annotations
from types import SimpleNamespace
from unittest.mock import patch
import pytest
def _response(content="ok"):
message = SimpleNamespace(content=content, tool_calls=[])
choice = SimpleNamespace(message=message, finish_reason="stop")
return SimpleNamespace(choices=[choice], usage=None, model="fake")
class TestSlotRuntimeApiMode:
"""_slot_runtime should include api_mode when resolve_runtime_provider returns it."""
@patch("hermes_cli.runtime_provider.resolve_runtime_provider")
def test_slot_runtime_includes_api_mode(self, mock_resolve):
"""api_mode from resolve_runtime_provider is forwarded in output dict."""
mock_resolve.return_value = {
"provider": "copilot",
"model": "gpt-5.5",
"base_url": "https://api.githubcopilot.com",
"api_key": "test-key",
"api_mode": "codex_responses",
}
from agent.moa_loop import _slot_runtime
result = _slot_runtime({"provider": "copilot", "model": "gpt-5.5"})
assert result["api_mode"] == "codex_responses"
assert result["base_url"] == "https://api.githubcopilot.com"
assert result["api_key"] == "test-key"
@patch("hermes_cli.runtime_provider.resolve_runtime_provider")
def test_slot_runtime_omits_api_mode_when_empty(self, mock_resolve):
"""Empty string api_mode is treated as absent."""
mock_resolve.return_value = {
"provider": "copilot",
"model": "gpt-5.5",
"base_url": "https://api.githubcopilot.com",
"api_key": "test-key",
"api_mode": "",
}
from agent.moa_loop import _slot_runtime
result = _slot_runtime({"provider": "copilot", "model": "gpt-5.5"})
assert "api_mode" not in result
def test_run_reference_passes_slot_extra_body(monkeypatch):
"""Reference advisors should receive custom provider extra_body."""
from agent import moa_loop
captured = {}
def fake_call_llm(**kwargs):
captured.update(kwargs)
return _response("advisor")
monkeypatch.setattr(
moa_loop,
"_slot_runtime",
lambda slot: {
"provider": "custom",
"model": "qwen3.7-max",
"base_url": "https://dashscope.example/v1",
"api_key": "test-key",
"extra_body": {"enable_thinking": False},
},
)
monkeypatch.setattr(moa_loop, "call_llm", fake_call_llm)
monkeypatch.setattr(moa_loop, "_maybe_apply_moa_cache_control", lambda messages, runtime: messages)
label, text, _usage = moa_loop._run_reference(
{"provider": "dashscope", "model": "qwen3.7-max"},
[{"role": "user", "content": "hello"}],
)
assert label == "dashscope:qwen3.7-max"
assert text == "advisor"
assert captured["extra_body"] == {"enable_thinking": False}
def test_moa_aggregator_merges_slot_extra_body_with_caller_override(tmp_path, monkeypatch):
"""Aggregator calls should merge slot defaults without duplicate kwargs."""
home = tmp_path / ".hermes"
home.mkdir()
(home / "config.yaml").write_text(
"""
moa:
default_preset: closed
presets:
closed:
enabled: true
reference_models: []
aggregator:
provider: dashscope
model: qwen3.7-max
""".strip(),
encoding="utf-8",
)
monkeypatch.setenv("HERMES_HOME", str(home))
from agent import moa_loop
captured = {}
def fake_call_llm(**kwargs):
captured.update(kwargs)
return _response("acted")
monkeypatch.setattr(
moa_loop,
"_slot_runtime",
lambda slot: {
"provider": "custom",
"model": "qwen3.7-max",
"base_url": "https://dashscope.example/v1",
"api_key": "test-key",
"extra_body": {
"enable_thinking": False,
"metadata": {"source": "slot"},
},
},
)
monkeypatch.setattr(moa_loop, "call_llm", fake_call_llm)
facade = moa_loop.MoAChatCompletions("closed")
facade.create(
model="closed",
messages=[{"role": "user", "content": "hello"}],
extra_body={
"metadata": {"source": "caller"},
"reasoning": {"effort": "none"},
},
)
assert captured["extra_body"] == {
"enable_thinking": False,
"metadata": {"source": "caller"},
"reasoning": {"effort": "none"},
}
def test_one_shot_aggregate_moa_context_passes_slot_extra_body(monkeypatch):
"""The one-shot `/moa <prompt>` synthesis call (aggregate_moa_context) is
the third independent MoA call path — its aggregator call receives the
slot runtime via **agg_runtime, so custom-provider extra_body must flow
through it too."""
from agent import moa_loop
captured_calls = []
def fake_call_llm(**kwargs):
captured_calls.append(kwargs)
return _response("synthesis")
monkeypatch.setattr(
moa_loop,
"_slot_runtime",
lambda slot: {
"provider": "custom",
"model": "qwen3.7-max",
"base_url": "https://dashscope.example/v1",
"api_key": "test-key",
"extra_body": {"enable_thinking": False},
},
)
monkeypatch.setattr(moa_loop, "call_llm", fake_call_llm)
monkeypatch.setattr(
moa_loop, "_maybe_apply_moa_cache_control", lambda messages, runtime: messages
)
result = moa_loop.aggregate_moa_context(
user_prompt="hello",
api_messages=[{"role": "user", "content": "hello"}],
reference_models=[{"provider": "dashscope", "model": "qwen3.7-max"}],
aggregator={"provider": "dashscope", "model": "qwen3.7-max"},
)
assert "synthesis" in result
agg_calls = [c for c in captured_calls if c.get("task") == "moa_aggregator"]
assert len(agg_calls) == 1
assert agg_calls[0]["extra_body"] == {"enable_thinking": False}
class TestCallLlmApiMode:
"""call_llm should accept and forward api_mode parameter."""
def test_call_llm_accepts_api_mode_kwarg(self):
"""call_llm signature includes api_mode parameter."""
import inspect
from agent.auxiliary_client import call_llm
sig = inspect.signature(call_llm)
assert "api_mode" in sig.parameters
assert sig.parameters["api_mode"].default is None