Bug
tests/hermes_cli/test_gateway_service.py::TestEnsureUserSystemdEnv::test_sets_xdg_runtime_dir_when_missing fails on Python 3.12 / WSL2.
Root Cause
The test uses a FakePath subclass to redirect /run/user/42 to a temp directory:
class FakePath(type(RealPath())):
def __new__(cls, *args):
if p == "/run/user/42":
return RealPath.__new__(cls, str(tmp_path))
In Python 3.12, PosixPath.__new__ ignores the path argument passed to RealPath.__new__ and re-initializes the internal path from the original string. So FakePath("/run/user/42").exists() returns False instead of True, and XDG_RUNTIME_DIR is never set.
Fix
Replace FakePath subclass with a direct monkeypatch on Path.exists:
monkeypatch.setattr(gateway_cli.Path, "exists", lambda self: str(self) == "/run/user/42")
This patches the method directly on the class used by the module under test, avoiding the Python 3.12 __new__ behavior entirely.
Evidence
FAILED tests/hermes_cli/test_gateway_service.py::TestEnsureUserSystemdEnv::test_sets_xdg_runtime_dir_when_missing
AssertionError: assert None == '/run/user/42'
Bug
tests/hermes_cli/test_gateway_service.py::TestEnsureUserSystemdEnv::test_sets_xdg_runtime_dir_when_missingfails on Python 3.12 / WSL2.Root Cause
The test uses a
FakePathsubclass to redirect/run/user/42to a temp directory:In Python 3.12,
PosixPath.__new__ignores the path argument passed toRealPath.__new__and re-initializes the internal path from the original string. SoFakePath("/run/user/42").exists()returnsFalseinstead ofTrue, andXDG_RUNTIME_DIRis never set.Fix
Replace
FakePathsubclass with a directmonkeypatchonPath.exists:This patches the method directly on the class used by the module under test, avoiding the Python 3.12
__new__behavior entirely.Evidence