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>
206 lines
6.8 KiB
Python
206 lines
6.8 KiB
Python
"""Unit tests for the pure addon drift-discovery core.
|
|
|
|
The live external test (`tests/external/update/addons/`) is warn-only and
|
|
opt-in; the reconciliation logic it relies on is exercised here with fixture
|
|
catalogs covering the three behaviours the requirement calls out: a version
|
|
bump, a newly discovered addon, and a marketplace entry intentionally ignored
|
|
by the curated relevance rules.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import tempfile
|
|
import textwrap
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
from utils.roles.mapping import ROLE_DIR_META_ADDONS
|
|
from utils.update.addons import (
|
|
AddonEntry,
|
|
CatalogCandidate,
|
|
collect_addon_entries,
|
|
discover_addon_updates,
|
|
version_is_newer,
|
|
)
|
|
|
|
|
|
def _entry(
|
|
addon_id, version="", monitored=True, upstream_id=None, catalog="wordpress-org"
|
|
):
|
|
spec = {
|
|
"mechanism": "plugin",
|
|
"source": "upstream",
|
|
"version": version,
|
|
"update": {"monitored": monitored, "catalog": catalog},
|
|
}
|
|
if upstream_id:
|
|
spec["update"]["upstream_id"] = upstream_id
|
|
return AddonEntry(
|
|
role="web-app-demo",
|
|
addon_id=addon_id,
|
|
config_path=Path("roles/web-app-demo")
|
|
/ ROLE_DIR_META_ADDONS
|
|
/ f"{addon_id}.yml",
|
|
spec=spec,
|
|
)
|
|
|
|
|
|
class TestVersionIsNewer(unittest.TestCase):
|
|
def test_strictly_newer(self):
|
|
self.assertTrue(version_is_newer("2.3.1", "2.4.0"))
|
|
|
|
def test_equal_is_not_newer(self):
|
|
self.assertFalse(version_is_newer("2.3.1", "2.3.1"))
|
|
|
|
def test_blank_current_never_suggests(self):
|
|
self.assertFalse(version_is_newer("", "2.4.0"))
|
|
|
|
def test_non_semver_latest_ignored(self):
|
|
self.assertFalse(version_is_newer("2.3.1", "master"))
|
|
|
|
|
|
class TestDiscoverAddonUpdates(unittest.TestCase):
|
|
def test_version_bump_suggested_for_monitored_pin(self):
|
|
declared = [_entry("oidc", version="2.3.1")]
|
|
candidates = [
|
|
CatalogCandidate(
|
|
upstream_id="oidc",
|
|
latest="2.4.0",
|
|
mechanism="plugin",
|
|
source="built",
|
|
catalog_url="https://example.test/oidc",
|
|
)
|
|
]
|
|
result = discover_addon_updates(
|
|
role="web-app-demo",
|
|
catalog="wordpress-org",
|
|
declared=declared,
|
|
candidates=candidates,
|
|
)
|
|
self.assertEqual(len(result.version_updates), 1)
|
|
self.assertEqual(result.version_updates[0].current, "2.3.1")
|
|
self.assertEqual(result.version_updates[0].latest, "2.4.0")
|
|
self.assertEqual(result.new_addons, [])
|
|
|
|
def test_unmonitored_pin_is_not_bumped(self):
|
|
declared = [_entry("oidc", version="2.3.1", monitored=False)]
|
|
candidates = [
|
|
CatalogCandidate(
|
|
upstream_id="oidc",
|
|
latest="2.4.0",
|
|
mechanism="plugin",
|
|
source="upstream",
|
|
catalog_url="https://example.test/oidc",
|
|
)
|
|
]
|
|
result = discover_addon_updates(
|
|
role="web-app-demo",
|
|
catalog="wordpress-org",
|
|
declared=declared,
|
|
candidates=candidates,
|
|
)
|
|
self.assertEqual(result.version_updates, [])
|
|
|
|
def test_new_addon_discovered(self):
|
|
declared = [_entry("oidc", version="2.3.1")]
|
|
candidates = [
|
|
CatalogCandidate(
|
|
upstream_id="oidc",
|
|
latest="2.3.1",
|
|
mechanism="plugin",
|
|
source="upstream",
|
|
catalog_url="https://example.test/oidc",
|
|
),
|
|
CatalogCandidate(
|
|
upstream_id="wp-discourse",
|
|
latest="2.5.0",
|
|
mechanism="plugin",
|
|
source="upstream",
|
|
catalog_url="https://example.test/wp-discourse",
|
|
reason="curated: bridges web-app-discourse",
|
|
),
|
|
]
|
|
result = discover_addon_updates(
|
|
role="web-app-demo",
|
|
catalog="wordpress-org",
|
|
declared=declared,
|
|
candidates=candidates,
|
|
)
|
|
self.assertEqual(len(result.new_addons), 1)
|
|
self.assertEqual(result.new_addons[0].addon_id, "wp-discourse")
|
|
self.assertEqual(result.version_updates, [])
|
|
|
|
def test_irrelevant_marketplace_entry_ignored(self):
|
|
declared = [_entry("oidc", version="2.3.1")]
|
|
candidates = [
|
|
CatalogCandidate(
|
|
upstream_id="some-random-marketplace-plugin",
|
|
latest="9.9.9",
|
|
mechanism="plugin",
|
|
source="upstream",
|
|
catalog_url="https://example.test/random",
|
|
relevant=False,
|
|
reason="not in curated relevance set",
|
|
)
|
|
]
|
|
result = discover_addon_updates(
|
|
role="web-app-demo",
|
|
catalog="wordpress-org",
|
|
declared=declared,
|
|
candidates=candidates,
|
|
)
|
|
self.assertEqual(result.new_addons, [])
|
|
self.assertEqual(result.version_updates, [])
|
|
|
|
def test_upstream_id_override_matches_declared(self):
|
|
declared = [_entry("oidc", version="2.3.1", upstream_id="pretix-oidc")]
|
|
candidates = [
|
|
CatalogCandidate(
|
|
upstream_id="pretix-oidc",
|
|
latest="2.4.0",
|
|
mechanism="plugin",
|
|
source="built",
|
|
catalog_url="https://example.test/pretix-oidc",
|
|
)
|
|
]
|
|
result = discover_addon_updates(
|
|
role="web-app-demo",
|
|
catalog="odoo-apps",
|
|
declared=declared,
|
|
candidates=candidates,
|
|
)
|
|
self.assertEqual(len(result.version_updates), 1)
|
|
self.assertEqual(result.version_updates[0].addon_id, "oidc")
|
|
|
|
|
|
class TestCollectAddonEntries(unittest.TestCase):
|
|
def test_collects_and_skips_malformed(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
addons = Path(tmp) / "roles" / "web-app-demo" / ROLE_DIR_META_ADDONS
|
|
addons.mkdir(parents=True)
|
|
(addons / "good.yml").write_text(
|
|
textwrap.dedent(
|
|
"""
|
|
---
|
|
mechanism: plugin
|
|
source: upstream
|
|
version: "1.0"
|
|
update:
|
|
monitored: true
|
|
catalog: wordpress-org
|
|
"""
|
|
),
|
|
encoding="utf-8",
|
|
)
|
|
(addons / "bad.yml").write_text("not a mapping\n", encoding="utf-8")
|
|
entries = collect_addon_entries(Path(tmp) / "roles")
|
|
ids = sorted(e.addon_id for e in entries)
|
|
self.assertEqual(ids, ["good"])
|
|
self.assertTrue(entries[0].monitored)
|
|
self.assertEqual(entries[0].catalog, "wordpress-org")
|
|
self.assertEqual(entries[0].upstream_id, "good")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|