@@ -1797,6 +1797,35 @@ async def mock_get_dashboard_version(*args, **kwargs):
17971797 assert data ["data" ]["has_new_version" ] is False
17981798
17991799
1800+ @pytest .mark .asyncio
1801+ async def test_restart_core_rejects_desktop_managed_backend (
1802+ app : Quart ,
1803+ authenticated_header : dict ,
1804+ core_lifecycle_td : AstrBotCoreLifecycle ,
1805+ monkeypatch ,
1806+ ):
1807+ test_client = app .test_client ()
1808+ restart_called = False
1809+
1810+ async def mock_restart ():
1811+ nonlocal restart_called
1812+ restart_called = True
1813+
1814+ monkeypatch .setenv ("ASTRBOT_DESKTOP_MANAGED" , "1" )
1815+ monkeypatch .setattr (core_lifecycle_td , "restart" , mock_restart )
1816+
1817+ response = await test_client .post (
1818+ "/api/stat/restart-core" ,
1819+ headers = authenticated_header ,
1820+ )
1821+
1822+ assert response .status_code == 200
1823+ data = await response .get_json ()
1824+ assert data ["status" ] == "error"
1825+ assert "desktop" in data ["message" ].lower ()
1826+ assert restart_called is False
1827+
1828+
18001829@pytest .mark .asyncio
18011830async def test_do_update (
18021831 app : Quart ,
@@ -1863,6 +1892,39 @@ async def mock_pip_install(*args, **kwargs):
18631892 assert progress_data ["data" ]["overall_percent" ] == 100
18641893
18651894
1895+ @pytest .mark .asyncio
1896+ async def test_do_update_rejects_desktop_managed_backend (
1897+ app : Quart ,
1898+ authenticated_header : dict ,
1899+ core_lifecycle_td : AstrBotCoreLifecycle ,
1900+ monkeypatch ,
1901+ ):
1902+ test_client = app .test_client ()
1903+ calls = []
1904+
1905+ async def mock_update (* args , ** kwargs ):
1906+ calls .append ("core" )
1907+
1908+ async def mock_restart ():
1909+ calls .append ("restart" )
1910+
1911+ monkeypatch .setenv ("ASTRBOT_DESKTOP_MANAGED" , "1" )
1912+ monkeypatch .setattr (core_lifecycle_td .astrbot_updator , "update" , mock_update )
1913+ monkeypatch .setattr (core_lifecycle_td , "restart" , mock_restart )
1914+
1915+ response = await test_client .post (
1916+ "/api/update/do" ,
1917+ headers = authenticated_header ,
1918+ json = {"version" : "v3.4.0" , "progress_id" : "desktop-progress" },
1919+ )
1920+
1921+ assert response .status_code == 200
1922+ data = await response .get_json ()
1923+ assert data ["status" ] == "error"
1924+ assert "desktop" in data ["message" ].lower ()
1925+ assert calls == []
1926+
1927+
18661928@pytest .mark .asyncio
18671929async def test_install_pip_package_returns_pip_install_error_message (
18681930 app : Quart ,
0 commit comments