"""Customer Mission #5 — a non-security target: evidence relevance flips both ways.

Pins the one claim this mission exists to prove: relevance(evidence, target) is a function of the
TARGET, not an attribute of the evidence. The same ISO 14001 is keine against CRA/TISAX but hoch
against an environmental/material target, while the security certs flip the other way (hoch against
security targets, keine against the environmental one). Tight scope: no corpus, no norm model, no
new runtime module, no real names.
"""

from __future__ import annotations

import os
import subprocess
import sys


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


def test_runs_end_to_end():
    out = _run()
    assert "Customer Mission #5" in out


def test_iso14001_relevance_flips_to_high_on_environmental_target():
    out = _run()
    # the headline: same cert, keine against security targets, hoch against the environmental one
    assert "**ISO14001** | keine (0) | keine (0) | hoch (3) |" in out


def test_security_evidence_is_worthless_against_environmental_target():
    out = _run()
    # symmetry: security certs are relevant for security, keine for the environmental target
    assert "**ISO27001** | hoch (5) | hoch (3) | keine (0) |" in out
    assert "**PSIRT** | hoch (3) | keine (0) | keine (0) |" in out


def test_relevance_is_a_function_of_the_target():
    out = _run()
    assert "relevance(evidence, target)` zweiseitig bewiesen" in out
    # five target types now covered -> selector becomes sensible
    assert "fünf Zielarten" in out


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