mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-06 10:59:59 +00:00
Run the python suites through pytest-xdist when pytest is importable (id-level collection parity with unittest discover verified per suite; serial unittest stays the fallback), with -rP so warnings printed by passing tests, like the update annotations, still reach the log. run.sh self-provisions the dev extras through scripts/install/dev-extras.sh, which stamps inside the venv and skips read-only venvs; make onboard pre-warms the same path in the running container. Hoist per-test cache resets and roles scans to setUpClass in the lookup and resolvable suites (a per-test fingerprint-memo reset closes an id()-reuse cache-poisoning flake the hoist exposed), inject generation names into the nfs backup script test instead of sleeping, and narrow ansible-lint scope to real ansible content. ansible-lint additionally sits behind a content fingerprint gate that skips the run when nothing it walks has changed; without a usable git (container bind mounts) the gate disables itself and the full run remains. Drop the import-linter layer and ignore for the deleted deps module; the contract now locks compose -> common -> env. Measured on the host: unit 101s to 20s, integration 90s to 24s, lint tests 43s to 19s, repeated ansible-lint 53s to 0.4s. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
72 lines
2.3 KiB
Python
72 lines
2.3 KiB
Python
import unittest
|
|
|
|
from plugins.lookup.service import LookupModule
|
|
from utils.roles.applications.services.registry import (
|
|
build_service_registry_from_roles_dir,
|
|
load_applications_from_roles_dir,
|
|
)
|
|
|
|
from . import PROJECT_ROOT
|
|
|
|
|
|
class TestServicesResolvable(unittest.TestCase):
|
|
"""Discovered service keys and provider roles must resolve via the service lookup."""
|
|
|
|
@classmethod
|
|
def setUpClass(cls):
|
|
cls.repo_root = PROJECT_ROOT
|
|
cls.roles_dir = cls.repo_root / "roles"
|
|
cls.applications = load_applications_from_roles_dir(cls.roles_dir)
|
|
cls.service_registry = build_service_registry_from_roles_dir(cls.roles_dir)
|
|
|
|
def setUp(self):
|
|
self.assertGreater(
|
|
len(self.service_registry),
|
|
0,
|
|
"discovered service registry must not be empty",
|
|
)
|
|
|
|
def _run(self, term):
|
|
return LookupModule().run(
|
|
[term],
|
|
variables={
|
|
"applications": self.applications,
|
|
"group_names": [],
|
|
},
|
|
service_registry=self.service_registry,
|
|
)[0]
|
|
|
|
def test_all_keys_resolvable(self):
|
|
for key in self.service_registry:
|
|
with self.subTest(key=key):
|
|
result = self._run(key)
|
|
self.assertEqual(result["id"], key)
|
|
|
|
def test_all_primary_roles_resolve_to_primary_key(self):
|
|
seen_roles = set()
|
|
for key, entry in self.service_registry.items():
|
|
if "canonical" in entry:
|
|
continue
|
|
role = entry.get("role")
|
|
if not role or role in seen_roles:
|
|
continue
|
|
seen_roles.add(role)
|
|
with self.subTest(role=role, expected_key=key):
|
|
result = self._run(role)
|
|
self.assertEqual(result["role"], role)
|
|
self.assertEqual(result["id"], key)
|
|
|
|
def test_key_and_role_produce_identical_result_for_primary_keys(self):
|
|
for key, entry in self.service_registry.items():
|
|
if "canonical" in entry:
|
|
continue
|
|
role = entry.get("role")
|
|
if not role:
|
|
continue
|
|
with self.subTest(key=key):
|
|
self.assertEqual(self._run(key), self._run(role))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|