aboutsummaryrefslogtreecommitdiffstats
path: root/packages/meshbay-node/tests/test_cli_golden.py
diff options
context:
space:
mode:
Diffstat (limited to 'packages/meshbay-node/tests/test_cli_golden.py')
-rw-r--r--packages/meshbay-node/tests/test_cli_golden.py22
1 files changed, 20 insertions, 2 deletions
diff --git a/packages/meshbay-node/tests/test_cli_golden.py b/packages/meshbay-node/tests/test_cli_golden.py
index 3d7b0c0..5fe3f0b 100644
--- a/packages/meshbay-node/tests/test_cli_golden.py
+++ b/packages/meshbay-node/tests/test_cli_golden.py
@@ -18,11 +18,13 @@ import builtins
import getpass
import json
import os
+import re
import subprocess
import sys
from pathlib import Path
import pytest
+from meshbay_common import MNP_VERSION
from meshbay_node import config as config_mod
from meshbay_node import daemon as daemon_mod
from test_cli_dispatch import VERBS
@@ -77,7 +79,7 @@ def _run(argv: list[str], tmp_path: Path, capsys) -> dict:
return subprocess.CompletedProcess(args, 0, stdout="", stderr="")
conf = tmp_path / "node.toml"
- conf.write_text('[hub]\nurl = "https://example.invalid"\n')
+ conf.write_text('[hub]\nurl = "https://example.invalid"\n', encoding="utf-8")
code = 0
with pytest.MonkeyPatch.context() as mp:
patch_cli(mp, "_daemon_api", fake_api)
@@ -86,6 +88,9 @@ def _run(argv: list[str], tmp_path: Path, capsys) -> dict:
# The data directory and the keystore's default path come from these;
# left real, `status` would record the developer's own node.
mp.setenv("HOME", str(tmp_path / "home"))
+ # Path.home() on Windows: without it `member invite` and `operator
+ # pair` wrote their codes into the developer's own profile.
+ mp.setenv("USERPROFILE", str(tmp_path / "home"))
mp.setattr(config_mod, "DEFAULT_CONFIG_PATH", conf)
mp.setattr(builtins, "input", fake_input)
mp.setattr(getpass, "getpass", lambda *a, **kw: "test-password")
@@ -93,6 +98,9 @@ def _run(argv: list[str], tmp_path: Path, capsys) -> dict:
# argparse wraps the help to the terminal's width.
mp.setenv("COLUMNS", "100")
mp.setattr(sys, "argv", ["meshbay-node", *argv])
+ # Recorded on Linux: `autostart`/`service` are Windows-only there, and
+ # their Windows side is test_platform.py's and test_packaging_win.py's.
+ mp.setattr(sys, "platform", "linux")
try:
daemon_mod.main()
except SystemExit as e:
@@ -100,7 +108,17 @@ def _run(argv: list[str], tmp_path: Path, capsys) -> dict:
out = capsys.readouterr()
def mask(text: str) -> str:
- return text.replace(str(tmp_path), "<tmp>")
+ # Masked in the JSON text, where a Windows path's backslashes are
+ # doubled -- the unescaped form never matched there -- and spelled the
+ # POSIX way after it. The protocol version is not the CLI's shape: it
+ # left this recording failing everywhere from the MNP 4.0 bump on.
+ text = text.replace(json.dumps(str(tmp_path))[1:-1], "<tmp>")
+ text = re.sub(r'<tmp>(?:\\\\[^\\\s"]+)+',
+ lambda m: m.group(0).replace("\\\\", "/"), text)
+ # argparse quotes its choices on some Python versions and not others.
+ text = re.sub(r"\(choose from [^)]*\)",
+ lambda m: m.group(0).replace("'", ""), text)
+ return text.replace(f"MNP {MNP_VERSION}", "MNP <version>")
return json.loads(mask(json.dumps({
"exit": code, "stdout": out.out, "stderr": out.err,