Skip to content

Windows: replace POSIX file-mode XDG_RUNTIME_DIR tests with NTFS-aware equivalents #637

@memtomem

Description

@memtomem

Background

The Windows + macOS CI matrix expansion (#634) skips three test classes
in `packages/memtomem/tests/test_runtime_paths.py` on Windows:

  • `TestRuntimeDir`
  • `TestEnsureRuntimeDir`
  • `TestServerPidPath`

These classes assume POSIX semantics that don't translate cleanly to
NTFS:

  • The shared `_make_safe_xdg` fixture does `os.chmod(xdg, 0o700)` to
    set up the XDG base. NTFS reports synthesized POSIX mode bits
    (typically `0o666` or `0o777`) that don't match `0o700`, so
    `_is_safe_dir` (which checks `S_IMODE(st.st_mode) & 0o077`) would
    reject the directory and the XDG branch silently falls through to the
    tempdir form — breaking the tests that assert the XDG path is used.
  • `TestEnsureRuntimeDir.test_creates_directory_with_owner_only_mode`
    asserts `S_IMODE(d.stat().st_mode) == 0o700`, which is POSIX-only.
  • `TestEnsureRuntimeDir.test_explicit_chmod_survives_wild_umask` uses
    `os.umask(0o177)`, which Windows ignores.
  • `TestEnsureRuntimeDir.test_refuses_existing_loose_mode` depends on
    the `0o755` vs `0o700` distinction.

The runtime code itself
(`packages/memtomem/src/memtomem/_runtime_paths.py`) already has a
Windows-aware path through `tempfile.gettempdir()` + `uid=0` (the
`os.geteuid()` calls are `hasattr`-guarded), but its behavior on
NTFS is unverified
today — that's what this issue tracks.

Scope

  1. Verify `runtime_dir()` and `ensure_runtime_dir()` behave correctly
    on Windows: pid file lands at `%LOCALAPPDATA%\Temp\memtomem-0`
    (or whatever `tempfile.gettempdir()` returns), `ensure_runtime_dir()`
    doesn't raise on a fresh runner, and validation doesn't no-op away
    the security guarantees we care about.
  2. Decide the NTFS security contract. Options:
    • Relax `_is_safe_dir` on Windows (accept the kernel default).
    • Use `os.access(path, os.W_OK)` + owner-SID checks via stdlib
      `os.stat()` + `stat.FILE_ATTRIBUTE_*` (or `pywin32` if needed).
    • Document Windows as best-effort and skip mode-bit validation.
  3. Either rewrite the three skipped classes to be Windows-aware, or
    add a separate `TestRuntimeDir{Windows,Posix}` split with native
    assertions per platform.

Out of scope: changing the runtime code's POSIX contract. The pid-file
location and ownership semantics on Windows are an open design
question that this issue should decide before relaxing anything.

References

  • ci: add Windows runner to CI matrix #634 — Windows + macOS CI matrix expansion
  • `packages/memtomem/src/memtomem/_runtime_paths.py:63-145` — runtime
    resolver + `ensure_runtime_dir`
  • `packages/memtomem/tests/test_runtime_paths.py` — three test classes
    currently skipped on Windows

🤖 Generated with Claude Code

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions