- deploy_app: checkout the pinned tag + deploy NON-chaos when a version is pinned (chaos only for version=None / PR-head). Was always -C, which ignored the pin and deployed LATEST -> upgrade no-op. - do_upgrade: assert the deployment actually MOVED (coop-cloud version label and/or image changed) via lifecycle.deployed_identity -> a vacuous no-op upgrade can no longer pass (DG2). - G2: migrate custom-html overlays to the assertion-only contract (override + extend-by-composition + data-continuity; split backup/restore). tests/unit/test_discovery.py proves precedence (5/5). Probe (Adversary's F1d-2 test): hedgedoc deploy-prev=1.10.7 -> upgrade=1.10.8, CHANGED=True. hedgedoc full generic lifecycle green (install/upgrade/backup/restore, deploy-count=1). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
54 lines
2.5 KiB
Python
54 lines
2.5 KiB
Python
"""Unit tests for overlay/custom/hook discovery + precedence (Phase 1d, DG4).
|
|
|
|
Deterministic, no deployment — proves the resolution rule (repo-local > cc-ci > generic) and the
|
|
invariant "no overlay for an op ⇒ generic runs". Run with: `cc-ci-run -m pytest tests/unit`.
|
|
These live under tests/unit/ (NOT a recipe name, NOT tests/_generic/) so the run orchestrator never
|
|
picks them up as overlays/custom tests."""
|
|
|
|
import os
|
|
import sys
|
|
|
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "..", "runner"))
|
|
from harness import discovery # noqa: E402
|
|
|
|
|
|
def test_no_overlay_falls_back_to_generic():
|
|
# hedgedoc has no tests/hedgedoc/ in cc-ci and no repo-local dir -> generic is the floor (DG4 invariant)
|
|
source, path = discovery.resolve_op("hedgedoc", "install", None)
|
|
assert source == "generic"
|
|
assert path == os.path.join(discovery.GENERIC_DIR, "test_install.py")
|
|
|
|
|
|
def test_cc_ci_overlay_overrides_generic():
|
|
# custom-html ships cc-ci overlays for all four ops -> cc-ci wins over generic when no repo-local
|
|
for op in discovery.LIFECYCLE_OPS:
|
|
source, path = discovery.resolve_op("custom-html", op, None)
|
|
assert source == "cc-ci", op
|
|
assert path == os.path.join(discovery.cc_ci_dir("custom-html"), f"test_{op}.py")
|
|
|
|
|
|
def test_repo_local_wins_same_name_collision(tmp_path):
|
|
# repo-local is upstream-authoritative: a repo-local test_install.py beats cc-ci's for that op
|
|
(tmp_path / "test_install.py").write_text("# repo-local overlay\n")
|
|
source, path = discovery.resolve_op("custom-html", "install", str(tmp_path))
|
|
assert source == "repo-local"
|
|
assert path == str(tmp_path / "test_install.py")
|
|
|
|
|
|
def test_custom_tests_additive_from_both_locations(tmp_path):
|
|
# non-lifecycle test_*.py are opt-in and additive; lifecycle names are excluded
|
|
(tmp_path / "test_sso.py").write_text("# repo-local custom\n")
|
|
(tmp_path / "test_install.py").write_text("# lifecycle name -> excluded from custom\n")
|
|
customs = discovery.custom_tests("custom-html", str(tmp_path))
|
|
names = {(src, os.path.basename(p)) for src, p in customs}
|
|
assert ("repo-local", "test_sso.py") in names
|
|
assert all(os.path.basename(p) != "test_install.py" for _, p in customs)
|
|
|
|
|
|
def test_install_steps_repo_local_over_cc_ci(tmp_path):
|
|
(tmp_path / "install_steps.sh").write_text("#!/usr/bin/env bash\n")
|
|
hook = discovery.install_steps("custom-html", str(tmp_path))
|
|
assert hook is not None
|
|
assert hook[0] == "repo-local"
|
|
assert discovery.install_steps("hedgedoc", None) is None
|