From 6e9afe3e54ab6fb0162393150b7892655b4561d4 Mon Sep 17 00:00:00 2001 From: Christophe Besson Date: Thu, 24 Sep 2026 18:19:13 +0200 Subject: refactor(node): move the CLI out of daemon.py into cli/ Each `if args.command == ...` branch of main() becomes a function in cli/ (one module per family of verbs); the parser, the process setup and a VERBS table go to cli/parser.py and cli/dispatch.py. daemon.main runs the verb or starts the daemon. Tests patch the CLI through conftest.patch_cli; the CLI golden is unchanged. Co-Authored-By: Claude Opus 5.5 --- packages/meshbay-node/tests/conftest.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'packages/meshbay-node/tests/conftest.py') diff --git a/packages/meshbay-node/tests/conftest.py b/packages/meshbay-node/tests/conftest.py index 2ca0c8a..9ef23a3 100644 --- a/packages/meshbay-node/tests/conftest.py +++ b/packages/meshbay-node/tests/conftest.py @@ -92,3 +92,26 @@ def opened_ack(session, msg: dict) -> dict: ctx = session._group_ctx() return file_upload_ack_payload(ctx["gek"], session._group_id or "", msg) + + +def patch_cli(monkeypatch, name: str, value) -> None: + """Replace `name` wherever `meshbay-node`'s command line reads it. + + Each module of `meshbay_node.cli` imports what it uses by name, so a helper + like `_daemon_api` is bound once in every module that calls it, and patching + the one that defines it leaves the verbs calling the real thing — which + talks to whatever node is running on this machine. `daemon` is included: + its `main()` still reads the config path when no verb is given. + """ + import importlib + import pkgutil + + import meshbay_node.cli as cli + from meshbay_node import daemon + + modules = [daemon] + [importlib.import_module(f"meshbay_node.cli.{m.name}") + for m in pkgutil.iter_modules(cli.__path__)] + holders = [m for m in modules if hasattr(m, name)] + assert holders, f"no module of the CLI has {name!r} to patch" + for module in holders: + monkeypatch.setattr(module, name, value) -- cgit v1.2.3