"""n8n — upgrade stage (D2): deploy the previous published version, write a data marker into the persistent /home/node/.n8n volume, upgrade to current/$REF, assert health + data survival. n8n state lives in the .n8n volume (sqlite + config); the marker is a file there, read back via `exec_in_app` (not HTTP-served).""" import os import sys import pytest sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "..", "runner")) from harness import lifecycle # noqa: E402 MARKER = "/home/node/.n8n/ci-marker.txt" @pytest.fixture def old_app(recipe, app_domain, meta, request): prev = lifecycle.previous_version(recipe) if not prev: pytest.skip(f"{recipe}: no previous published version to upgrade from") lifecycle.janitor() request.addfinalizer(lambda: lifecycle.teardown_app(app_domain)) lifecycle.deploy_app(recipe, app_domain, version=prev) lifecycle.wait_healthy(app_domain, ok_codes=tuple(meta["HEALTH_OK"]), path=meta["HEALTH_PATH"], deploy_timeout=meta["DEPLOY_TIMEOUT"], http_timeout=meta["HTTP_TIMEOUT"]) return app_domain, prev def test_upgrade_preserves_data(old_app, meta): domain, prev = old_app lifecycle.exec_in_app(domain, ["sh", "-c", f"echo upgrade-survives > {MARKER}"]) assert lifecycle.exec_in_app(domain, ["cat", MARKER]).strip() == "upgrade-survives" lifecycle.upgrade_app(domain, version=os.environ.get("VERSION") or None) lifecycle.wait_healthy(domain, ok_codes=tuple(meta["HEALTH_OK"]), path=meta["HEALTH_PATH"], deploy_timeout=meta["DEPLOY_TIMEOUT"], http_timeout=meta["HTTP_TIMEOUT"]) assert lifecycle.http_get(domain, meta["HEALTH_PATH"]) == 200 assert lifecycle.exec_in_app(domain, ["cat", MARKER]).strip() == "upgrade-survives", \ "data did not survive the upgrade"