fix(cli): use discovered class for channel login
This commit is contained in:
@@ -1009,7 +1009,7 @@ def channels_login(
|
|||||||
force: bool = typer.Option(False, "--force", "-f", help="Force re-authentication even if already logged in"),
|
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."""
|
"""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_all
|
||||||
from nanobot.config.loader import load_config
|
from nanobot.config.loader import load_config
|
||||||
|
|
||||||
config = load_config()
|
config = load_config()
|
||||||
@@ -1024,7 +1024,7 @@ def channels_login(
|
|||||||
|
|
||||||
console.print(f"{__logo__} {all_channels[channel_name].display_name} Login\n")
|
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)
|
channel = channel_cls(channel_cfg, bus=None)
|
||||||
|
|
||||||
success = asyncio.run(channel.login(force=force))
|
success = asyncio.run(channel.login(force=force))
|
||||||
|
|||||||
@@ -22,6 +22,10 @@ class _FakePlugin(BaseChannel):
|
|||||||
name = "fakeplugin"
|
name = "fakeplugin"
|
||||||
display_name = "Fake Plugin"
|
display_name = "Fake Plugin"
|
||||||
|
|
||||||
|
def __init__(self, config, bus):
|
||||||
|
super().__init__(config, bus)
|
||||||
|
self.login_calls: list[bool] = []
|
||||||
|
|
||||||
async def start(self) -> None:
|
async def start(self) -> None:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -31,6 +35,10 @@ class _FakePlugin(BaseChannel):
|
|||||||
async def send(self, msg: OutboundMessage) -> None:
|
async def send(self, msg: OutboundMessage) -> None:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
async def login(self, force: bool = False) -> bool:
|
||||||
|
self.login_calls.append(force)
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
class _FakeTelegram(BaseChannel):
|
class _FakeTelegram(BaseChannel):
|
||||||
"""Plugin that tries to shadow built-in telegram."""
|
"""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)
|
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.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_manager_skips_disabled_plugin():
|
async def test_manager_skips_disabled_plugin():
|
||||||
fake_config = SimpleNamespace(
|
fake_config = SimpleNamespace(
|
||||||
|
|||||||
Reference in New Issue
Block a user