From d88fe1d83ac118b79a39b6031cea117df750b106 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Wed, 30 Sep 2026 21:27:40 +0200 Subject: [PATCH] test(lint): let the legacy-path guard see the trees that still named the old layout `config/main.yml` exists in no role: f65f4d60fb migrated the last one. A guard against the string already exists, `TestNoLegacyPathReferences`, and it names `config/main.yml` among its LEGACY_TOKENS. It scanned plugins, utils, cli, roles, scripts, filter_plugins and lookup_plugins, which is every tree except the two the stale references actually lived in. So nine of them survived in `tests/`, and the guard reported green the whole time. The code underneath was already correct everywhere: `test_csp_consistency` and `test_role_wiring` iterate ROLE_FILE_META_SERVICES, and only their docstrings and one assertion message still said `config/main.yml`. Had any of them globbed the old path the test would have gone vacuous rather than red, which is the failure mode worth naming here. `tests` and `tasks` are now scanned. The targets come from `utils/roles/mapping.py`, not from guesswork: `config/main.yml` is `meta/services.yml`, `schema/main.yml` is `meta/secrets.yml` (confirmed at `cli/administration/inventory/provision/reset.py:67`, which reads exactly that file), and `users/main.yml` is `meta/users.yml`. Scanning `tasks` exposed a second dead pointer. The migration tool became a package on 2026-09-14, but EXEMPT_FILES still named `migrate_meta_layout.py`, a file that no longer exists, so the exemption was inert and only invisible because `tasks` went unscanned. Two dead pointers covering for each other. The exemption is now a directory, so a new module in that package cannot fall out of it. `test_no_direct_calls.py` named the same dead path in prose; that lint allows through nocheck markers at the call site, so nothing was broken there. `docs/administration/configuration/email.md` was the worst of them, because it instructed operators rather than describing tests: it told them to write `compose.services.email` into `roles//config/main.yml`. The consumer, `plugins/lookup/email.py:255`, reads `entry["services"]["email"]` and says in its own comment that there is no `compose.services` envelope. The role snippet, the inventory snippet and the precedence list now match the reader. `group_vars/all/TODO.md` pointed at the same dead file. Verified by watching the guard fail, twice. Re-introducing `config/main.yml` in a test file reports it; pointing the new directory exemption at a wrong path reports `tasks/utils/migrate_meta_layout/credentials.py`, which proves both that `tasks` is scanned and that the exemption is the only thing letting the migration tool through. Restored, 11 passed. The changelogs under `docs/changelog/` keep their mentions, and `.md` stays out of the scanned suffixes for that reason. Co-Authored-By: Claude Opus 5 (1M context) --- docs/administration/configuration/email.md | 23 ++++++++----------- group_vars/all/TODO.md | 2 +- .../ansible/inventory/test_manager.py | 2 +- .../infrastructure/services/README.md | 2 +- .../services/test_mailu_dependency.py | 2 +- .../roles/meta/server/test_csp_consistency.py | 2 +- .../services/prometheus/test_role_wiring.py | 4 ++-- tests/lint/ansible/roles/meta/test_layout.py | 12 ++++++++-- .../roles/web-app/integration/test_email.py | 2 +- .../repository/yaml/test_no_direct_calls.py | 2 +- .../provision/test_credentials_generator.py | 2 +- .../lookup/test_native_metrics_apps.py | 2 +- 12 files changed, 31 insertions(+), 26 deletions(-) diff --git a/docs/administration/configuration/email.md b/docs/administration/configuration/email.md index ab701da6fc..3a64f0b49a 100644 --- a/docs/administration/configuration/email.md +++ b/docs/administration/configuration/email.md @@ -38,18 +38,16 @@ overridden from inventory by setting the matching `SYSTEM_EMAIL_` variable ## Per-Application Overrides 🧩 Applications MAY override any subset of these keys under -`compose.services.email` in their role or inventory. +`services.email` in their role or inventory. Role defaults: ```yaml -# roles//config/main.yml -compose: - services: - email: - host: smtp.app.example.org - port: 587 - tls: true +# roles//meta/services.yml +email: + host: smtp.app.example.org + port: 587 + tls: true ``` Inventory overrides: @@ -58,10 +56,9 @@ Inventory overrides: # group_vars/.yml or host_vars/.yml applications: web-app-nextcloud: - compose: - services: - email: - username: nextcloud@example.org + services: + email: + username: nextcloud@example.org ``` Overrides are merged on top of the resolved defaults. Keys MUST use the short, @@ -71,7 +68,7 @@ lowercased names listed above. For each key, the first defined source wins: -1. `applications[''].compose.services.email.`, applied +1. `applications[''].services.email.`, applied only when an `application_id` is passed. 2. A `SYSTEM_EMAIL_` variable defined in inventory, group vars, or host vars. No such file ships with the project. This form is an escape hatch for diff --git a/group_vars/all/TODO.md b/group_vars/all/TODO.md index ea15d085fc..a26ed0cd82 100644 --- a/group_vars/all/TODO.md +++ b/group_vars/all/TODO.md @@ -1,5 +1,5 @@ # Todos - Remove *_ports.yml and*_networks.yml by a lookup function -- Move their values to the roles/*/config/main.yml file of each role +- Move their values to the roles/*/meta/services.yml file of each role - Implement validators (e.g. no overlappsing networks, unique ports) for all of this configurations diff --git a/tests/integration/ansible/inventory/test_manager.py b/tests/integration/ansible/inventory/test_manager.py index 9447307c6a..13907006d7 100644 --- a/tests/integration/ansible/inventory/test_manager.py +++ b/tests/integration/ansible/inventory/test_manager.py @@ -177,7 +177,7 @@ class TestInventoryManagerIntegration(TestCase): def test_apply_schema_skips_schema_less_transitive_provider_role(self): """ - Shared provider roles without schema/main.yml must be ignored gracefully. + Shared provider roles without meta/secrets.yml must be ignored gracefully. This matters for roles like web-svc-asset that participate in dependency discovery but do not define credentials. """ diff --git a/tests/integration/infrastructure/services/README.md b/tests/integration/infrastructure/services/README.md index ff51df69ee..8783ee97c8 100644 --- a/tests/integration/infrastructure/services/README.md +++ b/tests/integration/infrastructure/services/README.md @@ -1,6 +1,6 @@ # Service Registry Tests 🛰️ -Integration tests that validate the service registry discovered from `roles/*/config/main.yml`: canonical aliases are consistent, every service key resolves via `plugins/lookup/service.py`, `sys-svc-*` roles carry a `system_service_id` matching their folder, and transitive dependencies (e.g. dashboard → mailu) are declared correctly. +Integration tests that validate the service registry discovered from `roles/*/meta/services.yml`: canonical aliases are consistent, every service key resolves via `plugins/lookup/service.py`, `sys-svc-*` roles carry a `system_service_id` matching their folder, and transitive dependencies (e.g. dashboard → mailu) are declared correctly. Tests in this directory MUST only cover service-registry semantics. Tests for `application_id` identity MUST live under `tests/integration/roles/applications/id/`, and generic role-structure rules MUST live under `tests/integration/roles/`. diff --git a/tests/integration/infrastructure/services/test_mailu_dependency.py b/tests/integration/infrastructure/services/test_mailu_dependency.py index 0f4d306d73..727a514ec5 100644 --- a/tests/integration/infrastructure/services/test_mailu_dependency.py +++ b/tests/integration/infrastructure/services/test_mailu_dependency.py @@ -75,7 +75,7 @@ def _scan_role(role_path: Path) -> tuple[bool, bool]: class TestMailuServiceDependency(unittest.TestCase): """Every role that references 'web-app-mailu' or calls lookup('email', ...) must declare services.email with enabled: true and shared: true - in its config/main.yml.""" + in its meta/services.yml.""" def setUp(self): self.roles_root = PROJECT_ROOT / "roles" diff --git a/tests/integration/roles/meta/server/test_csp_consistency.py b/tests/integration/roles/meta/server/test_csp_consistency.py index de091aee24..99d90fbbfd 100644 --- a/tests/integration/roles/meta/server/test_csp_consistency.py +++ b/tests/integration/roles/meta/server/test_csp_consistency.py @@ -12,7 +12,7 @@ from . import PROJECT_ROOT class TestCspConfigurationConsistency(unittest.TestCase): """ - Iterate all roles; for each config/main.yml that defines 'csp', + Iterate all roles; for each meta/services.yml that defines 'csp', assert consistent structure and values: - csp is a dict - whitelist/flags/hashes are dicts if present diff --git a/tests/integration/roles/meta/services/prometheus/test_role_wiring.py b/tests/integration/roles/meta/services/prometheus/test_role_wiring.py index 95a6ab1878..6d80e75e17 100644 --- a/tests/integration/roles/meta/services/prometheus/test_role_wiring.py +++ b/tests/integration/roles/meta/services/prometheus/test_role_wiring.py @@ -51,7 +51,7 @@ class TestPrometheusServicePresence(unittest.TestCase): def test_all_web_roles_have_prometheus_service(self): """Every web-app-* and web-svc-* role must have services.prometheus.""" configs = self._web_role_configs() - self.assertTrue(configs, "No web-app-*/web-svc-* config/main.yml files found") + self.assertTrue(configs, "No web-app-*/web-svc-* meta/services.yml files found") errors = [] for file_path in configs: @@ -130,7 +130,7 @@ class TestPrometheusServicePresence(unittest.TestCase): "prom/blackbox-exporter:latest", content, "compose.yml.j2 must not use :latest for blackbox-exporter — pin to a version " - "via config/main.yml (services.blackbox-exporter.version)", + "via meta/services.yml (services.blackbox-exporter.version)", ) self.assertIn( "lookup('container_image', application_id, 'blackbox-exporter')", diff --git a/tests/lint/ansible/roles/meta/test_layout.py b/tests/lint/ansible/roles/meta/test_layout.py index d00bf9c15e..0d4944b1ed 100644 --- a/tests/lint/ansible/roles/meta/test_layout.py +++ b/tests/lint/ansible/roles/meta/test_layout.py @@ -100,6 +100,8 @@ class TestNoLegacyPathReferences(unittest.TestCase): "cli", "roles", "scripts", + "tasks", + "tests", "filter_plugins", "lookup_plugins", ) @@ -113,7 +115,11 @@ class TestNoLegacyPathReferences(unittest.TestCase): ) EXEMPT_FILES: ClassVar[set[Path]] = { - PROJECT_ROOT / "tasks" / "utils" / "migrate_meta_layout.py", + Path(__file__).resolve(), + } + + EXEMPT_DIRS: ClassVar[set[Path]] = { + PROJECT_ROOT / "tasks" / "utils" / "migrate_meta_layout", } def test_no_legacy_path_strings(self): @@ -130,7 +136,9 @@ class TestNoLegacyPathReferences(unittest.TestCase): continue if any(frag in path_str for frag in self.SKIP_FRAGMENTS): continue - if path in self.EXEMPT_FILES: + if path in self.EXEMPT_FILES or any( + path.is_relative_to(exempt) for exempt in self.EXEMPT_DIRS + ): continue try: text = read_text(path_str) diff --git a/tests/lint/ansible/roles/web-app/integration/test_email.py b/tests/lint/ansible/roles/web-app/integration/test_email.py index 3e0b083338..c1014ec70b 100644 --- a/tests/lint/ansible/roles/web-app/integration/test_email.py +++ b/tests/lint/ansible/roles/web-app/integration/test_email.py @@ -108,7 +108,7 @@ class TestWebAppRolesIntegrateEmail(unittest.TestCase): * Roles that call ``lookup('email', ...)`` **must** declare ``services.email`` with ``enabled: true`` AND ``shared: true`` - in ``config/main.yml``. Missing declarations fail the test hard. + in ``meta/services.yml``. Missing declarations fail the test hard. * Roles that do **not** call ``lookup('email', ...)`` and have no explicit opt-out block emit a non-blocking warning annotation. """ diff --git a/tests/lint/repository/yaml/test_no_direct_calls.py b/tests/lint/repository/yaml/test_no_direct_calls.py index f8da5d1bce..da36afa305 100644 --- a/tests/lint/repository/yaml/test_no_direct_calls.py +++ b/tests/lint/repository/yaml/test_no_direct_calls.py @@ -19,7 +19,7 @@ Allowed ======= * ``utils/cache/yaml.py``: IS the cache, MUST call ``yaml.safe_load`` / ``yaml.safe_dump`` directly. -* ``tasks/utils/migrate_meta_layout.py``: migration script that +* ``tasks/utils/migrate_meta_layout/``: migration package that operates pre-migration on raw on-disk YAML; predates the cache by design. * Tests that legitimately need raw YAML access (e.g. writing synthetic diff --git a/tests/unit/python/cli/administration/inventory/provision/test_credentials_generator.py b/tests/unit/python/cli/administration/inventory/provision/test_credentials_generator.py index c6a101ff58..c0ecbccae0 100644 --- a/tests/unit/python/cli/administration/inventory/provision/test_credentials_generator.py +++ b/tests/unit/python/cli/administration/inventory/provision/test_credentials_generator.py @@ -84,7 +84,7 @@ ansible_become_password: !vault | def test_generate_credentials_does_not_fail_for_roles_without_schema(self): """ Schema-less roles may still be passed to cli.administration.inventory.credentials - because credentials generation can be driven transitively from config/main.yml. + because credentials generation can be driven transitively from meta/services.yml. The generator must not crash if the snippet is empty. """ with tempfile.TemporaryDirectory() as tmpdir: diff --git a/tests/unit/python/plugins/lookup/test_native_metrics_apps.py b/tests/unit/python/plugins/lookup/test_native_metrics_apps.py index 00ae9be327..9f08e43c77 100644 --- a/tests/unit/python/plugins/lookup/test_native_metrics_apps.py +++ b/tests/unit/python/plugins/lookup/test_native_metrics_apps.py @@ -49,7 +49,7 @@ def _run( def _make_roles(tmp: Path, specs: dict) -> dict: """Create minimal role fixtures under tmp/ and return an applications dict. - In real Ansible, role config/main.yml defaults are merged into the + In real Ansible, role meta/services.yml defaults are merged into the `applications` variable before any play runs. This helper replicates that by building both the filesystem structure (for fragment discovery) and the applications dict (for get_app_conf lookups) from the same spec.