"""Current-source descriptor/completion checks; no MPI, GPU or installed QC core."""
from pathlib import Path
import os
import shutil
import subprocess

import pytest

ROOT = Path(__file__).resolve().parents[1]


@pytest.fixture(scope="module")
def distributed_binary(tmp_path_factory):
    compiler = shutil.which(os.environ.get("CXX", "c++"))
    if compiler is None:
        pytest.skip("C++17 compiler unavailable")
    binary = tmp_path_factory.mktemp("tensor-distributed") / "distributed-test"
    subprocess.run([
        compiler, "-std=c++17", "-O2", "-pthread", "-I" + str(ROOT / "cpp/include"),
        str(ROOT / "tests/native/tensor_distributed.cpp"), "-o", str(binary),
    ], check=True, capture_output=True, text=True, timeout=120)
    return binary


@pytest.mark.parametrize("case", [
    "numerics", "descriptors", "lifetimes", "failures", "budgets", "codec", "bounded", "admission",
])
def test_fake_distributed_contract(distributed_binary, case):
    result = subprocess.run(
        [str(distributed_binary), case], text=True, capture_output=True, timeout=30,
    )
    assert result.returncode == 0, result.stdout + result.stderr
    assert f"{case} PASS" in result.stdout
