mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-06-11 08:42:11 +00:00
Follow-on to the cron extraction in the same Phase 2 PR. Same pattern: per-group build_<name>_parser() functions with injected handlers, no main import. - subcommands/profile.py: build_profile_parser (190-line block out of main()). - subcommands/gateway.py: build_gateway_parser (gateway + proxy, 238-line block; they shared one inline section). Imports argparse for SUPPRESS defaults. - main(): two more inline blocks become single builder calls. Behavior-neutral: 'profile [sub] --help' and 'gateway/proxy [sub] --help' byte-identical to pre-extraction (diff-verified). main() now 2723 LOC (was 3297 at Phase 2 start); add_parser calls in main.py 179 -> 141. Validation: tests/hermes_cli/ 6476 passed / 0 failed under per-file process isolation; new builder unit tests cover subactions, aliases, dispatch, flags.
83 lines
2.3 KiB
Python
83 lines
2.3 KiB
Python
"""Unit tests for extracted subcommand parser builders (profile, gateway).
|
|
|
|
Confirms the builders attach the same subactions and ``func=`` dispatch that
|
|
lived inline in ``main()`` before the god-file Phase 2 extraction.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
|
|
from hermes_cli.subcommands.gateway import build_gateway_parser
|
|
from hermes_cli.subcommands.profile import build_profile_parser
|
|
|
|
|
|
def _h_gateway(args): # pragma: no cover - identity only
|
|
return "gateway"
|
|
|
|
|
|
def _h_proxy(args): # pragma: no cover - identity only
|
|
return "proxy"
|
|
|
|
|
|
def _h_profile(args): # pragma: no cover - identity only
|
|
return "profile"
|
|
|
|
|
|
def _profile_parser():
|
|
p = argparse.ArgumentParser(prog="hermes")
|
|
sub = p.add_subparsers(dest="command")
|
|
build_profile_parser(sub, cmd_profile=_h_profile)
|
|
return p
|
|
|
|
|
|
def _gateway_parser():
|
|
p = argparse.ArgumentParser(prog="hermes")
|
|
sub = p.add_subparsers(dest="command")
|
|
build_gateway_parser(sub, cmd_gateway=_h_gateway, cmd_proxy=_h_proxy)
|
|
return p
|
|
|
|
|
|
def test_profile_subactions_and_dispatch():
|
|
p = _profile_parser()
|
|
ns = p.parse_args(["profile", "list"])
|
|
assert ns.command == "profile"
|
|
assert ns.profile_action == "list"
|
|
assert ns.func is _h_profile
|
|
# a representative arg-taking subaction
|
|
ns2 = p.parse_args(["profile", "show", "work"])
|
|
assert ns2.profile_action == "show"
|
|
|
|
|
|
def test_profile_has_expected_actions():
|
|
p = _profile_parser()
|
|
# Map each subaction to a minimal valid argv suffix.
|
|
cases = {
|
|
"list": [],
|
|
"use": ["work"],
|
|
"create": ["work"],
|
|
"delete": ["work"],
|
|
"show": ["work"],
|
|
"rename": ["old", "new"],
|
|
"export": ["work"],
|
|
"import": ["/tmp/x.zip"],
|
|
}
|
|
for action, extra in cases.items():
|
|
ns = p.parse_args(["profile", action, *extra])
|
|
assert ns.profile_action == action
|
|
|
|
|
|
def test_gateway_and_proxy_dispatch():
|
|
p = _gateway_parser()
|
|
gw = p.parse_args(["gateway", "run"])
|
|
assert gw.command == "gateway"
|
|
assert gw.func is _h_gateway
|
|
px = p.parse_args(["proxy"])
|
|
assert px.command == "proxy"
|
|
assert px.func is _h_proxy
|
|
|
|
|
|
def test_gateway_accept_hooks_flag():
|
|
p = _gateway_parser()
|
|
ns = p.parse_args(["gateway", "run", "--accept-hooks"])
|
|
assert ns.accept_hooks is True
|