Your lightweight open-source personal agent.
Python agent-frameworkai-agentai-agentschatbotchatopsdiscord-botllm-agentsllmslocal-llmmcpmodel-context-protocolmulti-agentopenai-compatibleopenclawpersonal-ai-assistantpythonself-hostedtelegram-bot-ai-assistantwebuiworkflow-automation
fix(cli): use discovered class for channel login
Xubin Ren0ca639bf2299
diff --git a/nanobot/cli/commands.py b/nanobot/cli/commands.pyindex ff747b198..87b2bc553 100644--- a/nanobot/cli/commands.py+++ b/nanobot/cli/commands.py@@ -1009,7 +1009,7 @@ def channels_login(force: bool = typer.Option(False, "--force", "-f", help="Force re-authentication even if already logged in"),):"""Authenticate with a channel via QR code or other interactive login."""- from nanobot.channels.registry import discover_all, load_channel_class+ from nanobot.channels.registry import discover_allfrom nanobot.config.loader import load_configconfig = load_config()@@ -1024,7 +1024,7 @@ def channels_login(console.print(f"{__logo__} {all_channels[channel_name].display_name} Login\n")- channel_cls = load_channel_class(channel_name)+ channel_cls = all_channels[channel_name]channel = channel_cls(channel_cfg, bus=None)success = asyncio.run(channel.login(force=force))diff --git a/tests/test_channel_plugins.py b/tests/test_channel_plugins.pyindex e8a6d4993..3f34dc598 100644--- a/tests/test_channel_plugins.py+++ b/tests/test_channel_plugins.py@@ -22,6 +22,10 @@ class _FakePlugin(BaseChannel):name = "fakeplugin"display_name = "Fake Plugin"+ def __init__(self, config, bus):+ super().__init__(config, bus)+ self.login_calls: list[bool] = []+async def start(self) -> None:pass@@ -31,6 +35,10 @@ class _FakePlugin(BaseChannel):async def send(self, msg: OutboundMessage) -> None:pass+ async def login(self, force: bool = False) -> bool:+ self.login_calls.append(force)+ return True+class _FakeTelegram(BaseChannel):"""Plugin that tries to shadow built-in telegram."""@@ -183,6 +191,34 @@ async def test_manager_loads_plugin_from_dict_config():assert isinstance(mgr.channels["fakeplugin"], _FakePlugin)+def test_channels_login_uses_discovered_plugin_class(monkeypatch):+ from nanobot.cli.commands import app+ from nanobot.config.schema import Config+ from typer.testing import CliRunner++ runner = CliRunner()+ seen: dict[str, object] = {}++ class _LoginPlugin(_FakePlugin):+ display_name = "Login Plugin"++ async def login(self, force: bool = False) -> bool:+ seen["force"] = force+ seen["config"] = self.config+ return True++ monkeypatch.setattr("nanobot.config.loader.load_config", lambda: Config())+ monkeypatch.setattr(+ "nanobot.channels.registry.discover_all",+ lambda: {"fakeplugin": _LoginPlugin},+ )++ result = runner.invoke(app, ["channels", "login", "fakeplugin", "--force"])++ assert result.exit_code == 0+ assert seen["force"] is True++@pytest.mark.asyncioasync def test_manager_skips_disabled_plugin():fake_config = SimpleNamespace(