Files
ComfyUI/tests/isolation/test_folder_paths_proxy.py
John Pollock c5e7b9cdaf feat(isolation): process isolation for custom nodes via pyisolate
Adds opt-in process isolation for custom nodes using pyisolate's
bwrap sandbox and JSON-RPC bridge. Each isolated node pack runs in
its own child process with zero-copy tensor transfer via shared memory.

Core infrastructure:
- CLI flag --use-process-isolation to enable isolation
- Host/child startup fencing via PYISOLATE_CHILD env var
- Manifest-driven node discovery and extension loading
- JSON-RPC bridge between host and child processes
- Shared memory forensics for leak detection

Proxy layer:
- ModelPatcher, CLIP, VAE, and ModelSampling proxies
- Host service proxies (folder_paths, model_management, progress, etc.)
- Proxy base with automatic method forwarding

Execution integration:
- Extension wrapper with V3 hidden param mapping
- Runtime helpers for isolated node execution
- Host policy for node isolation decisions
- Fenced sampler device handling and model ejection parity

Serializers for cross-process data transfer:
- File3D (GLB), PLY (structured + gaussian), NPZ (streaming frames),
  VIDEO (VideoFromFile + VideoFromComponents) serializers
- data_type flag in SerializerRegistry for type-aware dispatch
- Isolated get_temp_directory() fence

New core save nodes:
- SavePLY and SaveNPZ with comfytype registrations (Ply, Npz)

DynamicVRAM compatibility:
- comfy-aimdo early init gated by isolation fence

Tests:
- Integration and policy tests for isolation lifecycle
- Manifest loader, host policy, proxy, and adapter unit tests

Depends on: pyisolate >= 0.9.2
2026-03-12 01:13:43 -05:00

112 lines
5.4 KiB
Python

"""Unit tests for FolderPathsProxy."""
import pytest
from pathlib import Path
from comfy.isolation.proxies.folder_paths_proxy import FolderPathsProxy
class TestFolderPathsProxy:
"""Test FolderPathsProxy methods."""
@pytest.fixture
def proxy(self):
"""Create a FolderPathsProxy instance for testing."""
return FolderPathsProxy()
def test_get_temp_directory_returns_string(self, proxy):
"""Verify get_temp_directory returns a non-empty string."""
result = proxy.get_temp_directory()
assert isinstance(result, str), f"Expected str, got {type(result)}"
assert len(result) > 0, "Temp directory path is empty"
def test_get_temp_directory_returns_absolute_path(self, proxy):
"""Verify get_temp_directory returns an absolute path."""
result = proxy.get_temp_directory()
path = Path(result)
assert path.is_absolute(), f"Path is not absolute: {result}"
def test_get_input_directory_returns_string(self, proxy):
"""Verify get_input_directory returns a non-empty string."""
result = proxy.get_input_directory()
assert isinstance(result, str), f"Expected str, got {type(result)}"
assert len(result) > 0, "Input directory path is empty"
def test_get_input_directory_returns_absolute_path(self, proxy):
"""Verify get_input_directory returns an absolute path."""
result = proxy.get_input_directory()
path = Path(result)
assert path.is_absolute(), f"Path is not absolute: {result}"
def test_get_annotated_filepath_plain_name(self, proxy):
"""Verify get_annotated_filepath works with plain filename."""
result = proxy.get_annotated_filepath("test.png")
assert isinstance(result, str), f"Expected str, got {type(result)}"
assert "test.png" in result, f"Filename not in result: {result}"
def test_get_annotated_filepath_with_output_annotation(self, proxy):
"""Verify get_annotated_filepath handles [output] annotation."""
result = proxy.get_annotated_filepath("test.png[output]")
assert isinstance(result, str), f"Expected str, got {type(result)}"
assert "test.pn" in result, f"Filename base not in result: {result}"
# Should resolve to output directory
assert "output" in result.lower() or Path(result).parent.name == "output"
def test_get_annotated_filepath_with_input_annotation(self, proxy):
"""Verify get_annotated_filepath handles [input] annotation."""
result = proxy.get_annotated_filepath("test.png[input]")
assert isinstance(result, str), f"Expected str, got {type(result)}"
assert "test.pn" in result, f"Filename base not in result: {result}"
def test_get_annotated_filepath_with_temp_annotation(self, proxy):
"""Verify get_annotated_filepath handles [temp] annotation."""
result = proxy.get_annotated_filepath("test.png[temp]")
assert isinstance(result, str), f"Expected str, got {type(result)}"
assert "test.pn" in result, f"Filename base not in result: {result}"
def test_exists_annotated_filepath_returns_bool(self, proxy):
"""Verify exists_annotated_filepath returns a boolean."""
result = proxy.exists_annotated_filepath("nonexistent.png")
assert isinstance(result, bool), f"Expected bool, got {type(result)}"
def test_exists_annotated_filepath_nonexistent_file(self, proxy):
"""Verify exists_annotated_filepath returns False for nonexistent file."""
result = proxy.exists_annotated_filepath("definitely_does_not_exist_12345.png")
assert result is False, "Expected False for nonexistent file"
def test_exists_annotated_filepath_with_annotation(self, proxy):
"""Verify exists_annotated_filepath works with annotation suffix."""
# Even for nonexistent files, should return bool without error
result = proxy.exists_annotated_filepath("test.png[output]")
assert isinstance(result, bool), f"Expected bool, got {type(result)}"
def test_models_dir_property_returns_string(self, proxy):
"""Verify models_dir property returns valid path string."""
result = proxy.models_dir
assert isinstance(result, str), f"Expected str, got {type(result)}"
assert len(result) > 0, "Models directory path is empty"
def test_models_dir_is_absolute_path(self, proxy):
"""Verify models_dir returns an absolute path."""
result = proxy.models_dir
path = Path(result)
assert path.is_absolute(), f"Path is not absolute: {result}"
def test_add_model_folder_path_runs_without_error(self, proxy):
"""Verify add_model_folder_path executes without raising."""
test_path = "/tmp/test_models_florence2"
# Should not raise
proxy.add_model_folder_path("TEST_FLORENCE2", test_path)
def test_get_folder_paths_returns_list(self, proxy):
"""Verify get_folder_paths returns a list."""
# Use known folder type that should exist
result = proxy.get_folder_paths("checkpoints")
assert isinstance(result, list), f"Expected list, got {type(result)}"
def test_get_folder_paths_checkpoints_not_empty(self, proxy):
"""Verify checkpoints folder paths list is not empty."""
result = proxy.get_folder_paths("checkpoints")
# Should have at least one checkpoint path registered
assert len(result) > 0, "Checkpoints folder paths is empty"