From cd66b95e185288870c1e3914676af415c2c7faeb Mon Sep 17 00:00:00 2001 From: Artur Pragacz <49985303+arturpragacz@users.noreply.github.com> Date: Sun, 29 Nov 2026 19:16:33 +0100 Subject: [PATCH] Remove import violation skip from hassfest circular dependency check (#195165) --- script/hassfest/dependencies.py | 3 -- tests/script/hassfest/test_dependencies.py | 55 ++++++++++++++++++++++ 2 files changed, 55 insertions(+), 3 deletions(-) diff --git a/script/hassfest/dependencies.py b/script/hassfest/dependencies.py index 3cceba58534b..1a46ed10cf63 100644 --- a/script/hassfest/dependencies.py +++ b/script/hassfest/dependencies.py @@ -318,9 +318,6 @@ def _check_circular_deps( def _validate_circular_dependencies(integrations: dict[str, Integration]) -> None: for integration in integrations.values(): - if integration.domain in IGNORE_VIOLATIONS: - continue - _check_circular_deps( integrations, integration.domain, integration, set(), deque() ) diff --git a/tests/script/hassfest/test_dependencies.py b/tests/script/hassfest/test_dependencies.py index 89d87780bb48..f9390c8d695a 100644 --- a/tests/script/hassfest/test_dependencies.py +++ b/tests/script/hassfest/test_dependencies.py @@ -8,6 +8,7 @@ import pytest from script.hassfest.dependencies import ( CORE_INTEGRATIONS, ImportCollector, + _validate_circular_dependencies, _validate_dependencies, ) @@ -133,6 +134,60 @@ def test_dependency_on_non_core_integration_allowed(config: Config) -> None: assert consumer.errors == [] +@pytest.mark.parametrize( + "domain", + [ + pytest.param("consumer", id="regular"), + pytest.param("logbook", id="import_check_exempt"), + ], +) +@pytest.mark.parametrize( + ("manifest_key", "error"), + [ + pytest.param( + "dependencies", + "Found a circular dependency with other ({domain}, other)", + id="dependencies", + ), + pytest.param( + "after_dependencies", + "Found a circular dependency with after dependencies of other" + " ({domain}, other)", + id="after_dependencies", + ), + ], +) +def test_circular_dependency_rejected( + config: Config, domain: str, manifest_key: str, error: str +) -> None: + """Test that a circular dependency is rejected.""" + integration = get_integration(domain, config) + integration.manifest["dependencies"] = ["other"] + other = get_integration("other", config) + other.manifest[manifest_key] = [domain] + + _validate_circular_dependencies({domain: integration, "other": other}) + + assert [err.error for err in integration.errors] == [error.format(domain=domain)] + + +def test_no_circular_dependency_allowed(config: Config) -> None: + """Test that a dependency chain without a cycle is not rejected.""" + consumer = get_integration("consumer", config) + consumer.manifest["dependencies"] = ["other"] + other = get_integration("other", config) + other.manifest["after_dependencies"] = ["third"] + integrations = { + "consumer": consumer, + "other": other, + "third": get_integration("third", config), + } + + _validate_circular_dependencies(integrations) + + assert [integration.errors for integration in integrations.values()] == [[], [], []] + + def test_core_integrations_in_sync_with_bootstrap() -> None: """Test the duplicated CORE_INTEGRATIONS stays aligned with bootstrap.""" # Imported here so the rest of the hassfest tests are not slowed down