From 6df2f199c9b4be640a1c4ba4074d66caa69936bd Mon Sep 17 00:00:00 2001 From: Soulter <905617992@qq.com> Date: Fri, 19 Jun 2026 22:32:42 +0800 Subject: [PATCH] fix: import dashboard version before bundled fallback --- astrbot/core/utils/io.py | 4 ++-- tests/test_main.py | 26 +++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/astrbot/core/utils/io.py b/astrbot/core/utils/io.py index 77a54b34e..3e9c20e32 100644 --- a/astrbot/core/utils/io.py +++ b/astrbot/core/utils/io.py @@ -491,11 +491,11 @@ async def get_dashboard_version(): data/dist version when no compatible bundled WebUI is available. """ + from astrbot.core.config.default import VERSION + # First check user data directory (manually updated / downloaded dashboard). dist_dir = os.path.join(get_astrbot_data_path(), "dist") if os.path.exists(dist_dir): - from astrbot.core.config.default import VERSION - user_version = get_dashboard_dist_version(dist_dir) if is_dashboard_dist_compatible(dist_dir, VERSION): return user_version diff --git a/tests/test_main.py b/tests/test_main.py index a60168cf8..2132bd480 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -9,7 +9,7 @@ from unittest import mock import pytest -from astrbot.core.utils.io import should_use_bundled_dashboard_dist +from astrbot.core.utils.io import get_dashboard_version, should_use_bundled_dashboard_dist from main import ( DASHBOARD_RESET_PASSWORD_ENV, _apply_startup_env_flags, @@ -322,6 +322,30 @@ def test_should_use_bundled_dashboard_dist_when_data_version_file_is_missing(tmp assert should_use_bundled_dashboard_dist(user_dist, "4.24.4") is True +@pytest.mark.asyncio +async def test_get_dashboard_version_uses_bundled_dist_when_data_dist_is_missing( + tmp_path, +): + """Tests bundled WebUI version lookup when data/dist is absent.""" + from main import VERSION + + data_dir = tmp_path / "data" + bundled_dist = tmp_path / "bundled-dist" + (bundled_dist / "assets").mkdir(parents=True) + (bundled_dist / "assets" / "version").write_text(f"v{VERSION}", encoding="utf-8") + (bundled_dist / "index.html").write_text("bundled", encoding="utf-8") + + with mock.patch( + "astrbot.core.utils.io.get_astrbot_data_path", + return_value=str(data_dir), + ): + with mock.patch( + "astrbot.core.utils.io.get_bundled_dashboard_dist_path", + return_value=bundled_dist, + ): + assert await get_dashboard_version() == f"v{VERSION}" + + @pytest.mark.asyncio async def test_check_dashboard_files_replaces_stale_data_dist_with_bundled_dist( tmp_path,