diff options
| author | Christophe Besson <cbesson@gmail.com> | 2026-09-24 18:19:13 +0200 |
|---|---|---|
| committer | Christophe Besson <cbesson@gmail.com> | 2026-09-24 18:19:13 +0200 |
| commit | 6e9afe3e54ab6fb0162393150b7892655b4561d4 (patch) | |
| tree | f1cf20d891bf0d75dd206953bcec781f47ab7b15 /packages/meshbay-node/tests/test_cli_dispatch.py | |
| parent | a408a25af7b91abf729ec5fac7e5506437a86049 (diff) | |
| download | meshbay-6e9afe3e54ab6fb0162393150b7892655b4561d4.tar.gz | |
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 <noreply@anthropic.com>
Diffstat (limited to 'packages/meshbay-node/tests/test_cli_dispatch.py')
| -rw-r--r-- | packages/meshbay-node/tests/test_cli_dispatch.py | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/packages/meshbay-node/tests/test_cli_dispatch.py b/packages/meshbay-node/tests/test_cli_dispatch.py index 26ffb05..5b16fbe 100644 --- a/packages/meshbay-node/tests/test_cli_dispatch.py +++ b/packages/meshbay-node/tests/test_cli_dispatch.py @@ -20,6 +20,8 @@ import pytest from meshbay_node import daemon as daemon_mod from node_source import cli_source +from conftest import patch_cli + # Each verb, with the arguments that reach its branch. `--yes` where the command # would otherwise stop for a confirmation nobody can type in a test. VERBS = [ @@ -107,12 +109,12 @@ def stub_daemon(monkeypatch, tmp_path): "encrypted_messages": 0, "max_age_days": 30, } - monkeypatch.setattr(daemon_mod, "_daemon_api", fake_api) - monkeypatch.setattr(daemon_mod, "_resolve_group", lambda cfg, g: "g" * 32) + patch_cli(monkeypatch, "_daemon_api", fake_api) + patch_cli(monkeypatch, "_resolve_group", lambda cfg, g: "g" * 32) conf = tmp_path / "node.toml" conf.write_text('[hub]\nurl = "https://example.invalid"\n') - monkeypatch.setattr(daemon_mod, "DEFAULT_CONFIG_PATH", conf) + patch_cli(monkeypatch, "DEFAULT_CONFIG_PATH", conf) # And a home of its own: the data directory (where `member invite` and # `operator pair` write their code, where `status` finds the run token of # a live node) and the keystore's default path are both derived from it. @@ -192,6 +194,19 @@ def test_the_verb_list_here_matches_the_parser(monkeypatch, capsys): assert "ui" not in declared, "the `ui` verb came back" +def test_every_verb_the_parser_accepts_runs_something(): + """ + A verb the parser accepts and the dispatch table does not name would not + fail: `run()` would report nothing to run, and `main()` would go on and + start the daemon. + """ + from meshbay_node.cli.dispatch import VERBS + from meshbay_node.cli.parser import build_parser + + command = next(a for a in build_parser()._actions if a.dest == "command") + assert set(command.choices) == set(VERBS) + + @pytest.mark.skipif(sys.platform == "win32", reason="systemd lifecycle; Windows uses the loopback API / " "Startup-folder launcher, covered by test_platform.py") |