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.
159 lines
5.1 KiB
Python
159 lines
5.1 KiB
Python
"""Regression test for config.yaml `security.redact_secrets: false` toggle.
|
|
|
|
Bug: `agent/redact.py` snapshots `_REDACT_ENABLED` from the env var
|
|
`HERMES_REDACT_SECRETS` at module-import time. `hermes_cli/main.py` at
|
|
line ~174 calls `setup_logging(mode="cli")` which transitively imports
|
|
`agent.redact` — BEFORE any config bridge ran. So if a user set
|
|
`security.redact_secrets: false` in config.yaml (instead of as an env var
|
|
in .env), the toggle was silently ignored in both `hermes chat` and
|
|
`hermes gateway run`.
|
|
|
|
Fix: bridge `security.redact_secrets` from config.yaml → `HERMES_REDACT_SECRETS`
|
|
env var in `hermes_cli/main.py` BEFORE the `setup_logging()` call.
|
|
"""
|
|
import os
|
|
import subprocess
|
|
import sys
|
|
import textwrap
|
|
from pathlib import Path
|
|
|
|
REPO_ROOT = Path(__file__).resolve().parents[2]
|
|
|
|
|
|
def test_redact_secrets_false_in_config_yaml_is_honored(tmp_path):
|
|
"""Setting `security.redact_secrets: false` in config.yaml must disable
|
|
redaction — even though it's set in YAML, not as an env var."""
|
|
hermes_home = tmp_path / ".hermes"
|
|
hermes_home.mkdir()
|
|
|
|
# Write a config.yaml with redact_secrets: false
|
|
(hermes_home / "config.yaml").write_text(
|
|
textwrap.dedent(
|
|
"""\
|
|
security:
|
|
redact_secrets: false
|
|
"""
|
|
)
|
|
)
|
|
# Empty .env so nothing else sets the env var
|
|
(hermes_home / ".env").write_text("")
|
|
|
|
# Spawn a fresh Python process that imports hermes_cli.main and checks
|
|
# _REDACT_ENABLED. Must be a subprocess — we need a clean module state.
|
|
probe = textwrap.dedent(
|
|
"""\
|
|
import sys, os
|
|
# Make absolutely sure the env var is not pre-set
|
|
os.environ.pop("HERMES_REDACT_SECRETS", None)
|
|
sys.path.insert(0, %r)
|
|
import hermes_cli.main # triggers the bridge + setup_logging
|
|
import agent.redact
|
|
print(f"REDACT_ENABLED={agent.redact._REDACT_ENABLED}")
|
|
print(f"ENV_VAR={os.environ.get('HERMES_REDACT_SECRETS', '<unset>')}")
|
|
"""
|
|
) % str(REPO_ROOT)
|
|
|
|
env = dict(os.environ)
|
|
env["HERMES_HOME"] = str(hermes_home)
|
|
env.pop("HERMES_REDACT_SECRETS", None)
|
|
|
|
result = subprocess.run(
|
|
[sys.executable, "-c", probe],
|
|
env=env,
|
|
capture_output=True,
|
|
text=True,
|
|
cwd=str(REPO_ROOT),
|
|
timeout=30,
|
|
)
|
|
assert result.returncode == 0, f"probe failed: {result.stderr}"
|
|
assert "REDACT_ENABLED=False" in result.stdout, (
|
|
f"Config toggle not honored.\nstdout: {result.stdout}\nstderr: {result.stderr}"
|
|
)
|
|
assert "ENV_VAR=false" in result.stdout
|
|
|
|
|
|
def test_redact_secrets_default_true_when_unset(tmp_path):
|
|
"""Without the config key or env var, redaction is ON by default (#17691).
|
|
|
|
Secret redaction is a secure default — users who need raw credential
|
|
values in tool output (e.g. working on the redactor itself) must set
|
|
`security.redact_secrets: false` explicitly (or
|
|
`HERMES_REDACT_SECRETS=false`).
|
|
"""
|
|
hermes_home = tmp_path / ".hermes"
|
|
hermes_home.mkdir()
|
|
(hermes_home / "config.yaml").write_text("{}\n") # empty config
|
|
(hermes_home / ".env").write_text("")
|
|
|
|
probe = textwrap.dedent(
|
|
"""\
|
|
import sys, os
|
|
os.environ.pop("HERMES_REDACT_SECRETS", None)
|
|
sys.path.insert(0, %r)
|
|
import hermes_cli.main
|
|
import agent.redact
|
|
print(f"REDACT_ENABLED={agent.redact._REDACT_ENABLED}")
|
|
"""
|
|
) % str(REPO_ROOT)
|
|
|
|
env = dict(os.environ)
|
|
env["HERMES_HOME"] = str(hermes_home)
|
|
env.pop("HERMES_REDACT_SECRETS", None)
|
|
|
|
result = subprocess.run(
|
|
[sys.executable, "-c", probe],
|
|
env=env,
|
|
capture_output=True,
|
|
text=True,
|
|
cwd=str(REPO_ROOT),
|
|
timeout=30,
|
|
)
|
|
assert result.returncode == 0, f"probe failed: {result.stderr}"
|
|
assert "REDACT_ENABLED=True" in result.stdout
|
|
|
|
|
|
|
|
|
|
def test_dotenv_redact_secrets_beats_config_yaml(tmp_path):
|
|
""".env HERMES_REDACT_SECRETS takes precedence over config.yaml."""
|
|
hermes_home = tmp_path / ".hermes"
|
|
hermes_home.mkdir()
|
|
(hermes_home / "config.yaml").write_text(
|
|
textwrap.dedent(
|
|
"""\
|
|
security:
|
|
redact_secrets: false
|
|
"""
|
|
)
|
|
)
|
|
# .env force-enables redaction
|
|
(hermes_home / ".env").write_text("HERMES_REDACT_SECRETS=true\n")
|
|
|
|
probe = textwrap.dedent(
|
|
"""\
|
|
import sys, os
|
|
os.environ.pop("HERMES_REDACT_SECRETS", None)
|
|
sys.path.insert(0, %r)
|
|
import hermes_cli.main
|
|
import agent.redact
|
|
print(f"REDACT_ENABLED={agent.redact._REDACT_ENABLED}")
|
|
print(f"ENV_VAR={os.environ.get('HERMES_REDACT_SECRETS', '<unset>')}")
|
|
"""
|
|
) % str(REPO_ROOT)
|
|
|
|
env = dict(os.environ)
|
|
env["HERMES_HOME"] = str(hermes_home)
|
|
env.pop("HERMES_REDACT_SECRETS", None)
|
|
|
|
result = subprocess.run(
|
|
[sys.executable, "-c", probe],
|
|
env=env,
|
|
capture_output=True,
|
|
text=True,
|
|
cwd=str(REPO_ROOT),
|
|
timeout=30,
|
|
)
|
|
assert result.returncode == 0, f"probe failed: {result.stderr}"
|
|
# .env value wins
|
|
assert "REDACT_ENABLED=True" in result.stdout
|
|
assert "ENV_VAR=true" in result.stdout
|