import json import sys import os # Ensure the local src layout is importable in test runs SRC_DIR = os.path.join(os.path.dirname(os.path.dirname(__file__)), "src") if os.path.isdir(SRC_DIR) and SRC_DIR not in sys.path: sys.path.insert(0, SRC_DIR) from cosmosmesh_privacy_preserving_federated.catopt_bridge import to_catopt, from_catopt, LocalProblem, SharedVariables, PlanDelta def test_pilot_roundtrip_basic(): lp = LocalProblem( id="lp-t", domain="space", assets=["rover-1"], objective={"type": "min", "value": 1}, constraints={"time": 60}, version=1 ) sv = SharedVariables(forecasts={"energy": 5}, priors={"energy": 4}, version=1) delta = PlanDelta(delta={"task": "sample"}, timestamp="2026-01-01T00:00:00Z", author="tester", contract_id="c1", signature="sig") catopt = to_catopt(lp, sv, delta) recon = from_catopt(catopt) # Basic shape validation of round-trip results assert isinstance(recon.get("LocalProblem"), dict) assert isinstance(recon.get("PlanDelta"), dict)