From af0953985faf0d058656439c1c377e5996b4fbda Mon Sep 17 00:00:00 2001 From: teknium1 <127238744+teknium1@users.noreply.github.com> Date: Tue, 15 Sep 2026 11:52:06 -0700 Subject: [PATCH] test(cli): trim npm mount-path coverage to two invariants MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fold the four salvaged cases into one predicate truth table (WSL drive mounts and .cmd shims refused, /mnt/data and /usr/bin accepted) and one resolver test that walks the real re-scan: PATH interop hands back a Windows npm first, the scan skips the /mnt/c entry and accepts the native npm under /mnt/data. Drops the dead `hermes_cli.main._is_windows` patch — the resolver calls main_install_repair's own `_is_windows`, which is already False on the POSIX hosts these tests run on. --- .../test_node_runtime_npm_resolution.py | 58 +++++++------------ 1 file changed, 21 insertions(+), 37 deletions(-) diff --git a/tests/hermes_cli/test_node_runtime_npm_resolution.py b/tests/hermes_cli/test_node_runtime_npm_resolution.py index e2532701eb..80d6eaf97e 100644 --- a/tests/hermes_cli/test_node_runtime_npm_resolution.py +++ b/tests/hermes_cli/test_node_runtime_npm_resolution.py @@ -1,50 +1,34 @@ -"""Regression coverage for POSIX npm path classification.""" +"""POSIX npm path classification: only Windows shims are refused (#112041, #30271).""" from __future__ import annotations +import os from unittest.mock import patch -from hermes_cli.main_install_repair import ( - _is_windows_npm_path, - _resolve_node_runtime_npm, -) +from hermes_cli.main_install_repair import _is_windows_npm_path, _resolve_node_runtime_npm -def test_windows_npm_path_classifies_only_windows_drive_mounts(): - assert _is_windows_npm_path("/mnt/c/nodejs/npm") - assert not _is_windows_npm_path("/mnt/data/node/bin/npm") +def test_windows_npm_path_refuses_windows_shims_but_not_native_data_mounts(): + """A ``/mnt/`` WSL interop path or a ``.cmd`` shim is Windows npm; a native Linux + data mount such as ``/mnt/data`` is not — a folder prefix alone is not a Windows tell.""" + assert _is_windows_npm_path("/mnt/c/Program Files/nodejs/npm") + assert _is_windows_npm_path("/mnt/d/nodejs/npm") + assert _is_windows_npm_path("C:\\nodejs\\npm.cmd") + assert not _is_windows_npm_path("/mnt/data/hermes/home/.local/bin/npm") + assert not _is_windows_npm_path("/usr/bin/npm") -def test_resolve_node_runtime_npm_accepts_native_mnt_data_path(): +def test_resolve_node_runtime_npm_rescans_past_windows_drive_to_native_mount(monkeypatch): + """When PATH interop hands back a Windows npm first, the re-scan skips the Windows drive + mount but still accepts a native npm living under ``/mnt/data``.""" native_npm = "/mnt/data/node/bin/npm" + monkeypatch.setenv("PATH", os.pathsep.join(["/mnt/c/Program Files/nodejs", "/mnt/data/node/bin"])) + + def fake_which(cmd, path=None): + return native_npm if path == "/mnt/data/node/bin" else None + with ( - patch("hermes_cli.main._is_windows", return_value=False), - patch("hermes_constants.find_node_executable", return_value=native_npm), - ): - assert _resolve_node_runtime_npm() == native_npm - - -def test_resolve_node_runtime_npm_rejects_windows_drive_mount(monkeypatch): - monkeypatch.setenv("PATH", "/mnt/c/Program Files/nodejs") - with ( - patch("hermes_cli.main._is_windows", return_value=False), - patch( - "hermes_constants.find_node_executable", - return_value="/mnt/c/nodejs/npm", - ), - ): - assert _resolve_node_runtime_npm() is None - - -def test_resolve_node_runtime_npm_rescans_native_mnt_data_path(monkeypatch): - native_npm = "/mnt/data/node/bin/npm" - monkeypatch.setenv("PATH", "/mnt/data/node/bin") - with ( - patch("hermes_cli.main._is_windows", return_value=False), - patch( - "hermes_constants.find_node_executable", - return_value="/mnt/c/nodejs/npm", - ), - patch("hermes_cli.main_install_repair.shutil.which", return_value=native_npm), + patch("hermes_constants.find_node_executable", return_value="/mnt/c/Program Files/nodejs/npm"), + patch("hermes_cli.main_install_repair.shutil.which", side_effect=fake_which), ): assert _resolve_node_runtime_npm() == native_npm