Files
cc-ci/tests/unit/test_f212_upgrade_convergence.py
autonomic-bot fd02d9f4b8
All checks were successful
continuous-integration/drone/push Build is passing
feat(harness): P3 — uniform ctx hook convention (rcust)
harness.meta.HookCtx (frozen): .domain, .base_url, .meta (RecipeMeta), .deps
(provisioned dep creds from $CCCI_DEPS_FILE or None), .op (current lifecycle op
or None); built via meta.hook_ctx() at each hook call site.

All recipe callables now take ctx: EXTRA_ENV(ctx), UPGRADE_EXTRA_ENV(ctx),
READY_PROBE(ctx), BACKUP_VERIFY(ctx), SCREENSHOT(page, ctx), ops.py pre_<op>(ctx).
Dict-valued EXTRA_ENV/UPGRADE_EXTRA_ENV unchanged (only the callable signature
moved). Call sites converted: deploy_app env shaping, perform_upgrade,
wait_ready_probes (gains op=), _perform_op BACKUP_VERIFY, screenshot.capture,
_run_pre_hook.

Legacy signatures fail FAST with a clear migration message: the registry carries
hook_params per hook key, enforced at meta.load() (MetaError names the old vs new
signature); ops.py pre-op hooks get the same check at the orchestrator call site
(meta.check_hook_signature) — no silent TypeError mid-run.

Migrated every in-repo user mechanically (17 ops.py files; cryptpad/lasuite-*/
mailu EXTRA_ENV; mumble+lasuite-drive READY_PROBE; ghost/discourse BACKUP_VERIFY)
— seeded values, probes and assertions byte-identical (domain -> ctx.domain;
keycloak pre_restore's meta arg -> ctx.meta).

Unit tests: hook_ctx field contract, ctx.deps from the run deps file, legacy-
signature MetaError (READY_PROBE/EXTRA_ENV/SCREENSHOT + pre-op checker), ctx
signatures accepted. Docs table regenerated (signature docs in key docs).

Verified on cc-ci: cc-ci-run -m pytest tests/unit -q -> 180 passed; scripts/lint.sh -> PASS.
2026-06-10 17:10:26 +00:00

87 lines
4.2 KiB
Python

"""Unit tests for the F2-12 owned upgrade-convergence wait (P7-negative / non-vacuousness).
F2-12 fix: the upgrade chaos redeploy runs with `abra … -c` (skips abra's own convergence monitor),
and the harness OWNS the verification via `lifecycle.wait_healthy` (services N/N + app HEALTH_PATH)
then `lifecycle.wait_ready_probes` (recipe READY_PROBE, e.g. collabora WOPI discovery → 200). Skipping
abra's monitor is only acceptable if the replacement genuinely FAILS a broken convergence rather than
green-washing it (plan §7.1 / Adversary pre-claim recon 2026-05-29). These tests prove exactly that,
deterministically (fake clock, no deploy):
- wait_ready_probes RAISES when the probe never returns an OK status (stuck service).
- wait_ready_probes RETURNS when the probe reaches OK (and is a no-op without a READY_PROBE).
- wait_healthy RAISES when services never converge, and when they converge but HTTP never serves OK.
So `-c` + owned-wait is non-vacuous: a genuinely-broken upgrade stays RED.
"""
from __future__ import annotations
import dataclasses
import os
import sys
import pytest
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "..", "runner"))
from harness import lifecycle as lc # noqa: E402
from harness import meta as harness_meta # noqa: E402
def _fake_clock(monkeypatch):
"""Install a fake monotonic clock on lifecycle.time so sleeps advance it without real waiting."""
state = {"t": 1000.0}
monkeypatch.setattr(lc.time, "time", lambda: state["t"])
monkeypatch.setattr(lc.time, "sleep", lambda s: state.__setitem__("t", state["t"] + s))
return state
# RecipeMeta (rcust P1: wait_ready_probes reads meta.READY_PROBE off the loaded object); defaults
# + the drive-style probe hook (P3 ctx signature: the probe receives a HookCtx).
_DRIVE_META = dataclasses.replace(
harness_meta.load("ccci-no-such-recipe"),
READY_PROBE=lambda ctx: [
{"host": f"collabora-{ctx.domain}", "path": "/hosting/discovery", "ok": (200,)}
],
)
_NO_PROBE_META = harness_meta.load("ccci-no-such-recipe")
def test_wait_ready_probes_raises_when_never_ready(monkeypatch):
"""A READY_PROBE that never returns 200 (collabora discovery wedged) must raise TimeoutError —
NOT silently pass. This is what makes `-c` + owned-wait catch a genuinely stuck upgrade."""
_fake_clock(monkeypatch)
monkeypatch.setattr(lc, "http_get", lambda host, path="/", timeout=15: 404)
with pytest.raises(TimeoutError):
lc.wait_ready_probes(_DRIVE_META, "lasu-x.ci.commoninternet.net", timeout=120)
def test_wait_ready_probes_returns_when_ready(monkeypatch):
"""When the probe reaches 200, it returns (no raise)."""
_fake_clock(monkeypatch)
monkeypatch.setattr(lc, "http_get", lambda host, path="/", timeout=15: 200)
lc.wait_ready_probes(_DRIVE_META, "lasu-x.ci.commoninternet.net", timeout=120) # no raise
def test_wait_ready_probes_noop_without_probe(monkeypatch):
"""A recipe with no READY_PROBE is a clean no-op (default behavior preserved for all recipes)."""
monkeypatch.setattr(lc, "http_get", lambda *a, **k: 599) # would fail if it were consulted
lc.wait_ready_probes(_NO_PROBE_META, "x.ci.commoninternet.net", timeout=1) # no raise, no call
def test_wait_healthy_raises_when_services_never_converge(monkeypatch):
"""If swarm services never reach N/N, wait_healthy must raise (the upgrade op then fails the tier)."""
_fake_clock(monkeypatch)
monkeypatch.setattr(lc, "services_converged", lambda domain: False)
monkeypatch.setattr(lc, "http_get", lambda *a, **k: 200) # irrelevant; convergence gates first
with pytest.raises(TimeoutError):
lc.wait_healthy("x.ci.commoninternet.net", deploy_timeout=60, http_timeout=60)
def test_wait_healthy_raises_when_converged_but_never_serves(monkeypatch):
"""Services converged but the app never returns an OK status → wait_healthy raises (non-vacuous)."""
_fake_clock(monkeypatch)
monkeypatch.setattr(lc, "services_converged", lambda domain: True)
monkeypatch.setattr(lc, "http_get", lambda *a, **k: 502)
with pytest.raises(TimeoutError):
lc.wait_healthy(
"x.ci.commoninternet.net", ok_codes=(200,), deploy_timeout=60, http_timeout=60
)