mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-07-30 19:09:28 +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.
134 lines
4 KiB
Python
134 lines
4 KiB
Python
"""Regression tests for Linux/X11 capture target selection (#58026, #54173)."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from unittest.mock import patch
|
|
|
|
# Tied z_index=0 fixture from #58026 (ding ahead of real terminals).
|
|
ISSUE_58026_WINDOWS = [
|
|
{
|
|
"app_name": "ding",
|
|
"pid": 4294,
|
|
"window_id": 33554439,
|
|
"title": "Desktop Icons 1",
|
|
"is_on_screen": True,
|
|
"z_index": 0,
|
|
},
|
|
{
|
|
"app_name": "",
|
|
"pid": 1816017,
|
|
"window_id": 60817412,
|
|
"title": "zcode",
|
|
"is_on_screen": True,
|
|
"z_index": 0,
|
|
},
|
|
{
|
|
"app_name": "",
|
|
"pid": 1877178,
|
|
"window_id": 84043449,
|
|
"title": "xr@10:~/hermes",
|
|
"is_on_screen": True,
|
|
"z_index": 0,
|
|
},
|
|
{
|
|
"app_name": "",
|
|
"pid": 1877178,
|
|
"window_id": 84065715,
|
|
"title": "HERMES-CU",
|
|
"is_on_screen": True,
|
|
"z_index": 0,
|
|
},
|
|
]
|
|
|
|
# Linux metadata-quirk fixture from #54173 (null is_on_screen, GNOME Shell
|
|
# @!x,y;BDHF backdrop helper ahead of real app windows).
|
|
LINUX_LIST_WINDOWS = [
|
|
{
|
|
"app_name": "",
|
|
"pid": 2951331,
|
|
"window_id": 98566147,
|
|
"title": "@!1921,0;BDHF",
|
|
"is_on_screen": None,
|
|
"z_index": 0,
|
|
},
|
|
{
|
|
"app_name": "",
|
|
"pid": 11715,
|
|
"window_id": 81790890,
|
|
"title": "Guides — OMC Docs - Google Chrome",
|
|
"is_on_screen": None,
|
|
"z_index": 0,
|
|
},
|
|
{
|
|
"app_name": "",
|
|
"pid": 11433,
|
|
"window_id": 41943052,
|
|
"title": "README.md - hermes-agent - Visual Studio Code",
|
|
"is_on_screen": False,
|
|
"z_index": 0,
|
|
},
|
|
]
|
|
|
|
|
|
def _normalized_windows(raw=ISSUE_58026_WINDOWS):
|
|
from tools.computer_use.cua_backend import _ingest_windows
|
|
|
|
return _ingest_windows(raw)
|
|
|
|
|
|
def test_parse_xprop_net_active_window_standard_output():
|
|
from tools.computer_use.cua_backend import _parse_xprop_net_active_window
|
|
|
|
raw = "_NET_ACTIVE_WINDOW(WINDOW): window id # 0x503000b\n"
|
|
assert _parse_xprop_net_active_window(raw) == 0x503000b
|
|
|
|
|
|
def test_default_capture_prefers_x11_active_window_when_z_index_tied():
|
|
from tools.computer_use.cua_backend import _select_capture_target
|
|
|
|
windows = _normalized_windows()
|
|
|
|
with patch("tools.computer_use.cua_backend.sys.platform", "linux"), patch(
|
|
"tools.computer_use.cua_backend._linux_x11_active_window_id",
|
|
return_value=84043449,
|
|
):
|
|
target = _select_capture_target(windows, app_requested=False)
|
|
|
|
assert target["title"] == "xr@10:~/hermes"
|
|
assert target["window_id"] == 84043449
|
|
|
|
|
|
def test_default_capture_skips_desktop_helper_when_active_window_unknown():
|
|
"""Even without _NET_ACTIVE_WINDOW, ding/Desktop helpers must not win (#54173)."""
|
|
from tools.computer_use.cua_backend import _select_capture_target
|
|
|
|
windows = _normalized_windows()
|
|
|
|
with patch("tools.computer_use.cua_backend.sys.platform", "linux"), patch(
|
|
"tools.computer_use.cua_backend._linux_x11_active_window_id",
|
|
return_value=None,
|
|
):
|
|
target = _select_capture_target(windows, app_requested=False)
|
|
|
|
# "Desktop Icons 1" is a shell helper window that captures as empty; with
|
|
# the active window unknown, the first REAL app window wins list order.
|
|
assert target["window_id"] == 60817412
|
|
assert target["title"] == "zcode"
|
|
|
|
|
|
def test_linux_null_is_on_screen_is_treated_as_unknown_not_offscreen():
|
|
"""cua-driver 0.6.x may return JSON null for Linux is_on_screen (#54173)."""
|
|
windows = _normalized_windows(LINUX_LIST_WINDOWS)
|
|
|
|
assert windows[0]["off_screen"] is False
|
|
assert windows[1]["off_screen"] is False
|
|
assert windows[2]["off_screen"] is True
|
|
|
|
|
|
def test_explicit_app_capture_preserves_filtered_target_order():
|
|
"""When the caller filters first, target selection should not skip the match."""
|
|
from tools.computer_use.cua_backend import _select_capture_target
|
|
|
|
chrome = _normalized_windows(LINUX_LIST_WINDOWS)[1]
|
|
|
|
assert _select_capture_target([chrome], app_requested=True) == chrome
|