Skip to content

fix(tests): wrap Path.expanduser() to never raise on Windows runner#1276

Merged
danielmeppiel merged 2 commits into
mainfrom
fix/windows-expanduser
May 11, 2026
Merged

fix(tests): wrap Path.expanduser() to never raise on Windows runner#1276
danielmeppiel merged 2 commits into
mainfrom
fix/windows-expanduser

Conversation

@danielmeppiel
Copy link
Copy Markdown
Collaborator

Problem

The v0.13.0 retag CI still red-marked Windows on two tests after #1272:

FAILED tests/unit/install/test_user_scope_rejection_reason.py::test_user_scope_accepts_tilde_local_path[~/pkg]
FAILED tests/unit/install/test_user_scope_rejection_reason.py::test_user_scope_accepts_tilde_local_path[~/sub/pkg]
       raise RuntimeError("Could not determine home directory.")
E      RuntimeError: Could not determine home directory.
C:\hostedtoolcache\windows\Python\3.12.10\x64\Lib\pathlib.py:1406: RuntimeError

Different code path than #1272: production code in install.package_resolution.user_scope_rejection_reason calls Path('~/pkg').expanduser() to detect absoluteness. ntpath.expanduser raises RuntimeError when both USERPROFILE and HOMEPATH are absent — the windows-2025-vs2026 runner state.

Fix

tests/conftest.py (root, loaded by every xdist worker before any test): wrap Path.expanduser. On RuntimeError, fall back to _TMP_HOME (the same hermetic dir Path.home() uses). Expanded path is still absolute so production code's .is_absolute() check still behaves correctly.

Validation

  • New regression-trap test in tests/unit/test_path_home_override.py (clears HOME/USERPROFILE/HOMEDRIVE/HOMEPATH, asserts Path('~/pkg').expanduser() returns an absolute path without raising).
  • The two previously-failing tests now pass locally.
  • Lint clean.

Why ship now

Required for v0.13.0 retag to go green on Windows.

Companion to #1272. After the Path.home() override landed, the
windows-2025-vs2026 runner still red-marked two tests:

  tests/unit/install/test_user_scope_rejection_reason.py
    ::test_user_scope_accepts_tilde_local_path[~/pkg]
    ::test_user_scope_accepts_tilde_local_path[~/sub/pkg]

These hit a different code path: production code in
install.package_resolution.user_scope_rejection_reason calls
Path('~/pkg').expanduser() to detect that the path is absolute.
ntpath.expanduser raises RuntimeError('Could not determine home
directory.') when both USERPROFILE and HOMEPATH are absent --
exactly the windows-2025-vs2026 worker env state.

Fix in tests/conftest.py (root, loaded by every xdist worker before
any test):

  - Wrap Path.expanduser. On RuntimeError, fall back to _TMP_HOME
    (the same hermetic dir Path.home() uses). The expanded path is
    still absolute, so production code's .is_absolute() check keeps
    behaving correctly.

Regression trap added in tests/unit/test_path_home_override.py: clears
HOME/USERPROFILE/HOMEDRIVE/HOMEPATH and asserts Path('~/pkg').expanduser()
returns an absolute path without raising.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 11, 2026 13:25
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@danielmeppiel danielmeppiel merged commit 9216516 into main May 11, 2026
9 checks passed
@danielmeppiel danielmeppiel deleted the fix/windows-expanduser branch May 11, 2026 13:47
@danielmeppiel danielmeppiel review requested due to automatic review settings May 11, 2026 13:50
danielmeppiel pushed a commit that referenced this pull request May 18, 2026
- One concise line per PR answering 'so what?' for end users
- Add 5 missing entries: #1376 (perf resolver), #1373 (shared/apm.md
  matrix secret-stripping), #1246 (install.ps1 GHES env vars), #1255
  (warn missing apm.yml), #1248 (extends:org unmanaged_files)
