From 46a9b817e748860314486007515536e91ec31803 Mon Sep 17 00:00:00 2001 From: DawnARC Date: Fri, 17 Apr 2026 08:33:01 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E4=BB=85=E4=BD=BF=E7=94=A8=E5=8C=85?= =?UTF-8?q?=E5=86=85WebUI=E9=9D=99=E6=80=81=E8=B5=84=E6=BA=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 暂时注释本地dashboard/dist回退逻辑,并同步调整WebUI静态路径解析测试,确保仅从maibot_dashboard包加载前端资源。 --- pytests/webui/test_app.py | 6 +++--- src/webui/app.py | 11 ++++++----- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/pytests/webui/test_app.py b/pytests/webui/test_app.py index 3ef1cfdd..bc7343ea 100644 --- a/pytests/webui/test_app.py +++ b/pytests/webui/test_app.py @@ -79,7 +79,7 @@ def test_resolve_static_path_prefers_installed_dashboard_package(monkeypatch, tm assert resolved_path == package_dist -def test_resolve_static_path_uses_dashboard_dist(monkeypatch, tmp_path) -> None: +def test_resolve_static_path_ignores_dashboard_dist_when_package_is_unavailable(monkeypatch, tmp_path) -> None: dashboard_dist = tmp_path / "dashboard" / "dist" dashboard_dist.mkdir(parents=True) (dashboard_dist / "index.html").write_text("", encoding="utf-8") @@ -89,10 +89,10 @@ def test_resolve_static_path_uses_dashboard_dist(monkeypatch, tmp_path) -> None: with patch.object(webui_app, "import_module", side_effect=ImportError): resolved_path = webui_app._resolve_static_path() - assert resolved_path == dashboard_dist + assert resolved_path is None -def test_resolve_static_path_falls_back_to_package_when_dashboard_dist_has_no_index(monkeypatch, tmp_path) -> None: +def test_resolve_static_path_uses_package_even_when_dashboard_dist_exists(monkeypatch, tmp_path) -> None: dashboard_dist = tmp_path / "dashboard" / "dist" dashboard_dist.mkdir(parents=True) diff --git a/src/webui/app.py b/src/webui/app.py index 366c1c79..54b1288b 100644 --- a/src/webui/app.py +++ b/src/webui/app.py @@ -205,11 +205,12 @@ def _setup_static_files(app: FastAPI): def _resolve_static_path() -> Path | None: - # 开发环境优先允许复用仓库里的现成 dist - base_dir = _get_project_root() - static_path = base_dir / "dashboard" / "dist" - if static_path.is_dir() and (static_path / "index.html").exists(): - return static_path + # 临时仅允许使用已安装的 maibot-dashboard 包,不使用仓库本地 dashboard/dist。 + # 如需恢复本地回退逻辑,可取消下方注释。 + # base_dir = _get_project_root() + # static_path = base_dir / "dashboard" / "dist" + # if static_path.is_dir() and (static_path / "index.html").exists(): + # return static_path try: module = import_module("maibot_dashboard")