Files
computer-playbook/tests/unit/python/utils/roles/test_custom.py
T
kevinveenbirkenbachandClaude Opus 5.5 d92375922d feat(roles): pull custom roles from inventory-declared sources
An inventory group web-app-cst-<name> with applications.<id>.custom: true and
a pinned source {url, version, path} is pulled into roles/ before the play,
read raw (Jinja, Ansible tags and credential URLs refused), placed through a
staging directory under an exclusive lock, and owned by a marker that names
its own directory, so a pull or roles-clean never replaces or removes a
directory it did not place and a failed pull leaves roles/ as it was.
Directory inventories, host lists and non-UTF-8 files behave as Ansible
reads them; generated test deploys pass --skip-pull. make roles-pull,
roles-clean and roles list, INFINITO_EXTRA_MOUNTS for local sources, the
web-app-cst category, the reserved prefix lint and a central
repository_files() that also yields the gitignored custom roles let every
lint scan them like in-tree roles. Supersedes the uncommitted 045 External
Roles draft and reuses its fetch, sync and mount design.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-29 00:02:58 +01:00

40 lines
1.1 KiB
Python

from __future__ import annotations
import unittest
from utils.roles.custom import is_custom, is_custom_path
from utils.roles.mapping import ROLE_FILE_TASKS_MAIN
class TestIsCustom(unittest.TestCase):
def test_reserved_prefix_is_custom(self):
self.assertTrue(is_custom("web-app-cst-security-check"))
def test_in_tree_application_is_not_custom(self):
self.assertFalse(is_custom("web-app-nextcloud"))
def test_category_name_alone_is_not_custom(self):
self.assertFalse(is_custom("web-app-cst"))
class TestIsCustomPath(unittest.TestCase):
def test_file_in_a_placed_custom_role(self):
self.assertTrue(
is_custom_path(f"roles/web-app-cst-store/{ROLE_FILE_TASKS_MAIN}")
)
def test_file_in_an_in_tree_role(self):
self.assertFalse(
is_custom_path(f"roles/web-app-nextcloud/{ROLE_FILE_TASKS_MAIN}")
)
def test_custom_prefix_outside_roles(self):
self.assertFalse(is_custom_path("docs/web-app-cst-store/README.md"))
def test_roles_directory_itself(self):
self.assertFalse(is_custom_path("roles"))
if __name__ == "__main__":
unittest.main()