Spaces:
Running
Running
Download editor/test_fleet.py from acecalisto3/SignalMesh: direct link, hf CLI and curl.
- Browser
- Download file 5.27 kB
-
https://huggingface.co/spaces/acecalisto3/SignalMesh/resolve/main/editor/test_fleet.py
- Command line
-
hf download hf://spaces/acecalisto3/SignalMesh/editor/test_fleet.py
-
curl -L -o test_fleet.py https://huggingface.co/spaces/acecalisto3/SignalMesh/resolve/main/editor/test_fleet.py
5.27 kB
| """Fleet ingestion invariants across Joomla schema generations.""" | |
| import json | |
| import time | |
| import fleet | |
| import mesh | |
| def _m(version, author="Acme"): | |
| return json.dumps({"version": version, "author": author}) | |
| EXT = [ | |
| {"extension_id": 1, "name": "files_joomla", "type": "file", "element": "joomla", | |
| "folder": "", "package_id": 0, "manifest_cache": _m("5.1.2", fleet.CORE_AUTHOR)}, | |
| {"extension_id": 2, "name": "com_widgetkit", "type": "component", "element": "widgetkit", | |
| "folder": "", "package_id": 0, "manifest_cache": _m("4.0.0")}, | |
| {"extension_id": 3, "name": "com_rsform", "type": "component", "element": "rsform", | |
| "folder": "", "package_id": 0, "manifest_cache": _m("3.1.0")}, | |
| {"extension_id": 4, "name": "com_lostsoul", "type": "component", "element": "lostsoul", | |
| "folder": "", "package_id": 0, "manifest_cache": _m("1.0")}, | |
| # Rides its package's update site; must not be counted as sourceless. | |
| {"extension_id": 5, "name": "plg_child", "type": "plugin", "element": "child", | |
| "folder": "system", "package_id": 3, "manifest_cache": _m("3.1.0")}, | |
| # Core extension with no site row of its own — rides the core update. | |
| {"extension_id": 6, "name": "com_content", "type": "component", "element": "content", | |
| "folder": "", "package_id": 0, "manifest_cache": _m("5.1.2", fleet.CORE_AUTHOR)}, | |
| ] | |
| NOW = int(time.time()) | |
| ROUTES = { | |
| 1: [{"name": "Joomla core", "location": "https://update.joomla.org/core/list.xml", | |
| "enabled": True, "last_check_timestamp": NOW}], | |
| 2: [{"name": "Widgetkit", "location": "https://yootheme.com/update.xml", | |
| "enabled": True, "last_check_timestamp": NOW}], | |
| # Known route, switched off — not the same as no route. | |
| 3: [{"name": "RSForm!Pro", "location": "https://rsjoomla.com/update.xml", | |
| "enabled": False, "last_check_timestamp": 0}], | |
| } | |
| UPDATES = { | |
| 2: {"extension_id": 2, "name": "com_widgetkit", "element": "widgetkit", | |
| "type": "component", "version": "4.1.0", | |
| "detailsurl": "https://yootheme.com/d.xml", "changelogurl": ""}, | |
| } | |
| class _Conn: | |
| def close(self): | |
| pass | |
| def _patch(monkeypatch): | |
| monkeypatch.setattr(mesh, "connect", lambda site=None: _Conn()) | |
| monkeypatch.setattr(mesh, "prefix", lambda site=None: "fwk_") | |
| monkeypatch.setattr(mesh, "env", lambda site=None: {"JOOMLA_URL": "https://x.test"}) | |
| monkeypatch.setattr(fleet, "_installed", lambda conn, p: [dict(x) for x in EXT]) | |
| monkeypatch.setattr(fleet, "_pending", lambda conn, p: {k: dict(v) for k, v in UPDATES.items()}) | |
| monkeypatch.setattr(fleet, "_update_routes", lambda conn, p: { | |
| k: [dict(x) for x in rows] for k, rows in ROUTES.items() | |
| }) | |
| def test_only_the_genuinely_sourceless_are_unmanaged(monkeypatch): | |
| _patch(monkeypatch) | |
| s = fleet.survey("maplewood") | |
| assert [x["name"] for x in s["unmanaged"]] == ["com_lostsoul"] | |
| assert [x["name"] for x in s["switched_off"]] == ["com_rsform"] | |
| assert s["switched_off_count"] == 1 | |
| def test_every_extension_reports_its_route(monkeypatch): | |
| _patch(monkeypatch) | |
| s = fleet.survey("maplewood") | |
| assert s["outdated"][0]["source"] == "https://yootheme.com/update.xml" | |
| off = s["switched_off"][0] | |
| assert off["source"] == "https://rsjoomla.com/update.xml" and off["enabled"] is False | |
| # package child (5) + core extension (6) inherit, so 5 of 6 are routed | |
| assert s["routed"] == 5 | |
| assert s["unmanaged"][0]["source"] == "" | |
| def test_a_never_checked_update_cache_reads_as_stale(monkeypatch): | |
| _patch(monkeypatch) | |
| assert fleet.survey("x")["stale"] is False | |
| monkeypatch.setattr(fleet, "STALE_AFTER", 0) | |
| assert fleet.survey("x")["stale"] is True | |
| class _SchemaCursor: | |
| """Tiny DB cursor proving optional columns are selected through aliases.""" | |
| def __init__(self, conn): | |
| self.conn = conn | |
| self.rows = [] | |
| def __enter__(self): | |
| return self | |
| def __exit__(self, *exc): | |
| return False | |
| def execute(self, sql): | |
| self.conn.sql.append(sql) | |
| if sql.startswith("SHOW COLUMNS"): | |
| self.rows = [{"Field": c} for c in ( | |
| "extension_id", "name", "element", "type", "version", "detailsurl" | |
| )] | |
| return | |
| assert "'' AS `changelogurl`" in sql, sql | |
| self.rows = [{ | |
| "extension_id": 9, "name": "Legacy updater", "element": "legacy", | |
| "type": "component", "version": "2.0", "detailsurl": "https://x.test/u", | |
| "changelogurl": "", | |
| }] | |
| def fetchall(self): | |
| return self.rows | |
| class _SchemaConn: | |
| def __init__(self): | |
| self.sql = [] | |
| def cursor(self): | |
| return _SchemaCursor(self) | |
| def test_missing_changelogurl_does_not_make_joomla_unreadable(): | |
| conn = _SchemaConn() | |
| got = fleet._pending(conn, "j5_") | |
| assert got[9]["version"] == "2.0" | |
| assert got[9]["changelogurl"] == "" | |
| assert any("'' AS `changelogurl`" in sql for sql in conn.sql) | |
| if __name__ == "__main__": | |
| # pytest runs the monkeypatch cases; the direct schema regression can also be | |
| # run in the lightweight migration workflow without pytest fixtures. | |
| test_missing_changelogurl_does_not_make_joomla_unreadable() | |
| print("fleet schema drift: OK") | |