From 9cf7153b1d912e4706e86359b3d640a0f9b01f31 Mon Sep 17 00:00:00 2001 From: Admire <64821731+LittleChenLiya@users.noreply.github.com> Date: Tue, 14 Apr 2026 10:29:44 +0800 Subject: [PATCH] fix(check): windows pnpm version detection in check script (#2189) * fix: resolve Windows pnpm detection in check script * style: format check script regression test * Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * fix: resolve corepack fallback on windows --------- Co-authored-by: Willem Jiang Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- backend/tests/test_check_script.py | 57 ++++++++++++++++++++++++++++++ scripts/check.py | 21 +++++++---- 2 files changed, 71 insertions(+), 7 deletions(-) create mode 100644 backend/tests/test_check_script.py diff --git a/backend/tests/test_check_script.py b/backend/tests/test_check_script.py new file mode 100644 index 000000000..c8e96e47f --- /dev/null +++ b/backend/tests/test_check_script.py @@ -0,0 +1,57 @@ +from __future__ import annotations + +import importlib.util +from pathlib import Path + +REPO_ROOT = Path(__file__).resolve().parents[2] +CHECK_SCRIPT_PATH = REPO_ROOT / "scripts" / "check.py" + + +spec = importlib.util.spec_from_file_location("deerflow_check_script", CHECK_SCRIPT_PATH) +assert spec is not None +assert spec.loader is not None +check_script = importlib.util.module_from_spec(spec) +spec.loader.exec_module(check_script) + + +def test_find_pnpm_command_prefers_resolved_executable(monkeypatch): + def fake_which(name: str) -> str | None: + if name == "pnpm": + return r"C:\Users\tester\AppData\Roaming\npm\pnpm.CMD" + if name == "pnpm.cmd": + return r"C:\Users\tester\AppData\Roaming\npm\pnpm.cmd" + return None + + monkeypatch.setattr(check_script.shutil, "which", fake_which) + + assert check_script.find_pnpm_command() == [r"C:\Users\tester\AppData\Roaming\npm\pnpm.CMD"] + + +def test_find_pnpm_command_falls_back_to_corepack(monkeypatch): + def fake_which(name: str) -> str | None: + if name == "corepack": + return r"C:\Program Files\nodejs\corepack.exe" + return None + + monkeypatch.setattr(check_script.shutil, "which", fake_which) + + assert check_script.find_pnpm_command() == [ + r"C:\Program Files\nodejs\corepack.exe", + "pnpm", + ] + + +def test_find_pnpm_command_falls_back_to_corepack_cmd(monkeypatch): + def fake_which(name: str) -> str | None: + if name == "corepack": + return None + if name == "corepack.cmd": + return r"C:\Program Files\nodejs\corepack.cmd" + return None + + monkeypatch.setattr(check_script.shutil, "which", fake_which) + + assert check_script.find_pnpm_command() == [ + r"C:\Program Files\nodejs\corepack.cmd", + "pnpm", + ] diff --git a/scripts/check.py b/scripts/check.py index f77d54109..b633b1015 100644 --- a/scripts/check.py +++ b/scripts/check.py @@ -6,6 +6,7 @@ from __future__ import annotations import shutil import subprocess import sys +from pathlib import Path def configure_stdio() -> None: @@ -30,13 +31,19 @@ def run_command(command: list[str]) -> str | None: def find_pnpm_command() -> list[str] | None: """Return a pnpm-compatible command that exists on this machine.""" - candidates = [["pnpm"], ["pnpm.cmd"]] - if shutil.which("corepack"): - candidates.append(["corepack", "pnpm"]) + pnpm_path = shutil.which("pnpm") + if pnpm_path: + return [str(Path(pnpm_path))] - for command in candidates: - if shutil.which(command[0]): - return command + pnpm_cmd_path = shutil.which("pnpm.cmd") + if pnpm_cmd_path: + return [str(Path(pnpm_cmd_path))] + + corepack_path = shutil.which("corepack") + if not corepack_path: + corepack_path = shutil.which("corepack.cmd") + if corepack_path: + return [str(Path(corepack_path)), "pnpm"] return None @@ -88,7 +95,7 @@ def main() -> int: if pnpm_command: pnpm_version = run_command([*pnpm_command, "-v"]) if pnpm_version: - if pnpm_command[0] == "corepack": + if Path(pnpm_command[0]).stem.lower() == "corepack": print(f" OK pnpm {pnpm_version} (via Corepack)") else: print(f" OK pnpm {pnpm_version}")