mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-06 19:01:54 +00:00
Every script a role ships now lives under `files/<language>/`, and the unit
suite is split the same way: `tests/unit/python/` beside new sibling trees for
the other languages. `tests/lint/filesystem/test_role_files_layout.py` keeps it
that way; directories whose shape is dictated from outside carry a `.nocheck`
naming the constraint (Docker build contexts, WordPress mu-plugins, the Joomla
extension, Odoo addons, Playwright suites, the `files/test/test.sh` harness
that `test-e2e-cli` resolves generically).
This cannot be applied in halves. Moving a file and repointing what names it
are the same change: 14 references resolve only at deploy time, so the tree is
green either before or after, never between.
Those 14 were found by static resolution over every reference class, not by the
test suite -- a full `make quality-high` was green while all of them were
broken:
* 7 `src:` values built from a role variable holding a bare filename
(svc-bkp-remote-2-local, decidim, espocrm, friendica, joomla, pixelfed x2).
The variable doubles as the destination name inside the container, so the
language segment belongs at the call site, not in the variable.
* `sys-service/tasks/04_base.yml` resolved every consumer's systemd script
through `first_found(..., errors='strict')` over `files/script.{sh,py}`.
18 roles ship exactly that and have no template fallback: the play would
have died on each.
* `sys-front-inj-javascript` fell back to `<role>/files/javascript.js`; the
interface now reads `files/javascript/javascript.js`.
* `sys-front-inj-logout/templates/head_sub.j2` built the cache-busting mtime
path through `path_absolute(... 'files', ...)`.
* 4 `ansible.builtin.script:` invocations naming a bare command
(pull.py, prune.sh, set_postgres_superuser_password.sh, ganesha-serve.sh).
* `dev-python/files/shell/install.sh` pointed at a sibling role's script.
Depth-dependent paths inside the moved trees were bumped accordingly: 59
`parents[N]` computations, 12 relative climbs, and the per-role recover CLI,
whose path `cli/administration/recover/recoverers.py` still assembled from the
pre-move location.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
161 lines
5.6 KiB
Python
161 lines
5.6 KiB
Python
from __future__ import annotations
|
|
|
|
import textwrap
|
|
import unittest
|
|
from pathlib import Path
|
|
from unittest.mock import patch
|
|
|
|
from utils.cache.yaml import load_yaml_str
|
|
from utils.docker.image.discovery import iter_role_images
|
|
from utils.roles.mapping import ROLE_FILE_META_SERVICES
|
|
|
|
|
|
def _make_fs(files: dict[str, str]) -> dict[Path, str]:
|
|
return {Path(k): textwrap.dedent(v) for k, v in files.items()}
|
|
|
|
|
|
class TestIterRoleImagesMetaServices(unittest.TestCase):
|
|
"""iter_role_images reads meta/services.yml → services (any registry)."""
|
|
|
|
def _run(self, fs: dict[str, str]) -> list:
|
|
real_fs = _make_fs(fs)
|
|
|
|
def fake_glob(self, pattern: str):
|
|
return [p for p in real_fs if p.match(pattern)]
|
|
|
|
def fake_load(path: Path) -> dict:
|
|
|
|
content = real_fs.get(path, "")
|
|
return load_yaml_str(content) or {}
|
|
|
|
with (
|
|
patch.object(Path, "glob", fake_glob),
|
|
patch("utils.docker.image.discovery.load_yaml", side_effect=fake_load),
|
|
):
|
|
return list(iter_role_images(Path("/repo")))
|
|
|
|
def test_mcr_playwright_image(self):
|
|
refs = self._run(
|
|
{
|
|
f"roles/test-e2e-playwright/{ROLE_FILE_META_SERVICES}": """
|
|
playwright:
|
|
image: mcr.microsoft.com/playwright
|
|
version: v1.58.2-noble
|
|
""",
|
|
}
|
|
)
|
|
self.assertEqual(len(refs), 1)
|
|
ref = refs[0]
|
|
self.assertEqual(ref.role, "test-e2e-playwright")
|
|
self.assertEqual(ref.service, "playwright")
|
|
self.assertEqual(ref.name, "playwright")
|
|
self.assertEqual(ref.version, "v1.58.2-noble")
|
|
self.assertEqual(ref.registry, "mcr.microsoft.com")
|
|
self.assertEqual(ref.source, "mcr.microsoft.com/playwright:v1.58.2-noble")
|
|
self.assertEqual(ref.source_file, ROLE_FILE_META_SERVICES)
|
|
|
|
def test_ghcr_image_strips_registry_from_name(self):
|
|
refs = self._run(
|
|
{
|
|
f"roles/web-app-matrix/{ROLE_FILE_META_SERVICES}": """
|
|
matrix-chatgpt-bot:
|
|
image: ghcr.io/matrixgpt/matrix-chatgpt-bot
|
|
version: latest
|
|
""",
|
|
}
|
|
)
|
|
self.assertEqual(len(refs), 1)
|
|
ref = refs[0]
|
|
self.assertEqual(ref.name, "matrixgpt/matrix-chatgpt-bot")
|
|
self.assertEqual(ref.registry, "ghcr.io")
|
|
self.assertEqual(ref.source, "ghcr.io/matrixgpt/matrix-chatgpt-bot:latest")
|
|
self.assertEqual(ref.source_file, ROLE_FILE_META_SERVICES)
|
|
|
|
def test_missing_image_or_version_is_skipped(self):
|
|
refs = self._run(
|
|
{
|
|
f"roles/some-role/{ROLE_FILE_META_SERVICES}": """
|
|
no-version:
|
|
image: ghcr.io/foo/bar
|
|
no-image:
|
|
version: "1.0"
|
|
""",
|
|
}
|
|
)
|
|
self.assertEqual(refs, [])
|
|
|
|
def test_no_image_keys_yields_nothing(self):
|
|
refs = self._run(
|
|
{
|
|
f"roles/some-role/{ROLE_FILE_META_SERVICES}": """
|
|
some-svc:
|
|
lifecycle: beta
|
|
""",
|
|
}
|
|
)
|
|
self.assertEqual(refs, [])
|
|
|
|
def test_meta_services_ghcr_image(self):
|
|
refs = self._run(
|
|
{
|
|
f"roles/web-app-matrix/{ROLE_FILE_META_SERVICES}": """
|
|
matrix-chatgpt-bot:
|
|
image: ghcr.io/matrixgpt/matrix-chatgpt-bot
|
|
version: latest
|
|
""",
|
|
}
|
|
)
|
|
self.assertEqual(len(refs), 1)
|
|
ref = refs[0]
|
|
self.assertEqual(ref.role, "web-app-matrix")
|
|
self.assertEqual(ref.service, "matrix-chatgpt-bot")
|
|
self.assertEqual(ref.name, "matrixgpt/matrix-chatgpt-bot")
|
|
self.assertEqual(ref.registry, "ghcr.io")
|
|
self.assertEqual(ref.source, "ghcr.io/matrixgpt/matrix-chatgpt-bot:latest")
|
|
self.assertEqual(ref.source_file, ROLE_FILE_META_SERVICES)
|
|
|
|
def test_gitlab_registry_image_strips_registry_from_name(self):
|
|
refs = self._run(
|
|
{
|
|
f"roles/web-app-gitlab/{ROLE_FILE_META_SERVICES}": """
|
|
webservice:
|
|
image: registry.gitlab.com/gitlab-org/build/cng/gitlab-webservice-ce
|
|
version: v19.1.1
|
|
""",
|
|
}
|
|
)
|
|
self.assertEqual(len(refs), 1)
|
|
ref = refs[0]
|
|
self.assertEqual(ref.role, "web-app-gitlab")
|
|
self.assertEqual(ref.service, "webservice")
|
|
self.assertEqual(ref.name, "gitlab-org/build/cng/gitlab-webservice-ce")
|
|
self.assertEqual(ref.registry, "registry.gitlab.com")
|
|
self.assertEqual(
|
|
ref.source,
|
|
"registry.gitlab.com/gitlab-org/build/cng/gitlab-webservice-ce:v19.1.1",
|
|
)
|
|
self.assertEqual(ref.source_file, ROLE_FILE_META_SERVICES)
|
|
|
|
def test_opencode_gitlab_image_strips_registry_from_name(self):
|
|
refs = self._run(
|
|
{
|
|
f"roles/web-app-opentalk/{ROLE_FILE_META_SERVICES}": """
|
|
controller:
|
|
image: registry.opencode.de/opentalk/controller
|
|
version: v0.33.2
|
|
""",
|
|
}
|
|
)
|
|
self.assertEqual(len(refs), 1)
|
|
ref = refs[0]
|
|
self.assertEqual(ref.role, "web-app-opentalk")
|
|
self.assertEqual(ref.service, "controller")
|
|
self.assertEqual(ref.name, "opentalk/controller")
|
|
self.assertEqual(ref.registry, "registry.opencode.de")
|
|
self.assertEqual(ref.source, "registry.opencode.de/opentalk/controller:v0.33.2")
|
|
self.assertEqual(ref.source_file, ROLE_FILE_META_SERVICES)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|