- Drop internal/CI/test-infra entries (#1270, #1271, #1272, #1274,
  #1276, #1291, #1360 refactor)
- Consolidate three #605 lines and four #1317 lines into one entry
  per PR where appropriate
- Promote MCP Registry v0.1 to a dedicated Breaking section

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
danielmeppiel added a commit that referenced this pull request May 18, 2026
* chore: cut 0.14.0

Renames the [Unreleased] block in CHANGELOG.md to [0.14.0] - 2026-05-18
and bumps the package version from 0.13.0 to 0.14.0 in pyproject.toml
(and uv.lock by regeneration).

0.14.0 ships the producer-experience epic (#1348) on the CLI side --
notably:

- apm pack --check-versions / --check-clean (#1365), the release gates
  consumed by apm-action mode: release.
- apm plugin init (#1370), the noun-verb successor to apm init --plugin.
- apm pack multi-format outputs (--marketplace, --marketplace-path,
  --json, marketplace.outputs map form) (#1317).
- New producer docs corpus (repo-shapes / releasing-from-any-ci /
  versioning-strategies) (#1370).
- Breaking: MCP registry client adopts the official v0.1 spec; self-
  hosted registries must serve /v0.1/ paths (#1337).

Plus the deprecations and fixes already listed in the moved block.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* docs(changelog): tighten v0.14.0 entries; add post-cut PRs

- One concise line per PR answering 'so what?' for end users
- Add 5 missing entries: #1376 (perf resolver), #1373 (shared/apm.md
  matrix secret-stripping), #1246 (install.ps1 GHES env vars), #1255
  (warn missing apm.yml), #1248 (extends:org unmanaged_files)
- Drop internal/CI/test-infra entries (#1270, #1271, #1272, #1274,
  #1276, #1291, #1360 refactor)
- Consolidate three #605 lines and four #1317 lines into one entry
  per PR where appropriate
- Promote MCP Registry v0.1 to a dedicated Breaking section

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* docs(changelog): add #1377 Bitbucket DC tilde fix

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: Daniel Meppiel <copilot-rework@github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
sergio-sisternes-epam pushed a commit that referenced this pull request May 19, 2026
…1276)

* fix(tests): wrap Path.expanduser() to never raise on Windows runner

Companion to #1272. After the Path.home() override landed, the
windows-2025-vs2026 runner still red-marked two tests:

  tests/unit/install/test_user_scope_rejection_reason.py
    ::test_user_scope_accepts_tilde_local_path[~/pkg]
    ::test_user_scope_accepts_tilde_local_path[~/sub/pkg]

These hit a different code path: production code in
install.package_resolution.user_scope_rejection_reason calls
Path('~/pkg').expanduser() to detect that the path is absolute.
ntpath.expanduser raises RuntimeError('Could not determine home
directory.') when both USERPROFILE and HOMEPATH are absent --
exactly the windows-2025-vs2026 worker env state.

Fix in tests/conftest.py (root, loaded by every xdist worker before
any test):

  - Wrap Path.expanduser. On RuntimeError, fall back to _TMP_HOME
    (the same hermetic dir Path.home() uses). The expanded path is
    still absolute, so production code's .is_absolute() check keeps
    behaving correctly.

Regression trap added in tests/unit/test_path_home_override.py: clears
HOME/USERPROFILE/HOMEDRIVE/HOMEPATH and asserts Path('~/pkg').expanduser()
returns an absolute path without raising.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* chore: correct PR number in CHANGELOG entry

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: Daniel Meppiel <copilot-rework@github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
sergio-sisternes-epam pushed a commit that referenced this pull request May 19, 2026
* chore: cut 0.14.0

Renames the [Unreleased] block in CHANGELOG.md to [0.14.0] - 2026-05-18
and bumps the package version from 0.13.0 to 0.14.0 in pyproject.toml
(and uv.lock by regeneration).

0.14.0 ships the producer-experience epic (#1348) on the CLI side --
notably:

- apm pack --check-versions / --check-clean (#1365), the release gates
  consumed by apm-action mode: release.
- apm plugin init (#1370), the noun-verb successor to apm init --plugin.
- apm pack multi-format outputs (--marketplace, --marketplace-path,
  --json, marketplace.outputs map form) (#1317).
- New producer docs corpus (repo-shapes / releasing-from-any-ci /
  versioning-strategies) (#1370).
- Breaking: MCP registry client adopts the official v0.1 spec; self-
  hosted registries must serve /v0.1/ paths (#1337).

Plus the deprecations and fixes already listed in the moved block.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* docs(changelog): tighten v0.14.0 entries; add post-cut PRs

- One concise line per PR answering 'so what?' for end users
- Add 5 missing entries: #1376 (perf resolver), #1373 (shared/apm.md
  matrix secret-stripping), #1246 (install.ps1 GHES env vars), #1255
  (warn missing apm.yml), #1248 (extends:org unmanaged_files)
- Drop internal/CI/test-infra entries (#1270, #1271, #1272, #1274,
  #1276, #1291, #1360 refactor)
- Consolidate three #605 lines and four #1317 lines into one entry
  per PR where appropriate
- Promote MCP Registry v0.1 to a dedicated Breaking section

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* docs(changelog): add #1377 Bitbucket DC tilde fix

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: Daniel Meppiel <copilot-rework@github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant