Files
mistral-vibe/tests/cli/test_commands.py
Clément Sirieix 04305bd77c v2.8.0 (#616)
Co-authored-by: Kim-Adeline Miguel <51720070+kimadeline@users.noreply.github.com>
Co-authored-by: Mathias Gesbert <mathias.gesbert@mistral.ai>
Co-authored-by: Michel Thomazo <51709227+michelTho@users.noreply.github.com>
Co-authored-by: Pierre Rossinès <pierre.rossines@mistral.ai>
Co-authored-by: Mistral Vibe <vibe@mistral.ai>
2026-04-21 15:19:59 +02:00

92 lines
4.0 KiB
Python

from __future__ import annotations
from vibe.cli.commands import Command, CommandRegistry
class TestCommandRegistry:
def test_get_command_name_returns_canonical_name_for_alias(self) -> None:
registry = CommandRegistry()
assert registry.get_command_name("/help") == "help"
assert registry.get_command_name("/config") == "config"
assert registry.get_command_name("/model") == "model"
assert registry.get_command_name("/connectors") == "mcp"
assert registry.get_command_name("/clear") == "clear"
assert registry.get_command_name("/exit") == "exit"
assert registry.get_command_name("/data-retention") == "data-retention"
def test_get_command_name_normalizes_input(self) -> None:
registry = CommandRegistry()
assert registry.get_command_name(" /help ") == "help"
assert registry.get_command_name("/HELP") == "help"
def test_get_command_name_returns_none_for_unknown(self) -> None:
registry = CommandRegistry()
assert registry.get_command_name("/unknown") is None
assert registry.get_command_name("hello") is None
assert registry.get_command_name("") is None
def test_parse_command_returns_command_when_alias_matches(self) -> None:
registry = CommandRegistry()
result = registry.parse_command("/help")
assert result is not None
cmd_name, cmd, cmd_args = result
assert cmd_name == "help"
assert cmd.handler == "_show_help"
assert isinstance(cmd, Command)
assert cmd_args == ""
def test_parse_command_returns_none_when_no_match(self) -> None:
registry = CommandRegistry()
assert registry.parse_command("/nonexistent") is None
def test_parse_command_uses_get_command_name(self) -> None:
"""parse_command and get_command_name stay in sync for same input."""
registry = CommandRegistry()
for alias in ["/help", "/config", "/clear", "/exit"]:
cmd_name = registry.get_command_name(alias)
result = registry.parse_command(alias)
if cmd_name is None:
assert result is None
else:
assert result is not None
found_name, found_cmd, _ = result
assert found_name == cmd_name
assert registry.commands[cmd_name] is found_cmd
def test_excluded_commands_not_in_registry(self) -> None:
registry = CommandRegistry(excluded_commands=["exit"])
assert registry.get_command_name("/exit") is None
assert registry.parse_command("/exit") is None
assert registry.get_command_name("/help") == "help"
def test_resume_command_registration(self) -> None:
registry = CommandRegistry()
assert registry.get_command_name("/resume") == "resume"
assert registry.get_command_name("/continue") == "resume"
result = registry.parse_command("/resume")
assert result is not None
_, cmd, _ = result
assert cmd.handler == "_show_session_picker"
def test_parse_command_keeps_args_for_no_arg_commands(self) -> None:
registry = CommandRegistry()
result = registry.parse_command("/help extra")
assert result == ("help", registry.commands["help"], "extra")
def test_parse_command_keeps_args_for_argument_commands(self) -> None:
registry = CommandRegistry()
result = registry.parse_command("/mcp filesystem")
assert result == ("mcp", registry.commands["mcp"], "filesystem")
def test_parse_command_maps_connector_alias_to_mcp(self) -> None:
registry = CommandRegistry()
result = registry.parse_command("/connectors filesystem")
assert result == ("mcp", registry.commands["mcp"], "filesystem")
def test_data_retention_command_registration(self) -> None:
registry = CommandRegistry()
result = registry.parse_command("/data-retention")
assert result is not None
_, cmd, _ = result
assert cmd.handler == "_show_data_retention"