Release V3.8X2 package 3.8.3
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
from pathlib import Path
|
||||
import sys
|
||||
import uuid
|
||||
|
||||
import pytest
|
||||
import torch
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parents[2]))
|
||||
sys.modules["decode_cache_test_fixtures"] = sys.modules[__name__]
|
||||
|
||||
|
||||
class NativeVideoModel(torch.nn.Module):
|
||||
__module__ = "comfy.ldm.minimax.vae"
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.register_parameter("weight", torch.nn.Parameter(torch.ones(1), requires_grad=False))
|
||||
self.register_buffer("offset", torch.zeros(1))
|
||||
self.tile_size = 256
|
||||
self.eval()
|
||||
|
||||
def decode(self, tensor):
|
||||
return tensor * self.weight + self.offset
|
||||
|
||||
|
||||
class NativeAudioModel(NativeVideoModel):
|
||||
__module__ = "comfy.ldm.minimax.audio_vae"
|
||||
|
||||
|
||||
class Patcher:
|
||||
def __init__(self):
|
||||
self.patches_uuid = uuid.uuid4()
|
||||
self.object_patches = {}
|
||||
|
||||
|
||||
class FakeVAE:
|
||||
"""Controlled delegate fixture, NOT a real MiniMax model/GPU execution."""
|
||||
__module__ = "comfy.sd"
|
||||
|
||||
def __init__(self, stream="video"):
|
||||
self.first_stage_model = NativeVideoModel() if stream == "video" else NativeAudioModel()
|
||||
self.patcher = Patcher()
|
||||
self.vae_dtype = torch.float32
|
||||
self.output_device = torch.device("cpu")
|
||||
self.device = torch.device("cpu")
|
||||
self.audio_sample_rate = 32000
|
||||
self.calls = 0
|
||||
|
||||
def decode(self, tensor):
|
||||
self.calls += 1
|
||||
return self.first_stage_model.decode(tensor)
|
||||
|
||||
def process_output(self, x):
|
||||
return x
|
||||
|
||||
|
||||
class NestedFixture:
|
||||
is_nested = True
|
||||
|
||||
def __init__(self, video, audio):
|
||||
self.parts = video, audio
|
||||
|
||||
def unbind(self):
|
||||
return self.parts
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def vae():
|
||||
return FakeVAE()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def samples():
|
||||
return {"samples": torch.arange(120, dtype=torch.float32).reshape(5, 3, 4, 2) / 120}
|
||||
@@ -0,0 +1,47 @@
|
||||
"""Isolated disposable-cache fault worker; never opens Run Storage or a ComfyUI backend."""
|
||||
from pathlib import Path
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[3]
|
||||
sys.path.insert(0, str(ROOT))
|
||||
|
||||
import torch
|
||||
from decode_cache import store as module
|
||||
from decode_cache.store import DecodeStore, MiB
|
||||
|
||||
parent, marker, point = Path(sys.argv[1]), Path(sys.argv[2]), sys.argv[3]
|
||||
store = DecodeStore(temp_parent=parent, memory_probe=lambda: 10**12, headroom_bytes=0)
|
||||
store.configure("Auto", MiB, 8*MiB, 0)
|
||||
if point == "reader":
|
||||
print(json.dumps({"hit": store.get("same-key") is not None, "root_created": store.root is not None}))
|
||||
sys.exit(0)
|
||||
|
||||
|
||||
def pause():
|
||||
marker.write_text(point, encoding="utf-8")
|
||||
while True:
|
||||
time.sleep(0.05)
|
||||
|
||||
|
||||
if point == "during_raw":
|
||||
original_blocks = module.tensor_blocks
|
||||
def blocks(tensor):
|
||||
iterator = iter(original_blocks(tensor))
|
||||
first = next(iterator)
|
||||
yield first[:16]
|
||||
pause()
|
||||
module.tensor_blocks = blocks
|
||||
elif point == "before_publish":
|
||||
replace = os.replace
|
||||
def before_replace(src, dst):
|
||||
pause()
|
||||
return replace(src, dst)
|
||||
os.replace = before_replace
|
||||
|
||||
result = store.put("same-key", torch.ones(64, 64, 3), "video", {}, (), store.epoch)
|
||||
if point == "after_publish":
|
||||
pause()
|
||||
raise RuntimeError("fault point was not reached")
|
||||
@@ -0,0 +1,273 @@
|
||||
import importlib.util
|
||||
import json
|
||||
import math
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from types import ModuleType, SimpleNamespace
|
||||
|
||||
import pytest
|
||||
import torch
|
||||
|
||||
from decode_cache.service import DecodeService, native_delegate
|
||||
from decode_cache.identity import selected_latent, vae_signature
|
||||
from decode_cache.nodes import H3DecodeCacheHelper, NODE_CLASS_MAPPINGS
|
||||
from decode_cache.store import DecodeStore, MiB
|
||||
from decode_cache_test_fixtures import FakeVAE, NestedFixture
|
||||
|
||||
|
||||
def fake_video(vae, samples):
|
||||
return vae.decode(selected_latent(samples, "video"))
|
||||
|
||||
|
||||
def fake_audio(vae, samples):
|
||||
# A controlled Core-helper surrogate returns sample-rate metadata as Core does.
|
||||
return {"waveform": vae.decode(selected_latent(samples, "audio")),
|
||||
"sample_rate": samples.get("sample_rate", vae.audio_sample_rate)}
|
||||
|
||||
|
||||
def resolver(stream):
|
||||
f = fake_video if stream == "video" else fake_audio
|
||||
return f, f
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def service(tmp_path):
|
||||
store = DecodeStore(temp_parent=tmp_path, memory_probe=lambda: 10**12,
|
||||
disk_probe=lambda p: SimpleNamespace(free=10**12), headroom_bytes=0)
|
||||
store.configure("Auto", MiB, 8*MiB, 0)
|
||||
service = DecodeService(store=store, delegate_resolver=resolver, interrupt=lambda: None)
|
||||
yield service
|
||||
service.store.close()
|
||||
|
||||
|
||||
def test_delegate_called_once_warm(service, vae, samples):
|
||||
a, e = service.decode(samples, vae, "video")
|
||||
b, f = service.decode(samples, vae, "video")
|
||||
assert e["status"] == "miss" and f["status"] == "hit"
|
||||
assert vae.calls == 1 and torch.equal(a, b)
|
||||
|
||||
|
||||
def test_audio_metadata_override_and_mutation(service):
|
||||
vae = FakeVAE("audio")
|
||||
samples = {"samples": torch.ones(1, 2, 40), "sample_rate": 22050}
|
||||
a, _ = service.decode(samples, vae, "audio")
|
||||
a["waveform"].zero_()
|
||||
a["sample_rate"] = 5
|
||||
b, e = service.decode(samples, vae, "audio")
|
||||
assert e["status"] == "hit"
|
||||
assert b["sample_rate"] == 22050 and b["waveform"].sum() == 80
|
||||
samples["sample_rate"] = 32000
|
||||
_, e = service.decode(samples, vae, "audio")
|
||||
assert e["status"] == "miss"
|
||||
|
||||
|
||||
def test_core_error_not_retried(service, vae, samples):
|
||||
calls = []
|
||||
def broken(vae, samples):
|
||||
calls.append(1)
|
||||
raise RuntimeError("native decode failed")
|
||||
service.delegate_resolver = lambda stream: (broken, broken)
|
||||
with pytest.raises(RuntimeError, match="native decode failed"):
|
||||
service.decode(samples, vae, "video")
|
||||
assert len(calls) == 1
|
||||
|
||||
|
||||
@pytest.mark.parametrize("point", ["signature", "get", "put"])
|
||||
def test_cache_fail_open(service, vae, samples, monkeypatch, point):
|
||||
def broken(*args, **kwargs):
|
||||
raise OSError("fixture-only cache failure")
|
||||
if point == "signature":
|
||||
service.signature_fn = broken
|
||||
else:
|
||||
monkeypatch.setattr(service.store, point, broken)
|
||||
result, event = service.decode(samples, vae, "video")
|
||||
assert torch.equal(result, samples["samples"])
|
||||
assert vae.calls == 1
|
||||
|
||||
|
||||
def test_interrupt_not_swallowed(service, vae, samples, monkeypatch):
|
||||
class InterruptProcessingException(Exception):
|
||||
pass
|
||||
def interrupted(*args):
|
||||
raise InterruptProcessingException()
|
||||
monkeypatch.setattr(service.store, "get", interrupted)
|
||||
with pytest.raises(InterruptProcessingException):
|
||||
service.decode(samples, vae, "video")
|
||||
assert vae.calls == 0
|
||||
|
||||
|
||||
def test_unsupported_vae_still_decodes(service, samples):
|
||||
class Unknown:
|
||||
def decode(self, tensor):
|
||||
return tensor.clone()
|
||||
result, event = service.decode(samples, Unknown(), "video")
|
||||
assert event["status"] == "bypass" and torch.equal(result, samples["samples"])
|
||||
|
||||
|
||||
def test_vae_change_during_decode_skips_store(service, vae, samples):
|
||||
def changing(vae, samples):
|
||||
vae.first_stage_model.tile_size += 1
|
||||
return vae.decode(selected_latent(samples, "video"))
|
||||
service.delegate_resolver = lambda stream: (changing, changing)
|
||||
_, event = service.decode(samples, vae, "video")
|
||||
assert "store_skipped" in event and not service.store.entries
|
||||
|
||||
|
||||
def test_q1_q2_q3_q4_physical_lists(service):
|
||||
vae = FakeVAE()
|
||||
groups = [{"samples": torch.ones(124 if i == 0 else 141, 2, 2, 3)*i} for i in range(3)]
|
||||
statuses = []
|
||||
for sequence in ([groups[0]], [groups[1]], groups, groups):
|
||||
statuses.append([service.decode(s, vae, "video")[1]["status"] for s in sequence])
|
||||
assert statuses == [["miss"], ["miss"], ["hit", "hit", "miss"], ["hit", "hit", "hit"]]
|
||||
assert vae.calls == 3
|
||||
|
||||
|
||||
def test_terminal_entry_never_sliced(service):
|
||||
vae = FakeVAE()
|
||||
x = torch.rand(260, 2, 2, 3)
|
||||
for _ in range(2):
|
||||
out, _ = service.decode({"samples": x}, vae, "video")
|
||||
assert torch.equal(out, x)
|
||||
assert vae.calls == 1
|
||||
|
||||
|
||||
def test_retry_changed_group_only_misses(service):
|
||||
vae = FakeVAE()
|
||||
a = {"samples": torch.ones(8, 2, 2, 3)}
|
||||
b = {"samples": torch.ones(8, 2, 2, 3)*2}
|
||||
service.decode(a, vae, "video")
|
||||
service.decode(b, vae, "video")
|
||||
b["samples"].add_(1)
|
||||
assert service.decode(a, vae, "video")[1]["status"] == "hit"
|
||||
assert service.decode(b, vae, "video")[1]["status"] == "miss"
|
||||
|
||||
|
||||
def test_native_functions_are_delegated(monkeypatch, vae, samples):
|
||||
calls = []
|
||||
mod = ModuleType("nodes")
|
||||
class VAEDecode:
|
||||
def decode(self, vae, samples):
|
||||
calls.append(("video", vae, samples))
|
||||
return (samples["samples"],)
|
||||
mod.VAEDecode = VAEDecode
|
||||
monkeypatch.setitem(sys.modules, "nodes", mod)
|
||||
audio = ModuleType("comfy_extras.nodes_audio")
|
||||
def audio_helper(vae, samples):
|
||||
calls.append(("audio", vae, samples))
|
||||
return {"waveform": samples["samples"], "sample_rate": 12345}
|
||||
audio.vae_decode_audio = audio_helper
|
||||
monkeypatch.setitem(sys.modules, "comfy_extras.nodes_audio", audio)
|
||||
assert native_delegate("video")[1](vae, samples) is samples["samples"]
|
||||
assert native_delegate("audio")[1](vae, samples)["sample_rate"] == 12345
|
||||
assert len(calls) == 2
|
||||
|
||||
|
||||
def test_one_public_node_and_nan():
|
||||
assert list(NODE_CLASS_MAPPINGS) == ["H3DecodeCacheHelper"]
|
||||
assert H3DecodeCacheHelper.INPUT_IS_LIST
|
||||
assert H3DecodeCacheHelper.OUTPUT_IS_LIST == (True, True, False)
|
||||
assert math.isnan(H3DecodeCacheHelper.IS_CHANGED())
|
||||
|
||||
|
||||
@pytest.mark.parametrize("streams", ["video", "audio", "both", "none"])
|
||||
def test_node_optional_independent_lists(service, streams):
|
||||
node = H3DecodeCacheHelper()
|
||||
node.service = service
|
||||
kwargs = {}
|
||||
if streams in ("video", "both"):
|
||||
kwargs.update(video_samples=[{"samples": torch.ones(4, 2, 2, 3)}]*2, video_vae=[FakeVAE()])
|
||||
if streams in ("audio", "both"):
|
||||
kwargs.update(audio_samples=[{"samples": torch.ones(1, 2, 16)}], audio_vae=[FakeVAE("audio")])
|
||||
images, audio, report = node.decode(["Auto"], [1], [1], [0], **kwargs)
|
||||
assert len(images) == (2 if streams in ("video", "both") else 0)
|
||||
assert len(audio) == (1 if streams in ("audio", "both") else 0)
|
||||
assert json.loads(report)["mode"] == "Auto"
|
||||
|
||||
|
||||
def test_none_position_no_broadcast(service):
|
||||
node = H3DecodeCacheHelper()
|
||||
node.service = service
|
||||
images, _, _ = node.decode(["Auto"], [1], [1], [0],
|
||||
video_samples=[None, {"samples": torch.ones(4, 2, 2, 3)}], video_vae=[FakeVAE()])
|
||||
assert images[0] is None and images[1].shape == (4, 2, 2, 3)
|
||||
|
||||
|
||||
def test_off_disables_content_cache(service, vae, samples):
|
||||
node = H3DecodeCacheHelper()
|
||||
node.service = service
|
||||
for _ in range(2):
|
||||
node.decode(["Off"], [1], [0], [0], video_samples=[samples], video_vae=[vae])
|
||||
assert vae.calls == 2 and not service.store.entries
|
||||
|
||||
|
||||
def test_cache_configuration_fault_is_nonfatal(service, vae, samples, monkeypatch):
|
||||
node = H3DecodeCacheHelper()
|
||||
node.service = service
|
||||
def bad(*a):
|
||||
raise OSError("memory probe unavailable")
|
||||
monkeypatch.setattr(service.store, "configure", bad)
|
||||
result = node.decode(["Auto"], [1], [1], [0], video_samples=[samples], video_vae=[vae])
|
||||
assert vae.calls == 1
|
||||
assert "cache_disabled_reason" in json.loads(result[2])
|
||||
|
||||
|
||||
def test_builtin_helper_is_publicly_registered():
|
||||
from ComfyUI_H3_Continuum_Join import nodes as continuum_nodes
|
||||
|
||||
assert "H3DecodeCacheHelper" in continuum_nodes.NODE_CLASS_MAPPINGS
|
||||
assert continuum_nodes.NODE_DISPLAY_NAME_MAPPINGS["H3DecodeCacheHelper"] == "Decode Cache Helper"
|
||||
|
||||
|
||||
def test_forbidden_runtime_imports():
|
||||
import ast
|
||||
root = Path(__file__).resolve().parents[2]/"decode_cache"
|
||||
forbidden = {"run_storage", "runtime_coordinator", "execution_planner", "sampling_engine"}
|
||||
for path in root.glob("*.py"):
|
||||
tree = ast.parse(path.read_text())
|
||||
for node in ast.walk(tree):
|
||||
if isinstance(node, ast.ImportFrom):
|
||||
assert not forbidden.intersection((node.module or "").split("."))
|
||||
|
||||
|
||||
def test_cache_memory_error_returns_already_decoded_result(service, vae, samples, monkeypatch):
|
||||
def no_memory(*args, **kwargs):
|
||||
raise MemoryError("cache allocation failed")
|
||||
monkeypatch.setattr(service.store, "put", no_memory)
|
||||
out, event = service.decode(samples, vae, "video")
|
||||
assert torch.equal(out, samples["samples"])
|
||||
assert vae.calls == 1 and "cache_write_error" in event
|
||||
|
||||
|
||||
def test_native_oom_propagates_exactly_once(service, vae, samples):
|
||||
calls = []
|
||||
def oom(*args, **kwargs):
|
||||
calls.append(1)
|
||||
raise torch.OutOfMemoryError("native fixture OOM")
|
||||
service.delegate_resolver = lambda stream: (oom, oom)
|
||||
with pytest.raises(torch.OutOfMemoryError):
|
||||
service.decode(samples, vae, "video")
|
||||
assert calls == [1]
|
||||
|
||||
|
||||
def test_cancel_during_cache_store_is_not_a_native_retry(service, vae, samples, monkeypatch):
|
||||
class InterruptProcessingException(Exception):
|
||||
pass
|
||||
def canceled(*args, **kwargs):
|
||||
raise InterruptProcessingException("cancel fixture")
|
||||
monkeypatch.setattr(service.store, "put", canceled)
|
||||
with pytest.raises(InterruptProcessingException):
|
||||
service.decode(samples, vae, "video")
|
||||
assert vae.calls == 1
|
||||
|
||||
|
||||
def test_two_simultaneous_node_calls_serialize_one_miss(service, vae, samples):
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
node = H3DecodeCacheHelper()
|
||||
node.service = service
|
||||
def run():
|
||||
return node.decode(["Auto"], [1], [1], [0], video_samples=[samples], video_vae=[vae])
|
||||
with ThreadPoolExecutor(max_workers=2) as pool:
|
||||
result = list(pool.map(lambda _: run(), range(2)))
|
||||
assert vae.calls == 1
|
||||
assert torch.equal(result[0][0][0], result[1][0][0])
|
||||
@@ -0,0 +1,164 @@
|
||||
import gc
|
||||
import uuid
|
||||
import weakref
|
||||
|
||||
import pytest
|
||||
import torch
|
||||
|
||||
from decode_cache.identity import CacheBypass, ObjectTokens, make_key, selected_latent, tensor_digest, vae_signature
|
||||
from decode_cache_test_fixtures import FakeVAE, NestedFixture
|
||||
|
||||
|
||||
def delegate():
|
||||
pass
|
||||
|
||||
|
||||
def test_same_content_different_object_same_key(samples):
|
||||
other = {"samples": samples["samples"].clone()}
|
||||
assert make_key(samples, "video", "s") == make_key(other, "video", "s")
|
||||
|
||||
|
||||
@pytest.mark.parametrize("dtype", [torch.float16, torch.float32, torch.float64, torch.bfloat16, torch.int16])
|
||||
def test_tensor_bytes_all_dtypes(dtype):
|
||||
x = torch.arange(60).to(dtype).reshape(3, 4, 5)
|
||||
assert tensor_digest(x) == tensor_digest(x.clone())
|
||||
x[0, 0, 0] += 1
|
||||
assert tensor_digest(x) != tensor_digest(torch.arange(60).to(dtype).reshape(3, 4, 5))
|
||||
|
||||
|
||||
@pytest.mark.parametrize("shape", [(), (0,), (1,), (3, 4), (1, 2, 8), (2, 1, 3, 4)])
|
||||
def test_block_hash_matches_raw(shape):
|
||||
import hashlib
|
||||
from decode_cache.identity import tensor_blocks
|
||||
x = torch.ones(shape)
|
||||
actual = hashlib.sha256(b"".join(bytes(b) for b in tensor_blocks(x, 9))).hexdigest()
|
||||
expected = hashlib.sha256(x.contiguous().reshape(-1).view(torch.uint8).numpy().tobytes()).hexdigest()
|
||||
assert actual == expected
|
||||
|
||||
|
||||
def test_noncontiguous_order():
|
||||
x = torch.arange(120).reshape(4, 5, 6).transpose(0, 2)
|
||||
assert tensor_digest(x) == tensor_digest(x.contiguous())
|
||||
|
||||
|
||||
@pytest.mark.parametrize("change", ["content", "dtype", "shape", "vae", "stream", "reset", "sample_rate", "extra"])
|
||||
def test_key_invalidations(samples, change):
|
||||
kwargs = {"samples": samples, "stream": "video", "signature": "s", "reset_token": 0}
|
||||
before = make_key(**kwargs)
|
||||
if change == "content":
|
||||
samples["samples"][0, 0, 0, 0] += 1
|
||||
elif change == "dtype":
|
||||
samples["samples"] = samples["samples"].double()
|
||||
elif change == "shape":
|
||||
samples["samples"] = samples["samples"].reshape(6, 2, 5, 2)
|
||||
elif change == "vae":
|
||||
kwargs["signature"] = "other"
|
||||
elif change == "stream":
|
||||
kwargs["stream"] = "audio"
|
||||
elif change == "reset":
|
||||
kwargs["reset_token"] = 1
|
||||
elif change == "sample_rate":
|
||||
samples["sample_rate"] = 22050
|
||||
else:
|
||||
samples["noise_mask"] = torch.zeros(1)
|
||||
assert make_key(**kwargs) != before
|
||||
|
||||
|
||||
def test_audio_rate_override_key():
|
||||
x = torch.zeros(1, 2, 8)
|
||||
assert make_key({"samples": x, "sample_rate": 16000}, "audio", "s") != make_key({"samples": x, "sample_rate": 32000}, "audio", "s")
|
||||
|
||||
|
||||
def test_nested_only_selected_stream():
|
||||
x, y = torch.ones(1, 24, 2, 2, 2), torch.ones(1, 32, 2, 4)
|
||||
s = {"samples": NestedFixture(x, y)}
|
||||
v = make_key(s, "video", "s")
|
||||
a = make_key(s, "audio", "s")
|
||||
y.add_(3)
|
||||
assert make_key(s, "video", "s") == v
|
||||
assert make_key(s, "audio", "s") != a
|
||||
assert selected_latent(s, "audio") is y
|
||||
|
||||
|
||||
def test_opaque_metadata_bypass(samples):
|
||||
samples["opaque"] = object()
|
||||
with pytest.raises(CacheBypass):
|
||||
make_key(samples, "video", "s")
|
||||
|
||||
|
||||
def test_inference_tensor_hash_no_version_required():
|
||||
with torch.inference_mode():
|
||||
x = torch.ones(4)
|
||||
assert tensor_digest(x) == tensor_digest(x.clone())
|
||||
|
||||
|
||||
def test_identity_does_not_keep_vae_alive():
|
||||
vae = FakeVAE() # no pytest fixture owner remains alive
|
||||
signature, refs = vae_signature(vae, "video", delegate)
|
||||
ref = weakref.ref(vae)
|
||||
del vae
|
||||
gc.collect()
|
||||
assert ref() is None
|
||||
assert refs[0]() is None
|
||||
|
||||
|
||||
def test_object_tokens_not_address_only():
|
||||
tokens = ObjectTokens()
|
||||
a, b = FakeVAE(), FakeVAE()
|
||||
assert tokens.token(a) == tokens.token(a)
|
||||
assert tokens.token(a) != tokens.token(b)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("change", ["patch_uuid", "weight_copy", "buffer_copy", "tiling", "dtype", "new_vae"])
|
||||
def test_vae_signature_changes(vae, change):
|
||||
a = vae_signature(vae, "video", delegate)[0]
|
||||
if change == "patch_uuid":
|
||||
vae.patcher.patches_uuid = uuid.uuid4()
|
||||
elif change == "weight_copy":
|
||||
vae.first_stage_model.weight.copy_(torch.ones(1)*2)
|
||||
elif change == "buffer_copy":
|
||||
vae.first_stage_model.offset.add_(1)
|
||||
elif change == "tiling":
|
||||
vae.first_stage_model.tile_size = 512
|
||||
elif change == "dtype":
|
||||
vae.vae_dtype = torch.float16
|
||||
else:
|
||||
vae = FakeVAE()
|
||||
assert vae_signature(vae, "video", delegate)[0] != a
|
||||
|
||||
|
||||
def test_unknown_vae_and_training_bypass(vae):
|
||||
with pytest.raises(CacheBypass):
|
||||
vae_signature(object(), "video", delegate)
|
||||
vae.first_stage_model.train()
|
||||
with pytest.raises(CacheBypass):
|
||||
vae_signature(vae, "video", delegate)
|
||||
|
||||
|
||||
def test_relocation_buffer_identity_not_used(vae):
|
||||
a = vae_signature(vae, "video", delegate)[0]
|
||||
vae.first_stage_model.offset = vae.first_stage_model.offset.clone()
|
||||
assert vae_signature(vae, "video", delegate)[0] == a
|
||||
|
||||
|
||||
def test_empty_native_model_options_allowed_but_hooks_bypass(vae):
|
||||
vae.patcher.model_options = {"transformer_options": {}}
|
||||
vae_signature(vae, "video", delegate)
|
||||
vae.patcher.model_options["transformer_options"]["wrapper"] = object()
|
||||
with pytest.raises(CacheBypass):
|
||||
vae_signature(vae, "video", delegate)
|
||||
|
||||
|
||||
def test_forward_hook_disables_cache_only(vae):
|
||||
handle = vae.first_stage_model.register_forward_hook(lambda *args: None)
|
||||
try:
|
||||
with pytest.raises(CacheBypass):
|
||||
vae_signature(vae, "video", delegate)
|
||||
finally:
|
||||
handle.remove()
|
||||
|
||||
|
||||
def test_inference_context_has_separate_identity(vae):
|
||||
before = vae_signature(vae, "video", delegate)[0]
|
||||
with torch.inference_mode():
|
||||
assert vae_signature(vae, "video", delegate)[0] != before
|
||||
@@ -0,0 +1,50 @@
|
||||
"""Process termination tests on the host OS, not a Windows/power-loss claim."""
|
||||
from pathlib import Path
|
||||
import json
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
|
||||
import numpy as np
|
||||
import pytest
|
||||
|
||||
WORKER = Path(__file__).parent / "helpers" / "cache_process_worker.py"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("point", ["during_raw", "before_publish", "after_publish"])
|
||||
def test_process_kill_leaves_only_disposable_private_files(tmp_path, point):
|
||||
parent = tmp_path / "private-cache-parent"
|
||||
parent.mkdir()
|
||||
marker = tmp_path / "ready.txt"
|
||||
user_file = tmp_path / "untouched-run-storage.txt"
|
||||
user_file.write_text("existing accepted data")
|
||||
env = {**os.environ, "PYTHONDONTWRITEBYTECODE": "1", "OMP_NUM_THREADS": "1"}
|
||||
p = subprocess.Popen([sys.executable, str(WORKER), str(parent), str(marker), point],
|
||||
stdout=subprocess.DEVNULL, stderr=subprocess.PIPE, env=env)
|
||||
try:
|
||||
deadline = time.monotonic() + 20
|
||||
while not marker.exists() and time.monotonic() < deadline:
|
||||
if p.poll() is not None:
|
||||
raise AssertionError(p.stderr.read().decode())
|
||||
time.sleep(0.03)
|
||||
assert marker.exists(), "worker never reached the kill boundary"
|
||||
p.kill()
|
||||
p.wait(timeout=5)
|
||||
finally:
|
||||
if p.poll() is None:
|
||||
p.kill()
|
||||
p.wait(timeout=5)
|
||||
if p.stderr:
|
||||
p.stderr.close()
|
||||
raw = list(parent.rglob("*.npy"))
|
||||
temporary = list(parent.rglob("*.tmp"))
|
||||
if point == "after_publish":
|
||||
assert len(raw) == 1 and not temporary
|
||||
assert np.array_equal(np.load(raw[0], allow_pickle=False), np.ones((64, 64, 3), dtype=np.float32))
|
||||
else:
|
||||
assert not raw and len(temporary) == 1
|
||||
reader = subprocess.run([sys.executable, str(WORKER), str(parent), str(marker), "reader"],
|
||||
capture_output=True, text=True, env=env, check=True, timeout=20)
|
||||
assert json.loads(reader.stdout.splitlines()[-1]) == {"hit": False, "root_created": False}
|
||||
assert user_file.read_text() == "existing accepted data"
|
||||
@@ -0,0 +1,295 @@
|
||||
import gc
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
from types import SimpleNamespace
|
||||
import weakref
|
||||
|
||||
import pytest
|
||||
import torch
|
||||
|
||||
from decode_cache.identity import CacheBypass
|
||||
from decode_cache.store import DecodeStore, MiB
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def store(tmp_path):
|
||||
s = DecodeStore(temp_parent=tmp_path, memory_probe=lambda: 10**12,
|
||||
disk_probe=lambda p: SimpleNamespace(free=10**12), headroom_bytes=0)
|
||||
s.configure("Auto", 1024**2, 1024**2, 0)
|
||||
yield s
|
||||
s.close()
|
||||
|
||||
|
||||
def put(store, key, x, stream="video"):
|
||||
return store.put(key, x, stream, {}, (), store.epoch)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("mode", ["Auto", "RAM"])
|
||||
def test_hit_bit_exact_mutation_isolation(store, mode):
|
||||
store.configure(mode, MiB, MiB, 0)
|
||||
x = torch.arange(120).float().reshape(5, 3, 4, 2)
|
||||
replacement = put(store, "a", x)
|
||||
first = replacement[0] if replacement else x
|
||||
first.add_(7)
|
||||
hit, _ = store.get("a")
|
||||
assert torch.equal(hit, torch.arange(120).float().reshape(5, 3, 4, 2))
|
||||
hit.zero_()
|
||||
again, _ = store.get("a")
|
||||
assert again.sum().item() > 0
|
||||
|
||||
|
||||
@pytest.mark.parametrize("mode", ["Auto", "RAM"])
|
||||
def test_view_mutation_does_not_poison(store, mode):
|
||||
store.configure(mode, MiB, MiB, 0)
|
||||
put(store, "a", torch.ones(4, 3, 2, 1))
|
||||
hit, _ = store.get("a")
|
||||
hit[1:3].mul_(0)
|
||||
other, _ = store.get("a")
|
||||
assert other.sum() == 24
|
||||
|
||||
|
||||
def test_noncontiguous_serialization(store):
|
||||
x = torch.arange(120).float().reshape(5, 3, 4, 2).transpose(0, 2)
|
||||
put(store, "a", x)
|
||||
y, _ = store.get("a")
|
||||
assert y.dtype == x.dtype and torch.equal(x, y)
|
||||
|
||||
|
||||
def test_dtype_unchanged(store):
|
||||
for dtype in (torch.float16, torch.float32, torch.float64):
|
||||
x = torch.arange(12).to(dtype)
|
||||
put(store, str(dtype), x)
|
||||
y, _ = store.get(str(dtype))
|
||||
assert y.dtype == dtype and torch.equal(x, y)
|
||||
|
||||
|
||||
def test_ram_lru_and_budget(store):
|
||||
store.configure("RAM", 32, MiB, 0)
|
||||
put(store, "a", torch.ones(4))
|
||||
put(store, "b", torch.ones(4)*2)
|
||||
assert store.get("a") is not None
|
||||
put(store, "c", torch.ones(4)*3)
|
||||
assert store.get("b") is None
|
||||
assert store.ram_bytes == 32
|
||||
|
||||
|
||||
def test_ram_pressure_evicts(store):
|
||||
store.configure("RAM", MiB, MiB, 0)
|
||||
put(store, "a", torch.ones(4))
|
||||
store.headroom_bytes = 1024
|
||||
store.memory_probe = lambda: 0
|
||||
store.configure("RAM", MiB, MiB, 0)
|
||||
assert store.get("a") is None
|
||||
assert store.ram_bytes == 0
|
||||
|
||||
|
||||
def test_auto_under_ram_pressure_uses_disk(store):
|
||||
store.memory_probe = lambda: 0
|
||||
put(store, "a", torch.ones(24), "audio")
|
||||
assert store.entries["a"].path is not None
|
||||
|
||||
|
||||
def test_disk_full_skips_cache(store):
|
||||
store.disk_probe = lambda p: SimpleNamespace(free=0)
|
||||
assert put(store, "a", torch.ones(4)) is None
|
||||
assert store.get("a") is None
|
||||
|
||||
|
||||
def test_oversized_skips(store):
|
||||
store.configure("Auto", 0, 8, 0)
|
||||
assert put(store, "a", torch.ones(4)) is None
|
||||
assert store.root is None
|
||||
|
||||
|
||||
def test_living_mmap_survives_clear_and_accounts_bytes(store):
|
||||
hit = put(store, "a", torch.ones(4))[0]
|
||||
path = store.entries["a"].path
|
||||
store.clear()
|
||||
assert path.exists()
|
||||
assert store.disk_bytes > 0
|
||||
hit.add_(2)
|
||||
assert torch.equal(hit, torch.ones(4)*3)
|
||||
del hit
|
||||
gc.collect()
|
||||
store.stats()
|
||||
assert not path.exists()
|
||||
assert store.disk_bytes == 0
|
||||
|
||||
|
||||
def test_no_cross_process_store_reuse(store, tmp_path):
|
||||
put(store, "a", torch.ones(4))
|
||||
other = DecodeStore(temp_parent=tmp_path)
|
||||
assert other.get("a") is None
|
||||
other.close()
|
||||
|
||||
|
||||
@pytest.mark.parametrize("damage", ["truncate", "header", "data", "delete"])
|
||||
def test_corrupt_disk_invalidates(store, damage):
|
||||
result = put(store, "a", torch.ones(20))
|
||||
del result
|
||||
gc.collect()
|
||||
path = store.entries["a"].path
|
||||
if damage == "delete":
|
||||
path.unlink()
|
||||
elif damage == "truncate":
|
||||
path.write_bytes(b"bad")
|
||||
else:
|
||||
with open(path, "r+b") as f:
|
||||
f.seek(-1 if damage == "data" else 0, 2 if damage == "data" else 0)
|
||||
b = f.read(1)
|
||||
f.seek(-1, 1)
|
||||
f.write(bytes([b[0] ^ 1]))
|
||||
with pytest.raises((CacheBypass, OSError, ValueError)):
|
||||
store.get("a")
|
||||
assert store.get("a") is None
|
||||
|
||||
|
||||
def test_corrupt_ram_invalidates(store):
|
||||
store.configure("RAM", MiB, MiB, 0)
|
||||
put(store, "a", torch.ones(4))
|
||||
store.entries["a"].tensor.zero_()
|
||||
with pytest.raises(CacheBypass):
|
||||
store.get("a")
|
||||
assert store.get("a") is None
|
||||
|
||||
|
||||
def test_dead_vae_eviction(store):
|
||||
class Owner:
|
||||
pass
|
||||
owner = Owner()
|
||||
store.put("a", torch.ones(4), "audio", {}, (weakref.ref(owner),), store.epoch)
|
||||
del owner
|
||||
gc.collect()
|
||||
assert store.get("a") is None
|
||||
|
||||
|
||||
def test_write_fault_no_published_entry(store, monkeypatch):
|
||||
def fail(*args):
|
||||
raise OSError("read-only test cache")
|
||||
monkeypatch.setattr(os, "replace", fail)
|
||||
with pytest.raises(OSError):
|
||||
put(store, "a", torch.ones(4))
|
||||
assert not store.entries
|
||||
assert not list(store.root.iterdir())
|
||||
|
||||
|
||||
def test_unknown_temp_is_never_loaded_or_removed(store):
|
||||
root = store._directory()
|
||||
stale = root / "foreign.tmp"
|
||||
stale.write_text("not a cache entry")
|
||||
store.close()
|
||||
assert stale.exists()
|
||||
|
||||
|
||||
def test_reset_and_disabled_no_storage(store):
|
||||
put(store, "a", torch.ones(4))
|
||||
store.configure("Off", MiB, MiB, 1)
|
||||
assert store.get("a") is None
|
||||
assert put(store, "b", torch.ones(4)) is None
|
||||
|
||||
|
||||
@pytest.mark.parametrize("mode", ["Auto", "RAM"])
|
||||
def test_token_change_clears_once_then_same_token_keeps_cache(store, mode):
|
||||
store.configure(mode, MiB, MiB, 0)
|
||||
put(store, "before", torch.ones(4))
|
||||
epoch = store.epoch
|
||||
store.configure(mode, MiB, MiB, 0)
|
||||
assert store.get("before") is not None
|
||||
assert store.epoch == epoch
|
||||
# The UI increments only the submitted INT; configure acts on next Queue.
|
||||
store.configure(mode, MiB, MiB, 1)
|
||||
assert store.get("before") is None
|
||||
assert store.epoch > epoch
|
||||
put(store, "after", torch.ones(4))
|
||||
epoch = store.epoch
|
||||
store.configure(mode, MiB, MiB, 1)
|
||||
assert store.get("after") is not None
|
||||
assert store.epoch == epoch
|
||||
|
||||
|
||||
def test_epoch_prevents_inflight_reinsertion(store):
|
||||
epoch = store.epoch
|
||||
store.clear()
|
||||
assert store.put("a", torch.ones(4), "video", {}, (), epoch) is None
|
||||
assert store.get("a") is None
|
||||
|
||||
|
||||
def test_pending_disk_files_are_in_quota(store):
|
||||
store.configure("Auto", 0, 6000, 0)
|
||||
x = torch.ones(1000) # 4000 bytes + header; next insert must not delete a live mmap
|
||||
first = put(store, "a", x)
|
||||
assert first is None # conservative header reservation is > 6000
|
||||
store.configure("Auto", 0, 10000, 0)
|
||||
first = put(store, "a", x)
|
||||
assert first is not None
|
||||
store.clear()
|
||||
# 4128 + conservative 8096 > quota; pinned pending file counts
|
||||
assert put(store, "b", x) is None
|
||||
del first
|
||||
gc.collect()
|
||||
assert put(store, "b", x) is not None
|
||||
|
||||
|
||||
@pytest.mark.parametrize("mode", ["Auto", "RAM"])
|
||||
def test_output_metadata_is_defensively_copied(store, mode):
|
||||
store.configure(mode, MiB, MiB, 0)
|
||||
extra = {"sample_rate": 32000, "future_metadata": {"labels": ["original"]}}
|
||||
store.put("a", torch.ones(12), "video", extra, (), store.epoch)
|
||||
extra["future_metadata"]["labels"][0] = "caller mutation"
|
||||
_, first = store.get("a")
|
||||
assert first["future_metadata"]["labels"] == ["original"]
|
||||
first["future_metadata"]["labels"][0] = "downstream mutation"
|
||||
_, second = store.get("a")
|
||||
assert second["future_metadata"]["labels"] == ["original"]
|
||||
|
||||
|
||||
def test_delete_failure_is_accounted_and_retried(store, monkeypatch):
|
||||
put(store, "a", torch.ones(12))
|
||||
path = store.entries["a"].path
|
||||
original_unlink = Path.unlink
|
||||
def denied(self, *args, **kwargs):
|
||||
if self == path:
|
||||
raise PermissionError("simulated Windows sharing violation")
|
||||
return original_unlink(self, *args, **kwargs)
|
||||
with monkeypatch.context() as m:
|
||||
m.setattr(Path, "unlink", denied)
|
||||
store.clear()
|
||||
assert store.disk_bytes > 0 and len(store.retired) == 1
|
||||
store.stats()
|
||||
assert not path.exists() and store.disk_bytes == 0
|
||||
|
||||
|
||||
def test_symlink_cache_file_is_not_opened(store, tmp_path):
|
||||
put(store, "a", torch.ones(12))
|
||||
path = store.entries["a"].path
|
||||
outside = tmp_path / "outside-user-file.bin"
|
||||
outside.write_bytes(b"DO NOT TOUCH")
|
||||
path.unlink()
|
||||
try:
|
||||
path.symlink_to(outside)
|
||||
except OSError:
|
||||
pytest.skip("symbolic links not available")
|
||||
with pytest.raises(CacheBypass):
|
||||
store.get("a")
|
||||
assert outside.read_bytes() == b"DO NOT TOUCH"
|
||||
|
||||
|
||||
def test_store_garbage_collection_cleans_unleased_private_files(tmp_path):
|
||||
s = DecodeStore(temp_parent=tmp_path, memory_probe=lambda: 10**12, headroom_bytes=0)
|
||||
put(s, "a", torch.ones(12))
|
||||
root = s.root
|
||||
assert root.exists()
|
||||
ref = weakref.ref(s)
|
||||
del s
|
||||
gc.collect()
|
||||
assert ref() is None and not root.exists()
|
||||
|
||||
|
||||
def test_explicit_private_cache_parent_uses_only_child_directory(tmp_path, monkeypatch):
|
||||
monkeypatch.setenv("H3_DECODE_CACHE_TEMP_DIR", str(tmp_path))
|
||||
s = DecodeStore(memory_probe=lambda: 10**12, headroom_bytes=0)
|
||||
put(s, "a", torch.ones(12))
|
||||
assert s.root.parent == tmp_path and s.root.name.startswith("h3-decode-cache-")
|
||||
s.close()
|
||||
assert tmp_path.exists()
|
||||
@@ -0,0 +1,80 @@
|
||||
import assert from "node:assert/strict";
|
||||
import fs from "node:fs";
|
||||
|
||||
const source = fs.readFileSync(new URL("../web/decode_cache_helper.js", import.meta.url), "utf8");
|
||||
let extension;
|
||||
globalThis.__h3TestApp = { registerExtension(value) { extension = value; }, graph: { _nodes: [] } };
|
||||
const module = await import(`data:text/javascript;base64,${Buffer.from(source.replace(
|
||||
'import { app } from "../../scripts/app.js";', 'const app = globalThis.__h3TestApp;',
|
||||
)).toString("base64")}`);
|
||||
|
||||
function createNode(type = "H3DecodeCacheHelper") {
|
||||
return {
|
||||
comfyClass: type,
|
||||
widgets: ["cache_mode", "ram_budget_mb", "disk_budget_gb", "reset_token"].map((name, i) => ({
|
||||
name, value: ["Auto", 256, 8, 0][i], type: i === 0 ? "combo" : "number", options: {},
|
||||
})),
|
||||
addWidget(type, name, value, callback, options) {
|
||||
const widget = { type, name, value, callback, options };
|
||||
this.widgets.push(widget);
|
||||
return widget;
|
||||
},
|
||||
serialize() { return { widgets_values: this.widgets.map((w) => w.value) }; },
|
||||
configure(data) { data.widgets_values.forEach((value, i) => { if (this.widgets[i]) this.widgets[i].value = value; }); },
|
||||
setDirtyCanvas() {},
|
||||
};
|
||||
}
|
||||
|
||||
const node = createNode();
|
||||
extension.nodeCreated(node);
|
||||
const token = node.widgets[3];
|
||||
const button = node.widgets[4];
|
||||
assert.equal(token.value, 0);
|
||||
assert.equal(token.hidden, true);
|
||||
assert.equal(token.options.hidden, true);
|
||||
assert.equal(token.options.serialize, undefined);
|
||||
assert.equal(button.type, "button");
|
||||
assert.equal(button.name, "キャッシュをクリア");
|
||||
assert.equal(button.options.serialize, false);
|
||||
assert.equal(button.serialize, false);
|
||||
assert.match(button.tooltip, /次回Queue/);
|
||||
assert.deepEqual(node.serialize().widgets_values, ["Auto", 256, 8, 0]);
|
||||
extension.loadedGraphNode(node);
|
||||
globalThis.__h3TestApp.graph._nodes = [node];
|
||||
extension.afterConfigureGraph();
|
||||
assert.equal(node.widgets.length, 5);
|
||||
assert.equal(token.value, 0);
|
||||
button.callback();
|
||||
assert.equal(token.value, 1);
|
||||
assert.deepEqual(node.serialize().widgets_values, ["Auto", 256, 8, 1]);
|
||||
|
||||
// Save/load and the clone path keep the same four backend values.
|
||||
const clone = createNode();
|
||||
extension.nodeCreated(clone);
|
||||
clone.configure(node.serialize());
|
||||
assert.deepEqual(clone.serialize(), node.serialize());
|
||||
assert.equal(clone.widgets.length, 5);
|
||||
clone.widgets[4].callback();
|
||||
assert.equal(clone.widgets[3].value, 2);
|
||||
assert.equal(token.value, 1);
|
||||
|
||||
// Both official V3.8X2 distribution names preserve the same helper settings.
|
||||
for (const filename of ["MiniMax_H3_Continuum_V38X2.json", "MiniMax_H3_Continuum_V38X2+Decode_Cache_Helper.json"]) {
|
||||
const workflow = JSON.parse(fs.readFileSync(new URL(`../examples/workflows/${filename}`, import.meta.url), "utf8"));
|
||||
const saved = workflow.nodes.find((n) => n.type === "H3DecodeCacheHelper");
|
||||
const loaded = createNode();
|
||||
extension.nodeCreated(loaded);
|
||||
loaded.configure(saved);
|
||||
assert.deepEqual(loaded.serialize().widgets_values, saved.widgets_values);
|
||||
assert.equal(loaded.widgets[3].hidden, true);
|
||||
}
|
||||
node.configure({ widgets_values: ["RAM", 128, 16, 2147483647] });
|
||||
button.callback();
|
||||
assert.deepEqual(node.serialize().widgets_values, ["RAM", 128, 16, 0]);
|
||||
const other = createNode("H3ContinuumSamplerV38");
|
||||
module.configureDecodeCacheHelper(other);
|
||||
assert.equal(other.widgets.length, 4);
|
||||
assert.equal(other.widgets[3].hidden, undefined);
|
||||
// Without JS the native reset_token input remains untouched.
|
||||
assert.equal(createNode().widgets[3].type, "number");
|
||||
console.log("Decode Cache Helper frontend lifecycle / serialization / clone / standard workflows: PASS");
|
||||
@@ -51,7 +51,8 @@ function environment() {
|
||||
const src=fs.readFileSync(path.join(ROOT,'web/project_id.js'),'utf8')
|
||||
.replace(/import \{ app \} from "\.\.\/\.\.\/scripts\/app.js";/,'')
|
||||
.replace(/import \{ api \} from "\.\.\/\.\.\/scripts\/api.js";/,'')
|
||||
.replace(/import \{ normalizeReferenceAudioLabels \} from "\.\/reference_audio_ui.js";/,'function normalizeReferenceAudioLabels() {}');
|
||||
.replace(/import \{ normalizeReferenceAudioLabels \} from "\.\/reference_audio_ui.js";/,'function normalizeReferenceAudioLabels() {}')
|
||||
.replace(/import \{ migrateReferenceImageInputs \} from "\.\/reference_image_ui.js";/,'function migrateReferenceImageInputs() {}');
|
||||
vm.runInNewContext(src+`\nglobalThis.testFns={configureNode,loadTakeHistory,takeCatalog,selectTakeOffset,selectTakeAction,reviewStatus,reviewSettingsChanged,synchronizeReviewQueue};`,sandbox);
|
||||
app.extension.setup();
|
||||
const f=sandbox.testFns;
|
||||
|
||||
@@ -6,7 +6,7 @@ import tomllib
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
EXPECTED_VERSION = "3.8.2"
|
||||
EXPECTED_VERSION = "3.8.3"
|
||||
|
||||
|
||||
def test_v35_release_metadata_is_consistent():
|
||||
@@ -20,12 +20,12 @@ def test_v35_release_metadata_is_consistent():
|
||||
assert metadata["project"]["version"] == EXPECTED_VERSION
|
||||
|
||||
|
||||
def test_v35_public_documents_identify_the_current_release():
|
||||
def test_public_documents_identify_the_current_v38x2_release():
|
||||
readme = (ROOT / "README.md").read_text(encoding="utf-8")
|
||||
readme_ja = (ROOT / "README_JA.md").read_text(encoding="utf-8")
|
||||
changelog = (ROOT / "CHANGELOG.md").read_text(encoding="utf-8")
|
||||
|
||||
expected_heading = f"# ComfyUI-H3-Continuum {EXPECTED_VERSION} — V3.8X\n"
|
||||
expected_heading = f"# ComfyUI-H3-Continuum {EXPECTED_VERSION} — V3.8X2\n"
|
||||
assert readme.startswith(expected_heading)
|
||||
assert readme_ja.startswith(expected_heading)
|
||||
assert f"## {EXPECTED_VERSION}" in changelog
|
||||
|
||||
@@ -132,7 +132,7 @@ def test_r6_facade_decorates_status_only_after_existing_runtime_returns():
|
||||
assert seen["video_latents"] is video
|
||||
assert seen["audio_latents"] is audio
|
||||
assert seen["assembly_plan"] is plan
|
||||
assert seen["reference_images"] == ("image-1", None, None)
|
||||
assert seen["reference_images"] == ("image-1",) + (None,) * 8
|
||||
assert seen["still_guide_active"] is True
|
||||
|
||||
|
||||
|
||||
@@ -145,4 +145,4 @@ def test_v217_result_pack_expands_legacy_outputs():
|
||||
def test_v217_has_no_frontend_display_controller():
|
||||
assert not (ROOT / "web" / "h3_continuum_v2.js").exists()
|
||||
version_source = (ROOT / "version.py").read_text(encoding="utf-8")
|
||||
assert 'PACKAGE_VERSION = "3.8.2"' in version_source
|
||||
assert 'PACKAGE_VERSION = "3.8.3"' in version_source
|
||||
|
||||
@@ -33,11 +33,11 @@ def test_v35_appends_reference_audio_sockets_without_changing_v34_schema():
|
||||
assert list(v35_optional)[-2:] == ["reference_audio_1", "reference_audio_vae"]
|
||||
assert v35_optional["reference_audio_1"][0] == "AUDIO"
|
||||
assert v35_optional["reference_audio_1"][1]["display_name"] == (
|
||||
"Reference Audio (Optional)"
|
||||
"Reference Audio (Legacy)"
|
||||
)
|
||||
assert v35_optional["reference_audio_vae"][0] == "VAE"
|
||||
assert v35_optional["reference_audio_vae"][1]["display_name"] == (
|
||||
"Reference Audio VAE (Optional)"
|
||||
"Reference Audio VAE (Legacy)"
|
||||
)
|
||||
assert "Driving Audio" in v35_optional["reference_audio_1"][1]["tooltip"]
|
||||
|
||||
|
||||
@@ -56,8 +56,8 @@ assert.deepEqual(
|
||||
"Video Guide Frames",
|
||||
"Driving Audio",
|
||||
"Driving Audio VAE",
|
||||
"Reference Audio (Optional)",
|
||||
"Reference Audio VAE (Optional)",
|
||||
"Reference Audio (Legacy)",
|
||||
"Reference Audio VAE (Legacy)",
|
||||
],
|
||||
);
|
||||
assert.equal(node.inputs[3].name, "reference_audio_1");
|
||||
|
||||
@@ -76,7 +76,8 @@ def test_public_helper_and_v38_socket_are_the_only_surface_additions():
|
||||
)
|
||||
assert H3ContinuumReferenceAudios.RETURN_TYPES == (REFERENCE_AUDIOS_TYPE,)
|
||||
assert "audio_references" not in v37["optional"]
|
||||
assert list(v38["optional"])[:-1] == list(v37["optional"])
|
||||
assert list(v38["optional"])[:-2] == list(v37["optional"])
|
||||
assert list(v38["optional"])[-2:] == ["audio_references", "image_references"]
|
||||
assert v38["optional"]["audio_references"][0] == REFERENCE_AUDIOS_TYPE
|
||||
|
||||
|
||||
|
||||
@@ -23,10 +23,12 @@ PUBLIC_DISPLAY_NAMES = {
|
||||
"H3EasyLoadAudio": "H3 Continuum Load Audio",
|
||||
"H3ContinuumLoadVideo": "H3 Continuum Load Video",
|
||||
"H3ContinuumSecondPassV35": "H3 Continuum Second Pass",
|
||||
"H3ContinuumReferenceImages": "H3 Continuum Reference Images",
|
||||
"H3DecodeCacheHelper": "Decode Cache Helper",
|
||||
}
|
||||
|
||||
|
||||
def test_public_export_is_exactly_the_seven_node_v38_allowlist():
|
||||
def test_public_export_is_exactly_the_v38x2_nine_node_allowlist():
|
||||
assert set(root_nodes.NODE_CLASS_MAPPINGS) == set(PUBLIC_DISPLAY_NAMES)
|
||||
assert root_nodes.NODE_DISPLAY_NAME_MAPPINGS == PUBLIC_DISPLAY_NAMES
|
||||
|
||||
@@ -106,10 +108,11 @@ def test_v38_schema_and_serialized_widget_order_are_unchanged():
|
||||
"reference_audio_vae",
|
||||
"guide",
|
||||
"audio_references",
|
||||
"image_references",
|
||||
]
|
||||
|
||||
|
||||
def test_registry_package_keeps_one_workflow_and_excludes_development_assets():
|
||||
def test_registry_package_keeps_official_v38x2_workflows_and_excludes_development_assets():
|
||||
rules = (ROOT / ".comfyignore").read_text(encoding="utf-8").splitlines()
|
||||
assert "tests/" in rules
|
||||
assert "tools/*" in rules
|
||||
@@ -123,12 +126,14 @@ def test_registry_package_keeps_one_workflow_and_excludes_development_assets():
|
||||
assert "examples/*" in rules
|
||||
assert "!examples/workflows/" in rules
|
||||
assert "examples/workflows/*" in rules
|
||||
assert "!examples/workflows/MiniMax_H3_Continuum_V38x.json" in rules
|
||||
assert "!examples/workflows/MiniMax_H3_Continuum_V38x.zip" in rules
|
||||
assert "!examples/workflows/MiniMax_H3_Continuum_V38X2.json" in rules
|
||||
assert "!examples/workflows/MiniMax_H3_Continuum_V38X2.zip" in rules
|
||||
assert "!examples/workflows/MiniMax_H3_Continuum_V38X2+Decode_Cache_Helper.json" in rules
|
||||
assert "!examples/workflows/MiniMax_H3_Continuum_V38X2+Decode_Cache_Helper.zip" in rules
|
||||
assert "*.zip" in rules
|
||||
|
||||
workflow = json.loads(
|
||||
(ROOT / "examples/workflows/MiniMax_H3_Continuum_V38x.json").read_text(
|
||||
(ROOT / "examples/workflows/MiniMax_H3_Continuum_V38X2.json").read_text(
|
||||
encoding="utf-8"
|
||||
)
|
||||
)
|
||||
@@ -170,8 +175,10 @@ def test_registry_manifest_matches_every_declared_source_file():
|
||||
assert {
|
||||
path for path in entries if path.startswith("examples/")
|
||||
} == {
|
||||
"examples/workflows/MiniMax_H3_Continuum_V38x.json",
|
||||
"examples/workflows/MiniMax_H3_Continuum_V38x.zip",
|
||||
"examples/workflows/MiniMax_H3_Continuum_V38X2.json",
|
||||
"examples/workflows/MiniMax_H3_Continuum_V38X2.zip",
|
||||
"examples/workflows/MiniMax_H3_Continuum_V38X2+Decode_Cache_Helper.json",
|
||||
"examples/workflows/MiniMax_H3_Continuum_V38X2+Decode_Cache_Helper.zip",
|
||||
}
|
||||
|
||||
for relative_path, expected_digest in entries.items():
|
||||
@@ -191,6 +198,9 @@ def test_intuitive_facade_is_discoverable_and_presentation_only(tmp_path):
|
||||
).replace(
|
||||
'import { normalizeReferenceAudioLabels } from "./reference_audio_ui.js";',
|
||||
"function normalizeReferenceAudioLabels() {}",
|
||||
).replace(
|
||||
'import { migrateReferenceImageInputs } from "./reference_image_ui.js";',
|
||||
"function migrateReferenceImageInputs() {}",
|
||||
).replace(
|
||||
'import { api } from "../../scripts/api.js";',
|
||||
"const api = { fetchApi: (...args) => globalThis.fetch(...args), "
|
||||
@@ -281,6 +291,7 @@ const node = {{
|
||||
this.widgets.push(item);
|
||||
return item;
|
||||
}},
|
||||
removeInput(index) {{ this.inputs.splice(index, 1); }},
|
||||
serialize() {{ return {{ widgets_values: this.widgets.map((item) => item.value) }}; }},
|
||||
configure(info) {{
|
||||
info.widgets_values.forEach((value, index) => {{ this.widgets[index].value = value; }});
|
||||
@@ -657,8 +668,7 @@ setTimeout(async () => {{
|
||||
"last_frame",
|
||||
"reference_image_1",
|
||||
"reference_video_1",
|
||||
"driving_audio",
|
||||
"audio_references",
|
||||
"guide",
|
||||
],
|
||||
"driving_audio",
|
||||
"audio_references",
|
||||
],
|
||||
}
|
||||
|
||||
@@ -7,12 +7,12 @@ from zipfile import ZipFile
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
WORKFLOW_PATH = ROOT / "examples" / "workflows" / "MiniMax_H3_Continuum_V38x.json"
|
||||
WORKFLOW_PATH = ROOT / "examples" / "workflows" / "MiniMax_H3_Continuum_V38X2.json"
|
||||
|
||||
# User-approved final distribution. Do not sanitize or reserialize this graph.
|
||||
WORKFLOW_SHA256 = "26bbca92b5f7cac4cbde89290b3f801b7a895df76a07493ca6f65c18d5b1154a"
|
||||
ZIP_SHA256 = "df4e0e355020d2e731932cff86a4b00932b4f193ec7ed513be0db994ec0e71bb"
|
||||
ZIP_WORKFLOW_NAME = "MiniMax_H3_Continuum_V38x.json"
|
||||
WORKFLOW_SHA256 = "6c445d62979632bc1a801b1c28dbd639c23b51cc156ebae18837baaa757e592b"
|
||||
ZIP_SHA256 = "29e8ea19cf7c7e8a8a5e98577905d8fd01fc800bb8edb4f4218a638fe39e69d0"
|
||||
ZIP_WORKFLOW_NAME = "MiniMax_H3_Continuum_V38X2.json"
|
||||
EXTERNAL_PACKAGES = {
|
||||
"comfyui-spectrum-minimax-h3",
|
||||
"rgthree-comfy",
|
||||
@@ -53,8 +53,8 @@ def _graph(workflow: dict) -> tuple[dict[int, dict], dict[int, list]]:
|
||||
|
||||
def test_v38_public_workflow_declares_external_dependencies_and_is_reloadable():
|
||||
workflow = _workflow()
|
||||
assert len(workflow["nodes"]) == 30
|
||||
assert len(workflow["links"]) == 36
|
||||
assert len(workflow["nodes"]) == 32
|
||||
assert len(workflow["links"]) == 38
|
||||
packages = {
|
||||
node.get("properties", {}).get("cnr_id") for node in workflow["nodes"]
|
||||
} - {None, "", "comfy-core"}
|
||||
@@ -83,6 +83,20 @@ def test_v38_public_workflow_and_zip_preserve_supplied_bytes():
|
||||
assert archive.read(ZIP_WORKFLOW_NAME) == payload
|
||||
|
||||
|
||||
def test_v38x2_official_names_are_the_same_graph_with_matching_zips():
|
||||
standard_payload = WORKFLOW_PATH.read_bytes()
|
||||
explicit_path = WORKFLOW_PATH.with_name(
|
||||
"MiniMax_H3_Continuum_V38X2+Decode_Cache_Helper.json"
|
||||
)
|
||||
assert explicit_path.read_bytes() == standard_payload
|
||||
for workflow_path in (WORKFLOW_PATH, explicit_path):
|
||||
archive_path = workflow_path.with_suffix(".zip")
|
||||
with ZipFile(archive_path) as archive:
|
||||
assert archive.namelist() == [workflow_path.name]
|
||||
assert archive.testzip() is None
|
||||
assert archive.read(workflow_path.name) == standard_payload
|
||||
|
||||
|
||||
def test_v38_public_workflow_preserves_sampler_widget_positions():
|
||||
workflow = _workflow()
|
||||
sampler = _one_node(workflow, "H3ContinuumSamplerV38")
|
||||
@@ -122,17 +136,17 @@ def test_v38_public_workflow_preserves_sampler_widget_positions():
|
||||
assert sampler["widgets_values"] == [
|
||||
sampler["widgets_values_named"][name] for name in names
|
||||
]
|
||||
assert sampler["widgets_values_named"]["generation_mode"] == "Full Run"
|
||||
assert sampler["widgets_values_named"]["generation_mode"] == "Review Each Chunk"
|
||||
assert sampler["widgets_values_named"]["review_action"] == "Continue / Next"
|
||||
assert sampler["widgets_values_named"]["run_storage"] == "Off"
|
||||
assert sampler["widgets_values_named"]["run_storage"] == "Save + Auto Resume"
|
||||
assert sampler["widgets_values_named"]["aspect"] == "Auto from First Image"
|
||||
assert sampler["widgets_values_named"]["preset"] == "Draft — 0.30 MP"
|
||||
assert sampler["widgets_values_named"]["size_source"] == "First Image"
|
||||
assert sampler["widgets_values_named"]["width"] == 448
|
||||
assert sampler["widgets_values_named"]["height"] == 672
|
||||
assert sampler["widgets_values_named"]["chunks"] == 1
|
||||
assert sampler["widgets_values_named"]["width"] == 480
|
||||
assert sampler["widgets_values_named"]["height"] == 640
|
||||
assert sampler["widgets_values_named"]["chunks"] == 2
|
||||
assert sampler["widgets_values_named"]["chunk_seconds"] == 10
|
||||
assert sampler["widgets_values_named"]["control_after_generate"] == "randomize"
|
||||
assert sampler["widgets_values_named"]["control_after_generate"] == "fixed"
|
||||
assert sampler["widgets_values_named"]["continuation_backend"] == "Standard"
|
||||
|
||||
|
||||
@@ -152,6 +166,7 @@ def test_v38_public_workflow_keeps_required_and_optional_connections():
|
||||
"audio_vae",
|
||||
"reference_video_1",
|
||||
"audio_references",
|
||||
"image_references",
|
||||
}
|
||||
assert required | optional <= set(inputs)
|
||||
assert all(inputs[name]["link"] is not None for name in required | optional)
|
||||
@@ -176,6 +191,7 @@ def test_v38_public_workflow_keeps_required_and_optional_connections():
|
||||
assert source_modes["driving_audio"] == 4
|
||||
assert source_modes["reference_video_1"] == 4
|
||||
assert source_types["audio_references"] == "H3ContinuumReferenceAudios"
|
||||
assert source_types["image_references"] == "H3ContinuumReferenceImages"
|
||||
|
||||
|
||||
def test_v38_public_workflow_preserves_accelerator_defaults_and_model_chain():
|
||||
@@ -193,7 +209,7 @@ def test_v38_public_workflow_preserves_accelerator_defaults_and_model_chain():
|
||||
lora = source(spectrum, "model")
|
||||
assert lora["type"] == "Power Lora Loader (rgthree)"
|
||||
loras = [item for item in lora["widgets_values"] if isinstance(item, dict) and "lora" in item]
|
||||
assert len(loras) == 4
|
||||
assert len(loras) == 5
|
||||
assert all(item["on"] is False for item in loras)
|
||||
sage = source(lora, "model")
|
||||
assert sage["type"] == "MiniMaxH3MemoryEfficientSageAttentionPatch"
|
||||
@@ -204,7 +220,7 @@ def test_v38_public_workflow_preserves_accelerator_defaults_and_model_chain():
|
||||
assert source(scheduler, "model")["id"] == spectrum["id"]
|
||||
|
||||
|
||||
def test_v38_public_workflow_keeps_decode_finalize_create_save_chain():
|
||||
def test_v38x2_public_workflow_keeps_helper_finalize_create_save_chain():
|
||||
workflow = _workflow()
|
||||
nodes, links = _graph(workflow)
|
||||
save = _one_node(workflow, "SaveVideo")
|
||||
@@ -215,7 +231,15 @@ def test_v38_public_workflow_keeps_decode_finalize_create_save_chain():
|
||||
finalize = _one_node(workflow, "H3ContinuumAssembleSeamV35")
|
||||
assert [links[item["link"]][1] for item in create["inputs"][:2]] == [finalize["id"]] * 2
|
||||
incoming = [nodes[links[item["link"]][1]]["type"] for item in finalize["inputs"][:3]]
|
||||
assert incoming == ["VAEDecode", "VAEDecodeAudio", "H3ContinuumSamplerV38"]
|
||||
for node_type in ("VAEDecode", "VAEDecodeAudio"):
|
||||
decode = _one_node(workflow, node_type)
|
||||
assert nodes[links[decode["inputs"][0]["link"]][1]]["type"] == "H3ContinuumSamplerV38"
|
||||
assert incoming == ["H3DecodeCacheHelper", "H3DecodeCacheHelper", "H3ContinuumSamplerV38"]
|
||||
helper = _one_node(workflow, "H3DecodeCacheHelper")
|
||||
helper_sources = {
|
||||
item["name"]: nodes[links[item["link"]][1]]["type"]
|
||||
for item in helper["inputs"]
|
||||
}
|
||||
assert helper_sources == {
|
||||
"video_samples": "H3ContinuumSamplerV38",
|
||||
"video_vae": "VAELoader",
|
||||
"audio_samples": "H3ContinuumSamplerV38",
|
||||
"audio_vae": "VAELoader",
|
||||
}
|
||||
|
||||
@@ -87,8 +87,8 @@ def test_current_v38_public_schema_is_preserved_exactly():
|
||||
)
|
||||
)
|
||||
assert tuple(v38["required"]) == tuple(expected_required)
|
||||
assert list(v38["optional"])[:-1] == list(v37["optional"])
|
||||
assert list(v38["optional"])[-1] == "audio_references"
|
||||
assert list(v38["optional"])[:-2] == list(v37["optional"])
|
||||
assert list(v38["optional"])[-2:] == ["audio_references", "image_references"]
|
||||
assert v38["optional"]["audio_references"][0] == (
|
||||
"H3_CONTINUUM_AUDIO_REFERENCES"
|
||||
)
|
||||
|
||||
@@ -201,8 +201,8 @@ def test_v38_schema_keeps_legacy_aspect_and_appends_size_source_contract():
|
||||
"the normal choice for T2VA or workflows without a First Image."
|
||||
),
|
||||
}
|
||||
assert list(v38["optional"])[:-1] == list(v37["optional"])
|
||||
assert list(v38["optional"])[-1] == "audio_references"
|
||||
assert list(v38["optional"])[:-2] == list(v37["optional"])
|
||||
assert list(v38["optional"])[-2:] == ["audio_references", "image_references"]
|
||||
assert v38["optional"]["audio_references"][0] == (
|
||||
"H3_CONTINUUM_AUDIO_REFERENCES"
|
||||
)
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import hashlib
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
from ComfyUI_H3_Continuum_Join import nodes as continuum_nodes
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
WORKFLOW = ROOT / "examples/workflows/MiniMax_H3_Continuum_V38X2.json"
|
||||
|
||||
|
||||
def test_builtin_helper_preserves_public_node_contract():
|
||||
helper = continuum_nodes.NODE_CLASS_MAPPINGS["H3DecodeCacheHelper"]
|
||||
assert continuum_nodes.NODE_DISPLAY_NAME_MAPPINGS["H3DecodeCacheHelper"] == "Decode Cache Helper"
|
||||
assert helper.RETURN_TYPES == ("IMAGE", "AUDIO", "STRING")
|
||||
assert helper.RETURN_NAMES == ("images", "audio", "report")
|
||||
assert helper.INPUT_IS_LIST is True
|
||||
assert helper.OUTPUT_IS_LIST == (True, True, False)
|
||||
assert helper.CATEGORY == "MiniMax H3/Continuum/Helpers"
|
||||
assert list(helper.INPUT_TYPES()["required"]) == [
|
||||
"cache_mode", "ram_budget_mb", "disk_budget_gb", "reset_token"
|
||||
]
|
||||
required = helper.INPUT_TYPES()["required"]
|
||||
assert required["cache_mode"][1]["default"] == "Auto"
|
||||
assert required["ram_budget_mb"][1]["default"] == 256
|
||||
assert required["disk_budget_gb"][1]["default"] == 8
|
||||
assert required["reset_token"][1]["default"] == 0
|
||||
assert required["reset_token"][0] == "INT"
|
||||
|
||||
|
||||
def test_supplied_workflow_is_preserved_and_routes_through_builtin_helper():
|
||||
payload = WORKFLOW.read_bytes()
|
||||
assert hashlib.sha256(payload).hexdigest().upper() == (
|
||||
"6C445D62979632BC1A801B1C28DBD639C23B51CC156EBAE18837BAAA757E592B"
|
||||
)
|
||||
workflow = json.loads(payload)
|
||||
nodes = {node["id"]: node for node in workflow["nodes"]}
|
||||
assert nodes[312]["type"] == "H3ContinuumSamplerV38"
|
||||
assert nodes[344]["type"] == "H3DecodeCacheHelper"
|
||||
assert nodes[306]["type"] == "H3ContinuumAssembleSeamV35"
|
||||
assert nodes[344]["widgets_values"] == ["Auto", 256, 8, 0]
|
||||
links = {(link[1], link[2], link[3], link[4], link[5]) for link in workflow["links"]}
|
||||
assert (312, 0, 344, 0, "LATENT") in links
|
||||
assert (312, 1, 344, 2, "LATENT") in links
|
||||
assert (344, 0, 306, 0, "IMAGE") in links
|
||||
assert (344, 1, 306, 1, "AUDIO") in links
|
||||
assert (312, 2, 306, 2, "H3_CONTINUUM_ASSEMBLY_PLAN") in links
|
||||
assert not any(node["type"] in {"VAEDecode", "VAEDecodeAudio"} for node in workflow["nodes"])
|
||||
|
||||
|
||||
def test_sampler_and_finalize_remain_separate_and_core_direct_workflow_remains():
|
||||
assert "H3ContinuumSamplerV38" in continuum_nodes.NODE_CLASS_MAPPINGS
|
||||
assert "H3ContinuumAssembleSeamV35" in continuum_nodes.NODE_CLASS_MAPPINGS
|
||||
core = json.loads(
|
||||
(ROOT / "examples/workflows/MiniMax_H3_Continuum_V38x.json").read_text(encoding="utf-8")
|
||||
)
|
||||
types = {node["type"] for node in core["nodes"]}
|
||||
assert {"VAEDecode", "VAEDecodeAudio", "H3ContinuumAssembleSeamV35"} <= types
|
||||
Reference in New Issue
Block a user