Files
meshcore-bot/tests/unit/test_help_text_signature.py
agessaman 7aba432b54 refactor(commands): every bundled get_help_text takes message=None
S4. BaseCommand and the 40 bundled overrides that took no argument now take `message: MeshMessage | None = None`, matching joke and rain, which already use the message. None of the 40 bodies read it, so their help text is unchanged. help and command_manager keep their TypeError retry, since local plugins may still implement get_help_text(self). For bundled commands the retry no longer runs: `help <command>` calls get_help_text(message) once instead of failing and calling it again. A new test pins the signature for every bundled command class. The offline smoke run against the real config produces the same help text for all 46 commands.
2026-10-03 22:28:45 -07:00

36 lines
1.2 KiB
Python

"""Every bundled command takes ``get_help_text(message=None)``.
help and command_manager still retry without the message when a command's
get_help_text takes none (local plugins may be written that way), but bundled
commands use the one signature.
"""
import importlib
import inspect
import pkgutil
import modules.commands
import modules.commands.alternatives
from modules.commands.base_command import BaseCommand
def _bundled_command_classes():
for package in (modules.commands, modules.commands.alternatives):
for info in pkgutil.iter_modules(package.__path__):
module = importlib.import_module(f"{package.__name__}.{info.name}")
for _, cls in inspect.getmembers(module, inspect.isclass):
if issubclass(cls, BaseCommand) and cls.__module__ == module.__name__:
yield cls
def test_every_bundled_get_help_text_takes_an_optional_message():
classes = list(_bundled_command_classes())
assert len(classes) > 40
wrong = []
for cls in classes:
params = inspect.signature(cls.get_help_text).parameters
message = params.get("message")
if message is None or message.default is not None:
wrong.append(cls.__name__)
assert wrong == []