From e3de01c9f61d026fa7c9638810f8878f100c2927 Mon Sep 17 00:00:00 2001 From: chengyongru <2755839590@qq.com> Date: Sun, 19 Jul 2026 23:56:35 +0800 Subject: [PATCH] fix(webui): resolve build runner executable --- nanobot/webui/build.py | 4 ++-- tests/webui/test_build.py | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/nanobot/webui/build.py b/nanobot/webui/build.py index 950cf1f0..6c53afc6 100644 --- a/nanobot/webui/build.py +++ b/nanobot/webui/build.py @@ -266,8 +266,8 @@ def ensure_webui_bundle( def pick_webui_build_runner() -> str | None: """Pick the frontend package manager used to build the WebUI.""" for candidate in ("bun", "npm"): - if shutil.which(candidate): - return candidate + if executable := shutil.which(candidate): + return executable return None diff --git a/tests/webui/test_build.py b/tests/webui/test_build.py index 5b70d17b..ff811ca1 100644 --- a/tests/webui/test_build.py +++ b/tests/webui/test_build.py @@ -4,7 +4,11 @@ import os import tomllib from pathlib import Path -from nanobot.webui.build import ensure_webui_bundle, inspect_webui_bundle +from nanobot.webui.build import ( + ensure_webui_bundle, + inspect_webui_bundle, + pick_webui_build_runner, +) _MTIME_BASE_NS = 1_700_000_000_000_000_000 _MTIME_STEP_NS = 5_000_000_000 @@ -119,6 +123,17 @@ def test_ensure_webui_bundle_auto_builds_stale_dist(tmp_path: Path) -> None: assert commands == [("bun", "install"), ("bun", "run", "build")] +def test_pick_webui_build_runner_returns_resolved_executable(monkeypatch) -> None: + bun_shim = r"C:\tools\npm\bun.CMD" + + monkeypatch.setattr( + "nanobot.webui.build.shutil.which", + lambda candidate: bun_shim if candidate == "bun" else None, + ) + + assert pick_webui_build_runner() == bun_shim + + def test_ensure_webui_bundle_warns_without_building(tmp_path: Path) -> None: source = tmp_path / "webui" dist = tmp_path / "nanobot" / "web" / "dist"