1
0
mirror of https://github.com/home-assistant/supervisor.git synced 2025-12-24 20:35:55 +00:00

Avoid reordering add-on repositories on Backup load (#5595)

* Avoid reordering add-on repositories on Backup load

The `ensure_builtin_repositories` function uses a set to deduplicate
items, which sometimes led to a change of order in elements. This is
problematic when deduplicating Backups.

Simply avoid mangling the list of add-on repositories on load. Instead
rely on `update_repositories` which uses the same function to ensure
built-in repositories when loading the store configuration and restoring
a backup file.

* Update tests

* ruff format

* ruff check

* ruff check fixes

* ruff format

* Update tests/store/test_validate.py

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* Simplify test

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
This commit is contained in:
Stefan Agner
2025-01-31 18:10:47 +01:00
committed by GitHub
parent 30cbb039d0
commit 9491b1ff89
4 changed files with 42 additions and 51 deletions

View File

@@ -1,45 +1,14 @@
"""Test schema validation."""
from typing import Any
import pytest
from voluptuous import Invalid
from supervisor.const import ATTR_REPOSITORIES
from supervisor.store.validate import SCHEMA_STORE_FILE, repositories
@pytest.mark.parametrize(
"config",
[
{},
{ATTR_REPOSITORIES: []},
{ATTR_REPOSITORIES: ["https://github.com/esphome/home-assistant-addon"]},
],
)
async def test_default_config(config: dict[Any]):
"""Test built-ins included by default."""
conf = SCHEMA_STORE_FILE(config)
assert ATTR_REPOSITORIES in conf
assert "core" in conf[ATTR_REPOSITORIES]
assert "local" in conf[ATTR_REPOSITORIES]
assert "https://github.com/hassio-addons/repository" in conf[ATTR_REPOSITORIES]
assert (
len(
[
repo
for repo in conf[ATTR_REPOSITORIES]
if repo == "https://github.com/esphome/home-assistant-addon"
]
)
== 1
)
from supervisor.store.validate import repositories
@pytest.mark.parametrize(
"repo_list,valid",
[
([], True),
(["core", "local"], True),
(["https://github.com/hassio-addons/repository"], True),
(["not_a_url"], False),
@@ -49,15 +18,7 @@ async def test_default_config(config: dict[Any]):
async def test_repository_validate(repo_list: list[str], valid: bool):
"""Test repository list validate."""
if valid:
processed = repositories(repo_list)
assert len(processed) == 5
assert set(repositories(repo_list)) == {
"core",
"local",
"https://github.com/hassio-addons/repository",
"https://github.com/esphome/home-assistant-addon",
"https://github.com/music-assistant/home-assistant-addon",
}
assert repositories(repo_list) == repo_list
else:
with pytest.raises(Invalid):
repositories(repo_list)