All checks were successful
continuous-integration/drone/push Build is passing
One loader: runner/harness/meta.py::load(recipe) -> RecipeMeta (frozen dataclass, attribute access), backed by the declarative KEYS registry (14 final keys + 3 P2-deprecated). The ONLY exec() of tests/<recipe>/recipe_meta.py. Validation per the locked decision: unknown ALL-CAPS top-level name or type mismatch = MetaError (hard error at load); underscore-prefixed names recipe-private; callables only on hook-typed keys. Migrated all six legacy loaders (spec §4 L1–L6): - run_recipe_ci.py::_load_meta deleted; orchestrator loads once, passes meta down - tests/conftest.py::_recipe_meta deleted; meta fixture returns full RecipeMeta (R3) - lifecycle.py::_recipe_extra_env/_recipe_meta_flag deleted; deploy_app takes meta - deps.py::declared_deps deleted; callers read meta.DEPS - canonical.py::is_enrolled reads through meta.load() - screenshot.py now actually receives SCREENSHOT through the orchestrator path (R2 fix; proven by unit test through the real load path) Mumble private constants underscore-prefixed (_WELCOME_TEXT_MARKER/_MAX_USERS) + importers fixed. New tests/unit/test_meta.py (all-recipes-load-clean typo gate, MetaError cases, spec §2 baseline defaults, underscore exemption, doc sync). Docs §4 key table now GENERATED from the registry (scripts/gen-meta-docs.py); drift fails CI. Verified on cc-ci: cc-ci-run -m pytest tests/unit -q -> 175 passed; scripts/lint.sh -> PASS.
99 lines
4.5 KiB
Python
99 lines
4.5 KiB
Python
"""Unit tests for the WC2 canonical registry (runner/harness/canonical.py).
|
|
|
|
Pure parts: enrollment (recipe_meta.WARM_CANONICAL), stable domain, registry read/write. The
|
|
data-warm lifecycle (deploy/undeploy-keep-volume/seed) is integration, proven live on a real recipe
|
|
canonical (W1).
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import os
|
|
import sys
|
|
|
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "..", "runner"))
|
|
from harness import canonical, warm # noqa: E402
|
|
from harness import meta as harness_meta # noqa: E402
|
|
|
|
|
|
def test_canonical_domain():
|
|
assert canonical.canonical_domain("custom-html") == "warm-custom-html.ci.commoninternet.net"
|
|
assert warm.stable_domain("keycloak") == "warm-keycloak.ci.commoninternet.net"
|
|
# stable_domain matches the live-warm keycloak's mapping (no divergence)
|
|
assert warm.stable_domain("keycloak") == warm.WARM_DOMAINS["keycloak"]
|
|
|
|
|
|
def test_is_enrolled_missing_meta_false(tmp_path, monkeypatch):
|
|
# A recipe with no recipe_meta.py is not enrolled.
|
|
assert canonical.is_enrolled("definitely-not-a-recipe-xyz") is False
|
|
|
|
|
|
def test_is_enrolled_reads_flag(tmp_path, monkeypatch):
|
|
# Point the module's tests/<recipe>/ lookup at a temp recipe by monkeypatching __file__ dir.
|
|
recipe = "tmpwarm"
|
|
tests_dir = tmp_path / "tests" / recipe
|
|
tests_dir.mkdir(parents=True)
|
|
(tests_dir / "recipe_meta.py").write_text("WARM_CANONICAL = True\n")
|
|
# is_enrolled reads through the single meta loader (rcust P1); point its tests/ root at the
|
|
# temp layout.
|
|
monkeypatch.setattr(harness_meta, "TESTS_DIR", str(tmp_path / "tests"))
|
|
assert canonical.is_enrolled(recipe) is True
|
|
(tests_dir / "recipe_meta.py").write_text("WARM_CANONICAL = False\n")
|
|
assert canonical.is_enrolled(recipe) is False
|
|
(tests_dir / "recipe_meta.py").write_text("DEPS = ['keycloak']\n") # flag absent
|
|
assert canonical.is_enrolled(recipe) is False
|
|
|
|
|
|
def test_registry_roundtrip(tmp_path, monkeypatch):
|
|
monkeypatch.setenv("CCCI_WARM_ROOT", str(tmp_path))
|
|
assert canonical.read_registry("custom-html") is None
|
|
rec = canonical.write_registry(
|
|
"custom-html", version="1.10.0+x", commit="abc123", status="idle"
|
|
)
|
|
assert rec["domain"] == "warm-custom-html.ci.commoninternet.net"
|
|
assert rec["version"] == "1.10.0+x" and rec["commit"] == "abc123" and rec["status"] == "idle"
|
|
back = canonical.read_registry("custom-html")
|
|
assert back == rec
|
|
# atomic overwrite to a new status
|
|
canonical.write_registry("custom-html", version="1.10.0+x", commit="abc123", status="warm")
|
|
assert canonical.read_registry("custom-html")["status"] == "warm"
|
|
# the file is valid JSON on disk
|
|
with open(canonical.registry_path("custom-html")) as f:
|
|
assert json.load(f)["status"] == "warm"
|
|
|
|
|
|
def test_enrolled_recipes_scans_meta(tmp_path, monkeypatch):
|
|
# enrolled_recipes() lists recipes whose tests/<r>/recipe_meta.py sets WARM_CANONICAL=True.
|
|
monkeypatch.setattr(harness_meta, "TESTS_DIR", str(tmp_path / "tests"))
|
|
for name, body in (
|
|
("aaa", "WARM_CANONICAL = True\n"),
|
|
("bbb", "DEPS=['x']\n"),
|
|
("ccc", "WARM_CANONICAL = True\n"),
|
|
):
|
|
d = tmp_path / "tests" / name
|
|
d.mkdir(parents=True)
|
|
(d / "recipe_meta.py").write_text(body)
|
|
(tmp_path / "tests" / "ddd").mkdir(parents=True) # no recipe_meta.py at all
|
|
assert canonical.enrolled_recipes() == ["aaa", "ccc"]
|
|
|
|
|
|
def test_prune_stale_drops_deenrolled_only(tmp_path, monkeypatch):
|
|
# prune_stale removes <recipe>/ dirs that have a canonical.json but aren't enrolled; keeps
|
|
# enrolled canonicals, reconciler dirs (no canonical.json), and alerts/.
|
|
monkeypatch.setenv("CCCI_WARM_ROOT", str(tmp_path))
|
|
monkeypatch.setattr(canonical, "enrolled_recipes", lambda: ["keepme"])
|
|
monkeypatch.setattr(canonical.warmsnap, "stack_volumes", lambda d: []) # no docker in unit
|
|
# enrolled canonical (keep), de-enrolled canonical (prune), reconciler dir (keep), alerts (keep)
|
|
for name in ("keepme", "gone"):
|
|
(tmp_path / name).mkdir()
|
|
(tmp_path / name / "canonical.json").write_text(f'{{"recipe":"{name}"}}')
|
|
(tmp_path / "keycloak").mkdir()
|
|
(tmp_path / "keycloak" / "last_good").write_text("v1") # reconciler
|
|
(tmp_path / "alerts").mkdir()
|
|
pruned = canonical.prune_stale()
|
|
assert pruned == ["gone"]
|
|
assert not (tmp_path / "gone").exists()
|
|
assert (tmp_path / "keepme").exists()
|
|
assert (tmp_path / "keycloak").exists() # no canonical.json → not a canonical → kept
|
|
assert (tmp_path / "alerts").exists()
|