import unittest from pathlib import Path import build import tempfile import subprocess from unittest.mock import patch class BuildContract(unittest.TestCase): def test_real_git_source_rejects_wrong_revision_and_dirty_checkout(self): with tempfile.TemporaryDirectory() as directory: source = Path(directory) def git(*args): return subprocess.check_output(["git", "-C", str(source), *args], stderr=subprocess.STDOUT).decode().strip() git("init", "--quiet") (source / "source.txt").write_text("fixture") git("add", "source.txt") git("-c", "user.name=karl", "-c", "user.email=fixture@invalid", "commit", "--quiet", "-m", "fixture") with self.assertRaises(ValueError): build.validate_source(source) with patch.object(build, "UPSTREAM", git("rev-parse", "HEAD")): build.validate_source(source) (source / "source.txt").write_text("changed") with self.assertRaises(ValueError): build.validate_source(source) def test_shared_helpers_load_without_running_build_or_downloading(self): self.assertTrue(callable(build.shared_helper("build_runtime.py").bundle_windows_crt)) self.assertTrue(callable(build.shared_helper("provision_vulkan.py").provision)) def test_linux_closure_rejects_build_paths_and_missing_dependencies(self): from types import SimpleNamespace with tempfile.TemporaryDirectory() as directory: root = Path(directory) for name in ['searchi-speech-worker', 'libwhisper.so.1', 'libggml-vulkan.so']: (root / name).write_bytes(b'fixture') metadata = {'RUNPATH': ['$ORIGIN'], 'NEEDED': ['libwhisper.so.1', 'libc.so.6']} helper = SimpleNamespace(elf_dynamic=lambda _: metadata, LINUX_SYSTEM_LIBRARIES={'libc.so.6'}) with patch.object(build, 'shared_helper', return_value=helper): build.verify_linux_closure(root) metadata['RUNPATH'] = ['/tmp/build'] with self.assertRaisesRegex(ValueError, 'origin-only'): build.verify_linux_closure(root) metadata['RUNPATH'] = ['$ORIGIN'] metadata['NEEDED'] = ['libmissing.so'] with self.assertRaisesRegex(ValueError, 'Unpackaged'): build.verify_linux_closure(root) metadata['NEEDED'] = ['libvulkan.so.1'] with self.assertRaisesRegex(ValueError, 'Unpackaged'): build.verify_linux_closure(root) if __name__ == "__main__": unittest.main()