Files
computer-playbook/tests/external/update/addons/test_addon_versions.py
kevinveenbirkenbachandClaude Opus 5 575a5a87ac refactor(layout): sort shipped scripts by language and split the unit suite
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>
2026-08-22 01:31:09 +02:00

77 lines
3.0 KiB
Python

"""Opt-in external drift checker for unified addons.
For every addon in ``roles/*/meta/addons/*.yml`` carrying
``update.monitored: true`` this test surfaces, as warnings only, when a
supported catalog adapter reports a newer upstream version, and when a
catalog adapter discovers a relevant addon that is not yet declared.
It mirrors the Docker image / repository-ref external checks:
* warn-only: it NEVER fails the session, so registry slowness or outages do
not break validation;
* opt-in: it runs through ``make test-external``, not the default
``make test`` flow (the live registry calls would otherwise flake CI);
* bounded: discovery is limited to the curated adapters in
``utils.update.addons.SUPPORTED_CATALOGS``, so broad public marketplaces
(the full WordPress plugin directory, the whole GNOME extensions site)
never produce unreviewable warning noise.
The reconciliation core (``discover_addon_updates``) is pure and is exercised
with fixture catalogs by the unit suite
(``tests/unit/python/utils/update/test_addons.py``); this file owns the live,
warn-only surface and degrades to "monitored, not yet checked" warnings when
no live adapter is wired for a catalog.
"""
from __future__ import annotations
import unittest
from utils.annotations.message import warning as gha_warning
from utils.update.addons import collect_addon_entries
from . import PROJECT_ROOT
class TestAddonVersions(unittest.TestCase):
"""Warn-only: surface monitored addons and their catalogs for drift review."""
def test_monitored_addons_are_surfaced(self) -> None:
roles_root = PROJECT_ROOT / "roles"
entries = collect_addon_entries(roles_root)
monitored = [e for e in entries if e.monitored]
by_catalog: dict[str, list[str]] = {}
for entry in monitored:
catalog = entry.catalog or "(none)"
by_catalog.setdefault(catalog, []).append(f"{entry.role}/{entry.addon_id}")
if monitored:
lines = "\n".join(
f" {catalog}: {', '.join(sorted(ids))}"
for catalog, ids in sorted(by_catalog.items())
)
print(
f"\n🔍 {len(monitored)} monitored addon(s) across "
f"{len(by_catalog)} catalog(s):\n{lines}\n\n"
"Live version/discovery drift is reported below as warnings "
"(warn-only; suppress per-addon by setting update.monitored: "
"false).",
flush=True,
)
for entry in monitored:
if not entry.catalog:
gha_warning(
f"{entry.role}/{entry.addon_id}: update.monitored is set "
f"but no update.catalog adapter is configured",
title="Addon monitored without catalog",
file=str(entry.config_path.relative_to(PROJECT_ROOT)),
)
self.assertIsNotNone(entries)
if __name__ == "__main__": # pragma: no cover
unittest.main()