mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-07-31 19:16:29 +00:00
Second, deeper pass over tools/gateway/hermes_cli plus first pass over the trees wave 1 missed (acp, acp_adapter, skills, computer_use, docker, dashboard, conformance, monitoring, secret_sources, hermes_state, providers). Same rubric as wave 1 (AGENTS.md test policy); security, alternation/caching invariants, issue-number regressions, and E2E kept. Real test-quality fixes found and rooted out along the way: - tests/tools/test_command_guards.py made real auxiliary-LLM HTTPS calls (DEFAULT_CONFIG smart-approval leaked in) — pinned approval mode=manual via autouse fixture: 17.4s → 0.4s. - test_model_switch_custom_providers.py / test_user_providers_model_switch.py silently probed live provider catalogs (~2s/test) — stubbed cached_provider_model_ids/provider_model_ids/fetch_api_models. - test_telegram_noise_filter.py: 15-platform copy-paste matrix over shared gateway.run logic → 3 representative platforms (55s → 3.9s). - test_gateway_shutdown.py: stop()'s 5s interrupt-deadline loop spun on MagicMock agents — interrupt.side_effect now clears _running_agents (22s → 1.0s). - test_gateway_inactivity_timeout.py poll-harness timings shrunk 3-5x (24s → 1.1s); test_mcp_stability.py backoff/SIGTERM-grace sleeps patched (15.4s → 2.5s); test_async_delegation.py negative-drain wait 5s → 0.5s. - test_telegram_init_deadline.py: loop-block margin restored to 1.0s with rationale comment — the watchdog-dump assertion needs the loop blocked well past deadline+grace under parallel load (flaked once in the 40-worker verification run at a 0.2s margin). Verification: full hermetic suite via scripts/run_tests.sh — 2,438 files, 21,718 tests passed, 0 failed, 293.9s wall. Suite totals vs original baseline: 46,820 → 19,757 test functions (−57.8%), wall 583.5s → 293.9s (−50%), subprocess CPU 13,564s → 11,623s.
138 lines
4.3 KiB
Python
138 lines
4.3 KiB
Python
"""Tests for transient-error handling in Telegram progress-message editing.
|
|
|
|
Issue: #27828
|
|
|
|
When ``edit_message_text`` fails with a transient network error (e.g.
|
|
``httpx.ConnectError``), the gateway must NOT permanently disable progress-
|
|
message editing. Only permanent failures (flood control, message-not-found,
|
|
permissions) should set ``can_edit = False``.
|
|
|
|
Two layers are tested:
|
|
|
|
1. The ``_TRANSIENT_EDIT_MARKERS`` / retryable classification logic in
|
|
``TelegramAdapter.edit_message``.
|
|
2. The ``send_progress_messages`` caller in ``run.py`` honours
|
|
``result.retryable`` and keeps ``can_edit = True``.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
import pytest
|
|
|
|
from gateway.platforms.base import SendResult
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Helpers
|
|
# ---------------------------------------------------------------------------
|
|
|
|
_TRANSIENT_MARKERS = (
|
|
"connecterror",
|
|
"connect error",
|
|
"connection error",
|
|
"networkerror",
|
|
"network error",
|
|
"timed out",
|
|
"readtimeout",
|
|
"writetimeout",
|
|
"server disconnected",
|
|
"temporarily unavailable",
|
|
"temporary failure",
|
|
"httpx",
|
|
)
|
|
|
|
_PERMANENT_MARKERS = (
|
|
"message to edit not found",
|
|
"message can't be edited",
|
|
"not enough rights",
|
|
"message_id_invalid",
|
|
)
|
|
|
|
|
|
def _is_transient(error_str: str) -> bool:
|
|
"""Mirrors the classification logic added to TelegramAdapter.edit_message."""
|
|
err = error_str.lower()
|
|
return any(m in err for m in _TRANSIENT_MARKERS)
|
|
|
|
|
|
def _is_permanent(error_str: str) -> bool:
|
|
err = error_str.lower()
|
|
return any(m in err for m in _PERMANENT_MARKERS)
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# 1. Error classification — transient vs permanent
|
|
# ---------------------------------------------------------------------------
|
|
|
|
@pytest.mark.parametrize("error_str", [
|
|
"httpx.ConnectError: Connection refused",
|
|
"telegram.error.NetworkError: httpx.ConnectError",
|
|
"NetworkError: remote end closed connection without response",
|
|
"httpx.ReadTimeout: read timed out",
|
|
"ReadTimeout: timed out",
|
|
"Server disconnected",
|
|
"Temporarily unavailable",
|
|
"Temporary failure in name resolution",
|
|
"Connection error: failed to connect",
|
|
])
|
|
def test_transient_errors_are_classified_as_transient(error_str):
|
|
"""Network / transient errors must be classified as retryable."""
|
|
assert _is_transient(error_str), (
|
|
f"Expected {error_str!r} to be transient"
|
|
)
|
|
|
|
|
|
@pytest.mark.parametrize("error_str", [
|
|
"Bad Request: message to edit not found",
|
|
"Bad Request: message can't be edited",
|
|
"Bad Request: not enough rights to edit the message",
|
|
"Bad Request: MESSAGE_ID_INVALID",
|
|
"flood_control:30.0",
|
|
"Forbidden: bot was blocked by the user",
|
|
])
|
|
def test_permanent_errors_are_not_transient(error_str):
|
|
"""Permanent edit failures must NOT be classified as retryable."""
|
|
assert not _is_transient(error_str), (
|
|
f"Expected {error_str!r} to be permanent (non-transient)"
|
|
)
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# 2. SendResult retryable field
|
|
# ---------------------------------------------------------------------------
|
|
|
|
def test_send_result_retryable_default_is_false():
|
|
r = SendResult(success=True, message_id="1")
|
|
assert r.retryable is False
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# 3. run.py logic — retryable result must NOT set can_edit=False
|
|
# We simulate the relevant block from send_progress_messages():
|
|
#
|
|
# if not result.success:
|
|
# if getattr(result, 'retryable', False):
|
|
# continue # <-- keep can_edit=True
|
|
# ...
|
|
# can_edit = False
|
|
#
|
|
# ---------------------------------------------------------------------------
|
|
|
|
def _simulate_progress_loop(edit_results):
|
|
"""
|
|
Simulate the can_edit decision for a sequence of edit_message results.
|
|
|
|
Returns the final value of can_edit after processing all results.
|
|
"""
|
|
can_edit = True
|
|
for result in edit_results:
|
|
if not result.success:
|
|
if getattr(result, "retryable", False):
|
|
# Transient — keep can_edit True and skip to next cycle
|
|
continue
|
|
can_edit = False
|
|
break
|
|
return can_edit
|
|
|
|
|