From 1772156082fed7e4e08e44ce1cb56e771e99952e Mon Sep 17 00:00:00 2001 From: xianshujun Date: Thu, 3 Dec 2026 11:34:57 +0900 Subject: [PATCH 1/2] fix: show CLI upgrade instructions in the WebUI --- astrbot/dashboard/services/update_service.py | 15 ++++++ .../src/i18n/locales/en-US/core/header.json | 4 +- .../src/i18n/locales/ja-JP/core/header.json | 4 +- .../src/i18n/locales/ru-RU/core/header.json | 4 +- .../src/i18n/locales/zh-CN/core/header.json | 4 +- .../full/vertical-header/VerticalHeader.vue | 46 +++++++++---------- dashboard/src/utils/updateProgressMessage.ts | 20 ++++++++ .../tests/updateProgressMessage.test.mjs | 28 +++++++++++ tests/test_dashboard.py | 45 ++++++++++++++++-- 9 files changed, 138 insertions(+), 32 deletions(-) create mode 100644 dashboard/src/utils/updateProgressMessage.ts create mode 100644 dashboard/tests/updateProgressMessage.test.mjs diff --git a/astrbot/dashboard/services/update_service.py b/astrbot/dashboard/services/update_service.py index 00f9e63f788..f8334f8a18f 100644 --- a/astrbot/dashboard/services/update_service.py +++ b/astrbot/dashboard/services/update_service.py @@ -1,6 +1,7 @@ from __future__ import annotations import asyncio +import os import traceback import uuid from collections.abc import Awaitable, Callable @@ -174,6 +175,20 @@ async def _run_update_project( reboot: Whether to restart AstrBot after applying files. proxy: Optional GitHub proxy URL. """ + if os.environ.get("ASTRBOT_CLI") == "1": + self.update_progress[progress_id].update( + status="error", + error_code="cli_update_required", + message=( + "AstrBot was started via the CLI and cannot be updated from the WebUI. " + "For a uv tool install, run uv tool upgrade astrbot. For a pip install, " + "run python -m pip install --upgrade astrbot in the original Python " + "environment. Then restart AstrBot. " + "Upgrade guide: https://docs.astrbot.app/en/deploy/update#package" + ), + ) + return + try: async def observe_update(event: UpdateProgress) -> None: diff --git a/dashboard/src/i18n/locales/en-US/core/header.json b/dashboard/src/i18n/locales/en-US/core/header.json index 8446fb4cc6a..0cae11f666c 100644 --- a/dashboard/src/i18n/locales/en-US/core/header.json +++ b/dashboard/src/i18n/locales/en-US/core/header.json @@ -66,7 +66,9 @@ "successReady": "Update successful", "autoReloadIn": "Refreshing automatically in {seconds}s", "reloadNow": "Refresh now", - "failed": "Update failed" + "failed": "Update failed", + "cliUpdateRequired": "AstrBot was started via the CLI and cannot be updated from the WebUI. For a uv tool install, run uv tool upgrade astrbot. For a pip install, run python -m pip install --upgrade astrbot in the original Python environment. Then restart AstrBot.", + "cliUpdateGuide": "Read the AstrBot upgrade guide" }, "redirectConfirm": { "title": "Leaving AstrBot", diff --git a/dashboard/src/i18n/locales/ja-JP/core/header.json b/dashboard/src/i18n/locales/ja-JP/core/header.json index 6d94895fba2..a40842bbbf1 100644 --- a/dashboard/src/i18n/locales/ja-JP/core/header.json +++ b/dashboard/src/i18n/locales/ja-JP/core/header.json @@ -66,7 +66,9 @@ "successReady": "更新に成功しました", "autoReloadIn": "{seconds} 秒後にページを自動的に再読み込みします", "reloadNow": "今すぐ再読み込み", - "failed": "更新に失敗しました" + "failed": "更新に失敗しました", + "cliUpdateRequired": "CLI から起動した AstrBot は WebUI では更新できません。uv tool でインストールした場合は uv tool upgrade astrbot を、pip の場合はインストール時の Python 環境で python -m pip install --upgrade astrbot を実行してください。更新後に AstrBot を再起動してください。", + "cliUpdateGuide": "AstrBot のアップグレードガイドを読む" }, "redirectConfirm": { "title": "公式アップデートガイドを開く", diff --git a/dashboard/src/i18n/locales/ru-RU/core/header.json b/dashboard/src/i18n/locales/ru-RU/core/header.json index 203188c6a3a..f908d692773 100644 --- a/dashboard/src/i18n/locales/ru-RU/core/header.json +++ b/dashboard/src/i18n/locales/ru-RU/core/header.json @@ -66,7 +66,9 @@ "successReady": "Обновление успешно", "autoReloadIn": "Автоматическое обновление через {seconds} с", "reloadNow": "Обновить сейчас", - "failed": "Ошибка обновления" + "failed": "Ошибка обновления", + "cliUpdateRequired": "AstrBot запущен через CLI, поэтому обновление из WebUI недоступно. Если вы установили AstrBot через uv tool, выполните uv tool upgrade astrbot. При установке через pip выполните python -m pip install --upgrade astrbot в исходном окружении Python. Затем перезапустите AstrBot.", + "cliUpdateGuide": "Руководство по обновлению AstrBot" }, "redirectConfirm": { "title": "Переход по ссылке", diff --git a/dashboard/src/i18n/locales/zh-CN/core/header.json b/dashboard/src/i18n/locales/zh-CN/core/header.json index 6fea11ea399..a4599464dfb 100644 --- a/dashboard/src/i18n/locales/zh-CN/core/header.json +++ b/dashboard/src/i18n/locales/zh-CN/core/header.json @@ -66,7 +66,9 @@ "successReady": "更新成功", "autoReloadIn": "{seconds} 秒后自动刷新", "reloadNow": "立即刷新", - "failed": "更新失败" + "failed": "更新失败", + "cliUpdateRequired": "通过 CLI 启动的 AstrBot 不能在 WebUI 中升级。请在终端使用原来的安装方式升级:uv tool 安装请运行 uv tool upgrade astrbot;pip 安装请在原 Python 环境中运行 python -m pip install --upgrade astrbot。升级后请重启 AstrBot。", + "cliUpdateGuide": "查看 AstrBot 更新指南" }, "redirectConfirm": { "title": "即将跳转", diff --git a/dashboard/src/layouts/full/vertical-header/VerticalHeader.vue b/dashboard/src/layouts/full/vertical-header/VerticalHeader.vue index 7fe271db402..51fbf2df7f6 100644 --- a/dashboard/src/layouts/full/vertical-header/VerticalHeader.vue +++ b/dashboard/src/layouts/full/vertical-header/VerticalHeader.vue @@ -25,6 +25,7 @@ import type { Locale } from "@/i18n/types"; import AboutPage from "@/views/AboutPage.vue"; import { authApi, isLegacyFallbackError, statsApi, updatesApi } from "@/api/v1"; import { getDesktopRuntimeInfo } from "@/utils/desktopRuntime"; +import { getUpdateProgressMessage } from "@/utils/updateProgressMessage"; enableKatex(); enableMermaid(); @@ -97,6 +98,7 @@ type UpdateProgress = { stage: string; version: string; message: string; + error_code?: string; overall_percent: number; stages: Record; }; @@ -234,30 +236,9 @@ const updateStageItems = computed(() => [ progress: updateProgress.value.stages.core || createEmptyDownloadStage(), }, ]); -const updateProgressMessage = computed(() => { - if (updateProgress.value.status === "error") { - return ( - updateProgress.value.message || - t("core.header.updateDialog.progress.failed") - ); - } - if (updateProgress.value.status === "success") { - return ( - updateProgress.value.message || - t("core.header.updateDialog.progress.completed") - ); - } - if (updateProgress.value.stage === "dependencies") { - return t("core.header.updateDialog.progress.dependencies"); - } - if (updateProgress.value.stage === "restart") { - return t("core.header.updateDialog.progress.restart"); - } - return ( - updateProgress.value.message || - t("core.header.updateDialog.progress.preparing") - ); -}); +const updateProgressMessage = computed(() => + getUpdateProgressMessage(updateProgress.value, t), +); // Form validation const formValid = ref(true); const passwordRules = computed(() => [ @@ -1075,6 +1056,11 @@ const languages = computed(() => })), ); const currentLocale = computed(() => locale.value); +const cliUpdateGuideUrl = computed(() => + currentLocale.value === "zh-CN" + ? "https://docs.astrbot.app/deploy/update#package" + : "https://docs.astrbot.app/en/deploy/update#package", +); const changeLanguage = async (langCode: string) => { await switchLanguage(langCode as Locale); mainMenuOpen.value = false; @@ -1540,6 +1526,18 @@ onMounted(async () => {
{{ updateProgressMessage }}
+ + {{ t("core.header.updateDialog.progress.cliUpdateGuide") }} +
{{ t("core.header.updateDialog.progress.target") }} {{ updateProgress.version || "latest" }} diff --git a/dashboard/src/utils/updateProgressMessage.ts b/dashboard/src/utils/updateProgressMessage.ts new file mode 100644 index 00000000000..cbdcb8d7482 --- /dev/null +++ b/dashboard/src/utils/updateProgressMessage.ts @@ -0,0 +1,20 @@ +type MessageFields = { status: string; stage: string; message: string; error_code?: string }; + +export function getUpdateProgressMessage(progress: MessageFields, t: (key: string) => string): string { + if (progress.status === "error") { + if (progress.error_code === "cli_update_required") { + return t("core.header.updateDialog.progress.cliUpdateRequired"); + } + return progress.message || t("core.header.updateDialog.progress.failed"); + } + if (progress.status === "success") { + return progress.message || t("core.header.updateDialog.progress.completed"); + } + if (progress.stage === "dependencies") { + return t("core.header.updateDialog.progress.dependencies"); + } + if (progress.stage === "restart") { + return t("core.header.updateDialog.progress.restart"); + } + return progress.message || t("core.header.updateDialog.progress.preparing"); +} diff --git a/dashboard/tests/updateProgressMessage.test.mjs b/dashboard/tests/updateProgressMessage.test.mjs new file mode 100644 index 00000000000..fb4ecb04969 --- /dev/null +++ b/dashboard/tests/updateProgressMessage.test.mjs @@ -0,0 +1,28 @@ +import assert from "node:assert/strict"; +import test from "node:test"; +import en from "../src/i18n/locales/en-US/core/header.json" with { type: "json" }; +import ja from "../src/i18n/locales/ja-JP/core/header.json" with { type: "json" }; +import ru from "../src/i18n/locales/ru-RU/core/header.json" with { type: "json" }; +import zh from "../src/i18n/locales/zh-CN/core/header.json" with { type: "json" }; +import { getUpdateProgressMessage } from "../src/utils/updateProgressMessage.ts"; + +const failure = { status: "error", stage: "preparing", message: "Server fallback" }; + +for (const [locale, header] of Object.entries({ en, ja, ru, zh })) { + test(`renders localized package-manager instructions for ${locale}`, () => { + const t = (key) => key.split(".").reduce((value, part) => value[part], { core: { header } }); + const message = getUpdateProgressMessage({ ...failure, error_code: "cli_update_required" }, t); + assert.ok(message.includes("uv tool upgrade astrbot")); + assert.ok(message.includes("python -m pip install --upgrade astrbot")); + assert.ok(t("core.header.updateDialog.progress.cliUpdateGuide")); + }); +} + +test("does not mislabel ordinary update errors or require an error code from older servers", () => { + const t = (key) => key; + assert.equal(getUpdateProgressMessage(failure, t), failure.message); + assert.equal( + getUpdateProgressMessage({ ...failure, error_code: "other", message: "" }, t), + "core.header.updateDialog.progress.failed", + ); +}); diff --git a/tests/test_dashboard.py b/tests/test_dashboard.py index 4b95471cc81..610810bd4c2 100644 --- a/tests/test_dashboard.py +++ b/tests/test_dashboard.py @@ -157,6 +157,8 @@ async def _wait_for_update_progress( test_client, authenticated_header: dict, progress_id: str, + *, + use_v1: bool = False, ) -> dict: """Wait until a dashboard update task reaches a terminal status. @@ -164,15 +166,18 @@ async def _wait_for_update_progress( test_client: Quart/FastAPI adapter test client. authenticated_header: Headers for authenticated dashboard requests. progress_id: Update progress id to poll. + use_v1: Poll the current WebUI endpoint instead of its legacy fallback. Returns: The progress response payload. """ + path = ( + f"/api/v1/updates/progress/{progress_id}" + if use_v1 + else f"/api/update/progress?id={progress_id}" + ) for _ in range(100): - response = await test_client.get( - f"/api/update/progress?id={progress_id}", - headers=authenticated_header, - ) + response = await test_client.get(path, headers=authenticated_header) data = await response.get_json() if data["data"].get("status") in {"success", "error"}: return data @@ -3219,6 +3224,38 @@ async def mock_update(*args, **kwargs): assert calls == ["update"] +@pytest.mark.asyncio +async def test_cli_update_guidance_in_polled_progress( + app: FastAPIAppAdapter, + authenticated_header: dict, + core_lifecycle_td: AstrBotCoreLifecycle, + monkeypatch: pytest.MonkeyPatch, +) -> None: + monkeypatch.setenv("ASTRBOT_CLI", "1") + update = AsyncMock(side_effect=RuntimeError("unexpected download")) + monkeypatch.setattr(core_lifecycle_td.astrbot_updater, "update", update) + client = app.test_client() + response = await client.post( + "/api/v1/updates/core", + headers=authenticated_header, + json={"version": "v4.30.2", "progress_id": "cli-progress"}, + ) + started = await response.get_json() + assert started["status"] == "ok" + polled = await _wait_for_update_progress( + client, authenticated_header, started["data"]["id"], use_v1=True + ) + progress = polled["data"] + assert progress["status"] == "error" + assert progress.get("error_code") == "cli_update_required" + assert "uv tool upgrade astrbot" in progress["message"] + assert "python -m pip install --upgrade astrbot" in progress["message"] + assert "original Python environment" in progress["message"] + assert "https://docs.astrbot.app/en/deploy/update#package" in progress["message"] + assert progress["overall_percent"] == 0 + update.assert_not_awaited() + + @pytest.mark.asyncio async def test_do_update_rejects_desktop_managed_backend( app: FastAPIAppAdapter, From c696aee96b8fcbe793142ecfeca97b9f4dc7610a Mon Sep 17 00:00:00 2001 From: Soulter <37870767+Soulter@users.noreply.github.com> Date: Thu, 3 Dec 2026 21:15:09 +0800 Subject: [PATCH 2/2] Delete dashboard/tests/updateProgressMessage.test.mjs --- .../tests/updateProgressMessage.test.mjs | 28 ------------------- 1 file changed, 28 deletions(-) delete mode 100644 dashboard/tests/updateProgressMessage.test.mjs diff --git a/dashboard/tests/updateProgressMessage.test.mjs b/dashboard/tests/updateProgressMessage.test.mjs deleted file mode 100644 index fb4ecb04969..00000000000 --- a/dashboard/tests/updateProgressMessage.test.mjs +++ /dev/null @@ -1,28 +0,0 @@ -import assert from "node:assert/strict"; -import test from "node:test"; -import en from "../src/i18n/locales/en-US/core/header.json" with { type: "json" }; -import ja from "../src/i18n/locales/ja-JP/core/header.json" with { type: "json" }; -import ru from "../src/i18n/locales/ru-RU/core/header.json" with { type: "json" }; -import zh from "../src/i18n/locales/zh-CN/core/header.json" with { type: "json" }; -import { getUpdateProgressMessage } from "../src/utils/updateProgressMessage.ts"; - -const failure = { status: "error", stage: "preparing", message: "Server fallback" }; - -for (const [locale, header] of Object.entries({ en, ja, ru, zh })) { - test(`renders localized package-manager instructions for ${locale}`, () => { - const t = (key) => key.split(".").reduce((value, part) => value[part], { core: { header } }); - const message = getUpdateProgressMessage({ ...failure, error_code: "cli_update_required" }, t); - assert.ok(message.includes("uv tool upgrade astrbot")); - assert.ok(message.includes("python -m pip install --upgrade astrbot")); - assert.ok(t("core.header.updateDialog.progress.cliUpdateGuide")); - }); -} - -test("does not mislabel ordinary update errors or require an error code from older servers", () => { - const t = (key) => key; - assert.equal(getUpdateProgressMessage(failure, t), failure.message); - assert.equal( - getUpdateProgressMessage({ ...failure, error_code: "other", message: "" }, t), - "core.header.updateDialog.progress.failed", - ); -});