nousresearch--hermes-agent
b4fbd6fe9f
Deploy Site / deploy-vercel (push) Has been skipped
Deploy Site / deploy-docs (push) Has been skipped
Build Skills Index / build-index (push) Has been skipped
CI / Deny unrelated histories (push) Has been skipped
CI / Detect affected areas (push) Successful in 27m35s
CI / OSV scan (push) Failing after 4s
CI / Build&Test Docker image (push) Successful in 9s
CI / Supply-chain scan (push) Has been skipped
CI / Lint Docker scripts (push) Failing after 5m13s
CI / Check contributors (push) Failing after 12m8s
CI / Docs Site (push) Failing after 12m8s
CI / TypeScript (push) Failing after 12m8s
CI / Python lints (push) Failing after 12m9s
CI / Python tests (push) Failing after 12m9s
CI / Check uv.lock (push) Failing after 23m22s
CI / CI timing report (push) Has been cancelled
Build Skills Index / trigger-deploy (push) Has been cancelled
CI / All required checks pass (push) Has been cancelled
78 行
2.7 KiB
Python
78 行
2.7 KiB
Python
"""Regression tests for #60328: --yolo must set HERMES_YOLO_MODE in
|
|
main() before _prepare_agent_startup() triggers tool imports.
|
|
|
|
The freeze mechanism in tools.approval (_YOLO_MODE_FROZEN) is correct
|
|
by design (PR #7994). The bug was that main() set the env var inside
|
|
cmd_chat(), which runs *after* _prepare_agent_startup() has already
|
|
imported tools.approval and frozen the constant to False.
|
|
|
|
These tests verify the ordering in main() itself: the env var must
|
|
already be set at the moment _prepare_agent_startup() is called.
|
|
If someone moves the assignment back into cmd_chat(), these tests
|
|
fail — catching the exact #60328 regression.
|
|
"""
|
|
|
|
import os
|
|
import sys
|
|
|
|
|
|
def _run_main_and_capture_yolo_at_startup(monkeypatch, argv):
|
|
"""Run main() with *argv*, capturing HERMES_YOLO_MODE at the
|
|
moment _prepare_agent_startup is called.
|
|
|
|
Returns the captured env var value (or None if unset).
|
|
"""
|
|
yolo_at_startup = {}
|
|
|
|
def spy_prepare_startup(args):
|
|
yolo_at_startup["value"] = os.environ.get("HERMES_YOLO_MODE")
|
|
|
|
monkeypatch.setattr(
|
|
"hermes_cli.main._prepare_agent_startup", spy_prepare_startup
|
|
)
|
|
# Stub cmd_chat so main() returns cleanly without entering chat.
|
|
monkeypatch.setattr("hermes_cli.main.cmd_chat", lambda args: None)
|
|
monkeypatch.delenv("HERMES_YOLO_MODE", raising=False)
|
|
monkeypatch.setattr(sys, "argv", argv)
|
|
|
|
from hermes_cli.main import main as cli_main
|
|
|
|
cli_main()
|
|
|
|
return yolo_at_startup.get("value")
|
|
|
|
|
|
def test_top_level_yolo_flag_sets_env_before_startup(monkeypatch):
|
|
"""hermes --yolo must set HERMES_YOLO_MODE before
|
|
_prepare_agent_startup imports tools.approval."""
|
|
result = _run_main_and_capture_yolo_at_startup(
|
|
monkeypatch, ["hermes", "--yolo"]
|
|
)
|
|
assert result == "1", (
|
|
"HERMES_YOLO_MODE was not '1' when _prepare_agent_startup was "
|
|
"called from main() with --yolo. This is the #60328 regression: "
|
|
"the env var is set too late (inside cmd_chat, after tool imports)."
|
|
)
|
|
|
|
|
|
def test_chat_subcommand_yolo_flag_sets_env_before_startup(monkeypatch):
|
|
"""hermes chat --yolo must also set HERMES_YOLO_MODE before
|
|
_prepare_agent_startup."""
|
|
result = _run_main_and_capture_yolo_at_startup(
|
|
monkeypatch, ["hermes", "chat", "--yolo"]
|
|
)
|
|
assert result == "1", (
|
|
"HERMES_YOLO_MODE was not '1' when _prepare_agent_startup was "
|
|
"called from main() with 'chat --yolo'."
|
|
)
|
|
|
|
|
|
def test_no_yolo_flag_leaves_env_unset_at_startup(monkeypatch):
|
|
"""Without --yolo, HERMES_YOLO_MODE must not be set at startup."""
|
|
result = _run_main_and_capture_yolo_at_startup(
|
|
monkeypatch, ["hermes"]
|
|
)
|
|
assert result is None, (
|
|
"HERMES_YOLO_MODE was unexpectedly set at startup without --yolo."
|
|
)
|