Skip to content

Fix: Resolve Matrix CI failure (Windows pipx detection)#462

Draft
curdriceaurora wants to merge 1 commit into
mainfrom
chore/ci-fix-doctor-pipx-windows
Draft

Fix: Resolve Matrix CI failure (Windows pipx detection)#462
curdriceaurora wants to merge 1 commit into
mainfrom
chore/ci-fix-doctor-pipx-windows

Conversation

@curdriceaurora
Copy link
Copy Markdown
Owner

Summary

The scheduled CI Full Matrix workflow has been failing daily on main since at least 2026-06-02 — the Test Windows (Python 3.12) job fails one test while all other matrix variants (Linux 3.11, Linux 3.12, macOS 3.12) pass.

Run Conclusion Failing job
#26938361854 (2026-06-04) failure Test Windows (py3.12)
#26871404355 (2026-06-03) failure Test Windows (py3.12)
#26806177119 (2026-06-02) failure Test Windows (py3.12)

Failing test (1 of 4922 total):

FAILED tests/cli/test_doctor.py::TestInstallMethodDetection::test_detect_pipx_via_pipx_home_env
  AssertionError: assert 'pip' == 'pipx'

Root Cause Analysis

The test sets PIPX_HOME=/custom/pipx and sys.executable=/custom/pipx/venvs/fo-core/bin/python, then expects _detect_install_method() to return "pipx".

cli/doctor.py:117-120 builds the match pattern via:

exe_path.startswith(os.path.join(pipx_home, "venvs") + os.sep)

On Windows:

  • os.path.join("/custom/pipx", "venvs")"/custom/pipx\venvs" (mixed separators; join doesn't rewrite the input's existing forward slashes but uses os.sep to attach the new segment)
  • os.sep"\\"
  • Pattern → "/custom/pipx\venvs\"
  • "/custom/pipx/venvs/fo-core/bin/python".startswith("/custom/pipx\venvs\")False → falls through to "pip".

This is a real correctness bug, not just a test issue: any Windows user whose PIPX_HOME carries forward slashes (env files copied from a POSIX machine, WSL setups, scripted exports) would have pipx misdetected. The other tests in this class happened to pass on Windows only because they used forward-slash paths on both sides of the comparison and didn't go through the os.path.join branch.

Classification: Deterministic code regression (Windows path handling). Not flaky, not infrastructure.

Fix

Normalize both the executable path and each candidate pattern with os.path.normpath() before the prefix check. The same treatment is applied to the ~/.local/pipx/... fallback branch for consistency.

exe_path = os.path.normpath(sys.executable)
...
pattern = os.path.normpath(os.path.join(pipx_home, "venvs")) + os.sep
if exe_path.startswith(pattern):
    return "pipx"

This keeps the production logic minimal and platform-agnostic; the test was already exercising a realistic input shape and didn't need to change.

Verification

  • ✅ 162 tests in tests/cli/test_doctor.py pass on Linux.
  • ✅ Direct simulation under ntpath (Windows path semantics) confirms:
    • test_detect_pipx_via_pipx_home_env now returns "pipx" (was "pip").
    • All other 4 TestInstallMethodDetection cases still behave correctly.
  • ruff check clean.
  • ✅ Other matrix variants (Linux py3.11/3.12, macOS) were already green; no behavior change for forward-slash-on-both-sides cases.

Impact

  • src/cli/doctor.py_detect_install_method() only (used in 4 call sites within the same file for install/upgrade flows).
  • No public API change.
  • No test changes.

Trade-offs considered

  • Fix in test instead (use platform-appropriate paths): rejected — the test input represents a realistic env-var shape and the production code should handle it. Project rule: "code correction over test weakening."
  • Use pathlib.Path: rejected — os.path.startswith-style prefix matching is more straightforward than pathlib's is_relative_to, which would require try/except and adds an import.

Generated by Claude Code

CI Full Matrix has failed daily on the Test Windows (py3.12) job for the
last several scheduled runs. Root cause is a Windows-only mismatch in
cli/doctor._detect_install_method:

  pattern = os.path.join(pipx_home, "venvs") + os.sep

On Windows, os.path.join("/custom/pipx", "venvs") produces
"/custom/pipx\\venvs" (mixed separators) and os.sep is "\\", so the
pattern becomes "/custom/pipx\\venvs\\". A sys.executable like
"/custom/pipx/venvs/fo-core/bin/python" (the value used by
test_detect_pipx_via_pipx_home_env, and a realistic env-var shape on
machines where PIPX_HOME originates from a POSIX-style config) never
satisfies startswith() against that pattern, so detection falls through
to "pip".

Normalize both the executable path and each candidate pattern with
os.path.normpath so prefix comparison is platform-agnostic. The other
detection paths (~/.local/pipx/...) get the same treatment for
consistency — they happened to pass on Windows only because both sides
of the comparison used forward slashes by coincidence.

Verified:
- 162 tests in tests/cli/test_doctor.py pass on Linux.
- Direct simulation of Windows path semantics (ntpath) confirms the
  failing test now passes and the other 4 cases in
  TestInstallMethodDetection still behave correctly.

Failing run: https://github.com/curdriceaurora/fo-core/actions/runs/26938361854
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 4, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: c79f2ef7-5caa-4ed1-9ae4-92067b48427c

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/ci-fix-doctor-pipx-windows

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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.

2 participants