|
20 | 20 | from astrbot.core import LogBroker |
21 | 21 | from astrbot.core.core_lifecycle import AstrBotCoreLifecycle |
22 | 22 | from astrbot.core.db.sqlite import SQLiteDatabase |
| 23 | +from astrbot.core.desktop_runtime import DESKTOP_MANAGED_RESTART_MESSAGE |
23 | 24 | from astrbot.core.star.star import StarMetadata, star_registry |
24 | 25 | from astrbot.core.star.star_handler import star_handlers_registry |
25 | 26 | from astrbot.core.utils.auth_password import ( |
@@ -2662,6 +2663,35 @@ async def mock_get_dashboard_version(*args, **kwargs): |
2662 | 2663 | assert data["data"]["has_new_version"] is False |
2663 | 2664 |
|
2664 | 2665 |
|
| 2666 | +@pytest.mark.asyncio |
| 2667 | +async def test_restart_core_rejects_desktop_managed_backend( |
| 2668 | + app: FastAPIAppAdapter, |
| 2669 | + authenticated_header: dict, |
| 2670 | + core_lifecycle_td: AstrBotCoreLifecycle, |
| 2671 | + monkeypatch, |
| 2672 | +): |
| 2673 | + test_client = app.test_client() |
| 2674 | + restart_called = False |
| 2675 | + |
| 2676 | + async def mock_restart(): |
| 2677 | + nonlocal restart_called |
| 2678 | + restart_called = True |
| 2679 | + |
| 2680 | + monkeypatch.setenv("ASTRBOT_DESKTOP_MANAGED", "1") |
| 2681 | + monkeypatch.setattr(core_lifecycle_td, "restart", mock_restart) |
| 2682 | + |
| 2683 | + response = await test_client.post( |
| 2684 | + "/api/stat/restart-core", |
| 2685 | + headers=authenticated_header, |
| 2686 | + ) |
| 2687 | + |
| 2688 | + assert response.status_code == 400 |
| 2689 | + data = await response.get_json() |
| 2690 | + assert data["status"] == "error" |
| 2691 | + assert data["message"] == DESKTOP_MANAGED_RESTART_MESSAGE |
| 2692 | + assert restart_called is False |
| 2693 | + |
| 2694 | + |
2665 | 2695 | @pytest.mark.asyncio |
2666 | 2696 | async def test_do_update( |
2667 | 2697 | app: FastAPIAppAdapter, |
@@ -2826,6 +2856,44 @@ def mock_extract_dashboard(*args, **kwargs): |
2826 | 2856 | assert calls == ["download-dashboard", "download-core"] |
2827 | 2857 |
|
2828 | 2858 |
|
| 2859 | +@pytest.mark.asyncio |
| 2860 | +async def test_do_update_rejects_desktop_managed_backend( |
| 2861 | + app: FastAPIAppAdapter, |
| 2862 | + authenticated_header: dict, |
| 2863 | + core_lifecycle_td: AstrBotCoreLifecycle, |
| 2864 | + monkeypatch, |
| 2865 | +): |
| 2866 | + test_client = app.test_client() |
| 2867 | + calls = [] |
| 2868 | + |
| 2869 | + async def mock_download_core(*args, **kwargs): |
| 2870 | + del args, kwargs |
| 2871 | + calls.append("download-core") |
| 2872 | + |
| 2873 | + async def mock_restart(): |
| 2874 | + calls.append("restart") |
| 2875 | + |
| 2876 | + monkeypatch.setenv("ASTRBOT_DESKTOP_MANAGED", "1") |
| 2877 | + monkeypatch.setattr( |
| 2878 | + core_lifecycle_td.astrbot_updator, |
| 2879 | + "download_update_package", |
| 2880 | + mock_download_core, |
| 2881 | + ) |
| 2882 | + monkeypatch.setattr(core_lifecycle_td, "restart", mock_restart) |
| 2883 | + |
| 2884 | + response = await test_client.post( |
| 2885 | + "/api/update/do", |
| 2886 | + headers=authenticated_header, |
| 2887 | + json={"version": "v3.4.0", "progress_id": "desktop-progress"}, |
| 2888 | + ) |
| 2889 | + |
| 2890 | + assert response.status_code == 200 |
| 2891 | + data = await response.get_json() |
| 2892 | + assert data["status"] == "error" |
| 2893 | + assert data["message"] == DESKTOP_MANAGED_RESTART_MESSAGE |
| 2894 | + assert calls == [] |
| 2895 | + |
| 2896 | + |
2829 | 2897 | @pytest.mark.asyncio |
2830 | 2898 | async def test_do_update_does_not_apply_files_when_package_verification_fails( |
2831 | 2899 | app: FastAPIAppAdapter, |
|
0 commit comments