Files
computer-playbook/tests/integration/roles/applications/id/test_basic.py
kevinveenbirkenbachandClaude Opus 5 e409674718 refactor(meta): centralize category/distro SPOTs
categories.yml moves from roles/ to the repository-root meta/, joining packages.yml. utils/roles/categories.py owns its location plus the tree-walking helpers that were stranded in entity/name.py, so no caller spells the path or duplicates the lookup.

meta/distros.yml becomes the SPOT for every distribution: os_family, Galaxy platform name, dev-environment base image, and the pkgmgr/pkgmgr-virgin/environment reference templates. It replaces seven scattered copies (DISTRO_FAMILY, VALID_DISTROS, _DISTROS, _CANONICAL_PLATFORMS, two shell arrays, a Makefile literal). INFINITO_DISTROS is no longer a static default but generated by utils/env/handlers/infinito/distros.py; the shell consumers read it through the env layer.

Drops dead CLI surface found along the way: --categories-file and --roles-dir on the provision CLI plus three unused parameters of generate_dynamic_inventory, and the positional roles_file of the invokable categories command.

tests/lint/repository/test_distros_spot.py pins the copies that cannot call the SPOT (workflow literals, docs table) and forbids composing a pkgmgr reference outside it.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-07-28 11:19:30 +02:00

62 lines
2.2 KiB
Python

import unittest
from pathlib import Path
from plugins.filter.invokable_paths import get_invokable_paths
from utils.cache.yaml import load_yaml_any
from utils.roles.categories import categories_file
from utils.roles.mapping import ROLE_FILE_VARS_MAIN
class TestSysRolesApplicationId(unittest.TestCase):
"""
Integration tests for sys-* roles based on categories.yml prefixes:
For each actual sys-* directory under roles/:
- If dash-joined prefix is in invokable_paths -> vars/main.yml must exist and contain application_id.
- Otherwise (non-invokable or undeclared) -> if vars/main.yml exists, it must NOT contain application_id.
"""
@classmethod
def setUpClass(cls):
from . import PROJECT_ROOT
cls.base_dir = str(PROJECT_ROOT)
cat_file = str(categories_file())
cls.invokable_prefixes = set(get_invokable_paths(cat_file))
roles_dir = Path(cls.base_dir) / "roles"
cls.actual_dirs = [
str(p)
for p in roles_dir.iterdir()
if p.is_dir() and p.name.startswith("sys-")
]
def test_sys_roles_application_id(self):
for role_dir in self.actual_dirs:
name = Path(role_dir).name
prefix = f"sys-{name.removeprefix('sys-')}"
vars_file = str(Path(role_dir) / ROLE_FILE_VARS_MAIN)
if prefix in self.invokable_prefixes:
self.assertTrue(
Path(vars_file).is_file(),
f"Missing vars/main.yml for invokable role {prefix}",
)
content = load_yaml_any(vars_file) or {}
self.assertIn(
"application_id",
content,
f"Expected 'application_id' in {vars_file} for invokable role {prefix}",
)
else:
if not Path(vars_file).is_file():
continue
content = load_yaml_any(vars_file) or {}
self.assertNotIn(
"application_id",
content,
f"Unexpected 'application_id' in {vars_file} for non-invokable role {prefix}",
)
if __name__ == "__main__":
unittest.main()
unittest.main()