mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-07-09 13:21:42 +00:00
Rebuilds the iron-proxy egress feature cleanly onto current main. The original feat/iron-proxy branch had diverged from main with an unmergeable history (no usable merge-base after main history motion), so the feature's content diff was re-applied onto a fresh main cut and the three config/docs conflicts (commands.py status/egress, config.py proxy vs computer_use, slash-commands.md) resolved keeping main's content plus the egress additions. Optional, off-by-default TLS-intercepting egress proxy for remote terminal sandboxes. Sandboxes hold opaque proxy tokens; iron-proxy swaps them for real provider API keys at the network boundary. Includes the full review-cycle hardening: - P0/P1/P2 rounds (GodsBoy, stephenschoettler, arshkumarsingh, annguyenNous, maxpetrusenko, sxuff findings) - v0.39 schema realignment + Docker bridge-bind/listener-role fixes - Docker UX/enforcement hardening Salvaged security fixes folded in with credit: - Three P0 gaps (version-probe env scrub, Bitwarden ImportError fail-closed, container-reuse egress-boundary) + Docker v29.5.3 empty-label edge — kuangmi-bit (#48073) - P1/P2 (fail-closed replace.require:true, NODE_OPTIONS CA-flag conflict, GPG checksum verify, threat-model wording) — Bartok9 (#48076) Co-authored-by: kuangmi-bit <kuangmi@deeparchi.com> Co-authored-by: Bartok9 <danielrpike9@gmail.com>
122 lines
3.9 KiB
Python
122 lines
3.9 KiB
Python
"""Tests for CLI /status command behavior."""
|
|
from datetime import datetime
|
|
from pathlib import Path
|
|
from types import SimpleNamespace
|
|
from unittest.mock import MagicMock, patch
|
|
|
|
from cli import HermesCLI
|
|
from hermes_cli.commands import resolve_command
|
|
|
|
|
|
def _make_cli():
|
|
cli_obj = HermesCLI.__new__(HermesCLI)
|
|
cli_obj.config = {}
|
|
cli_obj.console = MagicMock()
|
|
cli_obj.agent = None
|
|
cli_obj.conversation_history = []
|
|
cli_obj.session_id = "session-123"
|
|
cli_obj._pending_input = MagicMock()
|
|
cli_obj._status_bar_visible = True
|
|
cli_obj.model = "openai/gpt-5.4"
|
|
cli_obj.provider = "openai"
|
|
cli_obj.session_start = datetime(2026, 4, 9, 19, 24)
|
|
cli_obj._agent_running = False
|
|
cli_obj._session_db = MagicMock()
|
|
cli_obj._session_db.get_session.return_value = None
|
|
return cli_obj
|
|
|
|
|
|
def test_status_command_is_available_in_cli_registry():
|
|
cmd = resolve_command("status")
|
|
assert cmd is not None
|
|
assert cmd.gateway_only is False
|
|
|
|
|
|
def test_egress_command_is_available_in_cli_registry():
|
|
cmd = resolve_command("egress")
|
|
assert cmd is not None
|
|
assert cmd.gateway_only is False
|
|
assert "status" in cmd.subcommands
|
|
|
|
|
|
def test_process_command_status_dispatches_without_toggling_status_bar():
|
|
cli_obj = _make_cli()
|
|
|
|
with patch.object(cli_obj, "_show_session_status", create=True) as mock_status:
|
|
assert cli_obj.process_command("/status") is True
|
|
|
|
mock_status.assert_called_once_with()
|
|
assert cli_obj._status_bar_visible is True
|
|
|
|
|
|
def test_process_command_egress_prints_proxy_status(monkeypatch):
|
|
cli_obj = _make_cli()
|
|
monkeypatch.setattr(
|
|
"hermes_cli.proxy_cli.format_status_text",
|
|
lambda: "Egress proxy status\nEnabled: no",
|
|
)
|
|
|
|
assert cli_obj.process_command("/egress") is True
|
|
|
|
cli_obj.console.print.assert_called()
|
|
printed = "\n".join(str(call.args[0]) for call in cli_obj.console.print.call_args_list)
|
|
assert "Egress proxy status" in printed
|
|
|
|
|
|
def test_statusbar_still_toggles_visibility():
|
|
cli_obj = _make_cli()
|
|
|
|
assert cli_obj.process_command("/statusbar") is True
|
|
assert cli_obj._status_bar_visible is False
|
|
|
|
|
|
def test_status_prefix_prefers_status_command_over_statusbar_toggle():
|
|
cli_obj = _make_cli()
|
|
|
|
with patch.object(cli_obj, "_show_session_status") as mock_status:
|
|
assert cli_obj.process_command("/sta") is True
|
|
|
|
mock_status.assert_called_once_with()
|
|
assert cli_obj._status_bar_visible is True
|
|
|
|
|
|
def test_show_session_status_prints_gateway_style_summary():
|
|
cli_obj = _make_cli()
|
|
cli_obj.agent = SimpleNamespace(
|
|
session_total_tokens=321,
|
|
session_api_calls=4,
|
|
)
|
|
cli_obj._session_db.get_session.return_value = {
|
|
"title": "My titled session",
|
|
"started_at": 1775791440,
|
|
}
|
|
|
|
with patch("cli.display_hermes_home", return_value="~/.hermes"):
|
|
cli_obj._show_session_status()
|
|
|
|
printed = "\n".join(str(call.args[0]) for call in cli_obj.console.print.call_args_list)
|
|
assert "Hermes CLI Status" in printed
|
|
assert "Session ID: session-123" in printed
|
|
assert "Path: ~/.hermes" in printed
|
|
assert "Title: My titled session" in printed
|
|
assert "Model: openai/gpt-5.4 (openai)" in printed
|
|
assert "Tokens: 321" in printed
|
|
assert "Agent Running: No" in printed
|
|
_, kwargs = cli_obj.console.print.call_args
|
|
assert kwargs.get("highlight") is False
|
|
assert kwargs.get("markup") is False
|
|
|
|
|
|
def test_profile_command_reports_custom_root_profile(monkeypatch, tmp_path, capsys):
|
|
"""Profile detection works for custom-root deployments (not under ~/.hermes)."""
|
|
cli_obj = _make_cli()
|
|
profile_home = tmp_path / "profiles" / "coder"
|
|
|
|
monkeypatch.setenv("HERMES_HOME", str(profile_home))
|
|
monkeypatch.setattr(Path, "home", lambda: tmp_path / "unrelated-home")
|
|
|
|
cli_obj._handle_profile_command()
|
|
|
|
out = capsys.readouterr().out
|
|
assert "Profile: coder" in out
|
|
assert f"Home: {profile_home}" in out
|