"""Customer Mission #2 — the company arrives with a PROFILE, not a journey.

Pins the reframe Mission #2 proves with the real engines: the start state is a Company Capability
Profile (many certs aggregated), certifications are observations/evidence, and more evidence shrinks
the delta (single-cert 12 → multi-cert 9). The „journey" is the computed delta `(Profile, Target)`,
not a thing a selector picks — which shrinks Mission #1's one open seam.
"""

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_multicert_cra.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 #2" in out
    assert "Company Capability Profile — der eigentliche Startzustand" in out


def test_more_evidence_shrinks_the_delta():
    out = _run_mission()
    # multi-cert profile (9) must beat the single-cert counterfactual (12) — evidence is additive.
    assert "**Delta dieses Profils:** 9" in out
    assert "**Gegenprobe (nur ISO 27001):** 12" in out
    assert "Mehr Evidence → kleineres Delta" in out


def test_reframe_no_per_certificate_journey():
    out = _run_mission()
    # the journey is the computed delta (Profile, Target), not a selected cert→target transition.
    assert "Keine per-Zertifikat-Journey" in out
    assert "Company Capability Profile → CRA" in out
    assert "Es wurde **keine Journey ausgewählt**" in out


def test_five_selection_rationale_questions_present():
    out = _run_mission()
    for q in [
        "Welche Journey wurde gewählt?",
        "Warum?",
        "Welche Informationen waren für die Auswahl entscheidend?",
        "Musste das Journey-Modell erweitert werden?",
        "Musste ein neuer Selektionsparameter eingeführt werden?",
    ]:
        assert q in out


def test_evidence_is_target_relative():
    out = _run_mission()
    # honest: ISO 14001 is in the profile but does not help the CRA; PSIRT covers two CRA-delta caps.
    assert "ISO 14001" in out and "NICHT relevant" in out
    assert "PSIRT" in out


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