summaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
authorChristophe Besson <cbesson@gmail.com>2026-09-06 17:58:27 +0200
committerChristophe Besson <cbesson@gmail.com>2026-09-06 17:58:27 +0200
commit4e6d6573003b06dd58268602d50a98988d4ce3d0 (patch)
tree70f31e0e7f069a8bf34bf5dae3bc902ce0e8e3ee /packages
parentea56b8c79538323875c00db2e7006b255f7cd494 (diff)
downloadmeshbay-4e6d6573003b06dd58268602d50a98988d4ce3d0.tar.gz
test(node): the backslash-path test modelled the wrong platform
It asserted `Path(win_dir).as_posix() == "C:/Users/alice/Media"`, which is only true where `Path` is a `WindowsPath`. On every other machine a backslash is an ordinary filename character, `as_posix()` converts nothing, and the test failed against correct code — so it has never passed on this suite's usual host, and never guarded anything there. `PureWindowsPath` names the flavour and makes it the same assertion on all three platforms. The round trip also only ever proved that `as_posix()` produces a parseable string, never that the config writer calls it — which is the defect, and one no Linux machine can reproduce: the file is written, parsed and served correctly here and fails on the operator's Windows box. A second test reads ops.py for every f-string landing on the right of a TOML `path =` and requires `as_posix()` in it. Weak evidence, and the only kind available for a platform the suite does not run on; checked to fail with the call removed. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011pvMdvLBG92jyhvD5pD6us
Diffstat (limited to 'packages')
-rw-r--r--packages/meshbay-node/tests/test_ops.py46
1 files changed, 40 insertions, 6 deletions
diff --git a/packages/meshbay-node/tests/test_ops.py b/packages/meshbay-node/tests/test_ops.py
index b3f0378..c118b5a 100644
--- a/packages/meshbay-node/tests/test_ops.py
+++ b/packages/meshbay-node/tests/test_ops.py
@@ -11,7 +11,7 @@ call them.
import asyncio
import inspect
-from pathlib import Path
+from pathlib import Path, PureWindowsPath
from types import SimpleNamespace
import pytest
@@ -359,13 +359,47 @@ def test_update_node_toml_forces_lf_and_keeps_standalone_comments(tmp_path):
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().
+ """
+ attach_group and add_root embed a directory into a TOML basic string. A raw
+ Windows path there is a parse error, because backslash sequences are escapes
+ (`\\U`, `\\a`, ...); the code writes `as_posix()` and pathlib reads `/` back
+ on Windows.
+
+ `PureWindowsPath`, not `Path`: on this suite's usual machine `Path` is a
+ `PosixPath`, where a backslash is an ordinary filename character and
+ `as_posix()` converts nothing — so the test modelled the wrong platform and
+ failed everywhere except the one it was written for. Naming the flavour
+ explicitly is what makes it the same assertion on all three.
+ """
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"
+
+ assert tomllib.loads(
+ f'path = "{PureWindowsPath(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
+
+
+def test_every_path_written_into_node_toml_goes_through_as_posix():
+ """
+ The half the round trip above cannot see.
+
+ Proving `as_posix()` produces a parseable string says nothing about whether
+ the code calls it, and this is a defect no Linux machine can reproduce: the
+ config is written, parsed and served correctly here, and fails on the
+ operator's Windows box. So the source is read for the shape instead —
+ weak evidence, and the only kind available for a platform the suite does
+ not run on.
+ """
+ import re
+ source = inspect.getsource(ops)
+ # Every f-string interpolation that lands on the right of a TOML `path =`.
+ writes = re.findall(r'path\s*=\s*\\?"\{([^}]+)\}', source)
+ assert writes, "no TOML path writer found — did the config writer move?"
+ for expr in writes:
+ assert "as_posix()" in expr, (
+ f'node.toml path written as `{expr}` — a Windows path needs '
+ f'as_posix(), or the file it lands in will not parse')