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.
86 lines
2.9 KiB
Python
86 lines
2.9 KiB
Python
"""Tests that Camofox browser sends Authorization header when CAMOFOX_API_KEY is set.
|
|
|
|
Regression test for https://github.com/NousResearch/hermes-agent/issues/20476
|
|
"""
|
|
|
|
import json
|
|
from unittest.mock import MagicMock, patch
|
|
|
|
import pytest
|
|
|
|
from tools.browser_camofox import (
|
|
_auth_headers,
|
|
camofox_back,
|
|
camofox_click,
|
|
camofox_close,
|
|
camofox_navigate,
|
|
camofox_press,
|
|
camofox_scroll,
|
|
camofox_snapshot,
|
|
camofox_type,
|
|
)
|
|
|
|
|
|
def _mock_response(status=200, json_data=None):
|
|
resp = MagicMock()
|
|
resp.status_code = status
|
|
resp.json.return_value = json_data or {}
|
|
resp.content = b"\x89PNG\r\n\x1a\nfake"
|
|
resp.raise_for_status = MagicMock()
|
|
return resp
|
|
|
|
|
|
class TestAuthHeaders:
|
|
"""Unit tests for _auth_headers() helper."""
|
|
|
|
def test_empty_when_no_key(self, monkeypatch):
|
|
monkeypatch.delenv("CAMOFOX_API_KEY", raising=False)
|
|
assert _auth_headers() == {}
|
|
|
|
|
|
def test_empty_when_key_blank(self, monkeypatch):
|
|
monkeypatch.setenv("CAMOFOX_API_KEY", " ")
|
|
assert _auth_headers() == {}
|
|
|
|
|
|
class TestAuthHeadersSent:
|
|
"""Verify all HTTP call sites include auth headers when CAMOFOX_API_KEY is set."""
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def _set_key(self, monkeypatch):
|
|
monkeypatch.setenv("CAMOFOX_URL", "http://localhost:9377")
|
|
monkeypatch.setenv("CAMOFOX_API_KEY", "my-api-key")
|
|
|
|
@patch("tools.browser_camofox.requests.post")
|
|
def test_ensure_tab_sends_auth(self, mock_post):
|
|
mock_post.return_value = _mock_response(json_data={"tabId": "t1"})
|
|
camofox_navigate("https://example.com", task_id="auth_test_1")
|
|
_, kwargs = mock_post.call_args
|
|
assert kwargs["headers"] == {"Authorization": "Bearer my-api-key"}
|
|
|
|
|
|
@patch("tools.browser_camofox.requests.post")
|
|
@patch("tools.browser_camofox.requests.delete")
|
|
def test_delete_sends_auth(self, mock_delete, mock_post):
|
|
mock_post.return_value = _mock_response(json_data={"tabId": "t4"})
|
|
camofox_navigate("https://example.com", task_id="auth_test_4")
|
|
mock_delete.return_value = _mock_response(json_data={"ok": True})
|
|
camofox_close(task_id="auth_test_4")
|
|
_, kwargs = mock_delete.call_args
|
|
assert kwargs["headers"] == {"Authorization": "Bearer my-api-key"}
|
|
|
|
|
|
class TestNoAuthHeadersWhenKeyUnset:
|
|
"""Verify HTTP calls send empty headers when CAMOFOX_API_KEY is not set."""
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def _unset_key(self, monkeypatch):
|
|
monkeypatch.setenv("CAMOFOX_URL", "http://localhost:9377")
|
|
monkeypatch.delenv("CAMOFOX_API_KEY", raising=False)
|
|
|
|
@patch("tools.browser_camofox.requests.post")
|
|
def test_no_auth_on_tab_creation(self, mock_post):
|
|
mock_post.return_value = _mock_response(json_data={"tabId": "t5"})
|
|
camofox_navigate("https://example.com", task_id="noauth_test_1")
|
|
_, kwargs = mock_post.call_args
|
|
assert kwargs.get("headers") == {}
|