Files
hermes-agent/tests/hermes_cli/test_approvals_command.py
ethernet 284dbaf537 fix(pm): isolate bootstrap dependencies and unify YAML on ruamel
Activation reaches plugin discovery before the application dependencies
exist. Give PM its own locked Python project and runtime so it can install
or repair the application without importing that dependency tree.

Keep PM outside the application workspace. A shared uv workspace resolves
the application graph and cannot provide this isolation. Route mutations
through an isolated worker and preserve transaction callbacks, cancellation,
custom package registrations, and correlated receipts.

Use the same runtime builder for source installs and packaged payloads.
Keep offline wheelhouse support in that builder. Nix builds the independent
PM lock as a separate derivation. Refuse lazy-disabled bootstrap before
installing tools or dependencies.

Move first-party YAML readers and writers to ruamel. Keep the application
lock's transitive PyYAML requirements for third-party packages.

Verification:
- Focused canonical Python suite: 177 passed, 1 host-gated skip.
- Electron backend probes: 12 passed. Electron typecheck passed.
- Both uv locks, scoped lint, Bash syntax, and whitespace checks passed.
- Cold activation, corrupt-app repair, offline staging, and relocation ran.
- Built and exercised the Nix PM runtime and standalone YAML merge script.

Six broader caller test files retain the same 24 failing test IDs as an
archive of HEAD. The existing real-home guard blocks those tests before
they can exercise the affected paths. No full-suite pass is claimed.
Native Windows signing and full Bionic package execution remain unverified.
2026-09-11 12:23:51 -04:00

78 lines
2.4 KiB
Python

"""Cross-surface contract for the persistent /approvals mode command."""
from types import SimpleNamespace
from unittest.mock import MagicMock, patch
import hermes_yaml as yaml
from cli import HermesCLI
from hermes_cli.commands import GATEWAY_KNOWN_COMMANDS, SUBCOMMANDS, gateway_help_lines, resolve_command
from hermes_cli.commands_completion import SlashCommandCompleter
from hermes_cli.commands_platforms import telegram_bot_commands
from prompt_toolkit.completion import CompleteEvent
from prompt_toolkit.document import Document
def _completions(text: str) -> set[str]:
return {
item.text
for item in SlashCommandCompleter().get_completions(
Document(text=text), CompleteEvent(completion_requested=True)
)
}
def test_approvals_registry_drives_help_menu_and_autocomplete():
command = resolve_command("approvals")
assert command is not None
assert command.category == "Configuration"
assert command.args_hint == "[manual|smart|off]"
assert SUBCOMMANDS["/approvals"] == ["manual", "smart", "off"]
assert "approvals" in GATEWAY_KNOWN_COMMANDS
assert any("/approvals" in line for line in gateway_help_lines())
assert "approvals" in {name for name, _ in telegram_bot_commands()}
assert _completions("/approvals ") == {"manual", "smart", "off"}
def _isolate_config(monkeypatch, home):
monkeypatch.setenv("HERMES_HOME", str(home))
monkeypatch.setenv("HERMES_MANAGED_DIR", str(home / "missing-managed"))
from hermes_cli import managed_scope
from hermes_cli.config import _LOAD_CONFIG_CACHE, _RAW_CONFIG_CACHE
_LOAD_CONFIG_CACHE.clear()
_RAW_CONFIG_CACHE.clear()
managed_scope.invalidate_managed_cache()
def test_shared_command_refuses_managed_mode_override(tmp_path, monkeypatch):
from hermes_cli import managed_scope
from hermes_cli.approval_mode import run_approval_mode_command
home = tmp_path / "home"
managed = tmp_path / "managed"
home.mkdir()
managed.mkdir()
monkeypatch.setenv("HERMES_HOME", str(home))
monkeypatch.setenv("HERMES_MANAGED_DIR", str(managed))
(managed / "config.yaml").write_text("approvals:\n mode: manual\n", encoding="utf-8")
managed_scope.invalidate_managed_cache()
result = run_approval_mode_command("off")
assert result.ok is False
assert result.mode == "manual"
assert result.changed is False
assert "managed" in result.message.lower()
assert not (home / "config.yaml").exists()