aboutsummaryrefslogtreecommitdiffstats
path: root/packages/meshbay-cli/tests/test_completion.py
diff options
context:
space:
mode:
authorChristophe Besson <cbesson@gmail.com>2026-10-15 12:32:24 +0200
committerChristophe Besson <cbesson@gmail.com>2026-10-15 12:32:24 +0200
commit988a0eecd522431980174910db28e45a63ff2710 (patch)
tree80b16f8cfe907f084fac931fa35326c7f2892a9d /packages/meshbay-cli/tests/test_completion.py
parente0a1036e0fee15b3c6c83f3e935d50f472a2e776 (diff)
downloadmeshbay-988a0eecd522431980174910db28e45a63ff2710.tar.gz
feat(cli): account, rm -r and mkdir, Tab completion
account shows the account and does what the sign-up form and the Profile page do: register (the passphrase floor and the hub's proof of work checked here, the recovery key printed once), verify, change the passphrase, reset a forgotten one, change the e-mail address, sign out everywhere, delete. A new passphrase carries the copy of the account's keys each node keeps for browsers first — opened under the old M, the same keys sealed under the new one — and only then tells the hub; a refusal sets the copies back. A reset restores them from the recovery copy. The connections that do it never make keys nor ask for a device approval. This machine keeps the M it changed away from, so a node out of reach is carried at its next connection; a copy under an M it does not know is no longer rewritten, which locked the browsers out after a passphrase changed elsewhere. rm -r removes a folder and all it holds, from the node's operator key: the files, then the folders deepest first, one confirmation that counts them. mkdir makes folders, --parents the missing ones (not -p, the passphrase). completion bash|powershell prints the script that makes Tab complete actions, verbs, options and the paths of the groups this machine is signed in to, cached two minutes; the deb and rpm packages install the bash one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'packages/meshbay-cli/tests/test_completion.py')
-rw-r--r--packages/meshbay-cli/tests/test_completion.py92
1 files changed, 92 insertions, 0 deletions
diff --git a/packages/meshbay-cli/tests/test_completion.py b/packages/meshbay-cli/tests/test_completion.py
new file mode 100644
index 0000000..1222dc2
--- /dev/null
+++ b/packages/meshbay-cli/tests/test_completion.py
@@ -0,0 +1,92 @@
+"""
+Tab completion's candidates: from the parser for actions, verbs and options,
+from the hub and the node for remote paths — never a question, never an error.
+"""
+
+import pytest
+from fake_hub import PASSPHRASE, USERNAME, FakeHub
+from fake_node import FakeNode
+from meshbay_cli import __main__ as cli
+from meshbay_cli import complete
+from meshbay_cli.client import hub as hub_module
+from meshbay_cli.client import session as session_module
+from meshbay_cli.commands import context
+
+
+def _c(*words, shell="bash"):
+ return complete.candidates(shell, len(words), ["meshbay-cli", *words])
+
+
+def test_actions_verbs_options_and_choices_come_from_the_parser():
+ assert "account" in _c("") and "mkdir" in _c("") and "completion" in _c("")
+ assert _c("ac") == ["account"]
+ assert _c("account", "") == ["show", "register", "verify", "passphrase", "reset",
+ "email", "sign-out-everywhere", "delete"]
+ assert _c("account", "pa") == ["passphrase"]
+ assert _c("devices", "a") == ["approve"]
+ assert _c("browser-access", "") == ["on", "off"]
+ assert _c("completion", "") == ["bash", "powershell"]
+ assert _c("help", "mk") == ["mkdir"]
+ assert "--parents" in _c("mkdir", "--") and "--yes" in _c("rm", "--")
+ assert _c("ls", "--sort", "") == ["name", "size", "date"]
+ # A value, then the slots go on: `get -o DIR PATH`.
+ assert _c("get", "-o", "") == [complete.FILES]
+ assert _c("--hub", "https://x", "ac") == ["account"]
+
+
+@pytest.mark.parametrize("typed, shell, plain", [
+ ("Some\\ Saga", "bash", "Some Saga"),
+ ("'Some Saga", "bash", "Some Saga"),
+ ('"Some Saga"', "bash", "Some Saga"),
+ ("'it''s'", "powershell", "it's"),
+ ("C:\\Users\\x", "powershell", "C:\\Users\\x"),
+])
+def test_quoting_is_taken_off_as_each_shell_wrote_it(typed, shell, plain):
+ assert complete.unquote(typed, shell) == plain
+
+
+def test_nothing_signed_in_gives_no_candidate_and_no_error(capsys):
+ assert cli.main(["__complete", "bash", "2", "meshbay-cli", "ls", "Fam"]) == 0
+ out = capsys.readouterr()
+ assert out.out == "" and out.err == ""
+ assert cli.main(["__complete", "garbage"]) == 0
+
+
+@pytest.fixture
+def world(monkeypatch):
+ hub, node = FakeHub(), FakeNode()
+ node.add("share/2024/été", "plage.jpg", b"x")
+ node.add("share", "notes.txt", b"n")
+ monkeypatch.setattr(context, "Hub", lambda url: hub)
+ monkeypatch.setattr(hub_module, "Hub", lambda url: hub)
+
+ async def group_nodes(token, gid):
+ return [{"node_id": "node-1", "pk_node": "pk"}]
+ hub.group_nodes = group_nodes
+ opened = []
+
+ async def connect(account, gid, node_row, join_code=None, *, rewrap=None):
+ assert rewrap is not None, "completion must never make keys"
+ opened.append(gid)
+ return node.session()
+ monkeypatch.setattr(session_module, "connect", connect)
+ assert cli.main(["--hub", hub.url, "-u", USERNAME, "--password", PASSPHRASE,
+ "login"]) == 0
+ return opened
+
+
+def test_remote_paths_from_the_hub_and_the_node(world, capsys):
+ capsys.readouterr()
+ assert _c("ls", "fa") == ["Family@alice-test/"]
+ assert _c("ls", "Family@alice-test/") == ["Family@alice-test/share/"]
+ assert _c("get", "Family@alice-test/share/") == [
+ "Family@alice-test/share/2024/", "Family@alice-test/share/notes.txt"]
+ assert _c("get", "Family@alice-test/share/2024/é") == [
+ "Family@alice-test/share/2024/été/"]
+ assert _c("mkdir", "Family@alice-test/share/") == ["Family@alice-test/share/2024/"]
+ assert _c("chat", "F") == ["Family@alice-test"]
+ assert _c("put", "x", "Family@alice-test/sh") == [complete.FILES,
+ "Family@alice-test/share/"]
+ assert _c("ls", "Nope/") == []
+ # The node was asked once; the next Tabs read what it said.
+ assert world == ["g1"]