aboutsummaryrefslogtreecommitdiffstats
path: root/packages/meshbay-node/tests/test_ops.py
diff options
context:
space:
mode:
Diffstat (limited to 'packages/meshbay-node/tests/test_ops.py')
-rw-r--r--packages/meshbay-node/tests/test_ops.py42
1 files changed, 40 insertions, 2 deletions
diff --git a/packages/meshbay-node/tests/test_ops.py b/packages/meshbay-node/tests/test_ops.py
index 83758ae..92e32bf 100644
--- a/packages/meshbay-node/tests/test_ops.py
+++ b/packages/meshbay-node/tests/test_ops.py
@@ -15,12 +15,11 @@ from pathlib import Path
import pytest
from cryptography.hazmat.primitives.asymmetric.ed25519 import Ed25519PrivateKey
-
-from conftest import one_root
from meshbay_node import ops
from meshbay_node.indexer.group_index import GroupIndex
from meshbay_node.transport.quic_server import Denylist
+from conftest import one_root
def _state(tmp_path: Path) -> dict:
@@ -251,3 +250,42 @@ async def test_start_reload_without_fn_is_refused(tmp_path):
state = _state(tmp_path)
with pytest.raises(ops.OpError, match="Reload not available"):
await ops.start_reload(state)
+
+
+# ── node.toml editing survives Windows (LF, comments, backslash paths) ────────
+
+def test_update_node_toml_forces_lf_and_keeps_standalone_comments(tmp_path):
+ p = tmp_path / "node.toml"
+ p.write_bytes("\r\n".join([
+ "[hub]", 'url = "http://x"', "",
+ "[node]",
+ "# how long an invitation lives",
+ "invite_ttl_hours = 168",
+ "ui_port = 18000",
+ "",
+ "[[groups]]", 'id = "g1"',
+ ]).encode())
+
+ ops._update_node_toml(p, {"invite_ttl_hours": 24, "max_concurrent_streams": 4})
+
+ raw = p.read_bytes()
+ assert b"\r\n" not in raw, "must be rewritten LF-only, whatever it was read as"
+ text = raw.decode("utf-8")
+ assert "# how long an invitation lives" in text
+ import tomllib
+ node = tomllib.loads(text)["node"]
+ assert node["invite_ttl_hours"] == 24
+ assert node["max_concurrent_streams"] == 4
+
+
+def test_a_backslash_path_written_into_node_toml_stays_parseable():
+ # attach_group / add_root / init embed a directory into a TOML basic string.
+ # A raw Windows path there (drive + backslash + "Users" + ...) is a parse
+ # error since backslash sequences are escapes; the code writes as_posix().
+ import tomllib
+ bs = chr(92)
+ win_dir = f"C:{bs}Users{bs}alice{bs}Media"
+ assert tomllib.loads(f'path = "{Path(win_dir).as_posix()}"\n')["path"] == \
+ "C:/Users/alice/Media"
+ with pytest.raises(tomllib.TOMLDecodeError):
+ tomllib.loads(f'path = "{win_dir}"\n') # the bug this guards against