mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-07-31 19:16:29 +00:00
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).
129 lines
No EOL
4.1 KiB
Python
129 lines
No EOL
4.1 KiB
Python
"""Tests for the MOA progress indicator added in issue #59546.
|
|
|
|
The MoA facade (``MoAChatCompletions.create``) emits a sequence of display
|
|
events so a TUI / CLI / desktop surface can render progress as references
|
|
complete and the phase transitions from ``reference`` to ``aggregator``:
|
|
|
|
- ``moa.progress`` — fired once per reference completion with
|
|
``refs_done`` and ``refs_total`` (e.g. drives a
|
|
status-bar ``MOA: 2/3 refs done`` indicator)
|
|
- ``moa.phase`` — fired once per phase transition (currently only the
|
|
``phase="aggregator"`` transition right before the
|
|
aggregator acts)
|
|
|
|
These tests exercise the real callback surface end-to-end through the
|
|
display hook (``reference_callback``) — no mocks on the dispatch path.
|
|
The LLM is stubbed via ``call_llm`` so the test does not depend on any
|
|
real provider.
|
|
"""
|
|
|
|
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")
|
|
|
|
|
|
@pytest.fixture
|
|
def moa_config(tmp_path, monkeypatch):
|
|
home = tmp_path / ".hermes"
|
|
home.mkdir()
|
|
(home / "config.yaml").write_text(
|
|
"""
|
|
moa:
|
|
default_preset: closed
|
|
presets:
|
|
closed:
|
|
enabled: true
|
|
reference_models:
|
|
- provider: openrouter
|
|
model: anthropic/claude-opus-4.8
|
|
- provider: openrouter
|
|
model: openai/gpt-5.5
|
|
- provider: openrouter
|
|
model: google/gemini-3-pro
|
|
aggregator:
|
|
provider: openrouter
|
|
model: anthropic/claude-opus-4.8
|
|
""".strip(),
|
|
encoding="utf-8",
|
|
)
|
|
monkeypatch.setenv("HERMES_HOME", str(home))
|
|
return home
|
|
|
|
|
|
def _collect_emits(facade):
|
|
"""Pull every event the facade dispatches into a flat list of (event, kwargs)."""
|
|
captured: list[tuple[str, dict]] = []
|
|
|
|
def _capture(event: str, **kwargs):
|
|
captured.append((event, kwargs))
|
|
|
|
facade.reference_callback = _capture
|
|
return captured
|
|
|
|
|
|
|
|
|
|
def test_moa_phase_transitions_to_aggregator(moa_config, monkeypatch):
|
|
"""A single ``moa.phase`` event with ``phase="aggregator"`` fires after the fan-out."""
|
|
from agent.moa_loop import MoAChatCompletions
|
|
|
|
def fake_call_llm(**kwargs):
|
|
if kwargs.get("task") == "moa_reference":
|
|
return _response("advice")
|
|
return _response("acted")
|
|
|
|
monkeypatch.setattr("agent.moa_loop.call_llm", fake_call_llm)
|
|
|
|
facade = MoAChatCompletions("closed")
|
|
captured = _collect_emits(facade)
|
|
|
|
facade.create(
|
|
model="closed",
|
|
messages=[{"role": "user", "content": "plan the migration"}],
|
|
)
|
|
|
|
phase_events = [(e, k) for (e, k) in captured if e == "moa.phase"]
|
|
# Exactly one phase event per turn, identifying the aggregator.
|
|
assert len(phase_events) == 1
|
|
_event, kwargs = phase_events[0]
|
|
assert kwargs["phase"] == "aggregator"
|
|
assert kwargs["aggregator"] == "openrouter:anthropic/claude-opus-4.8"
|
|
# counts match the configured reference count
|
|
assert kwargs["refs_done"] == 3
|
|
assert kwargs["refs_total"] == 3
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_moa_progress_callback_none_safe(moa_config, monkeypatch):
|
|
"""A missing ``reference_callback`` does not break the fan-out or create()."""
|
|
from agent.moa_loop import MoAChatCompletions
|
|
|
|
def fake_call_llm(**kwargs):
|
|
if kwargs.get("task") == "moa_reference":
|
|
return _response("advice")
|
|
return _response("acted")
|
|
|
|
monkeypatch.setattr("agent.moa_loop.call_llm", fake_call_llm)
|
|
|
|
# No callback attached — the facade's _emit is a no-op in that case.
|
|
facade = MoAChatCompletions("closed")
|
|
assert facade.reference_callback is None
|
|
facade.create(
|
|
model="closed",
|
|
messages=[{"role": "user", "content": "noop"}],
|
|
)
|
|
# Turn still resolved cleanly; aggregator slot populated as usual.
|
|
assert facade.last_aggregator_slot is not None
|
|
assert facade.last_aggregator_slot["model"] == "anthropic/claude-opus-4.8" |