Skip to content
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions tests/hermes_cli/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,32 @@ def test_every_command_has_nonempty_description(self):
for cmd, desc in COMMANDS.items():
assert isinstance(desc, str) and len(desc) > 0, f"{cmd} has empty description"

def test_every_cli_command_has_dispatch_handler(self):
"""Every non-gateway_only CommandDef must have a handler branch in
process_command(). When this fails, a command is showing up in help
and autocomplete but returning "Unknown command" at runtime.

See #22960, #27603, #50618 for prior instances of this bug class.
"""
import inspect
import re

from cli import HermesCLI

src = inspect.getsource(HermesCLI.process_command)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inspect.getsource() makes this a source-shape test, which AGENTS.md:1380-1384 explicitly bans. Please test an executable dispatch contract instead; extract a small resolver/dispatch seam if the current method is too large to exercise directly.

# Canonical forms: elif canonical == "foo": / if canonical in {"foo", "bar"}:
dispatched = set(re.findall(r'canonical\s*(?:==|in\s+\{)\s*"([^"]+)"', src))
dispatched.update(re.findall(r"canonical\s*(?:==|in\s+\{)\s*'([^']+)'", src))

registry_cli = {cmd.name for cmd in COMMAND_REGISTRY if not cmd.gateway_only}
missing = registry_cli - dispatched

assert not missing, (
f"commands in COMMAND_REGISTRY with no dispatch handler: {sorted(missing)}. "
"Add an `elif canonical == \"<name>\":` branch to HermesCLI.process_command() "
"in cli.py, or mark the command gateway_only=True if it is not meant for CLI."
)


# ---------------------------------------------------------------------------
# Gateway helpers
Expand Down