Files
computer-playbook/tests/unit/python/utils/cache/test_gitignore.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

43 lines
1.4 KiB
Python

from __future__ import annotations
import tempfile
import unittest
from pathlib import Path
from utils.cache import gitignore
from utils.roles.custom import ROLES_GLOB
from utils.roles.mapping import ROLE_FILE_TASKS_MAIN
class TestLoadGitignorePatterns(unittest.TestCase):
def setUp(self) -> None:
tmp = tempfile.TemporaryDirectory()
self.addCleanup(tmp.cleanup)
self.addCleanup(gitignore._reset)
self.root = Path(tmp.name)
(self.root / ".gitignore").write_text(
f"# comment\n*.log\n{ROLES_GLOB}\n!keep.log\nbuild/*\n", encoding="utf-8"
)
def test_reads_plain_patterns(self):
patterns = gitignore.load_gitignore_patterns(str(self.root))
self.assertEqual(("*.log", "build/*"), patterns)
def test_pulled_custom_roles_stay_in_the_scanned_tree(self):
patterns = gitignore.load_gitignore_patterns(str(self.root))
self.assertFalse(
gitignore.is_path_gitignored(
f"roles/web-app-cst-demo/{ROLE_FILE_TASKS_MAIN}", patterns
)
)
def test_ignored_files_inside_a_custom_role_stay_ignored(self):
patterns = gitignore.load_gitignore_patterns(str(self.root))
self.assertTrue(
gitignore.is_path_gitignored("roles/web-app-cst-demo/debug.log", patterns)
)
if __name__ == "__main__":
unittest.main()