fix:仅使用包内WebUI静态资源
暂时注释本地dashboard/dist回退逻辑,并同步调整WebUI静态路径解析测试,确保仅从maibot_dashboard包加载前端资源。
This commit is contained in:
@@ -79,7 +79,7 @@ def test_resolve_static_path_prefers_installed_dashboard_package(monkeypatch, tm
|
|||||||
assert resolved_path == package_dist
|
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 = tmp_path / "dashboard" / "dist"
|
||||||
dashboard_dist.mkdir(parents=True)
|
dashboard_dist.mkdir(parents=True)
|
||||||
(dashboard_dist / "index.html").write_text("<html></html>", encoding="utf-8")
|
(dashboard_dist / "index.html").write_text("<html></html>", 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):
|
with patch.object(webui_app, "import_module", side_effect=ImportError):
|
||||||
resolved_path = webui_app._resolve_static_path()
|
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 = tmp_path / "dashboard" / "dist"
|
||||||
dashboard_dist.mkdir(parents=True)
|
dashboard_dist.mkdir(parents=True)
|
||||||
|
|
||||||
|
|||||||
@@ -205,11 +205,12 @@ def _setup_static_files(app: FastAPI):
|
|||||||
|
|
||||||
|
|
||||||
def _resolve_static_path() -> Path | None:
|
def _resolve_static_path() -> Path | None:
|
||||||
# 开发环境优先允许复用仓库里的现成 dist
|
# 临时仅允许使用已安装的 maibot-dashboard 包,不使用仓库本地 dashboard/dist。
|
||||||
base_dir = _get_project_root()
|
# 如需恢复本地回退逻辑,可取消下方注释。
|
||||||
static_path = base_dir / "dashboard" / "dist"
|
# base_dir = _get_project_root()
|
||||||
if static_path.is_dir() and (static_path / "index.html").exists():
|
# static_path = base_dir / "dashboard" / "dist"
|
||||||
return static_path
|
# if static_path.is_dir() and (static_path / "index.html").exists():
|
||||||
|
# return static_path
|
||||||
|
|
||||||
try:
|
try:
|
||||||
module = import_module("maibot_dashboard")
|
module = import_module("maibot_dashboard")
|
||||||
|
|||||||
Reference in New Issue
Block a user