feat(variants): let a variant dictate the config of the providers it pulls in

A round deploys a provider once, so the role that pulls it in is the only place that can say how lean it has to be. A variant entry may now carry any application config topic under a service it depends on: a mapping deep-merges, so naming one key changes that key alone, and null empties the topic. Empty was the case that needed a marker of its own, because merging an empty mapping is a no-op and would leave exactly the services the round was trying to shed.

The topic vocabulary and the merge semantics live in utils.roles.applications.topics, which is also where resources.py now gets them rather than spelling the same null-or-merge out a second time. Collecting who demands what stays in the inventory tree, refuses two roles demanding different values for one provider in the same round, and skips a role's own entity entry so the existing services.<own>.users declarations are not read as overrides.

The CI set-cover learns the same fact. Its greedy cover retires a role's variant-0 row when an earlier row of another role embeds it, on the stated premise that embedding pulls the provider's variant 0. A variant that dictates that provider's config breaks the premise from the other side: whatever ran, it was not the provider as the provider declares it. Such a pair now covers nothing, so the retired row keeps its job, its artefact and its verdict.

Measured on the current tree: 20 override pairs, 41 covered rows before and after, so nothing is revoked today. The rule bites the moment an override lands in a row that covers.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
kevinveenbirkenbachandClaude Opus 5 committed 2026-09-01 21:08:08 +02:00
1 parent 791eee7c9f
commit f1635e6a59
31 files changed
+712 -25

No files matched your search

@@ -0,0 +1,91 @@
"""Unit tests for `cli.administration.deploy.development.inventory.nested_overrides`.
The service registry is stubbed: what matters is which role a claim is
attributed to, not how a service key resolves to its provider.
"""
from __future__ import annotations
import unittest
from unittest.mock import patch
from cli.administration.deploy.development.inventory.nested_overrides import (
NestedOverrideConflictError,
collect_provider_overrides,
)
_REGISTRY = {
"openwebui": {"role": "web-app-openwebui"},
"gitea": {"role": "web-app-gitea"},
}
_PATCH = (
"cli.administration.deploy.development.inventory.nested_overrides"
".build_service_registry_from_roles_dir"
)
class TestCollectProviderOverrides(unittest.TestCase):
def _collect(self, payloads, registry=None):
with patch(_PATCH, autospec=True) as build:
build.return_value = _REGISTRY if registry is None else registry
return collect_provider_overrides(payloads, roles_dir="/roles")
def test_a_named_topic_reaches_its_provider(self) -> None:
payloads = {
"web-app-moodle": {"services": {"openwebui": {"services": None}}},
}
self.assertEqual(
{"web-app-openwebui": {"services": None}}, self._collect(payloads)
)
def test_several_topics_of_one_provider_are_collected_together(self) -> None:
payloads = {
"web-app-moodle": {
"services": {
"openwebui": {"services": None, "addons": {"whisper": False}},
},
},
}
self.assertEqual(
{"web-app-openwebui": {"services": None, "addons": {"whisper": False}}},
self._collect(payloads),
)
def test_a_roles_own_entry_is_not_an_override(self) -> None:
payloads = {"web-app-gitea": {"services": {"gitea": {"users": {"a": 1}}}}}
self.assertEqual({}, self._collect(payloads))
def test_an_unregistered_service_key_is_skipped(self) -> None:
payloads = {"web-app-moodle": {"services": {"nowhere": {"services": None}}}}
self.assertEqual({}, self._collect(payloads))
def test_two_roles_agreeing_is_not_a_conflict(self) -> None:
payloads = {
"web-app-moodle": {"services": {"openwebui": {"services": None}}},
"web-app-gitea": {"services": {"openwebui": {"services": None}}},
}
self.assertEqual(
{"web-app-openwebui": {"services": None}}, self._collect(payloads)
)
def test_two_roles_demanding_different_values_raises(self) -> None:
payloads = {
"web-app-moodle": {"services": {"openwebui": {"services": None}}},
"web-app-gitea": {"services": {"openwebui": {"services": {"a": 1}}}},
}
with self.assertRaises(NestedOverrideConflictError):
self._collect(payloads)
def test_a_round_without_overrides_never_builds_the_registry(self) -> None:
payloads = {"web-app-moodle": {"services": {"openwebui": {"enabled": True}}}}
with patch(_PATCH, autospec=True) as build:
build.return_value = _REGISTRY
self.assertEqual(
{}, collect_provider_overrides(payloads, roles_dir="/roles")
)
build.assert_not_called()
if __name__ == "__main__":
unittest.main()