mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-11-09 19:09:41 +00:00
* Store and persist OS upgrade map to fix update path evaluation The existing logic calculated OS upgrade paths inline during fetch_data, which will not get reevaluted when the current OS is unsupported (JobCondition.OS_SUPPORTED). E.g. after updating from 11.4 to 11.5, the system wouldn't offer the next available update (15.2) because the upgrade path calculation relied on fresh data from the blocked fetch operation. Changes: - Add ATTR_HASSOS_UPGRADE constant and schema validation - Store hassos-upgrade map from version JSON in updater data - Refactor version_hassos property to use stored upgrade map instead of inline calculation during fetch_data - Maintain upgrade path logic: upgrade within major version first, then jump to next major version when at the latest in current major - Add type safety checks for version.major access This ensures upgrade paths work correctly even when update data refresh is blocked due to unsupported OS versions, fixing the scenario where HAOS 11.5 wouldn't show 15.2 as the next available update. * Update supervisor/updater.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Address mypy issue * Fix pytest --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
98 lines
2.7 KiB
Python
98 lines
2.7 KiB
Python
"""Test Supervisor API."""
|
|
|
|
# pylint: disable=protected-access
|
|
from unittest.mock import AsyncMock, patch
|
|
|
|
from aiohttp.test_utils import TestClient
|
|
|
|
from supervisor.api.const import ATTR_AVAILABLE_UPDATES
|
|
from supervisor.coresys import CoreSys
|
|
|
|
from tests.const import TEST_ADDON_SLUG
|
|
|
|
|
|
async def test_api_info(api_client):
|
|
"""Test docker info api."""
|
|
resp = await api_client.get("/info")
|
|
result = await resp.json()
|
|
|
|
assert result["data"]["supervisor"] == "9999.09.9.dev9999"
|
|
assert result["data"]["docker"] == "1.0.0"
|
|
assert result["data"]["supported"] is True
|
|
assert result["data"]["channel"] == "stable"
|
|
assert result["data"]["logging"] == "info"
|
|
assert result["data"]["timezone"] == "Etc/UTC"
|
|
|
|
|
|
async def test_api_available_updates(
|
|
install_addon_ssh,
|
|
api_client,
|
|
coresys: CoreSys,
|
|
):
|
|
"""Test available_updates."""
|
|
installed_addon = coresys.addons.get(TEST_ADDON_SLUG)
|
|
installed_addon.persist["version"] = "1.2.3"
|
|
|
|
async def available_updates():
|
|
return (await (await api_client.get("/available_updates")).json())["data"][
|
|
ATTR_AVAILABLE_UPDATES
|
|
]
|
|
|
|
updates = await available_updates()
|
|
assert len(updates) == 1
|
|
assert updates[-1] == {
|
|
"icon": None,
|
|
"name": "Terminal & SSH",
|
|
"panel_path": "/update-available/local_ssh",
|
|
"update_type": "addon",
|
|
"version_latest": "9.2.1",
|
|
}
|
|
|
|
coresys.updater._data["hassos_unrestricted"] = "321"
|
|
coresys.os._version = "123"
|
|
updates = await available_updates()
|
|
assert len(updates) == 2
|
|
assert updates[0] == {
|
|
"panel_path": "/update-available/os",
|
|
"update_type": "os",
|
|
"version_latest": "321",
|
|
}
|
|
|
|
coresys.updater._data["homeassistant"] = "321"
|
|
coresys.homeassistant.version = "123"
|
|
updates = await available_updates()
|
|
assert len(updates) == 3
|
|
assert updates[0] == {
|
|
"panel_path": "/update-available/core",
|
|
"update_type": "core",
|
|
"version_latest": "321",
|
|
}
|
|
|
|
|
|
async def test_api_refresh_updates(api_client, coresys: CoreSys):
|
|
"""Test docker info api."""
|
|
|
|
coresys.updater.reload = AsyncMock()
|
|
coresys.store.reload = AsyncMock()
|
|
|
|
resp = await api_client.post("/refresh_updates")
|
|
assert resp.status == 200
|
|
|
|
assert coresys.updater.reload.called
|
|
assert coresys.store.reload.called
|
|
|
|
|
|
async def test_api_reload_updates(
|
|
coresys: CoreSys,
|
|
api_client: TestClient,
|
|
):
|
|
"""Test reload updates."""
|
|
with (
|
|
patch("supervisor.updater.Updater.fetch_data") as fetch_data,
|
|
):
|
|
resp = await api_client.post("/reload_updates")
|
|
|
|
fetch_data.assert_called_once_with()
|
|
|
|
assert resp.status == 200
|