mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-12-05 09:18:53 +00:00
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:
1 parent
791eee7c9f
commit
f1635e6a59
31 files changed
+712
-25
No files matched your search
@@ -0,0 +1,66 @@
|
||||
"""Unit tests for ``utils/roles/applications/topics.py``.
|
||||
|
||||
The three override shapes have to stay distinguishable: ``null`` empties,
|
||||
``{}`` is a no-op, and a mapping changes the keys it names and nothing else.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import unittest
|
||||
|
||||
from utils.cache.files import PROJECT_ROOT
|
||||
from utils.roles.applications.topics import (
|
||||
CONFIG_TOPICS,
|
||||
apply_topic,
|
||||
overridden_providers,
|
||||
)
|
||||
|
||||
|
||||
class TestApplyTopic(unittest.TestCase):
|
||||
def test_null_empties_the_topic(self):
|
||||
self.assertEqual({}, apply_topic({"a": {"enabled": True}}, None))
|
||||
|
||||
def test_an_empty_mapping_changes_nothing(self):
|
||||
base = {"a": {"enabled": True}}
|
||||
self.assertEqual(base, apply_topic(base, {}))
|
||||
|
||||
def test_a_mapping_merges_the_named_keys_only(self):
|
||||
base = {"a": {"enabled": True}, "b": {"enabled": True}}
|
||||
self.assertEqual(
|
||||
{"a": {"enabled": False}, "b": {"enabled": True}},
|
||||
apply_topic(base, {"a": {"enabled": False}}),
|
||||
)
|
||||
|
||||
def test_a_missing_base_still_takes_the_override(self):
|
||||
self.assertEqual({"a": 1}, apply_topic(None, {"a": 1}))
|
||||
|
||||
def test_the_vocabulary_covers_the_topics_a_variant_can_name(self):
|
||||
self.assertIn("services", CONFIG_TOPICS)
|
||||
self.assertIn("addons", CONFIG_TOPICS)
|
||||
self.assertNotIn("enabled", CONFIG_TOPICS)
|
||||
|
||||
|
||||
class TestOverriddenProviders(unittest.TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls) -> None:
|
||||
cls.found = overridden_providers(PROJECT_ROOT / "roles")
|
||||
|
||||
def test_the_scan_finds_the_declared_overrides(self) -> None:
|
||||
self.assertTrue(self.found)
|
||||
|
||||
def test_a_role_never_records_itself(self) -> None:
|
||||
self.assertEqual(
|
||||
[],
|
||||
[(role, i) for (role, i), targets in self.found.items() if role in targets],
|
||||
)
|
||||
|
||||
def test_every_target_is_a_role_that_exists(self) -> None:
|
||||
roles = {p.name for p in (PROJECT_ROOT / "roles").iterdir() if p.is_dir()}
|
||||
missing = sorted(
|
||||
{target for targets in self.found.values() for target in targets} - roles
|
||||
)
|
||||
self.assertEqual([], missing)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user