"""custom-html-rst-bad — RESTORE assertion (bad-restore RED canary).

No pre_backup → backup snapshot has no ci-marker.txt. pre_restore writes "mutated".
After restore: marker is "mutated" (restore can't recover "original" — wasn't backed up) → FAIL.
"""

import os
import sys

sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "..", "runner"))
from harness import lifecycle  # noqa: E402

MARKER_PATH = "/usr/share/nginx/html/ci-marker.txt"


def test_restore_returns_state(live_app):
    result = lifecycle.exec_in_app(
        live_app, ["sh", "-c", f"cat {MARKER_PATH} 2>/dev/null || echo MISSING"]
    ).strip()
    assert result == "original", (
        f"restore did not return the pre-mutation (backed-up) state: got {result!r}. "
        "Expected 'original'. The backup had no marker, so restore cannot recover it."
    )
