"""Integration test: C++ DAG engine compilation.""" import os import subprocess import sys import pytest @pytest.mark.skipif( not any( os.path.exists(p) for p in [ r"C:\Program Files\CMake\bin\cmake.exe", r"C:\Program Files (x86)\CMake\bin\cmake.exe", "/usr/bin/cmake", "/usr/local/bin/cmake", ] ) and subprocess.run(["cmake", "--version"], capture_output=True).returncode != 0, reason="CMake not found on system", ) class TestCppBuild: """Test that the C++ DAG engine compiles successfully.""" @staticmethod def _project_root(): return os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..")) def test_cmake_configure(self): """CMake should configure without errors.""" root = self._project_root() build_dir = os.path.join(root, "cpp", "build") os.makedirs(build_dir, exist_ok=True) result = subprocess.run( ["cmake", "-S", os.path.join(root, "cpp"), "-B", build_dir], capture_output=True, text=True, cwd=root, ) assert result.returncode == 0, f"CMake configure failed:\n{result.stderr}" def test_cmake_build(self): """CMake should build the autoforge-dag target.""" root = self._project_root() build_dir = os.path.join(root, "cpp", "build") # Ensure configured subprocess.run( ["cmake", "-S", os.path.join(root, "cpp"), "-B", build_dir], capture_output=True, cwd=root, ) result = subprocess.run( ["cmake", "--build", build_dir], capture_output=True, text=True, cwd=root, ) assert result.returncode == 0, f"CMake build failed:\n{result.stderr}" def test_binary_exists(self): """The built binary should exist.""" root = self._project_root() build_dir = os.path.join(root, "cpp", "build") # Build if needed subprocess.run(["cmake", "-S", os.path.join(root, "cpp"), "-B", build_dir], capture_output=True, cwd=root) subprocess.run(["cmake", "--build", build_dir], capture_output=True, cwd=root) # Check for binary (platform-dependent extension) if sys.platform == "win32": candidates = [ os.path.join(build_dir, "autoforge-dag.exe"), os.path.join(build_dir, "Debug", "autoforge-dag.exe"), os.path.join(build_dir, "Release", "autoforge-dag.exe"), ] else: candidates = [os.path.join(build_dir, "autoforge-dag")] assert any(os.path.exists(c) for c in candidates), ( f"Binary not found. Checked: {candidates}" )