"""n8n — pre-op seed hooks (Phase 1e HC3). The orchestrator runs these BEFORE the op; the matching
test_<op>.py asserts post-op (assertion-only). n8n state lives in the persistent /home/node/.n8n
volume (sqlite + config); the marker there is read back via exec_in_app (not HTTP-served)."""

import os
import sys

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"


def _write(domain, val):
    lifecycle.exec_in_app(domain, ["sh", "-c", f"echo {val} > {MARKER}"])


def pre_upgrade(ctx):
    _write(ctx.domain, "upgrade-survives")


def pre_backup(ctx):
    _write(ctx.domain, "original")


def pre_restore(ctx):
    _write(ctx.domain, "mutated")  # diverge so a successful restore is observable
