"""End-to-end test for Customer Mission #1 — the whole platform as ONE connected expert system.

This is NOT a knowledge-correctness test (that is the Reference Scenarios). It runs the FULL consulting
flow with the real engines and asserts the flow-continuity audit: the platform must carry a synthetic
machine builder from „what applies?" to a prioritised 6-month plan, with exactly the two known jumps
(Scope→Journey selector missing; Evidence→Verification parked) and no others creeping in.
"""

from __future__ import annotations

import os
import subprocess
import sys


def _run_mission():
    root = os.path.join(os.path.dirname(__file__), "..")
    r = subprocess.run(
        [sys.executable, "reference_scenarios/mission_machine_builder.py"],
        cwd=root, env={**os.environ, "PYTHONPATH": "."}, capture_output=True, text=True,
    )
    assert r.returncode == 0, r.stderr
    return r.stdout


def test_mission_runs_end_to_end():
    out = _run_mission()
    assert "Customer Mission #1" in out and "Flow-Continuity-Audit" in out
    # the consulting answer must be produced (top-5 leverage closes 9/16 = 56%)
    assert "56%" in out and "6-Monats-Antwort" in out


def test_exactly_two_real_jumps_no_regressions():
    out = _run_mission()
    # the flow must stay continuous: exactly the two KNOWN seams, no new ones
    assert "2 Sprünge" in out
    assert "Scope → Journey" in out and "Evidence → Verification" in out


def test_full_consulting_flow_present():
    out = _run_mission()
    for stage in ["1. Scope", "2. Journey", "3. Capability Delta", "4. Roadmap",
                  "5. Playbooks", "6. Nachweise", "7. Verification", "8. Completeness"]:
        assert stage in out


def test_no_real_company_names():
    out = _run_mission().lower()
    for name in ["eto", "owis", "winterhalter"]:
        assert name not in out          # synthetic archetype only
