"""Tests for asset syncing and custom_nodes archiving.""" from __future__ import annotations from pathlib import Path from typing import Any def test_sync_file_deduplicates_by_hash( settings_module: Any, sync_engine_module: Any, tmp_path: Path, ) -> None: """Repeated file syncs should reuse the same remote path and marker.""" asset_path = tmp_path / "model.safetensors" asset_path.write_bytes(b"model-bytes") settings = settings_module.ModalSyncSettings( app_name="app", execution_mode="local", sync_custom_nodes=False, volume_name="volume", route_path="/modal/queue_prompt", marker_property="is_modal_remote", local_storage_root=tmp_path / "storage", remote_storage_root="/storage", custom_nodes_archive_name="custom_nodes_bundle.zip", comfyui_root=None, custom_nodes_dir=None, ) engine = sync_engine_module.ModalAssetSyncEngine.from_environment(settings) first = engine.sync_file(asset_path) second = engine.sync_file(asset_path) assert first.remote_path == second.remote_path assert first.sha256 == second.sha256 assert (settings.local_storage_root / first.remote_path.lstrip("/")).exists() assert (settings.local_storage_root / f"hashes/{first.sha256}.done").exists() def test_sync_custom_nodes_directory_creates_archive( settings_module: Any, sync_engine_module: Any, tmp_path: Path, ) -> None: """The sync engine should archive and mirror a custom_nodes directory.""" custom_nodes_dir = tmp_path / "custom_nodes" package_dir = custom_nodes_dir / "example" package_dir.mkdir(parents=True) (package_dir / "__init__.py").write_text("NODE_CLASS_MAPPINGS = {}\n", encoding="utf-8") settings = settings_module.ModalSyncSettings( app_name="app", execution_mode="remote", sync_custom_nodes=True, volume_name="volume", route_path="/modal/queue_prompt", marker_property="is_modal_remote", local_storage_root=tmp_path / "storage", remote_storage_root="/storage", custom_nodes_archive_name="custom_nodes_bundle.zip", comfyui_root=None, custom_nodes_dir=custom_nodes_dir, ) engine = sync_engine_module.ModalAssetSyncEngine.from_environment(settings) bundle = engine.sync_custom_nodes_directory() assert bundle is not None assert bundle.remote_path.startswith("/custom_nodes/") assert (settings.local_storage_root / bundle.remote_path.lstrip("/")).exists()