"""Smoke test: the end-to-end demo runs clean and covers the whole pipeline.

Guards the flagship 'watch it all work' script from silently breaking.
"""
import os
import subprocess
import sys

HERE = os.path.dirname(os.path.abspath(__file__))
DEMO = os.path.join(HERE, "..", "demo", "full_demo.py")


def test_full_demo_runs_end_to_end(tmp_path):
    env = {**os.environ, "ABOM_KEY": str(tmp_path / "k.pem")}
    p = subprocess.run([sys.executable, DEMO], capture_output=True, text=True,
                       timeout=60, env=env)
    assert p.returncode == 0, p.stdout + p.stderr
    out = p.stdout
    # every stage of the story appears and shows the right outcome
    for marker in ("SCAN", "GATE", "BROKER", "WITNESS", "ANCHOR", "VERIFY",
                   "tool_not_in_manifest", "DENIED (-32001)",
                   "rewrite refused", "cosignature verifies",
                   "composed, enforced, brokered, witnessed, anchored, verified"):
        assert marker in out, f"missing from demo output: {marker!r}"
