#!/usr/bin/env python3
"""Verify CAD environment for ZimaOS headless pipeline."""
import sys, os

def check(module_name, extra_info=""):
    try:
        __import__(module_name)
        print(f"  ✅ {module_name:20s} {extra_info}")
        return True
    except Exception as e:
        print(f"  ❌ {module_name:20s} {e}")
        return False

print("=== CAD Environment Verification ===")
print(f"Python: {sys.executable}")
print(f"Version: {sys.version.split()[0]}")

all_ok = True
all_ok &= check("trimesh")
all_ok &= check("manifold3d")
all_ok &= check("numpy")
all_ok &= check("matplotlib", "(Agg backend for headless previews)")
all_ok &= check("lxml", "(required by trimesh for 3MF)")
all_ok &= check("networkx", "(required by trimesh for 3MF export)")

# CadQuery — expected to FAIL on headless ZimaOS
print("\n--- CadQuery (expected to FAIL on headless ZimaOS) ---")
cq_ok = check("cadquery")
if not cq_ok:
    print("  ℹ️  Acceptable — using trimesh+manifold3d instead")

print("\n--- Quick sanity check ---")
try:
    import trimesh
    m = trimesh.creation.box(extents=[10, 10, 10])
    m.export("/tmp/verify_box.stl")
    os.remove("/tmp/verify_box.stl")
    print("  ✅ STL export works")
except Exception as e:
    print(f"  ❌ STL export failed: {e}")
    all_ok = False

sys.exit(0 if all_ok else 1)
