Skip to content

test(windows): make test_init_cmd.py Windows-compatible (#643)#724

Merged
memtomem merged 1 commit intomainfrom
test/win-init-cmd-compat
May 2, 2026
Merged

test(windows): make test_init_cmd.py Windows-compatible (#643)#724
memtomem merged 1 commit intomainfrom
test/win-init-cmd-compat

Conversation

@memtomem
Copy link
Copy Markdown
Owner

@memtomem memtomem commented May 2, 2026

Summary

Cluster G of the #643 Windows sweep — 3 fixes in test_init_cmd.py, all making the test suite Windows-compatible without touching production. Bundled because they share the same axis (test_init_cmd.py Windows compat) and follow PR #713 / #714's "bundle by mechanism class" pattern.

# Test / helper Fix Root cause
1 test_project_install_profile_no_packages_dir skipif(win32) Monkeypatches sys.executable = "/usr/local/bin/python"; on Windows Path() normalizes that to backslashes, defeating production's startswith("/usr/local/bin/") check
2 test_origin_system_paths skipif(win32) Iterates hardcoded POSIX paths (/usr/bin/, /opt/homebrew/, etc.); none exist on Windows
3 _write_md helper newline="" on write_text Path.write_text translates \n\r\n by default on Windows; the dependent test asserts an exact byte count, failing 113 == 112

Why skipif (not rewrite for Windows) for #1 and #2

The classifier under test (_detect_mm_binary_origin) is a heuristic that tags well-known POSIX system Python locations. There is no canonical Windows analog (C:\Python313\python.exe? py.exe? WindowsApps\PythonSoftwareFoundation.Python.3.13...\python.exe?), so a "Windows system paths" rewrite would need a separate design call and is out of scope for this mechanical sweep.

Why production stays untouched

  • _detect_mm_binary_origin is correct on POSIX and intentionally permissive on Windows (returns unknown, which the wizard treats like uv-tool — see the docstring at init_cmd.py:230-251).
  • _collect_seed_scale reads raw byte counts via os.stat — already correct cross-platform.

Test plan

  • macOS: uv run pytest packages/memtomem/tests/test_init_cmd.py262/262 pass.
  • Lint: ruff check + ruff format --check clean.
  • Windows CI: 2 tests skip cleanly, 1 test passes via the fixed helper.

Out of scope

The remaining 23 Windows failures cluster into A (dirty state, 9 tests), C (claude-projects scope, 2), E (tilde expansion, 1), H (misc, 2). Cluster B (memory_dir prefix, 9) intentionally skipped — parallel work in flight on fix/647-windows-memory-dir-prefix and fix/720-source-filter-windows.

🤖 Generated with Claude Code

Cluster G of the #643 sweep — 3 fixes in one file, all making the test
suite Windows-compatible without touching production:

1) `test_project_install_profile_no_packages_dir` — skipif(win32). The
   test monkeypatches `sys.executable` to `"/usr/local/bin/python"` and
   then expects `mm_binary_origin == "system"`. On Windows `Path()`
   normalizes that string to backslashes, defeating the production
   `startswith("/usr/local/bin/")` check in `_detect_mm_binary_origin`.
   The fixture is POSIX-only by construction; rewriting it for Windows
   would need a Windows-flavored "system Python" path which has no
   single canonical answer (`C:\Python313\python.exe`? `py.exe`?).

2) `test_origin_system_paths` — skipif(win32). Same root cause: the
   test iterates over hardcoded POSIX paths (`/usr/bin/python3`,
   `/opt/homebrew/bin/python3.13`, etc.) and asserts `system`
   classification. None of these exist on Windows, and the prefix-match
   logic uses POSIX literals.

3) `_write_md` helper — `newline=""`. The helper is used by
   `test_collect_seed_scale_counts_md_only_and_sums_bytes` which
   asserts `total == len("hello world\n") + 100 == 112`. On Windows
   `Path.write_text` translates `\n` → `\r\n` by default (universal
   newlines), making the file 1 byte longer and the assertion fail
   `113 == 112`. Adding `newline=""` disables translation; production
   `_collect_seed_scale` already reads raw byte counts, so no
   production change is needed.

Mirrors PR #713's bundling pattern (multiple skipif sites in one PR
when they share the same POSIX-only rationale) and PR #714's bundling
pattern (helper-level fix sweeping the test sites that depend on it).

macOS: 262/262 pass. Lint clean.

Co-Authored-By: Claude <[email protected]>
@memtomem memtomem merged commit 149a190 into main May 2, 2026
8 of 9 checks passed
@memtomem memtomem deleted the test/win-init-cmd-compat branch May 2, 2026 07:36
@github-actions github-actions Bot locked and limited conversation to collaborators May 2, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants