Merge commit 'bf8f76505fdd25ea99770f262eb9371509bf226d' as 'vendor/dumas_h3_continuum'
This commit is contained in:
+55
@@ -0,0 +1,55 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import importlib
|
||||
import importlib.util
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
PACKAGE_NAME = "ComfyUI_H3_Continuum_Join"
|
||||
if PACKAGE_NAME not in sys.modules:
|
||||
spec = importlib.util.spec_from_file_location(
|
||||
PACKAGE_NAME,
|
||||
ROOT / "__init__.py",
|
||||
submodule_search_locations=[str(ROOT)],
|
||||
)
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
module.__path__ = [str(ROOT)]
|
||||
sys.modules[PACKAGE_NAME] = module
|
||||
|
||||
|
||||
# Run real production JS through ComfyUI's supported queue lifecycle once.
|
||||
# No unsupported beforeQueuePrompt helper injection or copied UI predicates.
|
||||
import json
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def require_comfy_core():
|
||||
"""Only skip integration cases when the standalone checkout lacks Core."""
|
||||
try:
|
||||
importlib.import_module("comfy")
|
||||
except ModuleNotFoundError as error:
|
||||
if error.name != "comfy":
|
||||
raise
|
||||
pytest.skip("Requires an installed ComfyUI Core; standalone CI has no Core")
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def review_queue_results():
|
||||
node = shutil.which("node")
|
||||
assert node, "Node.js is required for the frontend regression gate"
|
||||
result = subprocess.run(
|
||||
[node, str(ROOT / "tests" / "frontend_review_queue.cjs")],
|
||||
env={**os.environ, "H3_TEST_ROOT": str(ROOT)},
|
||||
capture_output=True, text=True, encoding="utf-8", timeout=45,
|
||||
)
|
||||
records = json.loads(result.stdout)
|
||||
assert len(records) == 90, "The complete queue fixture must finish, including rehydration, v5 history and read-only reasons"
|
||||
failures = [item for item in records if not item["pass"]]
|
||||
assert result.returncode == 0 and not failures, result.stdout + result.stderr
|
||||
return {item["name"]: item for item in records}
|
||||
@@ -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()
|
||||
+200
File diff suppressed because one or more lines are too long
@@ -0,0 +1,19 @@
|
||||
def _observe_model_options(options):
|
||||
transformer = options.get("transformer_options")
|
||||
if not isinstance(transformer, dict) or "optimized_attention_override" not in transformer:
|
||||
return _observe(options)
|
||||
try:
|
||||
adapted = _core_attention_override(transformer["optimized_attention_override"])
|
||||
except Exception:
|
||||
adapted = None
|
||||
if adapted is None:
|
||||
# Unknown overrides keep their prior descriptor and safe-side policy.
|
||||
return _observe(options)
|
||||
copied = dict(options)
|
||||
copied["transformer_options"] = dict(transformer)
|
||||
copied["transformer_options"]["optimized_attention_override"] = None
|
||||
observed, safe = _observe(copied)
|
||||
if not isinstance(observed.get("transformer_options"), dict) or "truncated" in observed["transformer_options"]:
|
||||
return observed, False
|
||||
observed["transformer_options"]["optimized_attention_override"] = adapted[0]
|
||||
return observed, safe and adapted[1]
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"last_node_id": 420,
|
||||
"last_link_id": 0,
|
||||
"nodes": [
|
||||
{
|
||||
"id": 420,
|
||||
"type": "H3ContinuumSelectiveSecondPassExperimental",
|
||||
"pos": [0, 0],
|
||||
"size": [360, 420],
|
||||
"flags": {},
|
||||
"order": 0,
|
||||
"mode": 0,
|
||||
"inputs": [],
|
||||
"outputs": [],
|
||||
"properties": {
|
||||
"Node name for S&R": "H3ContinuumSelectiveSecondPassExperimental"
|
||||
},
|
||||
"widgets_values": [73, "Video + Audio"]
|
||||
}
|
||||
],
|
||||
"links": [],
|
||||
"groups": [],
|
||||
"config": {},
|
||||
"extra": {},
|
||||
"version": 0.4
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
{
|
||||
"active_revisions": {
|
||||
"1": "f0d03f641973fb1d89c2ca4a",
|
||||
"2": "d5b6382c7152f233ac608bfa"
|
||||
},
|
||||
"branch_provenance_version": 1,
|
||||
"canonical_chain": [
|
||||
"f0d03f641973fb1d89c2ca4a",
|
||||
"d5b6382c7152f233ac608bfa"
|
||||
],
|
||||
"canonical_head_revision_id": "d5b6382c7152f233ac608bfa",
|
||||
"canonical_storage_revision_id": "d8352287737286e5",
|
||||
"group_revisions": [
|
||||
{
|
||||
"branch_provenance_version": 1,
|
||||
"created_utc": "2026-10-03T15:37:36+00:00",
|
||||
"generation_contract_sha256": "f5a4b7ec0041d5f51731148aae29b228608c1904aa7b3d922764697dc97daf46",
|
||||
"group": {
|
||||
"end": 1,
|
||||
"physical_group": 1,
|
||||
"start": 1
|
||||
},
|
||||
"lineage_sha256": "2dbba4b61863fde2a8d74a75dae4b563e7b79484a2ff678d0cbd333e504cf158",
|
||||
"parent_revision_id": null,
|
||||
"records": [
|
||||
{
|
||||
"file_sha256": "26e771cffc57f171f4cc4c6859876350bdf717d1e8213fc005343006a34f002f",
|
||||
"file_size": 110080,
|
||||
"filename": "rev-d8352287737286e5-txn-9bb0a584b7344342b114bd31b175225c-chunk-0001.safetensors",
|
||||
"prompt_hash": "5dec1ecc3f0d6f846562049c0a4968da02cbbb43113feb87a95cfd6d6691be07",
|
||||
"seed": 17671095936967226055,
|
||||
"sequence_index": 0,
|
||||
"storage_revision_id": "d8352287737286e5"
|
||||
}
|
||||
],
|
||||
"revision_id": "f0d03f641973fb1d89c2ca4a",
|
||||
"revision_order": "2026-10-03T15:37:36+00:00|f0d03f641973fb1d89c2ca4a",
|
||||
"seed_identity": "d54e2bdb426c4a8217b8d7a5cf608093c8a53b6087982053d294f61e042cbf49",
|
||||
"storage_revision_id": "d8352287737286e5",
|
||||
"variation_nonce": 0
|
||||
},
|
||||
{
|
||||
"branch_provenance_version": 1,
|
||||
"created_utc": "2026-10-03T15:37:36+00:00",
|
||||
"generation_contract_sha256": "f5a4b7ec0041d5f51731148aae29b228608c1904aa7b3d922764697dc97daf46",
|
||||
"group": {
|
||||
"end": 2,
|
||||
"physical_group": 2,
|
||||
"start": 2
|
||||
},
|
||||
"lineage_sha256": "2dbba4b61863fde2a8d74a75dae4b563e7b79484a2ff678d0cbd333e504cf158",
|
||||
"parent_revision_id": "f0d03f641973fb1d89c2ca4a",
|
||||
"records": [
|
||||
{
|
||||
"file_sha256": "8b8ca1b0c802d024c6915d903747d8722bea25628369997ab008ff896462b96a",
|
||||
"file_size": 124928,
|
||||
"filename": "rev-d8352287737286e5-txn-008f52b93a88461481ead25f91627af0-chunk-0002.safetensors",
|
||||
"prompt_hash": "5dec1ecc3f0d6f846562049c0a4968da02cbbb43113feb87a95cfd6d6691be07",
|
||||
"seed": 2167717532453298830,
|
||||
"sequence_index": 1,
|
||||
"storage_revision_id": "d8352287737286e5"
|
||||
}
|
||||
],
|
||||
"revision_id": "d5b6382c7152f233ac608bfa",
|
||||
"revision_order": "2026-10-03T15:37:36+00:00|d5b6382c7152f233ac608bfa",
|
||||
"seed_identity": "ea9acc75bcb213362286781997985bc03df80bb8e3b3368ab02907a465286579",
|
||||
"storage_revision_id": "d8352287737286e5",
|
||||
"variation_nonce": 0
|
||||
}
|
||||
],
|
||||
"revisions": [
|
||||
{
|
||||
"active_chain": [
|
||||
"f0d03f641973fb1d89c2ca4a",
|
||||
"d5b6382c7152f233ac608bfa"
|
||||
],
|
||||
"branch_regenerate_from": 0,
|
||||
"contract_sha256": "f5a4b7ec0041d5f51731148aae29b228608c1904aa7b3d922764697dc97daf46",
|
||||
"effective_reroll_nonce": 0,
|
||||
"nonce_mode": "inactive",
|
||||
"reroll_from_chunk": 0,
|
||||
"resume_safe": true,
|
||||
"review_control_version": 1,
|
||||
"review_pause_reason": "review_each_chunk",
|
||||
"review_unit": {
|
||||
"end": 2,
|
||||
"physical_group": 2,
|
||||
"start": 2
|
||||
},
|
||||
"revision_id": "d8352287737286e5",
|
||||
"sampling_revision_id": "f5a4b7ec0041d5f5",
|
||||
"status": "review_ready",
|
||||
"updated_utc": "2026-10-03T15:37:37+00:00"
|
||||
}
|
||||
],
|
||||
"run_name": "run_00bb27779f215038a7eb1845979fdd7c",
|
||||
"run_storage_schema_version": 3,
|
||||
"updated_utc": "2026-10-03T15:37:37+00:00"
|
||||
}
|
||||
BIN
Binary file not shown.
BIN
Binary file not shown.
Vendored
+726
@@ -0,0 +1,726 @@
|
||||
{
|
||||
"branch_provenance": {
|
||||
"active_chain": [
|
||||
"f0d03f641973fb1d89c2ca4a",
|
||||
"d5b6382c7152f233ac608bfa"
|
||||
],
|
||||
"canonical_committed_utc": "2026-10-03T15:37:37+00:00",
|
||||
"canonical_sequence": 1,
|
||||
"version": 1
|
||||
},
|
||||
"branch_regenerate_from": 0,
|
||||
"chunks": [
|
||||
{
|
||||
"entry": {
|
||||
"clip_index": 1,
|
||||
"context_frames": 0,
|
||||
"motion_score": 0.0,
|
||||
"plan": {
|
||||
"clip_index": 1,
|
||||
"context_frames": 5,
|
||||
"continuation": false,
|
||||
"debug": false,
|
||||
"height": 64,
|
||||
"magic": "H3_CONTINUUM_PLAN",
|
||||
"net_frames": 124,
|
||||
"requested_extend_seconds": 5.0,
|
||||
"schema_version": 1,
|
||||
"state_capacity_frames": 39,
|
||||
"total_frames": 124,
|
||||
"trim_frames": 0,
|
||||
"width": 64
|
||||
},
|
||||
"prompt_hash": "5dec1ecc3f0d6f846562049c0a4968da02cbbb43113feb87a95cfd6d6691be07",
|
||||
"seed": 17671095936967226055,
|
||||
"sequence_index": 0
|
||||
},
|
||||
"file_sha256": "26e771cffc57f171f4cc4c6859876350bdf717d1e8213fc005343006a34f002f",
|
||||
"file_size": 110080,
|
||||
"filename": "rev-d8352287737286e5-txn-9bb0a584b7344342b114bd31b175225c-chunk-0001.safetensors",
|
||||
"sequence_index": 0,
|
||||
"storage_revision_id": "d8352287737286e5"
|
||||
},
|
||||
{
|
||||
"entry": {
|
||||
"clip_index": 2,
|
||||
"context_frames": 22,
|
||||
"motion_score": 0.0,
|
||||
"plan": {
|
||||
"clip_index": 2,
|
||||
"context_frames": 22,
|
||||
"continuation": true,
|
||||
"debug": false,
|
||||
"height": 64,
|
||||
"magic": "H3_CONTINUUM_PLAN",
|
||||
"net_frames": 119,
|
||||
"requested_extend_seconds": 5.0,
|
||||
"schema_version": 1,
|
||||
"state_capacity_frames": 39,
|
||||
"total_frames": 141,
|
||||
"trim_frames": 22,
|
||||
"width": 64
|
||||
},
|
||||
"prompt_hash": "5dec1ecc3f0d6f846562049c0a4968da02cbbb43113feb87a95cfd6d6691be07",
|
||||
"seed": 2167717532453298830,
|
||||
"sequence_index": 1
|
||||
},
|
||||
"file_sha256": "8b8ca1b0c802d024c6915d903747d8722bea25628369997ab008ff896462b96a",
|
||||
"file_size": 124928,
|
||||
"filename": "rev-d8352287737286e5-txn-008f52b93a88461481ead25f91627af0-chunk-0002.safetensors",
|
||||
"sequence_index": 1,
|
||||
"storage_revision_id": "d8352287737286e5"
|
||||
}
|
||||
],
|
||||
"contract": {
|
||||
"chunk_contract_hashes": [
|
||||
"a1d04437be62e79c3945c65d26bbc2cc8fdab89c661d78e8dd8da4673b9f1f15",
|
||||
"b90a1eab80aaefd1db1935d6aec14050332ccc6047a7045bf52728de4f527259",
|
||||
"ffdc4b800b697062ab3d2e27c9079dda7fcd2e4c2a7d83fc98fac7402ffaaf55",
|
||||
"b07b8643f7706d41ae6a0b0a74c1f6771d844502ef8b006f5cf71664a0ba26f4"
|
||||
],
|
||||
"chunk_contracts": [
|
||||
{
|
||||
"chunk_number": 1,
|
||||
"effective_reroll_nonce": 0,
|
||||
"global_hash": "3f2ddb7a42a25548a6ec9319f859ed1a75ae0a11933056953d722e2553af357d",
|
||||
"last_frame_hash": "",
|
||||
"physical_group_reference_sha256": "ac4a88fbfb79802981cae2f4ce7b3befcfc5b40fa14f1cd9d03852a2e7a4678f",
|
||||
"prompt_hash": "5dec1ecc3f0d6f846562049c0a4968da02cbbb43113feb87a95cfd6d6691be07",
|
||||
"reroll_boundary": 0
|
||||
},
|
||||
{
|
||||
"chunk_number": 2,
|
||||
"effective_reroll_nonce": 0,
|
||||
"global_hash": "3f2ddb7a42a25548a6ec9319f859ed1a75ae0a11933056953d722e2553af357d",
|
||||
"last_frame_hash": "",
|
||||
"physical_group_reference_sha256": "24824ce6a4f406415e52b1909270780063bece5f97fc3fdb2e844d40878afdbe",
|
||||
"prompt_hash": "5dec1ecc3f0d6f846562049c0a4968da02cbbb43113feb87a95cfd6d6691be07",
|
||||
"reroll_boundary": 0
|
||||
},
|
||||
{
|
||||
"chunk_number": 3,
|
||||
"effective_reroll_nonce": 0,
|
||||
"global_hash": "3f2ddb7a42a25548a6ec9319f859ed1a75ae0a11933056953d722e2553af357d",
|
||||
"last_frame_hash": "",
|
||||
"physical_group_reference_sha256": "b9fcc63b033a0cdf334e68dad74f77ac87ff5e1f8c3b346aa5879411856f62da",
|
||||
"prompt_hash": "5dec1ecc3f0d6f846562049c0a4968da02cbbb43113feb87a95cfd6d6691be07",
|
||||
"reroll_boundary": 0
|
||||
},
|
||||
{
|
||||
"chunk_number": 4,
|
||||
"effective_reroll_nonce": 0,
|
||||
"global_hash": "3f2ddb7a42a25548a6ec9319f859ed1a75ae0a11933056953d722e2553af357d",
|
||||
"last_frame_hash": "6bc13118765285cba097403c4b340bac0e550599fb27a1b415ffc88fc6237daa",
|
||||
"physical_group_reference_sha256": "b9fcc63b033a0cdf334e68dad74f77ac87ff5e1f8c3b346aa5879411856f62da",
|
||||
"prompt_hash": "5dec1ecc3f0d6f846562049c0a4968da02cbbb43113feb87a95cfd6d6691be07",
|
||||
"reroll_boundary": 0
|
||||
}
|
||||
],
|
||||
"chunk_count": 4,
|
||||
"effective_reroll_nonce": 0,
|
||||
"global": {
|
||||
"actual_prefix_steps": 2,
|
||||
"audio_continuity": true,
|
||||
"base_seed": 1234,
|
||||
"chunk_seconds": 5.0,
|
||||
"clip": {
|
||||
"graph_route": {
|
||||
"node": {
|
||||
"class_type": "CLIPLoader",
|
||||
"inputs": {
|
||||
"clip_name": "audit_minimax_h3.safetensors",
|
||||
"type": "minimax"
|
||||
},
|
||||
"node_id": "clip"
|
||||
},
|
||||
"output": 0
|
||||
},
|
||||
"runtime": {
|
||||
"conditioner": {
|
||||
"parameter_count": 4,
|
||||
"parameter_layout_sha256": "bfc7a2fa460fae4eb803fa7bedfa5a2cb8c3c793902b65c1e7796159b92d79bd",
|
||||
"tensor_count": 1,
|
||||
"type": "audit_providers.TinyModule",
|
||||
"weight_probe": [
|
||||
{
|
||||
"dtype": "torch.float32",
|
||||
"name": "proj.weight",
|
||||
"sample_sha256": "c3a6b1f08b0b05ac05390d6c257551ffd0cdcf40496f232b52df2498f915469e",
|
||||
"shape": [
|
||||
2,
|
||||
2
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"options": {
|
||||
"layer_idx": null,
|
||||
"tokenizer_options": {},
|
||||
"use_clip_schedule": false
|
||||
},
|
||||
"patcher": {
|
||||
"model_type": "audit_providers.TinyModule",
|
||||
"state": {
|
||||
"model_options": {
|
||||
"transformer_options": {}
|
||||
},
|
||||
"object_patches": {},
|
||||
"patches": {},
|
||||
"wrappers": {}
|
||||
},
|
||||
"type": "comfy.model_patcher.ModelPatcher"
|
||||
},
|
||||
"runtime_observation": {
|
||||
"options_complete": true,
|
||||
"patcher_complete": true
|
||||
},
|
||||
"tokenizer": {
|
||||
"bos_token_id": null,
|
||||
"core_type": "types.SimpleNamespace",
|
||||
"eos_token_id": null,
|
||||
"model_max_length": 1024,
|
||||
"model_wrapper_type": "types.SimpleNamespace",
|
||||
"name_or_path": "audit-type-only",
|
||||
"pad_token_id": null,
|
||||
"padding_side": null,
|
||||
"truncation_side": null,
|
||||
"vocab_size": 10,
|
||||
"wrapper_type": "types.SimpleNamespace"
|
||||
},
|
||||
"wrapper_type": "audit_providers.SyntheticClip"
|
||||
}
|
||||
},
|
||||
"conditioning_mode": "fl2va",
|
||||
"continuity": "Balanced - 22 frames",
|
||||
"continuum_interop_api": 1,
|
||||
"driving_audio": {
|
||||
"driving_audio_contract_version": 1,
|
||||
"preprocess_version": 1,
|
||||
"resampled_dtype": "torch.float32",
|
||||
"resampled_sha256": "7cca6be8869d599159077330aaf71972b0328bf8758cd99e6d52ba5bd3466b7a",
|
||||
"resampled_shape": [
|
||||
1,
|
||||
2,
|
||||
640000
|
||||
],
|
||||
"resolved_vae_sample_rate": 32000,
|
||||
"source_dtype": "torch.float32",
|
||||
"source_sample_rate": 32000,
|
||||
"source_sha256": "7cca6be8869d599159077330aaf71972b0328bf8758cd99e6d52ba5bd3466b7a",
|
||||
"source_shape": [
|
||||
1,
|
||||
2,
|
||||
640000
|
||||
]
|
||||
},
|
||||
"driving_audio_vae": {
|
||||
"graph_route": {
|
||||
"node": {
|
||||
"class_type": "VAELoader",
|
||||
"inputs": {
|
||||
"vae_name": "audit_audio_vae.safetensors"
|
||||
},
|
||||
"node_id": "audio_vae"
|
||||
},
|
||||
"output": 0
|
||||
},
|
||||
"runtime": {
|
||||
"audio_sample_rate": 32000,
|
||||
"first_stage": {
|
||||
"parameter_count": 4,
|
||||
"parameter_layout_sha256": "bfc7a2fa460fae4eb803fa7bedfa5a2cb8c3c793902b65c1e7796159b92d79bd",
|
||||
"tensor_count": 1,
|
||||
"type": "audit_providers.TinyModule",
|
||||
"weight_probe": [
|
||||
{
|
||||
"dtype": "torch.float32",
|
||||
"name": "proj.weight",
|
||||
"sample_sha256": "cfd5cd0554b977e5208296d4a63e8d2ec6f6cc9823321f2d242239432b7d472b",
|
||||
"shape": [
|
||||
2,
|
||||
2
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"latent_channels": 32,
|
||||
"patcher": {
|
||||
"model_type": "audit_providers.TinyModule",
|
||||
"state": {
|
||||
"model_options": {
|
||||
"transformer_options": {}
|
||||
},
|
||||
"object_patches": {},
|
||||
"patches": {},
|
||||
"wrappers": {}
|
||||
},
|
||||
"type": "comfy.model_patcher.ModelPatcher"
|
||||
},
|
||||
"runtime_observation": {
|
||||
"config_complete": true,
|
||||
"patcher_complete": true
|
||||
},
|
||||
"vae_dtype": "torch.float32",
|
||||
"wrapper_type": "audit_providers.SyntheticAudioVAE"
|
||||
}
|
||||
},
|
||||
"execution_semantics": {
|
||||
"continuation_transport": "masked_av_prefix_22_v1",
|
||||
"flf_execution": "terminal_merged_10s_seed_v2",
|
||||
"terminal_seed_policy": "physical_window_seed_v2"
|
||||
},
|
||||
"first_frame_hash": "ce95397885a93617f1e00a1e6c9a4b5a9c03411a8f2ef58762709df00b6e95d6",
|
||||
"height": 64,
|
||||
"model": {
|
||||
"graph_route": {
|
||||
"node": {
|
||||
"class_type": "UNETLoader",
|
||||
"inputs": {
|
||||
"unet_name": "audit_minimax_h3_fl2va.safetensors",
|
||||
"weight_dtype": "default"
|
||||
},
|
||||
"node_id": "model"
|
||||
},
|
||||
"output": 0
|
||||
},
|
||||
"runtime": {
|
||||
"base": "audit_core_payload.TinyCoreH3",
|
||||
"dtype": "torch.float32",
|
||||
"inner": "audit_providers.TinyModule",
|
||||
"legacy_fingerprint": "2acbeaa9b63a6cf12d7a1b88a1533c12cf5329df420822568eaea5a0bc59bcd4",
|
||||
"model_patcher": "comfy.model_patcher.ModelPatcher",
|
||||
"model_size": 16,
|
||||
"patches": {},
|
||||
"runtime_observation": {
|
||||
"patches_complete": true,
|
||||
"transformer_options_complete": true,
|
||||
"wrappers_complete": true
|
||||
},
|
||||
"transformer_options": {},
|
||||
"weight_probe": [
|
||||
{
|
||||
"dtype": "torch.float32",
|
||||
"name": "proj.weight",
|
||||
"sample_sha256": "f6bb1294da2f78cd935b01c7656280df5eaa0439e9d97bc03775825a41a508e4",
|
||||
"shape": [
|
||||
2,
|
||||
2
|
||||
]
|
||||
}
|
||||
],
|
||||
"wrappers": {}
|
||||
}
|
||||
},
|
||||
"reference_audio": {
|
||||
"combined_hash": "a55474f5b6c557a5eaf70e78a5341a49a39fd2b0cb717b5d08396645d6e2ded8",
|
||||
"count": 2,
|
||||
"items": [
|
||||
{
|
||||
"audio_index": 1,
|
||||
"reference_audio": {
|
||||
"combined_hash": "64a489714dfa65dc229ad059608cd6f488ba1b2d49e815fd71403bfd100f2452",
|
||||
"preprocess_version": 1,
|
||||
"reference_audio_contract_version": 1,
|
||||
"resampled_dtype": "torch.float32",
|
||||
"resampled_sha256": "7ad1bd40edaed4e0a4601dca856191e3002a8b09b8551ec74b81365faecf0548",
|
||||
"resampled_shape": [
|
||||
1,
|
||||
2,
|
||||
3200
|
||||
],
|
||||
"resolved_vae_sample_rate": 32000,
|
||||
"source_dtype": "torch.float32",
|
||||
"source_sample_rate": 32000,
|
||||
"source_sha256": "7ad1bd40edaed4e0a4601dca856191e3002a8b09b8551ec74b81365faecf0548",
|
||||
"source_shape": [
|
||||
1,
|
||||
2,
|
||||
3200
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"audio_index": 2,
|
||||
"reference_audio": {
|
||||
"combined_hash": "5b8b8a88f1a7b2adf9005a4e9c32625b493812bb37d33837ee4d99890adafe54",
|
||||
"preprocess_version": 1,
|
||||
"reference_audio_contract_version": 1,
|
||||
"resampled_dtype": "torch.float32",
|
||||
"resampled_sha256": "69ac770debe6804e3d5762f61896bc226f266f57b8398ea3bed3dc67fde92a8a",
|
||||
"resampled_shape": [
|
||||
1,
|
||||
2,
|
||||
3200
|
||||
],
|
||||
"resolved_vae_sample_rate": 32000,
|
||||
"source_dtype": "torch.float32",
|
||||
"source_sample_rate": 32000,
|
||||
"source_sha256": "69ac770debe6804e3d5762f61896bc226f266f57b8398ea3bed3dc67fde92a8a",
|
||||
"source_shape": [
|
||||
1,
|
||||
2,
|
||||
3200
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"reference_audio_bundle_contract_version": 1
|
||||
},
|
||||
"reference_audio_vae": {
|
||||
"graph_route": {
|
||||
"node": {
|
||||
"class_type": "H3ContinuumReferenceAudios",
|
||||
"inputs": {
|
||||
"reference_audio_vae": {
|
||||
"node": {
|
||||
"class_type": "VAELoader",
|
||||
"inputs": {
|
||||
"vae_name": "audit_audio_vae.safetensors"
|
||||
},
|
||||
"node_id": "audio_vae"
|
||||
},
|
||||
"output": 0
|
||||
}
|
||||
},
|
||||
"node_id": "audio_bundle"
|
||||
},
|
||||
"output": 0
|
||||
},
|
||||
"runtime": {
|
||||
"audio_sample_rate": 32000,
|
||||
"first_stage": {
|
||||
"parameter_count": 4,
|
||||
"parameter_layout_sha256": "bfc7a2fa460fae4eb803fa7bedfa5a2cb8c3c793902b65c1e7796159b92d79bd",
|
||||
"tensor_count": 1,
|
||||
"type": "audit_providers.TinyModule",
|
||||
"weight_probe": [
|
||||
{
|
||||
"dtype": "torch.float32",
|
||||
"name": "proj.weight",
|
||||
"sample_sha256": "cfd5cd0554b977e5208296d4a63e8d2ec6f6cc9823321f2d242239432b7d472b",
|
||||
"shape": [
|
||||
2,
|
||||
2
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"latent_channels": 32,
|
||||
"patcher": {
|
||||
"model_type": "audit_providers.TinyModule",
|
||||
"state": {
|
||||
"model_options": {
|
||||
"transformer_options": {}
|
||||
},
|
||||
"object_patches": {},
|
||||
"patches": {},
|
||||
"wrappers": {}
|
||||
},
|
||||
"type": "comfy.model_patcher.ModelPatcher"
|
||||
},
|
||||
"runtime_observation": {
|
||||
"config_complete": true,
|
||||
"patcher_complete": true
|
||||
},
|
||||
"vae_dtype": "torch.float32",
|
||||
"wrapper_type": "audit_providers.SyntheticAudioVAE"
|
||||
}
|
||||
},
|
||||
"reference_routing_contract_version": 1,
|
||||
"sampler": {
|
||||
"function": "torch._VariableFunctionsClass.add",
|
||||
"options": {
|
||||
"extra_options": {},
|
||||
"inpaint_options": {}
|
||||
},
|
||||
"type": "types.SimpleNamespace"
|
||||
},
|
||||
"sampling_contract_version": 5,
|
||||
"sigmas": {
|
||||
"dtype": "torch.float32",
|
||||
"exact_sha256": "be115d3ffbb025877d7320bd3b0b29cbe245f520f805091917a60169e7737659",
|
||||
"shape": [
|
||||
3
|
||||
]
|
||||
},
|
||||
"strict_compatibility": false,
|
||||
"upstream_graph": {
|
||||
"routes": {
|
||||
"audio_vae": {
|
||||
"node": {
|
||||
"class_type": "VAELoader",
|
||||
"inputs": {
|
||||
"vae_name": "audit_audio_vae.safetensors"
|
||||
},
|
||||
"node_id": "audio_vae"
|
||||
},
|
||||
"output": 0
|
||||
},
|
||||
"clip": {
|
||||
"node": {
|
||||
"class_type": "CLIPLoader",
|
||||
"inputs": {
|
||||
"clip_name": "audit_minimax_h3.safetensors",
|
||||
"type": "minimax"
|
||||
},
|
||||
"node_id": "clip"
|
||||
},
|
||||
"output": 0
|
||||
},
|
||||
"model": {
|
||||
"node": {
|
||||
"class_type": "UNETLoader",
|
||||
"inputs": {
|
||||
"unet_name": "audit_minimax_h3_fl2va.safetensors",
|
||||
"weight_dtype": "default"
|
||||
},
|
||||
"node_id": "model"
|
||||
},
|
||||
"output": 0
|
||||
},
|
||||
"reference_audio_vae": {
|
||||
"node": {
|
||||
"class_type": "H3ContinuumReferenceAudios",
|
||||
"inputs": {
|
||||
"reference_audio_vae": {
|
||||
"node": {
|
||||
"class_type": "VAELoader",
|
||||
"inputs": {
|
||||
"vae_name": "audit_audio_vae.safetensors"
|
||||
},
|
||||
"node_id": "audio_vae"
|
||||
},
|
||||
"output": 0
|
||||
}
|
||||
},
|
||||
"node_id": "audio_bundle"
|
||||
},
|
||||
"output": 0
|
||||
},
|
||||
"video_vae": {
|
||||
"node": {
|
||||
"class_type": "VAELoader",
|
||||
"inputs": {
|
||||
"vae_name": "audit_video_vae.safetensors"
|
||||
},
|
||||
"node_id": "video_vae"
|
||||
},
|
||||
"output": 0
|
||||
}
|
||||
},
|
||||
"sampler_class_type": "H3ContinuumSamplerV39",
|
||||
"sha256": "f7f6f31d4e90a07b040f2774b93ff2e405e0565f8443f3ff1fb5c546394f2ca3",
|
||||
"version": 3
|
||||
},
|
||||
"video_vae": {
|
||||
"graph_route": {
|
||||
"node": {
|
||||
"class_type": "VAELoader",
|
||||
"inputs": {
|
||||
"vae_name": "audit_video_vae.safetensors"
|
||||
},
|
||||
"node_id": "video_vae"
|
||||
},
|
||||
"output": 0
|
||||
},
|
||||
"runtime": {
|
||||
"chunked_io": false,
|
||||
"downscale_ratio": 16,
|
||||
"first_stage": {
|
||||
"parameter_count": 4,
|
||||
"parameter_layout_sha256": "bfc7a2fa460fae4eb803fa7bedfa5a2cb8c3c793902b65c1e7796159b92d79bd",
|
||||
"tensor_count": 1,
|
||||
"type": "audit_providers.TinyModule",
|
||||
"weight_probe": [
|
||||
{
|
||||
"dtype": "torch.float32",
|
||||
"name": "proj.weight",
|
||||
"sample_sha256": "24c60715698663563d76ecaf262778712879423eb057d12b74a037150009d619",
|
||||
"shape": [
|
||||
2,
|
||||
2
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"latent_channels": 24,
|
||||
"patcher": {
|
||||
"model_type": "audit_providers.TinyModule",
|
||||
"state": {
|
||||
"model_options": {
|
||||
"transformer_options": {}
|
||||
},
|
||||
"object_patches": {},
|
||||
"patches": {},
|
||||
"wrappers": {}
|
||||
},
|
||||
"type": "comfy.model_patcher.ModelPatcher"
|
||||
},
|
||||
"required": true,
|
||||
"runtime_observation": {
|
||||
"config_complete": true,
|
||||
"patcher_complete": true
|
||||
},
|
||||
"upscale_ratio": 16,
|
||||
"vae_dtype": "torch.float32",
|
||||
"wrapper_type": "audit_providers.SyntheticVideoVAE"
|
||||
}
|
||||
},
|
||||
"width": 64
|
||||
},
|
||||
"last_frame_hash": "6bc13118765285cba097403c4b340bac0e550599fb27a1b415ffc88fc6237daa",
|
||||
"nonce_lifecycle": {
|
||||
"effective_nonce": 0,
|
||||
"lineage_sha256": "2dbba4b61863fde2a8d74a75dae4b563e7b79484a2ff678d0cbd333e504cf158",
|
||||
"mode": "inactive",
|
||||
"request_sha256": "55c6f2d10dbe9abae01443bac060ba1d56d583d0f80e5f3cfc586cef54a65fcd",
|
||||
"requested_nonce": 0
|
||||
},
|
||||
"nonce_lineage_sha256": "2dbba4b61863fde2a8d74a75dae4b563e7b79484a2ff678d0cbd333e504cf158",
|
||||
"nonce_request_sha256": "55c6f2d10dbe9abae01443bac060ba1d56d583d0f80e5f3cfc586cef54a65fcd",
|
||||
"prompt_hashes": [
|
||||
"5dec1ecc3f0d6f846562049c0a4968da02cbbb43113feb87a95cfd6d6691be07",
|
||||
"5dec1ecc3f0d6f846562049c0a4968da02cbbb43113feb87a95cfd6d6691be07",
|
||||
"5dec1ecc3f0d6f846562049c0a4968da02cbbb43113feb87a95cfd6d6691be07",
|
||||
"5dec1ecc3f0d6f846562049c0a4968da02cbbb43113feb87a95cfd6d6691be07"
|
||||
],
|
||||
"prompt_mode": "Fixed — one prompt",
|
||||
"reference_group_contracts": [
|
||||
{
|
||||
"descriptor": {
|
||||
"effective_prompt_sha256": "4de5a7dfe7c4a22a4f42e26d525e5175d90a85fe6eaa1a093663f3e5bf8ad6b1",
|
||||
"first_anchor": "ce95397885a93617f1e00a1e6c9a4b5a9c03411a8f2ef58762709df00b6e95d6",
|
||||
"last_anchor": "6bc13118765285cba097403c4b340bac0e550599fb27a1b415ffc88fc6237daa",
|
||||
"logical_chunks": [
|
||||
1
|
||||
],
|
||||
"physical_group": 1,
|
||||
"picture_order": [
|
||||
"first_frame",
|
||||
"last_frame",
|
||||
"R1"
|
||||
],
|
||||
"picture_presentation_version": 1,
|
||||
"reference_preprocess_version": 1,
|
||||
"reference_size_mode": "Match Output",
|
||||
"references": [
|
||||
{
|
||||
"picture_number": 3,
|
||||
"prepared_sha256": "4e2f68facb219819b6b0ba6c2c48f37a64b02ae159aef772e2e5d1dea15a3e62",
|
||||
"source_slot_id": "R1"
|
||||
}
|
||||
],
|
||||
"terminal_atomic": false,
|
||||
"terminal_prompt_policy": null,
|
||||
"version": 1
|
||||
},
|
||||
"sha256": "ac4a88fbfb79802981cae2f4ce7b3befcfc5b40fa14f1cd9d03852a2e7a4678f"
|
||||
},
|
||||
{
|
||||
"descriptor": {
|
||||
"effective_prompt_sha256": "4de5a7dfe7c4a22a4f42e26d525e5175d90a85fe6eaa1a093663f3e5bf8ad6b1",
|
||||
"first_anchor": "ce95397885a93617f1e00a1e6c9a4b5a9c03411a8f2ef58762709df00b6e95d6",
|
||||
"last_anchor": "6bc13118765285cba097403c4b340bac0e550599fb27a1b415ffc88fc6237daa",
|
||||
"logical_chunks": [
|
||||
2
|
||||
],
|
||||
"physical_group": 2,
|
||||
"picture_order": [
|
||||
"first_frame",
|
||||
"last_frame",
|
||||
"R1"
|
||||
],
|
||||
"picture_presentation_version": 1,
|
||||
"reference_preprocess_version": 1,
|
||||
"reference_size_mode": "Match Output",
|
||||
"references": [
|
||||
{
|
||||
"picture_number": 3,
|
||||
"prepared_sha256": "4e2f68facb219819b6b0ba6c2c48f37a64b02ae159aef772e2e5d1dea15a3e62",
|
||||
"source_slot_id": "R1"
|
||||
}
|
||||
],
|
||||
"terminal_atomic": false,
|
||||
"terminal_prompt_policy": null,
|
||||
"version": 1
|
||||
},
|
||||
"sha256": "24824ce6a4f406415e52b1909270780063bece5f97fc3fdb2e844d40878afdbe"
|
||||
},
|
||||
{
|
||||
"descriptor": {
|
||||
"effective_prompt_sha256": "4de5a7dfe7c4a22a4f42e26d525e5175d90a85fe6eaa1a093663f3e5bf8ad6b1",
|
||||
"first_anchor": "ce95397885a93617f1e00a1e6c9a4b5a9c03411a8f2ef58762709df00b6e95d6",
|
||||
"last_anchor": "6bc13118765285cba097403c4b340bac0e550599fb27a1b415ffc88fc6237daa",
|
||||
"logical_chunks": [
|
||||
3,
|
||||
4
|
||||
],
|
||||
"physical_group": 3,
|
||||
"picture_order": [
|
||||
"first_frame",
|
||||
"last_frame",
|
||||
"R1"
|
||||
],
|
||||
"picture_presentation_version": 1,
|
||||
"reference_preprocess_version": 1,
|
||||
"reference_size_mode": "Match Output",
|
||||
"references": [
|
||||
{
|
||||
"picture_number": 3,
|
||||
"prepared_sha256": "4e2f68facb219819b6b0ba6c2c48f37a64b02ae159aef772e2e5d1dea15a3e62",
|
||||
"source_slot_id": "R1"
|
||||
}
|
||||
],
|
||||
"terminal_atomic": true,
|
||||
"terminal_prompt_policy": "shared_prompt_v1",
|
||||
"version": 1
|
||||
},
|
||||
"sha256": "b9fcc63b033a0cdf334e68dad74f77ac87ff5e1f8c3b346aa5879411856f62da"
|
||||
}
|
||||
],
|
||||
"reroll_from_chunk": 0
|
||||
},
|
||||
"contract_sha256": "f5a4b7ec0041d5f51731148aae29b228608c1904aa7b3d922764697dc97daf46",
|
||||
"created_utc": "2026-10-03T15:37:36+00:00",
|
||||
"effective_reroll_nonce": 0,
|
||||
"nonce_lifecycle": {
|
||||
"effective_nonce": 0,
|
||||
"lineage_sha256": "2dbba4b61863fde2a8d74a75dae4b563e7b79484a2ff678d0cbd333e504cf158",
|
||||
"mode": "inactive",
|
||||
"request_sha256": "55c6f2d10dbe9abae01443bac060ba1d56d583d0f80e5f3cfc586cef54a65fcd",
|
||||
"requested_nonce": 0
|
||||
},
|
||||
"reference_routing_audit": {
|
||||
"requested_routes": [
|
||||
[
|
||||
"R1"
|
||||
],
|
||||
[
|
||||
"R1"
|
||||
],
|
||||
[
|
||||
"R1"
|
||||
]
|
||||
],
|
||||
"routing_config_sha256": "a3b1b8850a2c72eaa4e7c6c4f2697bb8bd6194091b677e5267338236e298734e",
|
||||
"version": 1
|
||||
},
|
||||
"report_summary": "H3 Continuum V3 3.9.0\nConditioning mode: Hybrid FL2VA + Reference + Continuation.\nPrompt plan: Fixed — one prompt; 4 chunks; 1 unique prompt(s); 5.000s per chunk. Auto detected Fixed.\nPrompt Preflight: OK.\nDecode: external ComfyUI Core VAE nodes; full raw AV chunks retained.\naccelerator markers not detected (informational only); Continuum APPLY_MODEL wrapper installed\nExecution: conditioning precomputed; single call-local MODEL clone per chunk; no internal VAE decode.\nDriving Audio: absolute-time guide slices enabled; original audio is preserved for final output.\nReference Audio conditioning: 2 ordered item(s); persistent across all chunks.\nV3.9 Custom Reference routing: group-local conditioning and complete-group saved-prefix verification; the verified effective Plan is available after Queue.\nFLF execution: terminal merged 10s seed v2; the final two 5-second logical chunks share one physical sample and are split back into normal chunk entries.\nresuming after accepted chunk 1\nPhysical review execution: 1 new physical group(s) completed; 2/4 logical chunks available.\nSession e03555e8: 2 chunks, 243 retained frames, 1 reused, 64x64.\nOutput: 2 raw AV latent chunk(s); connect Core VAE Decode nodes, then H3 Continuum Assemble V3.\nDecode preview: Chunk 2\nReference Plan Inspector (last Queue, runtime verified)\nMode: custom; accepted chunks: 2\nConnected: R1\nGroup 1 [C1] reused — R1=<Picture 3>; contract=ac4a88fbfb79\nGroup 2 [C2] generated — R1=<Picture 3>; contract=24824ce6a4f4\nGroup 3 [C3,4] pending — configured R1\nRun Storage: run_00bb27779f215038a7eb1845979fdd7c / revision d8352287737286e5; 1 reused, 1 generated, 4 total; resume=2; nonce=0 (inactive).\nWarning: Review is incomplete. Second Pass refinement of a partial review sequence is not yet supported.",
|
||||
"resume_disabled_reasons": [],
|
||||
"resume_safe": true,
|
||||
"review_control_version": 1,
|
||||
"review_pause_reason": "review_each_chunk",
|
||||
"review_unit": {
|
||||
"end": 2,
|
||||
"physical_group": 2,
|
||||
"start": 2
|
||||
},
|
||||
"revision_id": "d8352287737286e5",
|
||||
"run_name": "run_00bb27779f215038a7eb1845979fdd7c",
|
||||
"run_storage_schema_version": 3,
|
||||
"sampling_contract_version": 5,
|
||||
"sampling_revision_id": "f5a4b7ec0041d5f5",
|
||||
"session_id": "e03555e805774b9eb22b7d2eae44268c",
|
||||
"status": "review_ready",
|
||||
"updated_utc": "2026-10-03T15:37:37+00:00"
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
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: [] },
|
||||
ui: { settings: { getSettingValue: () => "en" } },
|
||||
};
|
||||
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, "Clear cache");
|
||||
assert.equal(button.options.serialize, false);
|
||||
assert.equal(button.serialize, false);
|
||||
assert.match(button.tooltip, /next 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");
|
||||
|
||||
// ComfyUI's explicit locale setting takes precedence over browser language.
|
||||
globalThis.__h3TestApp.ui = { settings: { getSettingValue: () => "ja" } };
|
||||
const japaneseNode = createNode();
|
||||
extension.nodeCreated(japaneseNode);
|
||||
assert.equal(japaneseNode.widgets[4].name, "キャッシュをクリア");
|
||||
assert.match(japaneseNode.widgets[4].tooltip, /次回Queue/);
|
||||
console.log("Decode Cache Helper frontend lifecycle / serialization / clone / standard workflows: PASS");
|
||||
@@ -0,0 +1,130 @@
|
||||
// Reuse the existing real-production-JS harness; do not copy UI predicates.
|
||||
const assert = require('node:assert/strict');
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
const vm = require('node:vm');
|
||||
const ROOT = process.env.H3_TEST_ROOT || path.resolve(__dirname, '..');
|
||||
const harness = fs.readFileSync(path.join(__dirname, 'frontend_review_queue.cjs'), 'utf8');
|
||||
const marker = harness.indexOf('(async()=>{');
|
||||
assert(marker > 0);
|
||||
const scope = {require, process, console, __dirname, setTimeout, clearTimeout, setImmediate, structuredClone};
|
||||
vm.runInNewContext(harness.slice(0, marker) + '\nglobalThis.fixtures={environment,project};', scope);
|
||||
const {environment, project} = scope.fixtures;
|
||||
const results = [];
|
||||
const widget = (e,n,name) => e.w(n,name);
|
||||
const sources = ['width','height'];
|
||||
const slot = (name, link=null) => ({name,type:'INT',widget:{name},link});
|
||||
function readyInputs(e,n) {
|
||||
for (const name of ['model','clip','video_vae','sampler','sigmas']) n.inputs.push({name,link:100});
|
||||
}
|
||||
async function test(name, body) {
|
||||
const e = environment();
|
||||
try { await body(e); results.push({name,pass:true}); }
|
||||
catch(error) { results.push({name,pass:false,error:error.stack}); }
|
||||
finally { e.close(); }
|
||||
}
|
||||
(async()=>{
|
||||
for (const nodeClass of ['H3ContinuumSamplerV38','H3ContinuumSamplerV39']) {
|
||||
await test(`${nodeClass}: current slots bind to dimension and duration Facades`, async e=>{
|
||||
const n=e.makeNode(312,'fixture',nodeClass);
|
||||
for (const [name,label] of [['width','Width'],['height','Height'],['chunks','Chunks'],['chunk_seconds','Seconds per Chunk']]) {
|
||||
const s=slot(name); n.inputs.push(s); e.f.configureNode(n);
|
||||
assert.equal(s._widget,e.w(n,label));
|
||||
assert.equal(n.getWidgetFromSlot(s),e.w(n,label));
|
||||
assert.equal(n.getSlotFromWidget(e.w(n,label)),s);
|
||||
assert.equal(n.getSlotFromWidget(e.w(n,name)),s);
|
||||
}
|
||||
const getter=n.getWidgetFromSlot; e.f.configureNode(n); assert.equal(n.getWidgetFromSlot,getter);
|
||||
assert.equal(n.inputs.length,4);
|
||||
});
|
||||
await test(`${nodeClass}: restored replacement slots rebind without duplicate sockets`, async e=>{
|
||||
const n=e.makeNode(312,'fixture',nodeClass); n.inputs.push(slot('width'),slot('height'));
|
||||
e.f.configureNode(n); const old=n.inputs;
|
||||
n.inputs=[slot('width',41),{name:'height',type:'INT',link:42}];
|
||||
e.f.configureNode(n); e.f.configureNode(n);
|
||||
for (const [i,label] of ['Width','Height'].entries()) {
|
||||
assert.notEqual(n.inputs[i],old[i]); assert.equal(n.inputs[i]._widget,e.w(n,label));
|
||||
assert.equal(n.getWidgetFromSlot(n.inputs[i]),e.w(n,label));
|
||||
assert.equal(n.getSlotFromWidget(e.w(n,label)),n.inputs[i]);
|
||||
}
|
||||
assert.equal(n.inputs.length,2);
|
||||
});
|
||||
for (const linkedAxes of [['width'],['height'],sources]) {
|
||||
await test(`${nodeClass}: linked ${linkedAxes.join('+')} reserve survives First Image preview`, async e=>{
|
||||
const n=e.makeNode(312,'fixture',nodeClass); e.w(n,'width').value=640; e.w(n,'height').value=768;
|
||||
n.inputs.push(...sources.map((name,i)=>slot(name,linkedAxes.includes(name)?41+i:null)),{name:'first_frame',link:45});
|
||||
e.app.graph._nodes.push({id:900,mode:0,imgs:[{naturalWidth:1920,naturalHeight:1080}]});
|
||||
e.app.graph.links[45]={origin_id:900,origin_slot:0};
|
||||
e.w(n,'size_source').value='First Image'; e.f.configureNode(n);
|
||||
assert.equal(e.w(n,'size_source').value,'First Image');
|
||||
for(const name of linkedAxes) assert.equal(e.w(n,name).value,name==='width'?640:768);
|
||||
e.w(n,'Size Source').callback('Manual'); e.f.configureNode(n);
|
||||
for(const name of sources) {
|
||||
const facade=e.w(n,name==='width'?'Width':'Height');
|
||||
assert.equal(facade.disabled,linkedAxes.includes(name));
|
||||
if(linkedAxes.includes(name)) { facade.callback(1024); assert.equal(e.w(n,name).value,name==='width'?640:768); }
|
||||
}
|
||||
for(const s of n.inputs) if(linkedAxes.includes(s.name))s.link=null;
|
||||
e.f.configureNode(n);
|
||||
for(const name of linkedAxes) {
|
||||
const facade=e.w(n,name==='width'?'Width':'Height'); assert.equal(facade.disabled,false);
|
||||
assert.equal(facade.value,name==='width'?640:768); facade.callback(1024); assert.equal(e.w(n,name).value,1024);
|
||||
}
|
||||
});
|
||||
}
|
||||
for (const linkedAxes of [[],['width'],['height'],sources]) {
|
||||
await test(`${nodeClass}: Manual summary and API adapter ${linkedAxes.join('+')||'native'}`, async e=>{
|
||||
const n=e.makeNode(312,'fixture',nodeClass); readyInputs(e,n);
|
||||
e.w(n,'run_storage').value='Off'; e.w(n,'width').value=640; e.w(n,'height').value=768;
|
||||
n.inputs.push(...sources.map((name,i)=>slot(name,linkedAxes.includes(name)?41+i:null)));
|
||||
e.f.configureNode(n);
|
||||
const summary=e.w(n,'Ready to Queue').detail;
|
||||
assert.equal(e.w(n,'Ready to Queue').headline,'Ready to Queue');
|
||||
if(linkedAxes.length===2) assert.match(summary,/Width.*Height.*connected/i);
|
||||
else if(linkedAxes.length===1) {
|
||||
assert.match(summary,new RegExp(`${linkedAxes[0]}.*connected`,'i'));
|
||||
assert.match(summary,new RegExp(linkedAxes[0]==='width'?'Height 768':'Width 640'));
|
||||
} else assert.match(summary,/640.*768/);
|
||||
const inputs=await e.inputs(n);
|
||||
for(const name of linkedAxes)inputs[name]=[name==='width'?'901':'902',0];
|
||||
const response=await e.api.queuePrompt(0,{output:{[n.id]:{class_type:nodeClass,inputs}},workflow:n.serialize()});
|
||||
const actual=e.submissions.at(-1).data.output[n.id].inputs;
|
||||
for(const name of sources) assert.deepEqual(actual[name],linkedAxes.includes(name)?[name==='width'?'901':'902',0]:name==='width'?640:768);
|
||||
assert(!Object.hasOwn(actual,'Width')); assert(!Object.hasOwn(actual,'Height'));
|
||||
await e.emit('execution_success',{prompt_id:response.prompt_id});
|
||||
e.w(n,'Size Source').callback('First Image'); e.f.configureNode(n);
|
||||
const fallback=e.w(n,'Ready to Queue').detail;
|
||||
if(linkedAxes.length) assert.match(fallback,/Fallback.*connected/i);
|
||||
else assert.match(fallback,/640.*768/);
|
||||
});
|
||||
}
|
||||
await test(`${nodeClass}: native reserve and links survive recreated workflow lifecycle`, async e=>{
|
||||
const n=e.makeNode(312,'fixture',nodeClass); e.w(n,'width').value=640; e.w(n,'height').value=768;
|
||||
n.inputs.push(slot('width',41),slot('height',42)); e.f.configureNode(n);
|
||||
const saved=n.serialize(), savedInputs=JSON.parse(JSON.stringify(n.inputs,(key,value)=>key==='_widget'?undefined:value));
|
||||
const nativeCount=saved.widgets_values.length;
|
||||
for(let i=0;i<5;i++) {
|
||||
e.app.extension.beforeConfigureGraph?.(); e.app.graph._nodes=[];
|
||||
const restored=e.makeNode(312,'fixture',nodeClass,false); e.app.extension.nodeCreated(restored);
|
||||
restored.configure(saved); restored.inputs=structuredClone(savedInputs);
|
||||
e.app.extension.loadedGraphNode(restored); await e.finishRestore();
|
||||
assert.equal(e.w(restored,'width').value,640); assert.equal(e.w(restored,'height').value,768);
|
||||
assert.equal(restored.serialize().widgets_values.length,nativeCount);
|
||||
assert.deepEqual(restored.inputs.map(s=>s.link),[41,42]);
|
||||
assert.equal(restored.inputs[0]._widget,e.w(restored,'Width')); assert.equal(restored.inputs[1]._widget,e.w(restored,'Height'));
|
||||
}
|
||||
});
|
||||
await test(`${nodeClass}: external INT edits retain Review safety guard`, async e=>{
|
||||
const n=e.makeNode(312,'fixture',nodeClass);
|
||||
const upstream={id:901,comfyClass:'PrimitiveInt',mode:0,widgets:[{name:'value',value:640}],inputs:[]};
|
||||
e.app.graph._nodes.push(upstream); e.app.graph.links[41]={origin_id:901,origin_slot:0};
|
||||
n.inputs.push(slot('width',41)); e.w(n,'generation_mode').value='Review Each Chunk'; e.f.configureNode(n);
|
||||
await e.load(n,project(1)); assert(e.visible(n,'Use it and continue'));
|
||||
upstream.widgets[0].value=672; n.__h3ContinuumProductionUxRefresh?.();
|
||||
assert(e.f.reviewSettingsChanged(n)); assert(!e.visible(n,'Use it and continue'));
|
||||
upstream.widgets[0].value=640; n.__h3ContinuumProductionUxRefresh?.();
|
||||
assert(!e.f.reviewSettingsChanged(n)); assert(e.visible(n,'Use it and continue'));
|
||||
});
|
||||
}
|
||||
console.log(JSON.stringify(results,null,2)); if(results.some(r=>!r.pass))process.exitCode=1;
|
||||
})();
|
||||
@@ -0,0 +1,131 @@
|
||||
// Exercise the complete production scripts through the existing Queue fixture.
|
||||
// DOM, graph and server responses are fixtures; no ComfyUI service or GPU is used.
|
||||
const assert = require('node:assert/strict');
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
const vm = require('node:vm');
|
||||
const ROOT = process.env.H3_TEST_ROOT || path.resolve(__dirname, '..');
|
||||
const harness = fs.readFileSync(path.join(ROOT, 'tests/frontend_review_queue.cjs'), 'utf8');
|
||||
const marker = harness.indexOf('\n(async()=>{');
|
||||
assert(marker > 0);
|
||||
function dom(tag) {
|
||||
return { tag, children: [], style: {}, textContent: '',
|
||||
append(...items) { this.children.push(...items); },
|
||||
replaceChildren(...items) { this.children = items; },
|
||||
addEventListener() {}, setAttribute(name, value) { this[name] = value; } };
|
||||
}
|
||||
const scope = { require, process, console, __dirname: path.join(ROOT, 'tests'),
|
||||
setTimeout, clearTimeout, setImmediate, structuredClone,
|
||||
document: { createElement: dom } };
|
||||
const prefix = harness.slice(0, marker)
|
||||
.replace('globalThis:null,', 'globalThis:null,document,')
|
||||
.replace('reviewSettingsChanged,synchronizeReviewQueue};',
|
||||
'reviewSettingsChanged,reviewSettingsSnapshot,synchronizeReviewQueue};');
|
||||
vm.runInNewContext(prefix + '\nglobalThis.fixtures={environment,project};', scope);
|
||||
const { environment, project } = scope.fixtures;
|
||||
const results = [];
|
||||
async function test(name, body, knownIssue = null) {
|
||||
const e = environment();
|
||||
try { await body(e); results.push({ name, pass: true, knownIssue }); }
|
||||
catch (error) { results.push({ name, pass: false, knownIssue, error: error.stack }); }
|
||||
finally { e.close(); }
|
||||
}
|
||||
function upstream(e, n, count = 20) {
|
||||
let previous = n;
|
||||
for (let i = 0; i < count; i++) {
|
||||
const source = { id: 900 + i, comfyClass: 'FixtureSource', mode: 0,
|
||||
widgets: [{ name: 'text', value: `source-${i}`, options: {} }], inputs: [] };
|
||||
e.app.graph._nodes.push(source);
|
||||
previous.inputs.push({ name: 'source', link: 70 + i });
|
||||
e.app.graph.links[70 + i] = { origin_id: source.id, origin_slot: 0 };
|
||||
previous = source;
|
||||
}
|
||||
return previous;
|
||||
}
|
||||
function helper(e, n) {
|
||||
const h = e.makeNode(391, 'helper', 'H3ContinuumReferenceImagesV39', false);
|
||||
h.widgets = [{ name: 'reference_use', value: 'Per chunk', options: {} },
|
||||
...Array.from({ length: 9 }, (_, i) => ({ name: `reference_r${i + 1}_chunks`, value: 'off', options: {} }))];
|
||||
h.inputs = [{ name: 'reference_image_1', link: 600 }];
|
||||
h.outputs = [{ name: 'reference_images', links: [900] }];
|
||||
h.addDOMWidget = function(_name, _type, host, options) {
|
||||
this.panel = host.children[0]; this.display = { options }; return this.display;
|
||||
};
|
||||
h.computeSize = function() { return [this.size[0], 310 + this.display.computeSize(this.size[0])[1]]; };
|
||||
h.setSize = function(size) { this.size = size; };
|
||||
e.app.graph.links[900] = { origin_id: h.id, target_id: n.id, origin_slot: 0 };
|
||||
n.inputs.push({ name: 'reference_images', link: 900 });
|
||||
e.f.configureNode(h);
|
||||
return h;
|
||||
}
|
||||
(async () => {
|
||||
await test('no Review baseline: draw does not traverse upstream settings', async e => {
|
||||
const n = e.makeNode(); upstream(e, n);
|
||||
let lookups = 0, refreshes = 0;
|
||||
const get = e.app.graph.getNodeById;
|
||||
e.app.graph.getNodeById = function(...args) { lookups++; return get.apply(this, args); };
|
||||
n.__h3ContinuumIntuitiveUxRefresh = n.__h3ContinuumProductionUxRefresh = () => { refreshes++; };
|
||||
for (const baseline of [undefined, null]) {
|
||||
n.__h3ContinuumReviewedSettings = baseline;
|
||||
n.__h3ContinuumReviewDrawChanged = false;
|
||||
for (let i = 0; i < 600; i++) n.onDrawForeground();
|
||||
assert.equal(e.f.reviewSettingsChanged(n), false);
|
||||
}
|
||||
assert.equal(lookups, 0); assert.equal(refreshes, 0);
|
||||
n.__h3ContinuumReviewedSettings = '';
|
||||
assert.equal(e.f.reviewSettingsChanged(n), true, 'an existing empty baseline still requires comparison');
|
||||
assert.equal(lookups, 20);
|
||||
});
|
||||
await test('Review baseline: every draw still detects upstream edits', async e => {
|
||||
const n = e.makeNode(), last = upstream(e, n);
|
||||
n.__h3ContinuumReviewedSettings = e.f.reviewSettingsSnapshot(n);
|
||||
n.__h3ContinuumReviewDrawChanged = false;
|
||||
let lookups = 0, refreshes = 0;
|
||||
const get = e.app.graph.getNodeById;
|
||||
e.app.graph.getNodeById = function(...args) { lookups++; return get.apply(this, args); };
|
||||
n.__h3ContinuumIntuitiveUxRefresh = n.__h3ContinuumProductionUxRefresh = () => { refreshes++; };
|
||||
for (let i = 0; i < 600; i++) n.onDrawForeground();
|
||||
assert.equal(lookups, 12000); assert.equal(refreshes, 0);
|
||||
last.widgets[0].value = 'edited';
|
||||
n.onDrawForeground();
|
||||
assert.equal(n.__h3ContinuumReviewDrawChanged, true);
|
||||
assert.equal(refreshes, 2);
|
||||
});
|
||||
for (const nodeClass of ['H3ContinuumSamplerV38', 'H3ContinuumSamplerV39']) {
|
||||
for (const change of ['widget', 'link']) {
|
||||
await test(`${nodeClass}: ${change} edit keeps immediate Take and draw guards`, async e => {
|
||||
const n = e.makeNode(312, 'fixture', nodeClass), source = upstream(e, n, 1);
|
||||
e.w(n, 'generation_mode').value = 'Review Each Chunk';
|
||||
await e.load(n, project(1));
|
||||
delete n.__h3ContinuumModeSetup;
|
||||
n.__h3ContinuumReviewedSettings = e.f.reviewSettingsSnapshot(n);
|
||||
n.__h3ContinuumProductionUxRefresh(); n.onDrawForeground();
|
||||
assert(e.visible(n, 'Use it and continue'));
|
||||
if (change === 'widget') source.widgets[0].value = 'edited';
|
||||
else e.app.graph.links[70].origin_slot = 1;
|
||||
assert(e.visible(n, 'Use it and continue'), 'no draw has occurred yet');
|
||||
e.f.selectTakeAction(n, 'Use This Take');
|
||||
assert.equal(e.w(n, 'take_action').value, 'Automatic');
|
||||
assert.equal(e.w(n, 'take_revision_id').value, '');
|
||||
n.onDrawForeground();
|
||||
assert(!e.visible(n, 'Use it and continue'));
|
||||
assert.match(e.w(n, 'Review Ready').headline, /Settings changed/);
|
||||
assert.equal(e.submissions.length, 0);
|
||||
});
|
||||
}
|
||||
}
|
||||
for (const passes of [1, 2, 100]) {
|
||||
await test(`Reference Inspector stays current after ${passes} configure passes`, async e => {
|
||||
const n = e.makeNode(312, 'fixture', 'H3ContinuumSamplerV39', false), h = helper(e, n);
|
||||
for (let i = 0; i < passes; i++) e.f.configureNode(n);
|
||||
n.onExecuted({ h3_reference_plan: ['fixture verified plan'] });
|
||||
const plan = e.w(n, 'Reference Plan Inspector');
|
||||
assert.equal(plan.value, 'fixture verified plan');
|
||||
h.widgets[1].value = '1'; h.widgets[1].callback('1');
|
||||
assert.equal(n.__h3ContinuumReferencePlan, null);
|
||||
assert.notEqual(plan.value, 'fixture verified plan', 'an invalidated plan must not keep its verified display');
|
||||
}, passes > 1 ? 'inspector-reconfigure' : null);
|
||||
}
|
||||
console.log(JSON.stringify(results));
|
||||
if (results.some(item => !item.pass && !item.knownIssue)) process.exitCode = 1;
|
||||
})();
|
||||
@@ -0,0 +1,307 @@
|
||||
const assert = require('node:assert/strict');
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
const vm = require('node:vm');
|
||||
|
||||
const root = process.env.H3_TEST_ROOT || path.resolve(__dirname, '..');
|
||||
const source = fs.readFileSync(path.join(root, 'web/reference_images_v39.js'), 'utf8')
|
||||
.replace('export function configureV39ReferenceImages', 'function configureV39ReferenceImages')
|
||||
.replace('export function refreshV39ReferenceImagesForSampler', 'function refreshV39ReferenceImagesForSampler')
|
||||
.replace('export function connectedV39LegacyReferenceInputs', 'function connectedV39LegacyReferenceInputs')
|
||||
.replace('export function pruneV39LegacyReferenceInputs', 'function pruneV39LegacyReferenceInputs');
|
||||
function dom(tag) {
|
||||
return {
|
||||
tag, children: [], style: {}, textContent: '',
|
||||
append(...items) { this.children.push(...items); },
|
||||
replaceChildren(...items) { this.children = items; },
|
||||
addEventListener() {}, setAttribute(name, value) { this[name] = value; },
|
||||
};
|
||||
}
|
||||
const graph = { links: {}, nodes: new Map(), getNodeById(id) { return this.nodes.get(id); } };
|
||||
const sandbox = { document: { createElement: dom }, app: { graph }, Set, Array, Number, JSON };
|
||||
vm.runInNewContext(source + '\nglobalThis.v39={configureV39ReferenceImages,refreshV39ReferenceImagesForSampler,connectedV39LegacyReferenceInputs,pruneV39LegacyReferenceInputs};', sandbox);
|
||||
const {
|
||||
configureV39ReferenceImages, refreshV39ReferenceImagesForSampler,
|
||||
connectedV39LegacyReferenceInputs, pruneV39LegacyReferenceInputs,
|
||||
} = sandbox.v39;
|
||||
const nativeCalls = [];
|
||||
let resizeCalls = 0;
|
||||
const selectors = Array.from({ length: 9 }, (_, i) => ({
|
||||
name: `reference_r${i + 1}_chunks`, value: 'off', type: 'text', options: {},
|
||||
callback(...args) { nativeCalls.push({ receiver: this, args }); return 'native-result'; },
|
||||
}));
|
||||
const mode = { name: 'reference_use', value: 'All chunks', type: 'combo', options: {} };
|
||||
const helper = {
|
||||
id: 1, graph, comfyClass: 'H3ContinuumReferenceImagesV39',
|
||||
size: [440, 500],
|
||||
widgets: [mode, ...selectors],
|
||||
inputs: Array.from({ length: 9 }, (_, i) => ({ name: `reference_image_${i + 1}`, link: i === 0 || i === 3 || i === 8 ? i + 100 : null })),
|
||||
outputs: [{ name: 'reference_images', links: [10] }],
|
||||
addDOMWidget(_name, _type, host, options) { this.host = host; this.panel = host.children[0]; this.domOptions = options; this.display = { options: {} }; return this.display; },
|
||||
computeSize() { return [this.size[0], 310 + this.display.computeSize(this.size[0])[1]]; },
|
||||
setSize(size) { resizeCalls++; this.size = size; },
|
||||
setDirtyCanvas() {},
|
||||
};
|
||||
const chunks = { name: 'chunks', value: 6 };
|
||||
const sampler = {
|
||||
id: 2, graph, comfyClass: 'H3ContinuumSamplerV39',
|
||||
widgets: [chunks], inputs: [{ name: 'reference_images', link: 10 }],
|
||||
refreshes: 0,
|
||||
__h3ContinuumIntuitiveUxRefresh() { this.refreshes++; },
|
||||
__h3ContinuumReferencePlan: 'verified', setDirtyCanvas() {},
|
||||
};
|
||||
graph.nodes.set(1, helper); graph.nodes.set(2, sampler);
|
||||
graph.links[10] = { origin_id: 1, target_id: 2 };
|
||||
configureV39ReferenceImages(helper);
|
||||
assert.equal(helper.domOptions.serialize, false);
|
||||
assert.equal(selectors[0].options.serialize, undefined);
|
||||
assert.equal(selectors[0].type, 'hidden');
|
||||
assert.equal(selectors[0].hidden, true);
|
||||
assert.equal(selectors[0].computeSize()[1], 0);
|
||||
assert.equal(typeof selectors[0].draw, 'function');
|
||||
assert.match(helper.host.style.cssText, /padding-top:8px/);
|
||||
assert.match(helper.panel.children[0].textContent, /all chunks/i);
|
||||
mode.value = 'Per chunk'; mode.callback('Per chunk');
|
||||
assert.equal(helper.display.computeSize(440)[1], 193);
|
||||
assert.equal(helper.panel.style.height, '185px');
|
||||
assert.equal(helper.size[1], 503, 'three-row assignment panel must size the node');
|
||||
const visit = (item, predicate) => {
|
||||
if (predicate(item)) return item;
|
||||
for (const child of item.children || []) {
|
||||
const found = visit(child, predicate);
|
||||
if (found) return found;
|
||||
}
|
||||
return null;
|
||||
};
|
||||
function click(slot, chunk) {
|
||||
const box = visit(helper.panel, (item) => item.tag === 'input'
|
||||
&& item['aria-label'] === `Image ${slot}, Chunk ${chunk}`);
|
||||
assert(box, `missing Image ${slot} / Chunk ${chunk}`);
|
||||
const before = { notifications: sampler.refreshes, native: nativeCalls.length, sizes: resizeCalls, width: helper.size[0] };
|
||||
box.checked = !box.checked; box.onchange();
|
||||
assert.equal(sampler.refreshes, before.notifications + 1, 'one synchronous Sampler notification per checkbox');
|
||||
assert.equal(nativeCalls.length, before.native + 1, 'preserve the native callback exactly once');
|
||||
assert.equal(nativeCalls.at(-1).receiver, selectors[slot - 1]);
|
||||
assert.equal(nativeCalls.at(-1).args[0], selectors[slot - 1].value);
|
||||
assert.equal(resizeCalls, before.sizes, 'selection changes must not resize an unchanged layout');
|
||||
assert.equal(helper.size[0], before.width, 'keep the manually chosen width');
|
||||
}
|
||||
for (const chunk of [1, 3, 6]) click(1, chunk);
|
||||
assert.equal(selectors[0].value, '1,3,6');
|
||||
assert.equal(sampler.__h3ContinuumReferencePlan, null);
|
||||
chunks.value = 3; refreshV39ReferenceImagesForSampler(sampler);
|
||||
assert.match(helper.panel.children.find((item) => item.textContent.startsWith('Image 1 →')).textContent, /saved beyond range: 6/);
|
||||
assert.equal(selectors[0].value, '1,3,6');
|
||||
function action(label) {
|
||||
const row = visit(helper.panel, (item) => item.tag === 'tr'
|
||||
&& item.children[0]?.textContent === 'Image 1 · @R1');
|
||||
const button = visit(row, (item) => item.tag === 'button' && item.textContent === label);
|
||||
assert(button && !button.disabled);
|
||||
const before = { notifications: sampler.refreshes, native: nativeCalls.length, sizes: resizeCalls };
|
||||
button.onclick();
|
||||
assert.equal(sampler.refreshes, before.notifications + 1, 'one notification per All / Off');
|
||||
assert.equal(nativeCalls.length, before.native + 1);
|
||||
assert.equal(resizeCalls, before.sizes);
|
||||
}
|
||||
action('All');
|
||||
assert.equal(selectors[0].value, '1,2,3,6', 'All preserves saved chunks beyond the current range');
|
||||
action('Off');
|
||||
assert.equal(selectors[0].value, '6', 'Off preserves saved chunks beyond the current range');
|
||||
selectors[0].value = '1,3,6';
|
||||
const nativeBefore = nativeCalls.length;
|
||||
const refreshBefore = sampler.refreshes;
|
||||
assert.equal(selectors[0].callback('1,3,6', 'native-edit'), 'native-result');
|
||||
assert.equal(nativeCalls.length, nativeBefore + 1);
|
||||
assert.equal(nativeCalls.at(-1).args[1], 'native-edit');
|
||||
assert.equal(sampler.refreshes, refreshBefore + 1);
|
||||
chunks.value = 6; refreshV39ReferenceImagesForSampler(sampler);
|
||||
assert.equal(selectors[0].value, '1,3,6');
|
||||
mode.value = 'All chunks'; mode.callback('All chunks');
|
||||
assert.equal(helper.display.computeSize(440)[1], 62);
|
||||
assert.equal(helper.size[1], 372, 'switching to All chunks must remove unused panel space');
|
||||
mode.value = 'Per chunk'; mode.callback('Per chunk');
|
||||
assert.equal(selectors[0].value, '1,3,6');
|
||||
helper.inputs.forEach((input, index) => { input.link = index + 100; });
|
||||
chunks.value = 16;
|
||||
helper.__h3ReferenceImagesRefresh();
|
||||
assert.equal(helper.display.computeSize(440)[1], 368);
|
||||
assert.equal(helper.panel.style.height, '360px');
|
||||
const stableSizes = resizeCalls;
|
||||
const wrappedCallback = selectors[0].callback;
|
||||
for (let i = 0; i < 100; i++) configureV39ReferenceImages(helper);
|
||||
assert.equal(selectors[0].callback, wrappedCallback, 'helper reconfiguration must not stack callbacks');
|
||||
assert.equal(resizeCalls, stableSizes);
|
||||
helper.size[0] = 620;
|
||||
click(1, 2);
|
||||
assert.equal(helper.size[0], 620);
|
||||
// Check another connected Sampler independently of the manually chosen width.
|
||||
helper.size[0] = 440;
|
||||
const secondSampler = { ...sampler, id: 3, refreshes: 0, widgets: [{ name: 'chunks', value: 16 }] };
|
||||
graph.nodes.set(3, secondSampler);
|
||||
graph.links[11] = { origin_id: 1, target_id: 3 };
|
||||
helper.outputs[0].links.push(11);
|
||||
click(1, 3);
|
||||
assert.equal(secondSampler.refreshes, 1, 'each connected Sampler receives the selection');
|
||||
assert.equal(secondSampler.__h3ContinuumReferencePlan, null);
|
||||
const separateSampler = { ...sampler, id: 5, refreshes: 0, widgets: [{ name: 'chunks', value: 16 }],
|
||||
__h3ContinuumReferencePlan: 'verified' };
|
||||
const separateHelper = {
|
||||
id: 4, graph, comfyClass: helper.comfyClass, size: [440, 500],
|
||||
widgets: [{ name: 'reference_use', value: 'Per chunk', options: {} },
|
||||
...Array.from({ length: 9 }, (_, i) => ({ name: `reference_r${i + 1}_chunks`, value: 'off', options: {} }))],
|
||||
inputs: helper.inputs.map((input) => ({ ...input })),
|
||||
outputs: [{ name: 'reference_images', links: [12] }],
|
||||
addDOMWidget: helper.addDOMWidget, computeSize: helper.computeSize,
|
||||
setSize: helper.setSize, setDirtyCanvas() {},
|
||||
};
|
||||
graph.nodes.set(4, separateHelper); graph.nodes.set(5, separateSampler);
|
||||
graph.links[12] = { origin_id: 4, target_id: 5 };
|
||||
configureV39ReferenceImages(separateHelper);
|
||||
const firstBefore = sampler.refreshes;
|
||||
click(1, 4);
|
||||
const separateBox = visit(separateHelper.panel, (item) => item.tag === 'input'
|
||||
&& item['aria-label'] === 'Image 1, Chunk 5');
|
||||
separateBox.checked = true; separateBox.onchange();
|
||||
assert.equal(sampler.refreshes, firstBefore + 1);
|
||||
assert.equal(separateSampler.refreshes, 1, 'independent helpers must not cancel each other');
|
||||
assert.equal(separateHelper.widgets[1].value, '5');
|
||||
assert.equal(separateSampler.__h3ContinuumReferencePlan, null);
|
||||
delete graph.links[12]; separateHelper.outputs[0].links = [];
|
||||
separateHelper.onConnectionsChange();
|
||||
const detachedRefreshes = separateSampler.refreshes;
|
||||
separateHelper.widgets[1].value = '6'; separateHelper.widgets[1].callback('6');
|
||||
assert.equal(separateSampler.refreshes, detachedRefreshes, 'disconnected Samplers are not notified');
|
||||
const oldSampler = {
|
||||
comfyClass: 'H3ContinuumSamplerV39',
|
||||
__h3ContinuumReferencePlan: 'old plan',
|
||||
inputs: [
|
||||
{ name: 'reference_image_1', link: null },
|
||||
{ name: 'reference_image_2', link: 22 },
|
||||
{ name: 'image_references', link: null },
|
||||
{ name: 'reference_images', link: 10 },
|
||||
],
|
||||
removeInput(index) { this.inputs.splice(index, 1); },
|
||||
setDirtyCanvas() { this.dirty = true; },
|
||||
};
|
||||
assert.equal(pruneV39LegacyReferenceInputs(oldSampler), 2);
|
||||
assert.deepEqual(oldSampler.inputs.map((input) => input.name), ['reference_image_2', 'reference_images']);
|
||||
assert.equal(oldSampler.__h3ContinuumReferencePlan, null);
|
||||
assert.equal(oldSampler.dirty, true);
|
||||
assert.equal(connectedV39LegacyReferenceInputs(oldSampler).join(','), 'reference_image_2');
|
||||
assert.equal(pruneV39LegacyReferenceInputs(oldSampler), 0);
|
||||
oldSampler.inputs[0].link = null;
|
||||
assert.equal(pruneV39LegacyReferenceInputs(oldSampler), 1);
|
||||
assert.deepEqual(oldSampler.inputs.map((input) => input.name), ['reference_images']);
|
||||
assert.equal(pruneV39LegacyReferenceInputs({ ...oldSampler, comfyClass: 'H3ContinuumSamplerV38' }), 0);
|
||||
// External INT values are not frontend widget values. Exercise the production
|
||||
// helper in fresh graphs without resolving or guessing any upstream value.
|
||||
function assignmentFixture({ value = 3, external = false, link = 90, saved = 'off', missing = false, other = null } = {}) {
|
||||
const graph = { links: {}, nodes: new Map(), getNodeById(id) { return this.nodes.get(id); } };
|
||||
const calls = { native: 0, notify: 0, size: 0 };
|
||||
const controls = Array.from({ length: 9 }, (_, i) => ({ name: `reference_r${i + 1}_chunks`,
|
||||
value: i === 0 ? saved : 'off', options: {}, callback() { calls.native++; } }));
|
||||
const helper = { id: 1, graph, comfyClass: 'H3ContinuumReferenceImagesV39', size: [440, 500],
|
||||
widgets: [{ name: 'reference_use', value: 'Per chunk' }, ...controls],
|
||||
inputs: [{ name: 'reference_image_1', link: 100 }], outputs: [{ name: 'reference_images', links: [10] }],
|
||||
addDOMWidget(_name, _type, host) { this.panel = host.children[0]; this.display = { options: {} }; return this.display; },
|
||||
computeSize() { return [440, 310 + this.display.computeSize(440)[1]]; },
|
||||
setSize(value) { calls.size++; this.size = value; }, setDirtyCanvas() {},
|
||||
};
|
||||
const sampler = { id: 2, graph, comfyClass: 'H3ContinuumSamplerV39',
|
||||
widgets: missing ? [] : [{ name: 'chunks', value }],
|
||||
inputs: [{ name: 'reference_images', link: 10 }, { name: 'chunks', link: external ? link : null }],
|
||||
__h3ContinuumIntuitiveUxRefresh() { calls.notify++; }, setDirtyCanvas() {},
|
||||
};
|
||||
graph.nodes.set(1, helper); graph.nodes.set(2, sampler); graph.links[10] = { origin_id: 1, target_id: 2 };
|
||||
if (other !== null) {
|
||||
const second = { ...sampler, id: 3, widgets: [{ name: 'chunks', value: other }],
|
||||
inputs: [{ name: 'reference_images', link: 11 }, { name: 'chunks', link: null }] };
|
||||
graph.nodes.set(3, second); graph.links[11] = { origin_id: 1, target_id: 3 }; helper.outputs[0].links.push(11);
|
||||
}
|
||||
configureV39ReferenceImages(helper);
|
||||
return { graph, helper, sampler, calls, control: controls[0],
|
||||
text() { const values = []; const collect = (node) => { values.push(node.textContent || ''); (node.children || []).forEach(collect); }; collect(helper.panel); return values.join('\n'); },
|
||||
checkbox(n) { return visit(helper.panel, (item) => item['aria-label'] === `Image 1, Chunk ${n}`); },
|
||||
action(label) { const button = visit(helper.panel, (item) => item.tag === 'button' && item.textContent === label); assert(button && !button.disabled, label); button.onclick(); },
|
||||
refresh() { refreshV39ReferenceImagesForSampler(sampler); },
|
||||
};
|
||||
}
|
||||
const externalCases = [];
|
||||
function externalCase(name, run) {
|
||||
try { run(); externalCases.push({ name, pass: true }); }
|
||||
catch (error) { externalCases.push({ name, pass: false, error: error.message }); }
|
||||
}
|
||||
function unknown(f, reason) {
|
||||
assert.match(f.text(), /range 1–16/);
|
||||
assert.match(f.text(), reason);
|
||||
assert(f.checkbox(3));
|
||||
assert(!f.text().includes('saved beyond range'));
|
||||
}
|
||||
externalCase('J01 direct three keeps native range', () => {
|
||||
const f = assignmentFixture(); assert.match(f.text(), /3 chunks/); assert(f.checkbox(3)); assert(!f.checkbox(4));
|
||||
f.action('All'); assert.equal(f.control.value, '1,2,3'); f.action('Off'); assert.equal(f.control.value, 'off');
|
||||
});
|
||||
externalCase('J02 external three and widget two allow C3', () => unknown(assignmentFixture({ value: 2, external: true }), /connected node/));
|
||||
externalCase('J03 external with matching widget remains unresolved', () => unknown(assignmentFixture({ external: true }), /connected node/));
|
||||
externalCase('J04 link zero is external', () => unknown(assignmentFixture({ external: true, link: 0 }), /connected node/));
|
||||
externalCase('J05 unrestored link stays external', () => unknown(assignmentFixture({ external: true, link: 99999 }), /connected node/));
|
||||
externalCase('J06 disconnected or absent socket uses direct value', () => {
|
||||
const f = assignmentFixture(); f.sampler.inputs.pop(); f.refresh(); assert.match(f.text(), /3 chunks/);
|
||||
});
|
||||
externalCase('J07 unavailable or invalid widget preserves selection', () => {
|
||||
for (const options of [{ missing: true }, { value: 0 }, { value: 17 }, { value: 2.5 }, { value: 'bad' }]) {
|
||||
const f = assignmentFixture({ ...options, saved: '1,2,3' }); unknown(f, /not available/); assert.equal(f.control.value, '1,2,3');
|
||||
}
|
||||
});
|
||||
externalCase('J08 multiple direct three targets agree', () => assert.match(assignmentFixture({ other: 3 }).text(), /3 chunks/));
|
||||
externalCase('J09 multiple different direct counts stay unresolved', () => unknown(assignmentFixture({ other: 2 }), /different chunk counts/));
|
||||
externalCase('J10 any externally connected target makes range unresolved', () => unknown(assignmentFixture({ external: true, other: 3 }), /connected node/));
|
||||
externalCase('J11 unknown reason refreshes even when range is unchanged', () => {
|
||||
const f = assignmentFixture({ external: true }); unknown(f, /connected node/);
|
||||
f.helper.outputs[0].links = []; f.helper.onConnectionsChange(); unknown(f, /Connect this helper to a Sampler/);
|
||||
assert(!f.text().includes('connected node'));
|
||||
});
|
||||
externalCase('J12 upstream value changes do not rewrite or rebuild', () => {
|
||||
const f = assignmentFixture({ external: true, saved: '1,2' }); const first = f.helper.panel.children[0];
|
||||
const counts = { ...f.calls }; f.graph.nodes.set(90, { value: 4 }); f.refresh();
|
||||
assert.equal(f.helper.panel.children[0], first); assert.equal(f.control.value, '1,2'); assert.deepEqual(f.calls, counts);
|
||||
});
|
||||
externalCase('J13 saved C3 remains visible and is not called outside range', () => {
|
||||
const f = assignmentFixture({ value: 2, external: true, saved: '1,2,3' }); f.refresh();
|
||||
assert.equal(f.control.value, '1,2,3'); assert(f.checkbox(3).checked); assert.match(f.text(), /Saved assignments: 1, 2, 3/);
|
||||
});
|
||||
externalCase('J14 old one-two is never automatically expanded', () => {
|
||||
const f = assignmentFixture({ value: 2, external: true, saved: '1,2' }); configureV39ReferenceImages(f.helper); f.refresh();
|
||||
assert.equal(f.control.value, '1,2'); assert(!f.checkbox(3).checked);
|
||||
});
|
||||
externalCase('J15 unknown All operates over all pages', () => {
|
||||
const f = assignmentFixture({ external: true }); f.action('▶'); f.action('▶'); f.action('All 1–16');
|
||||
assert.equal(f.control.value, Array.from({ length: 16 }, (_, i) => i + 1).join(','));
|
||||
});
|
||||
externalCase('J16 unknown Off clears future saved assignments', () => {
|
||||
const f = assignmentFixture({ external: true, saved: '1,2,3,16' }); f.action('Off 1–16'); assert.equal(f.control.value, 'off');
|
||||
});
|
||||
externalCase('J17 direct All and Off preserve saved future six', () => {
|
||||
const f = assignmentFixture({ saved: '6' }); f.action('All'); assert.equal(f.control.value, '1,2,3,6'); f.action('Off'); assert.equal(f.control.value, '6');
|
||||
});
|
||||
externalCase('J18 C3 updates native value and notifies once', () => {
|
||||
const f = assignmentFixture({ value: 2, external: true }); const counts = { ...f.calls }; const box = f.checkbox(3);
|
||||
assert(box); box.checked = true; box.onchange(); assert.equal(f.control.value, '3');
|
||||
assert.equal(f.calls.native, counts.native + 1); assert.equal(f.calls.notify, counts.notify + 1); assert.equal(f.calls.size, counts.size);
|
||||
});
|
||||
externalCase('J19 independent helpers and multiple targets stay independent', () => {
|
||||
const f = assignmentFixture({ external: true, other: 3 }), g = assignmentFixture({ external: true });
|
||||
f.action('All 1–16'); assert.equal(f.calls.notify, 2); assert.equal(g.control.value, 'off'); assert.equal(g.calls.notify, 0);
|
||||
});
|
||||
externalCase('J20 repeated configure keeps callbacks layout and width', () => {
|
||||
const f = assignmentFixture({ external: true }); const callback = f.control.callback, sizes = f.calls.size;
|
||||
for (let i = 0; i < 100; i++) configureV39ReferenceImages(f.helper);
|
||||
assert.equal(f.control.callback, callback); assert.equal(f.calls.size, sizes); assert.equal(f.helper.size[0], 440);
|
||||
});
|
||||
externalCase('J21 malformed saved selector remains disabled and unchanged', () => {
|
||||
const f = assignmentFixture({ external: true, saved: 'invalid' }); assert.equal(f.control.value, 'invalid');
|
||||
assert(f.checkbox(3).disabled); assert(visit(f.helper.panel, (item) => item.textContent === 'All 1–16').disabled);
|
||||
});
|
||||
console.log(JSON.stringify(externalCases));
|
||||
assert.equal(externalCases.filter((item) => !item.pass).length, 0, 'external Chunk assignment contracts failed');
|
||||
console.log('V3.9 Reference Images UI contract PASS');
|
||||
@@ -0,0 +1,821 @@
|
||||
// Runs the supplied frontend, not copied predicates. No GPU or ComfyUI server.
|
||||
const assert = require('node:assert/strict');
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
const vm = require('node:vm');
|
||||
const { webcrypto } = require('node:crypto');
|
||||
const ROOT = process.env.H3_TEST_ROOT || path.resolve(__dirname,'..');
|
||||
const results=[];
|
||||
const sleep=()=>new Promise(r=>setImmediate(r));
|
||||
function project(n=1,total=3,id='r1',run='fixture') {
|
||||
let parent=null;
|
||||
const groups=Array.from({length:n},(_,i)=>{
|
||||
const g={revision_id:`${id}-g${i+1}`,parent_revision_id:parent,lineage_sha256:'lineage',
|
||||
sampling_contract_version:6,generation_reusable:true,
|
||||
revision_order:String(i+1),take_number:1,group:{start:i+1,end:i+1,physical_group:i+1}};
|
||||
parent=g.revision_id;return g;
|
||||
});
|
||||
return {run_name:run,run_storage_schema_version:3,branch_provenance_version:1,
|
||||
canonical_storage_revision_id:id,canonical_head_revision_id:parent,
|
||||
canonical_chain:groups.map(g=>g.revision_id),
|
||||
active_revisions:Object.fromEntries(groups.map(g=>[String(g.group.physical_group),g.revision_id])),
|
||||
group_revisions:groups,revisions:[{revision_id:id,status:n===total?'complete':'review_ready',
|
||||
sampling_contract_version:6,generation_reusable:true,
|
||||
updated_utc:`2026-09-08T00:00:0${n}Z`,review_unit:{start:n,end:n,physical_group:n}}]};
|
||||
}
|
||||
function environment() {
|
||||
const listeners=new Map(), timers=new Set();
|
||||
let saved=null, postCount=0, fetchCount=0, nextError=null, queueHook=null, fetchHook=null;
|
||||
const submissions=[];
|
||||
const api={
|
||||
addEventListener(name,callback){const a=listeners.get(name)||[];a.push(callback);listeners.set(name,a);},
|
||||
async queuePrompt(number,data,options){
|
||||
submissions.push(structuredClone({number,data,options}));
|
||||
if(nextError){const e=nextError;nextError=null;throw e;}
|
||||
const response={prompt_id:`p${++postCount}`,number:postCount,node_errors:{}};
|
||||
if(queueHook)await queueHook(response,data);
|
||||
return response;
|
||||
},
|
||||
async fetchApi(url,opts){return fetcher(url,opts);}
|
||||
};
|
||||
async function fetcher(url,opts){
|
||||
fetchCount++;
|
||||
if(fetchHook)return fetchHook(url,opts);
|
||||
if(String(url).startsWith('/queue'))return {ok:true,status:200,json:async()=>({queue_running:[],queue_pending:[]})};
|
||||
return saved?{ok:true,status:200,json:async()=>structuredClone(saved)}:{ok:false,status:404,json:async()=>null};
|
||||
}
|
||||
const graph={_nodes:[],links:{},getNodeById(id){return this._nodes.find(n=>String(n.id)===String(id));}};
|
||||
const app={api,graph,ui:{settings:{getSettingValue:(_id,fallback)=>fallback,addSetting(){}}},registerExtension(e){this.extension=e;}};
|
||||
const sandbox={console,app,api,globalThis:null,crypto:webcrypto,fetch:fetcher,structuredClone,
|
||||
setTimeout(cb,ms){const t=setTimeout(()=>{timers.delete(t);cb();},ms);timers.add(t);return t;},
|
||||
clearTimeout(t){clearTimeout(t);timers.delete(t);}, Map, Set, WeakMap, Uint8Array};
|
||||
sandbox.globalThis=sandbox;
|
||||
const referenceSource=fs.readFileSync(path.join(ROOT,'web/reference_images_v39.js'),'utf8')
|
||||
.replace(/export function /g,'function ');
|
||||
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 \{ configureV39ReferenceImages, connectedV39LegacyReferenceInputs, pruneV39LegacyReferenceInputs, refreshV39ReferenceImagesForSampler \} from "\.\/reference_images_v39.js";/,'')
|
||||
.replace(/import \{ migrateReferenceImageInputs \} from "\.\/reference_image_ui.js";/,'function migrateReferenceImageInputs() {}');
|
||||
vm.runInNewContext(referenceSource+'\n'+src+`\nglobalThis.testFns={configureNode,loadTakeHistory,takeCatalog,selectTakeOffset,selectTakeAction,reviewStatus,reviewSettingsChanged,synchronizeReviewQueue};`,sandbox);
|
||||
app.extension.setup();
|
||||
const f=sandbox.testFns;
|
||||
function makeNode(id=312,run='fixture',nodeClass='H3ContinuumSamplerV38',configure=true){
|
||||
const v={prompt_mode:'Auto',chunks:3,chunk_seconds:5,aspect:'Auto from First Image',
|
||||
preset:'Draft — 0.30 MP',custom_mp:.3,continuity:'Balanced — 22 frames',base_seed:123,
|
||||
control_after_generate:'fixed',audio_continuity:true,continuation_backend:'Standard',
|
||||
run_storage:'Save + Auto Resume',reroll_from_chunk:'Auto',reroll_nonce:0,run_name:run,
|
||||
project_id:'550e8400-e29b-41d4-a716-446655440000',reference_size:'Match Output',
|
||||
video_reference_size:'Efficient - 0.4 MP',diagnostics:'Basic',strict_compatibility:false,
|
||||
debug:false,show_preview:true,generation_mode:'Full Run',review_action:'Continue / Next',
|
||||
take_group:0,take_revision_id:'',take_action:'Automatic',size_source:'Manual',width:544,height:544};
|
||||
const n={id,graph,comfyClass:nodeClass,properties:{},inputs:[],size:[500,500],
|
||||
widgets:Object.entries(v).map(([name,value])=>({name,value,type:typeof value==='number'?'number':'combo',options:{values:[]},computeSize:()=>[120,20]})),
|
||||
addWidget(type,name,value,callback,options){const w={type,name,value,callback,options:options||{},computeSize:()=>[120,20]};this.widgets.push(w);return w;},
|
||||
addCustomWidget(w){this.widgets.push(w);return w;},setDirtyCanvas(){},
|
||||
getWidgetFromSlot(slot){return this.widgets.find(w=>w.name===slot.widget?.name);},
|
||||
getSlotFromWidget(widget){return this.inputs.find(slot=>slot.widget?.name===widget?.name);},
|
||||
serialize(){return {widgets_values:this.widgets.map(w=>w.value)};},
|
||||
configure(info){info.widgets_values.forEach((v,i)=>{if(this.widgets[i])this.widgets[i].value=v;});}
|
||||
};
|
||||
graph._nodes.push(n);if(configure)f.configureNode(n);return n;
|
||||
}
|
||||
const w=(n,name)=>n.widgets.find(w=>w.name===name);
|
||||
async function inputs(n){
|
||||
for(const x of n.widgets)x.beforeQueued?.();
|
||||
const i={};for(const [index,x] of n.widgets.entries()){
|
||||
if(!x.name||x.options?.serialize===false)continue;
|
||||
i[x.name]=x.serializeValue?await x.serializeValue(n,index):x.value;
|
||||
}return i;
|
||||
}
|
||||
async function queue(n,options){const i=await inputs(n);const data={output:{[n.id]:{class_type:n.comfyClass,inputs:i}},workflow:n.serialize()};
|
||||
const result=await api.queuePrompt(0,data,options);
|
||||
for(const x of n.widgets)x.afterQueued?.({isPartialExecution:false});return result;}
|
||||
async function emit(type,detail){await Promise.all((listeners.get(type)||[]).map(cb=>cb({type,detail})));await sleep();await sleep();}
|
||||
async function finishRestore(){
|
||||
await app.extension.afterConfigureGraph();
|
||||
await Promise.all(graph._nodes.map(n=>n.__h3ContinuumHistoryRequest?.promise));
|
||||
await sleep();
|
||||
}
|
||||
return {f,api,app,w,inputs,queue,emit,makeNode,submissions,setSaved:p=>{saved=p;},
|
||||
finishRestore,
|
||||
getSaved:()=>saved,getFetchCount:()=>fetchCount,setQueueHook:h=>queueHook=h,setFetchHook:h=>fetchHook=h,
|
||||
failQueue:e=>nextError=e,visible:(n,name)=>!w(n,name)?.hidden,
|
||||
async load(n,p){saved=p;await f.loadTakeHistory(n,{force:true});n.__h3ContinuumIntuitiveUxRefresh?.();},
|
||||
close(){for(const t of timers)clearTimeout(t);}
|
||||
};
|
||||
}
|
||||
async function test(name,body){const e=environment();try{await body(e);results.push({name,pass:true});}catch(err){results.push({name,pass:false,error:err.stack});}finally{e.close();}}
|
||||
(async()=>{
|
||||
await test('no sampler executed: accepted prompt and committed readback open Review',async e=>{
|
||||
const n=e.makeNode();await e.load(n,null);e.w(n,'Run').callback('Review Each Chunk');
|
||||
const q=await e.queue(n);e.setSaved(project(1));await e.emit('execution_success',{prompt_id:q.prompt_id});
|
||||
assert(e.visible(n,'Use it and continue'),'review Continue is missing');
|
||||
const i=await e.inputs(n);assert.equal(i.reroll_from_chunk,'Auto');
|
||||
});
|
||||
await test('changing Full to Review preserves append intent and manual boundaries',async e=>{
|
||||
const n=e.makeNode();await e.load(n,project(3,3));e.w(n,'chunks').value=5;e.w(n,'Run').callback('Review Each Chunk');
|
||||
await e.queue(n);assert.equal(e.submissions.at(-1).data.output['312'].inputs.reroll_from_chunk,'Auto');
|
||||
e.w(n,'reroll_from_chunk').value='Chunk 3';await e.queue(n);assert.equal(e.submissions.at(-1).data.output['312'].inputs.reroll_from_chunk,'Chunk 3');
|
||||
});
|
||||
await test('three review queues advance without any executed events',async e=>{
|
||||
const n=e.makeNode();await e.load(n,null);e.w(n,'Run').callback('Review Each Chunk');
|
||||
for(let i=1;i<=3;i++){
|
||||
const q=await e.queue(n);assert.equal(e.submissions.at(-1).data.output['312'].inputs.reroll_from_chunk,'Auto');
|
||||
e.setSaved(project(i));await e.emit('execution_success',{prompt_id:q.prompt_id});
|
||||
assert.equal(e.visible(n,'Use it and continue'),i<3);
|
||||
assert(e.visible(n,'Try this chunk again'));
|
||||
if(i<3)e.w(n,'Use it and continue').callback();
|
||||
}
|
||||
});
|
||||
await test('unrelated terminal never reloads or clears another queued node',async e=>{
|
||||
const n=e.makeNode();await e.load(n,null);e.w(n,'Run').callback('Review Each Chunk');await e.queue(n);
|
||||
const before=e.getFetchCount();await e.emit('execution_error',{prompt_id:'unrelated'});
|
||||
assert.equal(e.getFetchCount(),before);assert(n.__h3ContinuumModeSetup);
|
||||
});
|
||||
await test('sampler saved, downstream failed: recover saved output, do not advance',async e=>{
|
||||
const n=e.makeNode();await e.load(n,null);e.w(n,'Run').callback('Review Each Chunk');const q=await e.queue(n);
|
||||
e.setSaved(project(1));await e.emit('execution_error',{prompt_id:q.prompt_id,node_id:'vae'});
|
||||
assert(e.visible(n,'Retry saved output'));assert(!e.visible(n,'Use it and continue'));
|
||||
assert.match(e.f.reviewStatus(n),/saved.*incomplete/i);
|
||||
e.w(n,'Retry saved output').callback();const retry=await e.queue(n);
|
||||
const inputs=e.submissions.at(-1).data.output['312'].inputs;
|
||||
assert.equal(inputs.take_action,'Use This Take');assert.equal(inputs.take_revision_id,'r1-g1');
|
||||
e.setSaved(project(1,3,'output-retry'));await e.emit('execution_success',{prompt_id:retry.prompt_id});
|
||||
assert(!n.__h3ContinuumOutputFailure);assert(e.visible(n,'Use it and continue'));
|
||||
});
|
||||
await test('interruption before commit retains intent without inventing a saved result',async e=>{
|
||||
const n=e.makeNode();await e.load(n,null);e.w(n,'Run').callback('Review Each Chunk');const q=await e.queue(n);
|
||||
await e.emit('execution_interrupted',{prompt_id:q.prompt_id});
|
||||
assert(!e.visible(n,'Use it and continue'));assert(!n.__h3ContinuumOutputFailure);
|
||||
const next=await e.inputs(n);assert.equal(next.reroll_from_chunk,'Auto');
|
||||
});
|
||||
await test('queue rejection preserves one-shot retry for resubmission',async e=>{
|
||||
const n=e.makeNode();e.w(n,'generation_mode').value='Review Each Chunk';await e.load(n,project(1));
|
||||
e.w(n,'Try this chunk again').callback();assert.equal(e.w(n,'review_action').value,'Regenerate Current');
|
||||
e.failQueue(new Error('validation failed'));await assert.rejects(e.queue(n),/validation failed/);
|
||||
assert.equal(e.w(n,'review_action').value,'Regenerate Current');
|
||||
await e.queue(n);assert.equal(e.submissions.at(-1).data.output['312'].inputs.review_action,'Regenerate Current');
|
||||
assert.equal(e.w(n,'review_action').value,'Continue / Next');
|
||||
});
|
||||
await test('history browsing never changes serialized selection, explicit apply does',async e=>{
|
||||
const n=e.makeNode();e.w(n,'generation_mode').value='Review Each Chunk';await e.load(n,project(3,3));
|
||||
const before=await e.inputs(n);e.f.selectTakeOffset(n,-1);const after=await e.inputs(n);
|
||||
for(const k of ['take_group','take_revision_id','take_action'])assert.equal(after[k],before[k]);
|
||||
e.f.selectTakeAction(n,'Use This Take');assert.equal(e.w(n,'take_group').value,2);
|
||||
assert.equal(e.w(n,'take_revision_id').value,'r1-g2');
|
||||
e.f.selectTakeOffset(n,-1);const q=await e.queue(n);
|
||||
assert.equal(e.submissions.at(-1).data.output['312'].inputs.take_revision_id,'r1-g2');
|
||||
});
|
||||
await test('late response for an old Run cannot replace the current history',async e=>{
|
||||
const n=e.makeNode();await e.load(n,project(1));let release;
|
||||
e.setFetchHook(()=>new Promise(r=>release=r));const pending=e.f.loadTakeHistory(n,{force:true});
|
||||
e.w(n,'run_name').value='other';release({ok:true,status:200,json:async()=>project(2)});await pending;
|
||||
assert.notEqual(n.__h3ContinuumTakeProject?.canonical_storage_revision_id,'r2');
|
||||
assert.notEqual(n.__h3ContinuumTakeProject?.revisions[0]?.review_unit?.end,2);
|
||||
});
|
||||
await test('clearing Run identity invalidates an in-flight history request',async e=>{
|
||||
const n=e.makeNode();await e.load(n,null);let release;
|
||||
e.setFetchHook(()=>new Promise(r=>release=r));const pending=e.f.loadTakeHistory(n,{force:true});
|
||||
e.w(n,'run_name').value='';e.w(n,'project_id').value='';await e.f.loadTakeHistory(n);
|
||||
release({ok:true,status:200,json:async()=>project(1)});await pending;assert.equal(n.__h3ContinuumTakeProject,null);
|
||||
});
|
||||
await test('identical concurrent history reads are coalesced',async e=>{
|
||||
const n=e.makeNode();await e.load(n,null);let release;const before=e.getFetchCount();
|
||||
e.setFetchHook(()=>new Promise(r=>release=r));const a=e.f.loadTakeHistory(n);const b=e.f.loadTakeHistory(n);
|
||||
assert.equal(e.getFetchCount(),before+1);release({ok:true,status:200,json:async()=>project(1)});await Promise.all([a,b]);
|
||||
});
|
||||
await test('two accepted prompts for one node retain distinct identity',async e=>{
|
||||
const n=e.makeNode();await e.load(n,null);e.w(n,'Run').callback('Review Each Chunk');
|
||||
const p1=await e.queue(n),p2=await e.queue(n);
|
||||
e.setSaved(project(2,3,'newer'));await e.emit('execution_success',{prompt_id:p2.prompt_id});
|
||||
e.setSaved(project(1,3,'older'));const reads=e.getFetchCount();await e.emit('execution_success',{prompt_id:p1.prompt_id});
|
||||
assert.equal(e.getFetchCount(),reads);assert.equal(n.__h3ContinuumTakeProject.canonical_storage_revision_id,'newer');
|
||||
});
|
||||
await test('a different sampler completion cannot release this node setup',async e=>{
|
||||
const a=e.makeNode(312,'first'),b=e.makeNode(313,'second');
|
||||
await e.load(a,null);await e.load(b,null);e.w(a,'Run').callback('Review Each Chunk');e.w(b,'Run').callback('Review Each Chunk');
|
||||
await e.queue(a);const q=await e.queue(b);e.setSaved(project(1,3,'second-r','second'));
|
||||
await e.emit('execution_success',{prompt_id:q.prompt_id});assert(a.__h3ContinuumModeSetup);assert(!b.__h3ContinuumModeSetup);
|
||||
});
|
||||
await test('partial execution excluding sampler leaves its state untouched',async e=>{
|
||||
const n=e.makeNode();await e.load(n,null);e.w(n,'Run').callback('Review Each Chunk');const reads=e.getFetchCount();
|
||||
const q=await e.queue(n,{partialExecutionTargets:['other-node']});e.setSaved(project(1));
|
||||
await e.emit('execution_success',{prompt_id:q.prompt_id});assert(n.__h3ContinuumModeSetup);assert.equal(reads,e.getFetchCount());
|
||||
});
|
||||
await test('early terminal before HTTP response is reconciled using the accepted ID',async e=>{
|
||||
const n=e.makeNode();await e.load(n,null);e.w(n,'Run').callback('Review Each Chunk');
|
||||
e.setQueueHook(async response=>{e.setSaved(project(1));await e.emit('execution_success',{prompt_id:response.prompt_id});});
|
||||
await e.queue(n);assert(e.visible(n,'Use it and continue'));assert(!n.__h3ContinuumModeSetup);
|
||||
});
|
||||
await test('the caller graph and workflow are not mutated by Queue adapter',async e=>{
|
||||
const n=e.makeNode();await e.load(n,project(1));e.w(n,'Run').callback('Review Each Chunk');
|
||||
const data={output:{'312':{class_type:n.comfyClass,inputs:await e.inputs(n)}},workflow:n.serialize()};
|
||||
const before=JSON.stringify(data);await e.api.queuePrompt(0,data);assert.equal(JSON.stringify(data),before);
|
||||
});
|
||||
await test('settings edited during execution remain out of date after readback',async e=>{
|
||||
const n=e.makeNode();await e.load(n,null);e.w(n,'Run').callback('Review Each Chunk');const q=await e.queue(n);
|
||||
e.w(n,'base_seed').value=999;e.setSaved(project(1));await e.emit('execution_success',{prompt_id:q.prompt_id});
|
||||
assert(e.f.reviewSettingsChanged(n));assert(!e.visible(n,'Use it and continue'));
|
||||
});
|
||||
await test('a later mode selection is not owned by an earlier prompt',async e=>{
|
||||
const n=e.makeNode();await e.load(n,null);e.w(n,'Run').callback('Review Each Chunk');const q=await e.queue(n);
|
||||
e.w(n,'Run').callback('Generate Full Video');e.w(n,'Run').callback('Review Each Chunk');const marker=n.__h3ContinuumModeSetup;
|
||||
e.setSaved(project(1));await e.emit('execution_success',{prompt_id:q.prompt_id});assert.equal(n.__h3ContinuumModeSetup,marker);
|
||||
});
|
||||
await test('missing/failed history readback does not claim success',async e=>{
|
||||
const n=e.makeNode();await e.load(n,null);e.w(n,'Run').callback('Review Each Chunk');const q=await e.queue(n);
|
||||
e.setFetchHook(async()=>{throw new Error('offline');});await e.emit('execution_success',{prompt_id:q.prompt_id});
|
||||
assert(n.__h3ContinuumModeSetup);assert(!e.visible(n,'Use it and continue'));assert.match(n.__h3ContinuumTakeError,/offline/);
|
||||
});
|
||||
await test('fresh browser state can open persisted Review without prior events',async e=>{
|
||||
const n=e.makeNode();e.w(n,'generation_mode').value='Review Each Chunk';await e.load(n,project(2));
|
||||
assert(e.visible(n,'Use it and continue'));assert.match(e.f.reviewStatus(n),/Chunk 2/);
|
||||
});
|
||||
await test('optional executed notification alone never releases setup',async e=>{
|
||||
const n=e.makeNode();await e.load(n,null);e.w(n,'Run').callback('Review Each Chunk');const q=await e.queue(n);
|
||||
e.setSaved(project(1));await e.emit('executed',{node:'312',prompt_id:q.prompt_id});assert(n.__h3ContinuumModeSetup);
|
||||
await e.emit('execution_success',{prompt_id:q.prompt_id});assert(!n.__h3ContinuumModeSetup);
|
||||
});
|
||||
await test('derived catalog is reused for one immutable readback',async e=>{
|
||||
const n=e.makeNode();await e.load(n,project(3,3));assert.equal(e.f.takeCatalog(n),e.f.takeCatalog(n));
|
||||
});
|
||||
await test('new Run identity cannot receive an older prompt result',async e=>{
|
||||
const n=e.makeNode();await e.load(n,null);e.w(n,'Run').callback('Review Each Chunk');const q=await e.queue(n);
|
||||
e.w(n,'run_name').value='new-run';e.setSaved(project(1));const reads=e.getFetchCount();
|
||||
await e.emit('execution_success',{prompt_id:q.prompt_id});assert.equal(e.getFetchCount(),reads);assert(n.__h3ContinuumModeSetup);
|
||||
});
|
||||
|
||||
|
||||
await test('cancelled queued prompt releases busy state without inventing a chunk',async e=>{
|
||||
const n=e.makeNode();await e.load(n,null);e.w(n,'Run').callback('Review Each Chunk');await e.queue(n);
|
||||
e.setFetchHook(async url=>({ok:true,status:200,json:async()=>String(url).startsWith('/queue')
|
||||
?{queue_running:[],queue_pending:[]}:{}}));
|
||||
await e.emit('status',{exec_info:{queue_remaining:0}});
|
||||
assert.match(e.f.reviewStatus(n),/no longer pending/);assert(n.__h3ContinuumModeSetup);
|
||||
});
|
||||
await test('missed websocket completion is recovered from exact prompt history',async e=>{
|
||||
const n=e.makeNode();await e.load(n,null);e.w(n,'Run').callback('Review Each Chunk');const q=await e.queue(n);
|
||||
e.setFetchHook(async url=>({ok:true,status:200,json:async()=>String(url).startsWith('/queue')
|
||||
?{queue_running:[],queue_pending:[]}:String(url).startsWith('/history/')
|
||||
?{[q.prompt_id]:{status:{messages:[['execution_success',{prompt_id:q.prompt_id}]]}}}:project(1)}));
|
||||
await e.emit('status',{exec_info:{queue_remaining:0}});
|
||||
assert(!n.__h3ContinuumModeSetup);assert(e.visible(n,'Use it and continue'));
|
||||
});
|
||||
await test('reconnect discovers the exact queued node/run after browser state loss',async e=>{
|
||||
const n=e.makeNode();e.w(n,'generation_mode').value='Review Each Chunk';await e.load(n,null);
|
||||
const inputs=await e.inputs(n);const queued=[1,'survived-prompt',{'312':{class_type:n.comfyClass,inputs}}, {},['312']];
|
||||
e.setFetchHook(async url=>({ok:true,status:200,json:async()=>String(url).startsWith('/queue')
|
||||
?{queue_running:[queued],queue_pending:[]}:project(1)}));
|
||||
await e.emit('reconnected',{});assert.match(e.f.reviewStatus(n),/Queued|progress/i);
|
||||
e.setFetchHook(null);e.setSaved(project(2));await e.emit('execution_success',{prompt_id:'survived-prompt'});
|
||||
assert(e.visible(n,'Use it and continue'));assert.match(e.f.reviewStatus(n),/Chunk 2/);
|
||||
});
|
||||
await test('connection error while reconciling is not treated as queue cancellation',async e=>{
|
||||
const n=e.makeNode();await e.load(n,null);e.w(n,'Run').callback('Review Each Chunk');const q=await e.queue(n);
|
||||
e.setFetchHook(async()=>{throw new Error('network unavailable');});await e.emit('status',{exec_info:{queue_remaining:0}});
|
||||
assert(!n.__h3ContinuumQueueNotice);e.setFetchHook(null);e.setSaved(project(1));
|
||||
await e.emit('execution_success',{prompt_id:q.prompt_id});assert(e.visible(n,'Use it and continue'));
|
||||
});
|
||||
await test('terminal readback failure can recover on reconnect without another Sampling',async e=>{
|
||||
const n=e.makeNode();await e.load(n,null);e.w(n,'Run').callback('Review Each Chunk');const q=await e.queue(n);
|
||||
e.setFetchHook(async()=>{throw new Error('readback offline');});await e.emit('execution_success',{prompt_id:q.prompt_id});
|
||||
e.setFetchHook(async url=>({ok:true,status:200,json:async()=>String(url).startsWith('/queue')
|
||||
?{queue_running:[],queue_pending:[]}:String(url).startsWith('/history/')
|
||||
?{[q.prompt_id]:{status:{messages:[['execution_success',{prompt_id:q.prompt_id}]]}}}:project(1)}));
|
||||
await e.emit('reconnected',{});assert(!n.__h3ContinuumModeSetup);assert(e.visible(n,'Use it and continue'));
|
||||
assert.equal(e.submissions.length,1);
|
||||
});
|
||||
|
||||
|
||||
await test('linked chunk count does not block committed review readback',async e=>{
|
||||
const n=e.makeNode();await e.load(n,null);e.w(n,'Run').callback('Review Each Chunk');
|
||||
const inputs={...await e.inputs(n),chunks:['primitive',0]};
|
||||
const q=await e.api.queuePrompt(0,{output:{'312':{class_type:n.comfyClass,inputs},primitive:{class_type:'PrimitiveInt',inputs:{value:3}}},workflow:{}});
|
||||
e.setSaved(project(1));await e.emit('execution_success',{prompt_id:q.prompt_id});
|
||||
assert(!n.__h3ContinuumModeSetup);assert(e.visible(n,'Use it and continue'));
|
||||
});
|
||||
await test('removing one sampler does not discard another accepted sampler',async e=>{
|
||||
const a=e.makeNode(312,'one'),b=e.makeNode(313,'two');await e.load(a,null);await e.load(b,null);
|
||||
e.w(a,'Run').callback('Review Each Chunk');e.w(b,'Run').callback('Review Each Chunk');
|
||||
const q=await e.api.queuePrompt(0,{output:{'312':{class_type:a.comfyClass,inputs:await e.inputs(a)},'313':{class_type:b.comfyClass,inputs:await e.inputs(b)}},workflow:{}});
|
||||
a.onRemoved();e.app.graph._nodes=e.app.graph._nodes.filter(n=>n!==a);
|
||||
e.setSaved(project(1,3,'two-r1','two'));await e.emit('execution_success',{prompt_id:q.prompt_id});
|
||||
assert(e.visible(b,'Use it and continue'));
|
||||
});
|
||||
await test('queue adapter owns setup preparation without mutating the caller payload',async e=>{
|
||||
const n=e.makeNode();await e.load(n,project(3,3));e.w(n,'chunks').value=5;e.w(n,'Run').callback('Review Each Chunk');
|
||||
const inputs=await e.inputs(n);const before=JSON.stringify(inputs);
|
||||
await e.api.queuePrompt(0,{output:{'312':{class_type:n.comfyClass,inputs}},workflow:{}});
|
||||
assert.equal(JSON.stringify(inputs),before);
|
||||
const sent=e.submissions.at(-1).data.output['312'].inputs;
|
||||
assert.equal(sent.reroll_from_chunk,'Auto');assert.equal(sent.review_action,'Continue / Next');
|
||||
assert.equal(sent.take_action,'Automatic');
|
||||
});
|
||||
|
||||
|
||||
await test('mode selection preserves progress and still exposes an explicit restart',async e=>{
|
||||
const n=e.makeNode();await e.load(n,project(3,3));e.w(n,'Run').callback('Review Each Chunk');
|
||||
assert(e.visible(n,'Start again from Chunk 1'));
|
||||
e.w(n,'Start again from Chunk 1').callback();const q=await e.queue(n);
|
||||
assert.equal(e.submissions.at(-1).data.output['312'].inputs.reroll_from_chunk,'Chunk 1');
|
||||
assert.equal(e.w(n,'reroll_from_chunk').value,'Auto');
|
||||
e.setSaved(project(1,3,'explicit-restart'));await e.emit('execution_success',{prompt_id:q.prompt_id});
|
||||
assert(e.visible(n,'Use it and continue'));
|
||||
});
|
||||
|
||||
|
||||
await test('persisted review repairs an unowned stale Chunk 1 boundary',async e=>{
|
||||
const n=e.makeNode();e.w(n,'reroll_from_chunk').value='Chunk 1';e.w(n,'generation_mode').value='Review Each Chunk';
|
||||
await e.load(n,project(1));
|
||||
assert.equal(e.w(n,'reroll_from_chunk').value,'Auto');
|
||||
assert(e.visible(n,'Use it and continue'));assert(e.visible(n,'Try this chunk again'));
|
||||
});
|
||||
await test('explicit advanced Regenerate From remains explicit after refresh',async e=>{
|
||||
const n=e.makeNode();e.w(n,'generation_mode').value='Review Each Chunk';await e.load(n,project(1));
|
||||
e.w(n,'reroll_from_chunk').value='Chunk 1';e.w(n,'reroll_from_chunk').callback?.('Chunk 1');
|
||||
await e.f.loadTakeHistory(n,{force:true});
|
||||
assert.equal(e.w(n,'reroll_from_chunk').value,'Chunk 1');
|
||||
assert.match(e.f.reviewStatus(n),/Regenerate from Chunk 1/);
|
||||
});
|
||||
await test('Progress Off cannot submit a stale Regenerate From boundary',async e=>{
|
||||
const n=e.makeNode();await e.load(n,project(1));
|
||||
e.w(n,'run_storage').value='Off';e.w(n,'reroll_from_chunk').value='Chunk 1';e.w(n,'generation_mode').value='Full Run';
|
||||
await e.queue(n);const sent=e.submissions.at(-1).data.output['312'].inputs;
|
||||
assert.equal(sent.run_storage,'Off');assert.equal(sent.reroll_from_chunk,'Auto');assert.equal(sent.reroll_nonce,0);
|
||||
assert.equal(e.w(n,'reroll_from_chunk').value,'Auto');
|
||||
});
|
||||
await test('successful Auto continue clears stale boundary and restores review buttons',async e=>{
|
||||
const n=e.makeNode();e.w(n,'generation_mode').value='Review Each Chunk';await e.load(n,project(1));
|
||||
e.w(n,'Use it and continue').callback();const q=await e.queue(n);
|
||||
assert.equal(e.submissions.at(-1).data.output['312'].inputs.reroll_from_chunk,'Auto');
|
||||
// Simulate stale hidden UI residue appearing after queue acceptance.
|
||||
e.w(n,'reroll_from_chunk').value='Chunk 1';
|
||||
e.setSaved(project(2));await e.emit('execution_success',{prompt_id:q.prompt_id});
|
||||
assert.equal(e.w(n,'reroll_from_chunk').value,'Auto');
|
||||
assert(e.visible(n,'Use it and continue'));assert(e.visible(n,'Try this chunk again'));
|
||||
});
|
||||
|
||||
|
||||
await test('retry consumed after acceptance without legacy preparation hook',async e=>{
|
||||
const n=e.makeNode();e.w(n,'generation_mode').value='Review Each Chunk';await e.load(n,project(1));
|
||||
e.w(n,'Try this chunk again').callback();await e.queue(n);
|
||||
assert.equal(e.w(n,'review_action').value,'Continue / Next');
|
||||
await e.queue(n);assert.equal(e.submissions.at(-1).data.output['312'].inputs.review_action,'Continue / Next');
|
||||
});
|
||||
await test('explicit restart consumed and Chunk 1 Continue restored',async e=>{
|
||||
const n=e.makeNode();e.w(n,'generation_mode').value='Review Each Chunk';await e.load(n,project(3,3));
|
||||
assert(e.visible(n,'Start again from Chunk 1'));e.w(n,'Start again from Chunk 1').callback();
|
||||
const q=await e.queue(n);assert.equal(e.submissions.at(-1).data.output['312'].inputs.reroll_from_chunk,'Chunk 1');
|
||||
e.setSaved(project(1,3,'restarted'));await e.emit('execution_success',{prompt_id:q.prompt_id});
|
||||
assert.equal(e.w(n,'reroll_from_chunk').value,'Auto');assert(e.visible(n,'Use it and continue'));
|
||||
});
|
||||
await test('850 ms terminal readback releases setup after it resolves',async e=>{
|
||||
const n=e.makeNode();await e.load(n,null);e.w(n,'Run').callback('Review Each Chunk');const q=await e.queue(n);
|
||||
e.setFetchHook(async()=>{await new Promise(r=>setTimeout(r,850));return {ok:true,status:200,json:async()=>project(1)};});
|
||||
await e.emit('execution_success',{prompt_id:q.prompt_id});
|
||||
assert.equal(n.__h3ContinuumTakeProject.canonical_storage_revision_id,'r1');
|
||||
assert(!n.__h3ContinuumModeSetup);assert(e.visible(n,'Use it and continue'));
|
||||
});
|
||||
await test('same completed revision reuse exits setup without new Sampling',async e=>{
|
||||
const n=e.makeNode();e.w(n,'chunks').value=2;await e.load(n,project(2,2,'done'));
|
||||
e.w(n,'Run').callback('Review Each Chunk');const q=await e.queue(n);
|
||||
e.setSaved(project(2,2,'done'));await e.emit('execution_success',{prompt_id:q.prompt_id});
|
||||
assert(!n.__h3ContinuumModeSetup);assert(e.visible(n,'Try this chunk again'));assert(e.visible(n,'Start again from Chunk 1'));
|
||||
assert(!e.visible(n,'Use it and continue'));assert.equal(e.submissions.length,1);
|
||||
});
|
||||
await test('Issue 20 store persistence excludes transient UI across reloads',async e=>{
|
||||
// Model the compact store serializer, which does NOT call node.serialize().
|
||||
// The flag contract is from ComfyUI_frontend 77bdc5d LGraphNode.ts.
|
||||
// Real Continuum UI creation/refresh runs through the existing environment.
|
||||
const n=e.makeNode();await e.load(n,null);
|
||||
const persistent=()=>n.widgets.filter(w=>!w.__h3ContinuumProductionTransient);
|
||||
const values=()=>persistent().map(w=>structuredClone(w.value));
|
||||
const storeSave=()=>{
|
||||
const widgets=n.widgets.filter(w=>w.serialize!==false);
|
||||
return {widgets_values:widgets.map(w=>structuredClone(w.value)),
|
||||
widgets_values_named:Object.fromEntries(widgets.map(w=>[w.name,structuredClone(w.value)]))};
|
||||
};
|
||||
// Array-only projection of Core's forceInput migration in litegraphUtil.ts.
|
||||
// A leaked history value makes 30 values look like a 31-value legacy payload.
|
||||
const migrate=(widgets,saved)=>{
|
||||
const defs=[{name:'sequence_prompt',forceInput:true},
|
||||
...persistent().filter(w=>w.name!=='control_after_generate')
|
||||
.map(w=>({name:w.name,control_after_generate:w.name==='base_seed'}))];
|
||||
const names=new Set(widgets.map(w=>w.name));
|
||||
const skipped=new Set(widgets.filter(w=>w.serialize===false).map(w=>w.name));
|
||||
const mask=defs.filter(d=>names.has(d.name)||d.forceInput).flatMap(d=>
|
||||
skipped.has(d.name)?[]:d.control_after_generate?[!!d.forceInput,false]:[!!d.forceInput]);
|
||||
const count=widgets.filter(w=>w.serialize!==false).length;
|
||||
if(!mask.includes(true)&&saved.length===count)return saved;
|
||||
const compacted=saved.filter((_,i)=>widgets[i]?.serialize!==false);
|
||||
const aligned=compacted.length===mask.length?compacted:saved.length===mask.length?saved:undefined;
|
||||
return aligned?aligned.filter((_,i)=>!mask[i]):saved;
|
||||
};
|
||||
const verify=async()=>{
|
||||
const expected=values();assert.equal(expected.length,30);
|
||||
const saved=storeSave();
|
||||
assert.equal(saved.widgets_values.length,30,'UI-only history leaked into workflow persistence');
|
||||
assert.deepEqual(saved.widgets_values,expected);
|
||||
assert.deepEqual(n.serialize().widgets_values,expected);
|
||||
assert.deepEqual(Object.keys(saved.widgets_values_named),persistent().map(w=>w.name));
|
||||
for(const w of n.widgets.filter(w=>w.__h3ContinuumProductionTransient)){
|
||||
assert.equal(w.serialize,false,`${w.name}: workflow exclusion`);
|
||||
assert.equal(w.options?.serialize,false,`${w.name}: API exclusion`);
|
||||
}
|
||||
const apiBefore=await e.inputs(n);
|
||||
assert(!Object.hasOwn(apiBefore,'Render History / Takes'));
|
||||
for(const named of [false,true]){
|
||||
for(let i=0;i<3;i++){
|
||||
const data=JSON.parse(JSON.stringify(storeSave()));
|
||||
const canonical=persistent();
|
||||
const migrated=migrate(canonical,data.widgets_values);
|
||||
assert.deepEqual(migrated,expected);
|
||||
if(named){
|
||||
for(const w of canonical)w.value=structuredClone(data.widgets_values_named[w.name]);
|
||||
}else n.configure({widgets_values:migrated});
|
||||
e.f.configureNode(n);
|
||||
assert.deepEqual(values(),expected);
|
||||
assert.equal(e.w(n,'Prompt Format').value,e.w(n,'prompt_mode').value);
|
||||
assert.equal(e.w(n,'Height').value,e.w(n,'height').value);
|
||||
}
|
||||
}
|
||||
assert.deepEqual(await e.inputs(n),apiBefore);
|
||||
};
|
||||
// Empty history, ordinary settings, expanded controls, Review and completion.
|
||||
e.w(n,'Chunks').callback(6);e.w(n,'Seconds per Chunk').callback(2.5);
|
||||
e.w(n,'Width').callback(640);e.w(n,'Height').callback(768);
|
||||
await verify();
|
||||
e.w(n,'Advanced Settings').callback();await verify();
|
||||
e.w(n,'generation_mode').value='Review Each Chunk';await e.load(n,project(1,6));
|
||||
await verify();e.w(n,'Render History').callback();await verify();
|
||||
e.w(n,'Back to Settings').callback();await verify();
|
||||
e.w(n,'Return to Review').callback();await verify();
|
||||
await e.load(n,project(6,6,'complete'));await verify();
|
||||
});
|
||||
await test('mode policy and transient UI serialization remain stable',async e=>{
|
||||
const n=e.makeNode();e.w(n,'run_storage').value='Off';e.w(n,'Run').callback('Review Each Chunk');
|
||||
assert.equal(e.w(n,'run_storage').value,'Save + Auto Resume');e.w(n,'Run').callback('Generate Full Video');
|
||||
assert.equal(e.w(n,'run_storage').value,'Save + Auto Resume');
|
||||
e.w(n,'Run').callback('Review Each Chunk');await e.load(n,project(1));e.w(n,'Return to Review').callback();
|
||||
const before=JSON.stringify(n.serialize());e.w(n,'Back to Settings').callback();e.w(n,'Return to Review').callback();
|
||||
assert.equal(JSON.stringify(n.serialize()),before);
|
||||
const p=project(2,2,'full-complete');delete p.revisions[0].review_unit;await e.load(n,p);
|
||||
assert(!e.visible(n,'Try this chunk again'));assert(e.visible(n,'Render History'));
|
||||
});
|
||||
await test('history catalog preserves lineage eligibility and compact summary',async e=>{
|
||||
const n=e.makeNode();e.w(n,'generation_mode').value='Review Each Chunk';const p=project(3,3);
|
||||
p.group_revisions.push({revision_id:'old',lineage_sha256:'other',sampling_contract_version:6,generation_reusable:true,group:{start:1,end:1,physical_group:1}},
|
||||
{revision_id:'orphan',parent_revision_id:'missing',lineage_sha256:'lineage',sampling_contract_version:6,generation_reusable:true,group:{start:2,end:2,physical_group:2}});
|
||||
await e.load(n,p);assert.equal(e.f.takeCatalog(n).length,3);
|
||||
e.w(n,'Render History').callback();const body=e.w(n,'Render History / Takes');
|
||||
assert(body.computeSize(400)[1]<=124);const drawn=[];
|
||||
body.draw({save(){},restore(){},beginPath(){},rect(){},clip(){},fillText(s){drawn.push(s);}},n,400,0,20);
|
||||
assert(drawn.length>1);assert(drawn.some(s=>s.startsWith('Selected:')));
|
||||
e.f.selectTakeOffset(n,-1);e.f.selectTakeAction(n,'Continue From Here');
|
||||
assert.equal(e.w(n,'take_revision_id').value,'r1-g2');assert.equal(e.w(n,'take_action').value,'Continue From Here');
|
||||
assert.equal(p.canonical_head_revision_id,'r1-g3');
|
||||
});
|
||||
|
||||
await test('duration sockets map to visible facades without changing Core names or types',async e=>{
|
||||
const n=e.makeNode();
|
||||
for(const [name,type,label] of [['chunks','INT','Chunks'],['chunk_seconds','FLOAT','Seconds per Chunk']]){
|
||||
const slot={name,type,link:null,widget:{name}};n.inputs.push(slot);
|
||||
assert.equal(n.getWidgetFromSlot(slot),e.w(n,label));
|
||||
assert.equal(n.getSlotFromWidget(e.w(n,label)),slot);
|
||||
assert.equal(n.getSlotFromWidget(e.w(n,name)),slot);
|
||||
assert.equal(slot.widget.name,name);assert.equal(slot.type,type);
|
||||
assert(!n.getWidgetFromSlot(slot).hidden);assert(e.w(n,name).hidden);
|
||||
}
|
||||
const other={name:'base_seed',widget:{name:'base_seed'}};n.inputs.push(other);
|
||||
assert.equal(n.getWidgetFromSlot(other),e.w(n,'base_seed'));
|
||||
const getter=n.getWidgetFromSlot;e.f.configureNode(n);assert.equal(n.getWidgetFromSlot,getter);
|
||||
for(const slot of n.inputs.filter(s=>['chunks','chunk_seconds'].includes(s.name))){
|
||||
assert.equal(slot._widget,n.getWidgetFromSlot(slot));
|
||||
assert(!slot._widget.hidden);
|
||||
}
|
||||
// Workflow loading replaces slot objects; configure must bind the new slots.
|
||||
n.inputs=n.inputs.map(s=>({name:s.name,type:s.type,widget:s.widget,link:null}));
|
||||
e.f.configureNode(n);
|
||||
assert.equal(n.inputs[0]._widget,e.w(n,'Chunks'));
|
||||
assert.equal(n.inputs[1]._widget,e.w(n,'Seconds per Chunk'));
|
||||
e.w(n,'generation_mode').value='Review Each Chunk';
|
||||
n.inputs[0].link=42;n.inputs[1].link=43;
|
||||
await e.load(n,project(1));
|
||||
assert(e.visible(n,'Chunks'));assert(e.visible(n,'Seconds per Chunk'));
|
||||
assert.equal(n.widgets[0].name,'Chunks');assert.equal(n.widgets[1].name,'Seconds per Chunk');
|
||||
e.w(n,'Back to Settings').callback();
|
||||
assert.equal(n.widgets[0].name,'Chunks');assert.equal(n.widgets[1].name,'Seconds per Chunk');
|
||||
e.w(n,'Return to Review').callback();
|
||||
assert.equal(n.widgets[0].name,'Chunks');assert.equal(n.widgets[1].name,'Seconds per Chunk');
|
||||
n.inputs[0].link=null;n.inputs[1].link=null;
|
||||
n.__h3ContinuumIntuitiveUxRefresh();n.__h3ContinuumProductionUxRefresh();
|
||||
assert(!e.visible(n,'Chunks'));assert(!e.visible(n,'Seconds per Chunk'));
|
||||
});
|
||||
await test('duration manual entry and serialized values survive connect disconnect and reload',async e=>{
|
||||
const n=e.makeNode();e.w(n,'Chunks').callback(6);e.w(n,'Seconds per Chunk').callback(2.5);
|
||||
const before=n.serialize();const input={name:'chunks',type:'INT',widget:{name:'chunks'},link:42};
|
||||
n.inputs.push(input);n.__h3ContinuumIntuitiveUxRefresh();
|
||||
assert.equal(e.w(n,'Total Length').value,'From connected inputs');
|
||||
assert.equal(JSON.stringify(n.serialize()),JSON.stringify(before));
|
||||
input.link=null;n.__h3ContinuumIntuitiveUxRefresh();
|
||||
assert.equal(e.w(n,'Total Length').value,'15 seconds');
|
||||
const restored=e.makeNode(313);restored.configure(before);
|
||||
assert.equal(e.w(restored,'chunks').value,6);assert.equal(e.w(restored,'chunk_seconds').value,2.5);
|
||||
const values=await e.inputs(restored);assert.equal(values.chunks,6);assert.equal(values.chunk_seconds,2.5);
|
||||
assert(!Object.hasOwn(values,'Chunks'));assert(!Object.hasOwn(values,'Seconds per Chunk'));
|
||||
});
|
||||
await test('external duration links remain links through actual review Queue adapter',async e=>{
|
||||
const n=e.makeNode();e.w(n,'chunks').value=1;
|
||||
n.inputs.push({name:'chunks',type:'INT',widget:{name:'chunks'},link:42});
|
||||
e.w(n,'Run').callback('Review Each Chunk');n.__h3ContinuumIntuitiveUxRefresh();
|
||||
assert(!e.w(n,'Chunks').tooltip.includes('Chunks is 1'));
|
||||
const data={output:{[n.id]:{class_type:n.comfyClass,inputs:{...(await e.inputs(n)),chunks:['900',0],chunk_seconds:['901',0]}}},workflow:n.serialize()};
|
||||
await e.api.queuePrompt(0,data);
|
||||
assert.deepEqual(e.submissions.at(-1).data.output[n.id].inputs.chunks,['900',0]);
|
||||
assert.deepEqual(e.submissions.at(-1).data.output[n.id].inputs.chunk_seconds,['901',0]);
|
||||
});
|
||||
await test('V39 helper settings invalidate transient observed Plan',async e=>{
|
||||
const n=e.makeNode(390,'v39','H3ContinuumSamplerV39');
|
||||
const helper=e.makeNode(391,'helper','H3ContinuumReferenceImagesV39');
|
||||
helper.widgets.push({name:'reference_use',value:'Per chunk',type:'combo',options:{}});
|
||||
helper.widgets.push({name:'reference_r1_chunks',value:'1,2',type:'text',options:{}});
|
||||
e.app.graph.links[900]={origin_id:391,origin_slot:0,target_id:390,target_slot:0};
|
||||
n.inputs.push({name:'reference_images',link:900});
|
||||
n.__h3ContinuumIntuitiveUxRefresh();
|
||||
const before=JSON.stringify(n.serialize());
|
||||
const observed='Reference Plan Inspector (runtime verified)\nGroup 1 [C1] generated — R1=<Picture 1>';
|
||||
n.onExecuted({h3_reference_plan:[observed]});
|
||||
assert.equal(e.w(n,'Reference Plan Inspector').value,observed);
|
||||
assert.equal(JSON.stringify(n.serialize()),before);
|
||||
assert.equal((await e.inputs(n)).reference_r1_chunks,undefined);
|
||||
e.w(helper,'reference_r1_chunks').value='2';
|
||||
n.__h3ContinuumIntuitiveUxRefresh();
|
||||
assert.match(e.w(n,'Reference Plan Inspector').value,/Configured only/);
|
||||
n.onExecuted({h3_reference_plan:[observed]});
|
||||
n.onConnectionsChange(1,0,true);
|
||||
assert.match(e.w(n,'Reference Plan Inspector').value,/Configured only/);
|
||||
e.app.extension.loadedGraphNode(n);
|
||||
assert.match(e.w(n,'Reference Plan Inspector').value,/Configured only/);
|
||||
assert.equal(e.w(helper,'reference_r1_chunks').value,'2');
|
||||
});
|
||||
await test('V39 loaded node removes only unused old Reference sockets',async e=>{
|
||||
const n=e.makeNode(392,'v39-stale','H3ContinuumSamplerV39');
|
||||
n.removeInput=function(index){this.inputs.splice(index,1);};
|
||||
n.inputs.push(
|
||||
{name:'reference_image_1',link:null},
|
||||
{name:'reference_image_2',link:77},
|
||||
{name:'reference_images',link:null},
|
||||
);
|
||||
e.app.extension.loadedGraphNode(n);
|
||||
assert.deepEqual(n.inputs.map(input=>input.name),['reference_image_2','reference_images']);
|
||||
assert.equal(n.inputs[0].link,77);
|
||||
assert.match(e.w(n,'Reference Plan Inspector').value,/Old Reference connection/);
|
||||
n.inputs[0].link=null;
|
||||
e.app.extension.loadedGraphNode(n);
|
||||
assert.deepEqual(n.inputs.map(input=>input.name),['reference_images']);
|
||||
assert.match(e.w(n,'Reference Plan Inspector').value,/Configured only/);
|
||||
});
|
||||
for(const nodeClass of ['H3ContinuumSamplerV38','H3ContinuumSamplerV39']) {
|
||||
await test(`${nodeClass}: recreated tab waits for saved identity and upstream links`,async e=>{
|
||||
const saved=project(1),before=JSON.stringify(saved);e.setSaved(saved);
|
||||
e.app.extension.beforeConfigureGraph?.();
|
||||
const n=e.makeNode(312,'',nodeClass,false);e.app.extension.nodeCreated(n);
|
||||
const reads=e.getFetchCount();
|
||||
e.w(n,'run_name').value='fixture';e.w(n,'generation_mode').value='Review Each Chunk';
|
||||
e.app.extension.loadedGraphNode(n);
|
||||
assert.equal(e.getFetchCount(),reads,'restoration must not fetch a default Run');
|
||||
// Core recreates nodes, then restores upstream nodes and link objects.
|
||||
const source={id:900,comfyClass:'Text',mode:0,widgets:[{name:'text',value:'A quiet scene.'}],inputs:[]};
|
||||
e.app.graph._nodes.push(source);e.app.graph.links[42]={origin_id:900,origin_slot:0};
|
||||
n.inputs.push({name:'sequence_prompt',link:42});await e.finishRestore();
|
||||
assert.equal(n.__h3ContinuumHistoryRun,'fixture');assert(!e.f.reviewSettingsChanged(n));
|
||||
for(const name of ['Use it and continue','Try this chunk again','Use it and finish the rest','Render History'])assert(e.visible(n,name),name);
|
||||
e.w(n,'Render History').callback();assert(e.visible(n,'Use This Take'));assert(!e.w(n,'Use This Take').disabled);
|
||||
assert.equal(JSON.stringify(saved),before);assert.equal(e.submissions.length,0);
|
||||
});
|
||||
}
|
||||
await test('ten rapid recreated tabs reject every obsolete history response',async e=>{
|
||||
const pending=[];e.setFetchHook(url=>new Promise(resolve=>pending.push({url,resolve})));
|
||||
const old=[];
|
||||
for(let i=0;i<10;i++){
|
||||
e.app.extension.beforeConfigureGraph?.();
|
||||
for(const n of e.app.graph._nodes){n.onRemoved?.();old.push(n);}e.app.graph._nodes=[];
|
||||
const n=e.makeNode(312,`run-${i}`,'H3ContinuumSamplerV39',false);
|
||||
e.w(n,'generation_mode').value='Review Each Chunk';e.app.extension.nodeCreated(n);e.app.extension.loadedGraphNode(n);
|
||||
await e.app.extension.afterConfigureGraph();
|
||||
}
|
||||
assert.equal(pending.length,10);
|
||||
const latest=e.app.graph._nodes[0];
|
||||
for(let i=9;i>=0;i--)pending[i].resolve({ok:true,status:200,json:async()=>project(1,3,`r-${i}`,`run-${i}`)});
|
||||
await Promise.all([...old,latest].map(n=>n.__h3ContinuumHistoryRequest?.promise));await sleep();
|
||||
assert.equal(latest.__h3ContinuumTakeProject.canonical_storage_revision_id,'r-9');
|
||||
assert(old.every(n=>!n.__h3ContinuumTakeProject));assert(e.visible(latest,'Use it and continue'));
|
||||
assert.equal(e.submissions.length,0);
|
||||
});
|
||||
await test('API graph restoration without a before hook still reloads history',async e=>{
|
||||
const n=e.makeNode();await e.load(n,null);e.setSaved(project(1));
|
||||
e.w(n,'generation_mode').value='Review Each Chunk';await e.finishRestore();
|
||||
assert(e.visible(n,'Use it and continue'));assert(!e.f.reviewSettingsChanged(n));
|
||||
});
|
||||
await test('manually added sampler loads history after deferred setup',async e=>{
|
||||
e.setSaved(project(1));const n=e.makeNode(312,'fixture','H3ContinuumSamplerV39',false);
|
||||
e.w(n,'generation_mode').value='Review Each Chunk';e.app.extension.nodeCreated(n);
|
||||
assert.equal(e.getFetchCount(),0);await n.__h3ContinuumConfigurePending?.promise;
|
||||
await n.__h3ContinuumHistoryRequest?.promise;await sleep();
|
||||
assert(e.visible(n,'Use it and continue'));
|
||||
});
|
||||
await test('real edits while restored history is pending retain the settings guard',async e=>{
|
||||
let release;e.setFetchHook(()=>new Promise(resolve=>release=resolve));
|
||||
e.app.extension.beforeConfigureGraph?.();const n=e.makeNode(312,'fixture','H3ContinuumSamplerV39',false);
|
||||
e.w(n,'generation_mode').value='Review Each Chunk';e.app.extension.nodeCreated(n);
|
||||
await e.app.extension.afterConfigureGraph();e.w(n,'base_seed').value=999;
|
||||
release({ok:true,status:200,json:async()=>project(1)});await n.__h3ContinuumHistoryRequest?.promise;
|
||||
assert(e.f.reviewSettingsChanged(n));assert(!e.visible(n,'Use it and continue'));
|
||||
});
|
||||
await test('same revision graph refresh cannot erase an existing real edit',async e=>{
|
||||
const n=e.makeNode();e.w(n,'generation_mode').value='Review Each Chunk';await e.load(n,project(1));
|
||||
e.w(n,'base_seed').value=999;await e.finishRestore();
|
||||
assert(e.f.reviewSettingsChanged(n));assert(!e.visible(n,'Use it and continue'));
|
||||
});
|
||||
await test('graph epoch rejects old results even if the same node remains attached',async e=>{
|
||||
const n=e.makeNode();await e.load(n,null);let release;
|
||||
e.setFetchHook(()=>new Promise(resolve=>release=resolve));const request=e.f.loadTakeHistory(n,{force:true});
|
||||
e.app.extension.beforeConfigureGraph?.();
|
||||
release({ok:true,status:200,json:async()=>project(1)});await request;
|
||||
assert(!n.__h3ContinuumTakeProject);
|
||||
e.setFetchHook(null);e.setSaved(project(1));e.w(n,'generation_mode').value='Review Each Chunk';
|
||||
await e.finishRestore();assert(e.visible(n,'Use it and continue'));
|
||||
});
|
||||
await test('removed sampler cancels deferred setup without fetching or mutating it',async e=>{
|
||||
e.setSaved(project(1));const n=e.makeNode(312,'fixture','H3ContinuumSamplerV39',false);
|
||||
e.app.extension.nodeCreated(n);const setup=n.__h3ContinuumConfigurePending?.promise;
|
||||
n.onRemoved();e.app.graph._nodes=[];await setup;
|
||||
assert.equal(e.getFetchCount(),0);assert(!n.__h3ContinuumTakeProject);
|
||||
});
|
||||
await test('initial restored history read preserves saved Take selection fields',async e=>{
|
||||
e.app.extension.beforeConfigureGraph?.();e.setSaved(project(1));
|
||||
const n=e.makeNode(312,'fixture','H3ContinuumSamplerV39',false);e.app.extension.nodeCreated(n);
|
||||
e.w(n,'take_group').value=1;e.w(n,'take_revision_id').value='r1-g1';
|
||||
// One-shot actions are normalized separately by the existing load hook.
|
||||
e.app.extension.loadedGraphNode(n);await e.finishRestore();
|
||||
assert.equal(e.w(n,'take_group').value,1);assert.equal(e.w(n,'take_revision_id').value,'r1-g1');
|
||||
});
|
||||
await test('restored missing or failed history reports accurately and can retry',async e=>{
|
||||
const n=e.makeNode();await e.load(n,null);await e.finishRestore();
|
||||
assert(!n.__h3ContinuumTakeProject);assert(!n.__h3ContinuumTakeError);
|
||||
e.setFetchHook(async()=>({ok:false,status:500}));await e.finishRestore();
|
||||
assert.match(e.w(n,'Ready to Queue').headline,/unavailable/);
|
||||
e.setFetchHook(null);e.setSaved(project(1));e.w(n,'generation_mode').value='Review Each Chunk';
|
||||
await e.finishRestore();assert(e.visible(n,'Use it and continue'));assert(!n.__h3ContinuumTakeError);
|
||||
});
|
||||
await test('failed graph load releases hydration gate for subsequent manual nodes',async e=>{
|
||||
e.app.extension.beforeConfigureGraph?.();e.app.extension.onGraphLoadError?.();
|
||||
e.setSaved(project(1));const n=e.makeNode(312,'fixture','H3ContinuumSamplerV39',false);
|
||||
e.w(n,'generation_mode').value='Review Each Chunk';e.app.extension.nodeCreated(n);
|
||||
await n.__h3ContinuumConfigurePending?.promise;await n.__h3ContinuumHistoryRequest?.promise;await sleep();
|
||||
assert(e.visible(n,'Use it and continue'));
|
||||
});
|
||||
await test('Sampling v5 history stays visible and actions remain read-only',async e=>{
|
||||
const p=project(2);for(const item of [...p.group_revisions,...p.revisions]){
|
||||
item.sampling_contract_version=5;item.generation_reusable=false;
|
||||
}
|
||||
const n=e.makeNode();await e.load(n,p);
|
||||
assert.equal(e.f.takeCatalog(n).length,2);
|
||||
assert.match(e.f.reviewStatus(n),/read-only/);
|
||||
const before=[e.w(n,'take_action').value,e.w(n,'take_revision_id').value];
|
||||
e.f.selectTakeAction(n,'Use This Take');
|
||||
assert.deepEqual([e.w(n,'take_action').value,e.w(n,'take_revision_id').value],before);
|
||||
assert(!e.visible(n,'Use it and continue'));
|
||||
});
|
||||
await test('archived v5 lineage remains browsable after a v6 canonical run',async e=>{
|
||||
const old=project(2,'fixture',3,'old');for(const item of old.group_revisions){
|
||||
item.sampling_contract_version=5;item.generation_reusable=false;item.lineage_sha256='old-lineage';
|
||||
}
|
||||
const current=project(1);current.group_revisions.push(...old.group_revisions);
|
||||
const n=e.makeNode();await e.load(n,current);
|
||||
assert.equal(e.f.takeCatalog(n).length,3);
|
||||
});
|
||||
|
||||
await test('v6 read-only reports saved preview source and keeps actions disabled',async e=>{
|
||||
const p=project(1),reason='KJ/Core preview implementation is outside the audited source profiles';
|
||||
for(const item of [...p.group_revisions,...p.revisions]){
|
||||
item.generation_reusable=false;item.resume_disabled_reasons=[reason];
|
||||
}
|
||||
const n=e.makeNode();e.w(n,'generation_mode').value='Review Each Chunk';await e.load(n,p);
|
||||
assert.match(e.f.reviewStatus(n),/Sampling v6 Take is read-only/);
|
||||
assert.match(e.f.reviewStatus(n),/Bypass KJ Model Preview Override/);
|
||||
assert(!e.visible(n,'Use it and continue'));
|
||||
const before=[e.w(n,'take_action').value,e.w(n,'take_revision_id').value,e.w(n,'run_name').value];
|
||||
e.f.selectTakeAction(n,'Use This Take');e.f.selectTakeAction(n,'Continue From Here');
|
||||
assert.deepEqual([e.w(n,'take_action').value,e.w(n,'take_revision_id').value,e.w(n,'run_name').value],before);
|
||||
});
|
||||
await test('preview setting remedies preserve generation VAE guidance',async e=>{
|
||||
const cases=[
|
||||
['KJ preview VAE/Audio VAE or Tiny VAE is outside the supported configuration',/Keep the generation VAEs connected/],
|
||||
['Core approximate-VAE preview is outside the supported configuration',/Auto or Latent2RGB/],
|
||||
];
|
||||
for(const [index,[reason,expected]] of cases.entries()){
|
||||
const p=project(1);for(const item of [...p.group_revisions,...p.revisions]){
|
||||
item.generation_reusable=false;item.resume_disabled_reasons=[reason];
|
||||
}
|
||||
const n=e.makeNode(312+index);e.w(n,'generation_mode').value='Review Each Chunk';await e.load(n,p);
|
||||
assert.match(e.f.reviewStatus(n),expected);
|
||||
assert.match(e.f.reviewStatus(n),/After correcting the configuration/);
|
||||
assert(!e.visible(n,'Use it and continue'));
|
||||
}
|
||||
});
|
||||
await test('missing compatibility metadata is not mislabeled v5 or a known KJ error',async e=>{
|
||||
for(const field of ['sampling_contract_version','generation_reusable']){
|
||||
const p=project(1);for(const item of [...p.group_revisions,...p.revisions])delete item[field];
|
||||
const n=e.makeNode(field==='sampling_contract_version'?312:313);e.w(n,'generation_mode').value='Review Each Chunk';await e.load(n,p);
|
||||
assert.match(e.f.reviewStatus(n),/metadata is incomplete or unsupported/);
|
||||
assert.doesNotMatch(e.f.reviewStatus(n),/Sampling v5|Bypass KJ/);
|
||||
assert(!e.visible(n,'Use it and continue'));
|
||||
}
|
||||
});
|
||||
await test('unknown saved reasons do not expose paths or unbounded text',async e=>{
|
||||
const p=project(1);for(const item of [...p.group_revisions,...p.revisions]){
|
||||
item.generation_reusable=false;item.resume_disabled_reasons=Array(20).fill('C:/Users/private/file.py'+'x'.repeat(10000));
|
||||
}
|
||||
const n=e.makeNode();e.w(n,'generation_mode').value='Review Each Chunk';await e.load(n,p);
|
||||
const text=e.f.reviewStatus(n);assert.match(text,/Detailed Report/);
|
||||
assert.doesNotMatch(text,/private|file.py/);assert(text.length<1500);
|
||||
});
|
||||
await test('history reasons follow the selected Take rather than the canonical revision',async e=>{
|
||||
const p=project(2),vae='KJ preview VAE/Audio VAE or Tiny VAE is outside the supported configuration';
|
||||
const core='Core approximate-VAE preview is outside the supported configuration';
|
||||
for(const item of [...p.group_revisions,...p.revisions])item.generation_reusable=false;
|
||||
p.group_revisions[0].resume_disabled_reasons=[vae];p.group_revisions[1].resume_disabled_reasons=[core];
|
||||
p.revisions[0].resume_disabled_reasons=[core];
|
||||
const n=e.makeNode();e.w(n,'generation_mode').value='Review Each Chunk';await e.load(n,p);e.f.selectTakeOffset(n,-1);
|
||||
const text=e.w(n,'Render History / Takes').value;
|
||||
assert.match(text,/Keep the generation VAEs connected/);assert.doesNotMatch(text,/Auto or Latent2RGB/);
|
||||
});
|
||||
await test('saved compatibility metadata controls Review with optional real backend vectors',async e=>{
|
||||
const configured=process.env.H3_READONLY_PROJECT_VECTORS;
|
||||
const p=project(1);p.revisions[0].resume_disabled_reasons=['KJ preview runtime code or state could not be verified'];
|
||||
const vectors=configured?JSON.parse(fs.readFileSync(configured,'utf8')):[{project:p,reusable:true}];
|
||||
assert(vectors.length>0);
|
||||
for(const [index,vector] of vectors.entries()){
|
||||
const n=e.makeNode(800+index,vector.project.run_name);e.w(n,'generation_mode').value='Review Each Chunk';await e.load(n,vector.project);
|
||||
assert.equal(e.visible(n,'Use it and continue'),vector.reusable,e.f.reviewStatus(n));
|
||||
if(vector.reason)assert(e.f.reviewStatus(n).includes(vector.reason));
|
||||
if(vector.reusable)assert.doesNotMatch(e.f.reviewStatus(n),/read-only|could not be verified/);
|
||||
}
|
||||
});
|
||||
|
||||
// Persisted explicit requests must survive Core's graph-restoration lifecycle.
|
||||
for(const nodeClass of ['H3ContinuumSamplerV38','H3ContinuumSamplerV39']) {
|
||||
for(const mode of ['Full Run','Review Each Chunk']) {
|
||||
for(const boundary of ['Chunk 1','Chunk 2']) {
|
||||
for(const nonce of [0,5]) {
|
||||
await test(`regenerate restore: ${nodeClass} ${mode} ${boundary} nonce ${nonce}`,async e=>{
|
||||
const n=e.makeNode(312,'fixture',nodeClass);await e.load(n,project(3,3));
|
||||
e.w(n,'generation_mode').value=mode;
|
||||
e.w(n,'reroll_from_chunk').value=boundary;e.w(n,'reroll_from_chunk').callback?.(boundary);
|
||||
e.w(n,'reroll_nonce').value=nonce;
|
||||
const info=JSON.parse(JSON.stringify({properties:n.properties,...n.serialize()}));
|
||||
const beforeHistory=JSON.stringify(e.getSaved());
|
||||
n.onRemoved?.();e.app.graph._nodes=[];e.app.extension.beforeConfigureGraph?.();
|
||||
const loaded=e.makeNode(312,'',nodeClass,false);e.app.extension.nodeCreated(loaded);
|
||||
loaded.properties=info.properties;loaded.configure(info);
|
||||
e.app.extension.loadedGraphNode(loaded);await e.finishRestore();
|
||||
assert.equal(e.w(loaded,'reroll_from_chunk').value,boundary);
|
||||
assert.equal(e.w(loaded,'reroll_nonce').value,nonce);
|
||||
await e.queue(loaded);const sent=e.submissions.at(-1).data.output['312'].inputs;
|
||||
assert.equal(sent.reroll_from_chunk,boundary);assert.equal(sent.reroll_nonce,nonce);
|
||||
assert.equal(sent.generation_mode,mode);assert.equal(sent.run_storage,'Save + Auto Resume');
|
||||
assert(!Object.hasOwn(sent,'h3_continuum_regenerate_from'));
|
||||
assert.equal(JSON.stringify(e.getSaved()),beforeHistory);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
for(const [boundary,nonce] of [['Chunk 2',0],['Chunk 1',5]]) {
|
||||
await test(`regenerate legacy: ${nodeClass} ${boundary} nonce ${nonce}`,async e=>{
|
||||
e.setSaved(project(3,3));e.app.extension.beforeConfigureGraph?.();
|
||||
const n=e.makeNode(312,'fixture',nodeClass,false);e.app.extension.nodeCreated(n);
|
||||
e.w(n,'generation_mode').value='Review Each Chunk';e.w(n,'reroll_from_chunk').value=boundary;
|
||||
e.w(n,'reroll_nonce').value=nonce;e.app.extension.loadedGraphNode(n);await e.finishRestore();
|
||||
assert.equal(e.w(n,'reroll_from_chunk').value,boundary);assert.equal(e.w(n,'reroll_nonce').value,nonce);
|
||||
e.w(n,'Run').callback('Review Each Chunk');
|
||||
await e.queue(n);assert.equal(e.submissions.at(-1).data.output['312'].inputs.reroll_from_chunk,boundary);
|
||||
assert.equal(e.submissions.at(-1).data.output['312'].inputs.reroll_nonce,nonce);
|
||||
});
|
||||
}
|
||||
await test(`regenerate intent reset: ${nodeClass}`,async e=>{
|
||||
const n=e.makeNode(312,'fixture',nodeClass);await e.load(n,project(1));
|
||||
e.w(n,'reroll_from_chunk').value='Chunk 1';e.w(n,'reroll_from_chunk').callback?.('Chunk 1');
|
||||
assert.equal(n.properties.h3_continuum_regenerate_from,'Chunk 1');
|
||||
e.w(n,'reroll_from_chunk').value='Auto';e.w(n,'reroll_from_chunk').callback?.('Auto');
|
||||
assert(!Object.hasOwn(n.properties,'h3_continuum_regenerate_from'));
|
||||
e.w(n,'Start again from Chunk 1').callback();await e.queue(n);
|
||||
assert.equal(e.w(n,'reroll_from_chunk').value,'Auto');
|
||||
assert(!Object.hasOwn(n.properties,'h3_continuum_regenerate_from'));
|
||||
});
|
||||
}
|
||||
|
||||
console.log(JSON.stringify(results,null,2));if(results.some(r=>!r.pass))process.exitCode=1;
|
||||
})();
|
||||
@@ -0,0 +1,128 @@
|
||||
import assert from "node:assert/strict";
|
||||
import fs from "node:fs";
|
||||
import vm from "node:vm";
|
||||
|
||||
class Element extends EventTarget {
|
||||
constructor(tag) { super(); this.tag = tag; this.children = []; this.style = {}; this.dataset = {}; this.attributes = {}; this.value = ""; this.disabled = false; this.textContent = ""; }
|
||||
append(child) { child.parentElement = this; this.children.push(child); }
|
||||
replaceChildren() { for (const child of this.children) child.parentElement = null; this.children = []; }
|
||||
setAttribute(name, value) { this.attributes[name] = value; }
|
||||
get isConnected() { return this === document.body || !!this.parentElement?.isConnected; }
|
||||
closest() { let node = this; while (node) { if (node.tag === "dialog" || node.attributes.role === "dialog") return node; node = node.parentElement; } return null; }
|
||||
remove() { this.parentElement.children = this.parentElement.children.filter(x => x !== this); this.parentElement = null; }
|
||||
showModal() { this.open = true; }
|
||||
close() { this.open = false; this.dispatchEvent(new Event("close")); }
|
||||
focus() {}
|
||||
click() { if (!this.disabled) this.dispatchEvent(new Event("click")); }
|
||||
}
|
||||
const all = [];
|
||||
globalThis.document = { createElement: tag => { const e = new Element(tag); all.push(e); return e; }, body: new Element("body") };
|
||||
Object.defineProperty(globalThis, "navigator", { value: { language: "en" }, configurable: true });
|
||||
let definition;
|
||||
globalThis.__app = { ui: { settings: { getSettingValue: () => "en", addSetting: d => { definition = d; } } }, registerExtension: d => d.setup() };
|
||||
const api = globalThis.__api = new EventTarget();
|
||||
const requests = [];
|
||||
let responseMode = "normal";
|
||||
let state = { path: "", revision: 0, busy: false, read_only: false, memory: { available_bytes: 8 * 1024 ** 3 }, roots: [], volumes: [], last_backend: null };
|
||||
api.fetchApi = async (path, options) => {
|
||||
const action = path.split("/").at(-1);
|
||||
const body = options.body ? JSON.parse(options.body) : undefined;
|
||||
requests.push({ action, body, path, options });
|
||||
if (responseMode === "network") throw new TypeError("fetch failed");
|
||||
if (responseMode === "both404") return new Response("", { status: 404 });
|
||||
if (responseMode === "empty200") return new Response("", { status: 200 });
|
||||
if (responseMode === "empty403") return new Response("", { status: 403 });
|
||||
if (responseMode === "empty500") return new Response("", { status: 500 });
|
||||
if (responseMode === "html") return new Response("<!doctype html><title>ComfyUI</title>", { status: 200 });
|
||||
if (responseMode === "schema") return Response.json({});
|
||||
if (responseMode === "cleanupEmpty" && action === "cleanup") return new Response("", { status: 200 });
|
||||
let value = structuredClone(state), ok = true;
|
||||
if (action === "settings") { assert.equal(body.revision, state.revision); state = { ...state, path: body.path, revision: state.revision + 1 }; value = state; }
|
||||
if (action === "validate") {
|
||||
ok = !body.path || body.path.startsWith("/");
|
||||
value = ok ? { path: body.path, roots: [{ free_bytes: 10 * 1024 ** 3 }] } : { error: "absolute path required" };
|
||||
}
|
||||
if (action === "cleanup") { assert.deepEqual(body, {}); value = { roots: [] }; }
|
||||
return Response.json(value, { status: ok ? 200 : 400 });
|
||||
};
|
||||
|
||||
const source = fs.readFileSync(new URL("../web/storage_settings.js", import.meta.url), "utf8")
|
||||
.replace('import { app } from "../../scripts/app.js";', "const app = globalThis.__app;")
|
||||
.replace('import { api } from "../../scripts/api.js";', "const api = globalThis.__api;")
|
||||
.replace("export function openStorageDialog", "function openStorageDialog");
|
||||
vm.runInThisContext(source);
|
||||
const settings = new Element("section"); settings.setAttribute("role", "dialog"); document.body.append(settings);
|
||||
const row = definition.type(); settings.append(row);
|
||||
const launch = row.children[0].children[0];
|
||||
const connected = tag => all.filter(x => x.tag === tag && x.isConnected);
|
||||
const dialog = () => connected("dialog")[0];
|
||||
const control = name => all.find(x => x.tag === "button" && x.isConnected && x.textContent === name);
|
||||
const settle = () => new Promise(resolve => setImmediate(resolve));
|
||||
|
||||
launch.click(); await settle();
|
||||
assert.equal(dialog().parentElement, settings, "preserve Core's settings dialog during native-modal interactions");
|
||||
assert.equal(connected("input")[0].value, "");
|
||||
assert.equal(requests.filter(r => r.action === "status").length, 1);
|
||||
launch.click(); assert.equal(connected("dialog").length, 1, "no duplicate modal");
|
||||
const input = connected("input")[0];
|
||||
input.value = "relative"; input.dispatchEvent(new Event("input"));
|
||||
control("Validate").click(); await settle();
|
||||
assert.ok(all.some(x => x.isConnected && x.textContent === "absolute path required"));
|
||||
input.value = "/scratch"; input.dispatchEvent(new Event("input"));
|
||||
control("Save").click(); control("Save").click(); await settle();
|
||||
assert.equal(requests.filter(r => r.action === "settings").length, 1, "one save while request is pending");
|
||||
assert.equal(state.path, "/scratch");
|
||||
const status = new Event("status"); status.detail = { exec_info: { queue_remaining: 1 } }; api.dispatchEvent(status);
|
||||
assert.equal(control("Save").disabled, true);
|
||||
assert.equal(control("Delete unused temporary files").disabled, true);
|
||||
status.detail.exec_info.queue_remaining = 0; api.dispatchEvent(status);
|
||||
control("Delete unused temporary files").click(); await settle();
|
||||
assert.equal(requests.filter(r => r.action === "cleanup").length, 1);
|
||||
control("Close").click(); assert.equal(connected("dialog").length, 0);
|
||||
const before = requests.length;
|
||||
for (let n = 0; n < 100; n++) {
|
||||
launch.click(); await settle();
|
||||
assert.equal(connected("input")[0].value, "/scratch");
|
||||
control("Close").click();
|
||||
}
|
||||
await settle();
|
||||
assert.equal(requests.length - before, 100, "one fetch per open and no periodic polling");
|
||||
assert.equal(connected("dialog").length, 0);
|
||||
// A disposed dialog's handler must not receive later status events.
|
||||
api.dispatchEvent(status);
|
||||
assert.equal(requests.length - before, 100);
|
||||
state.read_only = true;
|
||||
launch.click(); await settle();
|
||||
assert.equal(control("Save").disabled, true);
|
||||
assert.equal(control("Delete unused temporary files").disabled, true);
|
||||
assert.equal(connected("input")[0].disabled, true);
|
||||
control("Close").click();
|
||||
state.read_only = false;
|
||||
for (const [mode, text, count] of [["both404", "HTTP 404", 1], ["empty403", "HTTP 403", 1],
|
||||
["empty500", "HTTP 500", 1], ["empty200", "HTTP 200", 1], ["html", "HTTP 200", 1],
|
||||
["schema", "HTTP 200", 1], ["network", "current address", 1]]) {
|
||||
responseMode = mode;
|
||||
const before = requests.length;
|
||||
launch.click(); await settle();
|
||||
assert.equal(requests.length - before, count, mode);
|
||||
assert.ok(all.some(x => x.isConnected && x.attributes.role === "status" && x.textContent.includes(text)), mode);
|
||||
assert.equal(connected("input")[0].disabled, true, "no mutations with unavailable status");
|
||||
assert.equal(control("Save").disabled, true);
|
||||
assert.equal(connected("select")[0].disabled, true);
|
||||
assert.ok(connected("select")[0].children[0].textContent.includes("Refresh"));
|
||||
assert.equal(control("Refresh").disabled, false, "manual recovery stays available");
|
||||
responseMode = "normal";
|
||||
control("Refresh").click(); await settle();
|
||||
assert.equal(control("Save").disabled, false, "recover without reloading the browser");
|
||||
control("Close").click();
|
||||
}
|
||||
// A successful save/cleanup with an empty response must never be replayed.
|
||||
responseMode = "normal"; launch.click(); await settle();
|
||||
responseMode = "cleanupEmpty";
|
||||
const beforeCleanup = requests.length;
|
||||
control("Delete unused temporary files").click(); await settle();
|
||||
assert.equal(requests.length - beforeCleanup, 1, "never retry a mutating request");
|
||||
assert.ok(all.some(x => x.isConnected && x.attributes.role === "status" && x.textContent.includes("HTTP 200")));
|
||||
control("Close").click();
|
||||
console.log("Temporary storage frontend: settings nesting, deduplication, errors, save, busy/read-only gates, cleanup, and 100 reopen cycles passed");
|
||||
console.log("Empty/invalid HTTP responses, recovery, and no POST replay passed");
|
||||
@@ -0,0 +1,165 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import importlib.util
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import sys
|
||||
import time
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
PACKAGE_NAME = "ComfyUI_H3_Continuum_Join"
|
||||
if PACKAGE_NAME not in sys.modules:
|
||||
spec = importlib.util.spec_from_file_location(
|
||||
PACKAGE_NAME,
|
||||
ROOT / "__init__.py",
|
||||
submodule_search_locations=[str(ROOT)],
|
||||
)
|
||||
package = importlib.util.module_from_spec(spec)
|
||||
package.__path__ = [str(ROOT)]
|
||||
sys.modules[PACKAGE_NAME] = package
|
||||
|
||||
import ComfyUI_H3_Continuum_Join.run_storage as storage_runtime
|
||||
|
||||
|
||||
def _load_storage_cases():
|
||||
path = ROOT / "tests" / "test_v38_review_run_storage.py"
|
||||
spec = importlib.util.spec_from_file_location("r5_worker_storage_cases", path)
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
sys.modules[spec.name] = module
|
||||
spec.loader.exec_module(module)
|
||||
return module
|
||||
|
||||
|
||||
def main() -> None:
|
||||
scenario_root = Path(sys.argv[1]).resolve()
|
||||
stage = sys.argv[2]
|
||||
scenario_root.mkdir(parents=True, exist_ok=True)
|
||||
signal = scenario_root / "reached.json"
|
||||
|
||||
def reached() -> None:
|
||||
signal.write_text(
|
||||
json.dumps({"stage": stage, "pid": os.getpid()}),
|
||||
encoding="utf-8",
|
||||
)
|
||||
while True:
|
||||
time.sleep(1)
|
||||
|
||||
cases = _load_storage_cases()
|
||||
contract = cases._contract(chunks=2, terminal=True)
|
||||
controller = cases._controller(scenario_root, contract)
|
||||
controller.revision_root.mkdir(parents=True, exist_ok=True)
|
||||
controller._write_manifest()
|
||||
entries = (cases._entry(0, contract), cases._entry(1, contract))
|
||||
|
||||
if stage == "raw_before":
|
||||
reached()
|
||||
|
||||
if stage == "raw_mid":
|
||||
def partial_save(tensors, filename, *, metadata):
|
||||
with open(filename, "wb") as handle:
|
||||
handle.write(b"partial-r5-raw")
|
||||
handle.flush()
|
||||
os.fsync(handle.fileno())
|
||||
reached()
|
||||
|
||||
storage_runtime.save_file = partial_save
|
||||
|
||||
if stage == "first_raw_done":
|
||||
original_hash = storage_runtime._file_sha256
|
||||
hash_calls = 0
|
||||
|
||||
def observed_hash(path):
|
||||
nonlocal hash_calls
|
||||
value = original_hash(path)
|
||||
hash_calls += 1
|
||||
if hash_calls == 2:
|
||||
reached()
|
||||
return value
|
||||
|
||||
storage_runtime._file_sha256 = observed_hash
|
||||
|
||||
if stage == "before_manifest":
|
||||
original_write_manifest = controller._write_manifest
|
||||
|
||||
def before_manifest():
|
||||
reached()
|
||||
return original_write_manifest()
|
||||
|
||||
controller._write_manifest = before_manifest
|
||||
|
||||
if stage == "manifest_temp_mid":
|
||||
def partial_json_dump(payload, handle, **kwargs):
|
||||
handle.write('{"partial":')
|
||||
handle.flush()
|
||||
os.fsync(handle.fileno())
|
||||
reached()
|
||||
|
||||
storage_runtime.json.dump = partial_json_dump
|
||||
|
||||
if stage in {"before_replace", "after_replace"}:
|
||||
original_replace = storage_runtime._replace_json_atomically
|
||||
|
||||
def observed_replace(temporary, destination):
|
||||
if Path(destination).name != "manifest.json":
|
||||
return original_replace(temporary, destination)
|
||||
if stage == "before_replace":
|
||||
reached()
|
||||
result = original_replace(temporary, destination)
|
||||
reached()
|
||||
return result
|
||||
|
||||
storage_runtime._replace_json_atomically = observed_replace
|
||||
|
||||
if stage == "after_directory_durability":
|
||||
original_fsync_dir = storage_runtime._fsync_dir
|
||||
|
||||
def observed_fsync_dir(path):
|
||||
result = original_fsync_dir(path)
|
||||
if Path(path).resolve() == controller.revision_root.resolve():
|
||||
reached()
|
||||
return result
|
||||
|
||||
storage_runtime._fsync_dir = observed_fsync_dir
|
||||
|
||||
controller.commit_group(entries, positions=(0, 1))
|
||||
|
||||
if stage in {"finalize_manifest_1", "finalize_manifest_2"}:
|
||||
original_finalize_write = controller._write_manifest
|
||||
finalize_writes = 0
|
||||
|
||||
def observed_finalize_write():
|
||||
nonlocal finalize_writes
|
||||
result = original_finalize_write()
|
||||
finalize_writes += 1
|
||||
expected = 1 if stage == "finalize_manifest_1" else 2
|
||||
if finalize_writes == expected:
|
||||
reached()
|
||||
return result
|
||||
|
||||
controller._write_manifest = observed_finalize_write
|
||||
|
||||
if stage in {"project_before_replace", "project_after_replace"}:
|
||||
original_project_replace = storage_runtime._replace_json_atomically
|
||||
|
||||
def observed_project_replace(temporary, destination):
|
||||
if Path(destination).name != "project.json":
|
||||
return original_project_replace(temporary, destination)
|
||||
if stage == "project_before_replace":
|
||||
reached()
|
||||
result = original_project_replace(temporary, destination)
|
||||
reached()
|
||||
return result
|
||||
|
||||
storage_runtime._replace_json_atomically = observed_project_replace
|
||||
|
||||
controller.finalize(
|
||||
session={"session_id": "r5-crash-worker", "chunks": list(entries)},
|
||||
report="r5 process crash fixture",
|
||||
)
|
||||
raise RuntimeError(f"stage did not block: {stage}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,378 @@
|
||||
"""Tests-only capture and comparison helpers for Terminal Merge diagnostics.
|
||||
|
||||
This module deliberately has no production imports or runtime hooks. Tests can
|
||||
monkeypatch Core and Continuum boundaries, feed the captured values here, and
|
||||
identify the first pipeline stage that differs without changing generation
|
||||
semantics.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass
|
||||
from enum import Enum
|
||||
from hashlib import sha256
|
||||
import json
|
||||
from pathlib import Path
|
||||
from typing import Any, Mapping
|
||||
|
||||
import torch
|
||||
|
||||
|
||||
STAGE_ORDER = (
|
||||
"A_pre_sampler",
|
||||
"B_first_model_call",
|
||||
"C_sampled_physical_av",
|
||||
"D_split_recombine",
|
||||
"E_decode_assembly",
|
||||
)
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class TensorFingerprint:
|
||||
shape: tuple[int, ...]
|
||||
dtype: str
|
||||
sha256: str
|
||||
|
||||
def as_dict(self) -> dict[str, Any]:
|
||||
return {
|
||||
"shape": list(self.shape),
|
||||
"dtype": self.dtype,
|
||||
"sha256": self.sha256,
|
||||
}
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class TensorDifference:
|
||||
same_shape: bool
|
||||
same_dtype: bool
|
||||
bit_exact: bool
|
||||
allclose: bool
|
||||
max_abs_diff: float | None
|
||||
mean_abs_diff: float | None
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class StageSnapshot:
|
||||
name: str
|
||||
sha256: str
|
||||
payload: Any
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class StageComparison:
|
||||
name: str
|
||||
equal: bool
|
||||
core_sha256: str | None
|
||||
continuum_sha256: str | None
|
||||
missing_from: str | None = None
|
||||
|
||||
|
||||
def _tensor_raw_bytes(tensor: torch.Tensor) -> bytes:
|
||||
value = tensor.detach().to("cpu").contiguous()
|
||||
if value.numel() == 0:
|
||||
return b""
|
||||
return value.reshape(-1).view(torch.uint8).numpy().tobytes()
|
||||
|
||||
|
||||
def tensor_fingerprint(tensor: torch.Tensor) -> TensorFingerprint:
|
||||
if not torch.is_tensor(tensor):
|
||||
raise TypeError("tensor_fingerprint expects a torch.Tensor")
|
||||
return TensorFingerprint(
|
||||
shape=tuple(int(size) for size in tensor.shape),
|
||||
dtype=str(tensor.dtype),
|
||||
sha256=sha256(_tensor_raw_bytes(tensor)).hexdigest(),
|
||||
)
|
||||
|
||||
|
||||
def tensor_difference(
|
||||
core: torch.Tensor,
|
||||
continuum: torch.Tensor,
|
||||
*,
|
||||
rtol: float = 1.0e-5,
|
||||
atol: float = 1.0e-6,
|
||||
) -> TensorDifference:
|
||||
if not torch.is_tensor(core) or not torch.is_tensor(continuum):
|
||||
raise TypeError("tensor_difference expects two torch.Tensor values")
|
||||
|
||||
same_shape = tuple(core.shape) == tuple(continuum.shape)
|
||||
same_dtype = core.dtype == continuum.dtype
|
||||
bit_exact = (
|
||||
same_shape
|
||||
and same_dtype
|
||||
and tensor_fingerprint(core).sha256 == tensor_fingerprint(continuum).sha256
|
||||
)
|
||||
if not same_shape:
|
||||
return TensorDifference(
|
||||
same_shape=False,
|
||||
same_dtype=same_dtype,
|
||||
bit_exact=False,
|
||||
allclose=False,
|
||||
max_abs_diff=None,
|
||||
mean_abs_diff=None,
|
||||
)
|
||||
|
||||
core_value = core.detach().to("cpu")
|
||||
continuum_value = continuum.detach().to("cpu")
|
||||
if core_value.is_complex() or continuum_value.is_complex():
|
||||
core_numeric = core_value.to(torch.complex128)
|
||||
continuum_numeric = continuum_value.to(torch.complex128)
|
||||
else:
|
||||
core_numeric = core_value.to(torch.float64)
|
||||
continuum_numeric = continuum_value.to(torch.float64)
|
||||
|
||||
if core_numeric.numel() == 0:
|
||||
max_abs_diff = 0.0
|
||||
mean_abs_diff = 0.0
|
||||
else:
|
||||
absolute = (core_numeric - continuum_numeric).abs()
|
||||
max_abs_diff = float(absolute.max().item())
|
||||
mean_abs_diff = float(absolute.mean().item())
|
||||
|
||||
return TensorDifference(
|
||||
same_shape=True,
|
||||
same_dtype=same_dtype,
|
||||
bit_exact=bit_exact,
|
||||
allclose=bool(
|
||||
torch.allclose(
|
||||
core_numeric,
|
||||
continuum_numeric,
|
||||
rtol=rtol,
|
||||
atol=atol,
|
||||
equal_nan=True,
|
||||
)
|
||||
),
|
||||
max_abs_diff=max_abs_diff,
|
||||
mean_abs_diff=mean_abs_diff,
|
||||
)
|
||||
|
||||
|
||||
def packed_layout_snapshot(layout: Any) -> dict[str, Any]:
|
||||
return {
|
||||
"signature": stable_snapshot(getattr(layout, "signature", None)),
|
||||
"segments": stable_snapshot(getattr(layout, "segments", None)),
|
||||
"position_ids": stable_snapshot(getattr(layout, "position_ids", None)),
|
||||
}
|
||||
|
||||
|
||||
def stable_snapshot(value: Any) -> Any:
|
||||
"""Convert diagnostic data to deterministic JSON-compatible state."""
|
||||
|
||||
if torch.is_tensor(value):
|
||||
return {"kind": "tensor", **tensor_fingerprint(value).as_dict()}
|
||||
if isinstance(value, TensorFingerprint):
|
||||
return {"kind": "tensor", **value.as_dict()}
|
||||
if value is None or isinstance(value, (bool, int, str)):
|
||||
return value
|
||||
if isinstance(value, float):
|
||||
return {"kind": "float", "hex": value.hex()}
|
||||
if isinstance(value, bytes):
|
||||
return {
|
||||
"kind": "bytes",
|
||||
"length": len(value),
|
||||
"sha256": sha256(value).hexdigest(),
|
||||
}
|
||||
if isinstance(value, (Path, torch.device, torch.dtype)):
|
||||
return str(value)
|
||||
if isinstance(value, Enum):
|
||||
return {
|
||||
"kind": "enum",
|
||||
"type": f"{type(value).__module__}.{type(value).__qualname__}",
|
||||
"value": stable_snapshot(value.value),
|
||||
}
|
||||
if isinstance(value, slice):
|
||||
return {
|
||||
"kind": "slice",
|
||||
"start": value.start,
|
||||
"stop": value.stop,
|
||||
"step": value.step,
|
||||
}
|
||||
if isinstance(value, Mapping):
|
||||
return {
|
||||
"kind": "mapping",
|
||||
"items": [
|
||||
[str(key), stable_snapshot(item)]
|
||||
for key, item in sorted(value.items(), key=lambda pair: str(pair[0]))
|
||||
],
|
||||
}
|
||||
if isinstance(value, tuple):
|
||||
return {"kind": "tuple", "items": [stable_snapshot(item) for item in value]}
|
||||
if isinstance(value, list):
|
||||
return {"kind": "list", "items": [stable_snapshot(item) for item in value]}
|
||||
if isinstance(value, (set, frozenset)):
|
||||
items = [stable_snapshot(item) for item in value]
|
||||
items.sort(key=lambda item: json.dumps(item, sort_keys=True, separators=(",", ":")))
|
||||
return {"kind": type(value).__name__, "items": items}
|
||||
if callable(value):
|
||||
return {
|
||||
"kind": "callable",
|
||||
"module": getattr(value, "__module__", type(value).__module__),
|
||||
"qualname": getattr(value, "__qualname__", type(value).__qualname__),
|
||||
}
|
||||
if all(hasattr(value, name) for name in ("signature", "segments", "position_ids")):
|
||||
return {"kind": "packed_layout", **packed_layout_snapshot(value)}
|
||||
if hasattr(value, "__dict__"):
|
||||
public_state = {
|
||||
key: item
|
||||
for key, item in vars(value).items()
|
||||
if not key.startswith("_") and not callable(item)
|
||||
}
|
||||
return {
|
||||
"kind": "object",
|
||||
"type": f"{type(value).__module__}.{type(value).__qualname__}",
|
||||
"state": stable_snapshot(public_state),
|
||||
}
|
||||
raise TypeError(f"Unsupported diagnostic value: {type(value)!r}")
|
||||
|
||||
|
||||
def snapshot_sha256(payload: Any) -> str:
|
||||
normalized = stable_snapshot(payload)
|
||||
encoded = json.dumps(
|
||||
normalized,
|
||||
ensure_ascii=True,
|
||||
sort_keys=True,
|
||||
separators=(",", ":"),
|
||||
).encode("utf-8")
|
||||
return sha256(encoded).hexdigest()
|
||||
|
||||
|
||||
class DiagnosticCapture:
|
||||
def __init__(self) -> None:
|
||||
self._stages: dict[str, StageSnapshot] = {}
|
||||
|
||||
@property
|
||||
def stages(self) -> Mapping[str, StageSnapshot]:
|
||||
return self._stages
|
||||
|
||||
def capture(self, stage: str, **payload: Any) -> StageSnapshot:
|
||||
if stage not in STAGE_ORDER:
|
||||
raise ValueError(f"Unknown diagnostic stage: {stage}")
|
||||
if stage in self._stages:
|
||||
raise ValueError(f"Diagnostic stage already captured: {stage}")
|
||||
normalized = stable_snapshot(payload)
|
||||
snapshot = StageSnapshot(
|
||||
name=stage,
|
||||
sha256=snapshot_sha256(normalized),
|
||||
payload=normalized,
|
||||
)
|
||||
self._stages[stage] = snapshot
|
||||
return snapshot
|
||||
|
||||
def capture_pre_sampler(
|
||||
self,
|
||||
*,
|
||||
physical_frames: int,
|
||||
seed: int,
|
||||
conditioning: Any,
|
||||
latent: Any,
|
||||
noise: torch.Tensor,
|
||||
keyframes: Any = None,
|
||||
qwen_images: Any = None,
|
||||
minimax_refs: Any = None,
|
||||
) -> StageSnapshot:
|
||||
return self.capture(
|
||||
"A_pre_sampler",
|
||||
physical_frames=physical_frames,
|
||||
seed=seed,
|
||||
conditioning=conditioning,
|
||||
latent=latent,
|
||||
noise=noise,
|
||||
keyframes=keyframes,
|
||||
qwen_images=qwen_images,
|
||||
minimax_refs=minimax_refs,
|
||||
)
|
||||
|
||||
def capture_first_model_call(
|
||||
self,
|
||||
*,
|
||||
minimax_payload: Any,
|
||||
transformer_options: Any,
|
||||
) -> StageSnapshot:
|
||||
return self.capture(
|
||||
"B_first_model_call",
|
||||
minimax_payload=minimax_payload,
|
||||
transformer_options=transformer_options,
|
||||
)
|
||||
|
||||
def capture_sampled_physical_av(
|
||||
self,
|
||||
*,
|
||||
video: torch.Tensor,
|
||||
audio: torch.Tensor,
|
||||
) -> StageSnapshot:
|
||||
return self.capture(
|
||||
"C_sampled_physical_av",
|
||||
video=video,
|
||||
audio=audio,
|
||||
)
|
||||
|
||||
def capture_split_recombine(
|
||||
self,
|
||||
*,
|
||||
physical_video: torch.Tensor,
|
||||
physical_audio: torch.Tensor,
|
||||
recombined_video: torch.Tensor,
|
||||
recombined_audio: torch.Tensor,
|
||||
) -> StageSnapshot:
|
||||
return self.capture(
|
||||
"D_split_recombine",
|
||||
physical_video=physical_video,
|
||||
physical_audio=physical_audio,
|
||||
recombined_video=recombined_video,
|
||||
recombined_audio=recombined_audio,
|
||||
video_difference=tensor_difference(physical_video, recombined_video).__dict__,
|
||||
audio_difference=tensor_difference(physical_audio, recombined_audio).__dict__,
|
||||
)
|
||||
|
||||
def capture_decode_assembly(
|
||||
self,
|
||||
*,
|
||||
physical_decoded: torch.Tensor,
|
||||
assembled_decoded: torch.Tensor,
|
||||
) -> StageSnapshot:
|
||||
return self.capture(
|
||||
"E_decode_assembly",
|
||||
physical_decoded=physical_decoded,
|
||||
assembled_decoded=assembled_decoded,
|
||||
difference=tensor_difference(physical_decoded, assembled_decoded).__dict__,
|
||||
)
|
||||
|
||||
|
||||
def compare_captures(
|
||||
core: DiagnosticCapture,
|
||||
continuum: DiagnosticCapture,
|
||||
) -> tuple[StageComparison, ...]:
|
||||
comparisons = []
|
||||
for stage in STAGE_ORDER:
|
||||
core_stage = core.stages.get(stage)
|
||||
continuum_stage = continuum.stages.get(stage)
|
||||
missing = None
|
||||
if core_stage is None and continuum_stage is None:
|
||||
missing = "both"
|
||||
elif core_stage is None:
|
||||
missing = "core"
|
||||
elif continuum_stage is None:
|
||||
missing = "continuum"
|
||||
comparisons.append(
|
||||
StageComparison(
|
||||
name=stage,
|
||||
equal=(
|
||||
core_stage is not None
|
||||
and continuum_stage is not None
|
||||
and core_stage.sha256 == continuum_stage.sha256
|
||||
),
|
||||
core_sha256=None if core_stage is None else core_stage.sha256,
|
||||
continuum_sha256=None if continuum_stage is None else continuum_stage.sha256,
|
||||
missing_from=missing,
|
||||
)
|
||||
)
|
||||
return tuple(comparisons)
|
||||
|
||||
|
||||
def first_divergent_stage(
|
||||
core: DiagnosticCapture,
|
||||
continuum: DiagnosticCapture,
|
||||
) -> str | None:
|
||||
for comparison in compare_captures(core, continuum):
|
||||
if not comparison.equal:
|
||||
return comparison.name
|
||||
return None
|
||||
@@ -0,0 +1,227 @@
|
||||
from collections.abc import Mapping
|
||||
import copy
|
||||
import json
|
||||
|
||||
import pytest
|
||||
import torch
|
||||
|
||||
from ComfyUI_H3_Continuum_Join.graph_contract import build_upstream_graph_contract
|
||||
from ComfyUI_H3_Continuum_Join.v2.prompts import make_prompt_plan
|
||||
from ComfyUI_H3_Continuum_Join.v2.session import make_session
|
||||
from ComfyUI_H3_Continuum_Join.constants import PROMPT_MODE_LIST
|
||||
from . import test_v38_review_execution_cap as cap
|
||||
from .test_v36_masked_video_prefix import _install_nested_tensor
|
||||
from .test_v35_context_sampler import _capture_sequence
|
||||
from .test_v31_run_storage import _controller
|
||||
|
||||
|
||||
def test_v3_reference_video_imports_the_shared_temporal_helper():
|
||||
from ComfyUI_H3_Continuum_Join.temporal import align_frame_count_up as shared
|
||||
from ComfyUI_H3_Continuum_Join.v3.reference_video import align_frame_count_up
|
||||
|
||||
assert align_frame_count_up is shared
|
||||
|
||||
|
||||
def test_reference_bundle_fingerprint_ignores_unused_legacy_vae():
|
||||
graph = {
|
||||
"1": {"class_type": "H3ContinuumSamplerV38", "inputs": {
|
||||
"model": ["2", 0], "clip": ["3", 0], "sampler": ["8", 0],
|
||||
"audio_references": ["4", 0], "reference_audio_vae": ["5", 0]}},
|
||||
"2": {"class_type": "UNETLoader", "inputs": {"unet_name": "model"}},
|
||||
"3": {"class_type": "CLIPLoader", "inputs": {"clip_name": "clip"}},
|
||||
"4": {"class_type": "H3ContinuumReferenceAudios", "inputs": {
|
||||
"reference_audio_vae": ["6", 0], "reference_audio_1": ["7", 0]}},
|
||||
"5": {"class_type": "VAELoader", "inputs": {"vae_name": "unused"}},
|
||||
"6": {"class_type": "VAELoader", "inputs": {"vae_name": "active"}},
|
||||
"7": {"class_type": "LoadAudio", "inputs": {"audio": "voice.wav"}},
|
||||
"8": {"class_type": "KSamplerSelect", "inputs": {"sampler_name": "euler"}},
|
||||
}
|
||||
|
||||
def contract(value):
|
||||
result, safe, _ = build_upstream_graph_contract(
|
||||
value, "1", require_video_vae=False, require_reference_audio_vae=True)
|
||||
assert safe
|
||||
return result
|
||||
|
||||
original = contract(graph)
|
||||
assert original["routes"]["reference_audio_vae"]["node"]["node_id"] == "4"
|
||||
active = copy.deepcopy(graph)
|
||||
active["6"]["inputs"]["vae_name"] = "new-active"
|
||||
assert contract(active)["sha256"] != original["sha256"]
|
||||
unused = copy.deepcopy(graph)
|
||||
unused["5"]["inputs"]["vae_name"] = "new-unused"
|
||||
assert contract(unused) == original
|
||||
legacy = copy.deepcopy(graph)
|
||||
del legacy["1"]["inputs"]["audio_references"]
|
||||
assert contract(legacy)["routes"]["reference_audio_vae"]["node"]["node_id"] == "5"
|
||||
|
||||
# A connected but empty bundle can return None; execution then uses legacy
|
||||
# audio. Run Storage supplies this resolved route, not just graph priority.
|
||||
resolved, safe, _ = build_upstream_graph_contract(
|
||||
graph, "1", require_video_vae=False, require_reference_audio_vae=True,
|
||||
reference_audio_route="reference_audio_vae")
|
||||
assert safe
|
||||
assert resolved["routes"]["reference_audio_vae"]["node"]["node_id"] == "5"
|
||||
|
||||
|
||||
def assert_nested_equal(actual, expected):
|
||||
if torch.is_tensor(expected):
|
||||
torch.testing.assert_close(actual, expected, rtol=0, atol=0)
|
||||
elif isinstance(expected, Mapping):
|
||||
assert actual.keys() == expected.keys()
|
||||
for key in expected:
|
||||
assert_nested_equal(actual[key], expected[key])
|
||||
elif isinstance(expected, (tuple, list)):
|
||||
assert len(actual) == len(expected)
|
||||
for a, b in zip(actual, expected, strict=True):
|
||||
assert_nested_equal(a, b)
|
||||
else:
|
||||
assert actual == expected
|
||||
|
||||
|
||||
@pytest.mark.parametrize("transport", ["reference_context_v1", "masked_av_prefix_22_v1", "masked_video_prefix_v1"])
|
||||
@pytest.mark.parametrize("anchors", ["none", "first", "first_last"])
|
||||
@pytest.mark.parametrize("chunks", [1, 3, 6])
|
||||
def test_review_and_complete_reuse_preserve_full_refine_context(monkeypatch, transport, anchors, chunks):
|
||||
_install_nested_tensor(monkeypatch)
|
||||
first = torch.zeros(1, 64, 96, 3) if anchors != "none" else None
|
||||
last = torch.ones(1, 64, 96, 3) if anchors == "first_last" else None
|
||||
runtime = cap._install_fake_runtime(monkeypatch, first_frame=first, last_frame=last)
|
||||
real = cap.sequence.run_sequence
|
||||
|
||||
def run(**kwargs):
|
||||
kwargs["continuation_transport"] = transport
|
||||
return real(**kwargs)
|
||||
|
||||
monkeypatch.setattr(cap.sequence, "run_sequence", run)
|
||||
options = dict(chunks=chunks, first_frame=first, last_frame=last, capture_refine_context=True)
|
||||
full = cap._run_sequence(runtime, **options)
|
||||
assert full[4]["complete"]
|
||||
expected_sample_count = len(runtime.samples)
|
||||
runtime.samples.clear()
|
||||
session = None
|
||||
for _ in range(chunks):
|
||||
before = len(runtime.samples)
|
||||
reviewed = cap._run_sequence(runtime, **options, limit=1, session=session)
|
||||
session = reviewed[2]
|
||||
assert len(runtime.samples) - before == 1
|
||||
if len(reviewed[0]) == chunks:
|
||||
break
|
||||
assert not reviewed[4]["complete"]
|
||||
assert len(runtime.samples) == expected_sample_count
|
||||
cap._assert_entry_parity(reviewed[0], full[0])
|
||||
assert reviewed[4]["complete"]
|
||||
assert_nested_equal(reviewed[4], full[4])
|
||||
runtime.samples.clear()
|
||||
reused = cap._run_sequence(runtime, **options, session=session)
|
||||
assert runtime.samples == []
|
||||
cap._assert_entry_parity(reused[0], full[0])
|
||||
assert_nested_equal(reused[4], full[4])
|
||||
|
||||
|
||||
def test_review_does_not_encode_future_prompts(monkeypatch):
|
||||
runtime = cap._install_fake_runtime(monkeypatch)
|
||||
real = cap.sequence.run_sequence
|
||||
encoded = []
|
||||
encoder = runtime.clip.encode_from_tokens_scheduled
|
||||
monkeypatch.setattr(runtime.clip, "encode_from_tokens_scheduled",
|
||||
lambda prompt: (encoded.append(prompt), encoder(prompt))[1])
|
||||
|
||||
def run(**kwargs):
|
||||
kwargs["prompt_plan"] = make_prompt_plan(
|
||||
mode=PROMPT_MODE_LIST, script=json.dumps([f"action {i}" for i in range(6)]),
|
||||
chunks=6, chunk_seconds=5.0)
|
||||
return real(**kwargs)
|
||||
|
||||
monkeypatch.setattr(cap.sequence, "run_sequence", run)
|
||||
cap._run_sequence(runtime, chunks=6, limit=1, capture_refine_context=True)
|
||||
assert len(runtime.samples) == 1
|
||||
assert encoded == ["action 0"]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("transport", ["reference_context_v1", "masked_av_prefix_22_v1", "masked_video_prefix_v1"])
|
||||
@pytest.mark.parametrize("terminal", [False, True])
|
||||
@pytest.mark.parametrize("image,audio", [(True, False), (False, True), (True, True)])
|
||||
def test_review_reconstructs_reference_conditions(monkeypatch, transport, terminal, image, audio):
|
||||
real = cap.sequence.run_sequence
|
||||
state = {"limit": None, "samples": 0}
|
||||
|
||||
def run(**kwargs):
|
||||
sample = cap.sequence.sample_chunk
|
||||
|
||||
def counted(**sample_kwargs):
|
||||
state["samples"] += 1
|
||||
return sample(**sample_kwargs)
|
||||
|
||||
monkeypatch.setattr(cap.sequence, "sample_chunk", counted)
|
||||
kwargs["max_new_physical_groups"] = state["limit"]
|
||||
return real(**kwargs)
|
||||
|
||||
monkeypatch.setattr(cap.sequence, "run_sequence", run)
|
||||
options = dict(terminal=terminal, reference_image=image, reference_audio=audio,
|
||||
continuation_transport=transport)
|
||||
full = _capture_sequence(monkeypatch, **options)
|
||||
assert state["samples"] == 2
|
||||
state.update(limit=1, samples=0)
|
||||
first = _capture_sequence(monkeypatch, **options)
|
||||
assert state["samples"] == 1
|
||||
assert not first[4]["complete"]
|
||||
final = _capture_sequence(monkeypatch, **options, session=first[2])
|
||||
assert state["samples"] == 2
|
||||
assert_nested_equal(final[4], full[4])
|
||||
state.update(limit=None, samples=0)
|
||||
reused = _capture_sequence(monkeypatch, **options, session=final[2])
|
||||
assert state["samples"] == 0
|
||||
assert_nested_equal(reused[4], full[4])
|
||||
|
||||
|
||||
def test_full_reuse_without_refine_capture_does_not_encode_or_sample(monkeypatch):
|
||||
runtime = cap._install_fake_runtime(monkeypatch)
|
||||
full = cap._run_sequence(runtime, chunks=3)
|
||||
runtime.samples.clear()
|
||||
|
||||
def unexpected(*args, **kwargs):
|
||||
pytest.fail("Full reuse without refine capture must not encode or sample")
|
||||
|
||||
monkeypatch.setattr(cap.sequence, "encode_identity_latents", unexpected)
|
||||
monkeypatch.setattr(runtime.clip, "encode_from_tokens_scheduled", unexpected)
|
||||
monkeypatch.setattr(cap.sequence, "sample_chunk", unexpected)
|
||||
reused = cap._run_sequence(runtime, chunks=3, session=full[2])
|
||||
assert len(reused) == 4
|
||||
cap._assert_entry_parity(reused[0], full[0])
|
||||
|
||||
|
||||
@pytest.mark.parametrize("terminal", [False, True])
|
||||
def test_refine_context_rebuild_after_safetensors_storage_roundtrip(monkeypatch, tmp_path, terminal):
|
||||
_install_nested_tensor(monkeypatch)
|
||||
first = torch.zeros(1, 64, 96, 3) if terminal else None
|
||||
last = torch.ones(1, 64, 96, 3) if terminal else None
|
||||
runtime = cap._install_fake_runtime(monkeypatch, first_frame=first, last_frame=last)
|
||||
options = dict(chunks=3, first_frame=first, last_frame=last, capture_refine_context=True)
|
||||
full = cap._run_sequence(runtime, **options)
|
||||
writer, hashes = _controller(tmp_path)
|
||||
writer.prompts = ["continuous shot"] * 3
|
||||
for index, entry in enumerate(full[0]):
|
||||
writer.commit_chunk(entry, position=index)
|
||||
reader, _ = _controller(tmp_path)
|
||||
reader.prompts = writer.prompts[:]
|
||||
reader.manifest = json.loads(writer._manifest_path().read_text(encoding="utf-8"))
|
||||
loaded, records = reader._valid_prefix(reader.manifest, hashes)
|
||||
assert len(records) == len(loaded) == 3
|
||||
assert loaded[0]["video"].data_ptr() != full[0][0]["video"].data_ptr()
|
||||
prior = full[2]
|
||||
# The normal storage adapter invokes make_session to convert disk positions
|
||||
# (zero-based) to Session indices (one-based); exercise that owner as well.
|
||||
session = make_session(
|
||||
chunks=loaded, width=prior["width"], height=prior["height"],
|
||||
chunk_seconds=prior["chunk_seconds"], identity_hash=prior["identity_hash"],
|
||||
model_fingerprint_value=prior["model_fingerprint"],
|
||||
parent_session_id=prior["session_id"], reroll_from_chunk=0,
|
||||
settings=prior["settings"])
|
||||
runtime.samples.clear()
|
||||
before = {path: path.read_bytes() for path in tmp_path.rglob("*") if path.is_file()}
|
||||
restored = cap._run_sequence(runtime, **options, session=session)
|
||||
assert runtime.samples == []
|
||||
assert_nested_equal(restored[4], full[4])
|
||||
cap._assert_entry_parity(restored[0], full[0])
|
||||
assert {path: path.read_bytes() for path in tmp_path.rglob("*") if path.is_file()} == before
|
||||
@@ -0,0 +1,83 @@
|
||||
from types import SimpleNamespace
|
||||
|
||||
from ComfyUI_H3_Continuum_Join.compatibility import (
|
||||
_missing_callable_parameters,
|
||||
accelerator_summary,
|
||||
)
|
||||
|
||||
|
||||
def test_signature_contract_accepts_native_packed_layout_signature():
|
||||
def native(
|
||||
self,
|
||||
text_len,
|
||||
latent_t,
|
||||
latent_h,
|
||||
latent_w,
|
||||
audio_t,
|
||||
keyframes=None,
|
||||
refs=None,
|
||||
frame_count=None,
|
||||
):
|
||||
pass
|
||||
|
||||
assert _missing_callable_parameters(
|
||||
native,
|
||||
positional=("text_len", "latent_t", "latent_h", "latent_w", "audio_t"),
|
||||
keywords=("keyframes", "refs", "frame_count"),
|
||||
) == []
|
||||
|
||||
|
||||
def test_signature_contract_accepts_sol_attn_style_forwarding_wrapper():
|
||||
# Sol-Attn's H3 Morton registration wraps PackedLayout.__init__ with this
|
||||
# effective shape: five named base args followed by *args/**kwargs.
|
||||
def sol_wrapper(
|
||||
self, text_len, latent_t, latent_h, latent_w, audio_t, *args, **kwargs
|
||||
):
|
||||
pass
|
||||
|
||||
assert _missing_callable_parameters(
|
||||
sol_wrapper,
|
||||
positional=("text_len", "latent_t", "latent_h", "latent_w", "audio_t"),
|
||||
keywords=("keyframes", "refs", "frame_count"),
|
||||
) == []
|
||||
|
||||
|
||||
def test_signature_contract_still_fails_closed_for_real_keyword_removal():
|
||||
def incompatible(self, text_len, latent_t, latent_h, latent_w, audio_t):
|
||||
pass
|
||||
|
||||
assert _missing_callable_parameters(
|
||||
incompatible,
|
||||
positional=("text_len", "latent_t", "latent_h", "latent_w", "audio_t"),
|
||||
keywords=("keyframes", "refs", "frame_count"),
|
||||
) == ["keyframes", "refs", "frame_count"]
|
||||
|
||||
|
||||
def test_accelerator_summary_reads_modelpatcher_wrappers_and_transformer_markers():
|
||||
model = SimpleNamespace(
|
||||
wrappers={
|
||||
"diffusion_model": {
|
||||
"spectrum_h3.diffusion_model": [object()],
|
||||
},
|
||||
"apply_model": {
|
||||
"h3_continuum_join.apply_model.v1": [object()],
|
||||
},
|
||||
},
|
||||
model_options={
|
||||
"transformer_options": {
|
||||
"optimized_attention_override": object(),
|
||||
"sol_compose": {"min_tokens": 4096},
|
||||
},
|
||||
"h3_continuum_join": {"api_version": 1},
|
||||
},
|
||||
)
|
||||
summary = accelerator_summary(model)
|
||||
assert "Spectrum" in summary
|
||||
assert "Sol-Attn" in summary
|
||||
assert "attention override" in summary
|
||||
assert "Continuum" in summary
|
||||
|
||||
|
||||
def test_accelerator_summary_is_informational_when_no_markers_exist():
|
||||
model = SimpleNamespace(wrappers={}, model_options={})
|
||||
assert "informational only" in accelerator_summary(model)
|
||||
@@ -0,0 +1,37 @@
|
||||
import pytest
|
||||
|
||||
from ComfyUI_H3_Continuum_Join.conditioning import (
|
||||
conditioning_mode_from_presence,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("has_first", "has_last", "has_reference", "expected"),
|
||||
[
|
||||
(False, False, False, "t2va"),
|
||||
(True, False, False, "i2va"),
|
||||
(False, True, False, "last_only"),
|
||||
(True, True, False, "fl2va"),
|
||||
(False, False, True, "reference"),
|
||||
],
|
||||
)
|
||||
def test_conditioning_mode_matrix(
|
||||
has_first, has_last, has_reference, expected
|
||||
):
|
||||
assert conditioning_mode_from_presence(
|
||||
has_first=has_first,
|
||||
has_last=has_last,
|
||||
has_reference=has_reference,
|
||||
) == expected
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("has_first", "has_last"),
|
||||
[(True, False), (False, True), (True, True)],
|
||||
)
|
||||
def test_reference_takes_precedence_over_first_or_last_frame(has_first, has_last):
|
||||
assert conditioning_mode_from_presence(
|
||||
has_first=has_first,
|
||||
has_last=has_last,
|
||||
has_reference=True,
|
||||
) == "reference"
|
||||
@@ -0,0 +1,46 @@
|
||||
import torch
|
||||
|
||||
from ComfyUI_H3_Continuum_Join.v2.context_diagnostics import (
|
||||
ContextDiagnosticsTracker,
|
||||
measure_video_context,
|
||||
)
|
||||
|
||||
|
||||
def test_measure_video_context_is_read_only():
|
||||
video = torch.linspace(-1.0, 1.0, 1 * 24 * 3 * 5 * 7).reshape(1, 24, 3, 5, 7)
|
||||
original = video.clone()
|
||||
stats = measure_video_context(video)
|
||||
assert stats.shape == tuple(video.shape)
|
||||
assert stats.std > 0.0
|
||||
assert stats.high_frequency_rms > 0.0
|
||||
assert stats.temporal_delta_rms > 0.0
|
||||
assert torch.equal(video, original)
|
||||
|
||||
|
||||
def test_constant_context_has_no_high_frequency_or_motion():
|
||||
stats = measure_video_context(torch.ones(1, 24, 2, 4, 4))
|
||||
assert stats.std == 0.0
|
||||
assert stats.high_frequency_rms == 0.0
|
||||
assert stats.temporal_delta_rms == 0.0
|
||||
assert stats.outlier_ratio == 0.0
|
||||
|
||||
|
||||
def test_tracker_reports_baseline_and_previous_ratios():
|
||||
tracker = ContextDiagnosticsTracker()
|
||||
first = torch.linspace(-1.0, 1.0, 1 * 24 * 2 * 4 * 4).reshape(1, 24, 2, 4, 4)
|
||||
first_report = tracker.observe(first, source_chunk=1, context_frames=22, reused=False)
|
||||
second_report = tracker.observe(first * 2.0, source_chunk=2, context_frames=22, reused=False)
|
||||
assert "hf_base=1.0000" in first_report
|
||||
assert "std_base=2.0000" in second_report
|
||||
assert "hf_prev=2.0000" in second_report
|
||||
assert "action=observe" in second_report
|
||||
|
||||
|
||||
def test_tracker_never_turns_diagnostic_failure_into_execution_error():
|
||||
report = ContextDiagnosticsTracker().observe(
|
||||
torch.zeros(1, 24, 2, 4),
|
||||
source_chunk=1,
|
||||
context_frames=22,
|
||||
reused=False,
|
||||
)
|
||||
assert "unavailable" in report
|
||||
@@ -0,0 +1,216 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import importlib.util
|
||||
import inspect
|
||||
import json
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
from types import ModuleType, SimpleNamespace
|
||||
|
||||
import pytest
|
||||
|
||||
from ComfyUI_H3_Continuum_Join import nodes as root_nodes
|
||||
from ComfyUI_H3_Continuum_Join.v3.easy_audio_nodes import (
|
||||
H3EasyLoadAudio,
|
||||
NODE_CLASS_MAPPINGS,
|
||||
NODE_DISPLAY_NAME_MAPPINGS,
|
||||
)
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
BACKEND_PATH = ROOT / "v3" / "easy_audio_nodes.py"
|
||||
COMMON_FRONTEND_PATH = ROOT / "web" / "easy_bypass_toggle.js"
|
||||
FRONTEND_PATH = ROOT / "web" / "easy_load_audio.js"
|
||||
|
||||
|
||||
def test_easy_load_audio_is_public_and_keeps_core_audio_contract():
|
||||
schema = H3EasyLoadAudio.define_schema()
|
||||
assert NODE_CLASS_MAPPINGS["H3EasyLoadAudio"] is H3EasyLoadAudio
|
||||
assert root_nodes.NODE_CLASS_MAPPINGS["H3EasyLoadAudio"] is H3EasyLoadAudio
|
||||
assert NODE_DISPLAY_NAME_MAPPINGS["H3EasyLoadAudio"] == "H3 Continuum Load Audio"
|
||||
assert root_nodes.NODE_DISPLAY_NAME_MAPPINGS["H3EasyLoadAudio"] == (
|
||||
"H3 Continuum Load Audio"
|
||||
)
|
||||
assert schema.node_id == "H3EasyLoadAudio"
|
||||
assert schema.display_name == "H3 Continuum Load Audio"
|
||||
source = inspect.getsource(H3EasyLoadAudio)
|
||||
assert "def execute" not in source
|
||||
assert "def fingerprint_inputs" not in source
|
||||
assert "def validate_inputs" not in source
|
||||
|
||||
|
||||
def test_easy_load_audio_inherits_and_delegates_to_runtime_core(monkeypatch):
|
||||
fake_package = ModuleType("comfy_extras")
|
||||
fake_audio_module = ModuleType("comfy_extras.nodes_audio")
|
||||
|
||||
class FakeCoreLoadAudio:
|
||||
@classmethod
|
||||
def define_schema(cls):
|
||||
return SimpleNamespace(
|
||||
node_id="LoadAudio",
|
||||
display_name="Load Audio",
|
||||
category="audio",
|
||||
essentials_category="Audio",
|
||||
description="core",
|
||||
search_aliases=["audio file"],
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def execute(cls, audio):
|
||||
return f"loaded:{audio}"
|
||||
|
||||
@classmethod
|
||||
def fingerprint_inputs(cls, audio):
|
||||
return f"fingerprint:{audio}"
|
||||
|
||||
@classmethod
|
||||
def validate_inputs(cls, audio):
|
||||
return audio == "valid.wav"
|
||||
|
||||
fake_audio_module.LoadAudio = FakeCoreLoadAudio
|
||||
monkeypatch.setitem(sys.modules, "comfy_extras", fake_package)
|
||||
monkeypatch.setitem(sys.modules, "comfy_extras.nodes_audio", fake_audio_module)
|
||||
spec = importlib.util.spec_from_file_location("h3_easy_audio_runtime_probe", BACKEND_PATH)
|
||||
assert spec is not None and spec.loader is not None
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(module)
|
||||
|
||||
assert issubclass(module.H3EasyLoadAudio, FakeCoreLoadAudio)
|
||||
schema = module.H3EasyLoadAudio.define_schema()
|
||||
assert schema.node_id == "H3EasyLoadAudio"
|
||||
assert schema.display_name == "H3 Continuum Load Audio"
|
||||
assert module.H3EasyLoadAudio.execute("voice.wav") == "loaded:voice.wav"
|
||||
assert module.H3EasyLoadAudio.fingerprint_inputs("voice.wav") == (
|
||||
"fingerprint:voice.wav"
|
||||
)
|
||||
assert module.H3EasyLoadAudio.validate_inputs("valid.wav") is True
|
||||
|
||||
|
||||
def test_easy_load_audio_frontend_preserves_filename_player_and_mode(tmp_path):
|
||||
node_executable = shutil.which("node")
|
||||
if node_executable is None:
|
||||
pytest.skip("Node.js is required for the frontend behavior regression")
|
||||
functions = COMMON_FRONTEND_PATH.read_text(encoding="utf-8").replace(
|
||||
"export ", ""
|
||||
)
|
||||
script = f"""
|
||||
{functions}
|
||||
function plainWidget(name, value) {{
|
||||
return {{ name, value, options: {{}}, serialize: true }};
|
||||
}}
|
||||
const audioWidget = plainWidget("audio", "voice.wav");
|
||||
const playerWidget = plainWidget("audioUI", {{ position: 1.25, volume: 0.8 }});
|
||||
const node = {{
|
||||
comfyClass: "H3EasyLoadAudio",
|
||||
mode: 0,
|
||||
widgets: [audioWidget, playerWidget],
|
||||
addWidget(type, name, value, callback, options) {{
|
||||
const widget = {{ type, name, value, callback, options, serialize: true }};
|
||||
this.widgets.push(widget);
|
||||
return widget;
|
||||
}},
|
||||
setDirtyCanvas() {{}},
|
||||
serialize() {{
|
||||
return {{
|
||||
mode: this.mode,
|
||||
widgets_values: this.widgets
|
||||
.filter((widget) => widget.serialize !== false)
|
||||
.map((widget) => widget.value),
|
||||
}};
|
||||
}},
|
||||
configure(info) {{
|
||||
this.mode = info.mode;
|
||||
for (let index = 0; index < info.widgets_values.length; index++) {{
|
||||
this.widgets[index].value = info.widgets_values[index];
|
||||
}}
|
||||
}},
|
||||
}};
|
||||
configureEasyBypassToggleNode(node, {{
|
||||
nodeClass: "H3EasyLoadAudio",
|
||||
widgetName: "Enable Audio",
|
||||
tooltip: "audio tooltip",
|
||||
}});
|
||||
const toggle = findEasyBypassWidget(node);
|
||||
const initial = {{ names: node.widgets.map((w) => w.name), saved: node.serialize() }};
|
||||
toggle.callback(false);
|
||||
const off = {{ mode: node.mode, toggle: toggle.value, saved: node.serialize() }};
|
||||
toggle.callback(true);
|
||||
const onAgain = {{ mode: node.mode, toggle: toggle.value, saved: node.serialize() }};
|
||||
node.mode = 4;
|
||||
const externalBypass = {{ mode: node.mode, toggle: toggle.value }};
|
||||
node.configure({{
|
||||
mode: 4,
|
||||
widgets_values: ["reloaded.wav", {{ position: 2.5, volume: 0.6 }}],
|
||||
}});
|
||||
const reloaded = {{
|
||||
mode: node.mode,
|
||||
toggle: toggle.value,
|
||||
audio: audioWidget.value,
|
||||
player: playerWidget.value,
|
||||
names: node.widgets.map((w) => w.name),
|
||||
}};
|
||||
console.log(JSON.stringify({{ initial, off, onAgain, externalBypass, reloaded }}));
|
||||
"""
|
||||
script_path = tmp_path / "easy-load-audio-frontend.js"
|
||||
script_path.write_text(script, encoding="utf-8")
|
||||
result = subprocess.run(
|
||||
[node_executable, str(script_path)],
|
||||
check=True,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
)
|
||||
observed = json.loads(result.stdout)
|
||||
assert observed == {
|
||||
"initial": {
|
||||
"names": ["audio", "audioUI", "Enable Audio"],
|
||||
"saved": {
|
||||
"mode": 0,
|
||||
"widgets_values": [
|
||||
"voice.wav",
|
||||
{"position": 1.25, "volume": 0.8},
|
||||
],
|
||||
},
|
||||
},
|
||||
"off": {
|
||||
"mode": 4,
|
||||
"toggle": False,
|
||||
"saved": {
|
||||
"mode": 4,
|
||||
"widgets_values": [
|
||||
"voice.wav",
|
||||
{"position": 1.25, "volume": 0.8},
|
||||
],
|
||||
},
|
||||
},
|
||||
"onAgain": {
|
||||
"mode": 0,
|
||||
"toggle": True,
|
||||
"saved": {
|
||||
"mode": 0,
|
||||
"widgets_values": [
|
||||
"voice.wav",
|
||||
{"position": 1.25, "volume": 0.8},
|
||||
],
|
||||
},
|
||||
},
|
||||
"externalBypass": {"mode": 4, "toggle": False},
|
||||
"reloaded": {
|
||||
"mode": 4,
|
||||
"toggle": False,
|
||||
"audio": "reloaded.wav",
|
||||
"player": {"position": 2.5, "volume": 0.6},
|
||||
"names": ["audio", "audioUI", "Enable Audio"],
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
def test_easy_load_audio_uses_shared_non_polling_bypass_helper():
|
||||
source = FRONTEND_PATH.read_text(encoding="utf-8")
|
||||
common = COMMON_FRONTEND_PATH.read_text(encoding="utf-8")
|
||||
assert 'from "./easy_bypass_toggle.js"' in source
|
||||
assert 'widgetName: "Enable Audio"' in source
|
||||
assert "setInterval" not in common
|
||||
assert "setTimeout" not in common
|
||||
assert "node.mode = enabled ? NODE_MODE_ALWAYS : NODE_MODE_BYPASS" in common
|
||||
@@ -0,0 +1,269 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import importlib.util
|
||||
import inspect
|
||||
import json
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
from types import ModuleType
|
||||
|
||||
import pytest
|
||||
|
||||
from ComfyUI_H3_Continuum_Join import nodes as root_nodes
|
||||
from ComfyUI_H3_Continuum_Join.v3.easy_image_nodes import (
|
||||
H3EasyLoadImage,
|
||||
NODE_CLASS_MAPPINGS,
|
||||
NODE_DISPLAY_NAME_MAPPINGS,
|
||||
)
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
BACKEND_PATH = ROOT / "v3" / "easy_image_nodes.py"
|
||||
FRONTEND_PATH = ROOT / "web" / "easy_load_image.js"
|
||||
COMMON_FRONTEND_PATH = ROOT / "web" / "easy_bypass_toggle.js"
|
||||
|
||||
|
||||
def test_easy_load_image_is_public_and_keeps_core_image_mask_contract():
|
||||
assert NODE_CLASS_MAPPINGS["H3EasyLoadImage"] is H3EasyLoadImage
|
||||
assert root_nodes.NODE_CLASS_MAPPINGS["H3EasyLoadImage"] is H3EasyLoadImage
|
||||
assert NODE_DISPLAY_NAME_MAPPINGS["H3EasyLoadImage"] == "H3 Continuum Load Image"
|
||||
assert root_nodes.NODE_DISPLAY_NAME_MAPPINGS["H3EasyLoadImage"] == (
|
||||
"H3 Continuum Load Image"
|
||||
)
|
||||
assert H3EasyLoadImage.RETURN_TYPES == ("IMAGE", "MASK")
|
||||
assert H3EasyLoadImage.FUNCTION == "load_image"
|
||||
assert H3EasyLoadImage.DEPRECATED is False
|
||||
assert "def load_image" not in inspect.getsource(H3EasyLoadImage)
|
||||
|
||||
|
||||
def test_easy_load_image_inherits_the_runtime_core_loader(monkeypatch):
|
||||
fake_core = ModuleType("nodes")
|
||||
|
||||
class FakeCoreLoadImage:
|
||||
RETURN_TYPES = ("IMAGE", "MASK")
|
||||
FUNCTION = "load_image"
|
||||
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls):
|
||||
return {"required": {"image": (("core.png",), {"image_upload": True})}}
|
||||
|
||||
def load_image(self, image):
|
||||
return f"image:{image}", f"mask:{image}"
|
||||
|
||||
fake_core.LoadImage = FakeCoreLoadImage
|
||||
monkeypatch.setitem(sys.modules, "nodes", fake_core)
|
||||
spec = importlib.util.spec_from_file_location("h3_easy_image_runtime_probe", BACKEND_PATH)
|
||||
assert spec is not None and spec.loader is not None
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(module)
|
||||
|
||||
assert issubclass(module.H3EasyLoadImage, FakeCoreLoadImage)
|
||||
assert module.H3EasyLoadImage.INPUT_TYPES() == FakeCoreLoadImage.INPUT_TYPES()
|
||||
assert module.H3EasyLoadImage().load_image("core.png") == (
|
||||
"image:core.png",
|
||||
"mask:core.png",
|
||||
)
|
||||
|
||||
|
||||
def _frontend_functions(source: str) -> str:
|
||||
return source.replace("export ", "")
|
||||
|
||||
|
||||
def test_easy_load_image_frontend_uses_mode_as_single_source_of_truth(tmp_path):
|
||||
node_executable = shutil.which("node")
|
||||
if node_executable is None:
|
||||
pytest.skip("Node.js is required for the frontend behavior regression")
|
||||
source = COMMON_FRONTEND_PATH.read_text(encoding="utf-8")
|
||||
functions = _frontend_functions(source)
|
||||
script = f"""
|
||||
const EASY_LOAD_IMAGE_CLASS = "H3EasyLoadImage";
|
||||
{functions}
|
||||
function plainWidget(name, value) {{
|
||||
return {{ name, value, options: {{}}, serialize: true }};
|
||||
}}
|
||||
const imageWidget = plainWidget("image", "first.png");
|
||||
const uploadWidget = plainWidget("upload", "image");
|
||||
const node = {{
|
||||
comfyClass: EASY_LOAD_IMAGE_CLASS,
|
||||
mode: NODE_MODE_ALWAYS,
|
||||
widgets: [imageWidget, uploadWidget],
|
||||
dirtyCalls: 0,
|
||||
addWidget(type, name, value, callback, options) {{
|
||||
const widget = {{ type, name, value, callback, options, serialize: true }};
|
||||
this.widgets.push(widget);
|
||||
return widget;
|
||||
}},
|
||||
setDirtyCanvas() {{ this.dirtyCalls += 1; }},
|
||||
serialize() {{
|
||||
return {{
|
||||
mode: this.mode,
|
||||
widgets_values: this.widgets
|
||||
.filter((widget) => widget.serialize !== false)
|
||||
.map((widget) => widget.value),
|
||||
}};
|
||||
}},
|
||||
configure(info) {{
|
||||
this.mode = info.mode;
|
||||
for (let index = 0; index < info.widgets_values.length; index++) {{
|
||||
this.widgets[index].value = info.widgets_values[index];
|
||||
}}
|
||||
}},
|
||||
}};
|
||||
configureEasyBypassToggleNode(node, {{
|
||||
nodeClass: EASY_LOAD_IMAGE_CLASS,
|
||||
widgetName: "Enable Image",
|
||||
tooltip: "image tooltip",
|
||||
}});
|
||||
const toggle = findEasyBypassWidget(node);
|
||||
const initial = {{
|
||||
names: node.widgets.map((widget) => widget.name),
|
||||
toggle: toggle.value,
|
||||
saved: node.serialize(),
|
||||
}};
|
||||
toggle.value = false;
|
||||
toggle.callback(false);
|
||||
const toggledOff = {{ mode: node.mode, toggle: toggle.value, saved: node.serialize() }};
|
||||
node.mode = NODE_MODE_ALWAYS;
|
||||
const externalUnbypass = {{ mode: node.mode, toggle: toggle.value }};
|
||||
node.mode = NODE_MODE_BYPASS;
|
||||
const externalBypass = {{ mode: node.mode, toggle: toggle.value }};
|
||||
node.configure({{ mode: NODE_MODE_BYPASS, widgets_values: ["reloaded.png", "image"] }});
|
||||
const reloaded = {{
|
||||
mode: node.mode,
|
||||
toggle: toggle.value,
|
||||
image: imageWidget.value,
|
||||
upload: uploadWidget.value,
|
||||
names: node.widgets.map((widget) => widget.name),
|
||||
}};
|
||||
console.log(JSON.stringify({{ initial, toggledOff, externalUnbypass, externalBypass, reloaded }}));
|
||||
"""
|
||||
script_path = tmp_path / "easy-load-image-frontend.js"
|
||||
script_path.write_text(script, encoding="utf-8")
|
||||
result = subprocess.run(
|
||||
[node_executable, str(script_path)],
|
||||
check=True,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
)
|
||||
observed = json.loads(result.stdout)
|
||||
assert observed == {
|
||||
"initial": {
|
||||
"names": ["image", "upload", "Enable Image"],
|
||||
"toggle": True,
|
||||
"saved": {"mode": 0, "widgets_values": ["first.png", "image"]},
|
||||
},
|
||||
"toggledOff": {
|
||||
"mode": 4,
|
||||
"toggle": False,
|
||||
"saved": {"mode": 4, "widgets_values": ["first.png", "image"]},
|
||||
},
|
||||
"externalUnbypass": {"mode": 0, "toggle": True},
|
||||
"externalBypass": {"mode": 4, "toggle": False},
|
||||
"reloaded": {
|
||||
"mode": 4,
|
||||
"toggle": False,
|
||||
"image": "reloaded.png",
|
||||
"upload": "image",
|
||||
"names": ["image", "upload", "Enable Image"],
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
def test_shared_bypass_helper_preserves_core_widget_collection_when_drawing(tmp_path):
|
||||
node_executable = shutil.which("node")
|
||||
if node_executable is None:
|
||||
pytest.skip("Node.js is required for the frontend drawing regression")
|
||||
functions = _frontend_functions(
|
||||
COMMON_FRONTEND_PATH.read_text(encoding="utf-8")
|
||||
)
|
||||
script = f"""
|
||||
{functions}
|
||||
function widget(name, value) {{
|
||||
return {{ name, value, options: {{}}, serialize: true }};
|
||||
}}
|
||||
function nodeFor(nodeClass, enableName, existing) {{
|
||||
const enable = existing ? widget(enableName, false) : undefined;
|
||||
const node = {{
|
||||
comfyClass: nodeClass,
|
||||
mode: NODE_MODE_ALWAYS,
|
||||
widgets: existing ? [enable, widget("file", "media.bin")] : [widget("file", "media.bin")],
|
||||
drawCalls: [],
|
||||
addWidget(type, name, value, callback, options) {{
|
||||
const created = {{ type, name, value, callback, options, serialize: true }};
|
||||
this.widgets.push(created);
|
||||
return created;
|
||||
}},
|
||||
drawWidgets(ctx, options) {{
|
||||
this.drawCalls.push({{
|
||||
names: this.widgets.map((item) => item.name),
|
||||
alpha: options.editorAlpha,
|
||||
}});
|
||||
}},
|
||||
setDirtyCanvas() {{}},
|
||||
}};
|
||||
if (existing) {{
|
||||
configureExistingEasyBypassWidgetNode(node, {{
|
||||
nodeClass,
|
||||
widgetNames: [enableName],
|
||||
}});
|
||||
}} else {{
|
||||
configureEasyBypassToggleNode(node, {{
|
||||
nodeClass,
|
||||
widgetName: enableName,
|
||||
tooltip: "enable tooltip",
|
||||
}});
|
||||
node.mode = NODE_MODE_BYPASS;
|
||||
}}
|
||||
const toggle = findEasyBypassWidget(node);
|
||||
node.drawWidgets({{}}, {{ editorAlpha: 0.2, lowQuality: false }});
|
||||
const bypassCalls = node.drawCalls.slice();
|
||||
toggle.callback(true);
|
||||
node.drawCalls = [];
|
||||
node.drawWidgets({{}}, {{ editorAlpha: 1, lowQuality: false }});
|
||||
return {{
|
||||
bypassCalls,
|
||||
enabledCalls: node.drawCalls,
|
||||
mode: node.mode,
|
||||
toggle: toggle.value,
|
||||
clickable: typeof toggle.callback === "function",
|
||||
visible: toggle.hidden !== true,
|
||||
}};
|
||||
}}
|
||||
console.log(JSON.stringify({{
|
||||
image: nodeFor("H3EasyLoadImage", "Enable Image", false),
|
||||
audio: nodeFor("H3EasyLoadAudio", "Enable Audio", false),
|
||||
video: nodeFor("H3ContinuumLoadVideo", "enable_video", true),
|
||||
}}));
|
||||
"""
|
||||
script_path = tmp_path / "easy-loader-bypass-foreground.js"
|
||||
script_path.write_text(script, encoding="utf-8")
|
||||
result = subprocess.run(
|
||||
[node_executable, str(script_path)],
|
||||
check=True,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
)
|
||||
observed = json.loads(result.stdout)
|
||||
for kind, result in observed.items():
|
||||
names = ["enable_video", "file"] if kind == "video" else ["file", f"Enable {kind.title()}"]
|
||||
assert result == {
|
||||
"bypassCalls": [{"names": names, "alpha": 0.2}],
|
||||
"enabledCalls": [{"names": names, "alpha": 1}],
|
||||
"mode": 0,
|
||||
"toggle": True,
|
||||
"clickable": True,
|
||||
"visible": True,
|
||||
}
|
||||
|
||||
|
||||
def test_easy_load_image_frontend_has_no_backend_boolean_or_polling():
|
||||
source = FRONTEND_PATH.read_text(encoding="utf-8")
|
||||
common = COMMON_FRONTEND_PATH.read_text(encoding="utf-8")
|
||||
assert "setInterval" not in common
|
||||
assert "setTimeout" not in common
|
||||
assert "node.mode = enabled ? NODE_MODE_ALWAYS : NODE_MODE_BYPASS" in common
|
||||
assert "widget.options.serialize = false" in common
|
||||
assert 'from "./easy_bypass_toggle.js"' in source
|
||||
assert "configureEasyBypassToggleNode" in source
|
||||
@@ -0,0 +1,345 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from fractions import Fraction
|
||||
import inspect
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import subprocess
|
||||
from types import SimpleNamespace
|
||||
|
||||
import pytest
|
||||
import torch
|
||||
|
||||
from ComfyUI_H3_Continuum_Join import nodes as root_nodes
|
||||
from ComfyUI_H3_Continuum_Join.v3 import easy_video_nodes as video_nodes
|
||||
from ComfyUI_H3_Continuum_Join.v3.easy_video_nodes import (
|
||||
ExecutionBlocker,
|
||||
H3ContinuumLoadVideo,
|
||||
NODE_CLASS_MAPPINGS,
|
||||
NODE_DISPLAY_NAME_MAPPINGS,
|
||||
_resample_video_frames,
|
||||
load_video_components,
|
||||
)
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
COMMON_FRONTEND_PATH = ROOT / "web" / "easy_bypass_toggle.js"
|
||||
FRONTEND_PATH = ROOT / "web" / "easy_load_video.js"
|
||||
|
||||
|
||||
def _frames(count: int) -> torch.Tensor:
|
||||
values = torch.arange(count, dtype=torch.float32).view(count, 1, 1, 1)
|
||||
return values.expand(-1, 2, 2, 3).clone()
|
||||
|
||||
|
||||
def test_schema_registration_and_minimal_core_contract():
|
||||
schema = H3ContinuumLoadVideo.define_schema()
|
||||
assert NODE_CLASS_MAPPINGS["H3ContinuumLoadVideo"] is H3ContinuumLoadVideo
|
||||
assert root_nodes.NODE_CLASS_MAPPINGS["H3ContinuumLoadVideo"] is (
|
||||
H3ContinuumLoadVideo
|
||||
)
|
||||
assert NODE_DISPLAY_NAME_MAPPINGS["H3ContinuumLoadVideo"] == (
|
||||
"H3 Continuum Load Video"
|
||||
)
|
||||
assert schema.node_id == "H3ContinuumLoadVideo"
|
||||
assert schema.display_name == "H3 Continuum Load Video"
|
||||
assert schema.category == "MiniMax H3/Continuum"
|
||||
assert [item.id for item in schema.inputs] == [
|
||||
"enable_video",
|
||||
"file",
|
||||
"force_rate",
|
||||
]
|
||||
assert schema.inputs[0].default is True
|
||||
assert schema.inputs[1].upload.value == "video_upload"
|
||||
assert schema.inputs[2].default == 24.0
|
||||
assert schema.inputs[2].min == 0.0
|
||||
assert schema.inputs[2].max == 120.0
|
||||
assert schema.inputs[2].step == 0.01
|
||||
assert len(schema.outputs) == 2
|
||||
source = inspect.getsource(video_nodes)
|
||||
assert "InputImpl.VideoFromFile" in source
|
||||
assert "import av" not in source
|
||||
assert "subprocess" not in source
|
||||
|
||||
|
||||
def test_24_to_24_returns_the_identical_image_batch():
|
||||
images = _frames(240)
|
||||
result = _resample_video_frames(images, Fraction(24, 1), 24.0)
|
||||
assert result is images
|
||||
|
||||
|
||||
def test_30_to_24_preserves_ten_second_duration():
|
||||
result = _resample_video_frames(_frames(300), Fraction(30, 1), 24.0)
|
||||
assert result.shape[0] == 240
|
||||
assert result.shape[0] / 24.0 == 10.0
|
||||
|
||||
|
||||
def test_24_to_30_preserves_duration_and_duplicates_frames():
|
||||
result = _resample_video_frames(_frames(240), Fraction(24, 1), 30.0)
|
||||
assert result.shape[0] == 300
|
||||
assert result.shape[0] / 30.0 == 10.0
|
||||
source_values = result[:, 0, 0, 0]
|
||||
assert torch.unique(source_values).numel() == 240
|
||||
|
||||
|
||||
def test_2997_to_24_uses_fraction_without_off_by_one():
|
||||
result = _resample_video_frames(
|
||||
_frames(300),
|
||||
Fraction(30_000, 1_001),
|
||||
24.0,
|
||||
)
|
||||
assert result.shape[0] == 240
|
||||
|
||||
|
||||
def test_force_rate_zero_returns_the_identical_image_batch():
|
||||
images = _frames(123)
|
||||
result = _resample_video_frames(images, Fraction(30_000, 1_001), 0.0)
|
||||
assert result is images
|
||||
|
||||
|
||||
def test_audio_is_bit_exact_and_core_components_are_used(monkeypatch):
|
||||
images = _frames(300)
|
||||
waveform = torch.linspace(-1.0, 1.0, 64).reshape(1, 1, 64)
|
||||
audio = {"waveform": waveform, "sample_rate": 32_000}
|
||||
calls = []
|
||||
|
||||
class FakeVideo:
|
||||
def get_components(self):
|
||||
calls.append("get_components")
|
||||
return SimpleNamespace(
|
||||
images=images,
|
||||
audio=audio,
|
||||
frame_rate=Fraction(30, 1),
|
||||
)
|
||||
|
||||
def fake_video_from_file(path):
|
||||
calls.append(("VideoFromFile", path))
|
||||
return FakeVideo()
|
||||
|
||||
monkeypatch.setattr(
|
||||
video_nodes.folder_paths,
|
||||
"get_annotated_filepath",
|
||||
lambda file: f"D:/input/{file}",
|
||||
)
|
||||
monkeypatch.setattr(video_nodes.InputImpl, "VideoFromFile", fake_video_from_file)
|
||||
output_images, output_audio = load_video_components(
|
||||
file="source.mp4",
|
||||
enable_video=True,
|
||||
force_rate=24.0,
|
||||
)
|
||||
|
||||
assert output_images.shape[0] == 240
|
||||
assert output_audio is audio
|
||||
assert output_audio["sample_rate"] == 32_000
|
||||
assert output_audio["waveform"].shape == waveform.shape
|
||||
assert torch.equal(output_audio["waveform"], waveform)
|
||||
assert calls == [("VideoFromFile", "D:/input/source.mp4"), "get_components"]
|
||||
|
||||
|
||||
def test_enable_video_off_never_resolves_or_decodes(monkeypatch):
|
||||
def forbidden(*args, **kwargs):
|
||||
raise AssertionError("disabled video must not touch Core decode or the file")
|
||||
|
||||
monkeypatch.setattr(video_nodes.folder_paths, "get_annotated_filepath", forbidden)
|
||||
monkeypatch.setattr(video_nodes.InputImpl, "VideoFromFile", forbidden)
|
||||
image, audio = load_video_components(
|
||||
file="missing-old-file.mp4",
|
||||
enable_video=False,
|
||||
force_rate=24.0,
|
||||
)
|
||||
assert isinstance(image, ExecutionBlocker)
|
||||
assert isinstance(audio, ExecutionBlocker)
|
||||
assert image.message is None
|
||||
assert audio.message is None
|
||||
|
||||
|
||||
def test_audio_missing_blocks_only_audio_branch(monkeypatch):
|
||||
images = _frames(24)
|
||||
|
||||
class FakeVideo:
|
||||
def get_components(self):
|
||||
return SimpleNamespace(
|
||||
images=images,
|
||||
audio=None,
|
||||
frame_rate=Fraction(24, 1),
|
||||
)
|
||||
|
||||
monkeypatch.setattr(
|
||||
video_nodes.folder_paths,
|
||||
"get_annotated_filepath",
|
||||
lambda file: f"D:/input/{file}",
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
video_nodes.InputImpl,
|
||||
"VideoFromFile",
|
||||
lambda path: FakeVideo(),
|
||||
)
|
||||
output_images, output_audio = load_video_components(
|
||||
file="silent.mp4",
|
||||
enable_video=True,
|
||||
force_rate=24.0,
|
||||
)
|
||||
assert output_images is images
|
||||
assert isinstance(output_audio, ExecutionBlocker)
|
||||
assert output_audio.message is None
|
||||
|
||||
|
||||
def test_validation_and_fingerprint_skip_stale_file_when_disabled(
|
||||
monkeypatch,
|
||||
tmp_path: Path,
|
||||
):
|
||||
calls = []
|
||||
|
||||
def exists(file):
|
||||
calls.append(("exists", file))
|
||||
return file == "valid.mp4"
|
||||
|
||||
monkeypatch.setattr(video_nodes.folder_paths, "exists_annotated_filepath", exists)
|
||||
assert H3ContinuumLoadVideo.validate_inputs(False, "missing.mp4", 24.0) is True
|
||||
assert calls == []
|
||||
disabled_fingerprint = H3ContinuumLoadVideo.fingerprint_inputs(
|
||||
False,
|
||||
"missing.mp4",
|
||||
24.0,
|
||||
)
|
||||
assert disabled_fingerprint == (False, "missing.mp4", 24.0, None)
|
||||
assert calls == []
|
||||
|
||||
invalid = H3ContinuumLoadVideo.validate_inputs(True, "missing.mp4", 24.0)
|
||||
assert invalid == "Invalid video file: missing.mp4"
|
||||
assert H3ContinuumLoadVideo.validate_inputs(True, "valid.mp4", 24.0) is True
|
||||
|
||||
video_path = tmp_path / "valid.mp4"
|
||||
video_path.write_bytes(b"video")
|
||||
monkeypatch.setattr(
|
||||
video_nodes.folder_paths,
|
||||
"get_annotated_filepath",
|
||||
lambda file: str(video_path),
|
||||
)
|
||||
fingerprint = H3ContinuumLoadVideo.fingerprint_inputs(
|
||||
True,
|
||||
"valid.mp4",
|
||||
30.0,
|
||||
)
|
||||
assert fingerprint[:3] == (True, "valid.mp4", 30.0)
|
||||
assert fingerprint[3] == os.path.getmtime(video_path)
|
||||
|
||||
|
||||
def test_enable_video_false_uses_native_bypass_appearance(tmp_path):
|
||||
node_executable = shutil.which("node")
|
||||
if node_executable is None:
|
||||
pytest.skip("Node.js is required for the frontend behavior regression")
|
||||
functions = COMMON_FRONTEND_PATH.read_text(encoding="utf-8").replace(
|
||||
"export ", ""
|
||||
)
|
||||
script = f"""
|
||||
{functions}
|
||||
function plainWidget(name, value) {{
|
||||
return {{ name, value, options: {{}}, serialize: true }};
|
||||
}}
|
||||
const enableWidget = plainWidget("enable_video", false);
|
||||
const fileWidget = plainWidget("file", "clip.mp4");
|
||||
const rateWidget = plainWidget("force_rate", 24.0);
|
||||
const uploadWidget = plainWidget("upload", "video");
|
||||
const node = {{
|
||||
comfyClass: "H3ContinuumLoadVideo",
|
||||
mode: 0,
|
||||
widgets: [enableWidget, fileWidget, rateWidget, uploadWidget],
|
||||
dirtyCalls: 0,
|
||||
setDirtyCanvas() {{ this.dirtyCalls += 1; }},
|
||||
serialize() {{
|
||||
return {{
|
||||
mode: this.mode,
|
||||
widgets_values: this.widgets.map((widget) => widget.value),
|
||||
}};
|
||||
}},
|
||||
configure(info) {{
|
||||
this.mode = info.mode;
|
||||
for (let index = 0; index < info.widgets_values.length; index++) {{
|
||||
this.widgets[index].value = info.widgets_values[index];
|
||||
}}
|
||||
}},
|
||||
}};
|
||||
configureExistingEasyBypassWidgetNode(node, {{
|
||||
nodeClass: "H3ContinuumLoadVideo",
|
||||
widgetNames: ["enable_video", "Enable Video"],
|
||||
}});
|
||||
const initial = {{
|
||||
mode: node.mode,
|
||||
enabled: enableWidget.value,
|
||||
names: node.widgets.map((widget) => widget.name),
|
||||
saved: node.serialize(),
|
||||
}};
|
||||
enableWidget.callback(true);
|
||||
const enabled = {{ mode: node.mode, enabled: enableWidget.value }};
|
||||
node.mode = 4;
|
||||
const externalBypass = {{ mode: node.mode, enabled: enableWidget.value }};
|
||||
node.mode = 0;
|
||||
const externalUnbypass = {{ mode: node.mode, enabled: enableWidget.value }};
|
||||
node.configure({{
|
||||
mode: 0,
|
||||
widgets_values: [false, "reloaded.mp4", 30.0, "video"],
|
||||
}});
|
||||
configureExistingEasyBypassWidgetNode(node, {{
|
||||
nodeClass: "H3ContinuumLoadVideo",
|
||||
widgetNames: ["enable_video", "Enable Video"],
|
||||
}});
|
||||
const reloaded = {{
|
||||
mode: node.mode,
|
||||
enabled: enableWidget.value,
|
||||
file: fileWidget.value,
|
||||
rate: rateWidget.value,
|
||||
names: node.widgets.map((widget) => widget.name),
|
||||
saved: node.serialize(),
|
||||
}};
|
||||
console.log(JSON.stringify({{ initial, enabled, externalBypass, externalUnbypass, reloaded }}));
|
||||
"""
|
||||
script_path = tmp_path / "easy-load-video-frontend.js"
|
||||
script_path.write_text(script, encoding="utf-8")
|
||||
result = subprocess.run(
|
||||
[node_executable, str(script_path)],
|
||||
check=True,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
)
|
||||
observed = json.loads(result.stdout)
|
||||
assert observed == {
|
||||
"initial": {
|
||||
"mode": 4,
|
||||
"enabled": False,
|
||||
"names": ["enable_video", "file", "force_rate", "upload"],
|
||||
"saved": {
|
||||
"mode": 4,
|
||||
"widgets_values": [False, "clip.mp4", 24, "video"],
|
||||
},
|
||||
},
|
||||
"enabled": {"mode": 0, "enabled": True},
|
||||
"externalBypass": {"mode": 4, "enabled": False},
|
||||
"externalUnbypass": {"mode": 0, "enabled": True},
|
||||
"reloaded": {
|
||||
"mode": 4,
|
||||
"enabled": False,
|
||||
"file": "reloaded.mp4",
|
||||
"rate": 30,
|
||||
"names": ["enable_video", "file", "force_rate", "upload"],
|
||||
"saved": {
|
||||
"mode": 4,
|
||||
"widgets_values": [False, "reloaded.mp4", 30, "video"],
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
def test_legacy_video_has_no_frontend_enable_bridge():
|
||||
source = FRONTEND_PATH.read_text(encoding="utf-8")
|
||||
common = COMMON_FRONTEND_PATH.read_text(encoding="utf-8")
|
||||
assert 'from "./easy_bypass_toggle.js"' not in source
|
||||
assert "configureExistingEasyBypassWidgetNode" not in source
|
||||
assert 'widgetNames: ["enable_video", "Enable Video"]' not in source
|
||||
assert "NODE_MODE_BYPASS" in common
|
||||
assert "node.color" not in source
|
||||
assert "node.bgcolor" not in source
|
||||
assert "setInterval" not in common
|
||||
assert "setTimeout" not in common
|
||||
@@ -0,0 +1,58 @@
|
||||
"""Issue #25 leaves backend dimensions, execution and identity unchanged."""
|
||||
import json
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from ComfyUI_H3_Continuum_Join.v3.driving_nodes import H3ContinuumSamplerV38, H3ContinuumSamplerV39
|
||||
from ComfyUI_H3_Continuum_Join.v3.resolution import resolve_h3_size_source
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
|
||||
|
||||
@pytest.mark.parametrize('cls', [H3ContinuumSamplerV38, H3ContinuumSamplerV39])
|
||||
def test_external_size_schema_remains_native_required_int(cls):
|
||||
required = cls.INPUT_TYPES()['required']
|
||||
assert list(required).index('height') == list(required).index('width') + 1
|
||||
for axis in ('width', 'height'):
|
||||
kind, options = required[axis]
|
||||
assert kind == 'INT'
|
||||
assert options['default'] == (736 if axis == 'width' else 416)
|
||||
assert (options['min'], options['max'], options['step']) == (32, 16384, 32)
|
||||
assert 'forceInput' not in options and 'defaultInput' not in options
|
||||
|
||||
|
||||
@pytest.mark.parametrize('width,height', [(641,768),(640,767),(0,768),(True,768),(640,False),(16416,768)])
|
||||
def test_external_resolved_dimension_uses_existing_validation(width, height):
|
||||
with pytest.raises((TypeError, ValueError)):
|
||||
resolve_h3_size_source(size_source='Manual', width=width, height=height)
|
||||
|
||||
|
||||
def test_external_resolved_dimension_equals_manual_and_missing_first_fallback():
|
||||
manual = resolve_h3_size_source(size_source='Manual', width=640, height=768)
|
||||
assert (manual.width, manual.height) == (640,768)
|
||||
fallback = resolve_h3_size_source(size_source='First Image', width=640, height=768)
|
||||
assert (fallback.width, fallback.height) == (manual.width, manual.height)
|
||||
|
||||
|
||||
def test_external_dimensions_do_not_override_active_first_image():
|
||||
class Image:
|
||||
shape = (1,1080,1920,3)
|
||||
expected = resolve_h3_size_source(size_source='First Image', first_frame=Image())
|
||||
external = resolve_h3_size_source(size_source='First Image', width=641, height=True, first_frame=Image())
|
||||
assert external == expected
|
||||
|
||||
|
||||
def test_external_int_frontend_gate():
|
||||
runner = shutil.which('node')
|
||||
assert runner, 'Node.js is required for frontend tests'
|
||||
result = subprocess.run([runner, str(ROOT/'tests/frontend_external_int_size.cjs')],
|
||||
env={**os.environ, 'H3_TEST_ROOT':str(ROOT)},
|
||||
capture_output=True, text=True, encoding='utf-8', timeout=45)
|
||||
records = json.loads(result.stdout)
|
||||
assert len(records) == 22
|
||||
failures = [r for r in records if not r['pass']]
|
||||
assert result.returncode == 0 and not failures, result.stdout + result.stderr
|
||||
@@ -0,0 +1,81 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import importlib.util
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
import torch
|
||||
|
||||
|
||||
MODULE_PATH = Path(__file__).parents[1] / "tools" / "gpu_diagnostic_node" / "capture.py"
|
||||
SPEC = importlib.util.spec_from_file_location("h3_gpu_diagnostic_capture", MODULE_PATH)
|
||||
capture = importlib.util.module_from_spec(SPEC)
|
||||
assert SPEC.loader is not None
|
||||
sys.modules[SPEC.name] = capture
|
||||
SPEC.loader.exec_module(capture)
|
||||
|
||||
|
||||
def test_tensor_fingerprint_is_deterministic():
|
||||
value = torch.arange(12, dtype=torch.float32).reshape(1, 3, 4)
|
||||
assert capture.tensor_fingerprint(value) == capture.tensor_fingerprint(value.clone())
|
||||
|
||||
|
||||
def test_tensor_comparison_records_numerical_difference():
|
||||
left = torch.tensor([1.0, 2.0], dtype=torch.float32)
|
||||
right = torch.tensor([1.0, 2.000001], dtype=torch.float32)
|
||||
result = capture.compare_tensors(left, right)
|
||||
assert not result.bit_exact
|
||||
assert result.allclose
|
||||
assert result.matches
|
||||
assert result.max_abs_diff > 0.0
|
||||
|
||||
|
||||
def test_terminal_video_recombine_is_bit_exact():
|
||||
physical = torch.arange(72, dtype=torch.float32).reshape(1, 1, 72, 1, 1)
|
||||
first = physical[:, :, 0:37]
|
||||
second = physical[:, :, 30:72]
|
||||
rebuilt = capture.recombine_terminal_streams(
|
||||
first,
|
||||
second,
|
||||
first_range=(0, 37),
|
||||
second_range=(30, 72),
|
||||
dim=2,
|
||||
)
|
||||
assert torch.equal(rebuilt, physical)
|
||||
|
||||
|
||||
def test_terminal_audio_recombine_is_bit_exact():
|
||||
physical = torch.arange(405, dtype=torch.float32).reshape(1, 1, 405)
|
||||
first = physical[..., 0:207]
|
||||
second = physical[..., 170:405]
|
||||
rebuilt = capture.recombine_terminal_streams(
|
||||
first,
|
||||
second,
|
||||
first_range=(0, 207),
|
||||
second_range=(170, 405),
|
||||
dim=-1,
|
||||
)
|
||||
assert torch.equal(rebuilt, physical)
|
||||
|
||||
|
||||
def test_stage_comparison_reports_first_field():
|
||||
left = capture.DiagnosticCapture("core")
|
||||
right = capture.DiagnosticCapture("continuum")
|
||||
left.add_value("A_pre_sampler", "seed", 42)
|
||||
right.add_value("A_pre_sampler", "seed", 43)
|
||||
left.add_tensor("A_pre_sampler", "sigmas", torch.ones(2))
|
||||
right.add_tensor("A_pre_sampler", "sigmas", torch.ones(2))
|
||||
result = capture.compare_stage(left, right, "A_pre_sampler")
|
||||
assert result["status"] == "DIFFER"
|
||||
assert result["first_field"] == "seed"
|
||||
|
||||
|
||||
def test_summary_uses_stage_order_and_first_divergence(tmp_path):
|
||||
comparison = {
|
||||
"A_pre_sampler": {"status": "MATCH", "first_field": None},
|
||||
"B_first_model_call": {"status": "DIFFER", "first_field": "position_ids"},
|
||||
}
|
||||
text = capture.format_comparison(comparison, tmp_path)
|
||||
assert "A_pre_sampler: MATCH" in text
|
||||
assert "B_first_model_call: DIFFER" in text
|
||||
assert "First divergence: B_first_model_call.position_ids" in text
|
||||
@@ -0,0 +1,313 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import importlib.util
|
||||
from pathlib import Path
|
||||
import sys
|
||||
|
||||
import numpy as np
|
||||
import torch
|
||||
|
||||
|
||||
TOOLS = Path(__file__).parents[1] / "tools"
|
||||
|
||||
|
||||
def _load(name: str, filename: str):
|
||||
path = TOOLS / filename
|
||||
spec = importlib.util.spec_from_file_location(name, path)
|
||||
assert spec is not None and spec.loader is not None
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
sys.modules[name] = module
|
||||
spec.loader.exec_module(module)
|
||||
return module
|
||||
|
||||
|
||||
runner = _load("h3_issue13_r25_gate_runner", "issue13_r25_gate_runner.py")
|
||||
analyzer = _load("h3_issue13_r25_analyze", "issue13_r2_analyze.py")
|
||||
soft_reanchor = _load(
|
||||
"h3_issue13_soft_reanchor",
|
||||
"gpu_diagnostic_node/soft_reanchor.py",
|
||||
)
|
||||
|
||||
|
||||
def _source_prompt() -> dict:
|
||||
return {
|
||||
"114": {"inputs": {"image": "old.png"}},
|
||||
"119": {"inputs": {}},
|
||||
"139": {"inputs": {"sampler_name": "res_multistep"}},
|
||||
"150": {"inputs": {"enabled": True}},
|
||||
"153": {"inputs": {"scheduler": "old", "steps": 20, "denoise": 0.5}},
|
||||
"188": {"inputs": {"value": "old"}},
|
||||
"191": {"inputs": {}},
|
||||
"249": {"inputs": {}},
|
||||
"286": {
|
||||
"inputs": {
|
||||
"lora_1": {"on": True, "lora": "old.safetensors", "strength": 1.0}
|
||||
}
|
||||
},
|
||||
"297": {"inputs": {"value": 0.3}},
|
||||
"305": {
|
||||
"class_type": "H3ContinuumSamplerV37",
|
||||
"inputs": {
|
||||
"continuation_backend": "Standard",
|
||||
"generation_mode": "Full Run",
|
||||
"review_action": "Continue / Next",
|
||||
"guide": ["900", 0],
|
||||
"last_frame": ["901", 0],
|
||||
},
|
||||
},
|
||||
"306": {"inputs": {}},
|
||||
}
|
||||
|
||||
|
||||
def test_screening_order_and_contract_are_fixed():
|
||||
assert tuple(runner.CASE_SPECS)[:3] == (
|
||||
"screen_3x5_turbo",
|
||||
"screen_3x10_turbo",
|
||||
"screen_6x5_turbo",
|
||||
)
|
||||
prompt, loras = runner.configure_prompt(
|
||||
_source_prompt(),
|
||||
case="screen_3x10_turbo",
|
||||
output_prefix="video/test",
|
||||
image_name="closeup.png",
|
||||
seed=131325,
|
||||
width=576,
|
||||
height=864,
|
||||
diagnostic_nonce=7,
|
||||
)
|
||||
inputs = prompt["305"]["inputs"]
|
||||
assert inputs["chunks"] == 3
|
||||
assert inputs["chunk_seconds"] == 10.0
|
||||
assert inputs["width"] == 576
|
||||
assert inputs["height"] == 864
|
||||
assert prompt["139"]["inputs"]["sampler_name"] == "euler"
|
||||
assert prompt["153"]["inputs"]["steps"] == 8
|
||||
assert prompt["153"]["inputs"]["scheduler"] == "simple"
|
||||
assert prompt["114"]["inputs"]["image"] == "closeup.png"
|
||||
assert loras == [{"name": runner.TURBO_LORA, "strength": 1.0}]
|
||||
assert prompt["188"]["inputs"]["value"].count("\n---\n") == 2
|
||||
assert "dynv2" not in prompt["188"]["inputs"]["value"]
|
||||
|
||||
|
||||
def test_six_by_five_uses_six_motion_steps():
|
||||
prompt, _ = runner.configure_prompt(
|
||||
_source_prompt(),
|
||||
case="screen_6x5_turbo",
|
||||
output_prefix="video/test",
|
||||
image_name="closeup.png",
|
||||
seed=1,
|
||||
width=576,
|
||||
height=864,
|
||||
diagnostic_nonce=8,
|
||||
)
|
||||
assert prompt["305"]["inputs"]["chunks"] == 6
|
||||
assert prompt["188"]["inputs"]["value"].count("\n---\n") == 5
|
||||
|
||||
|
||||
def test_six_by_five_fixed_prompt_repeats_one_prompt():
|
||||
prompt, loras = runner.configure_prompt(
|
||||
_source_prompt(),
|
||||
case="screen_6x5_turbo_fixed_prompt",
|
||||
output_prefix="video/issue13_r26/fixed",
|
||||
image_name="closeup.png",
|
||||
seed=131325,
|
||||
width=576,
|
||||
height=864,
|
||||
diagnostic_nonce=132600,
|
||||
)
|
||||
prompts = prompt["188"]["inputs"]["value"].split("\n---\n")
|
||||
assert len(prompts) == 6
|
||||
assert len(set(prompts)) == 1
|
||||
assert prompt["305"]["inputs"]["chunks"] == 6
|
||||
assert prompt["305"]["inputs"]["chunk_seconds"] == 5.0
|
||||
assert prompt["153"]["inputs"]["steps"] == 8
|
||||
assert loras == [{"name": runner.TURBO_LORA, "strength": 1.0}]
|
||||
|
||||
|
||||
def test_six_by_five_fixed_prefix_changes_only_diagnostic_source_mode():
|
||||
source = _source_prompt()
|
||||
recursive, _ = runner.configure_prompt(
|
||||
source,
|
||||
case="screen_6x5_turbo_fixed_prompt",
|
||||
output_prefix="video/issue13_r26/recursive",
|
||||
image_name="closeup.png",
|
||||
seed=131325,
|
||||
width=576,
|
||||
height=864,
|
||||
diagnostic_nonce=132600,
|
||||
)
|
||||
fixed, _ = runner.configure_prompt(
|
||||
source,
|
||||
case="screen_6x5_turbo_fixed_prefix",
|
||||
output_prefix="video/issue13_r26/fixed-prefix",
|
||||
image_name="closeup.png",
|
||||
seed=131325,
|
||||
width=576,
|
||||
height=864,
|
||||
diagnostic_nonce=132601,
|
||||
)
|
||||
recursive_inputs = recursive["305"]["inputs"]
|
||||
fixed_inputs = fixed["305"]["inputs"]
|
||||
assert recursive_inputs["continuation_source_mode"] == "Recursive"
|
||||
assert fixed_inputs["continuation_source_mode"] == "Fixed Group 1 Tail"
|
||||
ignored = {"continuation_source_mode", "diagnostic_nonce"}
|
||||
assert {
|
||||
key: value for key, value in recursive_inputs.items() if key not in ignored
|
||||
} == {key: value for key, value in fixed_inputs.items() if key not in ignored}
|
||||
assert recursive["188"]["inputs"]["value"] == fixed["188"]["inputs"]["value"]
|
||||
|
||||
|
||||
def test_six_by_five_soft_reanchor_changes_only_diagnostic_source_mode():
|
||||
source = _source_prompt()
|
||||
recursive, _ = runner.configure_prompt(
|
||||
source,
|
||||
case="screen_6x5_turbo_fixed_prompt",
|
||||
output_prefix="video/issue13_r27/recursive",
|
||||
image_name="closeup.png",
|
||||
seed=131325,
|
||||
width=576,
|
||||
height=864,
|
||||
diagnostic_nonce=132700,
|
||||
)
|
||||
reanchored, _ = runner.configure_prompt(
|
||||
source,
|
||||
case="screen_6x5_turbo_soft_reanchor",
|
||||
output_prefix="video/issue13_r27/soft-reanchor",
|
||||
image_name="closeup.png",
|
||||
seed=131325,
|
||||
width=576,
|
||||
height=864,
|
||||
diagnostic_nonce=132701,
|
||||
)
|
||||
recursive_inputs = recursive["305"]["inputs"]
|
||||
reanchored_inputs = reanchored["305"]["inputs"]
|
||||
assert recursive_inputs["continuation_source_mode"] == "Recursive"
|
||||
assert reanchored_inputs["continuation_source_mode"] == "Soft Re-anchor Group 4"
|
||||
ignored = {"continuation_source_mode", "diagnostic_nonce"}
|
||||
assert {
|
||||
key: value for key, value in recursive_inputs.items() if key not in ignored
|
||||
} == {key: value for key, value in reanchored_inputs.items() if key not in ignored}
|
||||
assert recursive["188"]["inputs"]["value"] == reanchored["188"]["inputs"]["value"]
|
||||
|
||||
|
||||
def test_soft_reanchor_moves_global_appearance_halfway_without_geometry_change():
|
||||
current = torch.zeros((1, 4, 8, 8, 3), dtype=torch.float32)
|
||||
current[..., 0] = 0.8
|
||||
current[..., 1] = 0.3
|
||||
current[..., 2] = 0.2
|
||||
reference = torch.zeros_like(current)
|
||||
reference[..., 0] = 0.4
|
||||
reference[..., 1] = 0.5
|
||||
reference[..., 2] = 0.6
|
||||
adjusted, report = soft_reanchor.soft_match_rgb_appearance(
|
||||
current,
|
||||
reference,
|
||||
strength=0.5,
|
||||
)
|
||||
assert adjusted.shape == current.shape
|
||||
assert torch.equal(current[..., 0], torch.full_like(current[..., 0], 0.8))
|
||||
before_gap = abs(
|
||||
report["before"]["luma_mean"] - report["reference"]["luma_mean"]
|
||||
)
|
||||
after_gap = abs(
|
||||
report["after"]["luma_mean"] - report["reference"]["luma_mean"]
|
||||
)
|
||||
assert after_gap < before_gap
|
||||
assert report["strength"] == 0.5
|
||||
assert report["geometry_unchanged"] is True
|
||||
|
||||
|
||||
def test_soft_reanchor_vae_roundtrip_preserves_shape_and_inputs():
|
||||
class FakeVideoVAE:
|
||||
def decode(self, latent):
|
||||
value = float(latent.mean().item())
|
||||
pixels = torch.full((1, 22, 32, 32, 3), value, dtype=torch.float32)
|
||||
pixels[..., 0] = value + 0.1
|
||||
return pixels.clamp(0.0, 1.0)
|
||||
|
||||
def encode(self, pixels):
|
||||
value = float(pixels.mean().item())
|
||||
return torch.full((1, 24, 7, 2, 2), value, dtype=torch.float32)
|
||||
|
||||
current = torch.full((1, 24, 7, 2, 2), 0.7, dtype=torch.float32)
|
||||
reference = torch.full((1, 24, 7, 2, 2), 0.3, dtype=torch.float32)
|
||||
current_before = current.clone()
|
||||
reference_before = reference.clone()
|
||||
|
||||
encoded, report = soft_reanchor.soft_reanchor_context(
|
||||
current,
|
||||
reference,
|
||||
video_vae=FakeVideoVAE(),
|
||||
strength=0.5,
|
||||
)
|
||||
|
||||
assert encoded.shape == current.shape
|
||||
assert encoded.dtype == current.dtype
|
||||
assert torch.isfinite(encoded).all()
|
||||
assert torch.equal(current, current_before)
|
||||
assert torch.equal(reference, reference_before)
|
||||
assert report["current_context_unchanged"] is True
|
||||
assert report["reference_context_unchanged"] is True
|
||||
assert report["latent_shape_unchanged"] is True
|
||||
|
||||
|
||||
def test_boundary_metrics_report_flow_and_frame_jump():
|
||||
frames = []
|
||||
for index in range(12):
|
||||
frame = np.zeros((24, 24, 3), dtype=np.uint8)
|
||||
frame[:, max(0, min(20, index)) : max(1, min(24, index + 4))] = 80
|
||||
if index >= 6:
|
||||
frame = np.clip(frame + 80, 0, 255).astype(np.uint8)
|
||||
frames.append(frame)
|
||||
rows = analyzer._boundary_metrics(frames, chunks=2)
|
||||
assert len(rows) == 1
|
||||
assert rows[0]["target_group"] == 2
|
||||
assert rows[0]["frame_mae"] > 0.0
|
||||
assert rows[0]["trajectory_flow_discontinuity"] >= 0.0
|
||||
|
||||
|
||||
def test_motion_pair_ab_uses_normal_twenty_step_and_no_turbo():
|
||||
off, off_loras = runner.configure_prompt(
|
||||
_source_prompt(),
|
||||
case="motion_off_3x5_normal",
|
||||
output_prefix="video/test",
|
||||
image_name="closeup.png",
|
||||
seed=1,
|
||||
width=576,
|
||||
height=864,
|
||||
diagnostic_nonce=9,
|
||||
)
|
||||
both, both_loras = runner.configure_prompt(
|
||||
_source_prompt(),
|
||||
case="motion_both_3x5_normal",
|
||||
output_prefix="video/test",
|
||||
image_name="closeup.png",
|
||||
seed=1,
|
||||
width=576,
|
||||
height=864,
|
||||
diagnostic_nonce=10,
|
||||
)
|
||||
assert off_loras == []
|
||||
assert off["153"]["inputs"]["steps"] == 20
|
||||
assert "dynv2" in off["188"]["inputs"]["value"]
|
||||
assert [item["name"] for item in both_loras] == [
|
||||
runner.MOTION_BOOSTER_LORA,
|
||||
runner.MOTION_REPAIR_LORA,
|
||||
]
|
||||
assert both["153"]["inputs"]["steps"] == 20
|
||||
assert all(runner.TURBO_LORA != item["name"] for item in both_loras)
|
||||
|
||||
|
||||
def test_continuation_rgb_proxy_uses_pre_boundary_context_window():
|
||||
frames = [np.full((8, 8, 3), index, dtype=np.uint8) for index in range(30)]
|
||||
result = analyzer._continuation_input_rgb_proxy(
|
||||
frames, chunks=3, context_frames=4
|
||||
)
|
||||
assert result["context_frames"] == 4
|
||||
assert len(result["boundaries"]) == 2
|
||||
first = result["boundaries"][0]
|
||||
assert first["boundary_frame"] == 10
|
||||
assert first["window_start"] == 6
|
||||
assert first["window_end_exclusive"] == 10
|
||||
assert first["window_frames"] == 4
|
||||
assert abs(sum(first["luma_histogram"]) - 1.0) < 1e-9
|
||||
@@ -0,0 +1,213 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import importlib.util
|
||||
from pathlib import Path
|
||||
import sys
|
||||
|
||||
import torch
|
||||
|
||||
|
||||
TOOLS = Path(__file__).parents[1] / "tools"
|
||||
|
||||
|
||||
def _load(name: str, filename: str):
|
||||
path = TOOLS / filename
|
||||
spec = importlib.util.spec_from_file_location(name, path)
|
||||
assert spec is not None and spec.loader is not None
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
sys.modules[name] = module
|
||||
spec.loader.exec_module(module)
|
||||
return module
|
||||
|
||||
|
||||
policy_module = _load(
|
||||
"h3_issue13_r28_continuation_policy",
|
||||
"gpu_diagnostic_node/continuation_policy.py",
|
||||
)
|
||||
runner = _load("h3_issue13_r28_gate_runner", "issue13_r28_gate_runner.py")
|
||||
analyzer = _load("h3_issue13_r28_analyze", "issue13_r28_analyze.py")
|
||||
|
||||
|
||||
class FakeNested:
|
||||
def __init__(self, tensors):
|
||||
self.tensors = tuple(tensors)
|
||||
|
||||
def unbind(self):
|
||||
return self.tensors
|
||||
|
||||
|
||||
def _summary(tensor: torch.Tensor) -> dict:
|
||||
return {
|
||||
"shape": [int(value) for value in tensor.shape],
|
||||
"mean": float(tensor.float().mean().item()),
|
||||
}
|
||||
|
||||
|
||||
def _latent():
|
||||
video = torch.randn((1, 24, 42, 4, 4), generator=torch.Generator().manual_seed(1))
|
||||
audio = torch.randn((1, 32, 2, 235), generator=torch.Generator().manual_seed(2))
|
||||
video_mask = torch.ones((1, 1, 42, 4, 4), dtype=torch.float32)
|
||||
video_mask[:, :, :7] = 0.0
|
||||
audio_mask = torch.ones((1, 1, 2, 235), dtype=torch.float32)
|
||||
audio_mask[..., :37] = 0.0
|
||||
return {
|
||||
"samples": FakeNested((video, audio)),
|
||||
"noise_mask": FakeNested((video_mask, audio_mask)),
|
||||
}
|
||||
|
||||
|
||||
def _apply(mode: str):
|
||||
latent = _latent()
|
||||
original_samples = latent["samples"]
|
||||
original_video_mask, original_audio_mask = [
|
||||
value.clone() for value in latent["noise_mask"].unbind()
|
||||
]
|
||||
policy = policy_module.R28ContinuationPolicy(mode, tensor_summary=_summary)
|
||||
result = policy.prepare_masked_latent(
|
||||
latent=latent,
|
||||
physical_group=2,
|
||||
logical_chunks=(2,),
|
||||
context_frames=22,
|
||||
video_context=torch.zeros((1, 24, 7, 4, 4)),
|
||||
audio_context=torch.zeros((1, 32, 2, 37)),
|
||||
)
|
||||
assert result["samples"] is original_samples
|
||||
assert torch.equal(latent["noise_mask"].unbind()[0], original_video_mask)
|
||||
assert torch.equal(latent["noise_mask"].unbind()[1], original_audio_mask)
|
||||
return policy, result
|
||||
|
||||
|
||||
def test_depth_13_uses_last_four_slots_and_preserves_audio_contract():
|
||||
policy, result = _apply(policy_module.MODE_DEPTH_13)
|
||||
video_mask, audio_mask = result["noise_mask"].unbind()
|
||||
assert policy.active_video_slots == 4
|
||||
assert policy.active_video_frames == 13
|
||||
assert torch.all(video_mask[:, :, :3] == 1)
|
||||
assert torch.all(video_mask[:, :, 3:7] == 0)
|
||||
assert torch.all(video_mask[:, :, 7:] == 1)
|
||||
assert torch.all(audio_mask[..., :37] == 0)
|
||||
assert torch.all(audio_mask[..., 37:] == 1)
|
||||
|
||||
|
||||
def test_depth_9_uses_last_three_slots_only():
|
||||
policy, result = _apply(policy_module.MODE_DEPTH_9)
|
||||
video_mask, _ = result["noise_mask"].unbind()
|
||||
assert policy.active_video_slots == 3
|
||||
assert policy.active_video_frames == 9
|
||||
assert torch.all(video_mask[:, :, :4] == 1)
|
||||
assert torch.all(video_mask[:, :, 4:7] == 0)
|
||||
|
||||
|
||||
def test_strength_75_uses_core_fractional_mask_without_scaling_latent():
|
||||
latent = _latent()
|
||||
source_video, source_audio = latent["samples"].unbind()
|
||||
source_video_before = source_video.clone()
|
||||
source_audio_before = source_audio.clone()
|
||||
policy = policy_module.R28ContinuationPolicy(
|
||||
policy_module.MODE_STRENGTH_75, tensor_summary=_summary
|
||||
)
|
||||
result = policy.prepare_masked_latent(
|
||||
latent=latent,
|
||||
physical_group=2,
|
||||
logical_chunks=(2,),
|
||||
context_frames=22,
|
||||
video_context=torch.zeros((1, 24, 7, 4, 4)),
|
||||
audio_context=torch.zeros((1, 32, 2, 37)),
|
||||
)
|
||||
video_mask, audio_mask = result["noise_mask"].unbind()
|
||||
assert torch.all(video_mask[:, :, :7] == 0.25)
|
||||
assert torch.all(audio_mask[..., :37] == 0)
|
||||
assert torch.equal(source_video, source_video_before)
|
||||
assert torch.equal(source_audio, source_audio_before)
|
||||
|
||||
|
||||
def test_baseline_returns_original_latent_and_mask_objects():
|
||||
latent = _latent()
|
||||
policy = policy_module.R28ContinuationPolicy(
|
||||
policy_module.MODE_BASELINE_22, tensor_summary=_summary
|
||||
)
|
||||
result = policy.prepare_masked_latent(
|
||||
latent=latent,
|
||||
physical_group=2,
|
||||
logical_chunks=(2,),
|
||||
context_frames=22,
|
||||
video_context=torch.zeros((1, 24, 7, 4, 4)),
|
||||
audio_context=torch.zeros((1, 32, 2, 37)),
|
||||
)
|
||||
assert result is latent
|
||||
assert policy.active_video_slots == 7
|
||||
assert policy.active_video_frames == 22
|
||||
|
||||
|
||||
def _source_prompt() -> dict:
|
||||
return {
|
||||
"114": {"inputs": {"image": "old.png"}},
|
||||
"119": {"inputs": {}},
|
||||
"139": {"inputs": {"sampler_name": "old"}},
|
||||
"150": {"inputs": {"enabled": True}},
|
||||
"153": {"inputs": {"scheduler": "old", "steps": 20}},
|
||||
"188": {"inputs": {"value": "old"}},
|
||||
"191": {"inputs": {}},
|
||||
"249": {"inputs": {}},
|
||||
"286": {"inputs": {"lora_1": {"on": False}}},
|
||||
"297": {"inputs": {"value": 0.3}},
|
||||
"305": {
|
||||
"class_type": "H3ContinuumMaskedPrefixR1Diagnostic",
|
||||
"inputs": {
|
||||
"continuation_source_mode": "Recursive",
|
||||
"synchronize_sampling": True,
|
||||
"last_frame": ["900", 0],
|
||||
},
|
||||
},
|
||||
"306": {"inputs": {}},
|
||||
}
|
||||
|
||||
|
||||
def test_runner_changes_only_the_approved_r28_experiment_contract():
|
||||
prompt, loras = runner.configure_prompt(
|
||||
_source_prompt(),
|
||||
case="depth_13f",
|
||||
output_prefix="video/issue13_r28/test",
|
||||
image_name="closeup.png",
|
||||
seed=131325,
|
||||
width=576,
|
||||
height=864,
|
||||
diagnostic_nonce=132800,
|
||||
)
|
||||
inputs = prompt["305"]["inputs"]
|
||||
assert prompt["305"]["class_type"] == "H3ContinuumContinuationR28Diagnostic"
|
||||
assert inputs["continuation_experiment"] == "Video Depth 13f"
|
||||
assert inputs["continuation_transport"] == "masked_av_prefix_22_v1"
|
||||
assert inputs["continuity"] == "Balanced — 22 frames"
|
||||
assert inputs["audio_continuity"] is True
|
||||
assert inputs["chunks"] == 6
|
||||
assert inputs["chunk_seconds"] == 5.0
|
||||
assert "continuation_source_mode" not in inputs
|
||||
assert "synchronize_sampling" not in inputs
|
||||
assert "last_frame" not in inputs
|
||||
assert prompt["188"]["inputs"]["value"].count("\n---\n") == 5
|
||||
assert len(set(prompt["188"]["inputs"]["value"].split("\n---\n"))) == 1
|
||||
assert loras == [{"name": runner.r25.TURBO_LORA, "strength": 1.0}]
|
||||
|
||||
|
||||
def _analysis_case(scale: float) -> dict:
|
||||
rows = []
|
||||
for group in range(1, 7):
|
||||
row = {key: 0.0 for key in analyzer.base.METRIC_KEYS}
|
||||
for key in analyzer.DRIFT_KEYS:
|
||||
row[key] = float(group - 1) * scale
|
||||
rows.append(row)
|
||||
return {
|
||||
"end_trend": analyzer.base._trend(rows, analyzer.base.METRIC_KEYS),
|
||||
"boundary_metrics": [
|
||||
{"trajectory_flow_discontinuity": 0.1} for _ in range(5)
|
||||
],
|
||||
}
|
||||
|
||||
|
||||
def test_comparison_marks_a_clean_half_reduction_promising():
|
||||
result = analyzer._metric_comparison(_analysis_case(1.0), _analysis_case(0.5))
|
||||
assert result["screening_mean_reduction_percent"] == 50.0
|
||||
assert result["sharpness_not_worse"] is True
|
||||
assert result["gradient_not_worse"] is True
|
||||
assert result["numeric_promising"] is True
|
||||
@@ -0,0 +1,139 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import importlib.util
|
||||
from pathlib import Path
|
||||
import sys
|
||||
|
||||
import numpy as np
|
||||
import pytest
|
||||
|
||||
|
||||
TOOLS = Path(__file__).parents[1] / "tools"
|
||||
|
||||
|
||||
def _load(name: str, filename: str):
|
||||
path = TOOLS / filename
|
||||
spec = importlib.util.spec_from_file_location(name, path)
|
||||
assert spec is not None and spec.loader is not None
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
sys.modules[name] = module
|
||||
spec.loader.exec_module(module)
|
||||
return module
|
||||
|
||||
|
||||
runner = _load("h3_issue13_r2_gate_runner", "issue13_r2_gate_runner.py")
|
||||
analyzer = _load("h3_issue13_r2_analyze", "issue13_r2_analyze.py")
|
||||
|
||||
|
||||
def _source_prompt() -> dict:
|
||||
return {
|
||||
"305": {
|
||||
"class_type": "H3ContinuumSamplerV37",
|
||||
"inputs": {
|
||||
"continuation_backend": "Standard",
|
||||
"generation_mode": "Full Run",
|
||||
"review_action": "Continue / Next",
|
||||
"guide": ["900", 0],
|
||||
"last_frame": ["901", 0],
|
||||
},
|
||||
},
|
||||
"188": {"inputs": {"value": "old"}},
|
||||
"153": {"inputs": {"scheduler": "old", "steps": 20, "denoise": 0.5}},
|
||||
"297": {"inputs": {"value": 0.3}},
|
||||
"306": {"inputs": {}},
|
||||
"191": {"inputs": {}},
|
||||
"249": {"inputs": {}},
|
||||
"150": {"inputs": {"enabled": True}},
|
||||
"286": {
|
||||
"inputs": {
|
||||
"lora_1": {"on": True, "lora": "turbo.safetensors", "strength": 1.0}
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
def test_g1_configures_reported_six_by_ten_masked_av_baseline():
|
||||
prompt = runner.configure_prompt(
|
||||
_source_prompt(),
|
||||
case="g1_standard_6x10",
|
||||
output_prefix="video/test",
|
||||
seed=130013,
|
||||
steps=8,
|
||||
size=384,
|
||||
diagnostic_nonce=7,
|
||||
)
|
||||
sampler = prompt["305"]
|
||||
inputs = sampler["inputs"]
|
||||
assert sampler["class_type"] == "H3ContinuumMaskedPrefixR1Diagnostic"
|
||||
assert inputs["chunks"] == 6
|
||||
assert inputs["chunk_seconds"] == 10.0
|
||||
assert inputs["continuation_transport"] == "masked_av_prefix_22_v1"
|
||||
assert inputs["continuity"] == "Balanced — 22 frames"
|
||||
assert inputs["audio_continuity"] is True
|
||||
assert inputs["run_storage"] == "Off"
|
||||
assert "continuation_backend" not in inputs
|
||||
assert "guide" not in inputs
|
||||
assert "last_frame" not in inputs
|
||||
assert prompt["188"]["inputs"]["value"].count("\n---\n") == 5
|
||||
assert prompt["150"]["inputs"]["enabled"] is False
|
||||
assert prompt["286"]["inputs"]["lora_1"]["on"] is False
|
||||
assert prompt["306"]["inputs"]["video_seam"] == "Off"
|
||||
assert prompt["306"]["inputs"]["audio_seam"] == "Off"
|
||||
|
||||
|
||||
def test_g2_keeps_old_five_by_five_comparison_shape():
|
||||
prompt = runner.configure_prompt(
|
||||
_source_prompt(),
|
||||
case="g2_standard_5x5",
|
||||
output_prefix="video/test",
|
||||
seed=130013,
|
||||
steps=8,
|
||||
size=384,
|
||||
diagnostic_nonce=8,
|
||||
)
|
||||
inputs = prompt["305"]["inputs"]
|
||||
assert inputs["chunks"] == 5
|
||||
assert inputs["chunk_seconds"] == 5.0
|
||||
assert prompt["188"]["inputs"]["value"].count("\n---\n") == 4
|
||||
|
||||
|
||||
def test_diagnostic_payload_is_extracted_from_status_suffix():
|
||||
assert runner._diagnostic_from_status(
|
||||
'Production status\nV3.6-R1 diagnostic: {"transport":"masked_av_prefix_22_v1"}'
|
||||
) == {"transport": "masked_av_prefix_22_v1"}
|
||||
|
||||
|
||||
def test_decoded_metrics_include_local_sharpness():
|
||||
frame = np.zeros((32, 32, 3), dtype=np.uint8)
|
||||
frame[:, 16:] = 255
|
||||
metrics = analyzer._frame_metrics(frame)
|
||||
assert metrics["contrast_p95_p05"] == 1.0
|
||||
assert metrics["sharpness_laplacian_variance"] > 0.0
|
||||
assert metrics["gradient_mean"] > 0.0
|
||||
|
||||
|
||||
def test_latent_trend_requires_bit_exact_continuation_prefixes():
|
||||
diagnostic = {
|
||||
"sample_calls": [
|
||||
{"sample_number": 1, "output_tail": {"rms": 1.0, "std": 0.5}},
|
||||
{
|
||||
"sample_number": 2,
|
||||
"source_tail": {"rms": 1.0, "std": 0.5},
|
||||
"output_tail": {"rms": 1.2, "std": 0.7},
|
||||
},
|
||||
],
|
||||
"final_prefix_pairs": [
|
||||
{
|
||||
"bit_exact": True,
|
||||
"audio_bit_exact": True,
|
||||
"max_abs_diff": 0.0,
|
||||
"audio_max_abs_diff": 0.0,
|
||||
}
|
||||
],
|
||||
}
|
||||
result = analyzer._latent_trend(diagnostic)
|
||||
assert result["all_video_prefix_pairs_bit_exact"] is True
|
||||
assert result["all_audio_prefix_pairs_bit_exact"] is True
|
||||
trend = result["streams"]["output_tail"]["trend"]["rms"]
|
||||
assert trend["last_minus_first"] == pytest.approx(0.2)
|
||||
assert trend["increase_steps"] == 1
|
||||
@@ -0,0 +1,54 @@
|
||||
"""Issue #30 overhead regression, with the independent Inspector bug tracked."""
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import subprocess
|
||||
|
||||
import pytest
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
|
||||
|
||||
def run_frontend(filename):
|
||||
node = shutil.which("node")
|
||||
assert node, "Node.js is required for frontend regression tests"
|
||||
return subprocess.run(
|
||||
[node, str(ROOT / "tests" / filename)],
|
||||
env={**os.environ, "H3_TEST_ROOT": str(ROOT)},
|
||||
capture_output=True, text=True, encoding="utf-8", timeout=45,
|
||||
)
|
||||
|
||||
|
||||
def test_reference_selection_notifications_and_layout():
|
||||
result = run_frontend("frontend_reference_images_v39.cjs")
|
||||
assert result.returncode == 0, result.stdout + result.stderr
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def issue30_results():
|
||||
result = run_frontend("frontend_issue30_ui.cjs")
|
||||
assert result.returncode == 0, result.stdout + result.stderr
|
||||
records = json.loads(result.stdout)
|
||||
assert len(records) == 9
|
||||
for record in records:
|
||||
if record["knownIssue"] and not record["pass"]:
|
||||
assert "an invalidated plan must not keep its verified display" in record.get("error", ""), record
|
||||
return {record["name"]: record for record in records}
|
||||
|
||||
|
||||
@pytest.mark.parametrize("name", [
|
||||
"no Review baseline: draw does not traverse upstream settings",
|
||||
"Review baseline: every draw still detects upstream edits",
|
||||
*[f"{node_class}: {change} edit keeps immediate Take and draw guards"
|
||||
for node_class in ("H3ContinuumSamplerV38", "H3ContinuumSamplerV39")
|
||||
for change in ("widget", "link")],
|
||||
"Reference Inspector stays current after 1 configure passes",
|
||||
pytest.param("Reference Inspector stays current after 2 configure passes", marks=pytest.mark.xfail(
|
||||
strict=True, reason="Independent Inspector refresh hook is lost on Sampler reconfigure")),
|
||||
pytest.param("Reference Inspector stays current after 100 configure passes", marks=pytest.mark.xfail(
|
||||
strict=True, reason="Independent Inspector refresh hook is lost on Sampler reconfigure")),
|
||||
])
|
||||
def test_issue30_frontend_paths(issue30_results, name):
|
||||
record = issue30_results[name]
|
||||
assert record["pass"], record.get("error", name)
|
||||
@@ -0,0 +1,381 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import ast
|
||||
import copy
|
||||
import json
|
||||
import subprocess
|
||||
import sys
|
||||
import types
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
import torch
|
||||
|
||||
from ComfyUI_H3_Continuum_Join import run_storage as storage
|
||||
from . import test_v31_run_storage as signatures
|
||||
from . import test_v38_review_run_storage as review
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def core_attention(require_comfy_core, monkeypatch):
|
||||
import comfy.ldm.modules.attention as attention
|
||||
import comfy.model_patcher as patcher
|
||||
# A CPU build may not advertise INT8. Inspect the real loaded definition;
|
||||
# registration here is a fixture, not an assertion that a CPU kernel runs.
|
||||
monkeypatch.setitem(attention.REGISTERED_ATTENTION_FUNCTIONS, "comfy_kitchen_int8",
|
||||
attention.attention_comfy_kitchen_int8)
|
||||
return attention, patcher
|
||||
|
||||
|
||||
def model_with(core, name):
|
||||
attention, patcher = core
|
||||
torch.manual_seed(31)
|
||||
model = signatures._Model()
|
||||
model.model_options["transformer_options"] = {}
|
||||
patcher.ModelPatcher.set_model_optimized_attention(
|
||||
model, attention.REGISTERED_ATTENTION_FUNCTIONS[name])
|
||||
return model
|
||||
|
||||
|
||||
def observe(model):
|
||||
return storage._model_signature(model, "fixture")
|
||||
|
||||
|
||||
def remake(core, monkeypatch, name, *, raw_code=None, defaults=None):
|
||||
attention, _ = core
|
||||
old = attention.REGISTERED_ATTENTION_FUNCTIONS[name]
|
||||
raw = old.__wrapped__
|
||||
new = types.FunctionType(raw_code or raw.__code__, raw.__globals__,
|
||||
raw.__name__, raw.__defaults__ if defaults is None else defaults,
|
||||
raw.__closure__)
|
||||
new.__module__, new.__qualname__ = raw.__module__, raw.__qualname__
|
||||
new.__kwdefaults__ = copy.copy(raw.__kwdefaults__)
|
||||
new.__dict__.update(raw.__dict__)
|
||||
wrapped = attention.wrap_attn(new)
|
||||
wrapped.container_function = old.container_function
|
||||
monkeypatch.setitem(attention.REGISTERED_ATTENTION_FUNCTIONS, name, wrapped)
|
||||
monkeypatch.setattr(attention, "attention_" + name, wrapped)
|
||||
return wrapped
|
||||
|
||||
|
||||
@pytest.mark.parametrize("backend", ["pytorch", "comfy_kitchen_int8"])
|
||||
def test_real_core_backend_is_finite_clone_stable_and_non_mutating(core_attention, monkeypatch, backend):
|
||||
model = model_with(core_attention, backend)
|
||||
wrapped = core_attention[0].REGISTERED_ATTENTION_FUNCTIONS[backend]
|
||||
override = model.model_options["transformer_options"]["optimized_attention_override"]
|
||||
original = (dict(vars(wrapped)), dict(vars(override)), copy.copy(model.model_options))
|
||||
watched = {wrapped.__code__, wrapped.__wrapped__.__code__}
|
||||
if wrapped.container_function:
|
||||
watched.add(wrapped.container_function.__code__)
|
||||
calls = []
|
||||
previous = sys.getprofile()
|
||||
sys.setprofile(lambda frame, event, arg: calls.append(frame.f_code.co_name)
|
||||
if event == "call" and frame.f_code in watched else None)
|
||||
try:
|
||||
before, safe = observe(model)
|
||||
finally:
|
||||
sys.setprofile(previous)
|
||||
assert safe, before["model_options"]
|
||||
assert not calls
|
||||
assert original == (vars(wrapped), vars(override), model.model_options)
|
||||
cloned, cloned_safe = observe(copy.deepcopy(model))
|
||||
assert cloned_safe and cloned == before
|
||||
remake(core_attention, monkeypatch, backend)
|
||||
recreated, recreated_safe = observe(model_with(core_attention, backend))
|
||||
assert recreated_safe and recreated == before
|
||||
attention = before["model_options"]["transformer_options"]["optimized_attention_override"]
|
||||
assert attention["backend"] == backend
|
||||
assert attention["core_attention_signature_version"] == 1
|
||||
assert attention["wrapper"]["closure"][-1]["value"] == {"reference": "wrapper"}
|
||||
|
||||
|
||||
def test_pytorch_and_kitchen_are_distinct(core_attention):
|
||||
a, safe_a = observe(model_with(core_attention, "pytorch"))
|
||||
b, safe_b = observe(model_with(core_attention, "comfy_kitchen_int8"))
|
||||
assert safe_a and safe_b and a != b
|
||||
|
||||
|
||||
@pytest.mark.parametrize("backend", ["pytorch", "comfy_kitchen_int8"])
|
||||
@pytest.mark.parametrize("change", ["code", "defaults", "helper"])
|
||||
def test_attention_implementation_changes_identity(core_attention, monkeypatch, backend, change):
|
||||
before, safe = observe(model_with(core_attention, backend))
|
||||
assert safe
|
||||
attention, _ = core_attention
|
||||
if change == "code":
|
||||
raw = attention.REGISTERED_ATTENTION_FUNCTIONS[backend].__wrapped__
|
||||
def change_constant(c):
|
||||
if isinstance(c, tuple):
|
||||
return tuple(change_constant(v) for v in c)
|
||||
return "changed_scale" if c == "scale" else c
|
||||
constants = tuple(change_constant(c) for c in raw.__code__.co_consts)
|
||||
assert constants != raw.__code__.co_consts
|
||||
remake(core_attention, monkeypatch, backend, raw_code=raw.__code__.replace(co_consts=constants))
|
||||
elif change == "defaults":
|
||||
raw = attention.REGISTERED_ATTENTION_FUNCTIONS[backend].__wrapped__
|
||||
remake(core_attention, monkeypatch, backend, defaults=(17,) + raw.__defaults__[1:])
|
||||
else:
|
||||
helper = attention._heads_from_dim
|
||||
constants = tuple(2 if c == 0 else c for c in helper.__code__.co_consts)
|
||||
monkeypatch.setattr(attention, "_heads_from_dim",
|
||||
types.FunctionType(helper.__code__.replace(co_consts=constants),
|
||||
helper.__globals__, helper.__name__))
|
||||
after, after_safe = observe(model_with(core_attention, backend))
|
||||
assert after_safe and after != before
|
||||
|
||||
|
||||
@pytest.mark.parametrize("slot", ["inner", "outer"])
|
||||
@pytest.mark.parametrize("kind", ["function", "opaque", "none"])
|
||||
def test_container_changes_are_recorded_and_cannot_be_certified(core_attention, monkeypatch, slot, kind):
|
||||
model = model_with(core_attention, "comfy_kitchen_int8")
|
||||
before, safe = observe(model)
|
||||
assert safe
|
||||
target = (core_attention[0].attention_comfy_kitchen_int8 if slot == "inner" else
|
||||
model.model_options["transformer_options"]["optimized_attention_override"])
|
||||
class Opaque:
|
||||
__slots__ = ()
|
||||
def __call__(self, *args):
|
||||
raise AssertionError("signature must not invoke container")
|
||||
def replacement(*args):
|
||||
raise AssertionError("signature must not invoke container")
|
||||
value = {"function": replacement, "opaque": Opaque(), "none": None}[kind]
|
||||
monkeypatch.setattr(target, "container_function", value)
|
||||
after, safe_after = observe(model)
|
||||
assert after != before and not safe_after
|
||||
|
||||
|
||||
def test_unrelated_opaque_cfg_is_not_promoted(core_attention):
|
||||
model = model_with(core_attention, "pytorch")
|
||||
assert observe(model)[1]
|
||||
model.model_options["sampler_cfg_function"] = object()
|
||||
assert not observe(model)[1]
|
||||
contract, safe, reasons = signatures._sampling_contract(model=model)
|
||||
assert contract and not safe and reasons
|
||||
assert contract["global"]["sampling_contract_version"] == 6
|
||||
|
||||
|
||||
def test_unregistered_or_foreign_setter_keeps_generic_policy(core_attention, monkeypatch):
|
||||
attention, patcher = core_attention
|
||||
model = model_with(core_attention, "pytorch")
|
||||
callback = model.model_options["transformer_options"]["optimized_attention_override"]
|
||||
monkeypatch.delitem(attention.REGISTERED_ATTENTION_FUNCTIONS, "pytorch")
|
||||
assert storage._observe_model_options(model.model_options) == storage._observe(model.model_options)
|
||||
assert not observe(model)[1]
|
||||
def foreign(_, *args, **kwargs):
|
||||
return None
|
||||
model.model_options["transformer_options"]["optimized_attention_override"] = foreign
|
||||
assert storage._observe_model_options(model.model_options) == storage._observe(model.model_options)
|
||||
assert model.model_options["transformer_options"]["optimized_attention_override"] is foreign
|
||||
assert callback is not foreign
|
||||
|
||||
|
||||
def test_missing_provider_and_unknown_native_binding_are_unsafe(core_attention, monkeypatch):
|
||||
model = model_with(core_attention, "pytorch")
|
||||
monkeypatch.setattr(torch.nn.functional, "scaled_dot_product_attention", lambda *a: 0)
|
||||
result, safe = observe(model)
|
||||
assert not safe
|
||||
assert "observation_error" in result["model_options"]["transformer_options"]["optimized_attention_override"]
|
||||
|
||||
|
||||
def test_no_override_existing_v6_contract_is_byte_equivalent(monkeypatch):
|
||||
torch.manual_seed(31)
|
||||
model, clip, vae = signatures._Model(), signatures._Clip(), signatures._VideoVAE()
|
||||
model.model_options = {"transformer_options": {}, "disable_cfg1_optimization": True}
|
||||
# Use the actual pre-repair function, not an expected hash generated by the fix.
|
||||
original = subprocess.check_output(["git", "-C", str(ROOT), "show", "HEAD:run_storage.py"], text=True)
|
||||
node = next(n for n in ast.parse(original).body if isinstance(n, ast.FunctionDef) and n.name == "_model_signature")
|
||||
scope = dict(vars(storage))
|
||||
exec(compile(ast.Module(body=[node], type_ignores=[]), "original_model_signature.py", "exec"), scope)
|
||||
before, safe_before, _ = signatures._sampling_contract(model=model, clip=clip, video_vae=vae, reroll_from_chunk=0)
|
||||
with monkeypatch.context() as context:
|
||||
context.setattr(storage, "_model_signature", scope["_model_signature"])
|
||||
legacy, safe_legacy, _ = signatures._sampling_contract(model=model, clip=clip, video_vae=vae, reroll_from_chunk=0)
|
||||
assert safe_before and safe_legacy
|
||||
assert storage._canonical(before) == storage._canonical(legacy)
|
||||
assert storage.revision_identity(before) == storage.revision_identity(legacy)
|
||||
assert storage.SAMPLING_CONTRACT_VERSION == 6 and storage.RUNTIME_SIGNATURE_VERSION == 1
|
||||
|
||||
|
||||
def test_ordinary_custom_override_keeps_existing_descriptor():
|
||||
model = signatures._Model()
|
||||
model.model_options = {"transformer_options": {"optimized_attention_override": lambda x: x}}
|
||||
assert storage._observe_model_options(model.model_options) == storage._observe(model.model_options)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("backend", ["pytorch", "comfy_kitchen_int8"])
|
||||
def test_same_backend_reuses_prefix_but_changed_backend_does_not(tmp_path, core_attention, backend):
|
||||
model = model_with(core_attention, backend)
|
||||
torch.manual_seed(31)
|
||||
clip, vae = signatures._Clip(), signatures._VideoVAE()
|
||||
contract, safe, _ = signatures._sampling_contract(model=model, clip=clip, video_vae=vae, reroll_from_chunk=0)
|
||||
assert safe
|
||||
source = review._persist(tmp_path, contract, prefix=1, review_unit=(1, 1),
|
||||
updated_utc="2026-10-14T00:00:00+00:00")
|
||||
before_files = {str(p):p.read_bytes() for p in source.run_root.rglob("*") if p.is_file()}
|
||||
same, same_safe, _ = signatures._sampling_contract(model=copy.deepcopy(model), clip=clip, video_vae=vae, reroll_from_chunk=0)
|
||||
assert same_safe and storage.revision_identity(same) == storage.revision_identity(contract)
|
||||
reader = review._controller(tmp_path, same)
|
||||
reader.configure_review(generation_mode=review.GENERATION_MODE_REVIEW, review_action=review.REVIEW_ACTION_CONTINUE)
|
||||
prefix = reader._load_validated_review_prefix(same, resume_safe=same_safe)
|
||||
assert len(prefix.entries) == 1
|
||||
other = "pytorch" if backend == "comfy_kitchen_int8" else "comfy_kitchen_int8"
|
||||
changed, changed_safe, _ = signatures._sampling_contract(model=model_with(core_attention, other),
|
||||
clip=clip, video_vae=vae, reroll_from_chunk=0)
|
||||
assert changed_safe and storage.revision_identity(changed) != storage.revision_identity(contract)
|
||||
changed_reader = review._controller(tmp_path, changed)
|
||||
changed_reader.configure_review(generation_mode=review.GENERATION_MODE_REVIEW, review_action=review.REVIEW_ACTION_CONTINUE)
|
||||
assert not changed_reader._load_validated_review_prefix(changed, resume_safe=changed_safe).entries
|
||||
assert before_files == {str(p):p.read_bytes() for p in source.run_root.rglob("*") if p.is_file()}
|
||||
|
||||
|
||||
@pytest.mark.parametrize("entry_point", ["review", "head", "import", "compatible", "take"])
|
||||
def test_old_unsafe_attention_manifest_stays_read_only_and_unmodified(tmp_path, core_attention, monkeypatch, entry_point):
|
||||
model = model_with(core_attention, "pytorch")
|
||||
options = model.model_options
|
||||
# Original depth-limited observation, producing the old unsafe v6 contract.
|
||||
with monkeypatch.context() as context:
|
||||
context.setattr(storage, "_observe_model_options", storage._observe)
|
||||
old, old_safe, reasons = signatures._sampling_contract(model=model, reroll_from_chunk=0)
|
||||
assert not old_safe and reasons
|
||||
source = review._persist(tmp_path, old, prefix=1, review_unit=(1, 1),
|
||||
updated_utc="2026-10-14T00:00:00+00:00")
|
||||
source.manifest["resume_safe"] = False
|
||||
source.manifest["resume_disabled_reasons"] = reasons
|
||||
source._write_manifest()
|
||||
before = {str(p):p.read_bytes() for p in source.run_root.rglob("*") if p.is_file()}
|
||||
reader = review._controller(tmp_path, old)
|
||||
reader.configure_review(generation_mode=review.GENERATION_MODE_REVIEW, review_action=review.REVIEW_ACTION_CONTINUE)
|
||||
assert storage._reusable_manifest(source.manifest) is False
|
||||
if entry_point == "review":
|
||||
assert not reader._load_validated_review_prefix(old, resume_safe=True).entries
|
||||
elif entry_point == "head":
|
||||
assert reader.find_latest_review_head(old, resume_safe=True) is None
|
||||
elif entry_point == "import":
|
||||
assert reader._find_plan_import(old, resume_safe=True) is None
|
||||
elif entry_point == "compatible":
|
||||
assert reader._compatible_plan_prefix(source.manifest, old, resume_safe=True) == ([], [])
|
||||
else:
|
||||
reader.take_group = 1
|
||||
reader.take_revision_id = review._project(source)["canonical_head_revision_id"]
|
||||
with pytest.raises(storage.RunStorageError, match="read-only"):
|
||||
reader._validated_take_selection(old, resume_safe=True)
|
||||
assert before == {str(p):p.read_bytes() for p in source.run_root.rglob("*") if p.is_file()}
|
||||
|
||||
|
||||
def test_provider_policy_changes_are_observed(core_attention, monkeypatch):
|
||||
import comfy_kitchen.sage_attention as kitchen_attention
|
||||
model = model_with(core_attention, "comfy_kitchen_int8")
|
||||
before, safe = observe(model)
|
||||
assert safe
|
||||
monkeypatch.setattr(kitchen_attention, "LARGE_CTA_K", kitchen_attention.LARGE_CTA_K + 1)
|
||||
after, safe_after = observe(model)
|
||||
assert safe_after and before != after
|
||||
@pytest.mark.parametrize("slot", ["setter_globals", "raw_globals", "wrapper_code"])
|
||||
def test_lookalike_core_structure_is_not_promoted(core_attention, monkeypatch, slot):
|
||||
attention, _ = core_attention
|
||||
model = model_with(core_attention, "pytorch")
|
||||
if slot == "setter_globals":
|
||||
value = model.model_options["transformer_options"]["optimized_attention_override"]
|
||||
value = types.FunctionType(value.__code__, dict(value.__globals__), value.__name__,
|
||||
value.__defaults__, value.__closure__)
|
||||
model.model_options["transformer_options"]["optimized_attention_override"] = value
|
||||
elif slot == "raw_globals":
|
||||
wrapped = attention.attention_pytorch
|
||||
raw = wrapped.__wrapped__
|
||||
new = types.FunctionType(raw.__code__, dict(raw.__globals__), raw.__name__,
|
||||
raw.__defaults__, raw.__closure__)
|
||||
wrapped = attention.wrap_attn(new)
|
||||
monkeypatch.setitem(attention.REGISTERED_ATTENTION_FUNCTIONS, "pytorch", wrapped)
|
||||
monkeypatch.setattr(attention, "attention_pytorch", wrapped)
|
||||
model = model_with(core_attention, "pytorch")
|
||||
else:
|
||||
wrapped = attention.attention_pytorch
|
||||
monkeypatch.setattr(wrapped, "__code__", wrapped.__code__.replace(
|
||||
co_consts=wrapped.__code__.co_consts + ("unrecognized wrapper",)))
|
||||
assert not observe(model)[1]
|
||||
|
||||
|
||||
def test_torch_dispatch_flag_changes_identity(core_attention):
|
||||
model = model_with(core_attention, "pytorch")
|
||||
enabled = torch.backends.cuda.math_sdp_enabled()
|
||||
before, safe = observe(model)
|
||||
assert safe
|
||||
try:
|
||||
torch.backends.cuda.enable_math_sdp(not enabled)
|
||||
after, after_safe = observe(model)
|
||||
assert after_safe and after != before
|
||||
finally:
|
||||
torch.backends.cuda.enable_math_sdp(enabled)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("backend", ["pytorch", "comfy_kitchen_int8"])
|
||||
def test_signature_is_stable_in_separate_processes_and_hash_seeds(core_attention, backend):
|
||||
import os
|
||||
import comfy
|
||||
core_root = str(Path(core_attention[1].__file__).resolve().parent.parent)
|
||||
script = r"""
|
||||
import importlib.util,json,os,sys
|
||||
sys.path.insert(0,CORE_ROOT)
|
||||
os.environ["CUDA_VISIBLE_DEVICES"]="-1"
|
||||
import torch
|
||||
torch.cuda._lazy_init=lambda: (_ for _ in ()).throw(RuntimeError("CUDA forbidden"))
|
||||
from comfy.cli_args import args
|
||||
args.cpu=True
|
||||
from comfy.ldm.modules import attention
|
||||
from comfy import model_patcher
|
||||
name="ComfyUI_H3_Continuum_Join"
|
||||
spec=importlib.util.spec_from_file_location(name,ROOT+"/__init__.py",submodule_search_locations=[ROOT])
|
||||
sys.modules[name]=importlib.util.module_from_spec(spec)
|
||||
from ComfyUI_H3_Continuum_Join import run_storage as s
|
||||
from types import SimpleNamespace
|
||||
class Model:
|
||||
def __init__(self):
|
||||
self.model=SimpleNamespace(diffusion_model=torch.nn.Linear(2,2))
|
||||
self.wrappers={}
|
||||
self.patches={}
|
||||
self.model_options={"transformer_options":{}}
|
||||
def model_dtype(self): return torch.float32
|
||||
def model_size(self): return 4
|
||||
torch.manual_seed(31)
|
||||
model=Model()
|
||||
attention.REGISTERED_ATTENTION_FUNCTIONS["comfy_kitchen_int8"]=attention.attention_comfy_kitchen_int8
|
||||
model_patcher.ModelPatcher.set_model_optimized_attention(model,attention.REGISTERED_ATTENTION_FUNCTIONS[BACKEND])
|
||||
descriptor,safe=s._model_signature(model,"fixture")
|
||||
assert safe,descriptor["model_options"]
|
||||
print(s._hash(descriptor))
|
||||
"""
|
||||
script = "CORE_ROOT="+repr(core_root)+"\nROOT="+repr(str(ROOT))+"\nBACKEND="+repr(backend)+"\n"+script
|
||||
results = []
|
||||
for seed in ("1", "93017"):
|
||||
result = subprocess.run([sys.executable, "-B", "-c", script],
|
||||
env={**os.environ, "CUDA_VISIBLE_DEVICES":"-1", "PYTHONHASHSEED":seed},
|
||||
capture_output=True, text=True, timeout=90)
|
||||
assert result.returncode == 0, result.stderr + result.stdout
|
||||
results.append(result.stdout.strip().splitlines()[-1])
|
||||
assert results[0] == results[1]
|
||||
def test_unobservable_global_helper_state_stays_unsafe(core_attention, monkeypatch):
|
||||
attention, _ = core_attention
|
||||
model = model_with(core_attention, "pytorch")
|
||||
before, safe = observe(model)
|
||||
assert safe
|
||||
scope = vars(attention)
|
||||
exec("def issue31_helper(*args):\n return ISSUE31_UNOBSERVABLE_STATE", scope)
|
||||
try:
|
||||
monkeypatch.setattr(attention, "ISSUE31_UNOBSERVABLE_STATE", object(), raising=False)
|
||||
monkeypatch.setattr(attention, "_heads_from_dim", scope["issue31_helper"])
|
||||
after, after_safe = observe(model)
|
||||
assert after != before and not after_safe
|
||||
finally:
|
||||
scope.pop("issue31_helper", None)
|
||||
|
||||
|
||||
def test_fallback_pytorch_implementation_changes_kitchen_identity(core_attention, monkeypatch):
|
||||
attention, _ = core_attention
|
||||
model = model_with(core_attention, "comfy_kitchen_int8")
|
||||
before, safe = observe(model)
|
||||
assert safe
|
||||
raw = attention.attention_pytorch.__wrapped__
|
||||
remake(core_attention, monkeypatch, "pytorch", defaults=(19,) + raw.__defaults__[1:])
|
||||
after, after_safe = observe(model)
|
||||
assert after != before
|
||||
@@ -0,0 +1,328 @@
|
||||
"""Phase A: real audited KJ wrapper, CPU-only observation and Run Storage gates."""
|
||||
from __future__ import annotations
|
||||
|
||||
import importlib
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
import types
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
import torch
|
||||
from PIL import Image
|
||||
|
||||
from ComfyUI_H3_Continuum_Join import preview_override_signature as adapter
|
||||
from ComfyUI_H3_Continuum_Join import run_storage as storage
|
||||
from . import test_v31_run_storage as signatures
|
||||
from . import test_v38_review_run_storage as review
|
||||
from . import test_issue31_attention_signature as attention
|
||||
from .test_issue31_attention_signature import core_attention
|
||||
from .test_issue31_spectrum_signature import spectrum, binding
|
||||
|
||||
|
||||
@pytest.fixture(params=["local", "public"])
|
||||
def kj(require_comfy_core, request):
|
||||
root = os.environ.get("H3_KJ_PREVIEW_TEST_ROOT" if request.param == "local" else "H3_KJ_PREVIEW_PUBLIC_TEST_ROOT")
|
||||
if not root:
|
||||
pytest.skip("real audited KJ Preview Override provider is not configured")
|
||||
package = types.ModuleType("issue31_kj_preview_tests_" + request.param)
|
||||
package.__path__ = [str(Path(root) / "nodes")]
|
||||
sys.modules[package.__name__] = package
|
||||
return importlib.import_module(package.__name__ + ".preview_override_node")
|
||||
|
||||
|
||||
def wrapper(kj, **settings):
|
||||
values = dict(max_resolution=512, node_id="100", jpeg_quality=90,
|
||||
suppress_default=True, preview_frames=1, preview_fps=12)
|
||||
values.update(settings)
|
||||
return kj._PreviewOverrideWrapper(**values)
|
||||
|
||||
|
||||
def model_with(item):
|
||||
model = signatures._Model()
|
||||
model.wrappers = {"outer_sample": {"kj_preview_override": [item]}}
|
||||
return model
|
||||
|
||||
|
||||
def observe(model):
|
||||
return storage._model_signature(model, "fixture")
|
||||
|
||||
|
||||
def test_no_kj_observer_and_full_sampling_contract_are_exact(monkeypatch):
|
||||
model = signatures._Model()
|
||||
model.wrappers = {"outer_sample": {"other": [lambda executor: executor()]}}
|
||||
current = observe(model)
|
||||
torch.manual_seed(31016)
|
||||
clip, vae = signatures._Clip(), signatures._VideoVAE()
|
||||
contract = signatures._sampling_contract(model=model, clip=clip, video_vae=vae, reroll_from_chunk=0)
|
||||
with monkeypatch.context() as ctx:
|
||||
ctx.setattr(storage, "observe_model_wrappers", lambda value, observer: observer(value))
|
||||
assert observe(model) == current
|
||||
old = signatures._sampling_contract(model=model, clip=clip, video_vae=vae, reroll_from_chunk=0)
|
||||
assert storage._canonical(contract) == storage._canonical(old)
|
||||
assert storage.revision_identity(contract[0]) == storage.revision_identity(old[0])
|
||||
|
||||
|
||||
def test_real_provider_frames_and_recreated_wrapper_keep_contract(kj):
|
||||
item = wrapper(kj)
|
||||
model = model_with(item)
|
||||
before = observe(model)
|
||||
assert before[1], before[0]
|
||||
clip, vae = signatures._Clip(), signatures._VideoVAE()
|
||||
original = signatures._sampling_contract(model=model, clip=clip, video_vae=vae, reroll_from_chunk=0)
|
||||
assert original[1]
|
||||
for count in (1, 3, 0):
|
||||
item.frames[:] = [Image.new("RGB", (2, 2)) for _ in range(count)]
|
||||
frames = item.frames
|
||||
state = dict(vars(item))
|
||||
assert observe(model) == before
|
||||
current = signatures._sampling_contract(model=model, clip=clip, video_vae=vae, reroll_from_chunk=0)
|
||||
assert current == original
|
||||
assert vars(item) == state and item.frames is frames
|
||||
model.wrappers["outer_sample"]["kj_preview_override"] = [wrapper(kj)]
|
||||
assert observe(model) == before
|
||||
|
||||
|
||||
@pytest.mark.parametrize("setting,value", [("max_resolution", 768), ("node_id", "101"),
|
||||
("jpeg_quality", 80), ("suppress_default", False), ("preview_frames", 4), ("preview_fps", 24)])
|
||||
def test_every_fixed_setting_changes_identity(kj, setting, value):
|
||||
item = wrapper(kj)
|
||||
before, safe = adapter.preview_override_signature(item)
|
||||
assert safe, before
|
||||
setattr(item, setting, value)
|
||||
after, safe = adapter.preview_override_signature(item)
|
||||
assert safe and after != before
|
||||
|
||||
|
||||
def test_full_audit_profile_is_part_of_identity(kj, monkeypatch):
|
||||
item = wrapper(kj)
|
||||
before, safe = adapter.preview_override_signature(item)
|
||||
assert safe
|
||||
# An audit revision must change identity even with the same display ID and
|
||||
# wrapper source, so dependency-profile upgrades cannot reuse old Takes.
|
||||
profile, _ = adapter._provider_source(kj.__file__)
|
||||
monkeypatch.setitem(profile, "audit_revision", 2)
|
||||
after, safe = adapter.preview_override_signature(item)
|
||||
assert safe and before["profile"] == after["profile"]
|
||||
assert before["profile_sha256"] != after["profile_sha256"]
|
||||
|
||||
|
||||
def other_wrapper(executor, *args, **kwargs):
|
||||
return executor(*args, **kwargs)
|
||||
|
||||
|
||||
def test_key_and_list_execution_order_change_identity(kj):
|
||||
a, b = wrapper(kj), wrapper(kj, jpeg_quality=80)
|
||||
model = model_with(a)
|
||||
model.wrappers["outer_sample"] = {"other": [other_wrapper], "kj_preview_override": [a, b]}
|
||||
before, safe = observe(model)
|
||||
assert safe
|
||||
model.wrappers["outer_sample"] = {"kj_preview_override": [a, b], "other": [other_wrapper]}
|
||||
after, safe = observe(model)
|
||||
assert safe and after != before
|
||||
model.wrappers["outer_sample"]["kj_preview_override"] = [b, a]
|
||||
reordered, safe = observe(model)
|
||||
assert safe and reordered != after
|
||||
|
||||
|
||||
@pytest.mark.parametrize("change", ["source", "call_code", "helper_code", "defaults", "class_attribute",
|
||||
"instance_attribute", "frames_tuple", "frames_subclass", "vae", "audio_vae", "tiny_vae",
|
||||
"foreign", "subclass", "invalid_setting", "core_factory", "imported_helper_code",
|
||||
"core_preview_code", "dispatcher_code", "core_tiny_vae"])
|
||||
def test_unknown_implementations_and_out_of_scope_state_reject_reuse(kj, monkeypatch, change):
|
||||
item = wrapper(kj)
|
||||
if change == "source":
|
||||
profile, _ = adapter._provider_source(kj.__file__)
|
||||
monkeypatch.setitem(profile, "source_sha256", "f" * 64)
|
||||
elif change in ("call_code", "helper_code"):
|
||||
fn = type(item).__call__ if change == "call_code" else kj._normalize_packed_x0
|
||||
monkeypatch.setattr(fn, "__code__", fn.__code__.replace(co_consts=fn.__code__.co_consts + ("changed",)))
|
||||
elif change == "defaults":
|
||||
monkeypatch.setattr(type(item).__init__, "__defaults__", (2, 12, None, "none", None))
|
||||
elif change == "class_attribute":
|
||||
monkeypatch.setattr(type(item), "unrecognized", True, raising=False)
|
||||
elif change == "instance_attribute":
|
||||
item.unrecognized = True
|
||||
elif change == "frames_tuple":
|
||||
item.frames = ()
|
||||
elif change == "frames_subclass":
|
||||
class Frames(list):
|
||||
pass
|
||||
item.frames = Frames()
|
||||
elif change in ("vae", "audio_vae"):
|
||||
setattr(item, change, object())
|
||||
elif change == "tiny_vae":
|
||||
item.tiny_vae = "taeh3"
|
||||
elif change == "foreign":
|
||||
item = types.SimpleNamespace(**vars(item))
|
||||
elif change == "subclass":
|
||||
class Extra(type(item)):
|
||||
pass
|
||||
item = Extra(512, "100", 90, True)
|
||||
elif change == "invalid_setting":
|
||||
item.preview_frames = True
|
||||
elif change == "core_factory":
|
||||
monkeypatch.setattr(kj.latent_preview, "get_previewer", lambda *a: None)
|
||||
elif change == "core_tiny_vae":
|
||||
import latent_preview
|
||||
monkeypatch.setattr(latent_preview.args, "preview_method", latent_preview.LatentPreviewMethod.TAESD)
|
||||
else:
|
||||
if change == "imported_helper_code":
|
||||
fn = kj.load_tiny_vae_decoder
|
||||
elif change == "core_preview_code":
|
||||
fn = kj.latent_preview.Latent2RGBPreviewer.decode_latent_to_preview
|
||||
else:
|
||||
fn = sys.modules["comfy.patcher_extension"].get_all_wrappers
|
||||
monkeypatch.setattr(fn, "__code__", fn.__code__.replace(co_consts=fn.__code__.co_consts + ("changed",)))
|
||||
assert not observe(model_with(item))[1]
|
||||
|
||||
|
||||
def test_unknown_other_wrapper_is_not_promoted(kj):
|
||||
model = model_with(wrapper(kj))
|
||||
model.wrappers["outer_sample"]["unknown"] = [torch.nn.Linear(2, 2)]
|
||||
assert not observe(model)[1]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("items", [None, (), [], object()])
|
||||
def test_unknown_target_container_is_not_promoted(items):
|
||||
assert not adapter.observe_model_wrappers({"outer_sample": {"kj_preview_override": items}}, storage._observe)[1]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("container", ["root", "outer", "items"])
|
||||
def test_observation_limit_rejects_reuse_without_interrupting_generation(container):
|
||||
wrappers = {"outer_sample": {"kj_preview_override": [object()]}}
|
||||
if container == "items":
|
||||
wrappers["outer_sample"]["kj_preview_override"] *= 4097
|
||||
else:
|
||||
target = wrappers if container == "root" else wrappers["outer_sample"]
|
||||
target.update({str(i): [] for i in range(4097)})
|
||||
result, safe = adapter.observe_model_wrappers(wrappers, storage._observe)
|
||||
assert not safe and result["unsupported"]
|
||||
|
||||
|
||||
def test_observation_never_executes_provider_or_initializes_cuda(kj, monkeypatch):
|
||||
item = wrapper(kj)
|
||||
# Even frame objects whose representation or data cannot be inspected are
|
||||
# ignored. The exact builtin list is the only permitted transient container.
|
||||
class UnreadableFrame:
|
||||
def __repr__(self):
|
||||
raise AssertionError("frame inspected")
|
||||
item.frames.append(UnreadableFrame())
|
||||
def forbidden(*args, **kwargs):
|
||||
raise AssertionError("signature tried to execute GPU/preview code")
|
||||
monkeypatch.setattr(torch.cuda, "_lazy_init", forbidden)
|
||||
# Trace calls instead of patching the audited callable (which must reject).
|
||||
called = []
|
||||
watched = {kj._PreviewOverrideWrapper.__call__.__code__, kj._get_core_previewer.__code__,
|
||||
kj._frame_to_pil.__code__, kj.load_tiny_vae_decoder.__code__}
|
||||
def trace(frame, event, arg):
|
||||
if event == "call" and frame.f_code in watched:
|
||||
called.append(frame.f_code.co_name)
|
||||
return trace
|
||||
previous = sys.gettrace()
|
||||
try:
|
||||
sys.settrace(trace)
|
||||
result, safe = observe(model_with(item))
|
||||
finally:
|
||||
sys.settrace(previous)
|
||||
assert safe, result
|
||||
assert called == [] and not torch.cuda.is_initialized()
|
||||
|
||||
|
||||
@pytest.mark.parametrize("backend", ["pytorch", "comfy_kitchen_int8"])
|
||||
def test_attention_and_spectrum_combination_is_stable(kj, core_attention, spectrum, backend):
|
||||
model = attention.model_with(core_attention, backend)
|
||||
model.model_options["spectrum_h3_binding"] = binding(spectrum)
|
||||
base, safe = observe(model)
|
||||
assert safe
|
||||
item = wrapper(kj)
|
||||
model.wrappers = {"outer_sample": {"kj_preview_override": [item]}}
|
||||
before, safe = observe(model)
|
||||
assert safe
|
||||
assert before["model_options"] == base["model_options"]
|
||||
item.frames.append(Image.new("RGB", (2, 2)))
|
||||
assert observe(model) == (before, safe)
|
||||
|
||||
|
||||
def test_saved_prefix_is_reusable_after_preview_only_change(kj, tmp_path):
|
||||
item = wrapper(kj)
|
||||
model = model_with(item)
|
||||
clip, vae = signatures._Clip(), signatures._VideoVAE()
|
||||
contract, safe, _ = signatures._sampling_contract(model=model, clip=clip, video_vae=vae, reroll_from_chunk=0)
|
||||
assert safe
|
||||
saved = signatures._persist_contract_prefix(tmp_path, contract, count=1)
|
||||
before = {str(p): p.read_bytes() for p in tmp_path.rglob("*") if p.is_file()}
|
||||
item.frames.append(Image.new("RGB", (2, 2)))
|
||||
current, safe, _ = signatures._sampling_contract(model=model, clip=clip, video_vae=vae, reroll_from_chunk=0)
|
||||
assert safe and storage.revision_identity(current) == storage.revision_identity(contract)
|
||||
_, entries, records = signatures._load_compatible_prefix(tmp_path, saved, current)
|
||||
assert len(entries) == len(records) == 1
|
||||
assert before == {str(p): p.read_bytes() for p in tmp_path.rglob("*") if p.is_file()}
|
||||
|
||||
|
||||
@pytest.mark.parametrize("entry_point", ["review", "head", "import", "compatible", "take"])
|
||||
def test_old_unsafe_preview_history_is_never_promoted(kj, tmp_path, monkeypatch, entry_point):
|
||||
item = wrapper(kj)
|
||||
item.frames.append(Image.new("RGB", (2, 2)))
|
||||
model = model_with(item)
|
||||
with monkeypatch.context() as ctx:
|
||||
ctx.setattr(storage, "observe_model_wrappers", lambda value, observer: observer(value))
|
||||
old, safe, reasons = signatures._sampling_contract(model=model, reroll_from_chunk=0)
|
||||
assert not safe
|
||||
source = review._persist(tmp_path, old, prefix=1, review_unit=(1, 1), updated_utc="2026-10-16T00:00:00+00:00")
|
||||
source.manifest["resume_safe"] = False
|
||||
source.manifest["resume_disabled_reasons"] = reasons
|
||||
source._write_manifest()
|
||||
before = {str(p): p.read_bytes() for p in source.run_root.rglob("*") if p.is_file()}
|
||||
reader = review._controller(tmp_path, old)
|
||||
reader.configure_review(generation_mode=review.GENERATION_MODE_REVIEW, review_action=review.REVIEW_ACTION_CONTINUE)
|
||||
assert not storage._reusable_manifest(source.manifest)
|
||||
if entry_point == "review": assert not reader._load_validated_review_prefix(old, resume_safe=True).entries
|
||||
elif entry_point == "head": assert reader.find_latest_review_head(old, resume_safe=True) is None
|
||||
elif entry_point == "import": assert reader._find_plan_import(old, resume_safe=True) is None
|
||||
elif entry_point == "compatible": assert reader._compatible_plan_prefix(source.manifest, old, resume_safe=True) == ([], [])
|
||||
else:
|
||||
reader.take_group = 1
|
||||
reader.take_revision_id = review._project(source)["canonical_head_revision_id"]
|
||||
with pytest.raises(storage.RunStorageError, match="read-only"):
|
||||
reader._validated_take_selection(old, resume_safe=True)
|
||||
assert before == {str(p): p.read_bytes() for p in source.run_root.rglob("*") if p.is_file()}
|
||||
|
||||
|
||||
def test_other_profile_registration_does_not_change_identity(kj, monkeypatch):
|
||||
item = wrapper(kj)
|
||||
before, safe = adapter.preview_override_signature(item)
|
||||
assert safe
|
||||
active, _ = adapter._provider_source(kj.__file__)
|
||||
monkeypatch.setattr(adapter, "_PROFILES", (active,))
|
||||
assert adapter.preview_override_signature(item) == (before, True)
|
||||
monkeypatch.setattr(adapter, "_PROFILES", (active, dict(active, source_sha256="e" * 64)))
|
||||
assert adapter.preview_override_signature(item) == (before, True)
|
||||
monkeypatch.setattr(adapter, "_PROFILES", (active, active))
|
||||
assert not adapter.preview_override_signature(item)[1]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("contents", [None, "invalid json", "null", "[]", "{}"])
|
||||
def test_missing_or_malformed_optional_profile_does_not_break_existing_paths(tmp_path, contents):
|
||||
path = tmp_path / "public.json"
|
||||
if contents is not None:
|
||||
path.write_text(contents, encoding="utf-8")
|
||||
assert adapter._load_public_profile(path) is None
|
||||
model = signatures._Model()
|
||||
assert observe(model)[1]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("field", ["id", "source_sha256"])
|
||||
def test_optional_profile_collision_cannot_disable_original_profile(kj, tmp_path, monkeypatch, field):
|
||||
candidate = dict(adapter._PUBLIC_PROFILE)
|
||||
candidate[field] = adapter._PROFILE[field]
|
||||
path = tmp_path / "public.json"
|
||||
path.write_text(json.dumps(candidate), encoding="utf-8")
|
||||
loaded = adapter._load_public_profile(path)
|
||||
assert loaded is None
|
||||
monkeypatch.setattr(adapter, "_PROFILES", (adapter._PROFILE,))
|
||||
item = wrapper(kj)
|
||||
expected = "_local." in kj.__name__
|
||||
assert adapter.preview_override_signature(item)[1] is expected
|
||||
assert observe(signatures._Model())[1]
|
||||
@@ -0,0 +1,329 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import ast
|
||||
import dataclasses
|
||||
import hashlib
|
||||
import importlib
|
||||
import json
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
import types
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
import torch
|
||||
|
||||
from ComfyUI_H3_Continuum_Join import run_storage as storage
|
||||
from ComfyUI_H3_Continuum_Join import spectrum_signature as adapter
|
||||
from . import test_issue31_attention_signature as attention_tests
|
||||
from .test_issue31_attention_signature import core_attention
|
||||
from . import test_v31_run_storage as signatures
|
||||
from . import test_v38_review_run_storage as review
|
||||
|
||||
|
||||
@pytest.fixture(params=["local", "public029"])
|
||||
def spectrum(require_comfy_core, request):
|
||||
root = os.environ.get("H3_SPECTRUM_TEST_ROOT" if request.param == "local" else "H3_SPECTRUM_PUBLIC_TEST_ROOT")
|
||||
if not root:
|
||||
pytest.skip("real audited Spectrum checkout is not configured")
|
||||
package = types.ModuleType("issue31_spectrum_tests_" + request.param)
|
||||
package.__path__ = [root]
|
||||
sys.modules[package.__name__] = package
|
||||
prefix = package.__name__ + ".comfyui_spectrum_h3"
|
||||
sampling = importlib.import_module(prefix + ".sampling")
|
||||
runtime = importlib.import_module(prefix + ".runtime")
|
||||
config = importlib.import_module(prefix + ".config")
|
||||
return sampling, runtime, config
|
||||
|
||||
|
||||
def binding(spectrum, **settings):
|
||||
sampling, runtime, config = spectrum
|
||||
return sampling.SpectrumH3Binding(runtime.SpectrumH3Runtime(config.SpectrumH3Config(**settings)))
|
||||
|
||||
|
||||
def signature(value):
|
||||
result, safe = adapter.spectrum_binding_signature(value)
|
||||
assert safe, result.get("unsupported")
|
||||
return result
|
||||
|
||||
|
||||
def test_recreated_runtime_and_transient_history_keep_identity(spectrum):
|
||||
a, b = binding(spectrum), binding(spectrum)
|
||||
before = signature(a)
|
||||
assert signature(b) == before
|
||||
a.runtime._run_counter += 8
|
||||
a.runtime._consecutive_forecasts = 3
|
||||
a.runtime._current_window = 3.25
|
||||
a.runtime.forecaster.update(0.0, torch.arange(12, dtype=torch.float32).reshape(1,12))
|
||||
a.runtime.forecaster.update(1.0, torch.arange(12, dtype=torch.float32).reshape(1,12) + 1)
|
||||
a.runtime.model_aware.anchor_count = 7
|
||||
a.runtime.stats.current_window = 4.0
|
||||
assert signature(a) == before
|
||||
|
||||
|
||||
CHANGES = {
|
||||
"enabled": {"enabled": False}, "blend_weight": {"blend_weight": 0.6},
|
||||
"degree": {"degree": 2, "bootstrap_first_forecast": False},
|
||||
"ridge_lambda": {"ridge_lambda": 0.2}, "window_size": {"window_size": 3.0},
|
||||
"flex_window": {"flex_window": 1.0},
|
||||
"warmup_steps": {"warmup_steps": 2, "bootstrap_first_forecast": False},
|
||||
"tail_actual_steps": {"tail_actual_steps": 2}, "max_history": {"max_history": 9},
|
||||
"history_storage": {"history_storage": "vram"}, "debug": {"debug": True},
|
||||
"force_actual": {"force_actual": True},
|
||||
"bootstrap_first_forecast": {"bootstrap_first_forecast": False},
|
||||
"anchor_residual_feedback": {"anchor_residual_feedback": True, "offline_smoothing_replay": False},
|
||||
"selective_rollback_correction": {"selective_rollback_correction": True, "offline_smoothing_replay": False},
|
||||
"offline_smoothing_replay": {"offline_smoothing_replay": False},
|
||||
"audio_blend_weight": {"audio_blend_weight": 0.1},
|
||||
"offline_archive_storage": {"offline_archive_storage": "vram"},
|
||||
"model_aware_mode": {"model_aware_mode": "full"},
|
||||
"model_aware_risk_threshold": {"model_aware_risk_threshold": 0.5},
|
||||
"model_aware_trust_shrinkage": {"model_aware_mode": "full", "model_aware_trust_shrinkage": True},
|
||||
"model_aware_replay_generic_correction": {"model_aware_replay_generic_correction": True},
|
||||
"generic_correction_mode": {"generic_correction_mode": "legacy"},
|
||||
"generic_correction_limiter": {"generic_correction_limiter": "tanh"},
|
||||
"generic_correction_limit": {"generic_correction_limit": 0.3},
|
||||
"generic_correction_attenuation": {"generic_correction_attenuation": "general_confidence"},
|
||||
"sa_pece_forecast_policy": {"sa_pece_forecast_policy": "stable_start"},
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.parametrize("field", sorted(CHANGES))
|
||||
def test_every_config_field_changes_identity(spectrum, field):
|
||||
before = signature(binding(spectrum))
|
||||
changed = signature(binding(spectrum, **CHANGES[field]))
|
||||
assert set(before["config"]) == set(CHANGES) == set(adapter.CONFIG_FIELDS)
|
||||
assert before != changed and before["config"][field] != changed["config"][field]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("change", ["runtime_code", "wrapper_code", "wrapper_closure", "class_attribute", "source_digest"])
|
||||
def test_implementation_changes_are_rejected(spectrum, monkeypatch, change):
|
||||
item = binding(spectrum)
|
||||
signature(item)
|
||||
if change == "runtime_code":
|
||||
old = spectrum[1].SpectrumH3Runtime.__init__
|
||||
monkeypatch.setattr(old, "__code__", old.__code__.replace(co_consts=old.__code__.co_consts + ("changed",)))
|
||||
elif change == "wrapper_code":
|
||||
old = spectrum[0].outer_sample_wrapper
|
||||
monkeypatch.setattr(old, "__code__", old.__code__.replace(co_consts=old.__code__.co_consts + ("changed",)))
|
||||
elif change == "wrapper_closure":
|
||||
old = spectrum[0].run_selective_rollback_euler
|
||||
assert old.__closure__
|
||||
cells = list(old.__closure__)
|
||||
cells[0] = (lambda value: lambda: value)(object()).__closure__[0]
|
||||
changed = types.FunctionType(old.__code__, old.__globals__, old.__name__, old.__defaults__, tuple(cells))
|
||||
changed.__module__, changed.__qualname__ = old.__module__, old.__qualname__
|
||||
monkeypatch.setattr(spectrum[0], "run_selective_rollback_euler", changed)
|
||||
elif change == "class_attribute":
|
||||
monkeypatch.setattr(spectrum[1].SpectrumH3Runtime, "extra_contract", 1, raising=False)
|
||||
else:
|
||||
source, _ = adapter._select_source_profile(Path(spectrum[0].__file__).resolve().parent)
|
||||
monkeypatch.setitem(source, "sampling.py", "f" * 64)
|
||||
after, safe = adapter.spectrum_binding_signature(item)
|
||||
assert not safe and after.get("unsupported")
|
||||
|
||||
|
||||
@pytest.mark.parametrize("change", ["foreign_binding", "binding_subclass", "runtime_extra", "component_extra", "component_setting", "nan_config", "stats_replaced", "missing_runtime_field"])
|
||||
def test_unknown_binding_and_additional_state_are_not_promoted(spectrum, change):
|
||||
item = binding(spectrum)
|
||||
if change == "foreign_binding":
|
||||
@dataclasses.dataclass(slots=True)
|
||||
class SpectrumH3Binding:
|
||||
runtime: object
|
||||
item = SpectrumH3Binding(item.runtime)
|
||||
elif change == "binding_subclass":
|
||||
class ExtraBinding(type(item)):
|
||||
pass
|
||||
item = ExtraBinding(item.runtime)
|
||||
elif change == "runtime_extra":
|
||||
item.runtime.unrecognized = object()
|
||||
elif change == "component_extra":
|
||||
item.runtime.forecaster.unrecognized = 1
|
||||
elif change == "component_setting":
|
||||
item.runtime.forecaster.degree += 1
|
||||
elif change == "stats_replaced":
|
||||
item.runtime.stats = object()
|
||||
elif change == "missing_runtime_field":
|
||||
del item.runtime._run_counter
|
||||
else:
|
||||
object.__setattr__(item.runtime.config, "blend_weight", float("nan"))
|
||||
assert adapter.spectrum_binding_signature(item)[1] is False
|
||||
|
||||
|
||||
@pytest.mark.parametrize("backend", ["pytorch", "comfy_kitchen_int8"])
|
||||
def test_attention_and_spectrum_remain_clone_stable(core_attention, spectrum, backend):
|
||||
model = attention_tests.model_with(core_attention, backend)
|
||||
original = attention_tests.observe(model)
|
||||
model.model_options["spectrum_h3_binding"] = binding(spectrum)
|
||||
combined = attention_tests.observe(model)
|
||||
assert original[1] and combined[1]
|
||||
assert combined[0]["model_options"]["transformer_options"] == original[0]["model_options"]["transformer_options"]
|
||||
model.model_options["spectrum_h3_binding"] = binding(spectrum)
|
||||
assert attention_tests.observe(model) == combined
|
||||
|
||||
|
||||
@pytest.mark.parametrize("backend", [None, "pytorch", "comfy_kitchen_int8"])
|
||||
def test_spectrum_absent_preserves_full_phase1_descriptor(core_attention, monkeypatch, backend):
|
||||
model = signatures._Model() if backend is None else attention_tests.model_with(core_attention, backend)
|
||||
current = attention_tests.observe(model)
|
||||
old = storage._observe_attention_model_options(model.model_options)
|
||||
assert storage._observe_model_options(model.model_options) == old
|
||||
# Independent Phase 1 implementation is frozen in the reviewed test fixture.
|
||||
source = (Path(__file__).parent / "fixtures" / "issue31_phase1_model_options.py.txt").read_text()
|
||||
scope = dict(vars(storage))
|
||||
exec(compile(source, "phase1_options_fixture", "exec"), scope)
|
||||
before = scope["_observe_model_options"](model.model_options)
|
||||
assert before == old
|
||||
torch.manual_seed(315)
|
||||
clip, vae = signatures._Clip(), signatures._VideoVAE()
|
||||
contract, safe, reasons = signatures._sampling_contract(model=model, clip=clip, video_vae=vae, reroll_from_chunk=0)
|
||||
with monkeypatch.context() as context:
|
||||
context.setattr(storage, "_observe_model_options", scope["_observe_model_options"])
|
||||
previous, previous_safe, previous_reasons = signatures._sampling_contract(model=model, clip=clip, video_vae=vae, reroll_from_chunk=0)
|
||||
assert safe == previous_safe and reasons == previous_reasons
|
||||
assert storage._canonical(contract) == storage._canonical(previous)
|
||||
assert storage.revision_identity(contract) == storage.revision_identity(previous)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("entry_point", ["review", "head", "import", "compatible", "take"])
|
||||
def test_old_unsafe_spectrum_history_is_unmodified(tmp_path, core_attention, spectrum, monkeypatch, entry_point):
|
||||
model = attention_tests.model_with(core_attention, "pytorch")
|
||||
model.model_options["spectrum_h3_binding"] = binding(spectrum)
|
||||
with monkeypatch.context() as ctx:
|
||||
ctx.setattr(storage, "_observe_model_options", storage._observe_attention_model_options)
|
||||
old, safe, reasons = signatures._sampling_contract(model=model, reroll_from_chunk=0)
|
||||
assert not safe and reasons
|
||||
source = review._persist(tmp_path, old, prefix=1, review_unit=(1,1), updated_utc="2026-10-15T00:00:00+00:00")
|
||||
source.manifest["resume_safe"] = False
|
||||
source.manifest["resume_disabled_reasons"] = reasons
|
||||
source._write_manifest()
|
||||
before = {str(p):p.read_bytes() for p in source.run_root.rglob("*") if p.is_file()}
|
||||
current, current_safe, _ = signatures._sampling_contract(model=model, reroll_from_chunk=0)
|
||||
assert current_safe and storage.revision_identity(current) != storage.revision_identity(old)
|
||||
reader = review._controller(tmp_path, old)
|
||||
reader.configure_review(generation_mode=review.GENERATION_MODE_REVIEW, review_action=review.REVIEW_ACTION_CONTINUE)
|
||||
assert not storage._reusable_manifest(source.manifest)
|
||||
if entry_point == "review": assert not reader._load_validated_review_prefix(old,resume_safe=True).entries
|
||||
elif entry_point == "head": assert reader.find_latest_review_head(old,resume_safe=True) is None
|
||||
elif entry_point == "import": assert reader._find_plan_import(old,resume_safe=True) is None
|
||||
elif entry_point == "compatible": assert reader._compatible_plan_prefix(source.manifest,old,resume_safe=True)==([],[])
|
||||
else:
|
||||
reader.take_group=1;reader.take_revision_id=review._project(source)["canonical_head_revision_id"]
|
||||
with pytest.raises(storage.RunStorageError,match="read-only"):reader._validated_take_selection(old,resume_safe=True)
|
||||
assert before=={str(p):p.read_bytes() for p in source.run_root.rglob("*") if p.is_file()}
|
||||
|
||||
|
||||
def test_imports_and_profile_cache_do_not_change_identity(spectrum, monkeypatch):
|
||||
item=binding(spectrum);before=signature(item)
|
||||
prefix=spectrum[0].__name__.rsplit('.',1)[0]
|
||||
importlib.import_module(prefix+'.experiments')
|
||||
aware=importlib.import_module(prefix+'.model_aware')
|
||||
monkeypatch.setitem(aware._PROFILE_CACHE,('temporary',),object())
|
||||
assert signature(item)==before
|
||||
|
||||
|
||||
|
||||
def test_imported_original_implementation_changes_are_rejected(spectrum, monkeypatch):
|
||||
item=binding(spectrum);signature(item)
|
||||
module=importlib.import_module(spectrum[0].__name__.rsplit('.',1)[0]+'.generic_correction')
|
||||
old=module._ORIGINAL_FORECASTER_UPDATE
|
||||
changed=types.FunctionType(old.__code__.replace(co_consts=old.__code__.co_consts+('changed imported original',)),old.__globals__,old.__name__,old.__defaults__,old.__closure__)
|
||||
changed.__module__,changed.__qualname__=old.__module__,old.__qualname__
|
||||
monkeypatch.setattr(module,'_ORIGINAL_FORECASTER_UPDATE',changed)
|
||||
assert adapter.spectrum_binding_signature(item)[1] is False
|
||||
|
||||
|
||||
@pytest.mark.parametrize('backend',['pytorch','comfy_kitchen_int8'])
|
||||
def test_spectrum_same_settings_reuse_and_changed_settings_reject(tmp_path,core_attention,spectrum,backend):
|
||||
model=attention_tests.model_with(core_attention,backend)
|
||||
model.model_options['spectrum_h3_binding']=binding(spectrum)
|
||||
torch.manual_seed(315);clip,vae=signatures._Clip(),signatures._VideoVAE()
|
||||
contract,safe,_=signatures._sampling_contract(model=model,clip=clip,video_vae=vae,reroll_from_chunk=0);assert safe
|
||||
source=review._persist(tmp_path,contract,prefix=1,review_unit=(1,1),updated_utc='2026-10-15T00:00:00+00:00')
|
||||
before={str(p):p.read_bytes() for p in source.run_root.rglob('*') if p.is_file()}
|
||||
reader=review._controller(tmp_path,contract);reader.configure_review(generation_mode=review.GENERATION_MODE_REVIEW,review_action=review.REVIEW_ACTION_CONTINUE)
|
||||
assert len(reader._load_validated_review_prefix(contract,resume_safe=True).entries)==1
|
||||
model.model_options['spectrum_h3_binding']=binding(spectrum,blend_weight=0.6)
|
||||
changed,changed_safe,_=signatures._sampling_contract(model=model,clip=clip,video_vae=vae,reroll_from_chunk=0);assert changed_safe
|
||||
other=review._controller(tmp_path,changed);other.configure_review(generation_mode=review.GENERATION_MODE_REVIEW,review_action=review.REVIEW_ACTION_CONTINUE)
|
||||
assert not other._load_validated_review_prefix(changed,resume_safe=True).entries
|
||||
assert before=={str(p):p.read_bytes() for p in source.run_root.rglob('*') if p.is_file()}
|
||||
|
||||
|
||||
def test_signature_stable_across_processes_and_module_aliases(spectrum,core_attention):
|
||||
root=str(Path(spectrum[0].__file__).resolve().parents[1])
|
||||
core_root=str(Path(core_attention[1].__file__).resolve().parents[1])
|
||||
adapter_path=str(Path(adapter.__file__).resolve())
|
||||
script=r"""
|
||||
import os,sys,types,importlib,importlib.util,json,hashlib
|
||||
os.environ['CUDA_VISIBLE_DEVICES']='-1'
|
||||
sys.path.insert(0,CORE_ROOT)
|
||||
import torch
|
||||
torch.cuda._lazy_init=lambda: (_ for _ in ()).throw(RuntimeError('CUDA forbidden'))
|
||||
from comfy.cli_args import args
|
||||
args.cpu=True
|
||||
package=types.ModuleType('process_alias_'+os.environ['PYTHONHASHSEED']);package.__path__=[PROVIDER_ROOT];sys.modules[package.__name__]=package
|
||||
prefix=package.__name__+'.comfyui_spectrum_h3'
|
||||
s=importlib.import_module(prefix+'.sampling');r=importlib.import_module(prefix+'.runtime');c=importlib.import_module(prefix+'.config')
|
||||
spec=importlib.util.spec_from_file_location('process_adapter',ADAPTER_FILE);a=importlib.util.module_from_spec(spec);spec.loader.exec_module(a)
|
||||
value,safe=a.spectrum_binding_signature(s.SpectrumH3Binding(r.SpectrumH3Runtime(c.SpectrumH3Config())))
|
||||
assert safe,value.get('unsupported')
|
||||
print(hashlib.sha256(json.dumps(value,sort_keys=True,separators=(',',':')).encode()).hexdigest())
|
||||
"""
|
||||
script=script.replace('CORE_ROOT',repr(core_root)).replace('PROVIDER_ROOT',repr(root)).replace('ADAPTER_FILE',repr(adapter_path))
|
||||
outputs=[]
|
||||
for seed in ('13','71'):
|
||||
env=dict(os.environ,PYTHONHASHSEED=seed,PYTHONDONTWRITEBYTECODE='1')
|
||||
output=subprocess.check_output([sys.executable,'-c',script],env=env,text=True)
|
||||
outputs.append(output.strip().splitlines()[-1])
|
||||
assert outputs[0]==outputs[1]
|
||||
|
||||
|
||||
def test_core_node_registration_location_is_not_generation_identity(spectrum,monkeypatch):
|
||||
item=binding(spectrum);before=signature(item)
|
||||
prefix=spectrum[0].__name__.rsplit('.',1)[0]
|
||||
for suffix in ['nodes','objective_media_nodes']:
|
||||
module=importlib.import_module(prefix+'.'+suffix)
|
||||
for cls in module.NODE_CLASS_MAPPINGS.values():
|
||||
monkeypatch.setattr(cls,'RELATIVE_PYTHON_MODULE','custom_nodes.test_location',raising=False)
|
||||
assert signature(item)==before
|
||||
|
||||
|
||||
def test_original_local_profile_descriptor_is_unchanged(spectrum):
|
||||
item=binding(spectrum)
|
||||
source, _ = adapter._select_source_profile(Path(spectrum[0].__file__).resolve().parent)
|
||||
if source is not adapter.SUPPORTED_SOURCE:
|
||||
pytest.skip("original descriptor fixture covers the pre-existing local profile")
|
||||
scope={"__file__":adapter.__file__}
|
||||
fixture=Path(__file__).parent/"fixtures"/"issue31_local_spectrum_signature.py.txt"
|
||||
exec(compile(fixture.read_text(),str(fixture),"exec"),scope)
|
||||
previous = scope["spectrum_binding_signature"](item)
|
||||
current = adapter.spectrum_binding_signature(item)
|
||||
if sys.version_info[:2] == (3, 13):
|
||||
assert previous == current
|
||||
else:
|
||||
# Python 3.12 was never accepted by the original 3.13-only profile.
|
||||
# New support changes current observation, never a stored unsafe Take.
|
||||
assert sys.version_info[:2] == (3, 12)
|
||||
assert previous[1] is False and current[1] is True
|
||||
|
||||
def test_foreign_provider_file_set_stays_unsafe(tmp_path):
|
||||
(tmp_path/"unknown.py").write_text("pass")
|
||||
with pytest.raises(ValueError,match="unsupported provider source set"):
|
||||
adapter._select_source_profile(tmp_path)
|
||||
|
||||
|
||||
def test_foreign_module_closure_is_rejected():
|
||||
with pytest.raises(ValueError, match="unsupported provider module closure"):
|
||||
adapter._callable_value(types.ModuleType("foreign_provider"),provider_prefix="known.comfyui_spectrum_h3")
|
||||
|
||||
def test_unloaded_module_cannot_impersonate_provider():
|
||||
with pytest.raises(ValueError, match="provider module closure is not loaded"):
|
||||
adapter._callable_value(types.ModuleType("known.comfyui_spectrum_h3.runtime"),provider_prefix="known.comfyui_spectrum_h3")
|
||||
|
||||
def test_loaded_implementation_profiles_are_packaged():
|
||||
root=Path(adapter.__file__).parent
|
||||
for filename in ["spectrum_provider_v1.json","spectrum_provider_v029.json"]:
|
||||
assert json.loads((root/filename).read_text())["format"]=="audited_spectrum_loaded_implementation_v1"
|
||||
assert len(adapter.SUPPORTED_SOURCE)==44 and len(adapter.PUBLIC_SOURCE_029)==55
|
||||
@@ -0,0 +1,188 @@
|
||||
from types import SimpleNamespace
|
||||
|
||||
import torch
|
||||
|
||||
from ComfyUI_H3_Continuum_Join.constants import (
|
||||
MARK_AUDIO_CONTEXT,
|
||||
MARK_AUDIO_END_FRAME,
|
||||
MARK_AUDIO_OVERHANG,
|
||||
MARK_CONTEXT_FRAMES,
|
||||
MARK_VIDEO_CONTEXT,
|
||||
)
|
||||
from ComfyUI_H3_Continuum_Join.layout_adapter import (
|
||||
normalize_condition_latents,
|
||||
patch_layout_in_place,
|
||||
)
|
||||
|
||||
|
||||
def _video_times(origin: float):
|
||||
offsets = (0, 1, 5, 9, 13, 17, 18)
|
||||
return [origin + value * 5.0 / 3.0 for value in offsets]
|
||||
|
||||
|
||||
def _fake_layout(*, with_last_keyframe=False, audio_steps=37):
|
||||
# text=3, optional one stock keyframe, a 22-frame video/audio context ref,
|
||||
# target audio=10 steps, target video=7 slots x 2 rows.
|
||||
row = 0
|
||||
segments = [(row, row + 3, "text")]
|
||||
row += 3
|
||||
if with_last_keyframe:
|
||||
segments.append((row, row + 2, "cond"))
|
||||
row += 2
|
||||
audio_ref = (row, row + audio_steps * 2)
|
||||
segments.append((*audio_ref, "ref_audio"))
|
||||
row += audio_steps * 2
|
||||
video_ref = (row, row + 14)
|
||||
segments.append((*video_ref, "ref_img"))
|
||||
row += 14
|
||||
target_audio = (row, row + 20)
|
||||
segments.append((*target_audio, "audio"))
|
||||
row += 20
|
||||
target_video = (row, row + 14)
|
||||
segments.append((*target_video, "video"))
|
||||
row += 14
|
||||
|
||||
pos = torch.zeros(row, 3, dtype=torch.float64)
|
||||
pos[:3, 0] = torch.arange(3, dtype=torch.float64)
|
||||
if with_last_keyframe:
|
||||
# Stock last keyframe is text-relative before refs shift the target.
|
||||
pos[3:5, 0] = 3.0 + 35.0
|
||||
# Stock context ref lives in its own pre-target coordinate span.
|
||||
a0, a1 = audio_ref
|
||||
pos[a0 : a0 + audio_steps, 0] = (
|
||||
torch.arange(audio_steps, dtype=torch.float64) + 3.0
|
||||
)
|
||||
pos[a0 + audio_steps : a1, 0] = (
|
||||
torch.arange(audio_steps, dtype=torch.float64) + 3.0
|
||||
)
|
||||
v0, _v1 = video_ref
|
||||
for slot, value in enumerate(_video_times(3.0)):
|
||||
pos[v0 + slot * 2 : v0 + (slot + 1) * 2, 0] = value
|
||||
# Target origin follows Core's longest reference span.
|
||||
target_origin = 3.0 + max(float(audio_steps), 22.0 * 5.0 / 3.0)
|
||||
ta0, ta1 = target_audio
|
||||
pos[ta0 : ta0 + 10, 0] = torch.arange(10, dtype=torch.float64) + target_origin
|
||||
pos[ta0 + 10 : ta1, 0] = (
|
||||
torch.arange(10, dtype=torch.float64) + target_origin
|
||||
)
|
||||
tv0, _tv1 = target_video
|
||||
for slot, value in enumerate(_video_times(target_origin)):
|
||||
pos[tv0 + slot * 2 : tv0 + (slot + 1) * 2, 0] = value
|
||||
# Give every target video row distinct h/w values so the full-coordinate
|
||||
# copy (not only time) is tested.
|
||||
pos[tv0 : tv0 + 14, 1] = torch.arange(14, dtype=torch.float64)
|
||||
pos[tv0 : tv0 + 14, 2] = torch.arange(14, dtype=torch.float64) + 100
|
||||
|
||||
return SimpleNamespace(
|
||||
segments=segments,
|
||||
position_ids=pos,
|
||||
signature=(3, 7, 2, 2, 10),
|
||||
), video_ref, target_video
|
||||
|
||||
|
||||
def _context_ref(video, audio):
|
||||
return {
|
||||
"kind": "video_audio",
|
||||
"latent_t": 7,
|
||||
"latent_h": 2,
|
||||
"latent_w": 2,
|
||||
"ref_audio_t": 37,
|
||||
"latent": video,
|
||||
"audio_latent": audio,
|
||||
MARK_VIDEO_CONTEXT: True,
|
||||
MARK_CONTEXT_FRAMES: 22,
|
||||
MARK_AUDIO_CONTEXT: True,
|
||||
MARK_AUDIO_END_FRAME: 22.0,
|
||||
MARK_AUDIO_OVERHANG: 1.0 / 3.0,
|
||||
}
|
||||
|
||||
|
||||
def test_layout_patches_video_audio_ref_in_place_and_is_idempotent():
|
||||
layout, video_ref_span, target_video_span = _fake_layout()
|
||||
tensor_id = id(layout.position_ids)
|
||||
video = torch.zeros(1, 24, 7, 2, 2)
|
||||
audio = torch.zeros(1, 32, 2, 37)
|
||||
payload = {"layout": layout, "keyframes": [], "refs": [_context_ref(video, audio)]}
|
||||
normalize_condition_latents(payload)
|
||||
result = patch_layout_in_place(payload)
|
||||
assert result["video_refs"] == 1
|
||||
assert result["audio_windows"] == 1
|
||||
assert id(layout.position_ids) == tensor_id
|
||||
|
||||
rv0, rv1 = video_ref_span
|
||||
tv0, tv1 = target_video_span
|
||||
assert torch.equal(layout.position_ids[rv0:rv1], layout.position_ids[tv0:tv1])
|
||||
# 22 frames (36 2/3 audio steps) plus source overhang 1/3 = 37,
|
||||
# so the audio context begins exactly at target origin 40.
|
||||
audio_start = next(a for a, _b, kind in layout.segments if kind == "ref_audio")
|
||||
assert torch.isclose(
|
||||
layout.position_ids[audio_start, 0], torch.tensor(40.0, dtype=torch.float64)
|
||||
)
|
||||
|
||||
before = layout.position_ids.clone()
|
||||
second = patch_layout_in_place(payload)
|
||||
assert second["status"] == "already_patched"
|
||||
assert torch.equal(before, layout.position_ids)
|
||||
assert payload["cond_video_latents"] == [video]
|
||||
assert payload["cond_audio_latents"] == [audio]
|
||||
|
||||
|
||||
def test_existing_last_keyframe_is_shifted_with_context_ref():
|
||||
layout, _video_ref_span, target_video_span = _fake_layout(with_last_keyframe=True)
|
||||
target_origin = float(layout.position_ids[target_video_span[0], 0])
|
||||
image = torch.zeros(1, 24, 1, 2, 2)
|
||||
video = torch.zeros(1, 24, 7, 2, 2)
|
||||
audio = torch.zeros(1, 32, 2, 37)
|
||||
payload = {
|
||||
"layout": layout,
|
||||
"keyframes": [{"resolved_frame_index": 140, "latent": image}],
|
||||
"refs": [_context_ref(video, audio)],
|
||||
}
|
||||
normalize_condition_latents(payload)
|
||||
patch_layout_in_place(payload)
|
||||
cond_start = next(a for a, _b, kind in layout.segments if kind == "cond")
|
||||
expected = target_origin + 140.0 * 5.0 / 3.0
|
||||
assert torch.allclose(
|
||||
layout.position_ids[cond_start : cond_start + 2, 0],
|
||||
torch.full((2,), expected, dtype=torch.float64),
|
||||
)
|
||||
assert payload["cond_video_latents"] == [image, video]
|
||||
|
||||
|
||||
def test_negative_audio_grid_offset_places_context_before_target_origin():
|
||||
layout, _video_ref_span, _target_video_span = _fake_layout()
|
||||
video = torch.zeros(1, 24, 7, 2, 2)
|
||||
audio = torch.zeros(1, 32, 2, 37)
|
||||
ref = _context_ref(video, audio)
|
||||
ref[MARK_AUDIO_OVERHANG] = -1.0 / 3.0
|
||||
payload = {"layout": layout, "keyframes": [], "refs": [ref]}
|
||||
normalize_condition_latents(payload)
|
||||
patch_layout_in_place(payload)
|
||||
audio_start = next(a for a, _b, kind in layout.segments if kind == "ref_audio")
|
||||
# target origin is 40; 22 frames = 36 2/3 audio steps, signed offset -1/3,
|
||||
# and the retained window is 37 steps, so it starts 2/3 step before origin.
|
||||
assert torch.isclose(
|
||||
layout.position_ids[audio_start, 0],
|
||||
torch.tensor(40.0 - 2.0 / 3.0, dtype=torch.float64),
|
||||
)
|
||||
|
||||
|
||||
def test_audio40_research_window_is_end_aligned_without_layout_changes():
|
||||
layout, _video_ref_span, target_video_span = _fake_layout(audio_steps=40)
|
||||
video = torch.zeros(1, 24, 7, 2, 2)
|
||||
audio = torch.zeros(1, 32, 2, 40)
|
||||
ref = _context_ref(video, audio)
|
||||
ref["ref_audio_t"] = 40
|
||||
payload = {"layout": layout, "keyframes": [], "refs": [ref]}
|
||||
|
||||
normalize_condition_latents(payload)
|
||||
patch_layout_in_place(payload)
|
||||
|
||||
audio_start = next(a for a, _b, kind in layout.segments if kind == "ref_audio")
|
||||
target_origin = float(layout.position_ids[target_video_span[0], 0])
|
||||
# The extra three ticks precede the ordinary 37T window; both end at the
|
||||
# same source-grid phase beside the 22-frame video context.
|
||||
assert torch.isclose(
|
||||
layout.position_ids[audio_start, 0],
|
||||
torch.tensor(target_origin - 3.0, dtype=torch.float64),
|
||||
)
|
||||
@@ -0,0 +1,116 @@
|
||||
"""Regressions for Core's prototype mode accessor and stable widgets view.
|
||||
|
||||
This models the persistence boundary; it is not a real-browser acceptance test.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import subprocess
|
||||
|
||||
import pytest
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("store_backed", [False, True], ids=["legacy", "store"])
|
||||
@pytest.mark.parametrize("kind", ["image", "audio", "video"])
|
||||
def test_loader_state_survives_draw_save_and_workflow_roundtrip(tmp_path, kind, store_backed):
|
||||
node = shutil.which("node")
|
||||
if node is None:
|
||||
pytest.skip("Node.js is required for frontend regression tests")
|
||||
source = (ROOT / "web/easy_bypass_toggle.js").read_text(encoding="utf-8").replace("export ", "")
|
||||
script = source + "\n" + r'''
|
||||
const storeBacked = STORE_BACKED;
|
||||
const kind = KIND;
|
||||
const nodeClass = {image: "H3EasyLoadImage", audio: "H3EasyLoadAudio", video: "H3ContinuumLoadVideo"}[kind];
|
||||
const enableName = {image: "Enable Image", audio: "Enable Audio", video: "enable_video"}[kind];
|
||||
const fileName = {image: "image", audio: "audio", video: "file"}[kind];
|
||||
const selectedFile = {image: "selected-b.png", audio: "selected-b.wav", video: "selected-b.mp4"}[kind];
|
||||
function plainWidget(name, value) { return {name, value, options: {}, serialize: true}; }
|
||||
class StoreNode {
|
||||
constructor() {
|
||||
this.comfyClass = nodeClass;
|
||||
this._state = {mode: 0};
|
||||
this.drawCalls = 0;
|
||||
const widgets = [];
|
||||
// Like Core widgetsView: assignment mutates the same array/view.
|
||||
Object.defineProperty(this, "widgets", {
|
||||
configurable: true,
|
||||
get() { return widgets; },
|
||||
set(value) { widgets.splice(0, widgets.length, ...value); },
|
||||
});
|
||||
if (!storeBacked) {
|
||||
Object.defineProperty(this, "mode", {value: 0, writable: true, configurable: true});
|
||||
Object.defineProperty(this, "widgets", {value: [], writable: true, configurable: true});
|
||||
}
|
||||
if (kind === "video") this.widgets.push(plainWidget(enableName, true));
|
||||
this.widgets.push(plainWidget(fileName, "default-file"));
|
||||
if (kind === "video") this.widgets.push(plainWidget("force_rate", 30));
|
||||
}
|
||||
get mode() { return this._state.mode; }
|
||||
set mode(value) { this._state.mode = value; }
|
||||
setDirtyCanvas() {}
|
||||
addWidget(type, name, value, callback, options) {
|
||||
const w = {type, name, value, callback, options}; this.widgets.push(w); return w;
|
||||
}
|
||||
drawWidgets() { this.drawCalls++; }
|
||||
serializeFromStoreState(state) {
|
||||
const ws = this.widgets.filter(w => w.serialize !== false);
|
||||
return {mode: state.mode, widgets_values: ws.map(w => w.value),
|
||||
widgets_values_named: Object.fromEntries(ws.map(w => [w.name, w.value]))};
|
||||
}
|
||||
serialize() { return this.serializeFromStoreState(storeBacked ? this._state : {mode:this.mode}); }
|
||||
configure(info) {
|
||||
this.mode = info.mode;
|
||||
for (const w of this.widgets) {
|
||||
if (w.serialize !== false && Object.hasOwn(info.widgets_values_named, w.name))
|
||||
w.value = info.widgets_values_named[w.name];
|
||||
}
|
||||
}
|
||||
}
|
||||
function configure(n) {
|
||||
if (kind === "video") configureExistingEasyBypassWidgetNode(n, {nodeClass, widgetNames:[enableName]});
|
||||
else configureEasyBypassToggleNode(n, {nodeClass, widgetName:enableName, tooltip:"test"});
|
||||
}
|
||||
function saveGraph(n) {
|
||||
// Core 1.53 may bypass node.serialize() and use the store directly.
|
||||
return storeBacked ? n.serializeFromStoreState(n._state) : n.serialize();
|
||||
}
|
||||
const a = new StoreNode(); configure(a); configure(a);
|
||||
a.widgets.find(w => w.name === fileName).value = selectedFile;
|
||||
findEasyBypassWidget(a).callback(false);
|
||||
const beforeDraw = a.widgets.map(w => w.name);
|
||||
for (let i=0; i<4; i++) a.drawWidgets({}, {editorAlpha:0.2});
|
||||
const afterDraw = a.widgets.map(w => w.name);
|
||||
const saved = saveGraph(a);
|
||||
const b = new StoreNode(); configure(b); b.configure(saved); configure(b);
|
||||
const reopened = saveGraph(b);
|
||||
b.mode = 0;
|
||||
const externalOn = findEasyBypassWidget(b).value;
|
||||
b.mode = 4;
|
||||
const externalOff = findEasyBypassWidget(b).value;
|
||||
console.log(JSON.stringify({beforeDraw, afterDraw, liveMode:a.mode, storeMode:a._state.mode,
|
||||
saved, reopened, reopenedEnable:findEasyBypassWidget(b).value, externalOn, externalOff,
|
||||
selectedFile, fileName, kind, drawCalls:a.drawCalls}));
|
||||
'''
|
||||
script = script.replace("STORE_BACKED", str(store_backed).lower()).replace("KIND", json.dumps(kind))
|
||||
file = tmp_path / "loader-store.js"
|
||||
file.write_text(script, encoding="utf-8")
|
||||
result = subprocess.run([node, str(file)], capture_output=True, text=True, check=True)
|
||||
observed = json.loads(result.stdout)
|
||||
assert observed["beforeDraw"] == observed["afterDraw"], observed
|
||||
assert observed["liveMode"] == observed["saved"]["mode"] == 4, observed
|
||||
if store_backed:
|
||||
assert observed["storeMode"] == 4, observed
|
||||
assert observed["saved"]["widgets_values_named"][observed["fileName"]] == observed["selectedFile"]
|
||||
if kind == "video":
|
||||
assert observed["saved"]["widgets_values_named"]["force_rate"] == 30
|
||||
assert observed["saved"]["widgets_values_named"]["enable_video"] is False
|
||||
else:
|
||||
assert not any(name.startswith("Enable") for name in observed["saved"]["widgets_values_named"])
|
||||
assert observed["reopened"] == observed["saved"]
|
||||
assert observed["reopenedEnable"] is False
|
||||
assert observed["externalOn"] is True
|
||||
assert observed["externalOff"] is False
|
||||
@@ -0,0 +1,59 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
|
||||
from ComfyUI_H3_Continuum_Join.conditioning import (
|
||||
conditioning_display_label,
|
||||
conditioning_mode_from_presence,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("has_first", "has_last", "has_reference", "expected"),
|
||||
[
|
||||
(False, False, False, "T2VA + Continuation"),
|
||||
(True, False, False, "I2VA + Continuation"),
|
||||
(False, True, False, "Last Frame + Continuation"),
|
||||
(True, True, False, "FL2VA + Continuation"),
|
||||
(False, False, True, "Reference + Continuation"),
|
||||
(True, False, True, "Hybrid I2VA + Reference + Continuation"),
|
||||
(False, True, True, "Hybrid L2VA + Reference + Continuation"),
|
||||
(True, True, True, "Hybrid FL2VA + Reference + Continuation"),
|
||||
],
|
||||
)
|
||||
def test_conditioning_display_label_matrix(
|
||||
has_first: bool,
|
||||
has_last: bool,
|
||||
has_reference: bool,
|
||||
expected: str,
|
||||
) -> None:
|
||||
assert (
|
||||
conditioning_display_label(
|
||||
has_first=has_first,
|
||||
has_last=has_last,
|
||||
has_reference=has_reference,
|
||||
)
|
||||
== expected
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("has_first", "has_last"),
|
||||
[
|
||||
(True, False),
|
||||
(False, True),
|
||||
(True, True),
|
||||
],
|
||||
)
|
||||
def test_hybrid_display_does_not_change_internal_reference_mode(
|
||||
has_first: bool,
|
||||
has_last: bool,
|
||||
) -> None:
|
||||
assert (
|
||||
conditioning_mode_from_presence(
|
||||
has_first=has_first,
|
||||
has_last=has_last,
|
||||
has_reference=True,
|
||||
)
|
||||
== "reference"
|
||||
)
|
||||
+327
@@ -0,0 +1,327 @@
|
||||
from types import SimpleNamespace
|
||||
|
||||
import pytest
|
||||
import torch
|
||||
|
||||
from ComfyUI_H3_Continuum_Join.constants import (
|
||||
CONTINUUM_INTEROP_KEY,
|
||||
MARK_AUDIO_CONTEXT,
|
||||
MARK_AUDIO_END_FRAME,
|
||||
MARK_AUDIO_OVERHANG,
|
||||
MARK_CONTEXT_FRAMES,
|
||||
MARK_VIDEO_CONTEXT,
|
||||
)
|
||||
from ComfyUI_H3_Continuum_Join.model_patch import (
|
||||
LayoutValidationProfiler,
|
||||
_wrapper_factory,
|
||||
clone_model_for_chunk,
|
||||
patch_model,
|
||||
)
|
||||
|
||||
|
||||
class Executor:
|
||||
def __init__(self):
|
||||
inner_type = type(
|
||||
"MiniMaxH3Model",
|
||||
(),
|
||||
{
|
||||
"__module__": "comfy.ldm.minimax.model",
|
||||
"blocks": (),
|
||||
"final_layer": object(),
|
||||
"patch_size": (1, 2, 2),
|
||||
"latents_dim": 24,
|
||||
"audio_latents_dim": 32,
|
||||
"rope_freqs": lambda self, position_ids, device: position_ids,
|
||||
},
|
||||
)
|
||||
self.class_obj = SimpleNamespace(diffusion_model=inner_type())
|
||||
|
||||
def __call__(self, *args, **kwargs):
|
||||
return kwargs["minimax_payload"]
|
||||
|
||||
|
||||
def _layout():
|
||||
# text 1; ref audio 2 rows; ref video 1 row; target audio 2 rows; target video 1 row
|
||||
segments = [
|
||||
(0, 1, "text"),
|
||||
(1, 3, "ref_audio"),
|
||||
(3, 4, "ref_img"),
|
||||
(4, 6, "audio"),
|
||||
(6, 7, "video"),
|
||||
]
|
||||
pos = torch.zeros(7, 3, dtype=torch.float64)
|
||||
pos[1:3, 0] = 1
|
||||
pos[3, 0] = 1
|
||||
pos[4:6, 0] = 2
|
||||
pos[6, 0] = 2
|
||||
return SimpleNamespace(segments=segments, position_ids=pos, signature=(1, 1, 2, 2, 1))
|
||||
|
||||
|
||||
def test_apply_model_wrapper_repairs_payload_before_executor():
|
||||
video = torch.zeros(1, 24, 1, 2, 2)
|
||||
audio = torch.zeros(1, 32, 2, 1)
|
||||
ref = {
|
||||
"kind": "video_audio",
|
||||
"latent_t": 1,
|
||||
"latent_h": 2,
|
||||
"latent_w": 2,
|
||||
"ref_audio_t": 1,
|
||||
"latent": video,
|
||||
"audio_latent": audio,
|
||||
MARK_VIDEO_CONTEXT: True,
|
||||
MARK_CONTEXT_FRAMES: 1,
|
||||
MARK_AUDIO_CONTEXT: True,
|
||||
MARK_AUDIO_END_FRAME: 1.0,
|
||||
MARK_AUDIO_OVERHANG: 0.0,
|
||||
}
|
||||
payload = {"layout": _layout(), "keyframes": [], "refs": [ref]}
|
||||
wrapper = _wrapper_factory(strict=True, debug=False)
|
||||
result = wrapper(Executor(), torch.zeros(1), minimax_payload=payload)
|
||||
assert result["cond_video_latents"] == [video]
|
||||
assert result["cond_audio_latents"] == [audio]
|
||||
assert torch.equal(result["layout"].position_ids[3:4], result["layout"].position_ids[6:7])
|
||||
|
||||
|
||||
def test_apply_model_wrapper_repairs_keyframes_with_audio_reference_without_continuum():
|
||||
first = torch.zeros(1, 24, 1, 1, 1)
|
||||
last = torch.ones(1, 24, 1, 1, 1)
|
||||
audio = torch.zeros(1, 32, 2, 1)
|
||||
payload = {
|
||||
"keyframes": [
|
||||
{"resolved_frame_index": 0, "latent": first},
|
||||
{"resolved_frame_index": 4, "latent": last},
|
||||
],
|
||||
"refs": [
|
||||
{"kind": "audio", "ref_audio_t": 1, "audio_latent": audio}
|
||||
],
|
||||
# ComfyUI Core 0.33.1 overwrites this list while processing refs.
|
||||
"cond_video_latents": [],
|
||||
"cond_audio_latents": [audio],
|
||||
}
|
||||
wrapper = _wrapper_factory(strict=True, debug=False)
|
||||
|
||||
result = wrapper(Executor(), torch.zeros(1), minimax_payload=payload)
|
||||
|
||||
assert result["cond_video_latents"] == [first, last]
|
||||
assert result["cond_audio_latents"] == [audio]
|
||||
|
||||
|
||||
def test_apply_model_wrapper_persists_a_proven_stale_layout_repair(monkeypatch):
|
||||
import ComfyUI_H3_Continuum_Join.model_patch as model_patch
|
||||
|
||||
audio = torch.zeros(1, 32, 2, 1)
|
||||
old_layout = object()
|
||||
replacement = object()
|
||||
payload = {
|
||||
"layout": old_layout,
|
||||
"keyframes": [
|
||||
{"resolved_frame_index": 0, "audio_latent": audio}
|
||||
],
|
||||
"refs": [],
|
||||
}
|
||||
calls = []
|
||||
|
||||
def fake_preflight(value, *, repair_stale):
|
||||
calls.append(bool(repair_stale))
|
||||
if repair_stale:
|
||||
value["layout"] = replacement
|
||||
return {"repaired": True}
|
||||
assert value["layout"] is replacement
|
||||
return {"repaired": False}
|
||||
|
||||
monkeypatch.setattr(model_patch, "preflight_packed_layout", fake_preflight)
|
||||
wrapper = _wrapper_factory(strict=True, debug=False)
|
||||
|
||||
result = wrapper(Executor(), torch.zeros(1), minimax_payload=payload)
|
||||
|
||||
assert calls == [True, False]
|
||||
assert payload["layout"] is replacement
|
||||
assert result["layout"] is replacement
|
||||
|
||||
|
||||
def test_apply_model_wrapper_fails_when_actual_topology_changes():
|
||||
video = torch.zeros(1, 24, 1, 2, 2)
|
||||
audio = torch.zeros(1, 32, 2, 1)
|
||||
ref = {
|
||||
"kind": "video_audio",
|
||||
"latent_t": 1,
|
||||
"latent_h": 2,
|
||||
"latent_w": 2,
|
||||
"ref_audio_t": 1,
|
||||
"latent": video,
|
||||
"audio_latent": audio,
|
||||
MARK_VIDEO_CONTEXT: True,
|
||||
MARK_CONTEXT_FRAMES: 1,
|
||||
MARK_AUDIO_CONTEXT: True,
|
||||
MARK_AUDIO_END_FRAME: 1.0,
|
||||
MARK_AUDIO_OVERHANG: 0.0,
|
||||
}
|
||||
payload = {"layout": _layout(), "keyframes": [], "refs": [ref]}
|
||||
wrapper = _wrapper_factory(strict=True, debug=False)
|
||||
options = {
|
||||
"spectrum_h3_actual": True,
|
||||
"cond_or_uncond": [0],
|
||||
"uuids": ["positive"],
|
||||
}
|
||||
wrapper(Executor(), torch.zeros(1), transformer_options=options, minimax_payload=payload)
|
||||
payload["layout"].position_ids[-1, 1] = 1.0
|
||||
with pytest.raises(RuntimeError, match="topology changed"):
|
||||
wrapper(Executor(), torch.zeros(1), transformer_options=options, minimax_payload=payload)
|
||||
|
||||
|
||||
def test_layout_validation_profiler_records_full_calls_groups_and_step_contribution():
|
||||
profiler = LayoutValidationProfiler(route_markers="Sage + Sol + Spectrum")
|
||||
token = profiler.begin_sampling_group(
|
||||
physical_group=2,
|
||||
logical_chunks=(2,),
|
||||
sampling_steps=20,
|
||||
)
|
||||
profiler.record_validation(
|
||||
{"status": "baseline_created"},
|
||||
0.01,
|
||||
full_validation=True,
|
||||
)
|
||||
profiler.record_validation(
|
||||
{"status": "baseline_matched"},
|
||||
0.03,
|
||||
full_validation=True,
|
||||
)
|
||||
profiler.finish_sampling_group(token)
|
||||
|
||||
report = "\n".join(profiler.report_lines())
|
||||
assert "route_markers=Sage + Sol + Spectrum" in report
|
||||
assert "validation_calls=2" in report
|
||||
assert "full_validation_count=2" in report
|
||||
assert "cumulative_wall_including_existing_device_to_host_sync=0.040000s" in report
|
||||
assert "sampling_steps_total=20" in report
|
||||
assert "validated_sampling_steps=20" in report
|
||||
assert "calls_per_validated_step=0.100" in report
|
||||
assert "wall_per_validated_step=2.000ms" in report
|
||||
assert "physical_group=2" in report
|
||||
|
||||
|
||||
def test_apply_model_wrapper_reports_validator_status_without_changing_payload():
|
||||
video = torch.zeros(1, 24, 1, 2, 2)
|
||||
audio = torch.zeros(1, 32, 2, 1)
|
||||
ref = {
|
||||
"kind": "video_audio",
|
||||
"latent_t": 1,
|
||||
"latent_h": 2,
|
||||
"latent_w": 2,
|
||||
"ref_audio_t": 1,
|
||||
"latent": video,
|
||||
"audio_latent": audio,
|
||||
MARK_VIDEO_CONTEXT: True,
|
||||
MARK_CONTEXT_FRAMES: 1,
|
||||
MARK_AUDIO_CONTEXT: True,
|
||||
MARK_AUDIO_END_FRAME: 1.0,
|
||||
MARK_AUDIO_OVERHANG: 0.0,
|
||||
}
|
||||
payload = {"layout": _layout(), "keyframes": [], "refs": [ref]}
|
||||
profiler = LayoutValidationProfiler(route_markers="Sage")
|
||||
wrapper = _wrapper_factory(
|
||||
strict=True,
|
||||
debug=False,
|
||||
validation_profiler=profiler,
|
||||
)
|
||||
|
||||
first = wrapper(Executor(), torch.zeros(1), minimax_payload=payload)
|
||||
second = wrapper(Executor(), torch.zeros(1), minimax_payload=payload)
|
||||
|
||||
assert first["cond_video_latents"] == [video]
|
||||
assert second["cond_audio_latents"] == [audio]
|
||||
assert profiler.validation_calls == 2
|
||||
assert profiler.full_validation_count == 2
|
||||
assert profiler.status_counts == {
|
||||
"baseline_created": 1,
|
||||
"baseline_matched": 1,
|
||||
}
|
||||
|
||||
|
||||
class FakeModelPatcher:
|
||||
def __init__(self):
|
||||
inner_type = type(
|
||||
"MiniMaxH3Model",
|
||||
(),
|
||||
{
|
||||
"__module__": "comfy.ldm.minimax.model",
|
||||
"blocks": (),
|
||||
"final_layer": object(),
|
||||
"patch_size": (1, 2, 2),
|
||||
"latents_dim": 24,
|
||||
"audio_latents_dim": 32,
|
||||
"rope_freqs": lambda self, position_ids, device: position_ids,
|
||||
},
|
||||
)
|
||||
self.model = SimpleNamespace(diffusion_model=inner_type())
|
||||
self.model_options = {}
|
||||
self.added = []
|
||||
self.removed = []
|
||||
|
||||
def clone(self):
|
||||
clone = FakeModelPatcher()
|
||||
clone.model = self.model
|
||||
clone.model_options = {k: dict(v) if isinstance(v, dict) else v for k, v in self.model_options.items()}
|
||||
return clone
|
||||
|
||||
def add_wrapper_with_key(self, wrapper_type, key, wrapper):
|
||||
self.added.append((wrapper_type, key, wrapper))
|
||||
|
||||
def remove_wrappers_with_key(self, wrapper_type, key):
|
||||
self.removed.append((wrapper_type, key))
|
||||
|
||||
|
||||
def test_patch_model_validates_and_installs_per_model_wrapper(monkeypatch):
|
||||
import sys
|
||||
from types import ModuleType
|
||||
|
||||
extension = ModuleType("comfy.patcher_extension")
|
||||
extension.WrappersMP = SimpleNamespace(APPLY_MODEL="apply_model")
|
||||
comfy = sys.modules.get("comfy") or ModuleType("comfy")
|
||||
monkeypatch.setitem(sys.modules, "comfy", comfy)
|
||||
monkeypatch.setitem(sys.modules, "comfy.patcher_extension", extension)
|
||||
|
||||
patched = patch_model(FakeModelPatcher(), strict=True, debug=False)
|
||||
assert patched.removed[0][1] == "h3_continuum_join.apply_model.v1"
|
||||
assert patched.added[0][1] == "h3_continuum_join.apply_model.v1"
|
||||
assert patched.model_options["h3_continuum_join"]["api_version"] == 1
|
||||
|
||||
|
||||
def test_chunk_model_copy_on_write_and_context_scoped_hint(monkeypatch):
|
||||
import sys
|
||||
from types import ModuleType
|
||||
|
||||
extension = ModuleType("comfy.patcher_extension")
|
||||
extension.WrappersMP = SimpleNamespace(APPLY_MODEL="apply_model")
|
||||
comfy = sys.modules.get("comfy") or ModuleType("comfy")
|
||||
monkeypatch.setitem(sys.modules, "comfy", comfy)
|
||||
monkeypatch.setitem(sys.modules, "comfy.patcher_extension", extension)
|
||||
|
||||
source = FakeModelPatcher()
|
||||
clone_calls = 0
|
||||
original_clone = FakeModelPatcher.clone
|
||||
|
||||
def counted_clone(self):
|
||||
nonlocal clone_calls
|
||||
clone_calls += 1
|
||||
return original_clone(self)
|
||||
|
||||
monkeypatch.setattr(FakeModelPatcher, "clone", counted_clone)
|
||||
source.model_options = {"transformer_options": {"existing": "kept"}}
|
||||
first = clone_model_for_chunk(source, strict=True, debug=False, chunk_index=1, context_frames=None)
|
||||
second = clone_model_for_chunk(source, strict=True, debug=False, chunk_index=2, context_frames=22)
|
||||
third = clone_model_for_chunk(source, strict=True, debug=False, chunk_index=3, context_frames=22)
|
||||
|
||||
assert clone_calls == 3
|
||||
assert source.model_options == {"transformer_options": {"existing": "kept"}}
|
||||
assert CONTINUUM_INTEROP_KEY not in first.model_options["transformer_options"]
|
||||
request = second.model_options["transformer_options"][CONTINUUM_INTEROP_KEY]
|
||||
assert request == {
|
||||
"api": 1,
|
||||
"active": True,
|
||||
"min_actual_prefix_steps": 2,
|
||||
"chunk_index": 2,
|
||||
"context_frames": 22,
|
||||
}
|
||||
assert request is not third.model_options["transformer_options"][CONTINUUM_INTEROP_KEY]
|
||||
assert CONTINUUM_INTEROP_KEY not in source.model_options["transformer_options"]
|
||||
@@ -0,0 +1,95 @@
|
||||
import torch
|
||||
|
||||
from ComfyUI_H3_Continuum_Join.constants import (
|
||||
MARK_AUDIO_CONTEXT,
|
||||
MARK_VIDEO_CONTEXT,
|
||||
)
|
||||
from ComfyUI_H3_Continuum_Join.nodes import (
|
||||
POLICY_REPLACE,
|
||||
H3ContinuumAssemble,
|
||||
_conditioning_diagnostics,
|
||||
_prepare_conditioning,
|
||||
_trim_audio,
|
||||
)
|
||||
|
||||
|
||||
def test_prepare_conditioning_uses_one_video_audio_ref_and_moves_last():
|
||||
old_first = torch.zeros(1, 24, 1, 2, 2)
|
||||
old_last = torch.ones(1, 24, 1, 2, 2)
|
||||
tags = torch.tensor([1, 0, 0, 1])
|
||||
conditioning = [
|
||||
[
|
||||
torch.zeros(1, 4, 3),
|
||||
{
|
||||
"minimax_token_tags": tags,
|
||||
"minimax_frame_count": 124,
|
||||
"minimax_keyframes": [
|
||||
{"resolved_frame_index": 0, "latent": old_first},
|
||||
{"resolved_frame_index": 123, "latent": old_last},
|
||||
],
|
||||
},
|
||||
]
|
||||
]
|
||||
video_context = torch.randn(1, 24, 7, 2, 2)
|
||||
audio_context = torch.randn(1, 32, 2, 37)
|
||||
out = _prepare_conditioning(
|
||||
conditioning,
|
||||
video_context=video_context,
|
||||
audio_context=audio_context,
|
||||
audio_grid_offset=1 / 3,
|
||||
context_frames=22,
|
||||
new_frame_count=141,
|
||||
first_frame_policy=POLICY_REPLACE,
|
||||
preserve_last_frame=True,
|
||||
)
|
||||
meta = out[0][1]
|
||||
assert len(meta["minimax_keyframes"]) == 1
|
||||
assert meta["minimax_keyframes"][0]["resolved_frame_index"] == 140
|
||||
assert len(meta["minimax_refs"]) == 1
|
||||
ref = meta["minimax_refs"][0]
|
||||
assert ref["kind"] == "video_audio"
|
||||
assert ref[MARK_VIDEO_CONTEXT] is True
|
||||
assert ref[MARK_AUDIO_CONTEXT] is True
|
||||
assert ref["latent"] is video_context
|
||||
assert ref["audio_latent"] is audio_context
|
||||
assert _conditioning_diagnostics(conditioning)["visual_tokens"] == 2
|
||||
|
||||
|
||||
def test_prepare_video_only_context():
|
||||
conditioning = [[torch.zeros(1, 2, 3), {}]]
|
||||
video_context = torch.randn(1, 24, 2, 2, 2)
|
||||
out = _prepare_conditioning(
|
||||
conditioning,
|
||||
video_context=video_context,
|
||||
audio_context=None,
|
||||
audio_grid_offset=0.0,
|
||||
context_frames=5,
|
||||
new_frame_count=124,
|
||||
first_frame_policy=POLICY_REPLACE,
|
||||
preserve_last_frame=True,
|
||||
)
|
||||
ref = out[0][1]["minimax_refs"][0]
|
||||
assert ref["kind"] == "video"
|
||||
assert ref["ref_audio_t"] == 0
|
||||
assert MARK_AUDIO_CONTEXT not in ref
|
||||
|
||||
|
||||
def test_trim_audio_matches_video_duration():
|
||||
audio = {"waveform": torch.arange(1 * 2 * 4000).reshape(1, 2, 4000), "sample_rate": 1000}
|
||||
out = _trim_audio(audio, trim_frames=24, output_frames=48)
|
||||
assert out["waveform"].shape == (1, 2, 2000)
|
||||
assert out["waveform"][0, 0, 0] == audio["waveform"][0, 0, 1000]
|
||||
|
||||
|
||||
def test_assemble_segments():
|
||||
node = H3ContinuumAssemble()
|
||||
a_images = torch.zeros(24, 4, 6, 3)
|
||||
b_images = torch.ones(12, 4, 6, 3)
|
||||
a_audio = {"waveform": torch.zeros(1, 2, 1000), "sample_rate": 1000}
|
||||
# One extra sample is tolerated and corrected at the final total boundary.
|
||||
b_audio = {"waveform": torch.ones(1, 2, 501), "sample_rate": 1000}
|
||||
images, audio, report = node.assemble(a_images, a_audio, b_images, b_audio)
|
||||
assert images.shape[0] == 36
|
||||
assert audio["waveform"].shape[-1] == 1500
|
||||
assert torch.all(images[-12:] == 1)
|
||||
assert "sync correction -1" in report
|
||||
@@ -0,0 +1,515 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import gc
|
||||
import importlib.util
|
||||
import json
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import sys
|
||||
import threading
|
||||
import time
|
||||
import weakref
|
||||
|
||||
import pytest
|
||||
import torch
|
||||
|
||||
|
||||
MODULE_PATH = (
|
||||
Path(__file__).resolve().parents[1] / "tools" / "p20_file_backed_tensor_poc.py"
|
||||
)
|
||||
SPEC = importlib.util.spec_from_file_location("h3c_p20_file_backed_tensor_poc", MODULE_PATH)
|
||||
MODULE = importlib.util.module_from_spec(SPEC)
|
||||
assert SPEC.loader is not None
|
||||
sys.modules[SPEC.name] = MODULE
|
||||
SPEC.loader.exec_module(MODULE)
|
||||
|
||||
|
||||
def _known_files(root: Path) -> list[Path]:
|
||||
return sorted(path for path in root.iterdir() if path.name.startswith(MODULE.FILE_PREFIX))
|
||||
|
||||
|
||||
def test_shared_mapping_is_bit_exact_contiguous_and_write_through(tmp_path):
|
||||
manager = MODULE.StorageLifetimeManager(tmp_path)
|
||||
reference = torch.arange(120, dtype=torch.float32).reshape(2, 3, 4, 5)
|
||||
|
||||
with manager.allocate(tuple(reference.shape), dtype=reference.dtype) as allocation:
|
||||
allocation.tensor.copy_(reference)
|
||||
record = allocation.record
|
||||
output = allocation.publish()
|
||||
|
||||
assert output.shape == reference.shape
|
||||
assert output.dtype == reference.dtype
|
||||
assert output.device.type == "cpu"
|
||||
assert output.is_contiguous()
|
||||
assert output.contiguous().data_ptr() == output.data_ptr()
|
||||
assert record.data_path.stat().st_size == reference.numel() * reference.element_size()
|
||||
assert record.data_path.read_bytes() == reference.numpy().tobytes(order="C")
|
||||
assert torch.equal(output, reference)
|
||||
|
||||
storage_pointer = output.untyped_storage().data_ptr()
|
||||
assert output[1].untyped_storage().data_ptr() == storage_pointer
|
||||
assert output.detach().untyped_storage().data_ptr() == storage_pointer
|
||||
assert output.reshape(6, 4, 5).untyped_storage().data_ptr() == storage_pointer
|
||||
assert output.clone().untyped_storage().data_ptr() != storage_pointer
|
||||
|
||||
del output
|
||||
gc.collect()
|
||||
result = manager.collect_ready()
|
||||
assert result.reclaimed == 1
|
||||
assert result.deferred == 0
|
||||
assert not _known_files(tmp_path)
|
||||
|
||||
|
||||
def test_lifetime_waits_for_last_storage_alias_and_not_root_tensor(tmp_path):
|
||||
manager = MODULE.StorageLifetimeManager(tmp_path)
|
||||
with manager.allocate((4, 3, 2), dtype=torch.float32) as allocation:
|
||||
allocation.tensor.copy_(torch.arange(24, dtype=torch.float32).reshape(4, 3, 2))
|
||||
record = allocation.record
|
||||
output = allocation.publish()
|
||||
|
||||
view = output[1:]
|
||||
cache = {"images": view}
|
||||
root_reference = weakref.ref(output)
|
||||
del output
|
||||
gc.collect()
|
||||
|
||||
assert root_reference() is None
|
||||
assert float(cache["images"].sum()) == pytest.approx(261.0)
|
||||
first = manager.collect_ready()
|
||||
assert first.reclaimed == 0
|
||||
assert first.deferred == 1
|
||||
assert record.data_path.exists()
|
||||
assert record.metadata_path.exists()
|
||||
|
||||
del view
|
||||
cache.clear()
|
||||
gc.collect()
|
||||
second = manager.collect_ready()
|
||||
assert second.reclaimed == 1
|
||||
assert second.deferred == 0
|
||||
assert not record.data_path.exists()
|
||||
assert not record.metadata_path.exists()
|
||||
|
||||
|
||||
@pytest.mark.parametrize("exception_type", [RuntimeError, MODULE.ProbeCancelled])
|
||||
def test_unpublished_exception_and_cancel_remove_provisional_files(
|
||||
tmp_path,
|
||||
exception_type,
|
||||
):
|
||||
manager = MODULE.StorageLifetimeManager(tmp_path)
|
||||
with pytest.raises(exception_type):
|
||||
with manager.allocate((2, 2), dtype=torch.float32) as allocation:
|
||||
allocation.tensor.fill_(1.0)
|
||||
raise exception_type("stop before publish")
|
||||
|
||||
assert manager.tracked_count() == 0
|
||||
assert not _known_files(tmp_path)
|
||||
|
||||
|
||||
def test_mapping_creation_failure_removes_reserved_file(tmp_path, monkeypatch):
|
||||
manager = MODULE.StorageLifetimeManager(tmp_path)
|
||||
|
||||
def fail_from_file(*args, **kwargs):
|
||||
raise RuntimeError("synthetic mapping failure")
|
||||
|
||||
monkeypatch.setattr(MODULE.torch, "from_file", fail_from_file)
|
||||
with pytest.raises(RuntimeError, match="synthetic mapping failure"):
|
||||
manager.allocate((2, 2), dtype=torch.float32)
|
||||
assert not _known_files(tmp_path)
|
||||
|
||||
|
||||
def test_temporary_unlink_failure_preserves_cancel_and_is_retried(
|
||||
tmp_path,
|
||||
monkeypatch,
|
||||
):
|
||||
manager = MODULE.StorageLifetimeManager(tmp_path)
|
||||
original_unlink = MODULE._unlink_known
|
||||
fail_unlink = {"enabled": True}
|
||||
|
||||
def sharing_violation(root, path):
|
||||
if fail_unlink["enabled"]:
|
||||
raise PermissionError(32, "synthetic sharing violation", str(path))
|
||||
return original_unlink(root, path)
|
||||
|
||||
monkeypatch.setattr(MODULE, "_unlink_known", sharing_violation)
|
||||
with pytest.raises(MODULE.ProbeCancelled, match="original cancel"):
|
||||
with manager.allocate((2, 2), dtype=torch.float32) as allocation:
|
||||
allocation.tensor.fill_(1.0)
|
||||
raise MODULE.ProbeCancelled("original cancel")
|
||||
|
||||
assert manager.pending_count() == 1
|
||||
assert len(_known_files(tmp_path)) == 2
|
||||
fail_unlink["enabled"] = False
|
||||
result = manager.collect_ready()
|
||||
assert result.reclaimed == 1
|
||||
assert result.deferred == 0
|
||||
assert manager.pending_count() == 0
|
||||
assert not _known_files(tmp_path)
|
||||
|
||||
|
||||
def test_cancel_after_backing_file_create_does_not_leave_orphan(
|
||||
tmp_path,
|
||||
monkeypatch,
|
||||
):
|
||||
manager = MODULE.StorageLifetimeManager(tmp_path)
|
||||
original_close = MODULE.os.close
|
||||
injected = False
|
||||
sentinel_path = tmp_path / "unrelated-live-descriptor.bin"
|
||||
sentinel_descriptor = None
|
||||
|
||||
def cancel_after_real_close(descriptor):
|
||||
nonlocal injected, sentinel_descriptor
|
||||
original_close(descriptor)
|
||||
if not injected:
|
||||
injected = True
|
||||
opened = MODULE.os.open(
|
||||
sentinel_path,
|
||||
MODULE.os.O_CREAT | MODULE.os.O_EXCL | MODULE.os.O_RDWR,
|
||||
0o600,
|
||||
)
|
||||
if opened != descriptor:
|
||||
MODULE.os.dup2(opened, descriptor)
|
||||
original_close(opened)
|
||||
opened = descriptor
|
||||
sentinel_descriptor = opened
|
||||
raise MODULE.ProbeCancelled("cancel after backing file create")
|
||||
|
||||
try:
|
||||
monkeypatch.setattr(MODULE.os, "close", cancel_after_real_close)
|
||||
with pytest.raises(MODULE.ProbeCancelled, match="after backing file create"):
|
||||
manager.allocate((2, 2), dtype=torch.float32)
|
||||
finally:
|
||||
monkeypatch.setattr(MODULE.os, "close", original_close)
|
||||
|
||||
assert sentinel_descriptor is not None
|
||||
MODULE.os.write(sentinel_descriptor, b"still-open")
|
||||
original_close(sentinel_descriptor)
|
||||
assert sentinel_path.read_bytes() == b"still-open"
|
||||
manager.collect_ready()
|
||||
assert manager.pending_count() == 0
|
||||
assert not _known_files(tmp_path)
|
||||
|
||||
|
||||
def test_dropped_unpublished_allocation_is_finalized(tmp_path):
|
||||
manager = MODULE.StorageLifetimeManager(tmp_path)
|
||||
allocation = manager.allocate((2, 2), dtype=torch.float32)
|
||||
allocation.tensor.fill_(3.0)
|
||||
allocation_reference = weakref.ref(allocation)
|
||||
del allocation
|
||||
gc.collect()
|
||||
|
||||
assert allocation_reference() is None
|
||||
manager.collect_ready()
|
||||
assert manager.pending_count() == 0
|
||||
assert not _known_files(tmp_path)
|
||||
|
||||
|
||||
def test_cache_requeue_keeps_backing_file_count_bounded(tmp_path):
|
||||
manager = MODULE.StorageLifetimeManager(tmp_path)
|
||||
cache = {}
|
||||
|
||||
for index in range(20):
|
||||
with manager.allocate((2, 2), dtype=torch.float32) as allocation:
|
||||
allocation.tensor.fill_(float(index))
|
||||
output = allocation.publish()
|
||||
cache["same_node_output"] = output
|
||||
del output
|
||||
gc.collect()
|
||||
assert len(list(tmp_path.glob(f"{MODULE.FILE_PREFIX}*.bin"))) <= 2
|
||||
|
||||
same_requeue = cache["same_node_output"]
|
||||
assert same_requeue is cache["same_node_output"]
|
||||
manager.collect_ready()
|
||||
assert len(list(tmp_path.glob(f"{MODULE.FILE_PREFIX}*.bin"))) == 1
|
||||
cache.clear()
|
||||
del same_requeue
|
||||
gc.collect()
|
||||
result = manager.collect_ready()
|
||||
assert result.reclaimed == 1
|
||||
assert not _known_files(tmp_path)
|
||||
|
||||
|
||||
def test_published_downstream_error_keeps_cache_then_reclaims_after_eviction(tmp_path):
|
||||
manager = MODULE.StorageLifetimeManager(tmp_path)
|
||||
cache = {}
|
||||
try:
|
||||
with manager.allocate((2, 2), dtype=torch.float32) as allocation:
|
||||
allocation.tensor.fill_(4.0)
|
||||
output = allocation.publish()
|
||||
cache["assembler_output"] = output
|
||||
raise RuntimeError("downstream node failed")
|
||||
except RuntimeError:
|
||||
pass
|
||||
|
||||
del output
|
||||
gc.collect()
|
||||
held = manager.collect_ready()
|
||||
assert held.reclaimed == 0
|
||||
assert held.deferred == 1
|
||||
assert len(list(tmp_path.glob(f"{MODULE.FILE_PREFIX}*.bin"))) == 1
|
||||
|
||||
cache.clear()
|
||||
gc.collect()
|
||||
released = manager.collect_ready()
|
||||
assert released.reclaimed == 1
|
||||
assert released.deferred == 0
|
||||
assert not _known_files(tmp_path)
|
||||
|
||||
|
||||
def test_process_global_manager_survives_node_local_scope(tmp_path):
|
||||
first = MODULE.get_process_lifetime_manager(tmp_path)
|
||||
second = MODULE.get_process_lifetime_manager(tmp_path)
|
||||
assert first is second
|
||||
|
||||
with first.allocate((2, 2), dtype=torch.float32) as allocation:
|
||||
output = allocation.publish()
|
||||
manager_reference = weakref.ref(first)
|
||||
del first
|
||||
del second
|
||||
gc.collect()
|
||||
assert manager_reference() is not None
|
||||
|
||||
del output
|
||||
gc.collect()
|
||||
manager = MODULE.get_process_lifetime_manager(tmp_path)
|
||||
assert manager.collect_ready().reclaimed == 1
|
||||
assert not _known_files(tmp_path)
|
||||
|
||||
|
||||
def test_stale_child_files_are_reclaimed_but_live_and_unknown_files_are_kept(tmp_path):
|
||||
subprocess.run(
|
||||
[
|
||||
sys.executable,
|
||||
str(MODULE_PATH),
|
||||
"--root",
|
||||
str(tmp_path),
|
||||
"--crash-child",
|
||||
],
|
||||
check=True,
|
||||
)
|
||||
assert len(list(tmp_path.glob(f"{MODULE.FILE_PREFIX}*.bin"))) == 1
|
||||
assert len(list(tmp_path.glob(f"{MODULE.FILE_PREFIX}*.json"))) == 1
|
||||
|
||||
unknown = tmp_path / "unrelated.bin"
|
||||
unknown.write_bytes(b"do not delete")
|
||||
outside = tmp_path.parent / "outside.bin"
|
||||
outside.write_bytes(b"outside root")
|
||||
malicious_id = "f" * 32
|
||||
malicious_metadata = tmp_path / f"{MODULE.FILE_PREFIX}{malicious_id}.json"
|
||||
malicious_data = tmp_path / f"{MODULE.FILE_PREFIX}{malicious_id}.bin"
|
||||
malicious_data.write_bytes(b"protected")
|
||||
malicious_metadata.write_text(
|
||||
json.dumps(
|
||||
{
|
||||
"schema": MODULE.SCHEMA,
|
||||
"schema_version": MODULE.SCHEMA_VERSION,
|
||||
"allocation_id": malicious_id,
|
||||
"data_file": "..\\outside.bin",
|
||||
"owner_pid": -1,
|
||||
"created_at": 0,
|
||||
}
|
||||
),
|
||||
encoding="utf-8",
|
||||
)
|
||||
|
||||
result = MODULE.cleanup_stale_files(tmp_path, grace_seconds=0.0)
|
||||
assert result.removed_pairs == 1
|
||||
assert result.invalid_metadata == 1
|
||||
assert unknown.read_bytes() == b"do not delete"
|
||||
assert outside.read_bytes() == b"outside root"
|
||||
assert malicious_data.read_bytes() == b"protected"
|
||||
assert malicious_metadata.exists()
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("field", "value", "remove"),
|
||||
[
|
||||
("owner_pid", None, True),
|
||||
("owner_pid", -1, False),
|
||||
("owner_create_time", float("nan"), False),
|
||||
("created_at", float("nan"), False),
|
||||
],
|
||||
)
|
||||
def test_invalid_ownership_metadata_never_deletes_live_mapping(
|
||||
tmp_path,
|
||||
field,
|
||||
value,
|
||||
remove,
|
||||
):
|
||||
manager = MODULE.StorageLifetimeManager(tmp_path)
|
||||
with manager.allocate((2, 2), dtype=torch.float32) as allocation:
|
||||
record = allocation.record
|
||||
output = allocation.publish()
|
||||
|
||||
payload = json.loads(record.metadata_path.read_text(encoding="utf-8"))
|
||||
if remove:
|
||||
payload.pop(field)
|
||||
else:
|
||||
payload[field] = value
|
||||
record.metadata_path.write_text(json.dumps(payload), encoding="utf-8")
|
||||
|
||||
result = MODULE.cleanup_stale_files(tmp_path, grace_seconds=0.0)
|
||||
assert result.invalid_metadata == 1
|
||||
assert result.removed_pairs == 0
|
||||
assert record.data_path.exists()
|
||||
assert record.metadata_path.exists()
|
||||
assert float(output.sum()) == pytest.approx(0.0)
|
||||
|
||||
del output
|
||||
gc.collect()
|
||||
assert manager.collect_ready().reclaimed == 1
|
||||
assert not _known_files(tmp_path)
|
||||
|
||||
|
||||
def test_cleanup_waits_for_in_progress_allocation_root_lock(tmp_path):
|
||||
allocation_entered = threading.Event()
|
||||
allow_allocation = threading.Event()
|
||||
output_holder = []
|
||||
cleanup_holder = []
|
||||
|
||||
def allocation_hook(_path):
|
||||
allocation_entered.set()
|
||||
assert allow_allocation.wait(timeout=5.0)
|
||||
|
||||
manager = MODULE.StorageLifetimeManager(
|
||||
tmp_path,
|
||||
allocation_hook=allocation_hook,
|
||||
)
|
||||
|
||||
def allocate_output():
|
||||
with manager.allocate((2, 2), dtype=torch.float32) as allocation:
|
||||
output_holder.append(allocation.publish())
|
||||
|
||||
def cleanup():
|
||||
cleanup_holder.append(
|
||||
MODULE.cleanup_stale_files(tmp_path, grace_seconds=0.0)
|
||||
)
|
||||
|
||||
allocation_thread = threading.Thread(target=allocate_output)
|
||||
allocation_thread.start()
|
||||
assert allocation_entered.wait(timeout=5.0)
|
||||
cleanup_thread = threading.Thread(target=cleanup)
|
||||
cleanup_thread.start()
|
||||
assert cleanup_thread.is_alive()
|
||||
allow_allocation.set()
|
||||
allocation_thread.join(timeout=5.0)
|
||||
cleanup_thread.join(timeout=5.0)
|
||||
|
||||
assert not allocation_thread.is_alive()
|
||||
assert not cleanup_thread.is_alive()
|
||||
assert cleanup_holder[0].retained_live == 1
|
||||
assert len(list(tmp_path.glob(f"{MODULE.FILE_PREFIX}*.bin"))) == 1
|
||||
|
||||
output_holder.clear()
|
||||
gc.collect()
|
||||
assert manager.collect_ready().reclaimed == 1
|
||||
assert not _known_files(tmp_path)
|
||||
|
||||
|
||||
def test_root_lock_is_reentrant_when_finalizer_runs_during_allocation(tmp_path):
|
||||
first_manager = MODULE.StorageLifetimeManager(tmp_path)
|
||||
abandoned = first_manager.allocate((2, 2), dtype=torch.float32)
|
||||
cycle = [abandoned]
|
||||
cycle.append(cycle)
|
||||
del abandoned
|
||||
del cycle
|
||||
|
||||
def collect_abandoned_allocation(_path):
|
||||
gc.collect()
|
||||
|
||||
second_manager = MODULE.StorageLifetimeManager(
|
||||
tmp_path,
|
||||
allocation_hook=collect_abandoned_allocation,
|
||||
)
|
||||
started = time.perf_counter()
|
||||
with second_manager.allocate((2, 2), dtype=torch.float32) as allocation:
|
||||
output = allocation.publish()
|
||||
elapsed = time.perf_counter() - started
|
||||
|
||||
assert elapsed < 2.0
|
||||
first_manager.collect_ready()
|
||||
del output
|
||||
gc.collect()
|
||||
second_manager.collect_ready()
|
||||
assert not _known_files(tmp_path)
|
||||
|
||||
|
||||
def test_cleanup_collect_and_gc_finalizer_have_no_lock_order_deadlock(tmp_path):
|
||||
subprocess.run(
|
||||
[
|
||||
sys.executable,
|
||||
str(MODULE_PATH),
|
||||
"--root",
|
||||
str(tmp_path),
|
||||
"--lock-order-child",
|
||||
],
|
||||
check=True,
|
||||
timeout=10.0,
|
||||
)
|
||||
assert not _known_files(tmp_path)
|
||||
|
||||
|
||||
def test_live_sidecar_is_retained_and_cleanup_is_idempotent(tmp_path):
|
||||
manager = MODULE.StorageLifetimeManager(tmp_path)
|
||||
with manager.allocate((2, 2), dtype=torch.float32) as allocation:
|
||||
allocation.tensor.fill_(2.0)
|
||||
record = allocation.record
|
||||
output = allocation.publish()
|
||||
|
||||
live = MODULE.cleanup_stale_files(tmp_path, grace_seconds=0.0)
|
||||
assert live.retained_live == 1
|
||||
assert record.data_path.exists()
|
||||
assert record.metadata_path.exists()
|
||||
|
||||
del output
|
||||
gc.collect()
|
||||
assert manager.collect_ready().reclaimed == 1
|
||||
empty = MODULE.cleanup_stale_files(tmp_path, grace_seconds=0.0)
|
||||
assert empty.removed_pairs == 0
|
||||
assert empty.removed_orphans == 0
|
||||
assert not _known_files(tmp_path)
|
||||
|
||||
|
||||
def test_orphan_and_partial_cleanup_respects_grace_period(tmp_path):
|
||||
allocation_id = "a" * 32
|
||||
orphan = tmp_path / f"{MODULE.FILE_PREFIX}{allocation_id}.bin"
|
||||
partial = tmp_path / f"{MODULE.FILE_PREFIX}{allocation_id}.json.partial"
|
||||
orphan.write_bytes(b"orphan")
|
||||
partial.write_text("partial", encoding="utf-8")
|
||||
now = time.time()
|
||||
|
||||
young = MODULE.cleanup_stale_files(
|
||||
tmp_path,
|
||||
grace_seconds=60.0,
|
||||
now=now,
|
||||
)
|
||||
assert young.retained_young == 2
|
||||
assert orphan.exists()
|
||||
assert partial.exists()
|
||||
|
||||
old = MODULE.cleanup_stale_files(
|
||||
tmp_path,
|
||||
grace_seconds=60.0,
|
||||
now=now + 61.0,
|
||||
)
|
||||
assert old.removed_orphans == 2
|
||||
assert not orphan.exists()
|
||||
assert not partial.exists()
|
||||
|
||||
|
||||
@pytest.mark.parametrize("shape", [(2.5, 2), (True, 2), ("2", 2), ()])
|
||||
def test_shape_contract_rejects_lossy_or_empty_dimensions(tmp_path, shape):
|
||||
manager = MODULE.StorageLifetimeManager(tmp_path)
|
||||
with pytest.raises((TypeError, ValueError)):
|
||||
manager.allocate(shape, dtype=torch.float32)
|
||||
assert not _known_files(tmp_path)
|
||||
|
||||
|
||||
def test_standalone_probe_passes(tmp_path):
|
||||
result = MODULE.run_probe(tmp_path)
|
||||
assert result.bit_exact
|
||||
assert result.file_size == result.expected_bytes
|
||||
assert result.root_released_while_alias_alive
|
||||
assert result.deferred_while_alias_alive == 1
|
||||
assert result.reclaimed_after_last_alias == 1
|
||||
assert result.files_remaining == 0
|
||||
@@ -0,0 +1,585 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
import torch
|
||||
|
||||
from ComfyUI_H3_Continuum_Join.constants import (
|
||||
DIAGNOSTICS_BASIC,
|
||||
DIAGNOSTICS_FULL,
|
||||
DIAGNOSTICS_OFF,
|
||||
)
|
||||
from ComfyUI_H3_Continuum_Join import hardening
|
||||
from ComfyUI_H3_Continuum_Join.hardening import enrich_assembly_plan
|
||||
from ComfyUI_H3_Continuum_Join.v3 import memory_attribution as memory
|
||||
from ComfyUI_H3_Continuum_Join.v3 import driving_nodes as driving_nodes_module
|
||||
from ComfyUI_H3_Continuum_Join.v3.driving_nodes import (
|
||||
H3ContinuumAssembleSeamV34,
|
||||
H3ContinuumAssembleSeamV35,
|
||||
NODE_CLASS_MAPPINGS,
|
||||
NODE_DISPLAY_NAME_MAPPINGS,
|
||||
)
|
||||
from ComfyUI_H3_Continuum_Join.v3.plan import ASSEMBLY_PLAN_MAGIC
|
||||
|
||||
|
||||
def _terminal_plan():
|
||||
plan = enrich_assembly_plan(
|
||||
{
|
||||
"magic": ASSEMBLY_PLAN_MAGIC,
|
||||
"schema_version": 1,
|
||||
"fps": 24,
|
||||
"width": 96,
|
||||
"height": 64,
|
||||
"chunk_seconds": 5.0,
|
||||
"target_frames": 360,
|
||||
"preserve_final_frame": True,
|
||||
"chunks": [
|
||||
{
|
||||
"sequence_index": 1,
|
||||
"chunk_index": 1,
|
||||
"total_frames": 124,
|
||||
"trim_frames": 0,
|
||||
"net_frames": 124,
|
||||
"context_frames": 0,
|
||||
"expected_video_latent_t": 37,
|
||||
"expected_audio_latent_t": 207,
|
||||
},
|
||||
{
|
||||
"sequence_index": 2,
|
||||
"chunk_index": 2,
|
||||
"total_frames": 141,
|
||||
"trim_frames": 22,
|
||||
"net_frames": 119,
|
||||
"context_frames": 22,
|
||||
"expected_video_latent_t": 42,
|
||||
"expected_audio_latent_t": 235,
|
||||
},
|
||||
{
|
||||
"sequence_index": 3,
|
||||
"chunk_index": 3,
|
||||
"total_frames": 141,
|
||||
"trim_frames": 22,
|
||||
"net_frames": 119,
|
||||
"context_frames": 22,
|
||||
"expected_video_latent_t": 42,
|
||||
"expected_audio_latent_t": 235,
|
||||
},
|
||||
],
|
||||
}
|
||||
)
|
||||
plan["decode_groups"] = [
|
||||
{
|
||||
"logical_chunk_indices": [1],
|
||||
"terminal_merged": False,
|
||||
"total_frames": 124,
|
||||
"trim_frames": 0,
|
||||
"net_frames": 124,
|
||||
"context_frames": 0,
|
||||
"expected_video_latent_t": 37,
|
||||
"expected_audio_latent_t": 207,
|
||||
"frame_start": 0,
|
||||
"frame_stop": 124,
|
||||
},
|
||||
{
|
||||
"logical_chunk_indices": [2, 3],
|
||||
"terminal_merged": True,
|
||||
"total_frames": 260,
|
||||
"trim_frames": 22,
|
||||
"net_frames": 238,
|
||||
"context_frames": 22,
|
||||
"expected_video_latent_t": 77,
|
||||
"expected_audio_latent_t": 433,
|
||||
"frame_start": 124,
|
||||
"frame_stop": 362,
|
||||
},
|
||||
]
|
||||
plan["physical_decode_group_count"] = 2
|
||||
return plan
|
||||
|
||||
|
||||
def _decoded(*, image_dtype=torch.float16, device=None):
|
||||
images = [
|
||||
torch.empty((124, 4, 6, 3), dtype=image_dtype, device=device),
|
||||
torch.empty((260, 4, 6, 3), dtype=image_dtype, device=device),
|
||||
]
|
||||
audio = [
|
||||
{
|
||||
"waveform": torch.empty(
|
||||
(1, 2, 500000),
|
||||
dtype=torch.float32,
|
||||
device=device,
|
||||
),
|
||||
"sample_rate": 32000,
|
||||
},
|
||||
{
|
||||
"waveform": torch.empty(
|
||||
(1, 2, 500000),
|
||||
dtype=torch.float32,
|
||||
device=device,
|
||||
),
|
||||
"sample_rate": 32000,
|
||||
},
|
||||
]
|
||||
return images, audio
|
||||
|
||||
|
||||
def test_snapshot_is_cpu_safe_read_only_and_deduplicates_retained_storage(
|
||||
monkeypatch,
|
||||
):
|
||||
video_storage = torch.arange(24, dtype=torch.float32)
|
||||
audio_storage = torch.arange(12, dtype=torch.float32)
|
||||
entries = [
|
||||
{"video": video_storage[:16], "audio": audio_storage[:8]},
|
||||
{"video": video_storage[8:], "audio": audio_storage[4:]},
|
||||
]
|
||||
monkeypatch.setattr(memory.torch.cuda, "is_available", lambda: False)
|
||||
for name in (
|
||||
"memory_allocated",
|
||||
"memory_reserved",
|
||||
"max_memory_allocated",
|
||||
"synchronize",
|
||||
"reset_peak_memory_stats",
|
||||
"empty_cache",
|
||||
):
|
||||
monkeypatch.setattr(
|
||||
memory.torch.cuda,
|
||||
name,
|
||||
lambda *args, _name=name, **kwargs: (_ for _ in ()).throw(
|
||||
AssertionError(f"unexpected CUDA call: {_name}")
|
||||
),
|
||||
)
|
||||
|
||||
line = memory.format_attribution_snapshot(
|
||||
"test",
|
||||
retained_entries=entries,
|
||||
)
|
||||
assert f"retained_video={video_storage.untyped_storage().nbytes()} bytes" in line
|
||||
assert f"retained_audio={audio_storage.untyped_storage().nbytes()} bytes" in line
|
||||
assert "CUDA_allocated=n/a" in line
|
||||
assert "CUDA_peak_allocated_since_external_reset=n/a" in line
|
||||
|
||||
|
||||
def test_snapshot_counter_failure_is_reported_as_unavailable(monkeypatch):
|
||||
monkeypatch.setattr(memory, "_process_counters", lambda: (None, None))
|
||||
monkeypatch.setattr(memory, "_cuda_counters", lambda: (None, None, None))
|
||||
line = memory.format_attribution_snapshot("failure-safe")
|
||||
assert "RSS=n/a" in line
|
||||
assert "system_available=n/a" in line
|
||||
assert "CUDA_reserved=n/a" in line
|
||||
|
||||
|
||||
def test_snapshot_counts_refine_context_storage_once():
|
||||
shared = torch.arange(32, dtype=torch.float32)
|
||||
refine_context = {
|
||||
"groups": (
|
||||
{
|
||||
"conditioning": (
|
||||
(shared[:8], {"reference": shared[8:16]}),
|
||||
),
|
||||
"first_image": shared[16:24],
|
||||
},
|
||||
),
|
||||
"alias": shared[4:28],
|
||||
}
|
||||
|
||||
line = memory.format_attribution_snapshot(
|
||||
"refine-context",
|
||||
retained_refine_context=refine_context,
|
||||
)
|
||||
|
||||
expected = shared.untyped_storage().nbytes()
|
||||
assert f"retained_refine_context_CPU={expected} bytes" in line
|
||||
assert "retained_refine_context_GPU=0 bytes" in line
|
||||
|
||||
|
||||
def test_cuda_snapshot_reads_counters_without_allocator_mutation(monkeypatch):
|
||||
monkeypatch.setattr(memory.torch.cuda, "is_available", lambda: True)
|
||||
monkeypatch.setattr(memory.torch.cuda, "memory_allocated", lambda: 11)
|
||||
monkeypatch.setattr(memory.torch.cuda, "memory_reserved", lambda: 22)
|
||||
monkeypatch.setattr(memory.torch.cuda, "max_memory_allocated", lambda: 33)
|
||||
for name in (
|
||||
"synchronize",
|
||||
"reset_peak_memory_stats",
|
||||
"empty_cache",
|
||||
):
|
||||
monkeypatch.setattr(
|
||||
memory.torch.cuda,
|
||||
name,
|
||||
lambda *args, _name=name, **kwargs: (_ for _ in ()).throw(
|
||||
AssertionError(f"unexpected CUDA mutation: {_name}")
|
||||
),
|
||||
)
|
||||
|
||||
line = memory.format_attribution_snapshot("cuda-read-only")
|
||||
|
||||
assert "CUDA_allocated=0.0 MiB" in line
|
||||
assert "CUDA_reserved=0.0 MiB" in line
|
||||
assert "CUDA_peak_allocated_since_external_reset=0.0 MiB" in line
|
||||
|
||||
|
||||
def test_performance_attribution_reports_group_and_summary_without_cuda_sync(
|
||||
monkeypatch,
|
||||
):
|
||||
ticks = iter((0.0, 0.0, 1.0, 2.0, 4.0, 5.0, 9.0, 10.0, 11.0, 12.0))
|
||||
monkeypatch.setattr(memory.time, "perf_counter", lambda: next(ticks))
|
||||
monkeypatch.setattr(
|
||||
memory.torch.cuda,
|
||||
"synchronize",
|
||||
lambda *args, **kwargs: (_ for _ in ()).throw(
|
||||
AssertionError("performance attribution must not synchronize CUDA")
|
||||
),
|
||||
)
|
||||
|
||||
collector = memory.MemoryAttributionCollector()
|
||||
collector.capture_sequence_start()
|
||||
collector.finish_phase(phase="preparation")
|
||||
collector.start_phase(
|
||||
phase="group_prepare", physical_group=1, logical_chunks=(1,)
|
||||
)
|
||||
collector.finish_phase(
|
||||
phase="group_prepare", physical_group=1, logical_chunks=(1,)
|
||||
)
|
||||
collector.start_phase(
|
||||
phase="sampling", physical_group=1, logical_chunks=(1,)
|
||||
)
|
||||
collector.finish_phase(
|
||||
phase="sampling", physical_group=1, logical_chunks=(1,)
|
||||
)
|
||||
collector.start_phase(
|
||||
phase="cpu_commit_validation", physical_group=1, logical_chunks=(1,)
|
||||
)
|
||||
collector.finish_phase(
|
||||
phase="cpu_commit_validation", physical_group=1, logical_chunks=(1,)
|
||||
)
|
||||
collector.capture_sequence_complete(entries=[])
|
||||
|
||||
group_line = next(
|
||||
line
|
||||
for line in collector.lines
|
||||
if line.startswith("Performance [V3.5 physical group 1")
|
||||
)
|
||||
summary = next(
|
||||
line
|
||||
for line in collector.lines
|
||||
if line.startswith("Performance [V3.5 summary]")
|
||||
)
|
||||
assert "group_prepare=2.000000s" in group_line
|
||||
assert "sampling=4.000000s" in group_line
|
||||
assert "cpu_commit_validation=1.000000s" in group_line
|
||||
assert "refine_context=n/a" in group_line
|
||||
assert "host_wall_including_diagnostics=12.000000s" in summary
|
||||
assert "preparation=1.000000s" in summary
|
||||
assert "CUDA_synchronize=not_used" in summary
|
||||
|
||||
|
||||
def test_performance_attribution_reports_conditioning_subphases_without_flattening():
|
||||
collector = memory.MemoryAttributionCollector()
|
||||
collector.capture_sequence_start()
|
||||
collector.start_phase(phase="conditioning")
|
||||
collector.start_phase(phase="conditioning_identity_video_vae")
|
||||
collector.finish_phase(phase="conditioning_identity_video_vae")
|
||||
collector.start_phase(phase="conditioning_reference_audio_vae")
|
||||
collector.finish_phase(phase="conditioning_reference_audio_vae")
|
||||
collector.start_phase(phase="conditioning_prompt_clip")
|
||||
collector.finish_phase(phase="conditioning_prompt_clip")
|
||||
collector.finish_phase(phase="conditioning")
|
||||
collector.capture_sequence_complete(entries=[])
|
||||
|
||||
summary = next(
|
||||
line
|
||||
for line in collector.lines
|
||||
if line.startswith("Performance [V3.5 summary]")
|
||||
)
|
||||
assert "conditioning_identity_video_vae=" in summary
|
||||
assert "conditioning_reference_audio_vae=" in summary
|
||||
assert "conditioning_prompt_clip=" in summary
|
||||
assert "conditioning_reference_image_vae=n/a" in summary
|
||||
assert "conditioning_identity_video_vae=1" in summary
|
||||
assert "conditioning_reference_audio_vae=1" in summary
|
||||
assert "conditioning_prompt_clip=1" in summary
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"method",
|
||||
(
|
||||
"capture_sequence_start",
|
||||
"capture_group",
|
||||
"capture_sequence_complete",
|
||||
),
|
||||
)
|
||||
def test_each_collector_stage_is_fail_soft(method):
|
||||
class ExplodingCollector:
|
||||
def __init__(self):
|
||||
self.lines = []
|
||||
|
||||
def __getattr__(self, name):
|
||||
if name.startswith("capture_"):
|
||||
return lambda **_kwargs: (_ for _ in ()).throw(
|
||||
RuntimeError(f"{name} failed")
|
||||
)
|
||||
raise AttributeError(name)
|
||||
|
||||
collector = ExplodingCollector()
|
||||
memory.capture_attribution_fail_soft(collector, method)
|
||||
|
||||
assert collector.lines == [
|
||||
f"Memory attribution [{method}]: unavailable "
|
||||
f"(RuntimeError: {method} failed)"
|
||||
]
|
||||
|
||||
|
||||
def test_sequence_start_and_complete_failures_do_not_replace_sampling_result():
|
||||
class ExplodingCollector:
|
||||
def __init__(self):
|
||||
self.lines = []
|
||||
|
||||
def capture_sequence_start(self):
|
||||
raise RuntimeError("start failed")
|
||||
|
||||
def capture_sequence_complete(self, **_kwargs):
|
||||
raise RuntimeError("complete failed")
|
||||
|
||||
collector = ExplodingCollector()
|
||||
entries = [{"video": torch.zeros(1), "audio": torch.zeros(1)}]
|
||||
session = {"chunks": entries}
|
||||
refine_context = {"groups": ()}
|
||||
base_result = (entries, "state", session, "base report", refine_context)
|
||||
base_calls = []
|
||||
|
||||
def base(
|
||||
*,
|
||||
video_vae,
|
||||
latent_only,
|
||||
diagnostics_mode,
|
||||
memory_attribution,
|
||||
_memory_attribution_collector=None,
|
||||
):
|
||||
base_calls.append(_memory_attribution_collector)
|
||||
return base_result
|
||||
|
||||
result = hardening.run_sequence_with_hardening(
|
||||
base,
|
||||
(),
|
||||
{
|
||||
"video_vae": object(),
|
||||
"latent_only": True,
|
||||
"diagnostics_mode": DIAGNOSTICS_FULL,
|
||||
"memory_attribution": True,
|
||||
"_memory_attribution_collector": collector,
|
||||
},
|
||||
)
|
||||
|
||||
assert base_calls == [collector]
|
||||
assert result[:3] == base_result[:3]
|
||||
assert result[4] is refine_context
|
||||
assert "base report" in result[3]
|
||||
assert "capture_sequence_start" in result[3]
|
||||
assert "capture_sequence_complete" in result[3]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("diagnostics", (DIAGNOSTICS_BASIC, DIAGNOSTICS_OFF))
|
||||
def test_v35_attribution_is_absent_outside_detailed_report(diagnostics):
|
||||
base_result = ("entries", "state", "session", "base report", "context")
|
||||
calls = []
|
||||
|
||||
def base(
|
||||
*,
|
||||
video_vae,
|
||||
latent_only,
|
||||
diagnostics_mode,
|
||||
memory_attribution,
|
||||
_memory_attribution_collector=None,
|
||||
):
|
||||
calls.append(_memory_attribution_collector)
|
||||
return base_result
|
||||
|
||||
result = hardening.run_sequence_with_hardening(
|
||||
base,
|
||||
(),
|
||||
{
|
||||
"video_vae": object(),
|
||||
"latent_only": True,
|
||||
"diagnostics_mode": diagnostics,
|
||||
"memory_attribution": True,
|
||||
},
|
||||
)
|
||||
|
||||
assert result is base_result
|
||||
assert calls == [None]
|
||||
assert "Memory [V3.5" not in result[3]
|
||||
|
||||
|
||||
def test_v34_private_flag_off_keeps_existing_detailed_report_path():
|
||||
entries = [{"video": torch.zeros(1), "audio": torch.zeros(1)}]
|
||||
session = {"chunks": entries}
|
||||
calls = []
|
||||
|
||||
def base(
|
||||
*,
|
||||
video_vae,
|
||||
latent_only,
|
||||
diagnostics_mode,
|
||||
memory_attribution=False,
|
||||
_memory_attribution_collector=None,
|
||||
):
|
||||
calls.append((memory_attribution, _memory_attribution_collector))
|
||||
return entries, "state", session, "base report"
|
||||
|
||||
result = hardening.run_sequence_with_hardening(
|
||||
base,
|
||||
(),
|
||||
{
|
||||
"video_vae": object(),
|
||||
"latent_only": True,
|
||||
"diagnostics_mode": DIAGNOSTICS_FULL,
|
||||
"memory_attribution": False,
|
||||
},
|
||||
)
|
||||
|
||||
assert calls == [(False, None)]
|
||||
assert result[0] is entries
|
||||
assert result[2] is session
|
||||
assert "Memory [sequence start]" in result[3]
|
||||
assert "Memory [sequence complete]" in result[3]
|
||||
assert "Memory [V3.5" not in result[3]
|
||||
|
||||
|
||||
def test_projection_uses_physical_groups_actual_dtypes_and_exact_target():
|
||||
images, audio = _decoded()
|
||||
off = memory.project_assembly_buffers(
|
||||
images=images,
|
||||
audio=audio,
|
||||
assembly_plan=_terminal_plan(),
|
||||
exact_total_duration=False,
|
||||
)
|
||||
assert off.natural_frames == 362
|
||||
assert off.target_frames == 362
|
||||
assert off.natural_image_bytes == 52128
|
||||
assert off.natural_audio_bytes == 3861336
|
||||
assert off.final_image_bytes == 52128
|
||||
assert off.final_audio_bytes == 3861336
|
||||
assert off.frame_count_adjustment_required is False
|
||||
|
||||
exact = memory.project_assembly_buffers(
|
||||
images=images,
|
||||
audio=audio,
|
||||
assembly_plan=_terminal_plan(),
|
||||
exact_total_duration=True,
|
||||
)
|
||||
assert exact.natural_frames == 362
|
||||
assert exact.target_frames == 360
|
||||
assert exact.natural_image_bytes == 52128
|
||||
assert exact.natural_audio_bytes == 3861336
|
||||
assert exact.final_image_bytes == 51840
|
||||
assert exact.final_audio_bytes == 3840000
|
||||
assert exact.frame_count_adjustment_required is True
|
||||
|
||||
|
||||
def test_projection_uses_python_int_for_real_1152_square_output():
|
||||
images, audio = _decoded(device="meta")
|
||||
images = [
|
||||
torch.empty((124, 1152, 1152, 3), dtype=torch.float32, device="meta"),
|
||||
torch.empty((260, 1152, 1152, 3), dtype=torch.float32, device="meta"),
|
||||
]
|
||||
projection = memory.project_assembly_buffers(
|
||||
images=images,
|
||||
audio=audio,
|
||||
assembly_plan=_terminal_plan(),
|
||||
exact_total_duration=True,
|
||||
)
|
||||
assert projection.final_image_bytes == 5733089280
|
||||
assert isinstance(projection.final_image_bytes, int)
|
||||
|
||||
|
||||
def test_v35_assembler_adds_projection_only_for_detailed_report(monkeypatch):
|
||||
input_images, input_audio = _decoded()
|
||||
output_images = torch.zeros((1, 1, 1, 3))
|
||||
output_audio = {"waveform": torch.zeros((1, 2, 1)), "sample_rate": 32000}
|
||||
base_calls = []
|
||||
|
||||
def fake_v35_assemble(**kwargs):
|
||||
base_calls.append(kwargs)
|
||||
return (
|
||||
output_images,
|
||||
output_audio,
|
||||
"base report\nMemory [assemble preflight]: test\n"
|
||||
"Memory [assemble complete]: test",
|
||||
)
|
||||
|
||||
monkeypatch.setattr(
|
||||
driving_nodes_module,
|
||||
"assemble_decoded_chunks_v35",
|
||||
fake_v35_assemble,
|
||||
)
|
||||
node = H3ContinuumAssembleSeamV35()
|
||||
detailed_images, detailed_audio, detailed_report = node.assemble(
|
||||
images=input_images,
|
||||
audio=input_audio,
|
||||
assembly_plan=_terminal_plan(),
|
||||
exact_total_duration=True,
|
||||
audio_seam="Auto",
|
||||
video_seam="Auto",
|
||||
buffer_backend="RAM",
|
||||
diagnostics=DIAGNOSTICS_FULL,
|
||||
)
|
||||
assert detailed_images is output_images
|
||||
assert detailed_audio is output_audio
|
||||
assert "Projected assembly buffers [V3.5]" in detailed_report
|
||||
assert detailed_report.index("Memory [assemble preflight]") < detailed_report.index(
|
||||
"Projected assembly buffers [V3.5]"
|
||||
)
|
||||
assert detailed_report.index("Projected assembly buffers [V3.5]") < (
|
||||
detailed_report.index("Memory [assemble complete]")
|
||||
)
|
||||
|
||||
_, _, basic_report = node.assemble(
|
||||
images=input_images,
|
||||
audio=input_audio,
|
||||
assembly_plan=_terminal_plan(),
|
||||
exact_total_duration=True,
|
||||
audio_seam="Auto",
|
||||
video_seam="Auto",
|
||||
buffer_backend="RAM",
|
||||
diagnostics=DIAGNOSTICS_BASIC,
|
||||
)
|
||||
assert "Projected assembly buffers [V3.5]" not in basic_report
|
||||
assert len(base_calls) == 2
|
||||
|
||||
|
||||
def test_v35_assembler_projection_failure_never_replaces_base_execution(monkeypatch):
|
||||
output_images = torch.zeros((1, 1, 1, 3))
|
||||
output_audio = {"waveform": torch.zeros((1, 2, 1)), "sample_rate": 32000}
|
||||
monkeypatch.setattr(
|
||||
driving_nodes_module,
|
||||
"assemble_decoded_chunks_v35",
|
||||
lambda **kwargs: (output_images, output_audio, "base report"),
|
||||
)
|
||||
images, audio, report = H3ContinuumAssembleSeamV35().assemble(
|
||||
images=[],
|
||||
audio=[],
|
||||
assembly_plan={},
|
||||
exact_total_duration=True,
|
||||
audio_seam="Auto",
|
||||
video_seam="Auto",
|
||||
buffer_backend="RAM",
|
||||
diagnostics=DIAGNOSTICS_FULL,
|
||||
)
|
||||
assert images is output_images
|
||||
assert audio is output_audio
|
||||
assert "Projected assembly buffers [V3.5]: unavailable" in report
|
||||
|
||||
|
||||
def test_v35_assembler_is_registered_without_replacing_v34():
|
||||
from ComfyUI_H3_Continuum_Join import nodes as root_nodes
|
||||
|
||||
assert NODE_CLASS_MAPPINGS["H3ContinuumAssembleSeamV34"] is (
|
||||
H3ContinuumAssembleSeamV34
|
||||
)
|
||||
assert NODE_CLASS_MAPPINGS["H3ContinuumAssembleSeamV35"] is (
|
||||
H3ContinuumAssembleSeamV35
|
||||
)
|
||||
assert root_nodes.NODE_CLASS_MAPPINGS["H3ContinuumAssembleSeamV35"] is (
|
||||
H3ContinuumAssembleSeamV35
|
||||
)
|
||||
assert NODE_DISPLAY_NAME_MAPPINGS["H3ContinuumAssembleSeamV35"] == (
|
||||
"H3 Continuum Finalize"
|
||||
)
|
||||
@@ -0,0 +1,269 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import gc
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import sys
|
||||
from types import SimpleNamespace
|
||||
|
||||
import pytest
|
||||
import torch
|
||||
|
||||
from ComfyUI_H3_Continuum_Join.v3 import file_backed_buffer as buffer
|
||||
|
||||
|
||||
def _managed_files(root: Path) -> list[Path]:
|
||||
return sorted(
|
||||
path
|
||||
for path in root.iterdir()
|
||||
if path.suffix in {".bin", ".json", ".partial"}
|
||||
)
|
||||
|
||||
|
||||
def test_backend_contract_accepts_auto_and_rejects_unknown_values():
|
||||
assert buffer.BUFFER_BACKEND_OPTIONS == (
|
||||
buffer.BUFFER_BACKEND_AUTO,
|
||||
buffer.BUFFER_BACKEND_RAM,
|
||||
buffer.BUFFER_BACKEND_DISK,
|
||||
)
|
||||
assert buffer.validate_buffer_backend("Auto") == "Auto"
|
||||
assert buffer.validate_buffer_backend("RAM") == "RAM"
|
||||
assert buffer.validate_buffer_backend("Disk-backed") == "Disk-backed"
|
||||
for value in ("disk-backed", "", None):
|
||||
with pytest.raises(ValueError, match="unknown Buffer Backend"):
|
||||
buffer.validate_buffer_backend(value)
|
||||
|
||||
|
||||
def test_auto_selects_ram_only_with_size_and_memory_headroom(tmp_path, monkeypatch):
|
||||
gib = 1024**3
|
||||
monkeypatch.setattr(
|
||||
buffer,
|
||||
"_system_memory_bytes",
|
||||
lambda: (16 * gib, 64 * gib),
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
buffer,
|
||||
"_disk_free_bytes",
|
||||
lambda _path: (_ for _ in ()).throw(
|
||||
AssertionError("disk must not be queried for a safe RAM decision")
|
||||
),
|
||||
)
|
||||
|
||||
decision = buffer.select_auto_buffer_backend(gib, backing_root=tmp_path)
|
||||
|
||||
assert decision.selected_backend == buffer.BUFFER_BACKEND_RAM
|
||||
assert decision.memory_reserve_bytes == int(64 * gib * 0.10)
|
||||
assert decision.disk_free_bytes is None
|
||||
assert "fits" in decision.reason
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("final_bytes", "available", "reason"),
|
||||
(
|
||||
(5 * 1024**3, 48 * 1024**3, "exceeds"),
|
||||
(1 * 1024**3, 5 * 1024**3, "below"),
|
||||
),
|
||||
)
|
||||
def test_auto_selects_disk_for_large_output_or_memory_pressure(
|
||||
tmp_path,
|
||||
monkeypatch,
|
||||
final_bytes,
|
||||
available,
|
||||
reason,
|
||||
):
|
||||
gib = 1024**3
|
||||
monkeypatch.setattr(
|
||||
buffer,
|
||||
"_system_memory_bytes",
|
||||
lambda: (available, 64 * gib),
|
||||
)
|
||||
monkeypatch.setattr(buffer, "_disk_free_bytes", lambda _path: 100 * gib)
|
||||
|
||||
decision = buffer.select_auto_buffer_backend(
|
||||
final_bytes,
|
||||
backing_root=tmp_path,
|
||||
)
|
||||
|
||||
assert decision.selected_backend == buffer.BUFFER_BACKEND_DISK
|
||||
assert decision.disk_free_bytes == 100 * gib
|
||||
assert reason in decision.reason
|
||||
|
||||
|
||||
def test_auto_uses_disk_when_memory_counters_are_unavailable(tmp_path, monkeypatch):
|
||||
gib = 1024**3
|
||||
monkeypatch.setattr(buffer, "_system_memory_bytes", lambda: (None, None))
|
||||
monkeypatch.setattr(buffer, "_disk_free_bytes", lambda _path: 100 * gib)
|
||||
|
||||
decision = buffer.select_auto_buffer_backend(gib, backing_root=tmp_path)
|
||||
|
||||
assert decision.selected_backend == buffer.BUFFER_BACKEND_DISK
|
||||
assert decision.memory_reserve_bytes is None
|
||||
assert "unavailable" in decision.reason
|
||||
|
||||
|
||||
def test_auto_disk_shortage_is_explicit_and_never_falls_back(tmp_path, monkeypatch):
|
||||
gib = 1024**3
|
||||
monkeypatch.setattr(
|
||||
buffer,
|
||||
"_system_memory_bytes",
|
||||
lambda: (48 * gib, 64 * gib),
|
||||
)
|
||||
monkeypatch.setattr(buffer, "_disk_free_bytes", lambda _path: 6 * gib)
|
||||
|
||||
with pytest.raises(RuntimeError, match="selected Disk-backed"):
|
||||
buffer.select_auto_buffer_backend(5 * gib, backing_root=tmp_path)
|
||||
|
||||
|
||||
def test_auto_decision_report_records_selection_inputs(tmp_path, monkeypatch):
|
||||
gib = 1024**3
|
||||
monkeypatch.setattr(
|
||||
buffer,
|
||||
"_system_memory_bytes",
|
||||
lambda: (16 * gib, 64 * gib),
|
||||
)
|
||||
decision = buffer.select_auto_buffer_backend(gib, backing_root=tmp_path)
|
||||
|
||||
report = buffer.format_auto_buffer_decision(decision)
|
||||
|
||||
assert "selected=RAM" in report
|
||||
assert f"final_IMAGE={gib} bytes" in report
|
||||
assert "RAM_IMAGE_limit=4294967296 bytes" in report
|
||||
assert "reason=" in report
|
||||
|
||||
|
||||
def test_default_root_is_resolved_lazily_from_comfyui_temp(tmp_path, monkeypatch):
|
||||
calls = []
|
||||
comfy_temp = tmp_path / "comfy-temp"
|
||||
fake_folder_paths = SimpleNamespace(
|
||||
get_temp_directory=lambda: calls.append(True) or str(comfy_temp)
|
||||
)
|
||||
monkeypatch.setitem(sys.modules, "folder_paths", fake_folder_paths)
|
||||
|
||||
assert calls == []
|
||||
resolved = buffer.resolve_backing_root()
|
||||
assert calls == [True]
|
||||
assert resolved == (comfy_temp / "h3-continuum-v35-file-backed").resolve()
|
||||
|
||||
|
||||
def test_default_root_has_a_non_comfy_test_fallback(tmp_path, monkeypatch):
|
||||
monkeypatch.setitem(sys.modules, "folder_paths", None)
|
||||
monkeypatch.setattr(buffer.tempfile, "gettempdir", lambda: str(tmp_path))
|
||||
|
||||
assert buffer.resolve_backing_root() == (
|
||||
tmp_path / "h3-continuum-v35-file-backed"
|
||||
).resolve()
|
||||
|
||||
|
||||
def test_explicit_root_bypasses_comfyui_resolution(tmp_path, monkeypatch):
|
||||
fake_folder_paths = SimpleNamespace(
|
||||
get_temp_directory=lambda: (_ for _ in ()).throw(
|
||||
AssertionError("folder_paths must not be evaluated")
|
||||
)
|
||||
)
|
||||
monkeypatch.setitem(sys.modules, "folder_paths", fake_folder_paths)
|
||||
|
||||
assert buffer.resolve_backing_root(tmp_path) == tmp_path.resolve()
|
||||
|
||||
|
||||
def test_file_backed_allocation_uses_process_global_manager_and_alias_lifetime(
|
||||
tmp_path,
|
||||
):
|
||||
manager = buffer.get_file_backed_image_manager(tmp_path)
|
||||
assert manager is buffer.get_file_backed_image_manager(tmp_path)
|
||||
reference = torch.arange(4 * 3 * 2 * 3, dtype=torch.float32).reshape(4, 3, 2, 3)
|
||||
|
||||
with buffer.allocate_file_backed_image(
|
||||
tuple(reference.shape),
|
||||
dtype=reference.dtype,
|
||||
backing_root=tmp_path,
|
||||
) as allocation:
|
||||
allocation.tensor.copy_(reference)
|
||||
record = allocation.record
|
||||
output = allocation.publish()
|
||||
|
||||
assert output.device.type == "cpu"
|
||||
assert output.is_contiguous()
|
||||
assert torch.equal(output, reference)
|
||||
assert record.data_path.parent == tmp_path.resolve()
|
||||
assert record.data_path.stat().st_size == reference.numel() * reference.element_size()
|
||||
assert record.data_path.exists()
|
||||
assert record.metadata_path.exists()
|
||||
|
||||
alias = output[1:]
|
||||
del output
|
||||
gc.collect()
|
||||
held = manager.collect_ready()
|
||||
assert held.reclaimed == 0
|
||||
assert held.deferred == 1
|
||||
assert float(alias.sum()) == pytest.approx(float(reference[1:].sum()))
|
||||
assert record.data_path.exists()
|
||||
|
||||
del alias
|
||||
gc.collect()
|
||||
released = manager.collect_ready()
|
||||
assert released.reclaimed == 1
|
||||
assert released.deferred == 0
|
||||
assert not _managed_files(tmp_path)
|
||||
|
||||
|
||||
def test_unpublished_error_aborts_provisional_files(tmp_path):
|
||||
manager = buffer.get_file_backed_image_manager(tmp_path)
|
||||
|
||||
with pytest.raises(RuntimeError, match="assembly failed"):
|
||||
with buffer.allocate_file_backed_image(
|
||||
(2, 2, 2, 3),
|
||||
dtype=torch.float32,
|
||||
backing_root=tmp_path,
|
||||
) as allocation:
|
||||
allocation.tensor.fill_(1.0)
|
||||
raise RuntimeError("assembly failed")
|
||||
|
||||
assert manager.tracked_count() == 0
|
||||
assert manager.pending_count() == 0
|
||||
assert not _managed_files(tmp_path)
|
||||
|
||||
|
||||
def test_disk_backend_failure_is_propagated_without_ram_fallback(
|
||||
tmp_path,
|
||||
monkeypatch,
|
||||
):
|
||||
class FailingManager:
|
||||
def allocate(self, *args, **kwargs):
|
||||
raise OSError("synthetic disk failure")
|
||||
|
||||
monkeypatch.setattr(
|
||||
buffer,
|
||||
"get_file_backed_image_manager",
|
||||
lambda backing_root=None: FailingManager(),
|
||||
)
|
||||
with pytest.raises(OSError, match="synthetic disk failure"):
|
||||
buffer.allocate_file_backed_image(
|
||||
(2, 2, 2, 3),
|
||||
dtype=torch.float32,
|
||||
backing_root=tmp_path,
|
||||
)
|
||||
|
||||
|
||||
def test_first_manager_access_reclaims_prior_dead_process_files(tmp_path):
|
||||
probe = (
|
||||
Path(__file__).resolve().parents[1]
|
||||
/ "tools"
|
||||
/ "p20_file_backed_tensor_poc.py"
|
||||
)
|
||||
subprocess.run(
|
||||
[
|
||||
sys.executable,
|
||||
str(probe),
|
||||
"--root",
|
||||
str(tmp_path),
|
||||
"--crash-child",
|
||||
],
|
||||
check=True,
|
||||
)
|
||||
assert list(tmp_path.glob("*.bin"))
|
||||
assert list(tmp_path.glob("*.json"))
|
||||
|
||||
buffer.get_file_backed_image_manager(tmp_path)
|
||||
|
||||
assert not list(tmp_path.glob("*.bin"))
|
||||
assert not list(tmp_path.glob("*.json"))
|
||||
@@ -0,0 +1,796 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import gc
|
||||
import inspect
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
import torch
|
||||
|
||||
from ComfyUI_H3_Continuum_Join.constants import (
|
||||
DIAGNOSTICS_BASIC,
|
||||
DIAGNOSTICS_FULL,
|
||||
)
|
||||
from ComfyUI_H3_Continuum_Join.hardening import enrich_assembly_plan
|
||||
from ComfyUI_H3_Continuum_Join.temporal import audio_latent_t, video_latent_t
|
||||
from ComfyUI_H3_Continuum_Join.v3 import assembly_v35
|
||||
from ComfyUI_H3_Continuum_Join.v3.assembly import (
|
||||
AUDIO_SEAM_AUTO,
|
||||
AUDIO_SEAM_OFF,
|
||||
VIDEO_SEAM_ANALYZE,
|
||||
VIDEO_SEAM_AUTO,
|
||||
VIDEO_SEAM_AUTO_2,
|
||||
VIDEO_SEAM_OFF,
|
||||
)
|
||||
from ComfyUI_H3_Continuum_Join.v3.driving_nodes import (
|
||||
H3ContinuumAssembleSeamV34,
|
||||
H3ContinuumAssembleSeamV35,
|
||||
)
|
||||
from ComfyUI_H3_Continuum_Join.v3.file_backed_buffer import (
|
||||
AutoBufferDecision,
|
||||
BUFFER_BACKEND_AUTO,
|
||||
BUFFER_BACKEND_DISK,
|
||||
BUFFER_BACKEND_RAM,
|
||||
get_file_backed_image_manager,
|
||||
)
|
||||
from ComfyUI_H3_Continuum_Join.v3.plan import ASSEMBLY_PLAN_MAGIC
|
||||
|
||||
|
||||
_FPS = 24
|
||||
_SAMPLE_RATE = 240
|
||||
|
||||
|
||||
def _logical_chunk(
|
||||
sequence_index: int,
|
||||
*,
|
||||
total_frames: int,
|
||||
trim_frames: int,
|
||||
) -> dict:
|
||||
return {
|
||||
"sequence_index": sequence_index,
|
||||
"chunk_index": sequence_index,
|
||||
"total_frames": total_frames,
|
||||
"trim_frames": trim_frames,
|
||||
"net_frames": total_frames - trim_frames,
|
||||
"context_frames": trim_frames,
|
||||
"expected_video_latent_t": video_latent_t(total_frames),
|
||||
"expected_audio_latent_t": audio_latent_t(total_frames),
|
||||
}
|
||||
|
||||
|
||||
def _physical_group(
|
||||
logical_chunks: list[int],
|
||||
*,
|
||||
total_frames: int,
|
||||
trim_frames: int,
|
||||
frame_start: int,
|
||||
terminal_merged: bool,
|
||||
) -> dict:
|
||||
net_frames = total_frames - trim_frames
|
||||
return {
|
||||
"logical_chunk_indices": logical_chunks,
|
||||
"terminal_merged": terminal_merged,
|
||||
"total_frames": total_frames,
|
||||
"trim_frames": trim_frames,
|
||||
"net_frames": net_frames,
|
||||
"context_frames": trim_frames,
|
||||
"expected_video_latent_t": video_latent_t(total_frames),
|
||||
"expected_audio_latent_t": audio_latent_t(total_frames),
|
||||
"frame_start": frame_start,
|
||||
"frame_stop": frame_start + net_frames,
|
||||
}
|
||||
|
||||
|
||||
def _plan(kind: str, *, target_frames: int | None = None, preserve=True) -> dict:
|
||||
if kind == "single":
|
||||
chunks = [_logical_chunk(1, total_frames=124, trim_frames=0)]
|
||||
groups = None
|
||||
default_target = 120
|
||||
elif kind == "single_pad":
|
||||
chunks = [_logical_chunk(1, total_frames=124, trim_frames=5)]
|
||||
groups = None
|
||||
default_target = 120
|
||||
elif kind == "terminal_2x5":
|
||||
chunks = [
|
||||
_logical_chunk(1, total_frames=124, trim_frames=0),
|
||||
_logical_chunk(2, total_frames=141, trim_frames=22),
|
||||
]
|
||||
groups = [
|
||||
_physical_group(
|
||||
[1, 2],
|
||||
total_frames=243,
|
||||
trim_frames=0,
|
||||
frame_start=0,
|
||||
terminal_merged=True,
|
||||
)
|
||||
]
|
||||
default_target = 240
|
||||
elif kind == "long_terminal_3x5":
|
||||
chunks = [
|
||||
_logical_chunk(1, total_frames=124, trim_frames=0),
|
||||
_logical_chunk(2, total_frames=141, trim_frames=22),
|
||||
_logical_chunk(3, total_frames=141, trim_frames=22),
|
||||
]
|
||||
groups = [
|
||||
_physical_group(
|
||||
[1],
|
||||
total_frames=124,
|
||||
trim_frames=0,
|
||||
frame_start=0,
|
||||
terminal_merged=False,
|
||||
),
|
||||
_physical_group(
|
||||
[2, 3],
|
||||
total_frames=260,
|
||||
trim_frames=22,
|
||||
frame_start=124,
|
||||
terminal_merged=True,
|
||||
),
|
||||
]
|
||||
default_target = 360
|
||||
else:
|
||||
raise AssertionError(f"unknown fixture kind: {kind}")
|
||||
|
||||
plan = enrich_assembly_plan(
|
||||
{
|
||||
"magic": ASSEMBLY_PLAN_MAGIC,
|
||||
"schema_version": 1,
|
||||
"fps": _FPS,
|
||||
"width": 8,
|
||||
"height": 8,
|
||||
"chunk_seconds": 5.0,
|
||||
"target_frames": int(
|
||||
default_target if target_frames is None else target_frames
|
||||
),
|
||||
"preserve_final_frame": bool(preserve),
|
||||
"chunks": chunks,
|
||||
}
|
||||
)
|
||||
if groups is not None:
|
||||
plan["decode_groups"] = groups
|
||||
plan["physical_decode_group_count"] = len(groups)
|
||||
return plan
|
||||
|
||||
|
||||
def _units(plan: dict) -> list[dict]:
|
||||
return list(plan.get("decode_groups") or plan["chunks"])
|
||||
|
||||
|
||||
def _decoded(
|
||||
plan: dict,
|
||||
*,
|
||||
seam_case: str = "ordered",
|
||||
sample_rate: int = _SAMPLE_RATE,
|
||||
) -> tuple[list[torch.Tensor], list[dict]]:
|
||||
images: list[torch.Tensor] = []
|
||||
audio: list[dict] = []
|
||||
for group_index, unit in enumerate(_units(plan)):
|
||||
total_frames = int(unit["total_frames"])
|
||||
if seam_case == "ordered":
|
||||
frame_values = (
|
||||
group_index * 0.25
|
||||
+ torch.arange(total_frames, dtype=torch.float32) / 4096.0
|
||||
)
|
||||
image = frame_values.view(-1, 1, 1, 1).expand(-1, 8, 8, 3).clone()
|
||||
else:
|
||||
image = torch.full((total_frames, 8, 8, 3), 0.25)
|
||||
if group_index == 1:
|
||||
trim = int(unit["trim_frames"])
|
||||
if seam_case == "transient":
|
||||
image[trim] = 1.0
|
||||
elif seam_case == "exposure":
|
||||
image[trim:] = 0.33
|
||||
image[trim : trim + 4] = torch.tensor(
|
||||
[0.27, 0.29, 0.31, 0.33]
|
||||
).view(4, 1, 1, 1)
|
||||
elif seam_case != "clean":
|
||||
raise AssertionError(f"unknown seam case: {seam_case}")
|
||||
|
||||
sample_count = int(round(total_frames / _FPS * sample_rate))
|
||||
time_values = (
|
||||
group_index * 10000
|
||||
+ torch.arange(sample_count, dtype=torch.float32)
|
||||
)
|
||||
waveform = torch.stack((time_values, -time_values), dim=0).unsqueeze(0)
|
||||
images.append(image)
|
||||
audio.append({"waveform": waveform, "sample_rate": sample_rate})
|
||||
return images, audio
|
||||
|
||||
|
||||
def _v34(
|
||||
images,
|
||||
audio,
|
||||
plan,
|
||||
*,
|
||||
exact: bool,
|
||||
audio_seam: str = AUDIO_SEAM_OFF,
|
||||
video_seam: str = VIDEO_SEAM_OFF,
|
||||
):
|
||||
return H3ContinuumAssembleSeamV34().assemble(
|
||||
images=images,
|
||||
audio=audio,
|
||||
assembly_plan=plan,
|
||||
exact_total_duration=exact,
|
||||
audio_seam=audio_seam,
|
||||
video_seam=video_seam,
|
||||
diagnostics=DIAGNOSTICS_BASIC,
|
||||
)
|
||||
|
||||
|
||||
def _v35(
|
||||
images,
|
||||
audio,
|
||||
plan,
|
||||
*,
|
||||
exact: bool,
|
||||
backend: str,
|
||||
backing_root: Path,
|
||||
audio_seam: str = AUDIO_SEAM_OFF,
|
||||
video_seam: str = VIDEO_SEAM_OFF,
|
||||
):
|
||||
return assembly_v35.assemble_decoded_chunks_v35(
|
||||
images=images,
|
||||
audio=audio,
|
||||
assembly_plan=plan,
|
||||
exact_total_duration=exact,
|
||||
audio_seam=audio_seam,
|
||||
video_seam=video_seam,
|
||||
diagnostics=DIAGNOSTICS_BASIC,
|
||||
buffer_backend=backend,
|
||||
backing_root=backing_root,
|
||||
)
|
||||
|
||||
|
||||
def _assert_av_equal(left, right) -> None:
|
||||
assert torch.equal(left[0], right[0])
|
||||
assert left[1]["sample_rate"] == right[1]["sample_rate"]
|
||||
assert torch.equal(left[1]["waveform"], right[1]["waveform"])
|
||||
|
||||
|
||||
def _collect_released_disk_tensor(root: Path) -> None:
|
||||
gc.collect()
|
||||
get_file_backed_image_manager(root).collect_ready()
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("kind", "exact", "expected_frames"),
|
||||
(
|
||||
("single", False, 124),
|
||||
("single", True, 120),
|
||||
("terminal_2x5", False, 243),
|
||||
("terminal_2x5", True, 240),
|
||||
("long_terminal_3x5", False, 362),
|
||||
("long_terminal_3x5", True, 360),
|
||||
),
|
||||
)
|
||||
def test_ram_and_disk_are_bit_exact_with_v34_required_layouts(
|
||||
tmp_path,
|
||||
kind,
|
||||
exact,
|
||||
expected_frames,
|
||||
):
|
||||
plan = _plan(kind)
|
||||
images, audio = _decoded(plan)
|
||||
baseline = _v34(images, audio, plan, exact=exact)
|
||||
ram = _v35(
|
||||
images,
|
||||
audio,
|
||||
plan,
|
||||
exact=exact,
|
||||
backend=BUFFER_BACKEND_RAM,
|
||||
backing_root=tmp_path,
|
||||
)
|
||||
disk = _v35(
|
||||
images,
|
||||
audio,
|
||||
plan,
|
||||
exact=exact,
|
||||
backend=BUFFER_BACKEND_DISK,
|
||||
backing_root=tmp_path,
|
||||
)
|
||||
|
||||
assert int(baseline[0].shape[0]) == expected_frames
|
||||
_assert_av_equal(ram, baseline)
|
||||
_assert_av_equal(disk, baseline)
|
||||
disk_image = disk[0]
|
||||
del disk
|
||||
del disk_image
|
||||
_collect_released_disk_tensor(tmp_path)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("video_seam", "seam_case"),
|
||||
(
|
||||
(VIDEO_SEAM_OFF, "transient"),
|
||||
(VIDEO_SEAM_ANALYZE, "transient"),
|
||||
(VIDEO_SEAM_AUTO, "transient"),
|
||||
(VIDEO_SEAM_AUTO_2, "exposure"),
|
||||
),
|
||||
)
|
||||
@pytest.mark.parametrize("backend", (BUFFER_BACKEND_RAM, BUFFER_BACKEND_DISK))
|
||||
@pytest.mark.parametrize("exact", (False, True))
|
||||
def test_all_video_seam_modes_are_bit_exact_with_v34(
|
||||
tmp_path,
|
||||
video_seam,
|
||||
seam_case,
|
||||
backend,
|
||||
exact,
|
||||
):
|
||||
plan = _plan("long_terminal_3x5")
|
||||
images, audio = _decoded(plan, seam_case=seam_case)
|
||||
baseline = _v34(
|
||||
images,
|
||||
audio,
|
||||
plan,
|
||||
exact=exact,
|
||||
video_seam=video_seam,
|
||||
)
|
||||
candidate = _v35(
|
||||
images,
|
||||
audio,
|
||||
plan,
|
||||
exact=exact,
|
||||
backend=backend,
|
||||
backing_root=tmp_path,
|
||||
video_seam=video_seam,
|
||||
)
|
||||
|
||||
_assert_av_equal(candidate, baseline)
|
||||
if backend == BUFFER_BACKEND_DISK:
|
||||
disk_image = candidate[0]
|
||||
del candidate
|
||||
del disk_image
|
||||
_collect_released_disk_tensor(tmp_path)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("backend", (BUFFER_BACKEND_RAM, BUFFER_BACKEND_DISK))
|
||||
@pytest.mark.parametrize("exact", (False, True))
|
||||
def test_audio_seam_auto_is_bit_exact_with_v34(tmp_path, backend, exact):
|
||||
plan = _plan("long_terminal_3x5")
|
||||
images, audio = _decoded(plan, seam_case="clean")
|
||||
previous_samples = int(round(124 / _FPS * _SAMPLE_RATE))
|
||||
context_samples = int(round(22 / _FPS * _SAMPLE_RATE))
|
||||
first_time = torch.arange(previous_samples, dtype=torch.float32)
|
||||
second_count = int(round(260 / _FPS * _SAMPLE_RATE))
|
||||
second_time = torch.arange(
|
||||
previous_samples - context_samples,
|
||||
previous_samples - context_samples + second_count,
|
||||
dtype=torch.float32,
|
||||
)
|
||||
first_wave = torch.sin(first_time * (2.0 * torch.pi / 31.0))
|
||||
second_wave = torch.sin(second_time * (2.0 * torch.pi / 31.0))
|
||||
audio[0]["waveform"] = first_wave.view(1, 1, -1).expand(1, 2, -1).clone()
|
||||
audio[1]["waveform"] = second_wave.view(1, 1, -1).expand(1, 2, -1).clone()
|
||||
baseline = _v34(
|
||||
images,
|
||||
audio,
|
||||
plan,
|
||||
exact=exact,
|
||||
audio_seam=AUDIO_SEAM_AUTO,
|
||||
)
|
||||
candidate = _v35(
|
||||
images,
|
||||
audio,
|
||||
plan,
|
||||
exact=exact,
|
||||
backend=backend,
|
||||
backing_root=tmp_path,
|
||||
audio_seam=AUDIO_SEAM_AUTO,
|
||||
)
|
||||
|
||||
_assert_av_equal(candidate, baseline)
|
||||
assert "audio seam 1->2" in baseline[2]
|
||||
assert "fade=0 samples" not in baseline[2]
|
||||
assert "fallback to native boundary" not in baseline[2]
|
||||
if backend == BUFFER_BACKEND_DISK:
|
||||
disk_image = candidate[0]
|
||||
del candidate
|
||||
del disk_image
|
||||
_collect_released_disk_tensor(tmp_path)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("backend", (BUFFER_BACKEND_RAM, BUFFER_BACKEND_DISK))
|
||||
@pytest.mark.parametrize("exact", (False, True))
|
||||
def test_32khz_cumulative_rounding_and_audio_seam_match_v34(
|
||||
tmp_path,
|
||||
backend,
|
||||
exact,
|
||||
):
|
||||
plan = _plan("long_terminal_3x5")
|
||||
images, audio = _decoded(plan, seam_case="clean", sample_rate=32000)
|
||||
baseline = _v34(
|
||||
images,
|
||||
audio,
|
||||
plan,
|
||||
exact=exact,
|
||||
audio_seam=AUDIO_SEAM_AUTO,
|
||||
)
|
||||
candidate = _v35(
|
||||
images,
|
||||
audio,
|
||||
plan,
|
||||
exact=exact,
|
||||
backend=backend,
|
||||
backing_root=tmp_path,
|
||||
audio_seam=AUDIO_SEAM_AUTO,
|
||||
)
|
||||
|
||||
_assert_av_equal(candidate, baseline)
|
||||
expected_frames = 360 if exact else 362
|
||||
assert candidate[1]["waveform"].shape[-1] == int(
|
||||
round(expected_frames / _FPS * 32000)
|
||||
)
|
||||
if backend == BUFFER_BACKEND_DISK:
|
||||
disk_image = candidate[0]
|
||||
del candidate
|
||||
del disk_image
|
||||
_collect_released_disk_tensor(tmp_path)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("backend", (BUFFER_BACKEND_RAM, BUFFER_BACKEND_DISK))
|
||||
def test_padding_and_final_frame_preservation_match_v34(tmp_path, backend):
|
||||
trim_plan = _plan("single", target_frames=120, preserve=True)
|
||||
trim_images, trim_audio = _decoded(trim_plan)
|
||||
trim_baseline = _v34(trim_images, trim_audio, trim_plan, exact=True)
|
||||
trim_candidate = _v35(
|
||||
trim_images,
|
||||
trim_audio,
|
||||
trim_plan,
|
||||
exact=True,
|
||||
backend=backend,
|
||||
backing_root=tmp_path / "trim",
|
||||
)
|
||||
_assert_av_equal(trim_candidate, trim_baseline)
|
||||
assert torch.equal(trim_candidate[0][-1], trim_images[0][-1])
|
||||
|
||||
pad_plan = _plan("single_pad", preserve=False)
|
||||
pad_images, pad_audio = _decoded(pad_plan)
|
||||
pad_baseline = _v34(pad_images, pad_audio, pad_plan, exact=True)
|
||||
pad_candidate = _v35(
|
||||
pad_images,
|
||||
pad_audio,
|
||||
pad_plan,
|
||||
exact=True,
|
||||
backend=backend,
|
||||
backing_root=tmp_path / "pad",
|
||||
)
|
||||
_assert_av_equal(pad_candidate, pad_baseline)
|
||||
assert torch.equal(pad_candidate[0][-1], pad_images[0][-1])
|
||||
|
||||
if backend == BUFFER_BACKEND_DISK:
|
||||
trim_image = trim_candidate[0]
|
||||
pad_image = pad_candidate[0]
|
||||
del trim_candidate, pad_candidate
|
||||
del trim_image, pad_image
|
||||
_collect_released_disk_tensor(tmp_path / "trim")
|
||||
_collect_released_disk_tensor(tmp_path / "pad")
|
||||
|
||||
|
||||
@pytest.mark.parametrize("backend", (BUFFER_BACKEND_RAM, BUFFER_BACKEND_DISK))
|
||||
def test_tail_trim_without_final_anchor_matches_v34(tmp_path, backend):
|
||||
plan = _plan("single", target_frames=120, preserve=False)
|
||||
images, audio = _decoded(plan)
|
||||
baseline = _v34(images, audio, plan, exact=True)
|
||||
candidate = _v35(
|
||||
images,
|
||||
audio,
|
||||
plan,
|
||||
exact=True,
|
||||
backend=backend,
|
||||
backing_root=tmp_path,
|
||||
)
|
||||
|
||||
_assert_av_equal(candidate, baseline)
|
||||
assert torch.equal(candidate[0][-1], images[0][119])
|
||||
assert not torch.equal(candidate[0][-1], images[0][-1])
|
||||
if backend == BUFFER_BACKEND_DISK:
|
||||
disk_image = candidate[0]
|
||||
del candidate
|
||||
del disk_image
|
||||
_collect_released_disk_tensor(tmp_path)
|
||||
|
||||
|
||||
def test_long_terminal_uses_physical_group_order_and_trim_contract(tmp_path):
|
||||
plan = _plan("long_terminal_3x5")
|
||||
images, audio = _decoded(plan)
|
||||
result = _v35(
|
||||
images,
|
||||
audio,
|
||||
plan,
|
||||
exact=False,
|
||||
backend=BUFFER_BACKEND_RAM,
|
||||
backing_root=tmp_path,
|
||||
)
|
||||
|
||||
assert result[0].shape[0] == 362
|
||||
assert torch.equal(result[0][:124], images[0])
|
||||
assert torch.equal(result[0][124:], images[1][22:260])
|
||||
expected_samples = int(round(362 / _FPS * _SAMPLE_RATE))
|
||||
assert result[1]["waveform"].shape[-1] == expected_samples
|
||||
|
||||
|
||||
def test_disk_storage_alias_keeps_backing_file_alive_until_last_view(tmp_path):
|
||||
plan = _plan("single")
|
||||
images, audio = _decoded(plan)
|
||||
output, _, _ = _v35(
|
||||
images,
|
||||
audio,
|
||||
plan,
|
||||
exact=True,
|
||||
backend=BUFFER_BACKEND_DISK,
|
||||
backing_root=tmp_path,
|
||||
)
|
||||
manager = get_file_backed_image_manager(tmp_path)
|
||||
managed = list(tmp_path.glob("*.bin"))
|
||||
assert len(managed) == 1
|
||||
assert managed[0].stat().st_size == output.numel() * output.element_size()
|
||||
|
||||
alias = output[1:]
|
||||
del output
|
||||
gc.collect()
|
||||
held = manager.collect_ready()
|
||||
assert held.reclaimed == 0
|
||||
assert held.deferred == 1
|
||||
assert managed[0].exists()
|
||||
assert torch.equal(alias[0], images[0][1])
|
||||
|
||||
del alias
|
||||
gc.collect()
|
||||
released = manager.collect_ready()
|
||||
assert released.reclaimed == 1
|
||||
assert not list(tmp_path.glob("*.bin"))
|
||||
assert not list(tmp_path.glob("*.json"))
|
||||
|
||||
|
||||
def test_disk_write_error_aborts_unpublished_allocation(tmp_path, monkeypatch):
|
||||
plan = _plan("single")
|
||||
images, audio = _decoded(plan)
|
||||
original = assembly_v35._copy_natural_interval
|
||||
|
||||
def fail_after_allocation(*args, **kwargs):
|
||||
original(*args, **kwargs)
|
||||
raise RuntimeError("synthetic direct-write failure")
|
||||
|
||||
monkeypatch.setattr(assembly_v35, "_copy_natural_interval", fail_after_allocation)
|
||||
with pytest.raises(RuntimeError, match="synthetic direct-write failure"):
|
||||
_v35(
|
||||
images,
|
||||
audio,
|
||||
plan,
|
||||
exact=True,
|
||||
backend=BUFFER_BACKEND_DISK,
|
||||
backing_root=tmp_path,
|
||||
)
|
||||
|
||||
manager = get_file_backed_image_manager(tmp_path)
|
||||
assert manager.tracked_count() == 0
|
||||
assert manager.pending_count() == 0
|
||||
assert not list(tmp_path.glob("*.bin"))
|
||||
assert not list(tmp_path.glob("*.json"))
|
||||
|
||||
|
||||
def test_invalid_driving_audio_aborts_before_disk_publish(tmp_path, monkeypatch):
|
||||
plan = _plan("single")
|
||||
images, audio = _decoded(plan)
|
||||
original_allocate = assembly_v35.allocate_file_backed_image
|
||||
|
||||
def allocate_at_test_root(shape, *, dtype, backing_root=None):
|
||||
return original_allocate(shape, dtype=dtype, backing_root=tmp_path)
|
||||
|
||||
monkeypatch.setattr(
|
||||
assembly_v35,
|
||||
"allocate_file_backed_image",
|
||||
allocate_at_test_root,
|
||||
)
|
||||
invalid_driving = {
|
||||
"waveform": torch.zeros((1, 1, 1240), dtype=torch.float32),
|
||||
"sample_rate": 0,
|
||||
}
|
||||
with pytest.raises(ValueError, match="sample_rate"):
|
||||
H3ContinuumAssembleSeamV35().assemble(
|
||||
images,
|
||||
audio,
|
||||
plan,
|
||||
True,
|
||||
AUDIO_SEAM_OFF,
|
||||
VIDEO_SEAM_OFF,
|
||||
BUFFER_BACKEND_DISK,
|
||||
DIAGNOSTICS_BASIC,
|
||||
driving_audio=invalid_driving,
|
||||
)
|
||||
|
||||
manager = get_file_backed_image_manager(tmp_path)
|
||||
assert manager.tracked_count() == 0
|
||||
assert manager.pending_count() == 0
|
||||
assert not list(tmp_path.glob("*.bin"))
|
||||
assert not list(tmp_path.glob("*.json"))
|
||||
|
||||
|
||||
def test_auto_backend_is_default_while_manual_values_remain_available():
|
||||
schema = H3ContinuumAssembleSeamV35.INPUT_TYPES()
|
||||
backend_options = schema["required"]["buffer_backend"][0]
|
||||
backend_config = schema["required"]["buffer_backend"][1]
|
||||
assert tuple(backend_options) == (
|
||||
BUFFER_BACKEND_AUTO,
|
||||
BUFFER_BACKEND_RAM,
|
||||
BUFFER_BACKEND_DISK,
|
||||
)
|
||||
assert backend_config["default"] == BUFFER_BACKEND_AUTO
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"selected_backend",
|
||||
(BUFFER_BACKEND_RAM, BUFFER_BACKEND_DISK),
|
||||
)
|
||||
def test_auto_backend_uses_selected_writer_and_reports_decision(
|
||||
tmp_path,
|
||||
monkeypatch,
|
||||
selected_backend,
|
||||
):
|
||||
gib = 1024**3
|
||||
plan = _plan("single")
|
||||
images, audio = _decoded(plan)
|
||||
decision = AutoBufferDecision(
|
||||
selected_backend=selected_backend,
|
||||
final_image_bytes=120 * 8 * 8 * 3 * 4,
|
||||
backing_root=tmp_path,
|
||||
available_memory_bytes=16 * gib,
|
||||
total_memory_bytes=64 * gib,
|
||||
memory_reserve_bytes=int(64 * gib * 0.10),
|
||||
ram_image_limit_bytes=4 * gib,
|
||||
disk_free_bytes=(100 * gib if selected_backend == BUFFER_BACKEND_DISK else None),
|
||||
disk_reserve_bytes=2 * gib,
|
||||
reason="synthetic test decision",
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
assembly_v35,
|
||||
"select_auto_buffer_backend",
|
||||
lambda final_image_bytes, backing_root=None: decision,
|
||||
)
|
||||
|
||||
candidate = _v35(
|
||||
images,
|
||||
audio,
|
||||
plan,
|
||||
exact=True,
|
||||
backend=BUFFER_BACKEND_AUTO,
|
||||
backing_root=tmp_path,
|
||||
)
|
||||
baseline = _v35(
|
||||
images,
|
||||
audio,
|
||||
plan,
|
||||
exact=True,
|
||||
backend=selected_backend,
|
||||
backing_root=tmp_path / "manual",
|
||||
)
|
||||
|
||||
_assert_av_equal(candidate, baseline)
|
||||
assert f"Buffer Backend: Auto -> {selected_backend}" in candidate[2]
|
||||
assert f"selected={selected_backend}" in candidate[2]
|
||||
assert "reason=synthetic test decision" in candidate[2]
|
||||
|
||||
candidate_image = candidate[0]
|
||||
baseline_image = baseline[0]
|
||||
del candidate, baseline, candidate_image, baseline_image
|
||||
if selected_backend == BUFFER_BACKEND_DISK:
|
||||
_collect_released_disk_tensor(tmp_path)
|
||||
_collect_released_disk_tensor(tmp_path / "manual")
|
||||
|
||||
|
||||
def test_direct_image_path_has_no_full_materialization_operations():
|
||||
source = inspect.getsource(assembly_v35)
|
||||
for forbidden in (
|
||||
"torch.cat(",
|
||||
"torch.stack(",
|
||||
".clone(",
|
||||
".contiguous(",
|
||||
"correct_decoded_boundaries",
|
||||
):
|
||||
assert forbidden not in source
|
||||
|
||||
|
||||
def test_small_patch_copy_intersects_prefix_and_final_anchor_spans_only():
|
||||
destination = torch.full((5, 1, 1, 1), -1.0)
|
||||
spans = (
|
||||
assembly_v35.CopySpan(0, 4, 0),
|
||||
assembly_v35.CopySpan(9, 10, 4),
|
||||
)
|
||||
crossing_patch = torch.tensor([30.0, 40.0, 50.0]).reshape(3, 1, 1, 1)
|
||||
assembly_v35._copy_natural_interval(
|
||||
destination,
|
||||
crossing_patch,
|
||||
natural_start=3,
|
||||
spans=spans,
|
||||
)
|
||||
anchor_patch = torch.tensor([90.0]).reshape(1, 1, 1, 1)
|
||||
assembly_v35._copy_natural_interval(
|
||||
destination,
|
||||
anchor_patch,
|
||||
natural_start=9,
|
||||
spans=spans,
|
||||
)
|
||||
|
||||
assert destination[:, 0, 0, 0].tolist() == [-1.0, -1.0, -1.0, 30.0, 90.0]
|
||||
|
||||
|
||||
def test_node_accepts_comfy_positional_list_inputs(tmp_path, monkeypatch):
|
||||
plan = _plan("single")
|
||||
images, audio = _decoded(plan)
|
||||
original_allocate = assembly_v35.allocate_file_backed_image
|
||||
|
||||
def allocate_at_test_root(shape, *, dtype, backing_root=None):
|
||||
return original_allocate(shape, dtype=dtype, backing_root=tmp_path)
|
||||
|
||||
monkeypatch.setattr(
|
||||
assembly_v35,
|
||||
"allocate_file_backed_image",
|
||||
allocate_at_test_root,
|
||||
)
|
||||
node = H3ContinuumAssembleSeamV35()
|
||||
result = node.assemble(
|
||||
images,
|
||||
audio,
|
||||
[plan],
|
||||
[True],
|
||||
[AUDIO_SEAM_OFF],
|
||||
[VIDEO_SEAM_OFF],
|
||||
[BUFFER_BACKEND_DISK],
|
||||
[DIAGNOSTICS_FULL],
|
||||
)
|
||||
baseline = _v34(images, audio, plan, exact=True)
|
||||
|
||||
assert node.INPUT_IS_LIST is True
|
||||
_assert_av_equal(result, baseline)
|
||||
assert "Buffer Backend: Disk-backed" in result[2]
|
||||
assert "Projected assembly buffers [V3.5]" in result[2]
|
||||
disk_image = result[0]
|
||||
del result
|
||||
del disk_image
|
||||
_collect_released_disk_tensor(tmp_path)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("stored_in_plan", (False, True))
|
||||
def test_driving_audio_selection_is_bit_exact_with_v34(
|
||||
tmp_path,
|
||||
stored_in_plan,
|
||||
):
|
||||
plan = _plan("single", preserve=True)
|
||||
images, audio = _decoded(plan)
|
||||
driving_samples = int(round(124 / _FPS * _SAMPLE_RATE))
|
||||
driving = {
|
||||
"waveform": torch.arange(
|
||||
driving_samples,
|
||||
dtype=torch.float32,
|
||||
).view(1, 1, -1),
|
||||
"sample_rate": _SAMPLE_RATE,
|
||||
}
|
||||
direct = None if stored_in_plan else driving
|
||||
if stored_in_plan:
|
||||
plan = dict(plan)
|
||||
plan["_h3_continuum_driving_audio_v1"] = driving
|
||||
|
||||
baseline = H3ContinuumAssembleSeamV34().assemble(
|
||||
images,
|
||||
audio,
|
||||
plan,
|
||||
True,
|
||||
AUDIO_SEAM_AUTO,
|
||||
VIDEO_SEAM_OFF,
|
||||
DIAGNOSTICS_BASIC,
|
||||
driving_audio=direct,
|
||||
)
|
||||
candidate = H3ContinuumAssembleSeamV35().assemble(
|
||||
images,
|
||||
audio,
|
||||
plan,
|
||||
True,
|
||||
AUDIO_SEAM_AUTO,
|
||||
VIDEO_SEAM_OFF,
|
||||
BUFFER_BACKEND_RAM,
|
||||
DIAGNOSTICS_BASIC,
|
||||
driving_audio=direct,
|
||||
)
|
||||
|
||||
_assert_av_equal(candidate, baseline)
|
||||
assert "Driving Audio: preserved source selected" in candidate[2]
|
||||
@@ -0,0 +1,187 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import replace
|
||||
|
||||
import pytest
|
||||
import torch
|
||||
|
||||
from ComfyUI_H3_Continuum_Join.hardening import enrich_assembly_plan
|
||||
from ComfyUI_H3_Continuum_Join.v3.plan import ASSEMBLY_PLAN_MAGIC
|
||||
from ComfyUI_H3_Continuum_Join.v3.video_seam import (
|
||||
analyze_decoded_boundaries,
|
||||
correct_decoded_boundaries,
|
||||
)
|
||||
from ComfyUI_H3_Continuum_Join.v3.video_seam_v35 import (
|
||||
build_boundary_patches,
|
||||
)
|
||||
|
||||
|
||||
def _plan():
|
||||
return enrich_assembly_plan(
|
||||
{
|
||||
"magic": ASSEMBLY_PLAN_MAGIC,
|
||||
"schema_version": 1,
|
||||
"fps": 24,
|
||||
"width": 8,
|
||||
"height": 8,
|
||||
"chunk_seconds": 5.0,
|
||||
"target_frames": 240,
|
||||
"preserve_final_frame": True,
|
||||
"chunks": [
|
||||
{
|
||||
"sequence_index": 1,
|
||||
"chunk_index": 1,
|
||||
"total_frames": 124,
|
||||
"trim_frames": 0,
|
||||
"net_frames": 124,
|
||||
"context_frames": 0,
|
||||
"expected_video_latent_t": 37,
|
||||
"expected_audio_latent_t": 207,
|
||||
},
|
||||
{
|
||||
"sequence_index": 2,
|
||||
"chunk_index": 2,
|
||||
"total_frames": 141,
|
||||
"trim_frames": 22,
|
||||
"net_frames": 119,
|
||||
"context_frames": 22,
|
||||
"expected_video_latent_t": 42,
|
||||
"expected_audio_latent_t": 235,
|
||||
},
|
||||
],
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
def _decoded(case: str) -> list[torch.Tensor]:
|
||||
images = [
|
||||
torch.full((124, 8, 8, 3), 0.25, dtype=torch.float32),
|
||||
torch.full((141, 8, 8, 3), 0.25, dtype=torch.float32),
|
||||
]
|
||||
if case == "transient":
|
||||
images[1][22] = 1.0
|
||||
elif case == "micro":
|
||||
images[1][22] = 0.258
|
||||
elif case == "exposure":
|
||||
images[1][22:] = 0.33
|
||||
images[1][22:26] = torch.tensor(
|
||||
[0.27, 0.29, 0.31, 0.33],
|
||||
dtype=torch.float32,
|
||||
).view(4, 1, 1, 1)
|
||||
elif case != "clean":
|
||||
raise AssertionError(f"unknown test case: {case}")
|
||||
return images
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("case", "enable_exposure_ramp", "expected_patch_frames"),
|
||||
(
|
||||
("transient", False, 1),
|
||||
("micro", False, 1),
|
||||
("exposure", False, 0),
|
||||
("exposure", True, 4),
|
||||
("clean", False, 0),
|
||||
),
|
||||
)
|
||||
def test_small_patches_are_bit_exact_with_v34_correction(
|
||||
case,
|
||||
enable_exposure_ramp,
|
||||
expected_patch_frames,
|
||||
):
|
||||
plan = _plan()
|
||||
images = _decoded(case)
|
||||
originals = [value.clone() for value in images]
|
||||
analyses = analyze_decoded_boundaries(images=images, assembly_plan=plan)
|
||||
|
||||
legacy, legacy_actions = correct_decoded_boundaries(
|
||||
images=images,
|
||||
assembly_plan=plan,
|
||||
analyses=analyses,
|
||||
enable_exposure_ramp=enable_exposure_ramp,
|
||||
)
|
||||
patches, actions = build_boundary_patches(
|
||||
images,
|
||||
plan,
|
||||
analyses,
|
||||
enable_exposure_ramp=enable_exposure_ramp,
|
||||
)
|
||||
|
||||
assert actions == legacy_actions
|
||||
assert all(torch.equal(value, original) for value, original in zip(images, originals))
|
||||
if expected_patch_frames == 0:
|
||||
assert patches == {}
|
||||
assert torch.equal(legacy[1], images[1])
|
||||
return
|
||||
|
||||
assert set(patches) == {1}
|
||||
patch = patches[1]
|
||||
assert patch.device.type == "cpu"
|
||||
assert patch.shape == (expected_patch_frames, 8, 8, 3)
|
||||
assert 1 <= int(patch.shape[0]) <= 4
|
||||
trim = int(plan["chunks"][1]["trim_frames"])
|
||||
assert torch.equal(
|
||||
patch,
|
||||
legacy[1][trim : trim + expected_patch_frames],
|
||||
)
|
||||
assert torch.equal(legacy[1][:trim], images[1][:trim])
|
||||
assert torch.equal(
|
||||
legacy[1][trim + expected_patch_frames :],
|
||||
images[1][trim + expected_patch_frames :],
|
||||
)
|
||||
|
||||
|
||||
def test_guarded_candidate_returns_native_action_without_a_patch():
|
||||
plan = _plan()
|
||||
images = _decoded("transient")
|
||||
analysis = analyze_decoded_boundaries(
|
||||
images=images,
|
||||
assembly_plan=plan,
|
||||
)[0]
|
||||
guarded = replace(analysis, scene_cut=True)
|
||||
|
||||
legacy, legacy_actions = correct_decoded_boundaries(
|
||||
images=images,
|
||||
assembly_plan=plan,
|
||||
analyses=[guarded],
|
||||
)
|
||||
patches, actions = build_boundary_patches(images, plan, [guarded])
|
||||
|
||||
assert patches == {}
|
||||
assert actions == legacy_actions == {
|
||||
1: "kept native boundary; correction guard rejected candidate"
|
||||
}
|
||||
assert legacy == images
|
||||
|
||||
|
||||
def test_patch_storage_is_independent_and_inputs_remain_unchanged():
|
||||
plan = _plan()
|
||||
images = _decoded("transient")
|
||||
original = images[1].clone()
|
||||
analysis = analyze_decoded_boundaries(
|
||||
images=images,
|
||||
assembly_plan=plan,
|
||||
)[0]
|
||||
|
||||
patches, _ = build_boundary_patches(images, plan, [analysis])
|
||||
patches[1].zero_()
|
||||
|
||||
assert torch.equal(images[1], original)
|
||||
|
||||
|
||||
def test_planning_error_does_not_mutate_inputs_or_return_a_partial_result():
|
||||
plan = _plan()
|
||||
images = _decoded("transient")
|
||||
originals = [value.clone() for value in images]
|
||||
analysis = analyze_decoded_boundaries(
|
||||
images=images,
|
||||
assembly_plan=plan,
|
||||
)[0]
|
||||
invalid = replace(analysis, boundary_index=2)
|
||||
|
||||
with pytest.raises(
|
||||
ValueError,
|
||||
match="boundary index is outside decoded chunks",
|
||||
):
|
||||
build_boundary_patches(images, plan, [analysis, invalid])
|
||||
|
||||
assert all(torch.equal(value, original) for value, original in zip(images, originals))
|
||||
@@ -0,0 +1,179 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import gc
|
||||
|
||||
import pytest
|
||||
import torch
|
||||
|
||||
from ComfyUI_H3_Continuum_Join.constants import DIAGNOSTICS_BASIC
|
||||
from ComfyUI_H3_Continuum_Join.hardening import enrich_assembly_plan
|
||||
from ComfyUI_H3_Continuum_Join.temporal import audio_latent_t, video_latent_t
|
||||
from ComfyUI_H3_Continuum_Join.v3.assembly import (
|
||||
AUDIO_SEAM_OFF,
|
||||
VIDEO_SEAM_OFF,
|
||||
)
|
||||
from ComfyUI_H3_Continuum_Join.v3.assembly_v35 import (
|
||||
assemble_decoded_chunks_v35,
|
||||
)
|
||||
from ComfyUI_H3_Continuum_Join.v3.file_backed_buffer import (
|
||||
BUFFER_BACKEND_DISK,
|
||||
BUFFER_BACKEND_RAM,
|
||||
get_file_backed_image_manager,
|
||||
)
|
||||
from ComfyUI_H3_Continuum_Join.v3.plan import ASSEMBLY_PLAN_MAGIC
|
||||
|
||||
|
||||
class ProbeCancelled(BaseException):
|
||||
pass
|
||||
|
||||
|
||||
def _fixture():
|
||||
total_frames = 124
|
||||
target_frames = 120
|
||||
sample_rate = 240
|
||||
chunk = {
|
||||
"sequence_index": 1,
|
||||
"chunk_index": 1,
|
||||
"total_frames": total_frames,
|
||||
"trim_frames": 0,
|
||||
"net_frames": total_frames,
|
||||
"context_frames": 0,
|
||||
"expected_video_latent_t": video_latent_t(total_frames),
|
||||
"expected_audio_latent_t": audio_latent_t(total_frames),
|
||||
}
|
||||
plan = enrich_assembly_plan(
|
||||
{
|
||||
"magic": ASSEMBLY_PLAN_MAGIC,
|
||||
"schema_version": 1,
|
||||
"fps": 24,
|
||||
"width": 8,
|
||||
"height": 8,
|
||||
"chunk_seconds": 5.0,
|
||||
"target_frames": target_frames,
|
||||
"preserve_final_frame": True,
|
||||
"chunks": [chunk],
|
||||
}
|
||||
)
|
||||
values = torch.arange(total_frames, dtype=torch.float32) / total_frames
|
||||
images = [values.reshape(-1, 1, 1, 1).expand(-1, 8, 8, 3).clone()]
|
||||
samples = int(round(total_frames / 24 * sample_rate))
|
||||
audio = [
|
||||
{
|
||||
"waveform": torch.linspace(0.0, 1.0, samples).reshape(1, 1, -1),
|
||||
"sample_rate": sample_rate,
|
||||
}
|
||||
]
|
||||
return images, audio, plan
|
||||
|
||||
|
||||
def _assemble(images, audio, plan, *, backend, root, interrupt_check):
|
||||
return assemble_decoded_chunks_v35(
|
||||
images=images,
|
||||
audio=audio,
|
||||
assembly_plan=plan,
|
||||
exact_total_duration=True,
|
||||
audio_seam=AUDIO_SEAM_OFF,
|
||||
video_seam=VIDEO_SEAM_OFF,
|
||||
diagnostics=DIAGNOSTICS_BASIC,
|
||||
buffer_backend=backend,
|
||||
backing_root=root,
|
||||
interrupt_check=interrupt_check,
|
||||
)
|
||||
|
||||
|
||||
def _collect(root, *values):
|
||||
del values
|
||||
gc.collect()
|
||||
manager = get_file_backed_image_manager(root)
|
||||
manager.collect_ready()
|
||||
gc.collect()
|
||||
manager.collect_ready()
|
||||
|
||||
|
||||
def test_interrupt_polling_keeps_ram_and_disk_outputs_bit_exact(tmp_path):
|
||||
images, audio, plan = _fixture()
|
||||
checks = 0
|
||||
|
||||
def check():
|
||||
nonlocal checks
|
||||
checks += 1
|
||||
|
||||
ram = _assemble(
|
||||
images,
|
||||
audio,
|
||||
plan,
|
||||
backend=BUFFER_BACKEND_RAM,
|
||||
root=tmp_path,
|
||||
interrupt_check=check,
|
||||
)
|
||||
disk = _assemble(
|
||||
images,
|
||||
audio,
|
||||
plan,
|
||||
backend=BUFFER_BACKEND_DISK,
|
||||
root=tmp_path,
|
||||
interrupt_check=check,
|
||||
)
|
||||
|
||||
assert checks >= 20
|
||||
assert torch.equal(disk[0], ram[0])
|
||||
assert torch.equal(disk[1]["waveform"], ram[1]["waveform"])
|
||||
assert disk[1]["sample_rate"] == ram[1]["sample_rate"]
|
||||
|
||||
disk_image = disk[0]
|
||||
del disk
|
||||
del disk_image
|
||||
_collect(tmp_path)
|
||||
assert not list(tmp_path.glob("*.bin"))
|
||||
assert not list(tmp_path.glob("*.json"))
|
||||
|
||||
|
||||
def test_mid_copy_cancel_aborts_unpublished_disk_pair(tmp_path):
|
||||
images, audio, plan = _fixture()
|
||||
checks = 0
|
||||
|
||||
def cancel_during_copy():
|
||||
nonlocal checks
|
||||
checks += 1
|
||||
if checks == 4:
|
||||
raise ProbeCancelled("P2-4 synthetic ESC")
|
||||
|
||||
with pytest.raises(ProbeCancelled, match="synthetic ESC"):
|
||||
_assemble(
|
||||
images,
|
||||
audio,
|
||||
plan,
|
||||
backend=BUFFER_BACKEND_DISK,
|
||||
root=tmp_path,
|
||||
interrupt_check=cancel_during_copy,
|
||||
)
|
||||
|
||||
manager = get_file_backed_image_manager(tmp_path)
|
||||
assert checks == 4
|
||||
assert manager.tracked_count() == 0
|
||||
assert manager.pending_count() == 0
|
||||
assert not list(tmp_path.glob("*.bin"))
|
||||
assert not list(tmp_path.glob("*.json"))
|
||||
|
||||
|
||||
def test_cancel_immediately_after_allocation_aborts_disk_pair(tmp_path):
|
||||
images, audio, plan = _fixture()
|
||||
|
||||
def cancel_after_allocation():
|
||||
raise ProbeCancelled("P2-4 pre-copy ESC")
|
||||
|
||||
with pytest.raises(ProbeCancelled, match="pre-copy ESC"):
|
||||
_assemble(
|
||||
images,
|
||||
audio,
|
||||
plan,
|
||||
backend=BUFFER_BACKEND_DISK,
|
||||
root=tmp_path,
|
||||
interrupt_check=cancel_after_allocation,
|
||||
)
|
||||
|
||||
manager = get_file_backed_image_manager(tmp_path)
|
||||
assert manager.tracked_count() == 0
|
||||
assert manager.pending_count() == 0
|
||||
assert not list(tmp_path.glob("*.bin"))
|
||||
assert not list(tmp_path.glob("*.json"))
|
||||
@@ -0,0 +1,59 @@
|
||||
import importlib.util
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
import torch
|
||||
|
||||
|
||||
def _probe_module():
|
||||
path = Path(__file__).resolve().parents[1] / "tools" / "p25_gpu_acceptance_probe.py"
|
||||
spec = importlib.util.spec_from_file_location("p25_gpu_acceptance_probe_test", path)
|
||||
assert spec is not None and spec.loader is not None
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(module)
|
||||
return module
|
||||
|
||||
|
||||
def test_p25_bounded_finite_check_and_hash_are_deterministic():
|
||||
probe = _probe_module()
|
||||
value = torch.arange(48, dtype=torch.float32).reshape(4, 3, 4)
|
||||
|
||||
assert probe._tensor_is_finite_batched(value, batch=1) is True
|
||||
assert probe._hash_tensor(value, batch=1) == probe._hash_tensor(value, batch=3)
|
||||
|
||||
invalid = value.clone()
|
||||
invalid[2, 1, 1] = float("nan")
|
||||
assert probe._tensor_is_finite_batched(invalid, batch=1) is False
|
||||
|
||||
|
||||
def test_p25_stress_prompt_bypasses_vae_and_preserves_assembler_contract():
|
||||
probe = _probe_module()
|
||||
prompt = probe._prompt("Disk-backed", stress=True)
|
||||
|
||||
assert set(prompt) == {"1", "6", "7"}
|
||||
assert prompt["1"]["class_type"] == "P25SyntheticDecodedStressFixture"
|
||||
assert prompt["6"]["class_type"] == "H3ContinuumAssembleSeamV35"
|
||||
assert prompt["6"]["inputs"]["images"] == ["1", 0]
|
||||
assert prompt["6"]["inputs"]["audio"] == ["1", 1]
|
||||
assert prompt["6"]["inputs"]["assembly_plan"] == ["1", 2]
|
||||
assert prompt["6"]["inputs"]["buffer_backend"] == "Disk-backed"
|
||||
assert prompt["6"]["inputs"]["exact_total_duration"] is True
|
||||
assert prompt["6"]["inputs"]["video_seam"] == "Auto"
|
||||
|
||||
|
||||
def test_p25_process_memory_snapshot_reports_portable_fields():
|
||||
probe = _probe_module()
|
||||
snapshot = probe._process_memory_snapshot()
|
||||
|
||||
assert snapshot["rss"] > 0
|
||||
if "uss" in snapshot:
|
||||
assert snapshot["uss"] > 0
|
||||
|
||||
|
||||
@pytest.mark.skipif(os.name != "nt", reason="Windows private commit field")
|
||||
def test_p25_process_memory_snapshot_reports_windows_commit_field():
|
||||
probe = _probe_module()
|
||||
snapshot = probe._process_memory_snapshot()
|
||||
|
||||
assert snapshot["private"] > 0
|
||||
@@ -0,0 +1,149 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from types import SimpleNamespace
|
||||
|
||||
import pytest
|
||||
import torch
|
||||
|
||||
from ComfyUI_H3_Continuum_Join.v2 import h3_builder
|
||||
|
||||
|
||||
class _Clip:
|
||||
def __init__(self):
|
||||
self.calls = 0
|
||||
self.layer_idx = None
|
||||
self.use_clip_schedule = False
|
||||
self.tokenizer_options = {}
|
||||
self.apply_hooks_to_conds = None
|
||||
self.patcher = SimpleNamespace(
|
||||
patches_uuid="patch-a",
|
||||
forced_hooks=None,
|
||||
current_hooks=None,
|
||||
hook_patches={},
|
||||
)
|
||||
|
||||
def tokenize(self, prompt, **kwargs):
|
||||
return prompt, kwargs
|
||||
|
||||
def encode_from_tokens_scheduled(self, _tokens):
|
||||
self.calls += 1
|
||||
return [[
|
||||
torch.tensor([[[1.0, 2.0]]]),
|
||||
{
|
||||
"pooled_output": torch.tensor([[3.0]]),
|
||||
"nested": {"items": ["original"]},
|
||||
},
|
||||
]]
|
||||
|
||||
|
||||
def _encode(clip, prompt="prompt", first=None, last=None, events=None):
|
||||
return h3_builder.encode_prompt_conditioning_cached(
|
||||
clip,
|
||||
prompt,
|
||||
first_image=first,
|
||||
last_image=last,
|
||||
first_image_fingerprint=h3_builder._tensor_fingerprint(first),
|
||||
last_image_fingerprint=h3_builder._tensor_fingerprint(last),
|
||||
cache_enabled=True,
|
||||
cache_event=None if events is None else events.append,
|
||||
)
|
||||
|
||||
|
||||
def test_cache_hit_is_bit_exact_and_only_metadata_containers_are_copied():
|
||||
clip = _Clip()
|
||||
first = _encode(clip)
|
||||
second = _encode(clip)
|
||||
|
||||
assert clip.calls == 1
|
||||
assert torch.equal(first[0][0], second[0][0])
|
||||
assert first[0][0] is second[0][0]
|
||||
assert first is not second
|
||||
assert first[0][1] is not second[0][1]
|
||||
assert first[0][1]["nested"] is not second[0][1]["nested"]
|
||||
assert first[0][1]["nested"]["items"] is not second[0][1]["nested"]["items"]
|
||||
second[0][1]["nested"]["items"].append("mutation")
|
||||
third = _encode(clip)
|
||||
assert third[0][1]["nested"]["items"] == ["original"]
|
||||
|
||||
|
||||
def test_prompt_first_last_clip_patch_and_layer_changes_are_misses():
|
||||
clip = _Clip()
|
||||
first = torch.zeros((1, 4, 4, 3))
|
||||
last = torch.ones((1, 4, 4, 3))
|
||||
_encode(clip, first=first, last=last)
|
||||
_encode(clip, prompt="changed", first=first, last=last)
|
||||
_encode(clip, prompt="changed", first=first.clone().fill_(0.5), last=last)
|
||||
_encode(clip, prompt="changed", first=first.clone().fill_(0.5), last=None)
|
||||
clip.patcher.patches_uuid = "patch-b"
|
||||
_encode(clip, prompt="changed", first=first.clone().fill_(0.5), last=None)
|
||||
clip.layer_idx = -2
|
||||
_encode(clip, prompt="changed", first=first.clone().fill_(0.5), last=None)
|
||||
assert clip.calls == 6
|
||||
|
||||
|
||||
def test_image_fingerprint_includes_shape_dtype_and_exact_content():
|
||||
base = torch.zeros((1, 4, 4, 3), dtype=torch.float32)
|
||||
changed = base.clone()
|
||||
changed[0, 0, 0, 0] = 1.0
|
||||
fingerprints = {
|
||||
h3_builder._tensor_fingerprint(base),
|
||||
h3_builder._tensor_fingerprint(base.reshape(1, 2, 8, 3)),
|
||||
h3_builder._tensor_fingerprint(base.to(torch.float64)),
|
||||
h3_builder._tensor_fingerprint(changed),
|
||||
}
|
||||
assert len(fingerprints) == 4
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"mutate",
|
||||
[
|
||||
lambda clip: setattr(clip, "use_clip_schedule", True),
|
||||
lambda clip: setattr(clip, "tokenizer_options", {"weight": "custom"}),
|
||||
lambda clip: setattr(clip, "apply_hooks_to_conds", object()),
|
||||
lambda clip: setattr(clip.patcher, "forced_hooks", object()),
|
||||
lambda clip: setattr(clip.patcher, "current_hooks", object()),
|
||||
lambda clip: setattr(clip.patcher, "hook_patches", {"hook": object()}),
|
||||
],
|
||||
)
|
||||
def test_special_clip_modes_bypass_cache(mutate):
|
||||
clip = _Clip()
|
||||
events = []
|
||||
mutate(clip)
|
||||
_encode(clip, events=events)
|
||||
_encode(clip, events=events)
|
||||
assert clip.calls == 2
|
||||
assert events == ["bypass_special_clip", "bypass_special_clip"]
|
||||
|
||||
|
||||
def test_lru_keeps_only_sixteen_entries_and_evicts_oldest():
|
||||
clip = _Clip()
|
||||
for index in range(17):
|
||||
_encode(clip, prompt=f"prompt-{index}")
|
||||
cache = getattr(clip, h3_builder._PROMPT_CACHE_ATTR)
|
||||
assert len(cache) == 16
|
||||
assert clip.calls == 17
|
||||
_encode(clip, prompt="prompt-0")
|
||||
assert clip.calls == 18
|
||||
assert len(cache) == 16
|
||||
|
||||
|
||||
def test_cuda_conditioning_is_not_retained(monkeypatch):
|
||||
clip = _Clip()
|
||||
events = []
|
||||
monkeypatch.setattr(h3_builder, "_contains_cuda_tensor", lambda _value: True)
|
||||
_encode(clip, events=events)
|
||||
_encode(clip, events=events)
|
||||
assert clip.calls == 2
|
||||
assert events == ["bypass_cuda_output", "bypass_cuda_output"]
|
||||
cache = getattr(clip, h3_builder._PROMPT_CACHE_ATTR)
|
||||
assert len(cache) == 0
|
||||
|
||||
|
||||
def test_cache_container_failure_falls_back_to_uncached_encode():
|
||||
clip = _Clip()
|
||||
events = []
|
||||
setattr(clip, h3_builder._PROMPT_CACHE_ATTR, {})
|
||||
_encode(clip, events=events)
|
||||
_encode(clip, events=events)
|
||||
assert clip.calls == 2
|
||||
assert events == ["bypass_cache_error", "bypass_cache_error"]
|
||||
@@ -0,0 +1,35 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import importlib.util
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
MODULE_PATH = Path(__file__).parents[1] / "tools" / "p32_api_runner.py"
|
||||
SPEC = importlib.util.spec_from_file_location("h3_p32_api_runner", MODULE_PATH)
|
||||
assert SPEC is not None and SPEC.loader is not None
|
||||
runner = importlib.util.module_from_spec(SPEC)
|
||||
SPEC.loader.exec_module(runner)
|
||||
|
||||
|
||||
def test_history_complete_accepts_completed_status():
|
||||
assert runner._history_complete(
|
||||
{"abc": {"status": {"completed": True}, "outputs": {}}}, "abc"
|
||||
)
|
||||
assert not runner._history_complete({}, "abc")
|
||||
|
||||
|
||||
def test_history_error_extracts_execution_failure():
|
||||
history = {
|
||||
"abc": {
|
||||
"status": {
|
||||
"messages": [
|
||||
["execution_start", {"prompt_id": "abc"}],
|
||||
["execution_error", {"exception_message": "bad"}],
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
value = runner._history_error(history, "abc")
|
||||
assert value is not None
|
||||
assert "execution_error" in value
|
||||
assert runner._history_error({}, "abc") is None
|
||||
@@ -0,0 +1,141 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import importlib.util
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
MODULE_PATH = Path(__file__).parents[1] / "tools" / "p32_gpu_profile_probe.py"
|
||||
SPEC = importlib.util.spec_from_file_location("h3_p32_profile_probe", MODULE_PATH)
|
||||
assert SPEC is not None and SPEC.loader is not None
|
||||
probe = importlib.util.module_from_spec(SPEC)
|
||||
SPEC.loader.exec_module(probe)
|
||||
|
||||
|
||||
def _base_prompt():
|
||||
return {
|
||||
"1": {"class_type": "UNETLoader", "inputs": {}},
|
||||
"2": {
|
||||
"class_type": "MiniMaxH3MemoryEfficientSageAttentionPatch",
|
||||
"inputs": {"model": ["1", 0]},
|
||||
},
|
||||
"3": {
|
||||
"class_type": "SpectrumApplyMiniMaxH3",
|
||||
"inputs": {"model": ["2", 0], "enabled": False},
|
||||
},
|
||||
"4": {
|
||||
"class_type": "H3ContinuumSamplerV35",
|
||||
"inputs": {"model": ["3", 0], "base_seed": 1},
|
||||
},
|
||||
"5": {
|
||||
"class_type": "SaveVideo",
|
||||
"inputs": {"filename_prefix": "original", "video": ["4", 0]},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("profile", "spectrum_enabled", "has_sol"),
|
||||
(
|
||||
("sage", False, False),
|
||||
("sage_sol", False, True),
|
||||
("sage_spectrum", True, False),
|
||||
("sage_sol_spectrum", True, True),
|
||||
),
|
||||
)
|
||||
def test_configure_profile_builds_exact_route(profile, spectrum_enabled, has_sol):
|
||||
source = _base_prompt()
|
||||
result = probe.configure_profile(source, profile)
|
||||
assert source["3"]["inputs"]["enabled"] is False
|
||||
assert result["3"]["inputs"]["enabled"] is spectrum_enabled
|
||||
sol_nodes = probe._find_nodes(result, "SolAttnPatch")
|
||||
assert bool(sol_nodes) is has_sol
|
||||
if has_sol:
|
||||
sol_id = sol_nodes[0]
|
||||
assert result[sol_id]["inputs"]["model"] == ["2", 0]
|
||||
assert result["3"]["inputs"]["model"] == [sol_id, 0]
|
||||
assert result[sol_id]["inputs"]["verbose"] is True
|
||||
else:
|
||||
assert result["3"]["inputs"]["model"] == ["2", 0]
|
||||
|
||||
|
||||
def test_mutate_run_changes_only_seed_and_filename():
|
||||
source = _base_prompt()
|
||||
result = probe.mutate_run(source, seed=99, filename_prefix="p32/test")
|
||||
assert source["4"]["inputs"]["base_seed"] == 1
|
||||
assert source["5"]["inputs"]["filename_prefix"] == "original"
|
||||
assert result["4"]["inputs"]["base_seed"] == 99
|
||||
assert result["5"]["inputs"]["filename_prefix"] == "p32/test"
|
||||
|
||||
|
||||
def test_summarize_runs_uses_median_and_keeps_missing_cuda_peak():
|
||||
runs = [
|
||||
{
|
||||
"elapsed_seconds": 9.0,
|
||||
"phase_totals_seconds": {"sampling": 7.0, "video_vae_decode": 1.0},
|
||||
"resources": {
|
||||
"peak_rss_bytes": 90,
|
||||
"peak_private_bytes": 70,
|
||||
"peak_uss_bytes": 60,
|
||||
"minimum_cuda_free_bytes": 40,
|
||||
},
|
||||
"cuda_global_peak_allocated_bytes": None,
|
||||
},
|
||||
{
|
||||
"elapsed_seconds": 5.0,
|
||||
"phase_totals_seconds": {"sampling": 3.0, "video_vae_decode": 0.5},
|
||||
"resources": {
|
||||
"peak_rss_bytes": 50,
|
||||
"peak_private_bytes": 30,
|
||||
"peak_uss_bytes": 20,
|
||||
"minimum_cuda_free_bytes": 10,
|
||||
},
|
||||
"cuda_global_peak_allocated_bytes": None,
|
||||
},
|
||||
{
|
||||
"elapsed_seconds": 7.0,
|
||||
"phase_totals_seconds": {"sampling": 5.0, "video_vae_decode": 0.8},
|
||||
"resources": {
|
||||
"peak_rss_bytes": 70,
|
||||
"peak_private_bytes": 50,
|
||||
"peak_uss_bytes": 40,
|
||||
"minimum_cuda_free_bytes": 20,
|
||||
},
|
||||
"cuda_global_peak_allocated_bytes": None,
|
||||
},
|
||||
]
|
||||
result = probe.summarize_runs(runs)
|
||||
assert result["median_elapsed_seconds"] == 7.0
|
||||
assert result["median_phase_seconds"]["sampling"] == 5.0
|
||||
assert result["median_peak_rss_bytes"] == 70.0
|
||||
assert result["median_peak_private_bytes"] == 50.0
|
||||
assert result["median_peak_uss_bytes"] == 40.0
|
||||
assert result["median_cuda_global_peak_allocated_bytes"] is None
|
||||
|
||||
|
||||
def test_phase_classification_is_explicit():
|
||||
assert probe._phase_for_class("H3ContinuumSamplerV35") == "sampling"
|
||||
assert probe._phase_for_class("VAEDecode") == "video_vae_decode"
|
||||
assert probe._phase_for_class("VAEDecodeAudio") == "audio_vae_decode"
|
||||
assert probe._phase_for_class("H3ContinuumAssembleSeamV35") == "assemble_seam"
|
||||
assert probe._phase_for_class("CreateVideo") == "video_create"
|
||||
assert probe._phase_for_class("SaveVideo") == "mp4_encode_save"
|
||||
assert probe._phase_for_class("UnknownNode") == "other"
|
||||
|
||||
|
||||
def test_resource_monitor_does_not_poll_cuda_runtime():
|
||||
source = MODULE_PATH.read_text(encoding="utf-8")
|
||||
assert "torch.cuda.mem_get_info" not in source.replace(
|
||||
'``torch.cuda.mem_get_info``', ""
|
||||
)
|
||||
assert "pynvml.nvmlDeviceGetMemoryInfo" in source
|
||||
|
||||
|
||||
def test_resource_monitor_does_not_poll_full_process_info():
|
||||
source = MODULE_PATH.read_text(encoding="utf-8")
|
||||
sample_body = source.split("def _sample(self) -> None:", 1)[1].split(
|
||||
"def _run(self) -> None:", 1
|
||||
)[0]
|
||||
assert "_memory_snapshot()" not in sample_body
|
||||
assert "self.process.memory_info()" in sample_body
|
||||
@@ -0,0 +1,32 @@
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
SERVER_PATH = Path(__file__).parents[1] / "tools" / "p32_profile_server.py"
|
||||
|
||||
|
||||
def test_phase32_api_profiler_is_diagnostic_only_and_synchronized():
|
||||
source = SERVER_PATH.read_text(encoding="utf-8")
|
||||
assert "torch.cuda.synchronize()" in source
|
||||
assert "torch.cuda.reset_peak_memory_stats()" in source
|
||||
assert 'PROFILE_MODE == "global"' in source
|
||||
assert 'PROFILE_MODE == "interval"' in source
|
||||
assert "original_execute_async" in source
|
||||
assert "original_get_output_data" in source
|
||||
assert "NODE_CLASS_MAPPINGS" not in source
|
||||
assert "class H3" not in source
|
||||
|
||||
|
||||
def test_phase32_api_profiler_records_required_pipeline_phases():
|
||||
source = SERVER_PATH.read_text(encoding="utf-8") + (
|
||||
Path(__file__).parents[1] / "tools" / "p32_gpu_profile_probe.py"
|
||||
).read_text(encoding="utf-8")
|
||||
for value in (
|
||||
"phase_totals_seconds",
|
||||
"cuda_global_peak_allocated_bytes",
|
||||
"peak_private_bytes",
|
||||
"peak_uss_bytes",
|
||||
"minimum_cuda_free_bytes",
|
||||
"route_observed",
|
||||
"spectrum_enabled",
|
||||
):
|
||||
assert value in source
|
||||
@@ -0,0 +1,100 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import hashlib
|
||||
|
||||
import pytest
|
||||
import torch
|
||||
|
||||
from ComfyUI_H3_Continuum_Join import reference_video
|
||||
|
||||
|
||||
def _legacy_v3_hash(value: torch.Tensor) -> str:
|
||||
normalized = value[:, :, :, :3].detach().to(
|
||||
device="cpu", dtype=torch.float32
|
||||
).contiguous()
|
||||
digest = hashlib.sha256()
|
||||
digest.update(str(tuple(int(item) for item in normalized.shape)).encode("ascii"))
|
||||
digest.update(str(normalized.dtype).encode("ascii"))
|
||||
digest.update(normalized.numpy().tobytes(order="C"))
|
||||
return digest.hexdigest()
|
||||
|
||||
|
||||
def _source(value: torch.Tensor, *, target_frames: int = 22):
|
||||
return reference_video.prepare_reference_video_source(
|
||||
value,
|
||||
target_frames=target_frames,
|
||||
output_width=32,
|
||||
output_height=32,
|
||||
)
|
||||
|
||||
|
||||
def test_chunked_source_hash_is_exactly_legacy_v3_for_full_normalized_input():
|
||||
torch.manual_seed(4601)
|
||||
value = torch.rand((43, 32, 48, 4), dtype=torch.float64)
|
||||
|
||||
source = _source(value)
|
||||
|
||||
assert source.source_sha256 == _legacy_v3_hash(value)
|
||||
assert source.source_shape == (43, 32, 48, 3)
|
||||
assert source.source_dtype == "torch.float32"
|
||||
assert source.contract["preprocess_version"] == 3
|
||||
|
||||
|
||||
def test_only_used_prefix_storage_is_retained_but_full_tail_remains_in_identity():
|
||||
torch.manual_seed(4602)
|
||||
value = torch.rand((80, 32, 32, 3), dtype=torch.float32)
|
||||
changed_tail = value.clone()
|
||||
changed_tail[-1, 0, 0, 0] += 0.25
|
||||
|
||||
original = _source(value)
|
||||
changed = _source(changed_tail)
|
||||
|
||||
assert original.frame_count == 22
|
||||
assert original.frames.shape == (22, 32, 32, 3)
|
||||
assert original.frames.untyped_storage().nbytes() == original.frames.numel() * 4
|
||||
assert torch.equal(original.frames, value[:22])
|
||||
assert torch.equal(original.frames, changed.frames)
|
||||
assert original.source_sha256 != changed.source_sha256
|
||||
assert original.combined_hash != changed.combined_hash
|
||||
assert reference_video.combine_reference_video_identity("visual", original) != (
|
||||
reference_video.combine_reference_video_identity("visual", changed)
|
||||
)
|
||||
|
||||
|
||||
def test_nonfinite_value_in_unused_tail_is_still_rejected():
|
||||
value = torch.zeros((80, 32, 32, 3), dtype=torch.float32)
|
||||
value[-1, 0, 0, 0] = torch.nan
|
||||
|
||||
with pytest.raises(reference_video.ReferenceVideoError, match="NaN or infinity"):
|
||||
_source(value)
|
||||
|
||||
|
||||
def test_short_source_keeps_v3_alignment_and_final_frame_padding_contract():
|
||||
value = torch.arange(6 * 32 * 32 * 3, dtype=torch.float32).reshape(
|
||||
6, 32, 32, 3
|
||||
)
|
||||
source = _source(value, target_frames=124)
|
||||
captured = {}
|
||||
|
||||
class VideoVAE:
|
||||
def encode(self, frames):
|
||||
captured["frames"] = frames.clone()
|
||||
return torch.zeros((1, 24, 7, 2, 2), dtype=torch.float32)
|
||||
|
||||
assets = reference_video.encode_reference_video(VideoVAE(), source)
|
||||
|
||||
assert source.frame_count == 22
|
||||
assert source.frames.shape[0] == 6
|
||||
assert captured["frames"].shape == (22, 32, 32, 3)
|
||||
assert torch.equal(captured["frames"][:6], value)
|
||||
assert torch.equal(
|
||||
captured["frames"][6:], value[-1:].expand(16, -1, -1, -1)
|
||||
)
|
||||
assert assets.block["latent_t"] == 7
|
||||
|
||||
|
||||
def test_chunked_tensor_hash_matches_legacy_byte_order():
|
||||
torch.manual_seed(4603)
|
||||
value = torch.rand((19, 7, 9, 3), dtype=torch.float32)
|
||||
|
||||
assert reference_video._tensor_hash(value) == _legacy_v3_hash(value)
|
||||
@@ -0,0 +1,269 @@
|
||||
from types import MappingProxyType
|
||||
|
||||
import pytest
|
||||
import torch
|
||||
|
||||
from ComfyUI_H3_Continuum_Join.layout_adapter import (
|
||||
LayoutCompatibilityError,
|
||||
normalize_condition_latents,
|
||||
preflight_packed_layout,
|
||||
)
|
||||
|
||||
|
||||
class FakePackedLayout:
|
||||
"""Small Core-compatible row topology used by contract tests."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
text_len,
|
||||
latent_t,
|
||||
latent_h,
|
||||
latent_w,
|
||||
audio_t,
|
||||
keyframes=None,
|
||||
refs=None,
|
||||
):
|
||||
self.signature = (
|
||||
int(text_len),
|
||||
int(latent_t),
|
||||
int(latent_h),
|
||||
int(latent_w),
|
||||
int(audio_t),
|
||||
)
|
||||
frame_rows = (int(latent_h) // 2) * (int(latent_w) // 2)
|
||||
parts = [("text", int(text_len))]
|
||||
for keyframe in keyframes or ():
|
||||
latent = keyframe.get("latent")
|
||||
if latent is not None:
|
||||
parts.append(("cond", int(latent.shape[2]) * frame_rows))
|
||||
audio = keyframe.get("audio_latent")
|
||||
if audio is not None:
|
||||
parts.append(("cond_audio", int(audio.shape[-1]) * 2))
|
||||
for ref in refs or ():
|
||||
kind = ref["kind"]
|
||||
if kind == "image":
|
||||
parts.append(
|
||||
(
|
||||
"ref_img",
|
||||
(int(ref["latent_h"]) // 2)
|
||||
* (int(ref["latent_w"]) // 2),
|
||||
)
|
||||
)
|
||||
elif kind == "audio":
|
||||
if int(ref["ref_audio_t"]) > 0:
|
||||
parts.append(("ref_audio", int(ref["ref_audio_t"]) * 2))
|
||||
elif kind in ("video", "video_audio"):
|
||||
if int(ref["ref_audio_t"]) > 0:
|
||||
parts.append(("ref_audio", int(ref["ref_audio_t"]) * 2))
|
||||
parts.append(
|
||||
(
|
||||
"ref_img",
|
||||
int(ref["latent_t"])
|
||||
* (int(ref["latent_h"]) // 2)
|
||||
* (int(ref["latent_w"]) // 2),
|
||||
)
|
||||
)
|
||||
else:
|
||||
raise ValueError(f"unsupported ref kind: {kind}")
|
||||
parts.extend(
|
||||
(
|
||||
("audio", int(audio_t) * 2),
|
||||
("video", int(latent_t) * frame_rows),
|
||||
)
|
||||
)
|
||||
row = 0
|
||||
self.segments = []
|
||||
for kind, count in parts:
|
||||
self.segments.append((row, row + count, kind))
|
||||
row += count
|
||||
self.seq_len = row
|
||||
self.position_ids = torch.zeros(row, 3, dtype=torch.float64)
|
||||
|
||||
|
||||
def _layout(*, keyframes=None, refs=None):
|
||||
return FakePackedLayout(
|
||||
3,
|
||||
2,
|
||||
4,
|
||||
6,
|
||||
5,
|
||||
keyframes=keyframes,
|
||||
refs=refs,
|
||||
)
|
||||
|
||||
|
||||
def test_preflight_accepts_self_consistent_visual_audio_and_multiple_blocks():
|
||||
first = torch.zeros(1, 24, 1, 4, 6)
|
||||
guide_audio = torch.zeros(1, 32, 2, 5)
|
||||
image = torch.zeros(1, 24, 1, 2, 4)
|
||||
video = torch.zeros(1, 24, 2, 2, 2)
|
||||
ref_audio = torch.zeros(1, 32, 2, 3)
|
||||
keyframes = [
|
||||
{"resolved_frame_index": 0, "latent": first},
|
||||
{"resolved_frame_index": 0, "audio_latent": guide_audio},
|
||||
]
|
||||
refs = [
|
||||
{
|
||||
"kind": "image",
|
||||
"latent_h": 2,
|
||||
"latent_w": 4,
|
||||
"latent": image,
|
||||
},
|
||||
{
|
||||
"kind": "video_audio",
|
||||
"latent_t": 2,
|
||||
"latent_h": 2,
|
||||
"latent_w": 2,
|
||||
"ref_audio_t": 3,
|
||||
"latent": video,
|
||||
"audio_latent": ref_audio,
|
||||
},
|
||||
]
|
||||
payload = {
|
||||
"layout": _layout(keyframes=keyframes, refs=refs),
|
||||
"keyframes": keyframes,
|
||||
"refs": refs,
|
||||
}
|
||||
normalize_condition_latents(payload)
|
||||
|
||||
result = preflight_packed_layout(payload, repair_stale=False)
|
||||
|
||||
assert result["status"] == "matched"
|
||||
assert result["layout_visual_rows"] == result["actual_visual_rows"] == 10
|
||||
assert result["layout_audio_rows"] == result["actual_audio_rows"] == 16
|
||||
assert len(result["visual_blocks"]) == 3
|
||||
assert len(result["audio_blocks"]) == 2
|
||||
|
||||
|
||||
def test_preflight_accepts_frozen_second_pass_reference_mapping():
|
||||
# RefineContext freezes First Pass metadata as MappingProxyType. Core
|
||||
# PackedLayout accepts it, so the Continuum preflight must do the same.
|
||||
ref = MappingProxyType({
|
||||
"kind": "image", "latent_h": 42, "latent_w": 28,
|
||||
"latent": torch.zeros(1, 24, 1, 42, 28),
|
||||
})
|
||||
payload = {"layout": _layout(refs=[ref]), "refs": [ref]}
|
||||
normalize_condition_latents(payload)
|
||||
|
||||
result = preflight_packed_layout(payload, repair_stale=False)
|
||||
|
||||
assert result["status"] == "matched"
|
||||
assert result["layout_visual_rows"] == result["actual_visual_rows"] == 294
|
||||
assert result["repaired"] is False
|
||||
|
||||
|
||||
def test_preflight_repairs_only_a_stale_layout_from_current_payload():
|
||||
first = torch.zeros(1, 24, 1, 4, 6)
|
||||
guide_audio = torch.zeros(1, 32, 2, 5)
|
||||
keyframes = [
|
||||
{"resolved_frame_index": 0, "latent": first},
|
||||
{"resolved_frame_index": 0, "audio_latent": guide_audio},
|
||||
]
|
||||
stale = _layout(keyframes=None, refs=None)
|
||||
payload = {"layout": stale, "keyframes": keyframes, "refs": []}
|
||||
normalize_condition_latents(payload)
|
||||
|
||||
result = preflight_packed_layout(payload, repair_stale=True)
|
||||
|
||||
assert result["status"] == "layout_rebuilt"
|
||||
assert result["repaired"] is True
|
||||
assert payload["layout"] is not stale
|
||||
assert result["layout_visual_rows"] == result["actual_visual_rows"] == 6
|
||||
assert result["layout_audio_rows"] == result["actual_audio_rows"] == 10
|
||||
final = preflight_packed_layout(payload, repair_stale=False)
|
||||
assert final["status"] == "matched"
|
||||
|
||||
|
||||
def test_preflight_rejects_keyframe_target_geometry_mismatch_without_mutation():
|
||||
first = torch.zeros(1, 24, 1, 4, 4)
|
||||
keyframes = [{"resolved_frame_index": 0, "latent": first}]
|
||||
payload = {
|
||||
"layout": _layout(keyframes=keyframes),
|
||||
"keyframes": keyframes,
|
||||
"refs": [],
|
||||
}
|
||||
original = first.clone()
|
||||
normalize_condition_latents(payload)
|
||||
|
||||
with pytest.raises(LayoutCompatibilityError) as caught:
|
||||
preflight_packed_layout(payload, repair_stale=True)
|
||||
|
||||
message = str(caught.value)
|
||||
assert "Visual block #1" in message
|
||||
assert "type: keyframe" in message
|
||||
assert "resolved_frame_index: 0" in message
|
||||
assert "latent shape: B=1 C=24 T=1 H=4 W=4" in message
|
||||
assert "expected rows: 6" in message
|
||||
assert "actual rows: 4" in message
|
||||
assert "delta: -2" in message
|
||||
assert "Unsafe geometry mismatch" in message
|
||||
assert "Sampling was not started" in message
|
||||
assert torch.equal(first, original)
|
||||
|
||||
|
||||
def test_preflight_rejects_reference_metadata_geometry_mismatch():
|
||||
image = torch.zeros(1, 24, 1, 4, 4)
|
||||
refs = [
|
||||
{
|
||||
"kind": "image",
|
||||
"latent_h": 4,
|
||||
"latent_w": 6,
|
||||
"latent": image,
|
||||
}
|
||||
]
|
||||
payload = {"layout": _layout(refs=refs), "keyframes": [], "refs": refs}
|
||||
normalize_condition_latents(payload)
|
||||
|
||||
with pytest.raises(LayoutCompatibilityError) as caught:
|
||||
preflight_packed_layout(payload, repair_stale=True)
|
||||
|
||||
message = str(caught.value)
|
||||
assert "type: ref_image" in message
|
||||
assert "reference metadata H/W (4, 6) != latent H/W (4, 4)" in message
|
||||
assert "expected rows: 6" in message
|
||||
assert "actual rows: 4" in message
|
||||
|
||||
|
||||
def test_preflight_rejects_reference_audio_metadata_mismatch():
|
||||
audio = torch.zeros(1, 32, 2, 3)
|
||||
refs = [
|
||||
{
|
||||
"kind": "audio",
|
||||
"ref_audio_t": 4,
|
||||
"audio_latent": audio,
|
||||
}
|
||||
]
|
||||
payload = {"layout": _layout(refs=refs), "keyframes": [], "refs": refs}
|
||||
normalize_condition_latents(payload)
|
||||
|
||||
with pytest.raises(LayoutCompatibilityError) as caught:
|
||||
preflight_packed_layout(payload, repair_stale=True)
|
||||
|
||||
message = str(caught.value)
|
||||
assert "Audio block #1" in message
|
||||
assert "type: ref_audio" in message
|
||||
assert "expected rows: 8" in message
|
||||
assert "actual rows: 6" in message
|
||||
assert "reference metadata audio_t 4 != latent audio_t 3" in message
|
||||
|
||||
|
||||
def test_preflight_does_not_invent_a_layout_when_core_has_not_built_one():
|
||||
payload = {
|
||||
"keyframes": [
|
||||
{
|
||||
"resolved_frame_index": 0,
|
||||
"audio_latent": torch.zeros(1, 32, 2, 3),
|
||||
}
|
||||
],
|
||||
"refs": [],
|
||||
}
|
||||
normalize_condition_latents(payload)
|
||||
|
||||
result = preflight_packed_layout(payload, repair_stale=True)
|
||||
|
||||
assert result == {
|
||||
"status": "layout_unavailable",
|
||||
"repaired": False,
|
||||
"visual_blocks": (),
|
||||
"audio_blocks": (),
|
||||
}
|
||||
@@ -0,0 +1,162 @@
|
||||
"""Saved reason projection and real-provider Review continuation, CPU only."""
|
||||
import copy
|
||||
import hashlib
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
import torch
|
||||
|
||||
from ComfyUI_H3_Continuum_Join import run_storage as storage
|
||||
from ComfyUI_H3_Continuum_Join import preview_override_signature as adapter
|
||||
from . import test_v31_run_storage as signatures
|
||||
from . import test_v38_review_run_storage as review
|
||||
from .test_issue31_preview_override_signature import kj, wrapper, model_with
|
||||
|
||||
|
||||
def prepare_kwargs(model):
|
||||
return dict(model=model, model_fingerprint_value="f" * 64, clip=signatures._Clip(),
|
||||
video_vae=signatures._VideoVAE(), sampler=signatures._Sampler(), sigmas=torch.tensor([1., 0.]),
|
||||
prompt_plan={"chunks": 3, "hashes": [str(i) * 64 for i in (1, 2, 3)],
|
||||
"mode": "list", "prompts": ["prompt 1", "prompt 2", "prompt 3"]},
|
||||
width=96, height=64, chunk_seconds=5., continuity="Balanced", audio_continuity=True,
|
||||
base_seed=1, reroll_from_chunk=0, reroll_nonce=0, first_frame_hash="a" * 64,
|
||||
last_frame_hash="", identity_hash="fixture", strict_compatibility=True,
|
||||
existing_session=None, conditioning_mode="i2va")
|
||||
|
||||
|
||||
def controller_at(path):
|
||||
controller = storage.RunStorageController("preview-reuse-test")
|
||||
controller.run_root = path
|
||||
controller.revisions_root = path / "revisions"
|
||||
controller.set_prompt_graph(signatures._prompt_graph(), "42")
|
||||
controller.configure_review(generation_mode=review.GENERATION_MODE_REVIEW,
|
||||
review_action=review.REVIEW_ACTION_CONTINUE)
|
||||
return controller
|
||||
|
||||
|
||||
@pytest.mark.parametrize("setting", [None, "vae", "audio_vae", "tiny_vae"])
|
||||
def test_real_provider_saved_take_and_separate_controller_continue(kj, tmp_path, setting):
|
||||
item = wrapper(kj)
|
||||
if setting is not None:
|
||||
setattr(item, setting, "taeh3" if setting == "tiny_vae" else object())
|
||||
kwargs = prepare_kwargs(model_with(item))
|
||||
source = controller_at(tmp_path)
|
||||
source.prepare(**kwargs)
|
||||
entry = review._entry(0, source.contract)
|
||||
source.commit_group((entry,), positions=(0,))
|
||||
source.mark_review_group(start=1, end=1, physical_group=1)
|
||||
source.finalize(session={"session_id": "fixture", "chunks": [entry]}, report="CPU fixture",
|
||||
review_pause_metadata=source.review_pause_metadata())
|
||||
project = review._project(source)
|
||||
take = project["group_revisions"][0]
|
||||
expected_safe = setting is None
|
||||
assert take["generation_reusable"] is expected_safe
|
||||
assert take["sampling_contract_version"] == 6
|
||||
if expected_safe:
|
||||
assert "resume_disabled_reasons" not in take
|
||||
else:
|
||||
expected = "KJ preview VAE/Audio VAE or Tiny VAE is outside the supported configuration"
|
||||
assert expected in source.manifest["resume_disabled_reasons"]
|
||||
assert expected in take["resume_disabled_reasons"]
|
||||
assert take["resume_disabled_reasons"] == project["revisions"][0]["resume_disabled_reasons"]
|
||||
original_raw = {str(p): hashlib.sha256(p.read_bytes()).hexdigest() for p in tmp_path.rglob("*.safetensors")}
|
||||
original_identity = storage.revision_identity(source.contract)
|
||||
item.frames.append(object())
|
||||
again = controller_at(tmp_path)
|
||||
session = again.prepare(**kwargs)
|
||||
assert again.reused_count == int(expected_safe)
|
||||
assert len((session or {}).get("chunks", [])) == int(expected_safe)
|
||||
assert again.review_execution.next_review_unit_start == (2 if expected_safe else 1)
|
||||
if expected_safe:
|
||||
assert storage.revision_identity(again.contract) == original_identity
|
||||
assert original_raw and all(hashlib.sha256(Path(p).read_bytes()).hexdigest() == digest
|
||||
for p, digest in original_raw.items())
|
||||
|
||||
|
||||
@pytest.mark.parametrize("failure,expected", [
|
||||
("provider source is outside the audited profile", "KJ/Core preview implementation is outside the audited source profiles"),
|
||||
("Core approximate VAE is outside Phase A", "Core approximate-VAE preview is outside the supported configuration"),
|
||||
("loaded code differs from audited source", "KJ preview runtime code or state could not be verified"),
|
||||
("private /local/path exception", "KJ preview runtime code or state could not be verified"),
|
||||
])
|
||||
def test_reason_classification_uses_only_observed_slot(failure, expected):
|
||||
descriptor = {"wrappers": {"outer_sample": {"kj_preview_override": [
|
||||
{"adapter": "kj_preview_override_v1", "unsupported": failure}]}}}
|
||||
before = copy.deepcopy(descriptor)
|
||||
assert adapter.preview_override_reuse_reasons(descriptor) == [expected]
|
||||
assert descriptor == before
|
||||
assert adapter.preview_override_reuse_reasons({"other": descriptor}) == []
|
||||
|
||||
|
||||
def test_reasons_do_not_enter_sampling_identity(kj, monkeypatch):
|
||||
item = wrapper(kj)
|
||||
item.tiny_vae = "taeh3"
|
||||
model, clip, vae = model_with(item), signatures._Clip(), signatures._VideoVAE()
|
||||
original, safe, reasons = signatures._sampling_contract(model=model, clip=clip, video_vae=vae)
|
||||
assert not safe and any(reason in adapter.PREVIEW_REUSE_REASONS for reason in reasons)
|
||||
monkeypatch.setattr(storage, "preview_override_reuse_reasons", lambda descriptor: [])
|
||||
current, safe, generic = signatures._sampling_contract(model=model, clip=clip, video_vae=vae)
|
||||
assert not safe and len(generic) < len(reasons)
|
||||
assert storage._canonical(original) == storage._canonical(current)
|
||||
assert storage.revision_identity(original) == storage.revision_identity(current)
|
||||
|
||||
|
||||
def test_projection_sanitizes_and_omits_safe_or_missing_reasons():
|
||||
contract, safe, _ = signatures._sampling_contract(reroll_from_chunk=0)
|
||||
assert safe
|
||||
manifest = {"sampling_contract_version": 6, "resume_safe": True, "contract": contract,
|
||||
"resume_disabled_reasons": list(adapter.PREVIEW_REUSE_REASONS)}
|
||||
assert storage._project_resume_diagnostics(manifest) == {}
|
||||
manifest["resume_safe"] = False
|
||||
private = "C:/Users/private/file.py" + "x" * 2000
|
||||
manifest["resume_disabled_reasons"] = [private] * 12
|
||||
projected = storage._project_resume_diagnostics(manifest)["resume_disabled_reasons"]
|
||||
assert projected == [storage._UNKNOWN_REUSE_REASON]
|
||||
assert private not in json.dumps(projected) and max(map(len, projected)) <= 256
|
||||
manifest.pop("resume_disabled_reasons")
|
||||
assert storage._project_resume_diagnostics(manifest) == {}
|
||||
|
||||
|
||||
def test_project_reason_belongs_to_its_saved_revision(tmp_path):
|
||||
contract, safe, _ = signatures._sampling_contract(reroll_from_chunk=0)
|
||||
assert safe
|
||||
source = review._persist(tmp_path, contract, prefix=1, review_unit=(1, 1),
|
||||
updated_utc="2026-10-19T00:00:00+00:00")
|
||||
source.manifest["resume_safe"] = False
|
||||
source.manifest["resume_disabled_reasons"] = ["KJ preview runtime code or state could not be verified"]
|
||||
source._write_manifest()
|
||||
manifest_before = source._manifest_path().read_bytes()
|
||||
source._write_project()
|
||||
project = review._project(source)
|
||||
assert project["group_revisions"][0]["resume_disabled_reasons"] == source.manifest["resume_disabled_reasons"]
|
||||
assert source._manifest_path().read_bytes() == manifest_before
|
||||
|
||||
|
||||
@pytest.mark.parametrize("display_id", [None, "display-node"])
|
||||
def test_public_node_uses_core_hidden_display_id(kj, monkeypatch, display_id):
|
||||
has_display_mapping = "dynprompt" in kj.ModelPreviewOverrideKJ.execute.__code__.co_names
|
||||
from comfy_api.latest import io
|
||||
# Full-suite helpers can put the plugin ahead of Core; both contain nodes.py.
|
||||
core_root = Path(kj.latent_preview.__file__).resolve().parent
|
||||
monkeypatch.syspath_prepend(str(core_root))
|
||||
from comfy_execution.graph import DynamicPrompt
|
||||
import nodes as core_nodes
|
||||
assert Path(core_nodes.__file__).resolve() == core_root / "nodes.py"
|
||||
node_class = kj.ModelPreviewOverrideKJ
|
||||
dynprompt = None
|
||||
if display_id is not None:
|
||||
dynprompt = DynamicPrompt({display_id: {}})
|
||||
dynprompt.add_ephemeral_node("generated-node", {}, display_id, display_id)
|
||||
hidden = io.HiddenHolder.from_dict({io.Hidden.unique_id: "generated-node", io.Hidden.dynprompt: dynprompt})
|
||||
monkeypatch.setattr(node_class, "hidden", hidden)
|
||||
class Model:
|
||||
def clone(self):
|
||||
return self
|
||||
|
||||
def add_wrapper_with_key(self, kind, key, value):
|
||||
self.wrapper = value
|
||||
model = Model()
|
||||
node_class.execute(model, 512, 80, True, 1, 12)
|
||||
assert model.wrapper.node_id == ((display_id or "generated-node") if has_display_mapping else "generated-node")
|
||||
assert adapter.preview_override_signature(model.wrapper)[1]
|
||||
@@ -0,0 +1,13 @@
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.mark.parametrize("case", [
|
||||
"v6 read-only reports saved preview source and keeps actions disabled",
|
||||
"preview setting remedies preserve generation VAE guidance",
|
||||
"missing compatibility metadata is not mislabeled v5 or a known KJ error",
|
||||
"unknown saved reasons do not expose paths or unbounded text",
|
||||
"history reasons follow the selected Take rather than the canonical revision",
|
||||
"saved compatibility metadata controls Review with optional real backend vectors",
|
||||
])
|
||||
def test_readonly_reason_with_real_frontend(review_queue_results, case):
|
||||
assert review_queue_results[case]["pass"]
|
||||
@@ -0,0 +1,20 @@
|
||||
from ComfyUI_H3_Continuum_Join import public_api
|
||||
|
||||
|
||||
def test_public_api_is_v3_ready_and_complete():
|
||||
assert public_api.PUBLIC_API_VERSION == 3
|
||||
for name in (
|
||||
"make_extension_shape",
|
||||
"prepare_conditioning",
|
||||
"new_h3_latent",
|
||||
"capture_state",
|
||||
"select_context",
|
||||
"patch_layout_in_place",
|
||||
"trim_audio",
|
||||
"assemble_segments",
|
||||
"make_prompt_plan",
|
||||
"derive_chunk_seed",
|
||||
"choose_context_frames",
|
||||
"validate_session",
|
||||
):
|
||||
assert callable(getattr(public_api, name))
|
||||
@@ -0,0 +1,61 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
WORKFLOW_DIR = ROOT / "examples" / "workflows"
|
||||
WORKFLOWS = sorted(WORKFLOW_DIR.glob("*.json"))
|
||||
|
||||
|
||||
@pytest.mark.parametrize("workflow_path", WORKFLOWS, ids=lambda path: path.name)
|
||||
def test_public_workflow_links_are_serialization_consistent(workflow_path: Path) -> None:
|
||||
workflow = json.loads(workflow_path.read_text(encoding="utf-8"))
|
||||
workflow = json.loads(json.dumps(workflow, ensure_ascii=False))
|
||||
nodes = {int(node["id"]): node for node in workflow["nodes"]}
|
||||
links = {int(link[0]): link for link in workflow["links"]}
|
||||
|
||||
assert len(nodes) == len(workflow["nodes"]), "duplicate node ID"
|
||||
assert len(links) == len(workflow["links"]), "duplicate link ID"
|
||||
|
||||
for link_id, link in links.items():
|
||||
_, source_id, source_slot, target_id, target_slot, link_type = link
|
||||
source = nodes[int(source_id)]
|
||||
target = nodes[int(target_id)]
|
||||
outputs = source.get("outputs") or []
|
||||
inputs = target.get("inputs") or []
|
||||
|
||||
assert 0 <= int(source_slot) < len(outputs), f"link {link_id}: invalid source slot"
|
||||
assert 0 <= int(target_slot) < len(inputs), f"link {link_id}: invalid target slot"
|
||||
assert link_id in (outputs[int(source_slot)].get("links") or []), (
|
||||
f"link {link_id}: source output does not reference the link"
|
||||
)
|
||||
assert inputs[int(target_slot)].get("link") == link_id, (
|
||||
f"link {link_id}: target input does not reference the link"
|
||||
)
|
||||
|
||||
endpoint_types = {
|
||||
value
|
||||
for value in (
|
||||
outputs[int(source_slot)].get("type"),
|
||||
inputs[int(target_slot)].get("type"),
|
||||
link_type,
|
||||
)
|
||||
if value not in (None, "*")
|
||||
}
|
||||
assert len(endpoint_types) <= 1, f"link {link_id}: endpoint type mismatch"
|
||||
|
||||
for node in nodes.values():
|
||||
for output in node.get("outputs") or []:
|
||||
for link_id in output.get("links") or []:
|
||||
assert int(link_id) in links, f"node {node['id']}: dangling output link {link_id}"
|
||||
for input_ in node.get("inputs") or []:
|
||||
link_id = input_.get("link")
|
||||
if link_id is not None:
|
||||
assert int(link_id) in links, f"node {node['id']}: dangling input link {link_id}"
|
||||
|
||||
if links:
|
||||
assert int(workflow["last_link_id"]) >= max(links)
|
||||
@@ -0,0 +1,30 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import configparser
|
||||
from pathlib import Path
|
||||
import tomllib
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
EXPECTED_VERSION = "3.9.10"
|
||||
|
||||
|
||||
def test_v35_release_metadata_is_consistent():
|
||||
version_source = (ROOT / "version.py").read_text(encoding="utf-8")
|
||||
pyproject = tomllib.loads((ROOT / "pyproject.toml").read_text(encoding="utf-8"))
|
||||
metadata = configparser.ConfigParser()
|
||||
metadata.read(ROOT / "metadata.ini", encoding="utf-8")
|
||||
|
||||
assert f'PACKAGE_VERSION = "{EXPECTED_VERSION}"' in version_source
|
||||
assert pyproject["project"]["version"] == EXPECTED_VERSION
|
||||
assert metadata["project"]["version"] == EXPECTED_VERSION
|
||||
|
||||
|
||||
def test_public_documents_identify_the_current_v39_main():
|
||||
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")
|
||||
|
||||
assert readme.startswith(f"# ComfyUI-H3-Continuum {EXPECTED_VERSION} — V3.9\n")
|
||||
assert readme_ja.startswith(f"# ComfyUI-H3-Continuum {EXPECTED_VERSION} — V3.9\n")
|
||||
assert f"## {EXPECTED_VERSION}" in changelog
|
||||
@@ -0,0 +1,113 @@
|
||||
"""Run Storage identity must not track Core's normal loading lifecycle."""
|
||||
import copy
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import sys
|
||||
from types import SimpleNamespace
|
||||
|
||||
import torch
|
||||
|
||||
from ComfyUI_H3_Continuum_Join.run_storage import (
|
||||
_hash, _module_signature, _observe, _video_vae_signature,
|
||||
)
|
||||
|
||||
|
||||
def vae_fixture():
|
||||
module = torch.nn.Module()
|
||||
module.encoder = torch.nn.Linear(3, 4, bias=False)
|
||||
module.decoder = torch.nn.Module()
|
||||
module.decoder.register_parameter('scale1', torch.nn.Parameter(torch.tensor([0.123456, 0.654321, 1.234567])))
|
||||
module.decoder.proj = torch.nn.Linear(4, 3, bias=False)
|
||||
module.decoder.scale1_comfy_model_dtype = torch.float16
|
||||
return SimpleNamespace(first_stage_model=module, patcher=None, vae_dtype=torch.float16)
|
||||
|
||||
|
||||
def test_video_vae_identity_survives_core_lazy_cast_without_mutation():
|
||||
vae = vae_fixture()
|
||||
before_tensors = {n: p.detach().clone() for n, p in vae.first_stage_model.named_parameters()}
|
||||
rng = torch.random.get_rng_state().clone()
|
||||
cold, cold_safe = _video_vae_signature(vae, required=True)
|
||||
assert cold_safe
|
||||
assert torch.equal(rng, torch.random.get_rng_state())
|
||||
assert all(torch.equal(before_tensors[n], p) for n, p in vae.first_stage_model.named_parameters())
|
||||
assert vae.first_stage_model.decoder.scale1.dtype == torch.float32
|
||||
# Same assignment as Core DynamicVRAM load, not a Continuum mutation.
|
||||
vae.first_stage_model.decoder.scale1 = torch.nn.Parameter(vae.first_stage_model.decoder.scale1.detach().half())
|
||||
warm, warm_safe = _video_vae_signature(vae, required=True)
|
||||
assert warm_safe and cold == warm
|
||||
assert not torch.cuda.is_initialized()
|
||||
|
||||
|
||||
def test_video_vae_real_weight_change_is_still_detected():
|
||||
vae = vae_fixture()
|
||||
before, _ = _video_vae_signature(vae, required=True)
|
||||
with torch.no_grad():
|
||||
vae.first_stage_model.decoder.scale1.add_(0.25)
|
||||
after, _ = _video_vae_signature(vae, required=True)
|
||||
assert before != after
|
||||
|
||||
|
||||
def test_declared_precision_change_is_not_ignored():
|
||||
vae = vae_fixture()
|
||||
before, _ = _video_vae_signature(vae, required=True)
|
||||
vae.first_stage_model.decoder.scale1_comfy_model_dtype = torch.bfloat16
|
||||
after, _ = _video_vae_signature(vae, required=True)
|
||||
assert before != after
|
||||
|
||||
|
||||
def test_no_core_dtype_metadata_preserves_original_probe_contract():
|
||||
module = torch.nn.Linear(3, 2, bias=False)
|
||||
before, safe = _module_signature(module)
|
||||
assert safe and before['weight_probe'][0]['dtype'] == 'torch.float32'
|
||||
after, safe = _module_signature(copy.deepcopy(module).half())
|
||||
assert safe and before != after
|
||||
|
||||
|
||||
def test_set_identity_is_complete_order_independent_and_typed():
|
||||
keys = {f'layer.{i}.lora_A.weight' for i in range(500)}
|
||||
before = copy.deepcopy(keys)
|
||||
a, safe = _observe(keys)
|
||||
b, other_safe = _observe(set(reversed(sorted(keys))))
|
||||
assert safe and other_safe and a == b and keys == before
|
||||
assert len(a['items']) == 500
|
||||
changed, _ = _observe(keys | {'different.weight'})
|
||||
frozen, _ = _observe(frozenset(keys))
|
||||
assert a != changed and a != frozen
|
||||
assert _observe([1, 2])[0] != _observe([2, 1])[0]
|
||||
|
||||
|
||||
def test_adapter_weight_and_strength_changes_are_not_hidden_by_set_fix():
|
||||
adapter = SimpleNamespace(loaded_keys={'b', 'a'}, weights=[torch.arange(8.), 8.])
|
||||
before, safe = _observe([(1., adapter)])
|
||||
assert safe
|
||||
adapter.weights[0][0] += 1
|
||||
after, safe = _observe([(1., adapter)])
|
||||
assert safe and before != after
|
||||
assert after != _observe([(0.5, adapter)])[0]
|
||||
|
||||
|
||||
def test_lora_set_identity_matches_across_python_hash_seeds():
|
||||
root = str(Path(__file__).resolve().parents[1])
|
||||
code = f'''
|
||||
import sys, types, json
|
||||
p = types.ModuleType("ComfyUI_H3_Continuum_Join")
|
||||
p.__path__ = [{root!r}]
|
||||
sys.modules[p.__name__] = p
|
||||
from ComfyUI_H3_Continuum_Join.run_storage import _observe, _hash
|
||||
from types import SimpleNamespace
|
||||
import torch
|
||||
obj = SimpleNamespace(loaded_keys={{f"layer.{{i}}.lora_A.weight" for i in range(500)}}, weights=[torch.arange(8.), 8.])
|
||||
value, safe = _observe(obj)
|
||||
assert safe and not torch.cuda.is_initialized()
|
||||
print("RESULT:" + json.dumps({{"sha": _hash(value), "safe": safe}}))
|
||||
'''
|
||||
results = []
|
||||
for seed in ('1', '777'):
|
||||
env = dict(os.environ, PYTHONHASHSEED=seed)
|
||||
run = subprocess.run([sys.executable, '-B', '-c', code], env=env, capture_output=True, text=True, timeout=30, check=True)
|
||||
records = [line[7:] for line in run.stdout.splitlines() if line.startswith('RESULT:')]
|
||||
assert len(records) == 1, run.stdout
|
||||
results.append(json.loads(records[0]))
|
||||
assert results[0] == results[1]
|
||||
@@ -0,0 +1,50 @@
|
||||
"""Real on-disk provenance must not bypass a newly requested reroll."""
|
||||
import pytest
|
||||
import importlib.util
|
||||
from pathlib import Path
|
||||
|
||||
_spec = importlib.util.spec_from_file_location(
|
||||
"review_storage_fixtures", Path(__file__).with_name("test_v38_review_run_storage.py"))
|
||||
_fixtures = importlib.util.module_from_spec(_spec)
|
||||
_spec.loader.exec_module(_fixtures)
|
||||
_contract, _controller, _persist = _fixtures._contract, _fixtures._controller, _fixtures._persist
|
||||
|
||||
|
||||
@pytest.mark.parametrize("boundary", [1, 2, 3, 4, 5, 6])
|
||||
def test_new_reroll_only_reuses_chunks_before_boundary(tmp_path, boundary):
|
||||
old = _persist(tmp_path, _contract(chunks=6), prefix=6, review_unit=(6, 6),
|
||||
updated_utc="2026-09-07T00:00:00+00:00")
|
||||
requested = _contract(chunks=6, boundary=boundary, nonce=1)
|
||||
current = _controller(tmp_path, requested)
|
||||
entries, records = current._valid_provenance_prefix(
|
||||
old.manifest, current_contract=requested, enforce_sampling_contract=True)
|
||||
assert len(entries) == len(records) == boundary - 1
|
||||
assert len(old.manifest["chunks"]) == 6
|
||||
|
||||
|
||||
def test_same_nonce_interrupted_prefix_can_resume(tmp_path):
|
||||
contract = _contract(chunks=6, boundary=2, nonce=1)
|
||||
old = _persist(tmp_path, contract, prefix=3, review_unit=(3, 3),
|
||||
updated_utc="2026-09-07T00:00:00+00:00")
|
||||
current = _controller(tmp_path, contract)
|
||||
entries, records = current._valid_provenance_prefix(
|
||||
old.manifest, current_contract=contract, enforce_sampling_contract=True)
|
||||
assert len(entries) == len(records) == 3
|
||||
|
||||
|
||||
def test_completed_same_contract_still_reuses_all(tmp_path):
|
||||
contract = _contract(chunks=2)
|
||||
old = _persist(tmp_path, contract, prefix=2, review_unit=(2, 2),
|
||||
updated_utc="2026-09-07T00:00:00+00:00")
|
||||
current = _controller(tmp_path, contract)
|
||||
assert len(current._valid_provenance_prefix(
|
||||
old.manifest, current_contract=contract, enforce_sampling_contract=True)[0]) == 2
|
||||
|
||||
|
||||
def test_smart_retry_new_nonce_does_not_reuse_previous_take(tmp_path):
|
||||
old = _persist(tmp_path, _contract(chunks=3, boundary=2, nonce=1),
|
||||
prefix=2, review_unit=(2, 2), updated_utc="2026-09-07T00:00:00+00:00")
|
||||
contract = _contract(chunks=3, boundary=2, nonce=2)
|
||||
current = _controller(tmp_path, contract)
|
||||
assert len(current._valid_provenance_prefix(
|
||||
old.manifest, current_contract=contract, enforce_sampling_contract=True)[0]) == 1
|
||||
@@ -0,0 +1,20 @@
|
||||
"""Exercise real frontend lifecycle hooks with recreated workflow nodes."""
|
||||
|
||||
|
||||
def test_review_workflow_rehydration(review_queue_results):
|
||||
cases = (
|
||||
"H3ContinuumSamplerV38: recreated tab waits for saved identity and upstream links",
|
||||
"H3ContinuumSamplerV39: recreated tab waits for saved identity and upstream links",
|
||||
"ten rapid recreated tabs reject every obsolete history response",
|
||||
"API graph restoration without a before hook still reloads history",
|
||||
"manually added sampler loads history after deferred setup",
|
||||
"real edits while restored history is pending retain the settings guard",
|
||||
"same revision graph refresh cannot erase an existing real edit",
|
||||
"graph epoch rejects old results even if the same node remains attached",
|
||||
"removed sampler cancels deferred setup without fetching or mutating it",
|
||||
"initial restored history read preserves saved Take selection fields",
|
||||
"restored missing or failed history reports accurately and can retry",
|
||||
"failed graph load releases hydration gate for subsequent manual nodes",
|
||||
)
|
||||
for case in cases:
|
||||
assert review_queue_results[case]["pass"]
|
||||
+403
@@ -0,0 +1,403 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
from types import SimpleNamespace
|
||||
|
||||
import pytest
|
||||
|
||||
import ComfyUI_H3_Continuum_Join.run_storage as storage_runtime
|
||||
from ComfyUI_H3_Continuum_Join.run_storage import RunStorageController, RunStorageError
|
||||
from ComfyUI_H3_Continuum_Join.v2 import sequence
|
||||
from ComfyUI_H3_Continuum_Join.v2.session import entry_to_state
|
||||
from ComfyUI_H3_Continuum_Join.v3.review_control import (
|
||||
GENERATION_MODE_REVIEW,
|
||||
REVIEW_ACTION_CONTINUE,
|
||||
REVISION_STATUS_REVIEW_READY,
|
||||
)
|
||||
|
||||
from . import test_v38_review_execution_cap as cap
|
||||
from . import test_v38_review_run_storage as storage_cases
|
||||
|
||||
|
||||
def _run_with_sources(
|
||||
monkeypatch,
|
||||
runtime,
|
||||
*,
|
||||
chunks: int,
|
||||
session=None,
|
||||
initial_state=None,
|
||||
reroll_from_chunk: int = 0,
|
||||
continuity: str | None = None,
|
||||
limit: int | None = None,
|
||||
):
|
||||
"""Exercise the unchanged public run_sequence contract with extra sources."""
|
||||
|
||||
original = cap.sequence.run_sequence
|
||||
|
||||
def forwarded(**kwargs):
|
||||
kwargs["initial_state"] = initial_state
|
||||
kwargs["reroll_from_chunk"] = reroll_from_chunk
|
||||
if continuity is not None:
|
||||
kwargs["continuity"] = continuity
|
||||
return original(**kwargs)
|
||||
|
||||
with monkeypatch.context() as local:
|
||||
local.setattr(cap.sequence, "run_sequence", forwarded)
|
||||
return cap._run_sequence(
|
||||
runtime,
|
||||
chunks=chunks,
|
||||
session=session,
|
||||
limit=limit,
|
||||
)
|
||||
|
||||
|
||||
def _state_from_session(session: dict, *, clip_index: int = 9) -> dict:
|
||||
state = dict(entry_to_state(session["chunks"][-1]))
|
||||
state["clip_index"] = clip_index
|
||||
return state
|
||||
|
||||
|
||||
def test_r0_storage_off_plain_full_run_uses_no_review_policy_or_filesystem(
|
||||
monkeypatch, tmp_path
|
||||
):
|
||||
runtime = cap._install_fake_runtime(monkeypatch)
|
||||
|
||||
def unexpected(*args, **kwargs):
|
||||
pytest.fail("Storage OFF Full Run must not resolve Run Storage Review policy")
|
||||
|
||||
monkeypatch.setattr(storage_runtime, "resolve_review_execution", unexpected)
|
||||
entries, last_state, session, _ = cap._run_sequence(runtime, chunks=3)
|
||||
|
||||
assert len(entries) == len(session["chunks"]) == len(runtime.samples) == 3
|
||||
assert last_state["clip_index"] == 3
|
||||
assert list(tmp_path.rglob("*")) == []
|
||||
|
||||
|
||||
def test_r0_storage_off_compatible_session_restores_prefix(monkeypatch):
|
||||
runtime = cap._install_fake_runtime(monkeypatch)
|
||||
_, _, saved, _ = cap._run_sequence(runtime, chunks=1)
|
||||
runtime.samples.clear()
|
||||
|
||||
entries, last_state, session, _ = cap._run_sequence(
|
||||
runtime,
|
||||
chunks=2,
|
||||
session=saved,
|
||||
)
|
||||
|
||||
assert len(entries) == len(session["chunks"]) == 2
|
||||
assert entries[0]["reused"] is True
|
||||
assert len(runtime.samples) == 1
|
||||
assert last_state["clip_index"] == 2
|
||||
|
||||
|
||||
def test_r0_storage_off_session_regenerate_from_preserves_only_prior_prefix(monkeypatch):
|
||||
runtime = cap._install_fake_runtime(monkeypatch)
|
||||
_, _, saved, _ = cap._run_sequence(runtime, chunks=3)
|
||||
runtime.samples.clear()
|
||||
|
||||
entries, last_state, session, _ = _run_with_sources(
|
||||
monkeypatch,
|
||||
runtime,
|
||||
chunks=3,
|
||||
session=saved,
|
||||
reroll_from_chunk=2,
|
||||
)
|
||||
|
||||
assert len(entries) == len(session["chunks"]) == 3
|
||||
assert [entry["reused"] for entry in entries] == [True, False, False]
|
||||
assert len(runtime.samples) == 2
|
||||
assert last_state["clip_index"] == 3
|
||||
|
||||
|
||||
def test_r0_storage_off_incompatible_session_is_advisory_and_starts_fresh(monkeypatch):
|
||||
runtime = cap._install_fake_runtime(monkeypatch)
|
||||
_, _, saved, _ = cap._run_sequence(runtime, chunks=1)
|
||||
incompatible = dict(saved)
|
||||
incompatible["width"] = 128
|
||||
runtime.samples.clear()
|
||||
|
||||
entries, last_state, session, report = cap._run_sequence(
|
||||
runtime,
|
||||
chunks=1,
|
||||
session=incompatible,
|
||||
)
|
||||
|
||||
assert len(entries) == len(session["chunks"]) == len(runtime.samples) == 1
|
||||
assert entries[0]["reused"] is False
|
||||
assert last_state["clip_index"] == 1
|
||||
assert "saved session was ignored; generated a fresh run" in report
|
||||
|
||||
|
||||
def test_r0_storage_off_invalid_session_suppresses_valid_state_without_fallback(
|
||||
monkeypatch,
|
||||
):
|
||||
runtime = cap._install_fake_runtime(monkeypatch)
|
||||
_, _, source, _ = cap._run_sequence(runtime, chunks=1)
|
||||
state = _state_from_session(source)
|
||||
runtime.samples.clear()
|
||||
|
||||
entries, last_state, session, report = _run_with_sources(
|
||||
monkeypatch,
|
||||
runtime,
|
||||
chunks=1,
|
||||
session={"magic": "not-a-session"},
|
||||
initial_state=state,
|
||||
)
|
||||
|
||||
# Current V3.8 behavior is advisory, not an exception: the invalid Session
|
||||
# is rejected, the simultaneously supplied State remains suppressed, and a
|
||||
# fresh Chunk 1 is generated. R0 records this fact without changing it.
|
||||
assert len(entries) == len(session["chunks"]) == len(runtime.samples) == 1
|
||||
assert last_state["clip_index"] == 1
|
||||
assert entries[0]["plan"]["continuation"] is False
|
||||
assert "saved session was ignored; generated a fresh run" in report
|
||||
|
||||
|
||||
def test_r0_storage_off_compatible_session_suppresses_initial_state(monkeypatch, caplog):
|
||||
runtime = cap._install_fake_runtime(monkeypatch)
|
||||
_, _, saved, _ = cap._run_sequence(runtime, chunks=1)
|
||||
state = _state_from_session(saved)
|
||||
runtime.samples.clear()
|
||||
|
||||
entries, last_state, _, _ = _run_with_sources(
|
||||
monkeypatch,
|
||||
runtime,
|
||||
chunks=2,
|
||||
session=saved,
|
||||
initial_state=state,
|
||||
)
|
||||
|
||||
assert len(entries) == 2
|
||||
assert entries[0]["reused"] is True
|
||||
assert len(runtime.samples) == 1
|
||||
assert last_state["clip_index"] == 2
|
||||
assert "using the session and ignoring initial_state" in caplog.text
|
||||
|
||||
|
||||
def test_r0_storage_off_initial_state_continues_without_session(monkeypatch):
|
||||
runtime = cap._install_fake_runtime(monkeypatch)
|
||||
_, _, source, _ = cap._run_sequence(runtime, chunks=1)
|
||||
state = _state_from_session(source)
|
||||
runtime.samples.clear()
|
||||
|
||||
entries, last_state, session, _ = _run_with_sources(
|
||||
monkeypatch,
|
||||
runtime,
|
||||
chunks=1,
|
||||
initial_state=state,
|
||||
)
|
||||
|
||||
assert len(entries) == len(session["chunks"]) == len(runtime.samples) == 1
|
||||
assert entries[0]["plan"]["continuation"] is True
|
||||
assert entries[0]["plan"]["clip_index"] == 10
|
||||
assert last_state["clip_index"] == 10
|
||||
|
||||
|
||||
def test_r0_storage_off_initial_state_rejects_invalid_regenerate_from(monkeypatch):
|
||||
runtime = cap._install_fake_runtime(monkeypatch)
|
||||
_, _, source, _ = cap._run_sequence(runtime, chunks=1)
|
||||
state = _state_from_session(source)
|
||||
|
||||
with pytest.raises(
|
||||
sequence.SequenceRuntimeError,
|
||||
match="with initial_state, reroll_from_chunk can only be 0 or 1",
|
||||
):
|
||||
_run_with_sources(
|
||||
monkeypatch,
|
||||
runtime,
|
||||
chunks=3,
|
||||
initial_state=state,
|
||||
reroll_from_chunk=2,
|
||||
)
|
||||
|
||||
|
||||
def test_r0_run_storage_on_rejects_explicit_session_before_filesystem_io(
|
||||
monkeypatch, tmp_path
|
||||
):
|
||||
runtime = cap._install_fake_runtime(monkeypatch)
|
||||
_, _, saved, _ = cap._run_sequence(runtime, chunks=1)
|
||||
monkeypatch.setattr(storage_runtime, "_output_root", lambda: tmp_path)
|
||||
controller = RunStorageController("r0-explicit-session")
|
||||
monkeypatch.setattr(storage_runtime, "get_active_run_storage", lambda: controller)
|
||||
|
||||
with pytest.raises(
|
||||
RunStorageError,
|
||||
match="Run Storage cannot be combined with an explicit Session",
|
||||
):
|
||||
cap._run_sequence(runtime, chunks=2, session=saved)
|
||||
|
||||
assert list(tmp_path.rglob("*")) == []
|
||||
|
||||
|
||||
def test_r0_run_storage_saved_prefix_precedes_initial_state(monkeypatch):
|
||||
runtime = cap._install_fake_runtime(monkeypatch)
|
||||
_, _, saved, _ = cap._run_sequence(runtime, chunks=1)
|
||||
state = _state_from_session(saved)
|
||||
runtime.samples.clear()
|
||||
storage = cap._CommitRecorder(runtime.timeline)
|
||||
storage.prepare = lambda **kwargs: saved
|
||||
monkeypatch.setattr(storage_runtime, "get_active_run_storage", lambda: storage)
|
||||
|
||||
entries, last_state, _, _ = _run_with_sources(
|
||||
monkeypatch,
|
||||
runtime,
|
||||
chunks=2,
|
||||
initial_state=state,
|
||||
)
|
||||
|
||||
assert len(entries) == 2
|
||||
assert entries[0]["reused"] is True
|
||||
assert len(runtime.samples) == 1
|
||||
assert last_state["clip_index"] == 2
|
||||
|
||||
|
||||
def test_r0_run_storage_without_prefix_uses_initial_state(monkeypatch):
|
||||
runtime = cap._install_fake_runtime(monkeypatch)
|
||||
_, _, source, _ = cap._run_sequence(runtime, chunks=1)
|
||||
state = _state_from_session(source)
|
||||
runtime.samples.clear()
|
||||
storage = cap._CommitRecorder(runtime.timeline)
|
||||
monkeypatch.setattr(storage_runtime, "get_active_run_storage", lambda: storage)
|
||||
|
||||
entries, last_state, _, _ = _run_with_sources(
|
||||
monkeypatch,
|
||||
runtime,
|
||||
chunks=1,
|
||||
initial_state=state,
|
||||
)
|
||||
|
||||
assert len(entries) == len(runtime.samples) == 1
|
||||
assert entries[0]["plan"]["continuation"] is True
|
||||
assert last_state["clip_index"] == 10
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("continuity", "expected_context"),
|
||||
(("Balanced — 22 frames", 22), ("Strong — 39 frames (Experimental)", 39)),
|
||||
)
|
||||
def test_r0_continuity_modes_keep_their_context_contract(
|
||||
monkeypatch, continuity, expected_context
|
||||
):
|
||||
runtime = cap._install_fake_runtime(monkeypatch)
|
||||
entries, _, _, _ = _run_with_sources(
|
||||
monkeypatch,
|
||||
runtime,
|
||||
chunks=2,
|
||||
continuity=continuity,
|
||||
)
|
||||
|
||||
assert entries[0]["plan"]["context_frames"] == 5
|
||||
assert entries[1]["plan"]["context_frames"] == expected_context
|
||||
assert entries[1]["plan"]["state_capacity_frames"] == 39
|
||||
|
||||
|
||||
def _failure_controller(tmp_path, contract: dict) -> RunStorageController:
|
||||
controller = storage_cases._controller(tmp_path, contract)
|
||||
controller.lock = storage_runtime._RunLock(controller.run_root / ".lock")
|
||||
controller.revision_root.mkdir(parents=True, exist_ok=True)
|
||||
controller._write_manifest()
|
||||
return controller
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("stage", "committed"),
|
||||
(
|
||||
("before sampling", 0),
|
||||
("after sampling before chunk commit", 0),
|
||||
("after manifest update", 1),
|
||||
("before output projection", 1),
|
||||
("during output projection", 1),
|
||||
("before storage finalize", 1),
|
||||
),
|
||||
)
|
||||
def test_r0_failure_baseline_marks_revision_interrupted(
|
||||
tmp_path, stage, committed
|
||||
):
|
||||
contract = storage_cases._contract(chunks=1)
|
||||
controller = _failure_controller(tmp_path, contract)
|
||||
|
||||
with pytest.raises(RuntimeError, match=stage):
|
||||
with controller:
|
||||
if committed:
|
||||
controller.commit_chunk(storage_cases._entry(0, contract), position=0)
|
||||
raise RuntimeError(stage)
|
||||
|
||||
manifest = json.loads(controller._manifest_path().read_text(encoding="utf-8"))
|
||||
assert manifest["status"] == "interrupted"
|
||||
assert len(manifest["chunks"]) == committed
|
||||
assert stage in manifest["last_error"]
|
||||
|
||||
|
||||
def test_r5_terminal_entry_cannot_expose_an_interrupted_half_group(
|
||||
tmp_path,
|
||||
):
|
||||
contract = storage_cases._contract(chunks=2, terminal=True)
|
||||
controller = _failure_controller(tmp_path, contract)
|
||||
|
||||
with pytest.raises(RunStorageError, match="physical group is incomplete"):
|
||||
with controller:
|
||||
controller.commit_chunk(storage_cases._entry(0, contract), position=0)
|
||||
|
||||
manifest = json.loads(controller._manifest_path().read_text(encoding="utf-8"))
|
||||
assert manifest["status"] == "interrupted"
|
||||
assert manifest["chunks"] == []
|
||||
project = json.loads((controller.run_root / "project.json").read_text(encoding="utf-8"))
|
||||
assert project["canonical_storage_revision_id"] is None
|
||||
|
||||
|
||||
def test_r0_failure_before_manifest_update_is_recovered_by_exception_handler(
|
||||
monkeypatch, tmp_path
|
||||
):
|
||||
contract = storage_cases._contract(chunks=1)
|
||||
controller = _failure_controller(tmp_path, contract)
|
||||
original = controller._write_manifest
|
||||
calls = 0
|
||||
|
||||
def fail_once():
|
||||
nonlocal calls
|
||||
calls += 1
|
||||
if calls == 1:
|
||||
raise RuntimeError("before manifest update")
|
||||
return original()
|
||||
|
||||
monkeypatch.setattr(controller, "_write_manifest", fail_once)
|
||||
with pytest.raises(RuntimeError, match="before manifest update"):
|
||||
with controller:
|
||||
controller.commit_chunk(storage_cases._entry(0, contract), position=0)
|
||||
|
||||
manifest = json.loads(controller._manifest_path().read_text(encoding="utf-8"))
|
||||
assert manifest["status"] == "interrupted"
|
||||
assert len(manifest["chunks"]) == 1
|
||||
assert calls == 2
|
||||
|
||||
|
||||
def test_r0_failure_before_canonical_update_keeps_current_recovery_semantics(
|
||||
monkeypatch, tmp_path
|
||||
):
|
||||
contract = storage_cases._contract(chunks=1)
|
||||
controller = _failure_controller(tmp_path, contract)
|
||||
entry = storage_cases._entry(0, contract)
|
||||
original = controller._write_project
|
||||
calls = 0
|
||||
|
||||
def fail_once(*, set_canonical=False):
|
||||
nonlocal calls
|
||||
calls += 1
|
||||
if calls == 1:
|
||||
raise RuntimeError("before canonical pointer update")
|
||||
return original(set_canonical=set_canonical)
|
||||
|
||||
monkeypatch.setattr(controller, "_write_project", fail_once)
|
||||
with pytest.raises(RuntimeError, match="before canonical pointer update"):
|
||||
with controller:
|
||||
controller.commit_chunk(entry, position=0)
|
||||
controller.finalize(
|
||||
session={"session_id": "r0", "chunks": [entry]},
|
||||
report="r0 failure baseline",
|
||||
)
|
||||
|
||||
manifest = json.loads(controller._manifest_path().read_text(encoding="utf-8"))
|
||||
project = json.loads((controller.run_root / "project.json").read_text(encoding="utf-8"))
|
||||
assert manifest["status"] == "interrupted"
|
||||
assert calls == 2
|
||||
assert project["canonical_storage_revision_id"] is None
|
||||
+214
@@ -0,0 +1,214 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import FrozenInstanceError
|
||||
|
||||
import pytest
|
||||
|
||||
import ComfyUI_H3_Continuum_Join.run_storage as storage_runtime
|
||||
from ComfyUI_H3_Continuum_Join.run_storage import (
|
||||
EmptyValidatedPrefix,
|
||||
RunStorageController,
|
||||
ValidatedPrefix,
|
||||
)
|
||||
from ComfyUI_H3_Continuum_Join.v3.planning_types import PrefixFacts
|
||||
from ComfyUI_H3_Continuum_Join.v3.review_control import (
|
||||
GENERATION_MODE_REVIEW,
|
||||
REVIEW_ACTION_CONTINUE,
|
||||
)
|
||||
|
||||
from . import test_v38_review_run_storage as cases
|
||||
|
||||
|
||||
def _review_controller(tmp_path, contract: dict) -> RunStorageController:
|
||||
controller = RunStorageController("phase-d-review")
|
||||
controller.run_root = tmp_path / "run"
|
||||
controller.revisions_root = controller.run_root / "revisions"
|
||||
controller.prompts = [
|
||||
f"prompt {index + 1}" for index in range(contract["chunk_count"])
|
||||
]
|
||||
controller.configure_review(
|
||||
generation_mode=GENERATION_MODE_REVIEW,
|
||||
review_action=REVIEW_ACTION_CONTINUE,
|
||||
)
|
||||
return controller
|
||||
|
||||
|
||||
def test_r2_raw_prefix_is_loaded_before_the_single_review_decision(
|
||||
monkeypatch, tmp_path
|
||||
):
|
||||
contract = cases._contract(chunks=3)
|
||||
cases._persist(
|
||||
tmp_path,
|
||||
contract,
|
||||
prefix=1,
|
||||
review_unit=(1, 1),
|
||||
updated_utc="2026-09-14T00:00:00+00:00",
|
||||
)
|
||||
controller = _review_controller(tmp_path, contract)
|
||||
events = []
|
||||
original_load = controller._load_entry
|
||||
original_resolve = storage_runtime.resolve_review_execution
|
||||
|
||||
def load(*args, **kwargs):
|
||||
events.append("raw_loaded")
|
||||
return original_load(*args, **kwargs)
|
||||
|
||||
def resolve(**kwargs):
|
||||
events.append("review_decision")
|
||||
return original_resolve(**kwargs)
|
||||
|
||||
monkeypatch.setattr(controller, "_load_entry", load)
|
||||
monkeypatch.setattr(storage_runtime, "resolve_review_execution", resolve)
|
||||
|
||||
prefix = controller._load_validated_review_prefix(contract, resume_safe=True)
|
||||
assert isinstance(prefix, ValidatedPrefix)
|
||||
assert events == ["raw_loaded"]
|
||||
controller._resolve_review_contract(
|
||||
contract,
|
||||
requested_nonce=0,
|
||||
resume_safe=True,
|
||||
validated_prefix=prefix,
|
||||
)
|
||||
|
||||
assert events == ["raw_loaded", "review_decision"]
|
||||
assert controller.review_runtime_metrics == {
|
||||
"review_decision_created": 1,
|
||||
"review_reconcile": 0,
|
||||
}
|
||||
assert not hasattr(controller, "_reconcile_review_execution_with_reused_prefix")
|
||||
|
||||
|
||||
def test_r2_validated_prefix_is_structurally_immutable_and_defensive(tmp_path):
|
||||
contract = cases._contract(chunks=3)
|
||||
cases._persist(
|
||||
tmp_path,
|
||||
contract,
|
||||
prefix=1,
|
||||
review_unit=(1, 1),
|
||||
updated_utc="2026-09-14T00:00:00+00:00",
|
||||
)
|
||||
controller = _review_controller(tmp_path, contract)
|
||||
candidate = controller.find_latest_review_head(contract)
|
||||
prefix = controller._freeze_validated_prefix(candidate, contract=contract)
|
||||
|
||||
assert isinstance(prefix.entries, tuple)
|
||||
assert isinstance(prefix.records, tuple)
|
||||
assert prefix.physical_group_boundaries == ((1, 1),)
|
||||
with pytest.raises(FrozenInstanceError):
|
||||
prefix.status = "changed"
|
||||
with pytest.raises(TypeError):
|
||||
prefix.manifest["status"] = "changed"
|
||||
candidate["manifest"]["status"] = "changed-after-freeze"
|
||||
assert prefix.manifest["status"] != "changed-after-freeze"
|
||||
|
||||
facts = prefix.to_planning_facts()
|
||||
assert isinstance(facts, PrefixFacts)
|
||||
assert facts.accepted_chunks == 1
|
||||
assert facts.configured_chunks == 3
|
||||
assert facts.review_unit.start == facts.review_unit.end == 1
|
||||
|
||||
|
||||
def test_r2_empty_validated_prefix_only_means_no_run_storage_prefix():
|
||||
prefix = EmptyValidatedPrefix(configured_chunks=3)
|
||||
facts = prefix.to_planning_facts()
|
||||
|
||||
assert prefix.entries == prefix.records == ()
|
||||
assert facts == PrefixFacts(
|
||||
accepted_chunks=0,
|
||||
configured_chunks=3,
|
||||
revision_id=None,
|
||||
status=None,
|
||||
review_unit=None,
|
||||
effective_nonce=0,
|
||||
branch_regenerate_from=0,
|
||||
physical_group_boundaries=(),
|
||||
)
|
||||
|
||||
|
||||
def test_r2_repository_validation_and_finalize_do_not_create_review_decisions(
|
||||
monkeypatch, tmp_path
|
||||
):
|
||||
contract = cases._contract(chunks=3)
|
||||
|
||||
def unexpected(**kwargs):
|
||||
pytest.fail("metadata validation must not create a Review Decision")
|
||||
|
||||
monkeypatch.setattr(storage_runtime, "resolve_review_execution", unexpected)
|
||||
cases._persist(
|
||||
tmp_path,
|
||||
contract,
|
||||
prefix=1,
|
||||
review_unit=(1, 1),
|
||||
updated_utc="2026-09-14T00:00:00+00:00",
|
||||
)
|
||||
controller = _review_controller(tmp_path, contract)
|
||||
prefix = controller._load_validated_review_prefix(contract, resume_safe=True)
|
||||
|
||||
assert isinstance(prefix, ValidatedPrefix)
|
||||
assert controller.review_runtime_metrics["review_decision_created"] == 0
|
||||
|
||||
|
||||
def test_r2_a_second_review_decision_is_rejected(tmp_path):
|
||||
contract = cases._contract(chunks=3)
|
||||
controller = _review_controller(tmp_path, contract)
|
||||
prefix = controller._load_validated_review_prefix(contract, resume_safe=True)
|
||||
controller._resolve_review_contract(
|
||||
contract,
|
||||
requested_nonce=0,
|
||||
resume_safe=True,
|
||||
validated_prefix=prefix,
|
||||
)
|
||||
|
||||
with pytest.raises(storage_runtime.RunStorageError, match="already created"):
|
||||
controller._resolve_review_contract(
|
||||
contract,
|
||||
requested_nonce=0,
|
||||
resume_safe=True,
|
||||
validated_prefix=prefix,
|
||||
)
|
||||
|
||||
|
||||
def test_r2_fixed_prefix_cannot_be_replaced_before_decision(tmp_path):
|
||||
contract = cases._contract(chunks=3)
|
||||
controller = _review_controller(tmp_path, contract)
|
||||
fixed = controller._load_validated_review_prefix(contract, resume_safe=True)
|
||||
replacement = EmptyValidatedPrefix(configured_chunks=3)
|
||||
|
||||
assert replacement is not fixed
|
||||
with pytest.raises(storage_runtime.RunStorageError, match="cannot replace"):
|
||||
controller._resolve_review_contract(
|
||||
contract,
|
||||
requested_nonce=0,
|
||||
resume_safe=True,
|
||||
validated_prefix=replacement,
|
||||
)
|
||||
assert controller.review_runtime_metrics == {
|
||||
"review_decision_created": 0,
|
||||
"review_reconcile": 0,
|
||||
}
|
||||
|
||||
|
||||
def test_r2_take_policy_also_creates_exactly_one_decision(tmp_path):
|
||||
contract = cases._contract(chunks=3, boundary=2, nonce=1)
|
||||
saved = cases._persist(
|
||||
tmp_path,
|
||||
contract,
|
||||
prefix=2,
|
||||
review_unit=(2, 2),
|
||||
updated_utc="2026-09-14T00:00:01+00:00",
|
||||
)
|
||||
revision = cases._take(cases._project(saved), group=2, nonce=1)
|
||||
|
||||
controller, _, _, _ = cases._resolve(
|
||||
tmp_path,
|
||||
cases._contract(chunks=3),
|
||||
take_action=storage_runtime.TAKE_ACTION_CONTINUE,
|
||||
take_group=2,
|
||||
take_revision_id=revision["revision_id"],
|
||||
)
|
||||
|
||||
assert isinstance(controller.validated_prefix, ValidatedPrefix)
|
||||
assert controller.review_runtime_metrics == {
|
||||
"review_decision_created": 1,
|
||||
"review_reconcile": 0,
|
||||
}
|
||||
@@ -0,0 +1,220 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import ast
|
||||
import inspect
|
||||
from pathlib import Path
|
||||
|
||||
import ComfyUI_H3_Continuum_Join.run_storage as storage_runtime
|
||||
from ComfyUI_H3_Continuum_Join.run_storage import EmptyValidatedPrefix
|
||||
from ComfyUI_H3_Continuum_Join.v3.runtime_coordinator import (
|
||||
project_selected_continuation_source,
|
||||
)
|
||||
from ComfyUI_H3_Continuum_Join.v3.execution_planner import (
|
||||
PROJECTION_CURRENT_REVIEW_UNIT,
|
||||
PROJECTION_FULL_ACCEPTED_PREFIX,
|
||||
build_execution_plan,
|
||||
)
|
||||
from ComfyUI_H3_Continuum_Join.v3.planning_types import (
|
||||
ContinuationSourceFacts,
|
||||
PrefixFacts,
|
||||
)
|
||||
from ComfyUI_H3_Continuum_Join.v3.review_control import (
|
||||
GENERATION_MODE_REVIEW,
|
||||
REVIEW_ACTION_CONTINUE,
|
||||
REVISION_STATUS_COMPLETE,
|
||||
REVISION_STATUS_REVIEW_READY,
|
||||
RUN_STORAGE_SAVE_AUTO_RESUME,
|
||||
ReviewUnit,
|
||||
resolve_review_execution,
|
||||
)
|
||||
|
||||
from . import test_v38_review_execution_cap as cap
|
||||
|
||||
|
||||
def _source(
|
||||
kind: str,
|
||||
*,
|
||||
accepted: int,
|
||||
reroll: int,
|
||||
boundaries: tuple[tuple[int, int], ...],
|
||||
) -> ContinuationSourceFacts:
|
||||
return project_selected_continuation_source(
|
||||
kind=kind,
|
||||
selected_source={
|
||||
"accepted_chunks": accepted,
|
||||
"reroll_from_chunk": reroll,
|
||||
"physical_group_boundaries": boundaries,
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
def _review_continue(*, chunks: int, prefix: int, terminal: bool):
|
||||
return resolve_review_execution(
|
||||
generation_mode=GENERATION_MODE_REVIEW,
|
||||
review_action=REVIEW_ACTION_CONTINUE,
|
||||
configured_chunks=chunks,
|
||||
validated_prefix_count=prefix,
|
||||
terminal_merge_enabled=terminal,
|
||||
terminal_pair_start=(chunks - 1 if terminal else None),
|
||||
manual_regenerate_from=0,
|
||||
run_storage_mode=RUN_STORAGE_SAVE_AUTO_RESUME,
|
||||
latest_review_unit=(
|
||||
None
|
||||
if prefix == 0
|
||||
else ReviewUnit(start=prefix, end=prefix, physical_group=prefix)
|
||||
),
|
||||
latest_revision_status=(
|
||||
None if prefix == 0 else REVISION_STATUS_REVIEW_READY
|
||||
),
|
||||
latest_effective_nonce=0,
|
||||
)
|
||||
|
||||
|
||||
def test_r3_projects_each_already_selected_continuation_source_kind():
|
||||
run_storage = _source(
|
||||
"run_storage",
|
||||
accepted=2,
|
||||
reroll=0,
|
||||
boundaries=((1, 1), (2, 2)),
|
||||
)
|
||||
explicit_session = _source(
|
||||
"explicit_session",
|
||||
accepted=1,
|
||||
reroll=2,
|
||||
boundaries=((1, 1),),
|
||||
)
|
||||
initial_state = _source(
|
||||
"initial_state",
|
||||
accepted=0,
|
||||
reroll=1,
|
||||
boundaries=(),
|
||||
)
|
||||
none = project_selected_continuation_source(
|
||||
kind="none",
|
||||
selected_source=None,
|
||||
)
|
||||
|
||||
assert run_storage == ContinuationSourceFacts(
|
||||
"run_storage", 2, 0, ((1, 1), (2, 2))
|
||||
)
|
||||
assert explicit_session == ContinuationSourceFacts(
|
||||
"explicit_session", 1, 2, ((1, 1),)
|
||||
)
|
||||
assert initial_state == ContinuationSourceFacts(
|
||||
"initial_state", 0, 1, ()
|
||||
)
|
||||
assert none == ContinuationSourceFacts("none", 0, 0, ())
|
||||
|
||||
|
||||
def test_r3_projection_boundary_has_no_selection_policy_calls():
|
||||
tree = ast.parse(inspect.getsource(project_selected_continuation_source))
|
||||
called_names = {
|
||||
node.func.id
|
||||
for node in ast.walk(tree)
|
||||
if isinstance(node, ast.Call) and isinstance(node.func, ast.Name)
|
||||
}
|
||||
assert called_names.isdisjoint(
|
||||
{
|
||||
"find_latest_review_head",
|
||||
"resolve_review_execution",
|
||||
"resolve_take_execution",
|
||||
"validate_session",
|
||||
"validate_state",
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
def test_r3_full_plan_owns_all_pending_physical_groups():
|
||||
plan = build_execution_plan(
|
||||
continuation_source_facts=ContinuationSourceFacts("none", 0, 0, ()),
|
||||
configured_chunks=3,
|
||||
terminal_merge_enabled=False,
|
||||
max_new_physical_groups=None,
|
||||
review_execution=None,
|
||||
)
|
||||
|
||||
assert [group.logical_chunks for group in plan.groups_to_generate] == [
|
||||
(1,),
|
||||
(2,),
|
||||
(3,),
|
||||
]
|
||||
assert plan.expected_status == REVISION_STATUS_COMPLETE
|
||||
assert plan.expected_review_unit is None
|
||||
assert plan.projection.kind == PROJECTION_FULL_ACCEPTED_PREFIX
|
||||
|
||||
|
||||
def test_r3_review_plan_generates_one_group_and_projects_only_that_unit():
|
||||
execution = _review_continue(chunks=3, prefix=1, terminal=False)
|
||||
plan = build_execution_plan(
|
||||
continuation_source_facts=ContinuationSourceFacts(
|
||||
"run_storage", 1, 0, ((1, 1),)
|
||||
),
|
||||
configured_chunks=3,
|
||||
terminal_merge_enabled=False,
|
||||
max_new_physical_groups=execution.max_new_physical_groups,
|
||||
review_execution=execution,
|
||||
retained_review_unit=ReviewUnit(1, 1, 1),
|
||||
)
|
||||
|
||||
assert [group.logical_chunks for group in plan.groups_to_generate] == [(2,)]
|
||||
assert plan.expected_status == REVISION_STATUS_REVIEW_READY
|
||||
assert plan.expected_review_unit == ReviewUnit(2, 2, 2)
|
||||
assert plan.projection.kind == PROJECTION_CURRENT_REVIEW_UNIT
|
||||
assert (plan.projection.start_chunk, plan.projection.end_chunk) == (2, 2)
|
||||
|
||||
|
||||
def test_r3_terminal_group_is_atomic_and_completion_projects_full_prefix():
|
||||
execution = _review_continue(chunks=3, prefix=1, terminal=True)
|
||||
plan = build_execution_plan(
|
||||
continuation_source_facts=ContinuationSourceFacts(
|
||||
"run_storage", 1, 0, ((1, 1),)
|
||||
),
|
||||
configured_chunks=3,
|
||||
terminal_merge_enabled=True,
|
||||
max_new_physical_groups=execution.max_new_physical_groups,
|
||||
review_execution=execution,
|
||||
retained_review_unit=ReviewUnit(1, 1, 1),
|
||||
)
|
||||
|
||||
assert len(plan.groups_to_generate) == 1
|
||||
assert plan.groups_to_generate[0].logical_chunks == (2, 3)
|
||||
assert plan.groups_to_generate[0].terminal_atomic is True
|
||||
assert plan.expected_status == REVISION_STATUS_COMPLETE
|
||||
assert plan.expected_review_unit == ReviewUnit(2, 3, 2)
|
||||
assert plan.projection.kind == PROJECTION_FULL_ACCEPTED_PREFIX
|
||||
|
||||
|
||||
def test_r3_planner_api_accepts_only_one_selected_source():
|
||||
parameters = inspect.signature(build_execution_plan).parameters
|
||||
assert "continuation_source_facts" in parameters
|
||||
assert "storage_prefix_facts" not in parameters
|
||||
assert "explicit_session_facts" not in parameters
|
||||
assert "initial_state_facts" not in parameters
|
||||
|
||||
|
||||
def test_r3_planner_module_imports_no_torch_or_comfyui():
|
||||
module_path = Path(inspect.getsourcefile(build_execution_plan))
|
||||
tree = ast.parse(module_path.read_text(encoding="utf-8"))
|
||||
imported = []
|
||||
for node in ast.walk(tree):
|
||||
if isinstance(node, ast.Import):
|
||||
imported.extend(alias.name for alias in node.names)
|
||||
elif isinstance(node, ast.ImportFrom) and node.module:
|
||||
imported.append(node.module)
|
||||
assert not any(name == "torch" or name.startswith("torch.") for name in imported)
|
||||
assert not any("comfy" in name.lower() for name in imported)
|
||||
|
||||
|
||||
def test_r3_validated_prefix_projection_contract_remains_prefix_facts():
|
||||
facts = EmptyValidatedPrefix(configured_chunks=3).to_planning_facts()
|
||||
assert isinstance(facts, PrefixFacts)
|
||||
assert not isinstance(facts, ContinuationSourceFacts)
|
||||
|
||||
|
||||
def test_r3_storage_off_runtime_consumes_the_pure_group_plan(monkeypatch):
|
||||
runtime = cap._install_fake_runtime(monkeypatch)
|
||||
entries, _, session, _ = cap._run_sequence(runtime, chunks=3)
|
||||
|
||||
assert len(entries) == len(session["chunks"]) == 3
|
||||
assert len(runtime.samples) == 3
|
||||
assert storage_runtime.get_active_run_storage() is None
|
||||
@@ -0,0 +1,209 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import ast
|
||||
import inspect
|
||||
|
||||
import pytest
|
||||
|
||||
from ComfyUI_H3_Continuum_Join.run_storage import RunStorageError
|
||||
from ComfyUI_H3_Continuum_Join.v2 import sequence
|
||||
from ComfyUI_H3_Continuum_Join.v3 import runtime_coordinator as coordinator_module
|
||||
from ComfyUI_H3_Continuum_Join.v3.runtime_coordinator import (
|
||||
InternalRuntimeCoordinator,
|
||||
)
|
||||
from ComfyUI_H3_Continuum_Join.v3.sampling_engine import sample_physical_group
|
||||
|
||||
|
||||
EXPECTED_RUN_SEQUENCE_PARAMETERS = (
|
||||
"model", "clip", "video_vae", "audio_vae", "sampler", "sigmas",
|
||||
"first_frame", "last_frame", "prompt_plan", "width", "height",
|
||||
"continuity", "base_seed", "audio_continuity", "exact_total_duration",
|
||||
"diagnostics_mode", "reroll_from_chunk", "reroll_nonce",
|
||||
"strict_compatibility", "debug", "seam_correction", "enable_preview",
|
||||
"session", "initial_state", "latent_only", "reference_assets",
|
||||
"reference_audio_source", "reference_audio_vae",
|
||||
"driving_audio_source", "driving_audio_vae", "reference_video_source",
|
||||
"timeline_video_source", "guide_source", "capture_refine_context",
|
||||
"memory_attribution", "prompt_conditioning_cache",
|
||||
"reference_encode_cache", "continuation_transport",
|
||||
"max_new_physical_groups", "_memory_attribution_collector",
|
||||
"_diagnostic_continuation_policy",
|
||||
)
|
||||
|
||||
|
||||
def _coordinator(*, storage=False, session=None, state=None):
|
||||
return InternalRuntimeCoordinator(
|
||||
storage_controller=(object() if storage else None),
|
||||
input_session=session,
|
||||
initial_state=state,
|
||||
)
|
||||
|
||||
|
||||
def test_r4_run_sequence_keeps_the_exact_explicit_41_keyword_signature():
|
||||
public = inspect.signature(sequence.run_sequence)
|
||||
internal = inspect.signature(sequence._run_runtime_internal)
|
||||
|
||||
assert tuple(public.parameters) == EXPECTED_RUN_SEQUENCE_PARAMETERS
|
||||
assert tuple(internal.parameters) == EXPECTED_RUN_SEQUENCE_PARAMETERS
|
||||
assert public == internal
|
||||
assert all(
|
||||
parameter.kind is inspect.Parameter.KEYWORD_ONLY
|
||||
for parameter in public.parameters.values()
|
||||
)
|
||||
|
||||
|
||||
def test_r4_storage_plus_explicit_session_keeps_existing_error():
|
||||
coordinator = _coordinator(storage=True, session={"session": True})
|
||||
|
||||
with pytest.raises(
|
||||
RunStorageError,
|
||||
match="Run Storage cannot be combined with an explicit Session",
|
||||
):
|
||||
coordinator.assert_storage_session_compatible()
|
||||
|
||||
|
||||
def test_r4_explicit_session_suppresses_state_before_session_validation(caplog):
|
||||
state = {"would": "otherwise be considered"}
|
||||
coordinator = _coordinator(
|
||||
session={"invalid": "session payload"},
|
||||
state=state,
|
||||
)
|
||||
|
||||
session, effective_state = coordinator.prepare_inputs()
|
||||
|
||||
assert session == {"invalid": "session payload"}
|
||||
assert effective_state is None
|
||||
assert coordinator.initial_state is None
|
||||
assert "using the session and ignoring initial_state" in caplog.text
|
||||
|
||||
|
||||
def test_r4_usable_storage_prefix_precedes_initial_state(monkeypatch):
|
||||
state = {"state": True}
|
||||
coordinator = _coordinator(storage=True, state=state)
|
||||
monkeypatch.setattr(
|
||||
coordinator_module,
|
||||
"entry_to_state",
|
||||
lambda entry: {"width": 64, "height": 64, "source": entry["source"]},
|
||||
)
|
||||
|
||||
selected = coordinator.select_continuation_source(
|
||||
preserved=[{"source": "storage"}],
|
||||
initial_state=state,
|
||||
chunks=2,
|
||||
width=64,
|
||||
height=64,
|
||||
reroll_from_chunk=0,
|
||||
effective_reroll_from_chunk=0,
|
||||
terminal_merge_enabled=False,
|
||||
)
|
||||
|
||||
assert selected.continuation_source_facts.kind == "run_storage"
|
||||
assert selected.continuation_source_facts.accepted_chunks == 1
|
||||
assert selected.previous_state["source"] == "storage"
|
||||
|
||||
|
||||
def test_r4_initial_state_is_considered_only_without_usable_prefix(monkeypatch):
|
||||
state = {"state": True}
|
||||
coordinator = _coordinator(storage=True, state=state)
|
||||
monkeypatch.setattr(
|
||||
coordinator_module,
|
||||
"validate_state",
|
||||
lambda value: {"width": 64, "height": 64, "source": value["state"]},
|
||||
)
|
||||
|
||||
selected = coordinator.select_continuation_source(
|
||||
preserved=[],
|
||||
initial_state=state,
|
||||
chunks=2,
|
||||
width=64,
|
||||
height=64,
|
||||
reroll_from_chunk=0,
|
||||
effective_reroll_from_chunk=0,
|
||||
terminal_merge_enabled=False,
|
||||
)
|
||||
|
||||
assert selected.continuation_source_facts.kind == "initial_state"
|
||||
assert selected.continuation_source_facts.accepted_chunks == 0
|
||||
assert selected.previous_state["source"] is True
|
||||
|
||||
|
||||
def test_r4_sampling_engine_owns_one_sample_and_preserves_observer_order():
|
||||
events = []
|
||||
|
||||
class Sigmas:
|
||||
shape = (5,)
|
||||
|
||||
class LayoutProfiler:
|
||||
def begin_sampling_group(self, **kwargs):
|
||||
events.append(("layout_begin", kwargs))
|
||||
return "layout-token"
|
||||
|
||||
def finish_sampling_group(self, token):
|
||||
events.append(("layout_finish", token))
|
||||
|
||||
class DiagnosticPolicy:
|
||||
def before_sampling(self, **kwargs):
|
||||
events.append(("diagnostic_before", kwargs))
|
||||
return "diagnostic-token"
|
||||
|
||||
def planner_event(_planner, event, **kwargs):
|
||||
events.append((f"planner_{event}", kwargs))
|
||||
|
||||
def sample_callable(**kwargs):
|
||||
events.append(("sample", kwargs))
|
||||
return "sampled"
|
||||
|
||||
sampled, diagnostic_token = sample_physical_group(
|
||||
sample_callable=sample_callable,
|
||||
model="model",
|
||||
conditioning="conditioning",
|
||||
latent="latent",
|
||||
sampler="sampler",
|
||||
sigmas=Sigmas(),
|
||||
seed=42,
|
||||
enable_preview=True,
|
||||
physical_group=2,
|
||||
logical_chunks=(2,),
|
||||
terminal_atomic=False,
|
||||
layout_validation_profiler=LayoutProfiler(),
|
||||
packed_row_planner="planner",
|
||||
planner_event=planner_event,
|
||||
diagnostic_policy=DiagnosticPolicy(),
|
||||
context_frames=22,
|
||||
)
|
||||
|
||||
assert sampled == "sampled"
|
||||
assert diagnostic_token == "diagnostic-token"
|
||||
assert [name for name, _ in events] == [
|
||||
"layout_begin",
|
||||
"diagnostic_before",
|
||||
"planner_begin_group",
|
||||
"sample",
|
||||
"planner_finish_group",
|
||||
"layout_finish",
|
||||
]
|
||||
|
||||
|
||||
def test_r4_runtime_uses_sampling_engine_and_engine_has_no_storage_import():
|
||||
runtime_tree = ast.parse(inspect.getsource(sequence._run_runtime_internal))
|
||||
calls = [
|
||||
node.func.id
|
||||
for node in ast.walk(runtime_tree)
|
||||
if isinstance(node, ast.Call) and isinstance(node.func, ast.Name)
|
||||
]
|
||||
engine_source = inspect.getsource(inspect.getmodule(sample_physical_group))
|
||||
|
||||
assert calls.count("sample_physical_group") == 2
|
||||
assert calls.count("sample_chunk") == 0
|
||||
assert "run_storage" not in engine_source.lower()
|
||||
|
||||
|
||||
def test_r4_continuation_priority_branches_have_one_owner():
|
||||
runtime_source = inspect.getsource(coordinator_module)
|
||||
sequence_source = inspect.getsource(sequence._run_runtime_internal)
|
||||
|
||||
assert runtime_source.count("class InternalRuntimeCoordinator") == 1
|
||||
assert runtime_source.count("def project_selected_continuation_source") == 1
|
||||
assert "selected_kind" in runtime_source
|
||||
assert "selected_source_kind" not in sequence_source
|
||||
assert "validate_state(initial_state)" not in sequence_source
|
||||
@@ -0,0 +1,318 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import hashlib
|
||||
import json
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
|
||||
import pytest
|
||||
|
||||
import ComfyUI_H3_Continuum_Join.run_storage as storage_runtime
|
||||
from ComfyUI_H3_Continuum_Join.run_storage import RunStorageError
|
||||
from ComfyUI_H3_Continuum_Join.v2.session import SessionValidationError
|
||||
|
||||
from . import test_v38_review_run_storage as storage_cases
|
||||
|
||||
|
||||
def _ready_controller(tmp_path, *, chunks: int = 2, terminal: bool = False):
|
||||
contract = storage_cases._contract(chunks=chunks, terminal=terminal)
|
||||
controller = storage_cases._controller(tmp_path, contract)
|
||||
controller.lock = storage_runtime._RunLock(controller.run_root / ".lock")
|
||||
controller.revision_root.mkdir(parents=True, exist_ok=True)
|
||||
controller._write_manifest()
|
||||
return controller, contract
|
||||
|
||||
|
||||
def _raw_path(controller, record: dict) -> Path:
|
||||
return controller.revision_root / "chunks" / record["filename"]
|
||||
|
||||
|
||||
def test_r5_retry_uses_a_new_raw_without_overwriting_the_accepted_raw(tmp_path):
|
||||
controller, contract = _ready_controller(tmp_path, chunks=1)
|
||||
controller.commit_group(
|
||||
(storage_cases._entry(0, contract),), positions=(0,)
|
||||
)
|
||||
first = dict(controller.manifest["chunks"][0])
|
||||
first_path = _raw_path(controller, first)
|
||||
first_bytes = first_path.read_bytes()
|
||||
|
||||
replacement = storage_cases._entry(0, contract)
|
||||
replacement["video"] = replacement["video"] + 1
|
||||
controller.commit_group((replacement,), positions=(0,))
|
||||
second = dict(controller.manifest["chunks"][0])
|
||||
|
||||
assert second["filename"] != first["filename"]
|
||||
assert first_path.read_bytes() == first_bytes
|
||||
assert hashlib.sha256(first_bytes).hexdigest() == first["file_sha256"]
|
||||
assert _raw_path(controller, second).is_file()
|
||||
|
||||
|
||||
def test_r5_terminal_group_uses_one_transaction_and_one_manifest_switch(
|
||||
monkeypatch, tmp_path
|
||||
):
|
||||
controller, contract = _ready_controller(tmp_path, terminal=True)
|
||||
writes = 0
|
||||
original = controller._write_manifest
|
||||
|
||||
def counted_write():
|
||||
nonlocal writes
|
||||
writes += 1
|
||||
return original()
|
||||
|
||||
monkeypatch.setattr(controller, "_write_manifest", counted_write)
|
||||
controller.commit_group(
|
||||
(
|
||||
storage_cases._entry(0, contract),
|
||||
storage_cases._entry(1, contract),
|
||||
),
|
||||
positions=(0, 1),
|
||||
)
|
||||
|
||||
records = controller.manifest["chunks"]
|
||||
assert writes == 1
|
||||
assert [record["sequence_index"] for record in records] == [0, 1]
|
||||
transaction_parts = [
|
||||
record["filename"].split("-txn-", 1)[1].split("-chunk-", 1)[0]
|
||||
for record in records
|
||||
]
|
||||
assert len(set(transaction_parts)) == 1
|
||||
|
||||
|
||||
def test_r5_terminal_half_is_rejected_before_any_raw_write(tmp_path):
|
||||
controller, contract = _ready_controller(tmp_path, terminal=True)
|
||||
|
||||
with pytest.raises(RunStorageError, match="physical group is incomplete"):
|
||||
controller.commit_chunk(storage_cases._entry(0, contract), position=0)
|
||||
|
||||
assert controller.manifest["chunks"] == []
|
||||
assert not list((controller.revision_root / "chunks").glob("*.safetensors"))
|
||||
|
||||
|
||||
def test_r5_validates_every_entry_before_writing_group_raw(tmp_path):
|
||||
controller, contract = _ready_controller(tmp_path, terminal=True)
|
||||
invalid = dict(storage_cases._entry(1, contract))
|
||||
invalid.pop("video")
|
||||
|
||||
with pytest.raises(SessionValidationError):
|
||||
controller.commit_group(
|
||||
(storage_cases._entry(0, contract), invalid), positions=(0, 1)
|
||||
)
|
||||
|
||||
assert controller.manifest["chunks"] == []
|
||||
assert not list((controller.revision_root / "chunks").glob("*.safetensors"))
|
||||
|
||||
|
||||
def test_r5_second_raw_failure_leaves_only_unreferenced_orphan(
|
||||
monkeypatch, tmp_path
|
||||
):
|
||||
controller, contract = _ready_controller(tmp_path, terminal=True)
|
||||
original = storage_runtime.save_file
|
||||
calls = 0
|
||||
|
||||
def fail_second(tensors, filename, *, metadata):
|
||||
nonlocal calls
|
||||
calls += 1
|
||||
if calls == 2:
|
||||
raise RuntimeError("synthetic second raw failure")
|
||||
return original(tensors, filename, metadata=metadata)
|
||||
|
||||
monkeypatch.setattr(storage_runtime, "save_file", fail_second)
|
||||
with pytest.raises(RuntimeError, match="second raw failure"):
|
||||
controller.commit_group(
|
||||
(
|
||||
storage_cases._entry(0, contract),
|
||||
storage_cases._entry(1, contract),
|
||||
),
|
||||
positions=(0, 1),
|
||||
)
|
||||
|
||||
persisted = json.loads(controller._manifest_path().read_text(encoding="utf-8"))
|
||||
assert persisted["chunks"] == []
|
||||
assert controller.manifest["chunks"] == []
|
||||
assert len(list((controller.revision_root / "chunks").glob("*.safetensors"))) == 1
|
||||
|
||||
|
||||
def test_r5_catchable_manifest_failure_recovers_only_the_complete_group(
|
||||
monkeypatch, tmp_path
|
||||
):
|
||||
controller, contract = _ready_controller(tmp_path, terminal=True)
|
||||
original = controller._write_manifest
|
||||
calls = 0
|
||||
|
||||
def fail_once():
|
||||
nonlocal calls
|
||||
calls += 1
|
||||
if calls == 1:
|
||||
raise RuntimeError("synthetic manifest switch failure")
|
||||
return original()
|
||||
|
||||
monkeypatch.setattr(controller, "_write_manifest", fail_once)
|
||||
with pytest.raises(RuntimeError, match="manifest switch failure"):
|
||||
with controller:
|
||||
controller.commit_group(
|
||||
(
|
||||
storage_cases._entry(0, contract),
|
||||
storage_cases._entry(1, contract),
|
||||
),
|
||||
positions=(0, 1),
|
||||
)
|
||||
|
||||
persisted = json.loads(controller._manifest_path().read_text(encoding="utf-8"))
|
||||
assert calls == 2
|
||||
assert persisted["status"] == "interrupted"
|
||||
assert [record["sequence_index"] for record in persisted["chunks"]] == [0, 1]
|
||||
|
||||
|
||||
def test_r5_commit_group_does_not_write_the_canonical_project(monkeypatch, tmp_path):
|
||||
controller, contract = _ready_controller(tmp_path, chunks=1)
|
||||
project_writes = 0
|
||||
|
||||
def unexpected_project_write(*, set_canonical=False):
|
||||
nonlocal project_writes
|
||||
project_writes += 1
|
||||
|
||||
monkeypatch.setattr(controller, "_write_project", unexpected_project_write)
|
||||
controller.commit_group(
|
||||
(storage_cases._entry(0, contract),), positions=(0,)
|
||||
)
|
||||
|
||||
assert project_writes == 0
|
||||
assert not (controller.run_root / "project.json").exists()
|
||||
|
||||
|
||||
def test_r5_reader_keeps_legacy_chunk_filename_compatibility(tmp_path):
|
||||
controller, contract = _ready_controller(tmp_path, chunks=1)
|
||||
controller.commit_group(
|
||||
(storage_cases._entry(0, contract),), positions=(0,)
|
||||
)
|
||||
record = controller.manifest["chunks"][0]
|
||||
current_path = _raw_path(controller, record)
|
||||
legacy_path = current_path.with_name("chunk_0001.safetensors")
|
||||
current_path.replace(legacy_path)
|
||||
record["filename"] = legacy_path.name
|
||||
record["file_size"] = legacy_path.stat().st_size
|
||||
record["file_sha256"] = hashlib.sha256(legacy_path.read_bytes()).hexdigest()
|
||||
controller._write_manifest()
|
||||
|
||||
entries, records = controller._valid_prefix(
|
||||
controller.manifest,
|
||||
list(contract["chunk_contract_hashes"]),
|
||||
current_contract=contract,
|
||||
)
|
||||
|
||||
assert len(entries) == len(records) == 1
|
||||
assert records[0]["filename"] == "chunk_0001.safetensors"
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("stage", "expected_records", "expected_raws"),
|
||||
(
|
||||
("raw_before", 0, 0),
|
||||
("raw_mid", 0, 0),
|
||||
("first_raw_done", 0, 1),
|
||||
("before_manifest", 0, 2),
|
||||
("manifest_temp_mid", 0, 2),
|
||||
("before_replace", 0, 2),
|
||||
("after_replace", 2, 2),
|
||||
("after_directory_durability", 2, 2),
|
||||
),
|
||||
)
|
||||
def test_r5_fresh_process_kill_never_exposes_a_partial_terminal_group(
|
||||
tmp_path, stage, expected_records, expected_raws
|
||||
):
|
||||
worker = (
|
||||
Path(__file__).parent / "helpers" / "r5_process_crash_worker.py"
|
||||
)
|
||||
scenario_root = tmp_path / stage
|
||||
process = subprocess.Popen(
|
||||
[sys.executable, str(worker), str(scenario_root), stage],
|
||||
cwd=str(Path(__file__).resolve().parents[1]),
|
||||
)
|
||||
signal = scenario_root / "reached.json"
|
||||
deadline = time.monotonic() + 30
|
||||
try:
|
||||
while time.monotonic() < deadline and not signal.exists():
|
||||
if process.poll() is not None:
|
||||
raise AssertionError(
|
||||
f"crash worker exited before {stage}: {process.returncode}"
|
||||
)
|
||||
time.sleep(0.05)
|
||||
assert signal.exists(), f"crash worker did not reach {stage}"
|
||||
process.terminate()
|
||||
process.wait(timeout=15)
|
||||
finally:
|
||||
if process.poll() is None:
|
||||
process.kill()
|
||||
process.wait(timeout=15)
|
||||
|
||||
manifest_paths = list((scenario_root / "run" / "revisions").glob("*/manifest.json"))
|
||||
assert len(manifest_paths) == 1
|
||||
manifest = json.loads(manifest_paths[0].read_text(encoding="utf-8"))
|
||||
assert len(manifest["chunks"]) == expected_records
|
||||
raw_paths = list((manifest_paths[0].parent / "chunks").glob("*.safetensors"))
|
||||
assert len(raw_paths) == expected_raws
|
||||
for record in manifest["chunks"]:
|
||||
raw = manifest_paths[0].parent / "chunks" / record["filename"]
|
||||
assert raw.is_file()
|
||||
assert raw.stat().st_size == record["file_size"]
|
||||
assert hashlib.sha256(raw.read_bytes()).hexdigest() == record["file_sha256"]
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("stage", "project_exists"),
|
||||
(
|
||||
("finalize_manifest_1", False),
|
||||
("finalize_manifest_2", False),
|
||||
("project_before_replace", False),
|
||||
("project_after_replace", True),
|
||||
),
|
||||
)
|
||||
def test_r5_finalize_and_canonical_kill_windows_preserve_fresh_reader_selection(
|
||||
tmp_path, stage, project_exists
|
||||
):
|
||||
worker = Path(__file__).parent / "helpers" / "r5_process_crash_worker.py"
|
||||
scenario_root = tmp_path / stage
|
||||
process = subprocess.Popen(
|
||||
[sys.executable, str(worker), str(scenario_root), stage],
|
||||
cwd=str(Path(__file__).resolve().parents[1]),
|
||||
)
|
||||
signal = scenario_root / "reached.json"
|
||||
deadline = time.monotonic() + 30
|
||||
try:
|
||||
while time.monotonic() < deadline and not signal.exists():
|
||||
if process.poll() is not None:
|
||||
raise AssertionError(
|
||||
f"crash worker exited before {stage}: {process.returncode}"
|
||||
)
|
||||
time.sleep(0.05)
|
||||
assert signal.exists(), f"crash worker did not reach {stage}"
|
||||
process.terminate()
|
||||
process.wait(timeout=15)
|
||||
finally:
|
||||
if process.poll() is None:
|
||||
process.kill()
|
||||
process.wait(timeout=15)
|
||||
|
||||
run_root = scenario_root / "run"
|
||||
project_path = run_root / "project.json"
|
||||
assert project_path.exists() is project_exists
|
||||
manifests = list((run_root / "revisions").glob("*/manifest.json"))
|
||||
assert len(manifests) == 1
|
||||
manifest = json.loads(manifests[0].read_text(encoding="utf-8"))
|
||||
assert len(manifest["chunks"]) == 2
|
||||
|
||||
fresh = storage_runtime.RunStorageController("phase-d-review")
|
||||
fresh.run_root = run_root
|
||||
fresh.revisions_root = run_root / "revisions"
|
||||
_, catalog, chains = fresh._provenance_catalog()
|
||||
selected_revision, selected_chain = fresh._canonical_project_selection(
|
||||
catalog=catalog,
|
||||
chains=chains,
|
||||
)
|
||||
# The R0 fallback selects a complete legacy-style manifest even before its
|
||||
# provenance and project pointer are published. R5 preserves that exact
|
||||
# fresh-reader behavior; only commit_group raw publication changes.
|
||||
assert selected_revision == manifest["revision_id"]
|
||||
assert selected_chain
|
||||
@@ -0,0 +1,204 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import ast
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from ComfyUI_H3_Continuum_Join.v3 import driving_nodes
|
||||
from ComfyUI_H3_Continuum_Join.v3.node_facade import (
|
||||
RuntimeOutput,
|
||||
execute_v38_runtime_request,
|
||||
make_runtime_request,
|
||||
)
|
||||
from ComfyUI_H3_Continuum_Join.v3.resolution import (
|
||||
H3_SIZE_SOURCE_LEGACY,
|
||||
H3_SIZE_SOURCE_MANUAL,
|
||||
)
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class _Resolution:
|
||||
width: int = 704
|
||||
height: int = 1024
|
||||
actual_mp: float = 0.720896
|
||||
aspect_source: str = "Manual Width / Height"
|
||||
warnings: tuple[str, ...] = ()
|
||||
|
||||
|
||||
def _request(*, mode="Off", size_source=H3_SIZE_SOURCE_LEGACY, inputs=None):
|
||||
return make_runtime_request(
|
||||
runtime_kwargs={"marker": object()},
|
||||
fixed_runtime_kwargs={"width": 704, "height": 1024},
|
||||
resolution=_Resolution(),
|
||||
size_source=size_source,
|
||||
diagnostics_mode=mode,
|
||||
diagnostics_inputs={"chunk_seconds": 5.0, **(inputs or {})},
|
||||
)
|
||||
|
||||
|
||||
def _append(status, diagnostics, *, mode):
|
||||
return f"{status}|{mode}|{diagnostics}"
|
||||
|
||||
|
||||
def test_r6_request_freezes_keyword_containers_without_copying_runtime_objects():
|
||||
marker = object()
|
||||
request = make_runtime_request(
|
||||
runtime_kwargs={"marker": marker},
|
||||
fixed_runtime_kwargs={"width": 704},
|
||||
resolution=_Resolution(),
|
||||
size_source=H3_SIZE_SOURCE_LEGACY,
|
||||
diagnostics_mode="Off",
|
||||
diagnostics_inputs={"chunk_seconds": 5.0, "reference": marker},
|
||||
)
|
||||
|
||||
assert request.runtime_kwargs["marker"] is marker
|
||||
assert request.diagnostics_inputs["reference"] is marker
|
||||
with pytest.raises(TypeError):
|
||||
request.runtime_kwargs["other"] = object()
|
||||
with pytest.raises(TypeError):
|
||||
request.diagnostics_inputs["other"] = object()
|
||||
|
||||
|
||||
def test_r6_request_rejects_duplicate_runtime_keywords():
|
||||
with pytest.raises(TypeError, match="multiple values"):
|
||||
make_runtime_request(
|
||||
runtime_kwargs={"width": 1},
|
||||
fixed_runtime_kwargs={"width": 704},
|
||||
resolution=_Resolution(),
|
||||
size_source=H3_SIZE_SOURCE_LEGACY,
|
||||
diagnostics_mode="Off",
|
||||
diagnostics_inputs={},
|
||||
)
|
||||
|
||||
|
||||
def test_r6_runtime_output_preserves_nonstandard_values_and_tuple_identity():
|
||||
marker = object()
|
||||
assert RuntimeOutput(marker).as_public_tuple() is marker
|
||||
|
||||
output = (object(), object(), object(), "status", object())
|
||||
request = _request()
|
||||
result = execute_v38_runtime_request(
|
||||
request,
|
||||
runtime_adapter=lambda **kwargs: output,
|
||||
legacy_size_source=H3_SIZE_SOURCE_LEGACY,
|
||||
diagnostics_off="Off",
|
||||
diagnostics_full="Detailed Report",
|
||||
reference_video_size_default="Efficient",
|
||||
build_diagnostics=lambda **kwargs: pytest.fail("must not run"),
|
||||
append_status=_append,
|
||||
)
|
||||
assert result is output
|
||||
|
||||
|
||||
def test_r6_facade_decorates_status_only_after_existing_runtime_returns():
|
||||
video, audio, plan, tail = object(), object(), object(), object()
|
||||
output = (video, audio, plan, "base", tail)
|
||||
seen = {}
|
||||
request = _request(
|
||||
mode="Basic",
|
||||
size_source=H3_SIZE_SOURCE_MANUAL,
|
||||
inputs={
|
||||
"reference_image_1": "image-1",
|
||||
"reference_size": "Match Output",
|
||||
"reference_video_1": "guide",
|
||||
"guide": "still",
|
||||
},
|
||||
)
|
||||
|
||||
def build(**kwargs):
|
||||
seen.update(kwargs)
|
||||
return "diagnostics"
|
||||
|
||||
result = execute_v38_runtime_request(
|
||||
request,
|
||||
runtime_adapter=lambda **kwargs: output,
|
||||
legacy_size_source=H3_SIZE_SOURCE_LEGACY,
|
||||
diagnostics_off="Off",
|
||||
diagnostics_full="Detailed Report",
|
||||
reference_video_size_default="Efficient",
|
||||
build_diagnostics=build,
|
||||
append_status=_append,
|
||||
)
|
||||
|
||||
assert result[:3] == output[:3]
|
||||
assert result[4] is tail
|
||||
assert "Resolution: 704 x 1024 (0.72 MP)" in result[3]
|
||||
assert result[3].endswith("|Basic|diagnostics")
|
||||
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,) * 8
|
||||
assert seen["still_guide_active"] is True
|
||||
|
||||
|
||||
def test_r6_diagnostic_failure_keeps_runtime_payloads_and_returns_status_warning():
|
||||
payload = (object(), object(), object(), "base", object())
|
||||
result = execute_v38_runtime_request(
|
||||
_request(mode="Detailed Report"),
|
||||
runtime_adapter=lambda **kwargs: payload,
|
||||
legacy_size_source=H3_SIZE_SOURCE_LEGACY,
|
||||
diagnostics_off="Off",
|
||||
diagnostics_full="Detailed Report",
|
||||
reference_video_size_default="Efficient",
|
||||
build_diagnostics=lambda **kwargs: (_ for _ in ()).throw(RuntimeError("bad")),
|
||||
append_status=_append,
|
||||
)
|
||||
|
||||
assert result[:3] == payload[:3]
|
||||
assert result[4] is payload[4]
|
||||
assert "generation result was preserved" in result[3]
|
||||
assert "RuntimeError: bad" in result[3]
|
||||
|
||||
|
||||
def test_r6_v38_node_builds_one_request_then_delegates_to_existing_runtime_adapter(monkeypatch):
|
||||
captured = {}
|
||||
|
||||
def facade(request, **kwargs):
|
||||
captured["request"] = request
|
||||
captured["adapter"] = kwargs["runtime_adapter"]
|
||||
return "facade-result"
|
||||
|
||||
monkeypatch.setattr(driving_nodes, "execute_v38_runtime_request", facade)
|
||||
result = driving_nodes.H3ContinuumSamplerV38().run(
|
||||
chunk_seconds=5.0,
|
||||
size_source=H3_SIZE_SOURCE_MANUAL,
|
||||
width=704,
|
||||
height=1024,
|
||||
project_id="stable-project",
|
||||
)
|
||||
|
||||
request = captured["request"]
|
||||
assert result == "facade-result"
|
||||
assert request.runtime_kwargs["width"] == 704
|
||||
assert request.runtime_kwargs["height"] == 1024
|
||||
assert request.runtime_kwargs["project_id"] == "stable-project"
|
||||
assert request.runtime_kwargs["reference_encode_cache"] is True
|
||||
assert "size_source" not in request.runtime_kwargs
|
||||
assert callable(captured["adapter"])
|
||||
|
||||
|
||||
def test_r6_facade_module_has_no_runtime_owner_imports():
|
||||
tree = ast.parse((ROOT / "v3" / "node_facade.py").read_text(encoding="utf-8"))
|
||||
imported = set()
|
||||
for node in ast.walk(tree):
|
||||
if isinstance(node, ast.Import):
|
||||
imported.update(alias.name for alias in node.names)
|
||||
elif isinstance(node, ast.ImportFrom) and node.module:
|
||||
imported.add(node.module)
|
||||
forbidden = {
|
||||
"torch",
|
||||
"run_storage",
|
||||
"runtime_coordinator",
|
||||
"execution_planner",
|
||||
"sampling_engine",
|
||||
}
|
||||
assert not any(
|
||||
name == forbidden_name or name.endswith(f".{forbidden_name}")
|
||||
for name in imported
|
||||
for forbidden_name in forbidden
|
||||
)
|
||||
@@ -0,0 +1,104 @@
|
||||
"""Preserve audited Spectrum identity across harmless newline/runtime differences."""
|
||||
from __future__ import annotations
|
||||
|
||||
import hashlib
|
||||
import importlib
|
||||
import json
|
||||
from pathlib import Path
|
||||
import sys
|
||||
import types
|
||||
|
||||
import pytest
|
||||
|
||||
from ComfyUI_H3_Continuum_Join import spectrum_signature as adapter
|
||||
from .test_issue31_spectrum_signature import binding, signature, spectrum
|
||||
|
||||
|
||||
def _relocate_provider(spectrum, tmp_path, monkeypatch, *, crlf=False):
|
||||
folder = Path(spectrum[0].__file__).resolve().parent
|
||||
for path in folder.glob("*.py"):
|
||||
data = path.read_bytes()
|
||||
if crlf:
|
||||
data = data.replace(b"\r\n", b"\n").replace(b"\n", b"\r\n")
|
||||
(tmp_path / path.name).write_bytes(data)
|
||||
prefix = spectrum[0].__name__.rsplit(".", 1)[0]
|
||||
for name, module in tuple(sys.modules.items()):
|
||||
if name == prefix or name.startswith(prefix + "."):
|
||||
original = getattr(module, "__file__", None)
|
||||
if original and Path(original).resolve().parent == folder:
|
||||
monkeypatch.setattr(module, "__file__", str(tmp_path / Path(original).name))
|
||||
return prefix
|
||||
|
||||
|
||||
def test_source_digest_normalizes_only_crlf(tmp_path):
|
||||
path = tmp_path / "provider.py"
|
||||
source = b"def value():\n return 'unchanged'\n"
|
||||
path.write_bytes(source)
|
||||
expected = hashlib.sha256(source).hexdigest()
|
||||
assert adapter._source_digest(path) == expected
|
||||
path.write_bytes(source.replace(b"\n", b"\r\n"))
|
||||
assert adapter._source_digest(path) == expected
|
||||
path.write_bytes(source.replace(b"unchanged", b"changed"))
|
||||
assert adapter._source_digest(path) != expected
|
||||
|
||||
|
||||
@pytest.mark.parametrize("newlines", ["all", "one"])
|
||||
def test_crlf_preserves_full_existing_descriptor(spectrum, tmp_path, monkeypatch, newlines):
|
||||
item = binding(spectrum)
|
||||
before = signature(item)
|
||||
_relocate_provider(spectrum, tmp_path, monkeypatch, crlf=newlines == "all")
|
||||
if newlines == "one":
|
||||
path = tmp_path / "config.py"
|
||||
path.write_bytes(path.read_bytes().replace(b"\r\n", b"\n").replace(b"\n", b"\r\n"))
|
||||
assert signature(item) == before
|
||||
|
||||
|
||||
def test_module_closure_crlf_keeps_original_digest(spectrum, tmp_path, monkeypatch):
|
||||
prefix = spectrum[0].__name__.rsplit(".", 1)[0]
|
||||
module = importlib.import_module(prefix + ".runtime")
|
||||
before = adapter._callable_value(module, provider_prefix=prefix)
|
||||
_relocate_provider(spectrum, tmp_path, monkeypatch, crlf=True)
|
||||
assert adapter._callable_value(module, provider_prefix=prefix) == before
|
||||
|
||||
|
||||
@pytest.mark.parametrize("change", ["code", "extra_file"])
|
||||
def test_real_source_changes_remain_unsafe(spectrum, tmp_path, monkeypatch, change):
|
||||
item = binding(spectrum)
|
||||
signature(item)
|
||||
_relocate_provider(spectrum, tmp_path, monkeypatch, crlf=True)
|
||||
if change == "code":
|
||||
path = tmp_path / "config.py"
|
||||
path.write_bytes(path.read_bytes() + b"\nUNKNOWN_ADDITIONAL_SETTING = True\n")
|
||||
else:
|
||||
(tmp_path / "unimported_helper.py").write_text("pass\n", encoding="utf-8")
|
||||
descriptor, safe = adapter.spectrum_binding_signature(item)
|
||||
assert not safe and descriptor.get("unsupported")
|
||||
|
||||
|
||||
@pytest.mark.parametrize("version,suffix", [((3, 12, 10), "_py312"), ((3, 13, 12), "")])
|
||||
def test_runtime_selects_explicit_audited_profile(monkeypatch, version, suffix):
|
||||
monkeypatch.setattr(adapter, "sys", types.SimpleNamespace(version_info=version))
|
||||
for name in ("spectrum_provider_v1.json", "spectrum_provider_v029.json"):
|
||||
assert adapter._runtime_metadata_file(name) == Path(name).stem + suffix + ".json"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("version", [(3, 10, 0), (3, 11, 0), (3, 14, 0)])
|
||||
def test_unaudited_python_runtime_stays_unsafe(monkeypatch, version):
|
||||
monkeypatch.setattr(adapter, "sys", types.SimpleNamespace(version_info=version))
|
||||
with pytest.raises(ValueError, match="unsupported provider Python runtime"):
|
||||
adapter._runtime_metadata_file("spectrum_provider_v029.json")
|
||||
|
||||
|
||||
def test_original_py313_profile_bytes_and_new_profile_packaging():
|
||||
root = Path(adapter.__file__).parent
|
||||
original = {
|
||||
"spectrum_provider_v1.json": "0efc8d65cb6f59042457ad843fe1b77a4bee45e59d3732f5c83fbc75a31ae77b",
|
||||
"spectrum_provider_v029.json": "8f786989af6339be8cec8f2bf602da89344cf96202d29c980af5c07175eea3d3",
|
||||
}
|
||||
for name, digest in original.items():
|
||||
assert hashlib.sha256((root / name).read_bytes()).hexdigest() == digest
|
||||
old = json.loads((root / name).read_text(encoding="utf-8"))
|
||||
current = json.loads((root / (Path(name).stem + "_py312.json")).read_text(encoding="utf-8"))
|
||||
assert old["format"] == current["format"] == "audited_spectrum_loaded_implementation_v1"
|
||||
assert set(old["modules"]) == set(current["modules"])
|
||||
assert old != current
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
import torch
|
||||
|
||||
from ComfyUI_H3_Continuum_Join.constants import PLAN_MAGIC
|
||||
from ComfyUI_H3_Continuum_Join.state import (
|
||||
capture_state,
|
||||
select_context,
|
||||
validate_plan,
|
||||
validate_state,
|
||||
)
|
||||
|
||||
|
||||
class FakeNested:
|
||||
def __init__(self, parts):
|
||||
self.parts = parts
|
||||
|
||||
def unbind(self):
|
||||
return tuple(self.parts)
|
||||
|
||||
|
||||
def _latent():
|
||||
return {
|
||||
"samples": FakeNested(
|
||||
(
|
||||
torch.randn(1, 24, 37, 4, 6),
|
||||
torch.randn(1, 32, 2, 207),
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
def test_capture_and_select():
|
||||
state = capture_state(_latent(), source_frame_count=124, clip_index=1)
|
||||
validate_state(state)
|
||||
assert state["video_tail"].shape == (1, 24, 12, 4, 6)
|
||||
assert state["audio_tail"].shape == (1, 32, 2, 65)
|
||||
video, audio, grid_offset = select_context(state, 22, include_audio=True)
|
||||
assert video.shape[2] == 7
|
||||
assert audio.shape[-1] == 37
|
||||
assert abs(grid_offset - 1.0 / 3.0) < 1e-6
|
||||
|
||||
|
||||
def test_research_audio40_window_is_available_without_changing_state_schema():
|
||||
state = capture_state(_latent(), source_frame_count=124, clip_index=1)
|
||||
_video, baseline_audio, _grid_offset = select_context(
|
||||
state, 22, include_audio=True
|
||||
)
|
||||
experimental_audio = state["audio_tail"][..., -40:].contiguous()
|
||||
|
||||
assert state["capacity_frames"] == 39
|
||||
assert state["audio_tail"].shape[-1] == 65
|
||||
assert baseline_audio.shape[-1] == 37
|
||||
assert experimental_audio.shape[-1] == 40
|
||||
assert torch.equal(experimental_audio[..., -37:], baseline_audio)
|
||||
|
||||
|
||||
def test_plan_validation():
|
||||
plan = {
|
||||
"magic": PLAN_MAGIC,
|
||||
"schema_version": 1,
|
||||
"total_frames": 141,
|
||||
"trim_frames": 22,
|
||||
"net_frames": 119,
|
||||
"width": 1344,
|
||||
"height": 768,
|
||||
"clip_index": 2,
|
||||
"continuation": True,
|
||||
"state_capacity_frames": 39,
|
||||
}
|
||||
assert validate_plan(plan) is plan
|
||||
|
||||
|
||||
def test_signed_audio_grid_offset_is_preserved_for_round_down_lengths():
|
||||
latent = {
|
||||
"samples": FakeNested(
|
||||
(
|
||||
torch.randn(1, 24, 47, 4, 6), # 158 frames
|
||||
torch.randn(1, 32, 2, 263),
|
||||
)
|
||||
)
|
||||
}
|
||||
state = capture_state(latent, source_frame_count=158, clip_index=2)
|
||||
assert abs(state["audio_overhang"] + 1.0 / 3.0) < 1e-6
|
||||
validate_state(state)
|
||||
@@ -0,0 +1,49 @@
|
||||
import torch
|
||||
|
||||
from ComfyUI_H3_Continuum_Join import state_io
|
||||
from ComfyUI_H3_Continuum_Join.constants import STATE_MAGIC
|
||||
|
||||
|
||||
def test_state_roundtrip(tmp_path, monkeypatch):
|
||||
monkeypatch.setattr(state_io, "state_directory", lambda: tmp_path)
|
||||
state = {
|
||||
"magic": STATE_MAGIC,
|
||||
"schema_version": 1,
|
||||
"clip_index": 2,
|
||||
"source_frame_count": 141,
|
||||
"capacity_frames": 39,
|
||||
"width": 96,
|
||||
"height": 64,
|
||||
"video_tail": torch.randn(1, 24, 12, 4, 6),
|
||||
"audio_tail": torch.randn(1, 32, 2, 65),
|
||||
"audio_overhang": 0.0,
|
||||
"source_mode": "latent_direct",
|
||||
}
|
||||
tensor_path, json_path = state_io.save_state(state, prefix="test state", slot=3)
|
||||
assert tensor_path.exists() and json_path.exists()
|
||||
loaded = state_io.load_state(prefix="test state", slot=3)
|
||||
assert torch.equal(loaded["video_tail"], state["video_tail"])
|
||||
assert torch.equal(loaded["audio_tail"], state["audio_tail"])
|
||||
assert loaded["clip_index"] == 2
|
||||
|
||||
|
||||
def test_state_loads_when_json_mirror_is_missing(tmp_path, monkeypatch):
|
||||
monkeypatch.setattr(state_io, "state_directory", lambda: tmp_path)
|
||||
state = {
|
||||
"magic": STATE_MAGIC,
|
||||
"schema_version": 1,
|
||||
"clip_index": 1,
|
||||
"source_frame_count": 124,
|
||||
"capacity_frames": 39,
|
||||
"width": 96,
|
||||
"height": 64,
|
||||
"video_tail": torch.randn(1, 24, 12, 4, 6),
|
||||
"audio_tail": torch.randn(1, 32, 2, 65),
|
||||
"audio_overhang": 1.0 / 3.0,
|
||||
"source_mode": "latent_direct",
|
||||
}
|
||||
_tensor_path, json_path = state_io.save_state(state, prefix="atomic", slot=1)
|
||||
json_path.unlink()
|
||||
loaded = state_io.load_state(prefix="atomic", slot=1)
|
||||
assert torch.equal(loaded["video_tail"], state["video_tail"])
|
||||
assert loaded["clip_index"] == 1
|
||||
@@ -0,0 +1,80 @@
|
||||
"""Real HTTP requests to the production routes, using a model-free server fixture."""
|
||||
import asyncio
|
||||
from pathlib import Path
|
||||
import sys
|
||||
import threading
|
||||
from types import SimpleNamespace
|
||||
|
||||
import pytest
|
||||
from aiohttp import web
|
||||
from aiohttp.test_utils import TestClient, TestServer
|
||||
|
||||
from ComfyUI_H3_Continuum_Join import storage_api, storage_settings
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def api_server(tmp_path, monkeypatch):
|
||||
user = tmp_path / "user"
|
||||
temp = tmp_path / "temp"
|
||||
temp.mkdir()
|
||||
def system_user(name):
|
||||
if not name.replace("_", "").isalnum():
|
||||
raise ValueError("Invalid system user name")
|
||||
return str(user / ("__" + name))
|
||||
monkeypatch.setitem(sys.modules, "folder_paths", SimpleNamespace(
|
||||
get_system_user_directory=system_user, get_temp_directory=lambda: str(temp)))
|
||||
monkeypatch.setitem(sys.modules, "comfy.cli_args", SimpleNamespace(args=SimpleNamespace(multi_user=False)))
|
||||
monkeypatch.setattr(storage_settings, "_MANAGER", None)
|
||||
queue = SimpleNamespace(mutex=threading.RLock(), running=[], pending=[])
|
||||
queue.get_current_queue = lambda: (queue.running, queue.pending)
|
||||
server = SimpleNamespace(routes=web.RouteTableDef(), prompt_queue=queue)
|
||||
manager = storage_api.register_routes(server)
|
||||
assert storage_api.register_routes(server) is None
|
||||
app = web.Application()
|
||||
app.add_routes(server.routes)
|
||||
return app, manager, queue
|
||||
|
||||
|
||||
def test_http_validation_save_status_and_revision_conflict(api_server, tmp_path):
|
||||
app, manager, queue = api_server
|
||||
async def scenario():
|
||||
async with TestClient(TestServer(app)) as client:
|
||||
status = await client.get("/h3-continuum/storage/status")
|
||||
assert status.status == 200
|
||||
state = await status.json()
|
||||
assert state["path"] == "" and not manager.config_file.exists()
|
||||
destination = str(tmp_path / "scratch disk")
|
||||
checked = await client.post("/h3-continuum/storage/validate", json={"path": destination})
|
||||
assert checked.status == 200 and not manager.config_file.exists()
|
||||
calls = [client.post("/h3-continuum/storage/settings", json={"path": destination, "revision": 0}) for _ in range(2)]
|
||||
responses = await asyncio.gather(*calls)
|
||||
assert sorted(r.status for r in responses) == [200, 409]
|
||||
status = await client.get("/h3-continuum/storage/status")
|
||||
state = await status.json()
|
||||
assert state["revision"] == 1 and state["path"] == destination
|
||||
assert len([r for r in state["roots"] if r["current"]]) == 2
|
||||
assert (await client.post("/h3-continuum/storage/cleanup", json={})).status == 200
|
||||
asyncio.run(scenario())
|
||||
|
||||
|
||||
def test_http_rejects_busy_read_only_and_arbitrary_cleanup_paths(api_server, tmp_path):
|
||||
app, manager, queue = api_server
|
||||
protected = tmp_path / "accepted.safetensors"
|
||||
protected.write_bytes(b"keep")
|
||||
async def scenario():
|
||||
async with TestClient(TestServer(app)) as client:
|
||||
prefix = "/h3-continuum/storage/"
|
||||
assert (await client.post(prefix + "cleanup", json={"path": str(protected)})).status == 400
|
||||
assert (await client.post(prefix + "cleanup", data="{}")).status == 415
|
||||
queue.pending.append("queued")
|
||||
for action, data in (("settings", {"path": "", "revision": 0}), ("cleanup", {}), ("validate", {"path": ""})):
|
||||
assert (await client.post(prefix + action, json=data)).status == 409
|
||||
queue.pending.clear()
|
||||
with manager.operation():
|
||||
assert (await client.post(prefix + "cleanup", json={})).status == 409
|
||||
manager.read_only = True
|
||||
assert (await client.get(prefix + "status")).status == 200
|
||||
assert (await client.post(prefix + "settings", json={"path": "", "revision": 0})).status == 403
|
||||
assert (await client.post(prefix + "cleanup", json={})).status == 403
|
||||
assert protected.read_bytes() == b"keep"
|
||||
asyncio.run(scenario())
|
||||
@@ -0,0 +1,14 @@
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import subprocess
|
||||
|
||||
|
||||
def test_storage_settings_frontend_lifecycle():
|
||||
node = shutil.which("node")
|
||||
assert node, "Node.js is required for frontend regression checks"
|
||||
script = Path(__file__).with_name("frontend_storage_settings.mjs")
|
||||
result = subprocess.run([node, str(script)], text=True, encoding="utf-8",
|
||||
capture_output=True, timeout=30)
|
||||
assert result.returncode == 0, result.stdout + result.stderr
|
||||
assert "100 reopen cycles passed" in result.stdout
|
||||
assert "Empty/invalid HTTP responses, recovery, and no POST replay passed" in result.stdout
|
||||
@@ -0,0 +1,97 @@
|
||||
import pytest
|
||||
|
||||
from ComfyUI_H3_Continuum_Join.temporal import (
|
||||
align_frame_count_nearest,
|
||||
audio_grid_offset,
|
||||
audio_latent_t,
|
||||
audio_latent_t_from_grid_offset,
|
||||
context_slots,
|
||||
latent_slot_offsets,
|
||||
largest_context_capacity,
|
||||
make_av_context_window,
|
||||
make_extension_shape,
|
||||
pixel_frames_for_latent_t,
|
||||
video_latent_t,
|
||||
)
|
||||
|
||||
|
||||
def test_context_presets():
|
||||
assert context_slots(5) == 2
|
||||
assert context_slots(22) == 7
|
||||
assert context_slots(39) == 12
|
||||
assert latent_slot_offsets(7) == (0, 1, 5, 9, 13, 17, 18)
|
||||
|
||||
|
||||
def test_valid_h3_counts():
|
||||
assert video_latent_t(124) == 37
|
||||
assert pixel_frames_for_latent_t(37) == 124
|
||||
assert audio_latent_t(124) == 207
|
||||
|
||||
|
||||
def test_balanced_five_second_extension():
|
||||
shape = make_extension_shape(22, 5.0)
|
||||
assert shape.total_frames == 141
|
||||
assert shape.net_new_frames == 119
|
||||
assert shape.video_latent_t == 42
|
||||
assert shape.audio_latent_t == 235
|
||||
|
||||
|
||||
def test_nearest_grid_choice():
|
||||
assert align_frame_count_nearest(13) == 5
|
||||
assert align_frame_count_nearest(14) == 22
|
||||
|
||||
|
||||
def test_audio_grid_offset_is_signed_and_bounded_on_valid_h3_lengths():
|
||||
offsets = []
|
||||
for k in range(0, 32):
|
||||
frames = 5 + 17 * k
|
||||
offsets.append(audio_grid_offset(frames, audio_latent_t(frames)))
|
||||
assert all(-0.500001 <= value <= 0.500001 for value in offsets)
|
||||
assert any(value < 0 for value in offsets)
|
||||
assert any(value > 0 for value in offsets)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("frames", "ticks", "offset"),
|
||||
(
|
||||
(124, 207, 1.0 / 3.0),
|
||||
(141, 235, 0.0),
|
||||
(260, 433, -1.0 / 3.0),
|
||||
),
|
||||
)
|
||||
def test_representative_audio_grid_phases_round_trip(frames, ticks, offset):
|
||||
assert audio_latent_t(frames) == ticks
|
||||
assert audio_grid_offset(frames, ticks) == pytest.approx(offset)
|
||||
assert audio_latent_t_from_grid_offset(frames, offset) == ticks
|
||||
|
||||
|
||||
def test_native_context_window_uses_source_av_grid_and_cycle_phase():
|
||||
balanced = make_av_context_window(141, audio_latent_t(141), 22)
|
||||
assert (balanced.video_start_slot, balanced.video_stop_slot) == (35, 42)
|
||||
assert (balanced.audio_start_tick, balanced.audio_stop_tick) == (198, 235)
|
||||
assert balanced.audio_steps == 37
|
||||
|
||||
shifted = make_av_context_window(158, audio_latent_t(158), 22)
|
||||
assert (shifted.video_start_slot, shifted.video_stop_slot) == (40, 47)
|
||||
assert (shifted.audio_start_tick, shifted.audio_stop_tick) == (226, 263)
|
||||
assert shifted.audio_grid_offset < 0
|
||||
|
||||
|
||||
def test_native_context_window_rejects_unknown_audio_grid_phase():
|
||||
with pytest.raises(ValueError, match="audio-grid offset"):
|
||||
make_av_context_window(141, audio_latent_t(141) + 2, 22)
|
||||
|
||||
|
||||
def test_dynamic_state_capacity_for_short_extensions():
|
||||
assert largest_context_capacity(119) == 39
|
||||
assert largest_context_capacity(34) == 22
|
||||
assert largest_context_capacity(17) == 5
|
||||
|
||||
|
||||
def test_extension_shapes_remain_valid_across_ui_range():
|
||||
for context in (5, 22, 39):
|
||||
for tenths in range(40, 301):
|
||||
shape = make_extension_shape(context, tenths / 10.0)
|
||||
assert shape.total_frames % 17 == 5
|
||||
assert shape.net_new_frames >= 5
|
||||
assert pixel_frames_for_latent_t(shape.video_latent_t) == shape.total_frames
|
||||
@@ -0,0 +1,471 @@
|
||||
"""Scratch relocation and cleanup regressions with real small CPU mappings."""
|
||||
from __future__ import annotations
|
||||
|
||||
import gc
|
||||
import json
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
import threading
|
||||
import weakref
|
||||
from types import SimpleNamespace
|
||||
|
||||
import pytest
|
||||
import torch
|
||||
|
||||
from ComfyUI_H3_Continuum_Join import storage_settings as settings
|
||||
from ComfyUI_H3_Continuum_Join import storage_fs as fs
|
||||
from ComfyUI_H3_Continuum_Join import storage_memory as memory
|
||||
from ComfyUI_H3_Continuum_Join.decode_cache.store import DecodeStore
|
||||
from ComfyUI_H3_Continuum_Join.decode_cache import store as store_module
|
||||
from ComfyUI_H3_Continuum_Join.tools import p20_file_backed_tensor_poc as backing
|
||||
from ComfyUI_H3_Continuum_Join.v3 import file_backed_buffer as buffer
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def manager(tmp_path, monkeypatch):
|
||||
finalize, decode = tmp_path / "default-final", tmp_path / "default-decode"
|
||||
decode.mkdir()
|
||||
value = settings.StorageSettings(tmp_path / "user" / "settings.json",
|
||||
default_finalize=lambda: finalize, default_decode=lambda: decode)
|
||||
monkeypatch.setattr(settings, "_MANAGER", value)
|
||||
monkeypatch.setenv("H3_DECODE_CACHE_TEMP_DIR", str(decode))
|
||||
return value
|
||||
|
||||
|
||||
def cache():
|
||||
value = DecodeStore(memory_probe=lambda: 10**12, headroom_bytes=0)
|
||||
value.configure("Auto", 1024**2, 1024**2, 0)
|
||||
return value
|
||||
|
||||
|
||||
def cache_put(store, name="first"):
|
||||
x = torch.arange(24, dtype=torch.float32).reshape(2, 3, 4)
|
||||
result = store.put(name, x, "video", {}, (), store.epoch)
|
||||
assert result is not None
|
||||
return result[0]
|
||||
|
||||
|
||||
def total_removed(result):
|
||||
return sum(row["removed_files"] for row in result["roots"])
|
||||
|
||||
|
||||
def test_default_and_explicit_internal_paths_keep_their_precedence(manager, tmp_path, monkeypatch):
|
||||
monkeypatch.setattr(buffer.tempfile, "gettempdir", lambda: str(tmp_path))
|
||||
import sys
|
||||
monkeypatch.setitem(sys.modules, "folder_paths", SimpleNamespace(get_temp_directory=lambda: str(tmp_path)))
|
||||
assert buffer.resolve_backing_root() == tmp_path / "h3-continuum-v35-file-backed"
|
||||
manager.save(str(tmp_path / "日本語 scratch"), 0)
|
||||
assert buffer.resolve_backing_root() == tmp_path / "日本語 scratch/h3-continuum-scratch/finalize"
|
||||
assert buffer.resolve_backing_root(tmp_path / "injected") == tmp_path / "injected"
|
||||
store = cache()
|
||||
output = cache_put(store)
|
||||
assert store.root.parent == tmp_path / "日本語 scratch/h3-continuum-scratch/decode"
|
||||
assert not list(manager.default_decode().iterdir())
|
||||
del output
|
||||
store.close()
|
||||
|
||||
|
||||
def test_validation_does_not_activate_a_path_and_settings_survive_reload(manager, tmp_path):
|
||||
destination = str(tmp_path / "other disk")
|
||||
manager.validate(destination)
|
||||
assert manager.status()["path"] == "" and not manager.config_file.exists()
|
||||
manager.save(destination, 0)
|
||||
restored = settings.StorageSettings(manager.config_file, default_finalize=manager.default_finalize,
|
||||
default_decode=manager.default_decode)
|
||||
assert restored.status()["path"] == destination
|
||||
with pytest.raises(settings.StorageBusy, match="refresh"):
|
||||
manager.save("", 0)
|
||||
manager.save("", 1)
|
||||
assert manager.status()["path"] == ""
|
||||
|
||||
|
||||
def test_switch_keeps_old_finalize_alias_and_both_cache_mappings(manager, tmp_path):
|
||||
manager.save(str(tmp_path / "disk-a"), 0)
|
||||
with buffer.allocate_file_backed_image((2, 3, 4), dtype=torch.float32) as allocation:
|
||||
allocation.tensor.copy_(torch.arange(24).reshape(2, 3, 4))
|
||||
output = allocation.publish()
|
||||
alias = output[1:]
|
||||
old_final = allocation.record.data_path
|
||||
del output, allocation
|
||||
store = cache()
|
||||
first = cache_put(store)
|
||||
old_cache = store.entries["first"].path
|
||||
manager.save(str(tmp_path / "disk-b"), 1)
|
||||
second = cache_put(store, "second")
|
||||
assert old_cache.parent != store.entries["second"].path.parent
|
||||
assert torch.equal(first, second)
|
||||
result = manager.cleanup()
|
||||
assert total_removed(result) == 0
|
||||
assert old_cache.exists() and old_final.exists()
|
||||
assert alias.sum() == sum(range(12, 24))
|
||||
del first, second, alias
|
||||
gc.collect()
|
||||
result = manager.cleanup()
|
||||
assert total_removed(result) == 4 # one bin/sidecar pair and two npy files
|
||||
assert not old_cache.exists() and not old_final.exists()
|
||||
assert not store.contains("first") and not store.contains("second")
|
||||
assert cache_put(store, "third").sum() == sum(range(24))
|
||||
store.close()
|
||||
|
||||
|
||||
def test_status_is_read_only_and_unknown_files_and_runs_are_protected(manager, tmp_path):
|
||||
manager.save(str(tmp_path / "disk"), 0)
|
||||
root = buffer.resolve_backing_root()
|
||||
unknown = root / (backing.FILE_PREFIX + "a" * 32 + ".bin")
|
||||
unknown.write_bytes(b"orphan")
|
||||
run = tmp_path / "saved-run.safetensors"
|
||||
run.write_bytes(b"accepted take")
|
||||
store = cache()
|
||||
tensor = cache_put(store)
|
||||
path = store.entries["first"].path
|
||||
del tensor
|
||||
before = {p: p.read_bytes() for p in tmp_path.rglob("*") if p.is_file()}
|
||||
report = manager.status()
|
||||
assert any(row["deletable_bytes"] > 0 for row in report["roots"])
|
||||
assert before == {p: p.read_bytes() for p in tmp_path.rglob("*") if p.is_file()}
|
||||
assert store.contains("first") and path.exists()
|
||||
manager.cleanup()
|
||||
assert unknown.read_bytes() == b"orphan" and run.read_bytes() == b"accepted take"
|
||||
assert not path.exists()
|
||||
|
||||
|
||||
def test_changed_mount_is_not_recreated_or_replaced_by_default(manager, tmp_path):
|
||||
manager.save(str(tmp_path / "disk"), 0)
|
||||
scratch = tmp_path / "disk/h3-continuum-scratch"
|
||||
scratch.rename(tmp_path / "detached")
|
||||
with pytest.raises(OSError):
|
||||
buffer.allocate_file_backed_image((1,), dtype=torch.float32)
|
||||
store = cache()
|
||||
with pytest.raises(OSError):
|
||||
cache_put(store)
|
||||
assert not scratch.exists()
|
||||
assert not list(manager.default_decode().iterdir())
|
||||
|
||||
|
||||
@pytest.mark.parametrize("kind", ["finalize", "decode"])
|
||||
def test_symlink_substitution_protects_the_target(manager, tmp_path, kind):
|
||||
manager.save(str(tmp_path / "disk"), 0)
|
||||
target = tmp_path / "disk/h3-continuum-scratch" / kind
|
||||
moved = tmp_path / "kept"
|
||||
target.rename(moved)
|
||||
try:
|
||||
target.symlink_to(moved, target_is_directory=True)
|
||||
except OSError:
|
||||
pytest.skip("OS does not allow creating symbolic links")
|
||||
report = manager.cleanup()
|
||||
assert any(row["errors"] for row in report["roots"] if row["kind"] == kind and row["current"])
|
||||
assert moved.exists()
|
||||
|
||||
|
||||
@pytest.mark.parametrize("read_only,busy", [(True, False), (False, True)])
|
||||
def test_server_enforces_read_only_and_busy(manager, tmp_path, read_only, busy):
|
||||
manager.read_only = read_only
|
||||
manager.busy = lambda: busy
|
||||
for action in (lambda: manager.validate(str(tmp_path / "disk")),
|
||||
lambda: manager.save(str(tmp_path / "disk"), 0), manager.cleanup):
|
||||
with pytest.raises(settings.StorageError):
|
||||
action()
|
||||
assert not manager.config_file.exists()
|
||||
|
||||
|
||||
def test_active_operation_blocks_maintenance_and_freezes_configuration(manager, tmp_path):
|
||||
entered, release = threading.Event(), threading.Event()
|
||||
errors = []
|
||||
def work():
|
||||
try:
|
||||
with manager.operation():
|
||||
entered.set()
|
||||
assert release.wait(3)
|
||||
except Exception as error:
|
||||
errors.append(error)
|
||||
worker = threading.Thread(target=work)
|
||||
worker.start()
|
||||
assert entered.wait(3)
|
||||
try:
|
||||
with pytest.raises(settings.StorageBusy):
|
||||
manager.save(str(tmp_path / "disk"), 0)
|
||||
with pytest.raises(settings.StorageBusy):
|
||||
manager.cleanup()
|
||||
finally:
|
||||
release.set()
|
||||
worker.join(3)
|
||||
assert not errors and not worker.is_alive()
|
||||
manager.save(str(tmp_path / "disk"), 0)
|
||||
|
||||
|
||||
def test_ownerless_legacy_cache_is_never_swept(manager):
|
||||
root = manager.default_decode() / "h3-decode-cache-old"
|
||||
root.mkdir()
|
||||
path = root / ("b" * 32 + ".npy")
|
||||
path.write_bytes(b"unattributed")
|
||||
manager.cleanup()
|
||||
assert path.read_bytes() == b"unattributed"
|
||||
|
||||
|
||||
def test_dead_cache_owner_only_authorizes_registered_files(manager, monkeypatch):
|
||||
store = cache()
|
||||
tensor = cache_put(store)
|
||||
path = store.entries["first"].path
|
||||
unknown = path.parent / ("c" * 32 + ".npy")
|
||||
unknown.write_bytes(b"not ours")
|
||||
second = cache_put(store, "second")
|
||||
# Isolate the crash-recovery path: the real mapping remains protected until
|
||||
# released; only then simulate a terminated writer with no live store.
|
||||
del tensor, second
|
||||
manager._stores.clear()
|
||||
manager._cache_states.clear()
|
||||
monkeypatch.setattr(fs, "owner_alive", lambda owner: False)
|
||||
result = manager.cleanup()
|
||||
assert total_removed(result) == 2
|
||||
assert not path.exists() and unknown.read_bytes() == b"not ours"
|
||||
|
||||
|
||||
def test_deleted_helper_keeps_mapping_until_last_alias_is_released(manager):
|
||||
store = cache()
|
||||
output = cache_put(store)
|
||||
view = output[1:]
|
||||
path = store.entries["first"].path
|
||||
ref = weakref.ref(store)
|
||||
del output, store
|
||||
gc.collect()
|
||||
assert ref() is None and path.exists()
|
||||
assert total_removed(manager.cleanup()) == 0
|
||||
assert view.sum() == sum(range(12, 24))
|
||||
del view
|
||||
gc.collect()
|
||||
assert total_removed(manager.cleanup()) == 1
|
||||
assert not path.exists()
|
||||
|
||||
|
||||
@pytest.mark.parametrize("owner", [{}, {"pid": 1, "created": float("nan")}, {"pid": -1, "created": 1}])
|
||||
def test_unknown_process_ownership_is_protected(owner):
|
||||
assert fs.owner_alive(owner)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("path", ["relative/folder", "\\\\server\\share", "//server/share", "bad\0path"])
|
||||
def test_invalid_destinations_do_not_change_settings(manager, path):
|
||||
with pytest.raises(settings.StorageError):
|
||||
manager.save(path, 0)
|
||||
assert manager.status()["path"] == ""
|
||||
|
||||
|
||||
def test_existing_unknown_scratch_folder_is_not_adopted(manager, tmp_path):
|
||||
root = tmp_path / "disk/h3-continuum-scratch"
|
||||
root.mkdir(parents=True)
|
||||
(root / "important").write_text("keep")
|
||||
with pytest.raises(settings.StorageError, match="unknown"):
|
||||
manager.save(str(tmp_path / "disk"), 0)
|
||||
assert (root / "important").read_text() == "keep"
|
||||
|
||||
|
||||
def test_mmap_failure_does_not_activate_destination(manager, tmp_path, monkeypatch):
|
||||
def fail(*args, **kwargs):
|
||||
raise OSError("mapping unsupported")
|
||||
monkeypatch.setattr(settings.mmap, "mmap", fail)
|
||||
with pytest.raises(OSError):
|
||||
manager.save(str(tmp_path / "disk"), 0)
|
||||
assert manager.status()["path"] == ""
|
||||
assert not list(tmp_path.rglob(".h3-probe-*"))
|
||||
|
||||
|
||||
def test_manual_ram_uses_real_bytes_and_never_falls_back(monkeypatch, tmp_path):
|
||||
gib = 1024**3
|
||||
monkeypatch.setattr(buffer, "_system_memory_bytes", lambda: (16*gib, 32*gib))
|
||||
buffer.preflight_manual_buffer("RAM", 5*gib) # no Auto 4 GiB cap
|
||||
monkeypatch.setattr(buffer, "_system_memory_bytes", lambda: (6*gib, 32*gib))
|
||||
with pytest.raises(RuntimeError, match="RAM buffer needs"):
|
||||
buffer.preflight_manual_buffer("RAM", 3*gib, tmp_path)
|
||||
assert not list(tmp_path.iterdir())
|
||||
monkeypatch.setattr(buffer, "_system_memory_bytes", lambda: (None, None))
|
||||
with pytest.raises(RuntimeError, match="unavailable"):
|
||||
buffer.preflight_manual_buffer("RAM", 1)
|
||||
|
||||
|
||||
def test_manual_disk_and_auto_disk_shortage_are_explicit(monkeypatch, tmp_path):
|
||||
monkeypatch.setattr(buffer, "_disk_free_bytes", lambda path: 1024)
|
||||
with pytest.raises(RuntimeError, match="Disk-backed buffer needs"):
|
||||
buffer.preflight_manual_buffer("Disk-backed", 1024, tmp_path)
|
||||
assert not list(tmp_path.iterdir())
|
||||
|
||||
|
||||
def test_cgroup_v2_uses_most_restrictive_ancestor(tmp_path):
|
||||
mount = tmp_path / "cgroup"
|
||||
child = mount / "nested"
|
||||
child.mkdir(parents=True)
|
||||
(mount / "memory.max").write_text("1000")
|
||||
(mount / "memory.current").write_text("900")
|
||||
(child / "memory.max").write_text("500")
|
||||
(child / "memory.current").write_text("200")
|
||||
proc = tmp_path / "cgroups"; proc.write_text("0::/nested\n")
|
||||
mounts = tmp_path / "mounts"; mounts.write_text(f"1 0 0:1 / {mount} rw - cgroup2 cgroup rw\n")
|
||||
assert list(memory._cgroup_limits(proc, mounts)) == [(300, 500), (100, 1000)]
|
||||
|
||||
|
||||
def test_real_terminated_cache_writer_is_reclaimed(manager, tmp_path):
|
||||
manager.save(str(tmp_path / "disk"), 0)
|
||||
repository = Path(__file__).resolve().parents[1]
|
||||
script = '''
|
||||
import os,sys,types
|
||||
from pathlib import Path
|
||||
import torch
|
||||
package=types.ModuleType("storage_child")
|
||||
package.__path__=[sys.argv[1]]
|
||||
sys.modules[package.__name__]=package
|
||||
from storage_child import storage_settings as settings
|
||||
from storage_child.decode_cache.store import DecodeStore
|
||||
manager=settings.StorageSettings(Path(sys.argv[2]),default_finalize=lambda:Path(sys.argv[3]),default_decode=lambda:Path(sys.argv[3]))
|
||||
settings.install_manager(manager)
|
||||
store=DecodeStore(memory_probe=lambda:10**12,headroom_bytes=0)
|
||||
store.configure("Auto",1024**2,1024**2,0)
|
||||
output=store.put("entry",torch.ones(2,3,4),"video",{},(),store.epoch)
|
||||
assert output is not None
|
||||
os._exit(0)
|
||||
'''
|
||||
subprocess.run([sys.executable, "-c", script, str(repository), str(manager.config_file), str(tmp_path)],
|
||||
check=True, timeout=30)
|
||||
cache_root = tmp_path / "disk/h3-continuum-scratch/decode"
|
||||
assert len(list(cache_root.rglob("*.npy"))) == 1
|
||||
assert total_removed(manager.cleanup()) == 1
|
||||
assert not list(cache_root.iterdir())
|
||||
|
||||
|
||||
def test_existing_manager_refuses_replaced_root_before_deletion(tmp_path):
|
||||
root = tmp_path / "original"
|
||||
manager = backing.StorageLifetimeManager(root)
|
||||
with manager.allocate((2,), dtype=torch.float32) as allocation:
|
||||
allocation.tensor.fill_(3)
|
||||
output = allocation.publish()
|
||||
record = allocation.record
|
||||
del allocation, output
|
||||
moved = tmp_path / "detached"
|
||||
root.rename(moved)
|
||||
root.mkdir()
|
||||
protected = root / record.data_path.name
|
||||
protected.write_bytes(b"replacement data")
|
||||
with pytest.raises(backing.FileBackedPoCError, match="changed"):
|
||||
manager.collect_ready()
|
||||
assert protected.read_bytes() == b"replacement data"
|
||||
|
||||
|
||||
def test_failed_unpublished_cache_write_remains_cleanable(manager, monkeypatch):
|
||||
store = cache()
|
||||
def broken_blocks(tensor):
|
||||
yield b"partial"
|
||||
raise OSError("writer interrupted")
|
||||
original_unlink = Path.unlink
|
||||
def busy_temp(path, *args, **kwargs):
|
||||
if path.suffix == ".tmp":
|
||||
raise PermissionError("temporarily locked")
|
||||
return original_unlink(path, *args, **kwargs)
|
||||
with monkeypatch.context() as patch:
|
||||
patch.setattr(store_module, "tensor_blocks", broken_blocks)
|
||||
patch.setattr(Path, "unlink", busy_temp)
|
||||
with pytest.raises(OSError, match="writer interrupted"):
|
||||
cache_put(store)
|
||||
assert not store.entries
|
||||
assert len(list(store.root.glob("*.tmp"))) == 1
|
||||
assert total_removed(manager.cleanup()) == 1
|
||||
assert not list(store.root.glob("*.tmp"))
|
||||
|
||||
|
||||
def test_two_processes_cannot_overwrite_the_same_settings_revision(manager, tmp_path):
|
||||
repository = Path(__file__).resolve().parents[1]
|
||||
script = '''
|
||||
import sys,types
|
||||
from pathlib import Path
|
||||
package=types.ModuleType("storage_child")
|
||||
package.__path__=[sys.argv[1]]
|
||||
sys.modules[package.__name__]=package
|
||||
from storage_child import storage_settings as settings
|
||||
manager=settings.StorageSettings(Path(sys.argv[2]),default_finalize=lambda:Path(sys.argv[3]),default_decode=lambda:Path(sys.argv[3]))
|
||||
sys.stdin.read(1)
|
||||
try:
|
||||
manager.save("",0)
|
||||
print("saved")
|
||||
except settings.StorageBusy:
|
||||
print("conflict")
|
||||
'''
|
||||
command = [sys.executable, "-c", script, str(repository), str(manager.config_file), str(tmp_path)]
|
||||
children = [subprocess.Popen(command, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE, text=True) for _ in range(2)]
|
||||
try:
|
||||
for child in children:
|
||||
child.stdin.write("x"); child.stdin.flush()
|
||||
outputs = [child.communicate(timeout=15) for child in children]
|
||||
assert all(child.returncode == 0 for child in children), outputs
|
||||
assert sorted(out.strip() for out, err in outputs) == ["conflict", "saved"]
|
||||
assert manager.status()["revision"] == 1
|
||||
finally:
|
||||
for child in children:
|
||||
if child.poll() is None:
|
||||
child.kill(); child.wait()
|
||||
|
||||
|
||||
def test_cleanup_reports_a_failed_unlink_and_can_retry(manager, monkeypatch):
|
||||
store = cache()
|
||||
output = cache_put(store)
|
||||
path = store.entries["first"].path
|
||||
del output
|
||||
original = Path.unlink
|
||||
def denied(value, *args, **kwargs):
|
||||
if value == path:
|
||||
raise PermissionError("file locked")
|
||||
return original(value, *args, **kwargs)
|
||||
with monkeypatch.context() as patch:
|
||||
patch.setattr(Path, "unlink", denied)
|
||||
result = manager.cleanup()
|
||||
assert total_removed(result) == 0 and path.exists()
|
||||
assert any(row["errors"] for row in result["roots"])
|
||||
assert total_removed(manager.cleanup()) == 1 and not path.exists()
|
||||
|
||||
|
||||
def test_finalize_startup_also_preserves_ownerless_files(manager, tmp_path):
|
||||
manager.save(str(tmp_path / "disk"), 0)
|
||||
root = buffer.resolve_backing_root()
|
||||
orphan = root / (backing.FILE_PREFIX + "d" * 32 + ".bin")
|
||||
orphan.write_bytes(b"unknown ownership")
|
||||
with buffer.allocate_file_backed_image((1,), dtype=torch.float32) as allocation:
|
||||
allocation.tensor.fill_(1)
|
||||
output = allocation.publish()
|
||||
assert output.item() == 1
|
||||
assert orphan.read_bytes() == b"unknown ownership"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("suffix", [".bin", ".json"])
|
||||
def test_finalize_cleanup_does_not_follow_file_links(manager, tmp_path, monkeypatch, suffix):
|
||||
manager.save(str(tmp_path / "disk"), 0)
|
||||
with buffer.allocate_file_backed_image((1,), dtype=torch.float32) as allocation:
|
||||
output = allocation.publish()
|
||||
record = allocation.record
|
||||
del allocation, output
|
||||
target = record.data_path if suffix == ".bin" else record.metadata_path
|
||||
outside = tmp_path / ("outside" + suffix)
|
||||
target.rename(outside)
|
||||
try:
|
||||
target.symlink_to(outside)
|
||||
except OSError:
|
||||
pytest.skip("File symlinks are unavailable")
|
||||
before = outside.read_bytes()
|
||||
assert total_removed(manager.cleanup()) == 0
|
||||
assert target.is_symlink() and outside.read_bytes() == before
|
||||
|
||||
|
||||
def test_finalize_failed_delete_keeps_ownership_for_retry(manager, tmp_path, monkeypatch):
|
||||
manager.save(str(tmp_path / "disk"), 0)
|
||||
with buffer.allocate_file_backed_image((1,), dtype=torch.float32) as allocation:
|
||||
output = allocation.publish()
|
||||
record = allocation.record
|
||||
del allocation, output
|
||||
original = Path.unlink
|
||||
def denied(value, *args, **kwargs):
|
||||
if value == record.data_path:
|
||||
raise PermissionError("file locked")
|
||||
return original(value, *args, **kwargs)
|
||||
with monkeypatch.context() as patch:
|
||||
patch.setattr(Path, "unlink", denied)
|
||||
result = manager.cleanup()
|
||||
assert total_removed(result) == 0 and record.metadata_path.exists()
|
||||
assert any(row["errors"] for row in result["roots"])
|
||||
assert total_removed(manager.cleanup()) == 2
|
||||
@@ -0,0 +1,183 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from types import SimpleNamespace
|
||||
|
||||
import torch
|
||||
|
||||
from ComfyUI_H3_Continuum_Join.v2.sequence import (
|
||||
_split_terminal_merged_latents,
|
||||
_terminal_pair_contract,
|
||||
)
|
||||
from ComfyUI_H3_Continuum_Join.tests.terminal_merge_diagnostics import (
|
||||
DiagnosticCapture,
|
||||
first_divergent_stage,
|
||||
tensor_difference,
|
||||
tensor_fingerprint,
|
||||
)
|
||||
|
||||
|
||||
def _capture_all_stages(*, sampled_offset: float = 0.0) -> DiagnosticCapture:
|
||||
capture = DiagnosticCapture()
|
||||
capture.capture_pre_sampler(
|
||||
physical_frames=243,
|
||||
seed=42,
|
||||
conditioning=[[torch.tensor([1.0]), {"minimax_frame_count": 243}]],
|
||||
latent={"video": torch.zeros(1, 24, 72, 2, 2)},
|
||||
noise=torch.arange(8, dtype=torch.float32),
|
||||
keyframes=(0, 242),
|
||||
qwen_images=("first", "last"),
|
||||
minimax_refs=None,
|
||||
)
|
||||
layout = SimpleNamespace(
|
||||
signature=(1, 2, 3),
|
||||
segments=(("target_video", 0, 72),),
|
||||
position_ids=torch.arange(12, dtype=torch.float32).reshape(6, 2),
|
||||
)
|
||||
capture.capture_first_model_call(
|
||||
minimax_payload={
|
||||
"layout": layout,
|
||||
"cond_video_latents": torch.ones(1, 24, 2, 2, 2),
|
||||
"target_video_shape": (1, 24, 72, 2, 2),
|
||||
"target_audio_shape": (1, 32, 2, 405),
|
||||
},
|
||||
transformer_options={"patches": {}},
|
||||
)
|
||||
video = torch.full((1, 24, 72, 2, 2), sampled_offset)
|
||||
audio = torch.zeros(1, 32, 2, 405)
|
||||
capture.capture_sampled_physical_av(video=video, audio=audio)
|
||||
capture.capture_split_recombine(
|
||||
physical_video=video,
|
||||
physical_audio=audio,
|
||||
recombined_video=video.clone(),
|
||||
recombined_audio=audio.clone(),
|
||||
)
|
||||
decoded = torch.zeros(243, 2, 2, 3)
|
||||
capture.capture_decode_assembly(
|
||||
physical_decoded=decoded,
|
||||
assembled_decoded=decoded.clone(),
|
||||
)
|
||||
return capture
|
||||
|
||||
|
||||
def test_tensor_fingerprint_is_deterministic_and_dtype_sensitive():
|
||||
value = torch.arange(12, dtype=torch.float32).reshape(3, 4)
|
||||
first = tensor_fingerprint(value)
|
||||
second = tensor_fingerprint(value.clone())
|
||||
|
||||
assert first == second
|
||||
assert first.shape == (3, 4)
|
||||
assert first.dtype == "torch.float32"
|
||||
assert first.sha256 != tensor_fingerprint(value.to(torch.float64)).sha256
|
||||
|
||||
|
||||
def test_tensor_difference_keeps_hash_mismatch_distinct_from_allclose():
|
||||
core = torch.tensor([1.0], dtype=torch.float32)
|
||||
continuum = torch.tensor([1.0 + 1.0e-7], dtype=torch.float32)
|
||||
|
||||
difference = tensor_difference(core, continuum)
|
||||
|
||||
assert difference.bit_exact is False
|
||||
assert difference.allclose is True
|
||||
assert difference.max_abs_diff is not None
|
||||
assert difference.max_abs_diff > 0.0
|
||||
assert difference.mean_abs_diff == difference.max_abs_diff
|
||||
|
||||
|
||||
def test_pre_sampler_capture_includes_initial_noise():
|
||||
core = _capture_all_stages()
|
||||
continuum = _capture_all_stages()
|
||||
assert first_divergent_stage(core, continuum) is None
|
||||
|
||||
changed = DiagnosticCapture()
|
||||
changed.capture_pre_sampler(
|
||||
physical_frames=243,
|
||||
seed=42,
|
||||
conditioning=[[torch.tensor([1.0]), {"minimax_frame_count": 243}]],
|
||||
latent={"video": torch.zeros(1, 24, 72, 2, 2)},
|
||||
noise=torch.arange(8, dtype=torch.float32) + 1.0,
|
||||
keyframes=(0, 242),
|
||||
qwen_images=("first", "last"),
|
||||
minimax_refs=None,
|
||||
)
|
||||
|
||||
assert first_divergent_stage(core, changed) == "A_pre_sampler"
|
||||
|
||||
|
||||
def test_first_model_call_capture_detects_packed_layout_difference():
|
||||
core = DiagnosticCapture()
|
||||
continuum = DiagnosticCapture()
|
||||
shared = dict(
|
||||
physical_frames=243,
|
||||
seed=42,
|
||||
conditioning=[torch.zeros(1)],
|
||||
latent=torch.zeros(1),
|
||||
noise=torch.zeros(1),
|
||||
)
|
||||
core.capture_pre_sampler(**shared)
|
||||
continuum.capture_pre_sampler(**shared)
|
||||
|
||||
core_layout = SimpleNamespace(
|
||||
signature=(1, 2),
|
||||
segments=(("target_video", 0, 72),),
|
||||
position_ids=torch.zeros(4, 2),
|
||||
)
|
||||
continuum_layout = SimpleNamespace(
|
||||
signature=(1, 2),
|
||||
segments=(("target_video", 0, 72),),
|
||||
position_ids=torch.ones(4, 2),
|
||||
)
|
||||
core.capture_first_model_call(
|
||||
minimax_payload={"layout": core_layout},
|
||||
transformer_options={},
|
||||
)
|
||||
continuum.capture_first_model_call(
|
||||
minimax_payload={"layout": continuum_layout},
|
||||
transformer_options={},
|
||||
)
|
||||
|
||||
assert first_divergent_stage(core, continuum) == "B_first_model_call"
|
||||
|
||||
|
||||
def test_first_divergent_stage_uses_pipeline_order():
|
||||
core = _capture_all_stages(sampled_offset=0.0)
|
||||
continuum = _capture_all_stages(sampled_offset=1.0)
|
||||
|
||||
assert first_divergent_stage(core, continuum) == "C_sampled_physical_av"
|
||||
|
||||
|
||||
def test_terminal_split_recombine_is_bit_exact():
|
||||
contract = _terminal_pair_contract(initial_pair=True, chunk_seconds=5.0)
|
||||
video = torch.arange(
|
||||
1 * 24 * contract["video_slices"][-1][1] * 2 * 2,
|
||||
dtype=torch.float32,
|
||||
).reshape(1, 24, contract["video_slices"][-1][1], 2, 2)
|
||||
audio = torch.arange(
|
||||
1 * 32 * 2 * contract["audio_slices"][-1][1],
|
||||
dtype=torch.float32,
|
||||
).reshape(1, 32, 2, contract["audio_slices"][-1][1])
|
||||
|
||||
(video_1, audio_1), (video_2, audio_2) = _split_terminal_merged_latents(
|
||||
video,
|
||||
audio,
|
||||
contract,
|
||||
)
|
||||
video_overlap = contract["video_slices"][0][1] - contract["video_slices"][1][0]
|
||||
audio_overlap = contract["audio_slices"][0][1] - contract["audio_slices"][1][0]
|
||||
recombined_video = torch.cat((video_1, video_2[:, :, video_overlap:]), dim=2)
|
||||
recombined_audio = torch.cat((audio_1, audio_2[..., audio_overlap:]), dim=-1)
|
||||
|
||||
assert contract["physical_frames"] == 243
|
||||
assert contract["logical_frames"] == (124, 141)
|
||||
assert torch.equal(recombined_video, video)
|
||||
assert torch.equal(recombined_audio, audio)
|
||||
assert tensor_difference(video, recombined_video).bit_exact is True
|
||||
assert tensor_difference(audio, recombined_audio).bit_exact is True
|
||||
|
||||
capture = DiagnosticCapture()
|
||||
stage = capture.capture_split_recombine(
|
||||
physical_video=video,
|
||||
physical_audio=audio,
|
||||
recombined_video=recombined_video,
|
||||
recombined_audio=recombined_audio,
|
||||
)
|
||||
assert stage.name == "D_split_recombine"
|
||||
@@ -0,0 +1,215 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import io
|
||||
from types import SimpleNamespace
|
||||
|
||||
import torch
|
||||
|
||||
from ComfyUI_H3_Continuum_Join.timeline_video import (
|
||||
TIMELINE_VIDEO_SIZE_BALANCED,
|
||||
TIMELINE_VIDEO_SIZE_EFFICIENT,
|
||||
TIMELINE_VIDEO_SIZE_MATCH_OUTPUT,
|
||||
combine_timeline_video_identity,
|
||||
encode_timeline_video_chunk,
|
||||
prepare_timeline_video_source,
|
||||
validate_timeline_video_prompts,
|
||||
)
|
||||
from ComfyUI_H3_Continuum_Join.v3.nodes import (
|
||||
H3ContinuumSamplerProduction,
|
||||
H3ContinuumSamplerTimelineVideo,
|
||||
)
|
||||
|
||||
|
||||
class _Trimmed:
|
||||
def __init__(self, frames):
|
||||
self.frames = frames
|
||||
|
||||
def get_components(self):
|
||||
return SimpleNamespace(images=self.frames, audio=None, frame_rate=24.0)
|
||||
|
||||
|
||||
class _Video:
|
||||
def __init__(self, frames, duration=10.0, width=32, height=32):
|
||||
self.frames = frames
|
||||
self.duration = duration
|
||||
self.width = width
|
||||
self.height = height
|
||||
self.calls = []
|
||||
self.stream = io.BytesIO(b"timeline-video-test")
|
||||
|
||||
def get_duration(self):
|
||||
return self.duration
|
||||
|
||||
def get_dimensions(self):
|
||||
return self.width, self.height
|
||||
|
||||
def get_stream_source(self):
|
||||
return self.stream
|
||||
|
||||
def as_trimmed(self, start_time=0, duration=0, strict_duration=True):
|
||||
self.calls.append((start_time, duration, strict_duration))
|
||||
return _Trimmed(self.frames)
|
||||
|
||||
|
||||
class _VAE:
|
||||
def __init__(self):
|
||||
self.calls = []
|
||||
|
||||
def encode(self, frames):
|
||||
self.calls.append(frames)
|
||||
return torch.zeros((1, 24, 8, 2, 2))
|
||||
|
||||
|
||||
def _source(size_mode=TIMELINE_VIDEO_SIZE_MATCH_OUTPUT):
|
||||
video = _Video(torch.zeros((120, 32, 32, 3)))
|
||||
source = prepare_timeline_video_source(
|
||||
video,
|
||||
chunks=2,
|
||||
chunk_seconds=5.0,
|
||||
output_width=32,
|
||||
output_height=32,
|
||||
size_mode=size_mode,
|
||||
)
|
||||
return video, source
|
||||
|
||||
|
||||
def test_v33_unifies_optional_timeline_video_and_keeps_v324_schema():
|
||||
legacy = H3ContinuumSamplerProduction.INPUT_TYPES()
|
||||
unified = H3ContinuumSamplerTimelineVideo.INPUT_TYPES()
|
||||
assert "timeline_video" not in legacy["required"]
|
||||
assert "timeline_video_size" not in legacy["required"]
|
||||
assert "timeline_video" not in unified["required"]
|
||||
assert unified["optional"]["timeline_video"][0] == "VIDEO"
|
||||
|
||||
from ComfyUI_H3_Continuum_Join import nodes as root_nodes
|
||||
|
||||
assert "H3ContinuumSamplerTimelineVideo" not in root_nodes.NODE_CLASS_MAPPINGS
|
||||
assert "H3ContinuumSamplerProduction" not in root_nodes.NODE_CLASS_MAPPINGS
|
||||
|
||||
|
||||
def test_timeline_node_without_video_delegates_to_stable_engine(monkeypatch):
|
||||
calls = []
|
||||
|
||||
def fake_run(self, **kwargs):
|
||||
calls.append(kwargs)
|
||||
return "stable"
|
||||
|
||||
monkeypatch.setattr(H3ContinuumSamplerProduction, "run", fake_run)
|
||||
result = H3ContinuumSamplerTimelineVideo().run(
|
||||
timeline_video=None,
|
||||
timeline_video_size="Efficient - 0.4 MP",
|
||||
marker="no-video",
|
||||
)
|
||||
|
||||
assert result == "stable"
|
||||
assert calls == [{"marker": "no-video"}]
|
||||
|
||||
|
||||
def test_timeline_node_with_video_prepares_source(monkeypatch):
|
||||
video = object()
|
||||
source = object()
|
||||
prepared = []
|
||||
delegated = []
|
||||
|
||||
def fake_prepare(value, **kwargs):
|
||||
prepared.append((value, kwargs))
|
||||
return source
|
||||
|
||||
def fake_run(self, **kwargs):
|
||||
delegated.append(kwargs)
|
||||
return "timeline"
|
||||
|
||||
monkeypatch.setattr(
|
||||
"ComfyUI_H3_Continuum_Join.timeline_video.prepare_timeline_video_source",
|
||||
fake_prepare,
|
||||
)
|
||||
monkeypatch.setattr(H3ContinuumSamplerProduction, "run", fake_run)
|
||||
result = H3ContinuumSamplerTimelineVideo().run(
|
||||
timeline_video=video,
|
||||
timeline_video_size="Efficient - 0.4 MP",
|
||||
chunks=2,
|
||||
chunk_seconds=5.0,
|
||||
width=800,
|
||||
height=800,
|
||||
)
|
||||
|
||||
assert result == "timeline"
|
||||
assert prepared == [
|
||||
(
|
||||
video,
|
||||
{
|
||||
"chunks": 2,
|
||||
"chunk_seconds": 5.0,
|
||||
"output_width": 800,
|
||||
"output_height": 800,
|
||||
"size_mode": "Efficient - 0.4 MP",
|
||||
},
|
||||
)
|
||||
]
|
||||
assert delegated == [
|
||||
{
|
||||
"timeline_video_source": source,
|
||||
"chunks": 2,
|
||||
"chunk_seconds": 5.0,
|
||||
"width": 800,
|
||||
"height": 800,
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
def test_timeline_contract_is_deterministic_and_chunked():
|
||||
_, first = _source()
|
||||
_, second = _source()
|
||||
assert first.contract == second.contract
|
||||
assert len(first.contract["chunk_slices"]) == 2
|
||||
assert first.contract["chunk_slices"][1]["start_seconds"] == 5.0
|
||||
|
||||
|
||||
def test_efficient_mode_resolves_about_point_four_megapixels():
|
||||
video = _Video(torch.zeros((120, 1080, 1920, 3)), width=1920, height=1080)
|
||||
source = prepare_timeline_video_source(
|
||||
video,
|
||||
chunks=1,
|
||||
chunk_seconds=5.0,
|
||||
output_width=1344,
|
||||
output_height=768,
|
||||
size_mode=TIMELINE_VIDEO_SIZE_EFFICIENT,
|
||||
)
|
||||
assert 350_000 <= source.target_width * source.target_height <= 450_000
|
||||
|
||||
|
||||
def test_balanced_mode_resolves_about_point_six_megapixels():
|
||||
video = _Video(torch.zeros((120, 1080, 1920, 3)), width=1920, height=1080)
|
||||
source = prepare_timeline_video_source(
|
||||
video,
|
||||
chunks=1,
|
||||
chunk_seconds=5.0,
|
||||
output_width=1344,
|
||||
output_height=768,
|
||||
size_mode=TIMELINE_VIDEO_SIZE_BALANCED,
|
||||
)
|
||||
assert 550_000 <= source.target_width * source.target_height <= 650_000
|
||||
|
||||
|
||||
def test_encode_processes_only_requested_chunk_and_builds_core_payload():
|
||||
video, source = _source()
|
||||
vae = _VAE()
|
||||
assets = encode_timeline_video_chunk(vae, source, 1)
|
||||
assert video.calls == [(5.0, 5.0, False)]
|
||||
assert len(vae.calls) == 1
|
||||
assert int(vae.calls[0].shape[0]) % 17 == 5
|
||||
assert assets.item["type"] == "video"
|
||||
assert assets.block["kind"] == "video"
|
||||
assert assets.block["ref_audio_t"] == 0
|
||||
|
||||
|
||||
def test_timeline_identity_is_noop_when_absent_and_changes_when_present():
|
||||
_, source = _source()
|
||||
assert combine_timeline_video_identity("visual", None) == "visual"
|
||||
assert combine_timeline_video_identity("visual", source) != "visual"
|
||||
|
||||
|
||||
def test_missing_video_tag_warns_without_stopping():
|
||||
_, source = _source()
|
||||
assert "H3C-P103" in validate_timeline_video_prompts(["A dancer moves."], source)
|
||||
assert validate_timeline_video_prompts(["Follow <Video 1>."], source) == ""
|
||||
@@ -0,0 +1,148 @@
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from ComfyUI_H3_Continuum_Join.constants import PROMPT_FORMAT_OPTIONS
|
||||
from ComfyUI_H3_Continuum_Join.v2.nodes import (
|
||||
H3ContinuumAdvanced,
|
||||
H3ContinuumClipOverrides,
|
||||
H3ContinuumResult,
|
||||
H3ContinuumSampler,
|
||||
H3ContinuumSamplerV2,
|
||||
NODE_CLASS_MAPPINGS,
|
||||
)
|
||||
from ComfyUI_H3_Continuum_Join.v2.prompts import PromptPlanError
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
|
||||
|
||||
def test_v217_registers_static_facade_and_preserves_legacy_sampler():
|
||||
assert NODE_CLASS_MAPPINGS["H3ContinuumSampler"] is H3ContinuumSampler
|
||||
assert NODE_CLASS_MAPPINGS["H3ContinuumSamplerV2"] is H3ContinuumSamplerV2
|
||||
assert NODE_CLASS_MAPPINGS["H3ContinuumClipOverrides"] is H3ContinuumClipOverrides
|
||||
assert NODE_CLASS_MAPPINGS["H3ContinuumAdvanced"] is H3ContinuumAdvanced
|
||||
assert NODE_CLASS_MAPPINGS["H3ContinuumResult"] is H3ContinuumResult
|
||||
|
||||
|
||||
def test_v217_facade_schema_is_static_and_compact():
|
||||
schema = H3ContinuumSampler.INPUT_TYPES()
|
||||
required = schema["required"]
|
||||
optional = schema["optional"]
|
||||
|
||||
assert "sequence_prompt" in required
|
||||
assert required["sequence_prompt"][1]["forceInput"] is True
|
||||
assert "prompt_script" not in required
|
||||
assert "prompt_overrides" in optional
|
||||
assert "advanced" in optional
|
||||
assert not any(name.startswith("clip_") for name in required | optional)
|
||||
assert set(H3ContinuumSampler.RETURN_NAMES) == {"images", "audio", "result"}
|
||||
|
||||
|
||||
def test_v217_pack_nodes_have_no_dynamic_clip_sockets():
|
||||
clip_schema = H3ContinuumClipOverrides.INPUT_TYPES()["required"]
|
||||
assert set(clip_schema) == {"prompt_mode", "override_script"}
|
||||
assert clip_schema["override_script"][1]["forceInput"] is True
|
||||
|
||||
advanced = H3ContinuumAdvanced.INPUT_TYPES()
|
||||
assert set(advanced["optional"]) == {
|
||||
"last_frame",
|
||||
"session",
|
||||
"initial_state",
|
||||
"prompt_plan",
|
||||
}
|
||||
|
||||
|
||||
def test_v217_facade_delegates_to_legacy_core(monkeypatch):
|
||||
captured = {}
|
||||
|
||||
def fake_run(_self, **kwargs):
|
||||
captured.update(kwargs)
|
||||
return "images", "audio", "state", "session", "report"
|
||||
|
||||
monkeypatch.setattr(H3ContinuumSamplerV2, "run", fake_run)
|
||||
facade = H3ContinuumSampler()
|
||||
result = facade.run(
|
||||
model="model",
|
||||
clip="clip",
|
||||
video_vae="video_vae",
|
||||
audio_vae="audio_vae",
|
||||
sampler="sampler",
|
||||
sigmas="sigmas",
|
||||
sequence_prompt="base prompt",
|
||||
prompt_mode=PROMPT_FORMAT_OPTIONS[0],
|
||||
chunks=3,
|
||||
chunk_seconds=5.0,
|
||||
width=1344,
|
||||
height=768,
|
||||
continuity="Balanced - 22 frames",
|
||||
base_seed=123,
|
||||
seam_correction="Auto",
|
||||
)
|
||||
|
||||
assert result == (
|
||||
"images",
|
||||
"audio",
|
||||
{"last_state": "state", "session": "session", "report": "report"},
|
||||
)
|
||||
assert captured["prompt_script"] == "base prompt"
|
||||
assert captured["sequence_prompt"] == "base prompt"
|
||||
assert captured["audio_continuity"] is True
|
||||
assert captured["show_preview"] is True
|
||||
|
||||
|
||||
def test_v217_facade_passes_only_sparse_override_clips(monkeypatch):
|
||||
captured = {}
|
||||
|
||||
def fake_run(_self, **kwargs):
|
||||
captured.update(kwargs)
|
||||
return "images", "audio", "state", "session", "report"
|
||||
|
||||
monkeypatch.setattr(H3ContinuumSamplerV2, "run", fake_run)
|
||||
pack = H3ContinuumClipOverrides().build(
|
||||
PROMPT_FORMAT_OPTIONS[0],
|
||||
"[Clip 2]\nclose-up\n\n[Clip 5]\nfinish naturally",
|
||||
)[0]
|
||||
H3ContinuumSampler().run(
|
||||
model="model", clip="clip", video_vae="video_vae", audio_vae="audio_vae",
|
||||
sampler="sampler", sigmas="sigmas", sequence_prompt="base",
|
||||
prompt_mode=PROMPT_FORMAT_OPTIONS[0], chunks=5, chunk_seconds=5.0,
|
||||
width=1344, height=768, continuity="Balanced - 22 frames", base_seed=123,
|
||||
seam_correction="Auto", prompt_overrides=pack,
|
||||
)
|
||||
assert captured["clip_2_prompt"] == "close-up"
|
||||
assert captured["clip_5_prompt"] == "finish naturally"
|
||||
assert not any(f"clip_{index}_prompt" in captured for index in (1, 3, 4))
|
||||
|
||||
|
||||
def test_v217_facade_ignores_sparse_override_outside_chunks(monkeypatch):
|
||||
captured = {}
|
||||
|
||||
def fake_run(_self, **kwargs):
|
||||
captured.update(kwargs)
|
||||
return "images", "audio", "state", "session", "report"
|
||||
|
||||
monkeypatch.setattr(H3ContinuumSamplerV2, "run", fake_run)
|
||||
pack = H3ContinuumClipOverrides().build(
|
||||
PROMPT_FORMAT_OPTIONS[0], "[Clip 6]\noutside"
|
||||
)[0]
|
||||
H3ContinuumSampler().run(
|
||||
model="model", clip="clip", video_vae="video_vae", audio_vae="audio_vae",
|
||||
sampler="sampler", sigmas="sigmas", sequence_prompt="base",
|
||||
prompt_mode=PROMPT_FORMAT_OPTIONS[0], chunks=5, chunk_seconds=5.0,
|
||||
width=1344, height=768, continuity="Balanced - 22 frames", base_seed=123,
|
||||
seam_correction="Auto", prompt_overrides=pack,
|
||||
)
|
||||
assert not any(key.startswith("clip_") and key.endswith("_prompt") for key in captured)
|
||||
|
||||
|
||||
def test_v217_result_pack_expands_legacy_outputs():
|
||||
assert H3ContinuumResult().unpack(
|
||||
{"last_state": "state", "session": "session", "report": "report"}
|
||||
) == ("state", "session", "report")
|
||||
|
||||
|
||||
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.9.10"' in version_source
|
||||
@@ -0,0 +1,87 @@
|
||||
import torch
|
||||
import pytest
|
||||
|
||||
from ComfyUI_H3_Continuum_Join.v2.decoder import (
|
||||
_slice_audio_for_timeline,
|
||||
enforce_total_frames,
|
||||
)
|
||||
|
||||
|
||||
def _audio(samples=200000, rate=32000):
|
||||
waveform = torch.arange(samples, dtype=torch.float32).reshape(1, 1, -1)
|
||||
return {"waveform": waveform, "sample_rate": rate}
|
||||
|
||||
|
||||
def test_cumulative_audio_boundaries_do_not_accumulate_rounding_error():
|
||||
audio = _audio()
|
||||
cursor = 124
|
||||
pieces = []
|
||||
for _ in range(2):
|
||||
stop = cursor + 119
|
||||
piece = _slice_audio_for_timeline(
|
||||
audio,
|
||||
trim_frames=22,
|
||||
frame_start=cursor,
|
||||
frame_stop=stop,
|
||||
)
|
||||
pieces.append(piece)
|
||||
assert piece.shape[-1] == round(stop / 24 * 32000) - round(cursor / 24 * 32000)
|
||||
cursor = stop
|
||||
assert sum(piece.shape[-1] for piece in pieces) == round(362 / 24 * 32000) - round(124 / 24 * 32000)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("chunks", (2, 3, 5))
|
||||
def test_long_audio_timeline_uses_cumulative_sample_boundaries(chunks):
|
||||
audio = _audio(samples=1_000_000)
|
||||
frame_starts = [0]
|
||||
for index in range(chunks):
|
||||
frame_starts.append(124 + 119 * index)
|
||||
|
||||
total_samples = 0
|
||||
for index in range(chunks):
|
||||
frame_start = frame_starts[index]
|
||||
frame_stop = frame_starts[index + 1]
|
||||
trim_frames = 0 if index == 0 else 22
|
||||
piece = _slice_audio_for_timeline(
|
||||
audio,
|
||||
trim_frames=trim_frames,
|
||||
frame_start=frame_start,
|
||||
frame_stop=frame_stop,
|
||||
)
|
||||
expected = round(frame_stop / 24 * 32000) - round(
|
||||
frame_start / 24 * 32000
|
||||
)
|
||||
assert piece.shape[-1] == expected
|
||||
total_samples += expected
|
||||
|
||||
assert total_samples == round(frame_starts[-1] / 24 * 32000)
|
||||
|
||||
|
||||
def test_exact_duration_aligns_video_and_audio():
|
||||
images = torch.zeros(362, 4, 6, 3)
|
||||
audio = {"waveform": torch.zeros(1, 2, round(362 / 24 * 32000)), "sample_rate": 32000}
|
||||
images, audio, report = enforce_total_frames(images, audio, target_frames=360)
|
||||
assert images.shape[0] == 360
|
||||
assert audio["waveform"].shape[-1] == 480000
|
||||
assert "362->360" in report
|
||||
|
||||
|
||||
def test_exact_duration_preserves_user_final_anchor_when_trimming():
|
||||
images = torch.arange(362, dtype=torch.float32).reshape(362, 1, 1, 1)
|
||||
rate = 32000
|
||||
samples = round(362 / 24 * rate)
|
||||
waveform = torch.linspace(-1.0, 1.0, samples).reshape(1, 1, -1)
|
||||
audio = {"waveform": waveform, "sample_rate": rate}
|
||||
|
||||
result_images, result_audio, report = enforce_total_frames(
|
||||
images,
|
||||
audio,
|
||||
target_frames=360,
|
||||
preserve_final_frame=True,
|
||||
)
|
||||
|
||||
assert result_images.shape[0] == 360
|
||||
assert float(result_images[-1]) == 361.0
|
||||
assert float(result_images[-2]) == 358.0
|
||||
assert result_audio["waveform"].shape[-1] == 480000
|
||||
assert "final anchor preserved" in report
|
||||
+541
@@ -0,0 +1,541 @@
|
||||
import pytest
|
||||
|
||||
from ComfyUI_H3_Continuum_Join.constants import (
|
||||
PROMPT_FORMAT_AUTO,
|
||||
PROMPT_FORMAT_FIXED,
|
||||
PROMPT_FORMAT_LIST,
|
||||
PROMPT_FORMAT_TIMELINE,
|
||||
PROMPT_MODE_FIXED,
|
||||
PROMPT_MODE_LIST,
|
||||
PROMPT_MODE_TIMELINE,
|
||||
)
|
||||
from ComfyUI_H3_Continuum_Join.v2.prompts import (
|
||||
PromptPlanError,
|
||||
apply_prompt_overrides,
|
||||
build_sampler_prompt_plan,
|
||||
detect_prompt_mode,
|
||||
make_prompt_plan,
|
||||
parse_sparse_prompt_overrides,
|
||||
prompt_hash,
|
||||
prompt_plan_report,
|
||||
validate_sparse_prompt_overrides,
|
||||
validate_prompt_plan,
|
||||
)
|
||||
from ComfyUI_H3_Continuum_Join.v2.nodes import H3ContinuumPromptPlanPreview
|
||||
|
||||
|
||||
def test_fixed_prompt_repeats_without_mutation():
|
||||
plan = make_prompt_plan(mode=PROMPT_MODE_FIXED, script="hello", chunks=3, chunk_seconds=5)
|
||||
assert plan["prompts"] == ["hello", "hello", "hello"]
|
||||
assert len(set(plan["hashes"])) == 1
|
||||
assert validate_prompt_plan(plan) is plan
|
||||
|
||||
|
||||
def test_prompt_transparency_t1_fixed_passthrough():
|
||||
script = "\n".join(
|
||||
[
|
||||
"<d>Hello world</d>",
|
||||
"embedding:character_style",
|
||||
"<Picture 1>",
|
||||
"<FutureH3Token>",
|
||||
"日本語 text:01",
|
||||
"symbols +=[]{}()",
|
||||
]
|
||||
)
|
||||
plan = make_prompt_plan(
|
||||
mode=PROMPT_MODE_FIXED,
|
||||
script=script,
|
||||
chunks=2,
|
||||
chunk_seconds=5,
|
||||
)
|
||||
assert plan["prompts"] == [script, script]
|
||||
|
||||
|
||||
def test_prompt_transparency_t2_list_passthrough():
|
||||
plan = make_prompt_plan(
|
||||
mode=PROMPT_MODE_LIST,
|
||||
script=(
|
||||
"<d>first dialogue</d>\n"
|
||||
"embedding:style_a\n"
|
||||
"---\n"
|
||||
"<d>second dialogue</d>\n"
|
||||
"<FutureToken>"
|
||||
),
|
||||
chunks=2,
|
||||
chunk_seconds=5,
|
||||
)
|
||||
assert plan["prompts"] == [
|
||||
"<d>first dialogue</d>\nembedding:style_a",
|
||||
"<d>second dialogue</d>\n<FutureToken>",
|
||||
]
|
||||
|
||||
|
||||
def test_prompt_transparency_t3_timeline_passthrough():
|
||||
plan = make_prompt_plan(
|
||||
mode=PROMPT_MODE_TIMELINE,
|
||||
script=(
|
||||
"Shared <FutureToken>\n"
|
||||
"embedding:global_style\n\n"
|
||||
"[0-5s]\n"
|
||||
"<d>first line</d>\n\n"
|
||||
"[5-10s]\n"
|
||||
"<d>second line</d>\n"
|
||||
"<Picture 2>"
|
||||
),
|
||||
chunks=2,
|
||||
chunk_seconds=5,
|
||||
)
|
||||
assert plan["prompts"] == [
|
||||
"Shared <FutureToken>\nembedding:global_style\n\n<d>first line</d>",
|
||||
"Shared <FutureToken>\nembedding:global_style\n\n<d>second line</d>\n<Picture 2>",
|
||||
]
|
||||
|
||||
|
||||
def test_prompt_transparency_t4_timeline_preamble_passthrough():
|
||||
preamble = "embedding:character_x\n<FutureToken>\n<d>shared instruction</d>"
|
||||
plan = make_prompt_plan(
|
||||
mode=PROMPT_MODE_TIMELINE,
|
||||
script=f"{preamble}\n\n[Chunk 1]\nfirst\n[Chunk 2]\nsecond",
|
||||
chunks=2,
|
||||
chunk_seconds=5,
|
||||
)
|
||||
assert plan["prompts"] == [
|
||||
f"{preamble}\n\nfirst",
|
||||
f"{preamble}\n\nsecond",
|
||||
]
|
||||
|
||||
|
||||
def test_prompt_transparency_t5_external_override_passthrough_and_rehash():
|
||||
plan = make_prompt_plan(
|
||||
mode=PROMPT_MODE_FIXED,
|
||||
script="base",
|
||||
chunks=2,
|
||||
chunk_seconds=5,
|
||||
)
|
||||
override = "<d>override dialogue</d>\nembedding:new_style\n<UnknownSpecial>"
|
||||
updated = apply_prompt_overrides(plan, [None, override])
|
||||
assert updated["prompts"] == ["base", override]
|
||||
assert updated["hashes"][0] == plan["hashes"][0]
|
||||
assert updated["hashes"][1] == prompt_hash(override)
|
||||
assert updated["hashes"][1] != plan["hashes"][1]
|
||||
|
||||
|
||||
def test_prompt_transparency_t6_invalid_timeline_fallback_passthrough():
|
||||
script = "[0 to 5s]\n<d>Hello</d>\nembedding:style\n<UnknownSpecial>"
|
||||
plan = make_prompt_plan(
|
||||
mode=PROMPT_MODE_TIMELINE,
|
||||
script=script,
|
||||
chunks=2,
|
||||
chunk_seconds=5,
|
||||
)
|
||||
assert plan["mode"] == PROMPT_MODE_FIXED
|
||||
assert plan["prompts"] == [script, script]
|
||||
assert plan["diagnostics"][0]["code"] == "H3C-P100"
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("left", "right"),
|
||||
[
|
||||
("<d>Hello</d>", "<d>hello</d>"),
|
||||
("embedding:a", "embedding:b"),
|
||||
("<FutureA>", "<FutureB>"),
|
||||
],
|
||||
)
|
||||
def test_prompt_transparency_t7_hash_sensitivity(left, right):
|
||||
assert prompt_hash(left) == prompt_hash(left)
|
||||
assert prompt_hash(left) != prompt_hash(right)
|
||||
|
||||
|
||||
def test_prompt_transparency_t8_unknown_future_syntax_is_literal():
|
||||
script = "\n".join(
|
||||
[
|
||||
'<h3_future_control value="1">',
|
||||
"<future:abc>",
|
||||
"[[SPECIAL_X]]",
|
||||
"token://future/value",
|
||||
]
|
||||
)
|
||||
plan = make_prompt_plan(
|
||||
mode=PROMPT_MODE_FIXED,
|
||||
script=script,
|
||||
chunks=2,
|
||||
chunk_seconds=5,
|
||||
)
|
||||
assert plan["prompts"] == [script, script]
|
||||
assert "diagnostics" not in plan
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("script", "expected"),
|
||||
[
|
||||
("one continuous prompt", PROMPT_MODE_FIXED),
|
||||
("first\n---\nsecond", PROMPT_MODE_LIST),
|
||||
("[0-5s]\nfirst", PROMPT_MODE_TIMELINE),
|
||||
("[Chunk 1]\nfirst", PROMPT_MODE_TIMELINE),
|
||||
],
|
||||
)
|
||||
def test_auto_detects_prompt_format(script, expected):
|
||||
assert detect_prompt_mode(script) == expected
|
||||
|
||||
|
||||
def test_auto_plan_records_detected_format_without_changing_schema_mode():
|
||||
plan = make_prompt_plan(mode=PROMPT_FORMAT_AUTO, script="first\n---\nsecond", chunks=2, chunk_seconds=5)
|
||||
assert plan["mode"] == PROMPT_MODE_LIST
|
||||
assert plan["prompts"] == ["first", "second"]
|
||||
assert plan["notes"][0] == "Auto detected List"
|
||||
|
||||
|
||||
def test_simple_fixed_format_maps_to_stable_fixed_plan_mode():
|
||||
plan = make_prompt_plan(mode=PROMPT_FORMAT_FIXED, script="same", chunks=2, chunk_seconds=5)
|
||||
assert plan["mode"] == PROMPT_MODE_FIXED
|
||||
|
||||
|
||||
def test_list_prompt_uses_separator_and_repeats_last():
|
||||
plan = make_prompt_plan(
|
||||
mode=PROMPT_MODE_LIST,
|
||||
script="first\n---\nsecond",
|
||||
chunks=3,
|
||||
chunk_seconds=5,
|
||||
)
|
||||
assert plan["prompts"] == ["first", "second", "second"]
|
||||
assert "repeated" in plan["notes"][0]
|
||||
|
||||
|
||||
def test_timeline_prompt_maps_ranges_and_chunk_headers():
|
||||
plan = make_prompt_plan(
|
||||
mode=PROMPT_MODE_TIMELINE,
|
||||
script="[0-5s]\none\n[5-10s]\ntwo\n[Chunk 3]\nthree",
|
||||
chunks=3,
|
||||
chunk_seconds=5,
|
||||
)
|
||||
assert plan["prompts"] == ["one", "two", "three"]
|
||||
assert not any(item["code"] == "H3C-P105" for item in plan.get("diagnostics", []))
|
||||
|
||||
|
||||
def test_clean_list_keeps_assignments_without_mixed_syntax_warning():
|
||||
plan = make_prompt_plan(
|
||||
mode=PROMPT_FORMAT_LIST,
|
||||
script="A\n---\nB\n---\nC",
|
||||
chunks=3,
|
||||
chunk_seconds=5,
|
||||
)
|
||||
assert plan["prompts"] == ["A", "B", "C"]
|
||||
assert not any(item["code"] == "H3C-P105" for item in plan.get("diagnostics", []))
|
||||
|
||||
|
||||
@pytest.mark.parametrize("mode", [PROMPT_FORMAT_AUTO, PROMPT_FORMAT_TIMELINE])
|
||||
def test_timeline_mixed_with_list_separator_warns_and_ignores_separator(mode):
|
||||
plan = make_prompt_plan(
|
||||
mode=mode,
|
||||
script="[Chunk 1]\nA\n[Chunk 2]\nB\n---\nC",
|
||||
chunks=3,
|
||||
chunk_seconds=5,
|
||||
)
|
||||
assert plan["mode"] == PROMPT_MODE_TIMELINE
|
||||
assert plan["prompts"] == ["A", "B\nC", "B\nC"]
|
||||
assert all("---" not in prompt for prompt in plan["prompts"])
|
||||
assert any(item["code"] == "H3C-P105" for item in plan["diagnostics"])
|
||||
assert any(item["code"] == "H3C-P101" for item in plan["diagnostics"])
|
||||
|
||||
|
||||
def test_timeline_mixed_separator_is_removed_from_shared_preamble():
|
||||
plan = make_prompt_plan(
|
||||
mode=PROMPT_FORMAT_AUTO,
|
||||
script="Shared preamble\n---\n[Chunk 1]\nA\n[Chunk 2]\nB",
|
||||
chunks=2,
|
||||
chunk_seconds=5,
|
||||
)
|
||||
assert plan["prompts"] == ["Shared preamble\n\nA", "Shared preamble\n\nB"]
|
||||
assert all("---" not in prompt for prompt in plan["prompts"])
|
||||
assert any(item["code"] == "H3C-P105" for item in plan["diagnostics"])
|
||||
|
||||
|
||||
def test_five_chunk_timeline_with_trailing_separator_preserves_all_assignments():
|
||||
script = "\n".join(
|
||||
[
|
||||
"[Chunk 1]", "A", "[Chunk 2]", "B", "[Chunk 3]", "C",
|
||||
"[Chunk 4]", "D", "[Chunk 5]", "E", "---",
|
||||
]
|
||||
)
|
||||
plan = make_prompt_plan(
|
||||
mode=PROMPT_FORMAT_AUTO,
|
||||
script=script,
|
||||
chunks=5,
|
||||
chunk_seconds=5,
|
||||
)
|
||||
assert plan["prompts"] == ["A", "B", "C", "D", "E"]
|
||||
assert any(item["code"] == "H3C-P105" for item in plan["diagnostics"])
|
||||
|
||||
|
||||
def test_explicit_list_with_timeline_header_warns_but_keeps_list_parsing():
|
||||
plan = make_prompt_plan(
|
||||
mode=PROMPT_FORMAT_LIST,
|
||||
script="[Chunk 1]\nA\n---\nB\n---\nC",
|
||||
chunks=3,
|
||||
chunk_seconds=5,
|
||||
)
|
||||
assert plan["mode"] == PROMPT_MODE_LIST
|
||||
assert plan["prompts"] == ["[Chunk 1]\nA", "B", "C"]
|
||||
assert any(item["code"] == "H3C-P105" for item in plan["diagnostics"])
|
||||
assert [item["message"] for item in plan["diagnostics"] if item["code"] == "H3C-P000"] == [
|
||||
"Chunk 1 source: List section 1",
|
||||
"Chunk 2 source: List section 2",
|
||||
"Chunk 3 source: List section 3",
|
||||
]
|
||||
|
||||
|
||||
def test_explicit_fixed_keeps_all_special_syntax_literal_without_warning():
|
||||
script = "[Chunk 1]\nA\n[0-5s]\nB\n---\nC"
|
||||
plan = make_prompt_plan(
|
||||
mode=PROMPT_FORMAT_FIXED,
|
||||
script=script,
|
||||
chunks=2,
|
||||
chunk_seconds=5,
|
||||
)
|
||||
assert plan["prompts"] == [script, script]
|
||||
assert "diagnostics" not in plan
|
||||
|
||||
|
||||
def test_mixed_syntax_report_leads_with_warning_and_resolved_chunk_sources():
|
||||
plan = make_prompt_plan(
|
||||
mode=PROMPT_FORMAT_AUTO,
|
||||
script="[Chunk 1]\nA\n[Chunk 2]\nB\n---\nC",
|
||||
chunks=3,
|
||||
chunk_seconds=5,
|
||||
)
|
||||
report = prompt_plan_report(plan)
|
||||
assert report.startswith("PROMPT PREFLIGHT WARNING")
|
||||
assert "H3C-P105" in report
|
||||
assert "H3C-P101" in report
|
||||
assert "Chunk 1 source:" in report
|
||||
assert "Chunk 3 source:" in report
|
||||
|
||||
|
||||
def test_prompt_preview_uses_the_same_mixed_syntax_resolution():
|
||||
script = "[Chunk 1]\nA\n[Chunk 2]\nB\n---\nC"
|
||||
expected = make_prompt_plan(
|
||||
mode=PROMPT_FORMAT_AUTO,
|
||||
script=script,
|
||||
chunks=3,
|
||||
chunk_seconds=5,
|
||||
)
|
||||
preview_plan, preview_report = H3ContinuumPromptPlanPreview().build(
|
||||
PROMPT_FORMAT_AUTO,
|
||||
script,
|
||||
3,
|
||||
5,
|
||||
)
|
||||
assert preview_plan == expected
|
||||
assert preview_report.startswith("PROMPT PREFLIGHT WARNING")
|
||||
assert "Chunk 2:\nB\nC" in preview_report
|
||||
assert "Chunk 3:\nB\nC" in preview_report
|
||||
|
||||
|
||||
def test_timeline_preamble_is_applied_to_every_chunk():
|
||||
plan = make_prompt_plan(
|
||||
mode=PROMPT_FORMAT_AUTO,
|
||||
script="Refer to <Picture 1>.\n[0-5s]\none\n[5-10s]\ntwo",
|
||||
chunks=2,
|
||||
chunk_seconds=5,
|
||||
)
|
||||
assert plan["prompts"] == ["Refer to <Picture 1>.\n\none", "Refer to <Picture 1>.\n\ntwo"]
|
||||
assert plan["notes"] == ["Auto detected Timeline", "applied timeline preamble to all chunks"]
|
||||
|
||||
|
||||
def test_timeline_missing_coverage_warns_and_repeats_previous_prompt():
|
||||
plan = make_prompt_plan(
|
||||
mode=PROMPT_MODE_TIMELINE,
|
||||
script="[0-5s]\none",
|
||||
chunks=2,
|
||||
chunk_seconds=5,
|
||||
)
|
||||
assert plan["prompts"] == ["one", "one"]
|
||||
assert any(item["code"] == "H3C-P101" for item in plan["diagnostics"])
|
||||
assert "fallback" in prompt_plan_report(plan)
|
||||
|
||||
|
||||
def test_timeline_leading_gap_uses_earliest_valid_prompt():
|
||||
plan = make_prompt_plan(
|
||||
mode=PROMPT_MODE_TIMELINE,
|
||||
script="[5-10s]\nsecond",
|
||||
chunks=2,
|
||||
chunk_seconds=5,
|
||||
)
|
||||
assert plan["prompts"] == ["second", "second"]
|
||||
assert plan["diagnostics"][0]["code"] == "H3C-P101"
|
||||
|
||||
|
||||
def test_timeline_extra_sections_warn_and_are_ignored():
|
||||
plan = make_prompt_plan(
|
||||
mode=PROMPT_MODE_TIMELINE,
|
||||
script="[0-5s]\none\n[5-10s]\ntwo\n[10-15s]\nextra",
|
||||
chunks=2,
|
||||
chunk_seconds=5,
|
||||
)
|
||||
assert plan["prompts"] == ["one", "two"]
|
||||
assert any(item["code"] == "H3C-P104" for item in plan["diagnostics"])
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("script", "code"),
|
||||
[
|
||||
("[0 to 5s]\none", "H3C-P001"),
|
||||
("[5-5s]\none", "H3C-P002"),
|
||||
("[Chunk 0]\none", "H3C-P004"),
|
||||
("[0-5s]\n", "H3C-P005"),
|
||||
],
|
||||
)
|
||||
def test_invalid_timeline_falls_back_with_actionable_diagnostic(script, code):
|
||||
plan = make_prompt_plan(
|
||||
mode=PROMPT_MODE_TIMELINE,
|
||||
script=script,
|
||||
chunks=2,
|
||||
chunk_seconds=5,
|
||||
)
|
||||
assert plan["mode"] == PROMPT_MODE_FIXED
|
||||
assert plan["prompts"] == [script.strip(), script.strip()]
|
||||
assert plan["diagnostics"][0]["code"] == "H3C-P100"
|
||||
assert code in plan["diagnostics"][0]["message"]
|
||||
|
||||
|
||||
def test_invalid_mixed_timeline_fallback_preserves_original_text():
|
||||
script = "[Chunk 0]\nA\n---\nB"
|
||||
plan = make_prompt_plan(
|
||||
mode=PROMPT_FORMAT_TIMELINE,
|
||||
script=script,
|
||||
chunks=2,
|
||||
chunk_seconds=5,
|
||||
)
|
||||
assert plan["mode"] == PROMPT_MODE_FIXED
|
||||
assert plan["prompts"] == [script, script]
|
||||
assert plan["diagnostics"][0]["code"] == "H3C-P100"
|
||||
|
||||
|
||||
def test_duplicate_chunk_section_falls_back_without_blocking():
|
||||
plan = make_prompt_plan(
|
||||
mode=PROMPT_MODE_TIMELINE,
|
||||
script="[Chunk 1]\none\n[Chunk 1]\ntwo",
|
||||
chunks=2,
|
||||
chunk_seconds=5,
|
||||
)
|
||||
assert plan["mode"] == PROMPT_MODE_FIXED
|
||||
assert any("H3C-P003" in item["message"] for item in plan["diagnostics"])
|
||||
|
||||
|
||||
def test_prompt_preflight_reports_explicit_chunk_sources():
|
||||
plan = make_prompt_plan(
|
||||
mode=PROMPT_MODE_TIMELINE,
|
||||
script="[0-5s]\none\n[5-10s]\ntwo",
|
||||
chunks=2,
|
||||
chunk_seconds=5,
|
||||
)
|
||||
report = prompt_plan_report(plan)
|
||||
assert "Prompt Preflight:" in report
|
||||
assert "Chunk 1 source:" in report
|
||||
assert "Chunk 2 source:" in report
|
||||
|
||||
|
||||
def test_native_h3_chunk_duration_rejects_sub_four_seconds():
|
||||
with pytest.raises(PromptPlanError):
|
||||
make_prompt_plan(mode=PROMPT_MODE_FIXED, script="x", chunks=1, chunk_seconds=3.9)
|
||||
|
||||
|
||||
def test_chunk_duration_accepts_thirty_seconds_and_rejects_above_limit():
|
||||
plan = make_prompt_plan(
|
||||
mode=PROMPT_MODE_FIXED,
|
||||
script="x",
|
||||
chunks=1,
|
||||
chunk_seconds=30.0,
|
||||
)
|
||||
assert plan["chunk_seconds"] == 30.0
|
||||
assert validate_prompt_plan(plan) is plan
|
||||
|
||||
invalid_plan = dict(plan, chunk_seconds=30.1)
|
||||
with pytest.raises(PromptPlanError, match="30.0"):
|
||||
validate_prompt_plan(invalid_plan)
|
||||
|
||||
with pytest.raises(PromptPlanError, match="30.0"):
|
||||
make_prompt_plan(
|
||||
mode=PROMPT_MODE_FIXED,
|
||||
script="x",
|
||||
chunks=1,
|
||||
chunk_seconds=30.1,
|
||||
)
|
||||
|
||||
|
||||
def test_thirty_second_timeline_maps_one_section_to_each_chunk():
|
||||
plan = make_prompt_plan(
|
||||
mode=PROMPT_MODE_TIMELINE,
|
||||
script="[0-30s]\nfirst\n[30-60s]\nsecond",
|
||||
chunks=2,
|
||||
chunk_seconds=30.0,
|
||||
)
|
||||
assert plan["prompts"] == ["first", "second"]
|
||||
|
||||
|
||||
def test_external_prompt_overrides_only_the_connected_clip_and_rehashes_it():
|
||||
plan = make_prompt_plan(mode=PROMPT_MODE_LIST, script="first\n---\nsecond\n---\nthird", chunks=3, chunk_seconds=5)
|
||||
updated = apply_prompt_overrides(plan, [None, "external second", None])
|
||||
assert updated["prompts"] == ["first", "external second", "third"]
|
||||
assert updated["hashes"][0] == plan["hashes"][0]
|
||||
assert updated["hashes"][1] != plan["hashes"][1]
|
||||
assert updated["hashes"][2] == plan["hashes"][2]
|
||||
assert updated["notes"][-1] == "external Clip Prompt input(s): 2"
|
||||
|
||||
|
||||
def test_external_prompt_with_same_text_keeps_the_same_hash():
|
||||
plan = make_prompt_plan(mode=PROMPT_MODE_FIXED, script="same", chunks=2, chunk_seconds=5)
|
||||
assert apply_prompt_overrides(plan, [None, "same"])["hashes"] == plan["hashes"]
|
||||
|
||||
|
||||
def test_external_prompt_accepts_empty_connected_text():
|
||||
plan = make_prompt_plan(mode=PROMPT_MODE_FIXED, script="fallback", chunks=1, chunk_seconds=5)
|
||||
updated = apply_prompt_overrides(plan, [" "])
|
||||
assert updated["prompts"] == [""]
|
||||
|
||||
|
||||
def test_sequence_prompt_precedes_connected_plan_and_legacy_script():
|
||||
connected = make_prompt_plan(mode=PROMPT_FORMAT_FIXED, script="connected plan", chunks=2, chunk_seconds=5)
|
||||
resolved = build_sampler_prompt_plan(prompt_mode=PROMPT_FORMAT_AUTO, prompt_script="legacy", sequence_prompt="first\n---\nsecond", prompt_plan=connected, chunks=2, chunk_seconds=5)
|
||||
assert resolved["prompts"] == ["first", "second"]
|
||||
|
||||
|
||||
def test_connected_plan_precedes_legacy_script_without_sequence_input():
|
||||
connected = make_prompt_plan(mode=PROMPT_FORMAT_FIXED, script="connected plan", chunks=2, chunk_seconds=5)
|
||||
resolved = build_sampler_prompt_plan(prompt_mode=PROMPT_FORMAT_AUTO, prompt_script="legacy", sequence_prompt=None, prompt_plan=connected, chunks=2, chunk_seconds=5)
|
||||
assert resolved == connected
|
||||
|
||||
|
||||
def test_sparse_overrides_replace_only_explicit_clips_and_rehash():
|
||||
plan = make_prompt_plan(mode=PROMPT_FORMAT_FIXED, script="Sequence Prompt", chunks=5, chunk_seconds=5)
|
||||
sparse = validate_sparse_prompt_overrides(parse_sparse_prompt_overrides("[Clip 2]\nclose-up\n\n[Clip 5]\nfinish naturally"), chunks=5)
|
||||
updated = apply_prompt_overrides(plan, [sparse.get(index) for index in range(1, 6)])
|
||||
assert updated["prompts"] == ["Sequence Prompt", "close-up", "Sequence Prompt", "Sequence Prompt", "finish naturally"]
|
||||
assert updated["hashes"][0] == plan["hashes"][0]
|
||||
assert updated["hashes"][1] != plan["hashes"][1]
|
||||
assert updated["hashes"][2] == plan["hashes"][2]
|
||||
assert updated["hashes"][3] == plan["hashes"][3]
|
||||
assert updated["hashes"][4] != plan["hashes"][4]
|
||||
|
||||
|
||||
def test_sparse_override_clip_one_leaves_remaining_clips_unchanged():
|
||||
plan = make_prompt_plan(mode=PROMPT_FORMAT_FIXED, script="base", chunks=5, chunk_seconds=5)
|
||||
sparse = validate_sparse_prompt_overrides(parse_sparse_prompt_overrides("[Clip 1]\nopening override"), chunks=5)
|
||||
updated = apply_prompt_overrides(plan, [sparse.get(index) for index in range(1, 6)])
|
||||
assert updated["prompts"] == ["opening override", "base", "base", "base", "base"]
|
||||
|
||||
|
||||
def test_sparse_override_rejects_out_of_range_clip():
|
||||
sparse = parse_sparse_prompt_overrides("[Clip 6]\noutside")
|
||||
with pytest.raises(PromptPlanError, match="outside"):
|
||||
validate_sparse_prompt_overrides(sparse, chunks=5)
|
||||
|
||||
|
||||
def test_sparse_override_rejects_duplicate_clip():
|
||||
with pytest.raises(PromptPlanError, match="more than once"):
|
||||
parse_sparse_prompt_overrides("[Clip 2]\nfirst\n\n[Chunk 2]\nsecond")
|
||||
|
||||
|
||||
def test_sparse_override_rejects_timeline_preamble():
|
||||
with pytest.raises(PromptPlanError, match="before the first"):
|
||||
parse_sparse_prompt_overrides("global text\n[Clip 1]\nopening override")
|
||||
@@ -0,0 +1,40 @@
|
||||
from ComfyUI_H3_Continuum_Join.constants import (
|
||||
PROMPT_FORMAT_OPTIONS,
|
||||
SEAM_CORRECTION_AUTO,
|
||||
)
|
||||
from ComfyUI_H3_Continuum_Join.v2.nodes import NODE_CLASS_MAPPINGS
|
||||
|
||||
|
||||
def test_v2_nodes_remain_available_in_the_internal_module():
|
||||
expected = {
|
||||
"H3ContinuumSamplerV2",
|
||||
"H3ContinuumPromptPlanPreview",
|
||||
"H3ContinuumSaveSession",
|
||||
"H3ContinuumLoadSession",
|
||||
"H3ContinuumSessionInfo",
|
||||
}
|
||||
assert expected.issubset(NODE_CLASS_MAPPINGS)
|
||||
|
||||
|
||||
def test_v2_sampler_accepts_connectable_prompt_plan():
|
||||
schema = NODE_CLASS_MAPPINGS["H3ContinuumSamplerV2"].INPUT_TYPES()
|
||||
assert "prompt_plan" in schema["optional"]
|
||||
|
||||
|
||||
def test_v2_sampler_registers_preview_setting_bridge_and_sixteen_prompt_inputs():
|
||||
schema = NODE_CLASS_MAPPINGS["H3ContinuumSamplerV2"].INPUT_TYPES()
|
||||
optional = schema["optional"]
|
||||
assert schema["required"]["prompt_mode"][0] == PROMPT_FORMAT_OPTIONS
|
||||
assert schema["required"]["prompt_mode"][1]["default"] == "Auto"
|
||||
assert optional["sequence_prompt"][0] == "STRING"
|
||||
assert optional["sequence_prompt"][1]["forceInput"] is True
|
||||
assert optional["show_preview"][1]["default"] is True
|
||||
for index in range(1, 17):
|
||||
prompt_input = optional[f"clip_{index}_prompt"]
|
||||
assert prompt_input[0] == "STRING"
|
||||
assert prompt_input[1]["forceInput"] is True
|
||||
|
||||
|
||||
def test_v2_sampler_defaults_to_auto_seam_correction():
|
||||
schema = NODE_CLASS_MAPPINGS["H3ContinuumSamplerV2"].INPUT_TYPES()
|
||||
assert schema["required"]["seam_correction"][1]["default"] == SEAM_CORRECTION_AUTO
|
||||
+127
@@ -0,0 +1,127 @@
|
||||
import torch
|
||||
|
||||
from ComfyUI_H3_Continuum_Join.v2.seam_guard import (
|
||||
analyze_audio_seam,
|
||||
apply_color_guard,
|
||||
choose_adaptive_cut,
|
||||
choose_video_blend,
|
||||
correct_audio_seam,
|
||||
correct_seam,
|
||||
)
|
||||
from ComfyUI_H3_Continuum_Join.v2.seam_types import VideoSeamMetrics
|
||||
|
||||
|
||||
def _frames(values):
|
||||
return torch.tensor(values, dtype=torch.float32).reshape(-1, 1, 1, 1).expand(-1, 12, 12, 3).clone()
|
||||
|
||||
|
||||
def test_adaptive_cut_detects_a_two_frame_earlier_clean_boundary():
|
||||
previous = _frames([0.0, 0.0, 0.0, 0.05, 0.10, 0.20, 0.30, 0.40])
|
||||
current = _frames([0.05, 0.10, 0.95, 0.205, 0.21, 0.90, 0.90, 0.90])
|
||||
|
||||
rewind, legacy, selected = choose_adaptive_cut(
|
||||
previous,
|
||||
current,
|
||||
context_frames=5,
|
||||
)
|
||||
|
||||
assert rewind == 2
|
||||
assert selected.score < legacy.score
|
||||
|
||||
|
||||
def test_corrected_cut_preserves_the_total_frame_count():
|
||||
previous = _frames([0.0, 0.0, 0.0, 0.05, 0.10, 0.20, 0.30, 0.40])
|
||||
current = _frames([0.05, 0.10, 0.95, 0.205, 0.21, 0.90, 0.90, 0.90])
|
||||
corrected, decision, _patch = correct_seam(
|
||||
previous,
|
||||
current,
|
||||
context_frames=5,
|
||||
)
|
||||
legacy_total = previous.shape[0] + current.shape[0] - 5
|
||||
corrected_total = (
|
||||
previous.shape[0] - decision.cut_rewind_frames + corrected.shape[0]
|
||||
)
|
||||
assert corrected_total == legacy_total
|
||||
|
||||
|
||||
def test_auto_keeps_a_clean_legacy_video_boundary():
|
||||
previous = _frames([0.2, 0.2, 0.2, 0.2])
|
||||
current = _frames([0.2, 0.2, 0.2, 0.2])
|
||||
|
||||
corrected, decision, patch = correct_seam(
|
||||
previous,
|
||||
current,
|
||||
context_frames=2,
|
||||
automatic=True,
|
||||
)
|
||||
|
||||
assert torch.equal(corrected, current[2:])
|
||||
assert decision.cut_rewind_frames == 0
|
||||
assert decision.corrected_score == decision.legacy_score
|
||||
assert decision.fallback_reason.startswith("Auto kept native video")
|
||||
assert patch is None
|
||||
|
||||
|
||||
def test_high_motion_disables_video_blend():
|
||||
metrics = VideoSeamMetrics(
|
||||
pixel_mae_norm=0.1,
|
||||
luma_norm=0.1,
|
||||
chroma_norm=0.1,
|
||||
edge_norm=0.1,
|
||||
temporal_norm=0.1,
|
||||
motion=0.2,
|
||||
score=0.1,
|
||||
)
|
||||
assert choose_video_blend(metrics) == 0
|
||||
|
||||
|
||||
def test_excessive_color_request_is_not_applied():
|
||||
previous = _frames([0.01, 0.01])
|
||||
current = _frames([1.0, 1.0, 1.0, 1.0])
|
||||
corrected, gain, bias, _metrics = apply_color_guard(previous, current)
|
||||
assert gain == 1.0
|
||||
assert bias == (0.0, 0.0, 0.0)
|
||||
assert torch.equal(corrected, current)
|
||||
|
||||
|
||||
def test_audio_seam_uses_one_offset_for_all_stereo_channels_and_keeps_a_local_patch():
|
||||
sample_rate = 1000
|
||||
time = torch.arange(800, dtype=torch.float32) / sample_rate
|
||||
signal = torch.sin(2.0 * torch.pi * 20.0 * time)
|
||||
previous = torch.stack((signal[:500], signal[:500]), dim=0).unsqueeze(0)
|
||||
current = torch.stack((signal, signal), dim=0).unsqueeze(0)
|
||||
|
||||
patch, metrics, fade_samples, _gain, _dc = correct_audio_seam(
|
||||
previous,
|
||||
current,
|
||||
sample_rate=sample_rate,
|
||||
cut_sample=500,
|
||||
)
|
||||
|
||||
assert isinstance(metrics.offset_samples, int)
|
||||
assert fade_samples <= round(sample_rate * 0.060)
|
||||
if patch is not None:
|
||||
assert patch.shape[1] == 2
|
||||
assert patch.shape[-1] == fade_samples
|
||||
|
||||
|
||||
def test_audio_seam_diagnostics_do_not_modify_input_waveforms():
|
||||
sample_rate = 1000
|
||||
time = torch.arange(800, dtype=torch.float32) / sample_rate
|
||||
signal = torch.sin(2.0 * torch.pi * 20.0 * time)
|
||||
previous = torch.stack((signal[:500], signal[:500]), dim=0).unsqueeze(0)
|
||||
current = torch.stack((signal, signal), dim=0).unsqueeze(0)
|
||||
previous_before = previous.clone()
|
||||
current_before = current.clone()
|
||||
|
||||
metrics = analyze_audio_seam(
|
||||
previous,
|
||||
current,
|
||||
sample_rate=sample_rate,
|
||||
cut_sample=500,
|
||||
)
|
||||
|
||||
assert -1.0 <= metrics.correlation_before <= 1.0
|
||||
assert isinstance(metrics.offset_samples, int)
|
||||
assert torch.equal(previous, previous_before)
|
||||
assert torch.equal(current, current_before)
|
||||
@@ -0,0 +1,46 @@
|
||||
import torch
|
||||
|
||||
from ComfyUI_H3_Continuum_Join.constants import (
|
||||
STATE_MAGIC,
|
||||
V2_CONTINUITY_AUTO,
|
||||
)
|
||||
from ComfyUI_H3_Continuum_Join.v2.motion import choose_context_frames, latent_motion_score
|
||||
from ComfyUI_H3_Continuum_Join.v2.seeds import derive_chunk_seed
|
||||
|
||||
|
||||
def _state(video):
|
||||
return {
|
||||
"magic": STATE_MAGIC,
|
||||
"schema_version": 1,
|
||||
"clip_index": 1,
|
||||
"source_frame_count": 124,
|
||||
"capacity_frames": 39,
|
||||
"width": 96,
|
||||
"height": 64,
|
||||
"video_tail": video,
|
||||
"audio_tail": torch.zeros(1, 32, 2, 65),
|
||||
"audio_overhang": 1.0 / 3.0,
|
||||
"source_mode": "latent_direct",
|
||||
}
|
||||
|
||||
|
||||
def test_chunk_seeds_are_stable_and_independent():
|
||||
values = [derive_chunk_seed(123, i, 0) for i in range(4)]
|
||||
assert values == [derive_chunk_seed(123, i, 0) for i in range(4)]
|
||||
assert len(set(values)) == 4
|
||||
rerolled = [derive_chunk_seed(123, i, 1) for i in range(4)]
|
||||
assert values != rerolled
|
||||
|
||||
|
||||
def test_auto_context_selects_static_and_dynamic_profiles():
|
||||
static_state = _state(torch.ones(1, 24, 12, 4, 6))
|
||||
assert latent_motion_score(static_state) == 0.0
|
||||
frames, _score, _reason = choose_context_frames(V2_CONTINUITY_AUTO, static_state)
|
||||
assert frames == 5
|
||||
|
||||
dynamic = torch.zeros(1, 24, 12, 4, 6)
|
||||
dynamic[:, :, 1::2] = 10
|
||||
dynamic_state = _state(dynamic)
|
||||
frames, score, _reason = choose_context_frames(V2_CONTINUITY_AUTO, dynamic_state)
|
||||
assert score > 0.12
|
||||
assert frames == 39
|
||||
@@ -0,0 +1,99 @@
|
||||
from types import SimpleNamespace
|
||||
import hashlib
|
||||
import torch
|
||||
from ComfyUI_H3_Continuum_Join.constants import CONTINUUM_INTEROP_KEY, DIAGNOSTICS_BASIC, PROMPT_MODE_FIXED, V2_CONTINUITY_OPTIONS
|
||||
from ComfyUI_H3_Continuum_Join.temporal import audio_latent_t, video_latent_t
|
||||
from ComfyUI_H3_Continuum_Join.v2.h3_builder import IdentityAssets, _tensor_fingerprint, encode_prompt_conditioning
|
||||
from ComfyUI_H3_Continuum_Join.v2.prompts import make_prompt_plan
|
||||
from ComfyUI_H3_Continuum_Join.v2 import sequence
|
||||
|
||||
class Nested:
|
||||
def __init__(self,parts): self.parts=list(parts)
|
||||
def unbind(self): return self.parts
|
||||
|
||||
def _latent(width,height,frames):
|
||||
return {"samples":Nested((torch.zeros(1,24,video_latent_t(frames),height//16,width//16),torch.zeros(1,32,2,audio_latent_t(frames))))}
|
||||
class FakeClip:
|
||||
def __init__(self,events): self.events=events
|
||||
def tokenize(self,prompt,images): self.events.append(("tokenize",prompt,len(images))); return prompt
|
||||
def encode_from_tokens_scheduled(self,tokens): self.events.append(("encode",tokens)); return [[torch.zeros(1,1,2),{}]]
|
||||
|
||||
|
||||
class ReferenceAudioClip:
|
||||
def __init__(self):
|
||||
self.tokenize_options = None
|
||||
|
||||
def tokenize(self, prompt, **kwargs):
|
||||
self.tokenize_options = kwargs
|
||||
return prompt
|
||||
|
||||
def encode_from_tokens_scheduled(self, tokens):
|
||||
return [[torch.zeros(1, 1, 2), {}]]
|
||||
|
||||
|
||||
def test_identity_fingerprint_hashes_full_resized_rgb_tensor():
|
||||
image = torch.zeros((1, 96, 64, 3), dtype=torch.float32)
|
||||
image[0, 95, 63, 2] = 1.0
|
||||
digest = hashlib.sha256()
|
||||
digest.update(str(tuple(image.shape)).encode("ascii"))
|
||||
digest.update(str(image.dtype).encode("ascii"))
|
||||
digest.update(image.contiguous().view(torch.uint8).numpy().tobytes(order="C"))
|
||||
assert _tensor_fingerprint(image) == digest.hexdigest()
|
||||
|
||||
|
||||
def test_first_last_and_reference_audio_use_ordered_tokenizer_items_only():
|
||||
first = torch.zeros((1, 32, 32, 3))
|
||||
last = torch.ones((1, 32, 32, 3))
|
||||
audio_latent = torch.zeros((1, 32, 2, 1))
|
||||
clip = ReferenceAudioClip()
|
||||
|
||||
conditioning = encode_prompt_conditioning(
|
||||
clip,
|
||||
"Use <Picture 1>, <Picture 2>, and <Audio 1>.",
|
||||
first_image=first,
|
||||
last_image=last,
|
||||
reference_audio_assets=SimpleNamespace(audio_latent=audio_latent),
|
||||
)
|
||||
|
||||
items = clip.tokenize_options["minimax_ref_items"]
|
||||
assert [item["type"] for item in items] == ["image", "image", "audio"]
|
||||
assert items[0]["data"] is first
|
||||
assert items[1]["data"] is last
|
||||
assert "images" not in clip.tokenize_options
|
||||
assert conditioning[0][1]["minimax_refs"] == [
|
||||
{"kind": "audio", "ref_audio_t": 1, "audio_latent": audio_latent}
|
||||
]
|
||||
|
||||
def test_v2_samples_every_chunk_before_any_decode(monkeypatch):
|
||||
events=[]; width,height=96,64
|
||||
fake_model=SimpleNamespace(model=SimpleNamespace(diffusion_model=SimpleNamespace()),model_options={},wrappers={},model_dtype=lambda:torch.bfloat16,model_size=lambda:0)
|
||||
assets=IdentityAssets(None,None,None,None,"none")
|
||||
monkeypatch.setattr(sequence,"check_comfy_h3_runtime",lambda:[])
|
||||
def clone_model_for_chunk(model,*,strict,debug,chunk_index,context_frames):
|
||||
options=dict(model.model_options); transformer_options=dict(options.get("transformer_options") or {})
|
||||
if context_frames is not None: transformer_options[CONTINUUM_INTEROP_KEY]={"api":1,"active":True,"min_actual_prefix_steps":2}
|
||||
options["transformer_options"]=transformer_options; events.append(("clone",chunk_index,context_frames))
|
||||
return SimpleNamespace(model=model.model,model_options=options,wrappers=model.wrappers,model_dtype=model.model_dtype,model_size=model.model_size)
|
||||
monkeypatch.setattr(sequence,"clone_model_for_chunk",clone_model_for_chunk)
|
||||
monkeypatch.setattr(sequence,"prepare_identity_assets",lambda *a,**k:assets)
|
||||
monkeypatch.setattr(sequence,"encode_identity_latents",lambda *a,**k:assets)
|
||||
monkeypatch.setattr(sequence,"empty_h3_latent",_latent)
|
||||
monkeypatch.setattr(sequence,"accelerator_summary",lambda model:"accelerators")
|
||||
def sample_chunk(**kwargs):
|
||||
frames=kwargs["latent"]["samples"].unbind()[0].shape[2]; hint=kwargs["model"].model_options["transformer_options"].get(CONTINUUM_INTEROP_KEY); events.append(("sample",int(frames),kwargs["seed"],hint)); return kwargs["latent"]
|
||||
def decode_sequence(**kwargs):
|
||||
events.append(("decode",len(kwargs["entries"]))); return torch.zeros(362,2,2,3),{"waveform":torch.zeros(1,2,round(362/24*32000)),"sample_rate":32000},[]
|
||||
monkeypatch.setattr(sequence,"sample_chunk",sample_chunk); monkeypatch.setattr(sequence,"decode_sequence",decode_sequence)
|
||||
monkeypatch.setattr(sequence,"decode_sequence_with_seam",lambda **kwargs: (_ for _ in ()).throw(AssertionError("Off must not enter the V2.1 seam decoder")))
|
||||
plan=make_prompt_plan(mode=PROMPT_MODE_FIXED,script="continuous shot",chunks=3,chunk_seconds=5.0)
|
||||
images,audio,last_state,session,report=sequence.run_sequence(model=fake_model,clip=FakeClip(events),video_vae=object(),audio_vae=object(),sampler=object(),sigmas=torch.tensor([1.0,0.0]),first_frame=None,last_frame=None,prompt_plan=plan,width=width,height=height,continuity=V2_CONTINUITY_OPTIONS[1],base_seed=42,audio_continuity=True,exact_total_duration=True,diagnostics_mode=DIAGNOSTICS_BASIC,reroll_from_chunk=0,reroll_nonce=0,strict_compatibility=True,debug=False)
|
||||
sample_positions=[i for i,e in enumerate(events) if e[0]=="sample"]; decode_position=next(i for i,e in enumerate(events) if e[0]=="decode")
|
||||
assert len(sample_positions)==3 and max(sample_positions)<decode_position
|
||||
sample_events=[e for e in events if e[0]=="sample"]
|
||||
assert sample_events[0][3] is None
|
||||
assert sample_events[1][3]["min_actual_prefix_steps"]==2 and sample_events[2][3]["min_actual_prefix_steps"]==2
|
||||
assert [e[2] for e in events if e[0]=="clone"]==[None,22,22]
|
||||
assert sum(e[0]=="encode" for e in events)==1
|
||||
assert images.shape[0]==360 and audio["waveform"].shape[-1]==480000
|
||||
assert last_state["clip_index"]==3 and len(session["chunks"])==3
|
||||
assert "call-local MODEL clone per chunk" in report
|
||||
+112
@@ -0,0 +1,112 @@
|
||||
import torch
|
||||
|
||||
from ComfyUI_H3_Continuum_Join.state import make_plan
|
||||
from ComfyUI_H3_Continuum_Join.v2 import session_io
|
||||
from ComfyUI_H3_Continuum_Join.v2.session import (
|
||||
entry_to_state,
|
||||
make_chunk_entry,
|
||||
make_session,
|
||||
validate_session,
|
||||
)
|
||||
|
||||
|
||||
def _latent(frame_count=124):
|
||||
import sys
|
||||
from types import ModuleType
|
||||
|
||||
# The session entry accepts a ComfyUI-like object exposing unbind().
|
||||
class Nested:
|
||||
def __init__(self, parts):
|
||||
self.parts = parts
|
||||
def unbind(self):
|
||||
return self.parts
|
||||
|
||||
video_t = 37 if frame_count == 124 else 42
|
||||
audio_t = 207 if frame_count == 124 else 235
|
||||
return {
|
||||
"samples": Nested(
|
||||
(
|
||||
torch.randn(1, 24, video_t, 4, 6),
|
||||
torch.randn(1, 32, 2, audio_t),
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
def test_session_roundtrip_and_last_state(tmp_path, monkeypatch):
|
||||
plan = make_plan(
|
||||
continuation=False,
|
||||
clip_index=1,
|
||||
total_frames=124,
|
||||
trim_frames=0,
|
||||
width=96,
|
||||
height=64,
|
||||
context_frames=22,
|
||||
state_capacity_frames=39,
|
||||
requested_extend_seconds=5,
|
||||
debug=False,
|
||||
)
|
||||
entry = make_chunk_entry(
|
||||
latent=_latent(),
|
||||
plan=plan,
|
||||
prompt="p",
|
||||
prompt_hash="0" * 64,
|
||||
seed=1,
|
||||
context_frames=0,
|
||||
motion_score=0.0,
|
||||
reused=False,
|
||||
)
|
||||
session = make_session(
|
||||
chunks=[entry],
|
||||
width=96,
|
||||
height=64,
|
||||
chunk_seconds=5,
|
||||
identity_hash="none",
|
||||
model_fingerprint_value="f" * 64,
|
||||
parent_session_id=None,
|
||||
reroll_from_chunk=0,
|
||||
settings={},
|
||||
)
|
||||
validate_session(session)
|
||||
state = entry_to_state(session["chunks"][0])
|
||||
assert state["capacity_frames"] == 39
|
||||
|
||||
monkeypatch.setattr(session_io, "session_directory", lambda: tmp_path)
|
||||
tensor_path, json_path = session_io.save_session(session, prefix="test", slot=1)
|
||||
assert tensor_path.exists() and json_path.exists()
|
||||
loaded = session_io.load_session(prefix="test", slot=1)
|
||||
assert torch.equal(loaded["chunks"][0]["video"], session["chunks"][0]["video"])
|
||||
assert loaded["session_id"] == session["session_id"]
|
||||
|
||||
def test_model_fingerprint_can_add_continuum_wrapper_without_mutating_model():
|
||||
from types import SimpleNamespace
|
||||
|
||||
from ComfyUI_H3_Continuum_Join.v2.session import model_fingerprint
|
||||
|
||||
base = SimpleNamespace(diffusion_model=object())
|
||||
model = SimpleNamespace(
|
||||
model=base,
|
||||
model_options={"transformer_options": {}},
|
||||
wrappers={},
|
||||
model_dtype=lambda: "float32",
|
||||
model_size=lambda: 1,
|
||||
)
|
||||
wrapped = SimpleNamespace(
|
||||
model=base,
|
||||
model_options={"transformer_options": {}},
|
||||
wrappers={
|
||||
"apply_model": {
|
||||
"h3_continuum_join.apply_model.v1": [object()],
|
||||
}
|
||||
},
|
||||
model_dtype=model.model_dtype,
|
||||
model_size=model.model_size,
|
||||
)
|
||||
|
||||
logical = model_fingerprint(
|
||||
model,
|
||||
extra_wrapper_keys=("h3_continuum_join.apply_model.v1",),
|
||||
)
|
||||
|
||||
assert logical == model_fingerprint(wrapped)
|
||||
assert model.wrappers == {}
|
||||
@@ -0,0 +1,210 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
import torch
|
||||
|
||||
from ComfyUI_H3_Continuum_Join.v2.sequence import (
|
||||
_atomic_terminal_prefix,
|
||||
_split_terminal_merged_latents,
|
||||
_terminal_flf_merge_enabled,
|
||||
_terminal_pair_prompt,
|
||||
_terminal_physical_seed_plan,
|
||||
_terminal_pair_contract,
|
||||
_terminal_sampling_plan,
|
||||
_terminal_strategy_mismatch,
|
||||
)
|
||||
from ComfyUI_H3_Continuum_Join.v2.seeds import derive_chunk_seed
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("initial_pair", "physical_frames", "logical_frames", "video_slices", "audio_slices"),
|
||||
[
|
||||
(True, 243, (124, 141), ((0, 37), (30, 72)), ((0, 207), (170, 405))),
|
||||
(False, 260, (141, 141), ((0, 42), (35, 77)), ((0, 235), (198, 433))),
|
||||
],
|
||||
)
|
||||
def test_terminal_pair_contract_uses_native_temporal_grid(
|
||||
initial_pair,
|
||||
physical_frames,
|
||||
logical_frames,
|
||||
video_slices,
|
||||
audio_slices,
|
||||
):
|
||||
contract = _terminal_pair_contract(initial_pair=initial_pair, chunk_seconds=5.0)
|
||||
assert contract["physical_frames"] == physical_frames
|
||||
assert contract["logical_frames"] == logical_frames
|
||||
assert contract["video_slices"] == video_slices
|
||||
assert contract["audio_slices"] == audio_slices
|
||||
|
||||
|
||||
@pytest.mark.parametrize("initial_pair", [True, False])
|
||||
def test_terminal_pair_split_preserves_expected_overlap(initial_pair):
|
||||
contract = _terminal_pair_contract(initial_pair=initial_pair, chunk_seconds=5.0)
|
||||
video_t = contract["video_slices"][-1][1]
|
||||
audio_t = contract["audio_slices"][-1][1]
|
||||
video = torch.arange(video_t, dtype=torch.float32).reshape(1, 1, video_t, 1, 1)
|
||||
audio = torch.arange(audio_t, dtype=torch.float32).reshape(1, 1, 1, audio_t)
|
||||
first, second = _split_terminal_merged_latents(video, audio, contract)
|
||||
assert first[0].shape[2] == contract["video_slices"][0][1]
|
||||
assert first[1].shape[-1] == contract["audio_slices"][0][1]
|
||||
assert second[0][0, 0, 0, 0, 0].item() == contract["video_slices"][1][0]
|
||||
assert second[1][0, 0, 0, 0].item() == contract["audio_slices"][1][0]
|
||||
|
||||
|
||||
def test_two_by_five_uses_one_physical_sample():
|
||||
normal, terminal = _terminal_sampling_plan(chunks=2, completed=0, merge_enabled=True)
|
||||
assert normal == ()
|
||||
assert terminal is True
|
||||
assert len(normal) + int(terminal) == 1
|
||||
|
||||
|
||||
def test_three_by_five_uses_one_normal_and_one_terminal_sample():
|
||||
normal, terminal = _terminal_sampling_plan(chunks=3, completed=0, merge_enabled=True)
|
||||
assert normal == (0,)
|
||||
assert terminal is True
|
||||
assert len(normal) + int(terminal) == 2
|
||||
|
||||
|
||||
def test_terminal_merge_accepts_distinct_prompts_but_not_timeline_video():
|
||||
common = dict(multi_chunk_flf=True, chunks=2, chunk_seconds=5.0)
|
||||
assert _terminal_flf_merge_enabled(**common, prompt_hashes=["same", "same"], timeline_video_source=None)
|
||||
assert _terminal_flf_merge_enabled(**common, prompt_hashes=["a", "b"], timeline_video_source=None)
|
||||
assert not _terminal_flf_merge_enabled(**common, prompt_hashes=["same", "same"], timeline_video_source=object())
|
||||
|
||||
|
||||
def test_terminal_pair_prompt_preserves_shared_prompt_exactly():
|
||||
prompt, policy = _terminal_pair_prompt(["same", "same"], pair_start=0, chunk_seconds=5.0)
|
||||
assert prompt == "same"
|
||||
assert policy == "shared_prompt_v1"
|
||||
|
||||
|
||||
def test_terminal_pair_prompt_rebases_distinct_sections_to_local_timeline():
|
||||
prompt, policy = _terminal_pair_prompt(["first action", "second action"], pair_start=0, chunk_seconds=5.0)
|
||||
assert prompt == "[0-5s]\nfirst action\n\n[5-10s]\nsecond action"
|
||||
assert policy == "paired_timeline_v1"
|
||||
|
||||
|
||||
def test_partial_terminal_pair_is_discarded_for_atomic_resume():
|
||||
preserved = [{"chunk": 1}, {"chunk": 2}]
|
||||
result, reset = _atomic_terminal_prefix(preserved, chunks=3, reroll_from_chunk=0)
|
||||
assert result == preserved[:1]
|
||||
assert reset is True
|
||||
|
||||
|
||||
def test_rerolling_final_chunk_regenerates_both_terminal_chunks():
|
||||
preserved = [{"chunk": 1}, {"chunk": 2}, {"chunk": 3}]
|
||||
result, reset = _atomic_terminal_prefix(preserved, chunks=3, reroll_from_chunk=3)
|
||||
assert result == preserved[:1]
|
||||
assert reset is True
|
||||
|
||||
|
||||
def test_two_chunk_terminal_cache_extended_to_three_reuses_one_generates_two():
|
||||
preserved = [{"chunk": 1}, {"chunk": 2}]
|
||||
|
||||
reusable, reset = _atomic_terminal_prefix(
|
||||
preserved,
|
||||
chunks=3,
|
||||
reroll_from_chunk=3,
|
||||
)
|
||||
normal, terminal = _terminal_sampling_plan(
|
||||
chunks=3,
|
||||
completed=len(reusable),
|
||||
merge_enabled=True,
|
||||
)
|
||||
|
||||
assert reusable == preserved[:1]
|
||||
assert reset is True
|
||||
assert normal == ()
|
||||
assert terminal is True
|
||||
assert (len(reusable), 2) == (1, 2)
|
||||
|
||||
|
||||
def test_complete_terminal_pair_remains_reusable_without_reroll():
|
||||
preserved = [{"chunk": 1}, {"chunk": 2}, {"chunk": 3}]
|
||||
result, reset = _atomic_terminal_prefix(preserved, chunks=3, reroll_from_chunk=0)
|
||||
assert result == preserved
|
||||
assert reset is False
|
||||
|
||||
|
||||
def test_non_terminal_flf_keeps_run_storage_validated_prefix_without_terminal_strategy():
|
||||
session = {"settings": {"run_storage_validated_prefix": True}}
|
||||
|
||||
assert not _terminal_strategy_mismatch(session, merge_enabled=False)
|
||||
|
||||
|
||||
def test_terminal_merge_rejects_prefix_without_matching_strategy():
|
||||
session = {"settings": {"run_storage_validated_prefix": True}}
|
||||
|
||||
assert _terminal_strategy_mismatch(session, merge_enabled=True)
|
||||
|
||||
|
||||
def test_terminal_merge_keeps_prefix_with_matching_strategy():
|
||||
session = {
|
||||
"settings": {
|
||||
"run_storage_validated_prefix": True,
|
||||
"flf_execution": "terminal_merged_10s_seed_v2",
|
||||
}
|
||||
}
|
||||
|
||||
assert not _terminal_strategy_mismatch(session, merge_enabled=True)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("base_seed", [42, 123456789])
|
||||
def test_initial_terminal_pair_uses_base_seed_directly(base_seed):
|
||||
plan = _terminal_physical_seed_plan(
|
||||
base_seed=base_seed,
|
||||
physical_window_start_index=0,
|
||||
reroll_nonce=0,
|
||||
)
|
||||
assert plan["physical_seed"] == base_seed
|
||||
assert plan["logical_entry_seeds"] == (base_seed, base_seed)
|
||||
|
||||
|
||||
def test_later_terminal_pair_derives_once_from_pair_start():
|
||||
plan = _terminal_physical_seed_plan(
|
||||
base_seed=42,
|
||||
physical_window_start_index=2,
|
||||
reroll_nonce=0,
|
||||
)
|
||||
assert plan["physical_seed"] == derive_chunk_seed(42, 2, 0)
|
||||
assert plan["physical_seed"] == 1808285636802909398
|
||||
assert plan["logical_entry_seeds"] == (plan["physical_seed"],) * 2
|
||||
|
||||
|
||||
def test_terminal_pair_reroll_derives_once_and_shares_new_seed():
|
||||
original = _terminal_physical_seed_plan(
|
||||
base_seed=42,
|
||||
physical_window_start_index=2,
|
||||
reroll_nonce=0,
|
||||
)
|
||||
rerolled = _terminal_physical_seed_plan(
|
||||
base_seed=42,
|
||||
physical_window_start_index=2,
|
||||
reroll_nonce=1,
|
||||
)
|
||||
assert rerolled["physical_seed"] == derive_chunk_seed(42, 2, 1)
|
||||
assert rerolled["physical_seed"] == 4306926667627841302
|
||||
assert rerolled["physical_seed"] != original["physical_seed"]
|
||||
assert rerolled["logical_entry_seeds"] == (rerolled["physical_seed"],) * 2
|
||||
|
||||
|
||||
def test_non_terminal_seed_derivation_golden_values_are_unchanged():
|
||||
assert derive_chunk_seed(42, 0, 0) == 15348518480342951850
|
||||
assert derive_chunk_seed(42, 1, 0) == 13021120982267964226
|
||||
|
||||
|
||||
def test_last_frame_absent_does_not_enable_terminal_merge():
|
||||
assert not _terminal_flf_merge_enabled(
|
||||
multi_chunk_flf=False,
|
||||
chunks=2,
|
||||
chunk_seconds=5.0,
|
||||
prompt_hashes=["same", "same"],
|
||||
timeline_video_source=None,
|
||||
)
|
||||
|
||||
|
||||
def test_one_chunk_keeps_normal_sampling_and_seed_behavior():
|
||||
normal, terminal = _terminal_sampling_plan(chunks=1, completed=0, merge_enabled=False)
|
||||
assert normal == (0,)
|
||||
assert terminal is False
|
||||
assert derive_chunk_seed(42, normal[0], 0) == 15348518480342951850
|
||||
@@ -0,0 +1,28 @@
|
||||
from ComfyUI_H3_Continuum_Join.constants import DIAGNOSTICS_BASIC
|
||||
from ComfyUI_H3_Continuum_Join.v2.nodes import _repair_v200_example_widget_shift
|
||||
|
||||
|
||||
def test_malformed_v200_example_widget_shift_is_repaired():
|
||||
values = _repair_v200_example_widget_shift(
|
||||
audio_continuity=True,
|
||||
exact_total_duration=DIAGNOSTICS_BASIC,
|
||||
diagnostics=0,
|
||||
reroll_from_chunk=0,
|
||||
reroll_nonce=True,
|
||||
strict_compatibility=False,
|
||||
debug=False,
|
||||
)
|
||||
assert values == (True, True, DIAGNOSTICS_BASIC, 0, 0, True, False)
|
||||
|
||||
|
||||
def test_valid_v2_widget_values_are_unchanged():
|
||||
values = _repair_v200_example_widget_shift(
|
||||
audio_continuity=False,
|
||||
exact_total_duration=False,
|
||||
diagnostics=DIAGNOSTICS_BASIC,
|
||||
reroll_from_chunk=2,
|
||||
reroll_nonce=7,
|
||||
strict_compatibility=True,
|
||||
debug=True,
|
||||
)
|
||||
assert values == (False, False, DIAGNOSTICS_BASIC, 2, 7, True, True)
|
||||
+1219
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,186 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
import torch
|
||||
|
||||
from ComfyUI_H3_Continuum_Join.reference import (
|
||||
REFERENCE_SIZE_MATCH_OUTPUT,
|
||||
ReferenceAssets,
|
||||
ReferenceConditioningError,
|
||||
prepare_reference_assets,
|
||||
validate_reference_prompts,
|
||||
)
|
||||
from ComfyUI_H3_Continuum_Join.reference_audio import validate_reference_audio_prompts
|
||||
from ComfyUI_H3_Continuum_Join.v3 import nodes as v3_nodes
|
||||
|
||||
|
||||
def test_reference_size_is_appended_after_v31_widgets():
|
||||
from pathlib import Path
|
||||
|
||||
source = (Path(__file__).resolve().parents[1] / "v3" / "nodes.py").read_text(
|
||||
encoding="utf-8"
|
||||
)
|
||||
production = source.split("class H3ContinuumSamplerProduction", 1)[1]
|
||||
required = production.split('"optional": {', 1)[0]
|
||||
assert required.index('"run_name"') < required.index('"reference_size"')
|
||||
|
||||
|
||||
def _assets(count: int = 2) -> ReferenceAssets:
|
||||
images = tuple(torch.zeros((1, 32, 32, 3)) for _ in range(count))
|
||||
hashes = tuple(str(index) * 64 for index in range(1, count + 1))
|
||||
return ReferenceAssets(
|
||||
images=images,
|
||||
latents=tuple(None for _ in range(count)),
|
||||
image_hashes=hashes,
|
||||
combined_hash="a" * 64,
|
||||
size_mode=REFERENCE_SIZE_MATCH_OUTPUT,
|
||||
)
|
||||
|
||||
|
||||
def test_reference_contract_contains_metadata_only():
|
||||
contract = _assets().contract
|
||||
assert contract["count"] == 2
|
||||
assert contract["size_mode"] == REFERENCE_SIZE_MATCH_OUTPUT
|
||||
assert contract["image_hashes"] == ["1" * 64, "2" * 64]
|
||||
assert not any(torch.is_tensor(value) for value in contract.values())
|
||||
|
||||
|
||||
@pytest.mark.parametrize("count", (1, 2))
|
||||
def test_v322_reference_contract_json_is_golden_compatible(count):
|
||||
hashes = [str(index) * 64 for index in range(1, count + 1)]
|
||||
assert _assets(count).contract == {
|
||||
"reference_contract_version": 1,
|
||||
"count": count,
|
||||
"size_mode": REFERENCE_SIZE_MATCH_OUTPUT,
|
||||
"image_hashes": hashes,
|
||||
"combined_hash": "a" * 64,
|
||||
}
|
||||
|
||||
|
||||
def test_v323_third_reference_adds_only_the_image_3_extension():
|
||||
contract = _assets(3).contract
|
||||
assert set(contract) == {
|
||||
"reference_contract_version",
|
||||
"count",
|
||||
"size_mode",
|
||||
"image_hashes",
|
||||
"combined_hash",
|
||||
"reference_image_3",
|
||||
}
|
||||
assert contract["reference_image_3"] == {
|
||||
"reference_position": 3,
|
||||
"shape": [1, 32, 32, 3],
|
||||
"dtype": "torch.float32",
|
||||
"sha256": "3" * 64,
|
||||
"preprocess_version": 1,
|
||||
}
|
||||
|
||||
|
||||
def test_unavailable_picture_tags_warn_without_stopping_like_core():
|
||||
assert validate_reference_prompts(["Use <Picture 1> and <Picture 2>."], 2) == ""
|
||||
message = validate_reference_prompts(["Use <Picture 2>."], 1)
|
||||
assert "H3C-P102" in message
|
||||
assert "only 1 active reference image(s) reached the Sampler" in message
|
||||
assert "generation will continue" in message
|
||||
assert "ignored or hallucinated" in message
|
||||
message = validate_reference_prompts(["Use <Picture 3>."], 2)
|
||||
assert "unavailable <Picture 3>" in message
|
||||
assert "generation will continue" in message
|
||||
|
||||
|
||||
def test_missing_picture_tag_is_a_warning_not_an_error():
|
||||
warning = validate_reference_prompts(["The same person walks forward."], 1)
|
||||
assert "H3C-P103" in warning
|
||||
assert "no <Picture N> tag" in warning
|
||||
|
||||
|
||||
def test_reference_socket_rejects_image_batches():
|
||||
with pytest.raises(ReferenceConditioningError, match="batch size B=1"):
|
||||
prepare_reference_assets(
|
||||
reference_image_1=torch.zeros((2, 32, 32, 3)),
|
||||
reference_image_2=None,
|
||||
output_width=32,
|
||||
output_height=32,
|
||||
size_mode=REFERENCE_SIZE_MATCH_OUTPUT,
|
||||
)
|
||||
|
||||
|
||||
def test_reference_image_3_rejects_image_batches():
|
||||
with pytest.raises(ReferenceConditioningError, match="batch size B=1"):
|
||||
prepare_reference_assets(
|
||||
reference_image_1=torch.zeros((1, 32, 32, 3)),
|
||||
reference_image_2=torch.zeros((1, 32, 32, 3)),
|
||||
reference_image_3=torch.zeros((2, 32, 32, 3)),
|
||||
output_width=32,
|
||||
output_height=32,
|
||||
size_mode=REFERENCE_SIZE_MATCH_OUTPUT,
|
||||
)
|
||||
|
||||
|
||||
def test_three_reference_images_are_ordered_and_contiguous():
|
||||
assets = prepare_reference_assets(
|
||||
reference_image_1=torch.zeros((1, 32, 32, 3)),
|
||||
reference_image_2=torch.ones((1, 32, 32, 3)),
|
||||
reference_image_3=torch.full((1, 32, 32, 3), 0.5),
|
||||
output_width=32,
|
||||
output_height=32,
|
||||
size_mode=REFERENCE_SIZE_MATCH_OUTPUT,
|
||||
)
|
||||
assert assets is not None
|
||||
assert assets.count == 3
|
||||
assert validate_reference_prompts(["Use <Picture 1>, <Picture 2>, and <Picture 3>."], 3) == ""
|
||||
|
||||
|
||||
def test_reference_image_gaps_are_compacted_like_core():
|
||||
first = torch.zeros((1, 32, 32, 3))
|
||||
third = torch.ones((1, 32, 32, 3))
|
||||
assets = prepare_reference_assets(
|
||||
reference_image_1=first,
|
||||
reference_image_2=None,
|
||||
reference_image_3=third,
|
||||
output_width=32,
|
||||
output_height=32,
|
||||
size_mode=REFERENCE_SIZE_MATCH_OUTPUT,
|
||||
)
|
||||
assert assets is not None
|
||||
assert len(assets.images) == 2
|
||||
assert torch.equal(assets.images[0], first)
|
||||
assert torch.equal(assets.images[1], third)
|
||||
|
||||
|
||||
def test_reference_image_2_alone_becomes_picture_1_like_core():
|
||||
second = torch.ones((1, 32, 32, 3))
|
||||
assets = prepare_reference_assets(
|
||||
reference_image_1=None,
|
||||
reference_image_2=second,
|
||||
reference_image_3=None,
|
||||
output_width=32,
|
||||
output_height=32,
|
||||
size_mode=REFERENCE_SIZE_MATCH_OUTPUT,
|
||||
)
|
||||
assert assets is not None
|
||||
assert len(assets.images) == 1
|
||||
assert torch.equal(assets.images[0], second)
|
||||
|
||||
|
||||
def test_unavailable_audio_tags_warn_without_stopping_like_core():
|
||||
message = validate_reference_audio_prompts(
|
||||
["Perform <Audio 1> and <Audio 2>."], None
|
||||
)
|
||||
assert "unavailable <Audio 1>" in message
|
||||
assert "H3C-P102" in message
|
||||
assert "unavailable <Audio 2>" in message
|
||||
assert "generation will continue" in message
|
||||
|
||||
|
||||
def test_connected_audio_keeps_unavailable_extra_tag_as_warning():
|
||||
message = validate_reference_audio_prompts(
|
||||
["Perform <Audio 2>."], object()
|
||||
)
|
||||
assert "unavailable <Audio 2>" in message
|
||||
assert "no <Audio 1> tag" in message
|
||||
assert "H3C-P103" in message
|
||||
|
||||
|
||||
def test_reference_checkpoint_filename_classification_is_removed():
|
||||
assert not hasattr(v3_nodes, "_validate_reference_checkpoint")
|
||||
@@ -0,0 +1,302 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
import torch
|
||||
|
||||
from ComfyUI_H3_Continuum_Join.driving_audio import (
|
||||
DrivingAudioAssets,
|
||||
DrivingAudioSource,
|
||||
attach_driving_audio,
|
||||
encode_driving_audio,
|
||||
prepare_driving_audio_source,
|
||||
slice_driving_audio_latent,
|
||||
)
|
||||
from ComfyUI_H3_Continuum_Join.run_storage import automatic_project_key
|
||||
from ComfyUI_H3_Continuum_Join.reference_video import (
|
||||
REFERENCE_VIDEO_SIZE_BALANCED,
|
||||
REFERENCE_VIDEO_SIZE_EFFICIENT,
|
||||
REFERENCE_VIDEO_SIZE_MATCH_OUTPUT,
|
||||
REFERENCE_VIDEO_SIZE_OPTIONS,
|
||||
_resolved_size,
|
||||
)
|
||||
from ComfyUI_H3_Continuum_Join.v3.assembly import (
|
||||
H3ContinuumAssembleSeamExperimental,
|
||||
)
|
||||
from ComfyUI_H3_Continuum_Join.v3.driving_nodes import (
|
||||
H3ContinuumAssembleSeamV34,
|
||||
H3ContinuumSamplerV34,
|
||||
)
|
||||
|
||||
|
||||
def test_v34_video_reference_schema_uses_image_batch():
|
||||
schema = H3ContinuumSamplerV34.INPUT_TYPES()
|
||||
assert schema["optional"]["reference_video_1"][0] == "IMAGE"
|
||||
size_schema = schema["required"]["video_reference_size"]
|
||||
assert size_schema[0] == REFERENCE_VIDEO_SIZE_OPTIONS
|
||||
assert size_schema[1]["default"] == REFERENCE_VIDEO_SIZE_EFFICIENT
|
||||
|
||||
|
||||
def test_v34_requests_one_chunk_video_reference(monkeypatch):
|
||||
import ComfyUI_H3_Continuum_Join.reference_video as reference_video
|
||||
|
||||
captured = {}
|
||||
|
||||
class _Captured(RuntimeError):
|
||||
pass
|
||||
|
||||
def capture_target(
|
||||
_video,
|
||||
*,
|
||||
target_frames,
|
||||
output_width,
|
||||
output_height,
|
||||
size_mode,
|
||||
):
|
||||
captured["target_frames"] = target_frames
|
||||
captured["output_size"] = (output_width, output_height)
|
||||
captured["size_mode"] = size_mode
|
||||
raise _Captured
|
||||
|
||||
monkeypatch.setattr(
|
||||
reference_video,
|
||||
"prepare_reference_video_source",
|
||||
capture_target,
|
||||
)
|
||||
with pytest.raises(_Captured):
|
||||
H3ContinuumSamplerV34().run(
|
||||
reference_video_1=torch.zeros((243, 8, 8, 3)),
|
||||
driving_audio=None,
|
||||
audio_vae=None,
|
||||
chunks=2,
|
||||
chunk_seconds=5.0,
|
||||
width=800,
|
||||
height=800,
|
||||
video_reference_size=REFERENCE_VIDEO_SIZE_BALANCED,
|
||||
)
|
||||
assert captured["target_frames"] == 124
|
||||
assert captured["output_size"] == (800, 800)
|
||||
assert captured["size_mode"] == REFERENCE_VIDEO_SIZE_BALANCED
|
||||
|
||||
|
||||
def test_video_reference_size_modes_preserve_source_and_avoid_upscale():
|
||||
assert _resolved_size(
|
||||
768,
|
||||
768,
|
||||
output_width=800,
|
||||
output_height=800,
|
||||
size_mode=REFERENCE_VIDEO_SIZE_EFFICIENT,
|
||||
) == (640, 640)
|
||||
assert _resolved_size(
|
||||
768,
|
||||
768,
|
||||
output_width=800,
|
||||
output_height=800,
|
||||
size_mode=REFERENCE_VIDEO_SIZE_BALANCED,
|
||||
) == (768, 768)
|
||||
assert _resolved_size(
|
||||
768,
|
||||
768,
|
||||
output_width=800,
|
||||
output_height=800,
|
||||
size_mode=REFERENCE_VIDEO_SIZE_MATCH_OUTPUT,
|
||||
) == (768, 768)
|
||||
|
||||
|
||||
def test_video_reference_match_output_preserves_source_aspect_ratio():
|
||||
width, height = _resolved_size(
|
||||
1920,
|
||||
1080,
|
||||
output_width=1344,
|
||||
output_height=768,
|
||||
size_mode=REFERENCE_VIDEO_SIZE_MATCH_OUTPUT,
|
||||
)
|
||||
assert width % 32 == 0
|
||||
assert height % 32 == 0
|
||||
assert width <= 1920
|
||||
assert height <= 1080
|
||||
assert abs((width / height) - (1920 / 1080)) < 0.06
|
||||
|
||||
class _AudioVAE:
|
||||
audio_sample_rate = 10
|
||||
|
||||
def __init__(self):
|
||||
self.calls = []
|
||||
|
||||
def encode(self, waveform):
|
||||
self.calls.append(waveform)
|
||||
return torch.arange(400, dtype=torch.float32).reshape(1, 1, 1, 400)
|
||||
|
||||
|
||||
def _audio(seconds: int, *, tail_value: float = 0.0):
|
||||
waveform = torch.zeros((1, 2, seconds * 10), dtype=torch.float32)
|
||||
if seconds > 15:
|
||||
waveform[..., 150:] = tail_value
|
||||
return {"waveform": waveform, "sample_rate": 10}
|
||||
|
||||
|
||||
def test_v34_public_schema_replaces_reference_audio_with_driving_audio():
|
||||
schema = H3ContinuumSamplerV34.INPUT_TYPES()
|
||||
assert "driving_audio" in schema["optional"]
|
||||
assert "audio_vae" in schema["optional"]
|
||||
assert schema["optional"]["reference_video_1"][1]["display_name"] == (
|
||||
"Video Guide Frames"
|
||||
)
|
||||
assert schema["optional"]["driving_audio"][1]["display_name"] == "Driving Audio"
|
||||
assert schema["optional"]["audio_vae"][1]["display_name"] == "Driving Audio VAE"
|
||||
assert schema["required"]["video_reference_size"][1]["display_name"] == (
|
||||
"Video Guide Size"
|
||||
)
|
||||
assert "reference_audio_1" not in schema["optional"]
|
||||
assert "reference_audio_vae" not in schema["optional"]
|
||||
|
||||
from ComfyUI_H3_Continuum_Join import nodes as root_nodes
|
||||
|
||||
assert "H3ContinuumSamplerV34" not in root_nodes.NODE_CLASS_MAPPINGS
|
||||
assert "H3ContinuumSamplerTimelineVideo" not in root_nodes.NODE_CLASS_MAPPINGS
|
||||
|
||||
|
||||
def test_unused_long_audio_tail_does_not_change_contract_or_output():
|
||||
vae = _AudioVAE()
|
||||
first = prepare_driving_audio_source(
|
||||
_audio(30, tail_value=1.0), vae, target_frames=360, fps=24
|
||||
)
|
||||
second = prepare_driving_audio_source(
|
||||
_audio(30, tail_value=9.0), vae, target_frames=360, fps=24
|
||||
)
|
||||
assert first.combined_hash == second.combined_hash
|
||||
assert first.source_audio["waveform"].shape[-1] == 150
|
||||
assert second.source_audio["waveform"].shape[-1] == 150
|
||||
|
||||
|
||||
def test_short_driving_audio_is_accepted_without_padding():
|
||||
source = prepare_driving_audio_source(
|
||||
_audio(4), _AudioVAE(), target_frames=360, fps=24
|
||||
)
|
||||
assert source.source_audio["waveform"].shape == (1, 2, 40)
|
||||
assert source.resampled_waveform.shape == (1, 2, 40)
|
||||
|
||||
|
||||
def test_encode_is_core_layout_and_absolute_slices_are_drift_free():
|
||||
vae = _AudioVAE()
|
||||
source = prepare_driving_audio_source(
|
||||
_audio(30), vae, target_frames=360, fps=24
|
||||
)
|
||||
assets = encode_driving_audio(source, vae)
|
||||
assert len(vae.calls) == 1
|
||||
assert vae.calls[0].shape == (1, 150, 2)
|
||||
|
||||
first = slice_driving_audio_latent(
|
||||
assets,
|
||||
cumulative_retained_before=0,
|
||||
total_frames=124,
|
||||
trim_frames=0,
|
||||
fps=24,
|
||||
)
|
||||
second = slice_driving_audio_latent(
|
||||
assets,
|
||||
cumulative_retained_before=124,
|
||||
total_frames=141,
|
||||
trim_frames=22,
|
||||
fps=24,
|
||||
)
|
||||
third = slice_driving_audio_latent(
|
||||
assets,
|
||||
cumulative_retained_before=243,
|
||||
total_frames=141,
|
||||
trim_frames=22,
|
||||
fps=24,
|
||||
)
|
||||
assert first.flatten()[0].item() == 0
|
||||
assert second.flatten()[0].item() == round(102 * 40 / 24)
|
||||
assert third.flatten()[0].item() == round(221 * 40 / 24)
|
||||
|
||||
|
||||
def test_driving_audio_uses_keyframe_payload_not_audio_reference_tokens():
|
||||
conditioning = [[torch.zeros((1, 2, 3)), {"minimax_ref_items": []}]]
|
||||
latent = torch.zeros((1, 32, 2, 10))
|
||||
output = attach_driving_audio(conditioning, latent)
|
||||
keyframe = output[0][1]["minimax_keyframes"][-1]
|
||||
assert keyframe == {"resolved_frame_index": 0, "audio_latent": latent}
|
||||
assert output[0][1]["minimax_ref_items"] == []
|
||||
|
||||
|
||||
def test_audio_vae_topology_is_ignored_when_driving_audio_is_disconnected():
|
||||
base = {
|
||||
"1": {"class_type": "H3ContinuumSamplerV34", "inputs": {}},
|
||||
"2": {"class_type": "VAELoader", "inputs": {}},
|
||||
}
|
||||
connected_vae_only = {
|
||||
**base,
|
||||
"1": {
|
||||
"class_type": "H3ContinuumSamplerV34",
|
||||
"inputs": {"audio_vae": ["2", 0]},
|
||||
},
|
||||
}
|
||||
assert automatic_project_key(base, "1") == automatic_project_key(
|
||||
connected_vae_only, "1"
|
||||
)
|
||||
|
||||
|
||||
def test_v34_assembler_selects_original_driving_audio_and_bypasses_seam(
|
||||
monkeypatch,
|
||||
):
|
||||
images = torch.zeros((10, 8, 8, 3))
|
||||
generated = {"waveform": torch.ones((1, 2, 20)), "sample_rate": 10}
|
||||
driving = {"waveform": torch.zeros((1, 2, 20)), "sample_rate": 10}
|
||||
|
||||
monkeypatch.setattr(
|
||||
H3ContinuumAssembleSeamExperimental,
|
||||
"assemble",
|
||||
lambda self, *args, **kwargs: (images, generated, "base report"),
|
||||
)
|
||||
output_images, output_audio, report = H3ContinuumAssembleSeamV34().assemble(
|
||||
images=[],
|
||||
audio=[],
|
||||
assembly_plan={"target_frames": 10},
|
||||
exact_total_duration=False,
|
||||
audio_seam="Auto",
|
||||
video_seam="Auto",
|
||||
diagnostics="Basic",
|
||||
driving_audio=driving,
|
||||
)
|
||||
assert output_images is images
|
||||
assert torch.equal(output_audio["waveform"], driving["waveform"])
|
||||
assert "Audio Seam bypassed" in report
|
||||
|
||||
|
||||
def test_v34_assembly_plan_audio_wins_when_direct_input_is_generated_audio(
|
||||
monkeypatch,
|
||||
):
|
||||
images = torch.zeros((10, 8, 8, 3))
|
||||
generated = {
|
||||
"waveform": torch.zeros((1, 2, 320000), dtype=torch.float32),
|
||||
"sample_rate": 32000,
|
||||
}
|
||||
original = {
|
||||
"waveform": torch.linspace(-1.0, 1.0, 480000, dtype=torch.float32)
|
||||
.reshape(1, 1, -1)
|
||||
.repeat(1, 2, 1),
|
||||
"sample_rate": 48000,
|
||||
}
|
||||
plan = {
|
||||
"target_frames": 10,
|
||||
"_h3_continuum_driving_audio_v1": original,
|
||||
}
|
||||
|
||||
monkeypatch.setattr(
|
||||
H3ContinuumAssembleSeamExperimental,
|
||||
"assemble",
|
||||
lambda self, *args, **kwargs: (images, generated, "base report"),
|
||||
)
|
||||
_, output_audio, report = H3ContinuumAssembleSeamV34().assemble(
|
||||
images=[],
|
||||
audio=[],
|
||||
assembly_plan=[plan],
|
||||
exact_total_duration=False,
|
||||
driving_audio=[generated],
|
||||
)
|
||||
|
||||
assert output_audio["sample_rate"] == 48000
|
||||
assert torch.equal(output_audio["waveform"], original["waveform"])
|
||||
assert output_audio["waveform"].data_ptr() != original["waveform"].data_ptr()
|
||||
assert "selected from assembly plan" in report
|
||||
@@ -0,0 +1,142 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from types import SimpleNamespace
|
||||
|
||||
import torch
|
||||
|
||||
from ComfyUI_H3_Continuum_Join.reference import (
|
||||
build_hybrid_presentation_items,
|
||||
combine_hybrid_visual_identity,
|
||||
validate_reference_prompts,
|
||||
)
|
||||
from ComfyUI_H3_Continuum_Join.v2.sequence import _conditioning_cache_key
|
||||
|
||||
|
||||
def _image(value: float) -> torch.Tensor:
|
||||
return torch.full((1, 2, 2, 3), value, dtype=torch.float32)
|
||||
|
||||
|
||||
def test_hybrid_picture_order_first_last_then_references() -> None:
|
||||
first = _image(1.0)
|
||||
last = _image(2.0)
|
||||
ref1 = _image(3.0)
|
||||
ref2 = _image(4.0)
|
||||
items = build_hybrid_presentation_items(
|
||||
[{"type": "image", "data": ref1}, {"type": "image", "data": ref2}],
|
||||
first_image=first,
|
||||
last_image=last,
|
||||
)
|
||||
assert [id(item["data"]) for item in items] == [id(first), id(last), id(ref1), id(ref2)]
|
||||
|
||||
|
||||
def test_hybrid_picture_order_supports_first_only() -> None:
|
||||
first = _image(1.0)
|
||||
ref = _image(2.0)
|
||||
items = build_hybrid_presentation_items(
|
||||
[{"type": "image", "data": ref}],
|
||||
first_image=first,
|
||||
)
|
||||
assert [id(item["data"]) for item in items] == [id(first), id(ref)]
|
||||
|
||||
|
||||
def test_hybrid_picture_order_supports_last_only() -> None:
|
||||
last = _image(1.0)
|
||||
ref = _image(2.0)
|
||||
items = build_hybrid_presentation_items(
|
||||
[{"type": "image", "data": ref}],
|
||||
last_image=last,
|
||||
)
|
||||
assert [id(item["data"]) for item in items] == [id(last), id(ref)]
|
||||
|
||||
|
||||
def test_hybrid_prompt_validation_offsets_reference_numbers() -> None:
|
||||
assert validate_reference_prompts(
|
||||
["<Picture 1> starts the shot and <Picture 3> defines identity."],
|
||||
1,
|
||||
picture_offset=2,
|
||||
) == ""
|
||||
|
||||
|
||||
def test_hybrid_prompt_validation_keeps_public_picture_numbers_in_warnings() -> None:
|
||||
warning = validate_reference_prompts(
|
||||
["<Picture 1> starts the shot and <Picture 4> is unavailable."],
|
||||
1,
|
||||
picture_offset=2,
|
||||
)
|
||||
assert "unavailable <Picture 4>" in warning
|
||||
assert "connected reference <Picture 3>" in warning
|
||||
assert "unavailable <Picture 2>" not in warning
|
||||
|
||||
|
||||
def test_hybrid_prompt_validation_reports_the_missing_reference_number() -> None:
|
||||
warning = validate_reference_prompts(
|
||||
["<Picture 1> starts the shot."],
|
||||
1,
|
||||
picture_offset=2,
|
||||
)
|
||||
assert "connected reference <Picture 3>" in warning
|
||||
assert "the prompt contains no <Picture N> tag" not in warning
|
||||
|
||||
|
||||
def test_pure_fl_identity_is_unchanged() -> None:
|
||||
assert combine_hybrid_visual_identity(
|
||||
keyframe_identity_hash="fl-identity",
|
||||
reference_assets=None,
|
||||
has_first=True,
|
||||
has_last=True,
|
||||
) == "fl-identity"
|
||||
|
||||
|
||||
def test_pure_reference_identity_is_unchanged() -> None:
|
||||
references = SimpleNamespace(combined_hash="reference-identity")
|
||||
assert combine_hybrid_visual_identity(
|
||||
keyframe_identity_hash="unused",
|
||||
reference_assets=references,
|
||||
has_first=False,
|
||||
has_last=False,
|
||||
) == "reference-identity"
|
||||
|
||||
|
||||
def test_hybrid_identity_uses_keyframes_and_references() -> None:
|
||||
references = SimpleNamespace(combined_hash="reference-identity")
|
||||
first = combine_hybrid_visual_identity(
|
||||
keyframe_identity_hash="keyframe-a",
|
||||
reference_assets=references,
|
||||
has_first=True,
|
||||
has_last=False,
|
||||
)
|
||||
second = combine_hybrid_visual_identity(
|
||||
keyframe_identity_hash="keyframe-b",
|
||||
reference_assets=references,
|
||||
has_first=True,
|
||||
has_last=False,
|
||||
)
|
||||
assert first != "keyframe-a"
|
||||
assert first != "reference-identity"
|
||||
assert first != second
|
||||
|
||||
|
||||
def test_hybrid_conditioning_cache_key_reuses_encoded_reference_prompt() -> None:
|
||||
references = SimpleNamespace(count=1)
|
||||
assert _conditioning_cache_key(
|
||||
"final prompt",
|
||||
include_last=True,
|
||||
reference_assets=references,
|
||||
) == ("final prompt", False)
|
||||
|
||||
|
||||
def test_pure_fl_conditioning_cache_key_keeps_final_frame_variant() -> None:
|
||||
assert _conditioning_cache_key(
|
||||
"final prompt",
|
||||
include_last=True,
|
||||
reference_assets=None,
|
||||
) == ("final prompt", True)
|
||||
|
||||
|
||||
def test_pure_reference_conditioning_cache_key_stays_without_last_frame() -> None:
|
||||
references = SimpleNamespace(count=1)
|
||||
assert _conditioning_cache_key(
|
||||
"reference prompt",
|
||||
include_last=False,
|
||||
reference_assets=references,
|
||||
) == ("reference prompt", False)
|
||||
@@ -0,0 +1,154 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import inspect
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
import torch
|
||||
|
||||
from ComfyUI_H3_Continuum_Join.reference_audio import (
|
||||
ReferenceAudioError,
|
||||
prepare_reference_audio_source,
|
||||
)
|
||||
from ComfyUI_H3_Continuum_Join.run_storage import automatic_project_key
|
||||
from ComfyUI_H3_Continuum_Join.v3 import driving_nodes
|
||||
from ComfyUI_H3_Continuum_Join.v3.driving_nodes import (
|
||||
H3ContinuumSamplerV34,
|
||||
H3ContinuumSamplerV35,
|
||||
)
|
||||
from ComfyUI_H3_Continuum_Join.v3.nodes import H3ContinuumSamplerProduction
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
|
||||
|
||||
def test_v35_appends_reference_audio_sockets_without_changing_v34_schema():
|
||||
v34_optional = H3ContinuumSamplerV34.INPUT_TYPES()["optional"]
|
||||
v35_optional = H3ContinuumSamplerV35.INPUT_TYPES()["optional"]
|
||||
|
||||
assert "reference_audio_1" not in v34_optional
|
||||
assert "reference_audio_vae" not in v34_optional
|
||||
assert list(v35_optional)[:-2] == list(v34_optional)
|
||||
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 (Legacy)"
|
||||
)
|
||||
assert v35_optional["reference_audio_vae"][0] == "VAE"
|
||||
assert v35_optional["reference_audio_vae"][1]["display_name"] == (
|
||||
"Reference Audio VAE (Legacy)"
|
||||
)
|
||||
assert "Driving Audio" in v35_optional["reference_audio_1"][1]["tooltip"]
|
||||
|
||||
|
||||
def test_v34_internal_reference_audio_parameters_are_appended_and_forwarded(
|
||||
monkeypatch,
|
||||
):
|
||||
parameters = list(inspect.signature(H3ContinuumSamplerV34.run).parameters)
|
||||
assert parameters[-4:] == [
|
||||
"capture_refine_context",
|
||||
"reference_audio_1",
|
||||
"reference_audio_vae",
|
||||
"kwargs",
|
||||
]
|
||||
|
||||
captured = {}
|
||||
reference_audio = object()
|
||||
reference_audio_vae = object()
|
||||
|
||||
monkeypatch.setattr(
|
||||
driving_nodes,
|
||||
"prepare_driving_audio_source",
|
||||
lambda *_args, **_kwargs: None,
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
"ComfyUI_H3_Continuum_Join.reference_video.prepare_reference_video_source",
|
||||
lambda *_args, **_kwargs: None,
|
||||
)
|
||||
|
||||
def production_run(_self, **kwargs):
|
||||
captured.update(kwargs)
|
||||
return [], [], {}, "status"
|
||||
|
||||
monkeypatch.setattr(H3ContinuumSamplerProduction, "run", production_run)
|
||||
outputs = H3ContinuumSamplerV34().run(
|
||||
reference_audio_1=reference_audio,
|
||||
reference_audio_vae=reference_audio_vae,
|
||||
chunks=1,
|
||||
chunk_seconds=5.0,
|
||||
width=640,
|
||||
height=640,
|
||||
)
|
||||
|
||||
assert captured["reference_audio_1"] is reference_audio
|
||||
assert captured["reference_audio_vae"] is reference_audio_vae
|
||||
assert outputs[-1] is None
|
||||
|
||||
|
||||
def test_v35_run_forwards_reference_audio_without_duplicate_preparation(monkeypatch):
|
||||
captured = {}
|
||||
reference_audio = object()
|
||||
reference_audio_vae = object()
|
||||
|
||||
def v34_run(_self, *args, **kwargs):
|
||||
captured.update(kwargs)
|
||||
return [], [], {}, "status", None, {"groups": ()}
|
||||
|
||||
monkeypatch.setattr(H3ContinuumSamplerV34, "run", v34_run)
|
||||
H3ContinuumSamplerV35().run(
|
||||
reference_audio_1=reference_audio,
|
||||
reference_audio_vae=reference_audio_vae,
|
||||
)
|
||||
|
||||
assert captured["reference_audio_1"] is reference_audio
|
||||
assert captured["reference_audio_vae"] is reference_audio_vae
|
||||
assert captured["capture_refine_context"] is True
|
||||
assert captured["memory_attribution"] is True
|
||||
|
||||
|
||||
def test_reference_audio_vae_is_ignored_without_audio_and_required_with_audio():
|
||||
vae = object()
|
||||
assert prepare_reference_audio_source(None, vae) is None
|
||||
audio = {
|
||||
"waveform": torch.zeros((1, 2, 32000), dtype=torch.float32),
|
||||
"sample_rate": 32000,
|
||||
}
|
||||
with pytest.raises(ReferenceAudioError, match="reference_audio_vae is required"):
|
||||
prepare_reference_audio_source(audio, None)
|
||||
|
||||
|
||||
def test_unused_reference_audio_vae_does_not_change_automatic_project_key():
|
||||
base = {
|
||||
"1": {"class_type": "H3ContinuumSamplerV35", "inputs": {}},
|
||||
"2": {"class_type": "VAELoader", "inputs": {}},
|
||||
}
|
||||
vae_only = {
|
||||
**base,
|
||||
"1": {
|
||||
"class_type": "H3ContinuumSamplerV35",
|
||||
"inputs": {"reference_audio_vae": ["2", 0]},
|
||||
},
|
||||
}
|
||||
assert automatic_project_key(base, "1") == automatic_project_key(vae_only, "1")
|
||||
|
||||
|
||||
def test_published_v35_template_keeps_existing_sampler_socket_routes():
|
||||
template = ROOT / "examples/workflows/MiniMax_H3_Continuum_V35.json"
|
||||
if not template.exists():
|
||||
pytest.skip("published workflow template is not installed in this runtime copy")
|
||||
workflow = json.loads(
|
||||
template.read_text(encoding="utf-8")
|
||||
)
|
||||
sampler = next(
|
||||
node for node in workflow["nodes"] if node["type"] == "H3ContinuumSamplerV35"
|
||||
)
|
||||
routes = {item["name"]: item.get("link") for item in sampler["inputs"]}
|
||||
assert routes["reference_image_1"] == 321
|
||||
assert routes["reference_image_2"] == 320
|
||||
assert routes["reference_image_3"] == 318
|
||||
assert routes["reference_video_1"] == 322
|
||||
assert routes["driving_audio"] == 294
|
||||
assert routes["audio_vae"] == 295
|
||||
assert "reference_audio_1" not in routes
|
||||
assert "reference_audio_vae" not in routes
|
||||
@@ -0,0 +1,166 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import shutil
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
PROJECT_ID_JS = ROOT / "web" / "project_id.js"
|
||||
REFERENCE_AUDIO_UI_JS = ROOT / "web" / "reference_audio_ui.js"
|
||||
def test_v35_keeps_reference_audio_inputs_permanent_after_node_setup():
|
||||
project_source = PROJECT_ID_JS.read_text(encoding="utf-8")
|
||||
reference_source = REFERENCE_AUDIO_UI_JS.read_text(encoding="utf-8")
|
||||
|
||||
assert 'import { normalizeReferenceAudioLabels } from "./reference_audio_ui.js";' in project_source
|
||||
assert "normalizeReferenceAudioLabels(node);" in project_source
|
||||
assert "configureReferenceAudioInputs" not in project_source
|
||||
assert "Reference Audio Inputs" not in reference_source
|
||||
assert "addInput" not in reference_source
|
||||
assert "removeInput" not in reference_source
|
||||
assert "addWidget" not in reference_source
|
||||
assert "onSerialize" not in reference_source
|
||||
|
||||
|
||||
def test_reference_audio_labels_do_not_change_inputs_or_widgets(tmp_path):
|
||||
node = shutil.which("node")
|
||||
assert node is not None, "Node.js is required for frontend behavior validation"
|
||||
|
||||
module_path = tmp_path / "reference_audio_ui.mjs"
|
||||
module_path.write_text(REFERENCE_AUDIO_UI_JS.read_text(encoding="utf-8"), encoding="utf-8")
|
||||
harness_path = tmp_path / "reference_audio_ui_harness.mjs"
|
||||
harness_path.write_text(
|
||||
r'''
|
||||
import assert from "node:assert/strict";
|
||||
import { normalizeReferenceAudioLabels } from "./reference_audio_ui.mjs";
|
||||
|
||||
const inputs = [
|
||||
{ name: "reference_video_1", type: "IMAGE", label: "Video Reference", link: null },
|
||||
{ name: "driving_audio", type: "AUDIO", label: "driving_audio", link: null },
|
||||
{ name: "audio_vae", type: "VAE", label: "audio_vae", link: null },
|
||||
{ name: "reference_audio_1", type: "AUDIO", label: "Reference Audio", link: null },
|
||||
{ name: "reference_audio_vae", type: "VAE", label: "Reference Audio VAE", link: null },
|
||||
{ name: "prompt_mode", type: "COMBO", link: null },
|
||||
];
|
||||
const widgets = [{ name: "prompt_mode", value: "Auto" }];
|
||||
const node = { inputs, widgets };
|
||||
const originalInputs = [...inputs];
|
||||
const originalWidgets = [...widgets];
|
||||
|
||||
assert.equal(normalizeReferenceAudioLabels(node), true);
|
||||
assert.deepEqual(node.inputs, originalInputs);
|
||||
assert.deepEqual(node.widgets, originalWidgets);
|
||||
assert.deepEqual(
|
||||
node.inputs.slice(0, 5).map((input) => input.label),
|
||||
[
|
||||
"Video Guide Frames",
|
||||
"Driving Audio",
|
||||
"Driving Audio VAE",
|
||||
"Reference Audio (Legacy)",
|
||||
"Reference Audio VAE (Legacy)",
|
||||
],
|
||||
);
|
||||
assert.equal(node.inputs[3].name, "reference_audio_1");
|
||||
assert.equal(node.inputs[4].name, "reference_audio_vae");
|
||||
''',
|
||||
encoding="utf-8",
|
||||
)
|
||||
|
||||
result = subprocess.run(
|
||||
[node, str(harness_path)],
|
||||
cwd=tmp_path,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
check=False,
|
||||
)
|
||||
assert result.returncode == 0, result.stdout + result.stderr
|
||||
|
||||
|
||||
def test_workflow_save_reload_preserves_v35_widget_value_alignment(tmp_path):
|
||||
node = shutil.which("node")
|
||||
assert node is not None, "Node.js is required for frontend behavior validation"
|
||||
|
||||
module_path = tmp_path / "reference_audio_ui.mjs"
|
||||
module_path.write_text(REFERENCE_AUDIO_UI_JS.read_text(encoding="utf-8"), encoding="utf-8")
|
||||
harness_path = tmp_path / "workflow_reload_harness.mjs"
|
||||
harness_path.write_text(
|
||||
r'''
|
||||
import assert from "node:assert/strict";
|
||||
import { normalizeReferenceAudioLabels } from "./reference_audio_ui.mjs";
|
||||
|
||||
const widgetValues = {
|
||||
prompt_mode: "Auto",
|
||||
chunks: 3,
|
||||
chunk_seconds: 5.0,
|
||||
width: 1344,
|
||||
height: 768,
|
||||
continuity: "Balanced — 22 frames",
|
||||
base_seed: 123456789,
|
||||
control_after_generate: "randomize",
|
||||
audio_continuity: true,
|
||||
diagnostics: "Detailed Report",
|
||||
reroll_from_chunk: "Auto",
|
||||
reroll_nonce: 7,
|
||||
strict_compatibility: false,
|
||||
debug: false,
|
||||
show_preview: true,
|
||||
run_storage: "Off",
|
||||
run_name: "alignment-test",
|
||||
reference_size: "Match Output",
|
||||
project_id: "workflow-save-reload",
|
||||
video_reference_size: "Efficient - 0.4 MP",
|
||||
};
|
||||
|
||||
function makeNode(values) {
|
||||
return {
|
||||
inputs: [
|
||||
{ name: "reference_video_1", type: "IMAGE", link: null },
|
||||
{ name: "driving_audio", type: "AUDIO", link: null },
|
||||
{ name: "audio_vae", type: "VAE", link: null },
|
||||
{ name: "reference_audio_1", type: "AUDIO", link: null },
|
||||
{ name: "reference_audio_vae", type: "VAE", link: null },
|
||||
],
|
||||
widgets: Object.entries(values).map(([name, value]) => ({ name, value })),
|
||||
};
|
||||
}
|
||||
|
||||
const original = makeNode(widgetValues);
|
||||
normalizeReferenceAudioLabels(original);
|
||||
const saved = JSON.parse(JSON.stringify({
|
||||
inputs: original.inputs.map(({ name, type, link }) => ({ name, type, link })),
|
||||
widgets_values: original.widgets
|
||||
.filter((widget) => widget.serialize !== false)
|
||||
.map((widget) => widget.value),
|
||||
}));
|
||||
|
||||
assert.equal(saved.inputs[3].name, "reference_audio_1");
|
||||
assert.equal(saved.inputs[4].name, "reference_audio_vae");
|
||||
assert.equal(saved.widgets_values.length, Object.keys(widgetValues).length);
|
||||
|
||||
const reloaded = makeNode(Object.fromEntries(Object.keys(widgetValues).map((name) => [name, null])));
|
||||
saved.widgets_values.forEach((value, index) => {
|
||||
reloaded.widgets[index].value = value;
|
||||
});
|
||||
normalizeReferenceAudioLabels(reloaded);
|
||||
|
||||
assert.deepEqual(
|
||||
Object.fromEntries(reloaded.widgets.map(({ name, value }) => [name, value])),
|
||||
widgetValues,
|
||||
);
|
||||
assert.equal(reloaded.widgets.some((widget) => widget.name === "Reference Audio Inputs"), false);
|
||||
assert.deepEqual(
|
||||
reloaded.inputs.map((input) => input.name),
|
||||
original.inputs.map((input) => input.name),
|
||||
);
|
||||
''',
|
||||
encoding="utf-8",
|
||||
)
|
||||
|
||||
result = subprocess.run(
|
||||
[node, str(harness_path)],
|
||||
cwd=tmp_path,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
check=False,
|
||||
)
|
||||
assert result.returncode == 0, result.stdout + result.stderr
|
||||
@@ -0,0 +1,182 @@
|
||||
from pathlib import Path
|
||||
import json
|
||||
import shutil
|
||||
import subprocess
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
PROJECT_ID_JS = ROOT / "web" / "project_id.js"
|
||||
|
||||
|
||||
def _function_source(source: str, name: str, next_name: str) -> str:
|
||||
start = source.index(f"function {name}")
|
||||
end = source.index(f"function {next_name}", start)
|
||||
return source[start:end]
|
||||
|
||||
|
||||
def test_v35_sampler_uses_existing_compact_runtime_settings_path():
|
||||
source = PROJECT_ID_JS.read_text(encoding="utf-8")
|
||||
configure = _function_source(source, "configureNode", "configureNodeAfterSetup")
|
||||
before_queue = source[source.index("async beforeQueuePrompt") :]
|
||||
|
||||
assert 'const V35_NODE_CLASS = "H3ContinuumSamplerV35";' in source
|
||||
assert "const isV35 = node.comfyClass === V35_NODE_CLASS;" in configure
|
||||
assert "!isProduction && !isTimeline && !isV34 && !isV35" in configure
|
||||
assert "isProduction || isV34 || isV35" in configure
|
||||
assert "node.comfyClass === V35_NODE_CLASS" in before_queue
|
||||
|
||||
for widget_name in (
|
||||
'"diagnostics"',
|
||||
'"strict_compatibility"',
|
||||
'"debug"',
|
||||
'"show_preview"',
|
||||
):
|
||||
assert f"hidePersistentWidget(findWidget(node, {widget_name}))" in configure
|
||||
|
||||
|
||||
def test_v36_sampler_uses_compact_settings_without_hiding_backend_choice():
|
||||
source = PROJECT_ID_JS.read_text(encoding="utf-8")
|
||||
configure = _function_source(source, "configureNode", "configureNodeAfterSetup")
|
||||
before_queue = source[source.index("async beforeQueuePrompt") :]
|
||||
|
||||
assert 'const V36_NODE_CLASS = "H3ContinuumSamplerV36";' in source
|
||||
assert "const isV36 = node.comfyClass === V36_NODE_CLASS;" in configure
|
||||
assert "!isProduction && !isTimeline && !isV34 && !isV35 && !isV36" in configure
|
||||
assert "isProduction || isV34 || isV35 || isV36" in configure
|
||||
assert "isV35 || isV36" in configure
|
||||
assert "node.comfyClass === V36_NODE_CLASS" in before_queue
|
||||
assert 'hidePersistentWidget(findWidget(node, "continuation_backend"))' not in configure
|
||||
|
||||
|
||||
def test_v37_sampler_inherits_v36_compact_frontend_and_queue_normalization():
|
||||
source = PROJECT_ID_JS.read_text(encoding="utf-8")
|
||||
configure = _function_source(source, "configureNode", "configureNodeAfterSetup")
|
||||
before_queue = source[source.index("async beforeQueuePrompt") :]
|
||||
|
||||
assert 'const V37_NODE_CLASS = "H3ContinuumSamplerV37";' in source
|
||||
assert "const isV37 = node.comfyClass === V37_NODE_CLASS;" in configure
|
||||
assert (
|
||||
"!isProduction && !isTimeline && !isV34 && !isV35 && !isV36 && !isV37"
|
||||
in configure
|
||||
)
|
||||
assert "isProduction || isV34 || isV35 || isV36 || isV37" in configure
|
||||
assert "isV35 || isV36 || isV37" in configure
|
||||
assert "node.comfyClass === V37_NODE_CLASS" in before_queue
|
||||
assert 'hidePersistentWidget(findWidget(node, "continuation_backend"))' not in configure
|
||||
|
||||
|
||||
def test_v35_assembler_uses_existing_compact_runtime_settings_path():
|
||||
source = PROJECT_ID_JS.read_text(encoding="utf-8")
|
||||
configure = _function_source(source, "configureAssembler", "configureNode")
|
||||
before_queue = source[source.index("async beforeQueuePrompt") :]
|
||||
|
||||
assert (
|
||||
'const V35_ASSEMBLE_SEAM_NODE_CLASS = "H3ContinuumAssembleSeamV35";'
|
||||
in source
|
||||
)
|
||||
assert "node.comfyClass !== V35_ASSEMBLE_SEAM_NODE_CLASS" in configure
|
||||
assert "node.comfyClass === V35_ASSEMBLE_SEAM_NODE_CLASS" in before_queue
|
||||
assert 'hidePersistentWidget(findWidget(node, "diagnostics"))' in configure
|
||||
|
||||
|
||||
def test_run_storage_off_normalizes_widgets_reload_and_queued_inputs(tmp_path):
|
||||
node_executable = shutil.which("node")
|
||||
if node_executable is None:
|
||||
pytest.skip("Node.js is required for the frontend behavior regression")
|
||||
|
||||
source = PROJECT_ID_JS.read_text(encoding="utf-8")
|
||||
functions = "\n".join(
|
||||
[
|
||||
next(line for line in source.splitlines()
|
||||
if line.startswith("const REGENERATE_INTENT_PROPERTY = ")),
|
||||
_function_source(source, "findWidget", "setWidgetVisible"),
|
||||
_function_source(source, "setWidgetVisible", "hidePersistentWidget"),
|
||||
_function_source(source, "linkedInput", "attachRefresh"),
|
||||
_function_source(source, "attachRefresh", "normalizedV38View"),
|
||||
_function_source(source, "normalizeRunStorageState", "configureConditionalWidgets"),
|
||||
_function_source(source, "configureConditionalWidgets", "configureAssembler"),
|
||||
]
|
||||
)
|
||||
script = f"""
|
||||
const RUN_STORAGE_WIDGET = "run_storage";
|
||||
const V38_NODE_CLASS = "H3ContinuumSamplerV38";
|
||||
const V39_NODE_CLASS = "H3ContinuumSamplerV39";
|
||||
const isModernSamplerClass = (name) => name === V38_NODE_CLASS || name === V39_NODE_CLASS;
|
||||
const REGENERATE_WIDGET = "reroll_from_chunk";
|
||||
const REROLL_NONCE_WIDGET = "reroll_nonce";
|
||||
const LEGACY_RUN_NAME_WIDGET = "run_name";
|
||||
const REFERENCE_SIZE_WIDGET = "reference_size";
|
||||
const TIMELINE_SIZE_WIDGET = "timeline_video_size";
|
||||
const VIDEO_REFERENCE_SIZE_WIDGET = "video_reference_size";
|
||||
{functions}
|
||||
|
||||
function widget(name, value) {{
|
||||
return {{ name, value, type: "combo", options: {{}}, computeSize: () => [120, 20] }};
|
||||
}}
|
||||
function makeNode(storage, regenerate, nonce) {{
|
||||
return {{
|
||||
widgets: [
|
||||
widget(RUN_STORAGE_WIDGET, storage),
|
||||
widget(REGENERATE_WIDGET, regenerate),
|
||||
widget(REROLL_NONCE_WIDGET, nonce),
|
||||
widget(LEGACY_RUN_NAME_WIDGET, "phase1-test"),
|
||||
widget(REFERENCE_SIZE_WIDGET, "Match Output"),
|
||||
widget(TIMELINE_SIZE_WIDGET, "Efficient"),
|
||||
widget(VIDEO_REFERENCE_SIZE_WIDGET, "Efficient"),
|
||||
],
|
||||
inputs: [],
|
||||
setDirtyCanvas() {{}},
|
||||
}};
|
||||
}}
|
||||
|
||||
const live = makeNode("Save + Auto Resume", "Auto", 0);
|
||||
configureConditionalWidgets(live);
|
||||
const liveStorage = findWidget(live, RUN_STORAGE_WIDGET);
|
||||
const liveRegenerate = findWidget(live, REGENERATE_WIDGET);
|
||||
const liveNonce = findWidget(live, REROLL_NONCE_WIDGET);
|
||||
liveRegenerate.value = "Chunk 2";
|
||||
liveRegenerate.callback("Chunk 2");
|
||||
liveNonce.value = 5;
|
||||
liveStorage.value = "Off";
|
||||
liveStorage.callback("Off");
|
||||
|
||||
const queued = {{ reroll_from_chunk: "Chunk 2", reroll_nonce: 5 }};
|
||||
normalizeRunStorageState(live, queued);
|
||||
|
||||
const reloaded = makeNode("Off", "Chunk 3", 9);
|
||||
configureConditionalWidgets(reloaded);
|
||||
const reloadRegenerate = findWidget(reloaded, REGENERATE_WIDGET);
|
||||
const reloadNonce = findWidget(reloaded, REROLL_NONCE_WIDGET);
|
||||
|
||||
console.log(JSON.stringify({{
|
||||
live: {{ regenerate: liveRegenerate.value, nonce: liveNonce.value }},
|
||||
queued,
|
||||
reloaded: {{
|
||||
regenerate: reloadRegenerate.value,
|
||||
nonce: reloadNonce.value,
|
||||
regenerateHidden: reloadRegenerate.hidden,
|
||||
nonceHidden: reloadNonce.hidden,
|
||||
}},
|
||||
}}));
|
||||
"""
|
||||
script_path = tmp_path / "run-storage-frontend-regression.js"
|
||||
script_path.write_text(script, encoding="utf-8")
|
||||
|
||||
result = subprocess.run(
|
||||
[node_executable, str(script_path)],
|
||||
check=True,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
)
|
||||
observed = json.loads(result.stdout)
|
||||
|
||||
assert observed["live"] == {"regenerate": "Auto", "nonce": 0}
|
||||
assert observed["queued"] == {"reroll_from_chunk": "Auto", "reroll_nonce": 0}
|
||||
assert observed["reloaded"] == {
|
||||
"regenerate": "Auto",
|
||||
"nonce": 0,
|
||||
"regenerateHidden": True,
|
||||
"nonceHidden": True,
|
||||
}
|
||||
@@ -0,0 +1,249 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import torch
|
||||
|
||||
from ComfyUI_H3_Continuum_Join.v3.conditioning_bridge_nodes import (
|
||||
NODE_CLASS_MAPPINGS,
|
||||
NODE_DISPLAY_NAME_MAPPINGS,
|
||||
)
|
||||
from ComfyUI_H3_Continuum_Join.v3 import conditioning_bridge_nodes
|
||||
from ComfyUI_H3_Continuum_Join.v3.conditioning_bridge_nodes import (
|
||||
H3ContinuumConditioningBridgeV35,
|
||||
)
|
||||
from ComfyUI_H3_Continuum_Join.v3.refine_context import (
|
||||
MAGIC as REFINE_CONTEXT_MAGIC,
|
||||
)
|
||||
from ComfyUI_H3_Continuum_Join.v3.second_pass import (
|
||||
prepare_physical_refine_groups,
|
||||
)
|
||||
|
||||
|
||||
def _group(
|
||||
group_id: int,
|
||||
*,
|
||||
logical_chunks: list[int],
|
||||
temporal: int,
|
||||
terminal: bool,
|
||||
) -> dict:
|
||||
return {
|
||||
"group_id": group_id,
|
||||
"logical_chunks": logical_chunks,
|
||||
"physical_prompt": f"physical prompt {group_id}",
|
||||
"prompt_policy": "paired_timeline_v1" if terminal else "single",
|
||||
"physical_frames": 260 if terminal else 124,
|
||||
"trim_prefix_frames": 22 if terminal else 0,
|
||||
"terminal_merged": terminal,
|
||||
"source_width": 640,
|
||||
"source_height": 640,
|
||||
"source_batch": 1,
|
||||
"latent_channels": 24,
|
||||
"source_latent_t": temporal,
|
||||
"source_latent_h": 40,
|
||||
"source_latent_w": 40,
|
||||
"source_audio_shape": [1, 8, temporal * 4],
|
||||
}
|
||||
|
||||
|
||||
def _fixture():
|
||||
groups = [
|
||||
_group(0, logical_chunks=[1], temporal=37, terminal=False),
|
||||
_group(1, logical_chunks=[2, 3], temporal=77, terminal=True),
|
||||
]
|
||||
plan = {
|
||||
"width": 640,
|
||||
"height": 640,
|
||||
"second_pass_contract": {
|
||||
"version": 1,
|
||||
"physical_groups": groups,
|
||||
},
|
||||
}
|
||||
videos = [
|
||||
{"samples": torch.zeros((1, 24, group["source_latent_t"], 48, 48))}
|
||||
for group in groups
|
||||
]
|
||||
context_groups = (
|
||||
{
|
||||
"group_id": 0,
|
||||
"logical_chunks": (1,),
|
||||
"physical_clip_index": 1,
|
||||
"context_frames": 0,
|
||||
},
|
||||
{
|
||||
"group_id": 1,
|
||||
"logical_chunks": (2, 3),
|
||||
"physical_clip_index": 2,
|
||||
"context_frames": 22,
|
||||
},
|
||||
)
|
||||
context = {
|
||||
"magic": REFINE_CONTEXT_MAGIC,
|
||||
"complete": True,
|
||||
"groups": context_groups,
|
||||
}
|
||||
return groups, plan, videos, context
|
||||
|
||||
|
||||
def test_conditioning_bridge_public_schema_and_registration():
|
||||
node_id = "H3ContinuumConditioningBridgeV35"
|
||||
node_class = NODE_CLASS_MAPPINGS[node_id]
|
||||
assert node_class is H3ContinuumConditioningBridgeV35
|
||||
assert NODE_DISPLAY_NAME_MAPPINGS[node_id] == (
|
||||
"H3 Continuum Conditioning Bridge V3.5"
|
||||
)
|
||||
assert node_class.CATEGORY == "MiniMax H3/Continuum/Advanced"
|
||||
assert node_class.DEPRECATED is False
|
||||
assert node_class.INPUT_IS_LIST is True
|
||||
assert node_class.OUTPUT_IS_LIST == (True, True, False, False)
|
||||
assert node_class.RETURN_TYPES == (
|
||||
"MODEL",
|
||||
"CONDITIONING",
|
||||
"H3_CONTINUUM_ASSEMBLY_PLAN",
|
||||
"STRING",
|
||||
)
|
||||
assert node_class.RETURN_NAMES == (
|
||||
"group_models",
|
||||
"conditioning",
|
||||
"updated_assembly_plan",
|
||||
"status",
|
||||
)
|
||||
schema = node_class.INPUT_TYPES()
|
||||
assert list(schema["required"]) == [
|
||||
"model",
|
||||
"clip",
|
||||
"video_latents",
|
||||
"assembly_plan",
|
||||
"refine_context",
|
||||
]
|
||||
assert list(schema["optional"]) == ["video_vae"]
|
||||
|
||||
|
||||
def test_prepare_keeps_one_complete_conditioning_per_physical_group():
|
||||
groups, plan, videos, context = _fixture()
|
||||
conditioning_objects = [
|
||||
[["group-0-entry-a", {"slot": 0}], ["group-0-entry-b", {"slot": 1}]],
|
||||
[["group-1-entry-a", {"slot": 0}], ["group-1-entry-b", {"slot": 1}]],
|
||||
]
|
||||
clone_calls = []
|
||||
|
||||
def validate_context(value, *, assembly_plan):
|
||||
assert value is context
|
||||
assert assembly_plan is plan
|
||||
return context
|
||||
|
||||
def adapt(group, **kwargs):
|
||||
assert kwargs["target_latent_h"] == 48
|
||||
assert kwargs["target_latent_w"] == 48
|
||||
return conditioning_objects[group["group_id"]], {"adapted": True}
|
||||
|
||||
def clone(model, **kwargs):
|
||||
clone_calls.append(kwargs)
|
||||
return f"model-{kwargs['chunk_index']}"
|
||||
|
||||
prepared = prepare_physical_refine_groups(
|
||||
model="base-model",
|
||||
clip="clip",
|
||||
video_latents=videos,
|
||||
assembly_plan=plan,
|
||||
refine_context=context,
|
||||
validate_refine_context_fn=validate_context,
|
||||
adapt_group_conditioning_fn=adapt,
|
||||
clone_model_fn=clone,
|
||||
)
|
||||
|
||||
assert prepared["physical_group_count"] == 2
|
||||
assert len(prepared["group_models"]) == len(prepared["conditioning"]) == 2
|
||||
assert prepared["group_models"] == ["model-1", "model-2"]
|
||||
assert prepared["conditioning"] == conditioning_objects
|
||||
assert prepared["conditioning"][0] is conditioning_objects[0]
|
||||
assert prepared["conditioning"][1] is conditioning_objects[1]
|
||||
assert [len(item) for item in prepared["conditioning"]] == [2, 2]
|
||||
assert [detail["group"]["logical_chunks"] for detail in prepared["details"]] == [
|
||||
[1],
|
||||
[2, 3],
|
||||
]
|
||||
assert [detail["context_frames"] for detail in prepared["details"]] == [0, 22]
|
||||
assert clone_calls == [
|
||||
{
|
||||
"strict": False,
|
||||
"debug": False,
|
||||
"chunk_index": 1,
|
||||
"context_frames": None,
|
||||
},
|
||||
{
|
||||
"strict": False,
|
||||
"debug": False,
|
||||
"chunk_index": 2,
|
||||
"context_frames": 22,
|
||||
},
|
||||
]
|
||||
assert prepared["updated_assembly_plan"]["width"] == 768
|
||||
assert prepared["updated_assembly_plan"]["height"] == 768
|
||||
assert plan["width"] == 640
|
||||
assert groups[1]["logical_chunks"] == [2, 3]
|
||||
|
||||
|
||||
def test_node_preserves_outer_physical_group_list_without_flattening(monkeypatch):
|
||||
_groups, plan, videos, context = _fixture()
|
||||
complete_conditioning = [
|
||||
[["first-entry", {"group": 0}], ["second-entry", {"group": 0}]],
|
||||
[["terminal-entry-a", {"group": 1}], ["terminal-entry-b", {"group": 1}]],
|
||||
]
|
||||
prepared = {
|
||||
"group_models": ["model-0", "model-1"],
|
||||
"conditioning": complete_conditioning,
|
||||
"updated_assembly_plan": {"width": 768, "height": 768},
|
||||
"physical_group_count": 2,
|
||||
"warnings": [],
|
||||
"details": [
|
||||
{
|
||||
"group_index": 0,
|
||||
"group": {"logical_chunks": [1], "prompt_policy": "single"},
|
||||
"conditioning_source": "refine_context",
|
||||
"physical_clip_index": 1,
|
||||
"context_frames": 0,
|
||||
},
|
||||
{
|
||||
"group_index": 1,
|
||||
"group": {
|
||||
"logical_chunks": [2, 3],
|
||||
"prompt_policy": "paired_timeline_v1",
|
||||
},
|
||||
"conditioning_source": "refine_context",
|
||||
"physical_clip_index": 2,
|
||||
"context_frames": 22,
|
||||
},
|
||||
],
|
||||
}
|
||||
captured = {}
|
||||
|
||||
def fake_prepare(**kwargs):
|
||||
captured.update(kwargs)
|
||||
return prepared
|
||||
|
||||
monkeypatch.setattr(
|
||||
conditioning_bridge_nodes,
|
||||
"prepare_physical_refine_groups",
|
||||
fake_prepare,
|
||||
)
|
||||
result = H3ContinuumConditioningBridgeV35().prepare(
|
||||
model=["base-model"],
|
||||
clip=["clip"],
|
||||
video_latents=videos,
|
||||
assembly_plan=[plan],
|
||||
refine_context=[context],
|
||||
video_vae=["vae"],
|
||||
)
|
||||
|
||||
assert captured["model"] == "base-model"
|
||||
assert captured["clip"] == "clip"
|
||||
assert captured["video_latents"] is videos
|
||||
assert captured["assembly_plan"] is plan
|
||||
assert captured["refine_context"] is context
|
||||
assert captured["video_vae"] == "vae"
|
||||
assert result[0] == ["model-0", "model-1"]
|
||||
assert result[1] is complete_conditioning
|
||||
assert len(result[1]) == 2
|
||||
assert [len(item) for item in result[1]] == [2, 2]
|
||||
assert result[2] is prepared["updated_assembly_plan"]
|
||||
assert "logical_chunks=[2, 3]" in result[3]
|
||||
assert "AV LATENT, Noise, and Audio Lock" in result[3]
|
||||
@@ -0,0 +1,533 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import sys
|
||||
from types import ModuleType
|
||||
from types import SimpleNamespace
|
||||
|
||||
import torch
|
||||
|
||||
from ComfyUI_H3_Continuum_Join.constants import (
|
||||
DIAGNOSTICS_BASIC,
|
||||
DIAGNOSTICS_FULL,
|
||||
PROMPT_MODE_FIXED,
|
||||
PROMPT_MODE_LIST,
|
||||
V2_CONTINUITY_OPTIONS,
|
||||
)
|
||||
from ComfyUI_H3_Continuum_Join.temporal import audio_latent_t, video_latent_t
|
||||
from ComfyUI_H3_Continuum_Join.reference import (
|
||||
REFERENCE_SIZE_MATCH_OUTPUT,
|
||||
ReferenceAssets,
|
||||
)
|
||||
from ComfyUI_H3_Continuum_Join.v2 import sequence
|
||||
from ComfyUI_H3_Continuum_Join.v2.h3_builder import IdentityAssets
|
||||
from ComfyUI_H3_Continuum_Join.v2.prompts import make_prompt_plan
|
||||
from ComfyUI_H3_Continuum_Join.v3.driving_nodes import (
|
||||
H3ContinuumSamplerV34,
|
||||
H3ContinuumSamplerV35,
|
||||
NODE_CLASS_MAPPINGS,
|
||||
NODE_DISPLAY_NAME_MAPPINGS,
|
||||
)
|
||||
from ComfyUI_H3_Continuum_Join.v3.nodes import H3ContinuumSamplerProduction
|
||||
from ComfyUI_H3_Continuum_Join.v3.plan import prepare_physical_decode_entries
|
||||
from ComfyUI_H3_Continuum_Join.v3.refine_context import validate_refine_context
|
||||
|
||||
|
||||
class _Nested:
|
||||
def __init__(self, parts):
|
||||
self.parts = list(parts)
|
||||
|
||||
def unbind(self):
|
||||
return self.parts
|
||||
|
||||
|
||||
def _install_nested_tensor(monkeypatch):
|
||||
nested_module = ModuleType("comfy.nested_tensor")
|
||||
nested_module.NestedTensor = _Nested
|
||||
comfy_module = sys.modules.get("comfy") or ModuleType("comfy")
|
||||
comfy_module.nested_tensor = nested_module
|
||||
monkeypatch.setitem(sys.modules, "comfy", comfy_module)
|
||||
monkeypatch.setitem(sys.modules, "comfy.nested_tensor", nested_module)
|
||||
|
||||
|
||||
class _Clip:
|
||||
def __init__(self):
|
||||
self.encode_calls = 0
|
||||
self.layer_idx = None
|
||||
self.use_clip_schedule = False
|
||||
self.tokenizer_options = {}
|
||||
self.apply_hooks_to_conds = None
|
||||
self.patcher = SimpleNamespace(
|
||||
patches_uuid="test-patch-a",
|
||||
forced_hooks=None,
|
||||
current_hooks=None,
|
||||
hook_patches={},
|
||||
)
|
||||
|
||||
def tokenize(self, prompt, **_kwargs):
|
||||
return prompt
|
||||
|
||||
def encode_from_tokens_scheduled(self, _tokens):
|
||||
self.encode_calls += 1
|
||||
return [[torch.zeros((1, 1, 2)), {}]]
|
||||
|
||||
|
||||
def _latent(width: int, height: int, frames: int):
|
||||
return {
|
||||
"samples": _Nested(
|
||||
(
|
||||
torch.zeros(
|
||||
(1, 24, video_latent_t(frames), height // 16, width // 16)
|
||||
),
|
||||
torch.zeros((1, 32, 2, audio_latent_t(frames))),
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
def _model():
|
||||
return SimpleNamespace(
|
||||
model=SimpleNamespace(diffusion_model=SimpleNamespace()),
|
||||
model_options={},
|
||||
wrappers={},
|
||||
model_dtype=lambda: torch.bfloat16,
|
||||
model_size=lambda: 0,
|
||||
)
|
||||
|
||||
|
||||
def _capture_sequence(
|
||||
monkeypatch,
|
||||
*,
|
||||
terminal: bool,
|
||||
reference_image: bool = False,
|
||||
reference_audio: bool = False,
|
||||
continuation_transport=sequence.REFERENCE_CONTEXT_V1,
|
||||
session=None,
|
||||
diagnostics=DIAGNOSTICS_BASIC,
|
||||
memory_attribution=False,
|
||||
prompt_conditioning_cache=False,
|
||||
clip=None,
|
||||
):
|
||||
_install_nested_tensor(monkeypatch)
|
||||
width, height = 96, 64
|
||||
first_image = torch.zeros((1, height, width, 3)) if terminal else None
|
||||
last_image = torch.ones((1, height, width, 3)) if terminal else None
|
||||
first_latent = torch.zeros((1, 24, 1, height // 16, width // 16)) if terminal else None
|
||||
last_latent = torch.ones((1, 24, 1, height // 16, width // 16)) if terminal else None
|
||||
assets = IdentityAssets(
|
||||
first_image,
|
||||
first_latent,
|
||||
last_image,
|
||||
last_latent,
|
||||
"identity" if terminal else "none",
|
||||
)
|
||||
monkeypatch.setattr(sequence, "check_comfy_h3_runtime", lambda: [])
|
||||
monkeypatch.setattr(sequence, "prepare_identity_assets", lambda *a, **k: assets)
|
||||
monkeypatch.setattr(sequence, "encode_identity_latents", lambda *a, **k: assets)
|
||||
monkeypatch.setattr(sequence, "empty_h3_latent", _latent)
|
||||
monkeypatch.setattr(
|
||||
sequence,
|
||||
"latent_from_cpu",
|
||||
lambda video, audio: {"samples": _Nested((video, audio))},
|
||||
)
|
||||
monkeypatch.setattr(sequence, "accelerator_summary", lambda _model: "accelerators")
|
||||
monkeypatch.setattr(sequence, "sample_chunk", lambda **kwargs: kwargs["latent"])
|
||||
monkeypatch.setattr(
|
||||
sequence,
|
||||
"clone_model_for_chunk",
|
||||
lambda model, **_kwargs: model,
|
||||
)
|
||||
reference_assets = None
|
||||
if reference_image:
|
||||
reference_assets = ReferenceAssets(
|
||||
images=(torch.full((1, height, width, 3), 0.5),),
|
||||
latents=(torch.full((1, 24, 1, height // 16, width // 16), 0.5),),
|
||||
image_hashes=("b" * 64,),
|
||||
combined_hash="c" * 64,
|
||||
size_mode=REFERENCE_SIZE_MATCH_OUTPUT,
|
||||
)
|
||||
reference_audio_source = None
|
||||
reference_audio_vae = None
|
||||
if reference_audio:
|
||||
from ComfyUI_H3_Continuum_Join import reference_audio as reference_audio_module
|
||||
|
||||
reference_audio_source = SimpleNamespace(
|
||||
combined_hash="reference-audio-hash",
|
||||
contract={
|
||||
"reference_audio_contract_version": 1,
|
||||
"source_sha256": "a" * 64,
|
||||
},
|
||||
)
|
||||
reference_audio_vae = object()
|
||||
reference_audio_assets = SimpleNamespace(
|
||||
audio_latent=torch.arange(64, dtype=torch.float32).reshape(1, 32, 2, 1)
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
reference_audio_module,
|
||||
"encode_reference_audio",
|
||||
lambda _vae, _source: reference_audio_assets,
|
||||
)
|
||||
chunks = 3 if terminal else 2
|
||||
mode = PROMPT_MODE_LIST if terminal else PROMPT_MODE_FIXED
|
||||
script = "first\n---\nmiddle\n---\nlast" if terminal else "same prompt"
|
||||
plan = make_prompt_plan(
|
||||
mode=mode,
|
||||
script=script,
|
||||
chunks=chunks,
|
||||
chunk_seconds=5.0,
|
||||
)
|
||||
return sequence.run_sequence(
|
||||
model=_model(),
|
||||
clip=clip or _Clip(),
|
||||
video_vae=object(),
|
||||
audio_vae=None,
|
||||
sampler=object(),
|
||||
sigmas=torch.tensor([1.0, 0.0]),
|
||||
first_frame=first_image,
|
||||
last_frame=last_image,
|
||||
prompt_plan=plan,
|
||||
width=width,
|
||||
height=height,
|
||||
continuity=V2_CONTINUITY_OPTIONS[1],
|
||||
base_seed=42,
|
||||
audio_continuity=True,
|
||||
exact_total_duration=False,
|
||||
diagnostics_mode=diagnostics,
|
||||
reroll_from_chunk=0,
|
||||
reroll_nonce=0,
|
||||
strict_compatibility=False,
|
||||
debug=False,
|
||||
session=session,
|
||||
latent_only=True,
|
||||
reference_assets=reference_assets,
|
||||
reference_audio_source=reference_audio_source,
|
||||
reference_audio_vae=reference_audio_vae,
|
||||
capture_refine_context=True,
|
||||
memory_attribution=memory_attribution,
|
||||
prompt_conditioning_cache=prompt_conditioning_cache,
|
||||
continuation_transport=continuation_transport,
|
||||
)
|
||||
|
||||
|
||||
def test_v34_public_output_schema_is_unchanged():
|
||||
assert H3ContinuumSamplerV34.RETURN_TYPES == (
|
||||
"LATENT",
|
||||
"LATENT",
|
||||
"H3_CONTINUUM_ASSEMBLY_PLAN",
|
||||
"STRING",
|
||||
"AUDIO",
|
||||
)
|
||||
assert H3ContinuumSamplerV34.RETURN_NAMES == (
|
||||
"video_latents",
|
||||
"audio_latents",
|
||||
"assembly_plan",
|
||||
"status",
|
||||
"driving_audio",
|
||||
)
|
||||
assert H3ContinuumSamplerV34.OUTPUT_IS_LIST == (True, True, False, False, False)
|
||||
|
||||
|
||||
def test_v35_is_registered_with_v34_outputs_then_refine_context():
|
||||
from ComfyUI_H3_Continuum_Join import nodes as root_nodes
|
||||
|
||||
assert NODE_CLASS_MAPPINGS["H3ContinuumSamplerV35"] is H3ContinuumSamplerV35
|
||||
assert NODE_DISPLAY_NAME_MAPPINGS["H3ContinuumSamplerV35"] == (
|
||||
"H3 Continuum Sampler V3.5"
|
||||
)
|
||||
assert "H3ContinuumSamplerV35" not in root_nodes.NODE_CLASS_MAPPINGS
|
||||
assert H3ContinuumSamplerV35.RETURN_TYPES[:5] == H3ContinuumSamplerV34.RETURN_TYPES
|
||||
assert H3ContinuumSamplerV35.RETURN_NAMES[:5] == H3ContinuumSamplerV34.RETURN_NAMES
|
||||
assert H3ContinuumSamplerV35.RETURN_TYPES[5] == "H3_CONTINUUM_REFINE_CONTEXT"
|
||||
assert H3ContinuumSamplerV35.RETURN_NAMES[5] == "refine_context"
|
||||
assert H3ContinuumSamplerV35.OUTPUT_IS_LIST == (
|
||||
True,
|
||||
True,
|
||||
False,
|
||||
False,
|
||||
False,
|
||||
False,
|
||||
)
|
||||
|
||||
|
||||
def test_v35_runtime_keeps_driving_audio_fifth_and_context_sixth(monkeypatch):
|
||||
captured = {}
|
||||
|
||||
def fake_production_run(_self, **kwargs):
|
||||
captured["capture"] = kwargs["capture_refine_context"]
|
||||
captured["memory"] = kwargs.get("memory_attribution", False)
|
||||
captured["prompt_cache"] = kwargs.get("prompt_conditioning_cache", False)
|
||||
base = ("video", "audio", {"plan": True}, "status")
|
||||
return (*base, "context") if kwargs["capture_refine_context"] else base
|
||||
|
||||
monkeypatch.setattr(H3ContinuumSamplerProduction, "run", fake_production_run)
|
||||
v34_outputs = H3ContinuumSamplerV34().run(
|
||||
chunks=1,
|
||||
chunk_seconds=5.0,
|
||||
width=96,
|
||||
height=64,
|
||||
)
|
||||
assert captured["capture"] is False
|
||||
assert captured["memory"] is False
|
||||
assert captured["prompt_cache"] is False
|
||||
assert v34_outputs == (
|
||||
"video",
|
||||
"audio",
|
||||
{"plan": True},
|
||||
"status",
|
||||
None,
|
||||
)
|
||||
outputs = H3ContinuumSamplerV35().run(
|
||||
chunks=1,
|
||||
chunk_seconds=5.0,
|
||||
width=96,
|
||||
height=64,
|
||||
)
|
||||
assert captured["capture"] is True
|
||||
assert captured["memory"] is True
|
||||
assert captured["prompt_cache"] is True
|
||||
assert outputs == (
|
||||
"video",
|
||||
"audio",
|
||||
{"plan": True},
|
||||
"status",
|
||||
None,
|
||||
"context",
|
||||
)
|
||||
|
||||
|
||||
def test_capture_records_normal_physical_groups_in_sampling_order(monkeypatch):
|
||||
outputs = _capture_sequence(monkeypatch, terminal=False)
|
||||
assert len(outputs) == 5
|
||||
context = outputs[4]
|
||||
assert context["complete"] is True
|
||||
assert context["conditioning_mode"] == "t2va"
|
||||
groups = context["groups"]
|
||||
assert [group["logical_chunks"] for group in groups] == [(1,), (2,)]
|
||||
assert [group["physical_clip_index"] for group in groups] == [1, 2]
|
||||
assert [group["context_frames"] for group in groups] == [0, 22]
|
||||
assert [group["prompt_policy"] for group in groups] == ["single", "single"]
|
||||
assert [group["source_video_shape"] for group in groups] == [
|
||||
(1, 24, 37, 4, 6),
|
||||
(1, 24, 42, 4, 6),
|
||||
]
|
||||
_, assembly_plan = prepare_physical_decode_entries(
|
||||
outputs[0],
|
||||
chunk_seconds=5.0,
|
||||
preserve_final_frame=False,
|
||||
terminal_merged=False,
|
||||
)
|
||||
assert validate_refine_context(context, assembly_plan) is context
|
||||
|
||||
|
||||
def test_capture_records_terminal_pair_as_one_physical_group(monkeypatch):
|
||||
outputs = _capture_sequence(monkeypatch, terminal=True)
|
||||
context = outputs[4]
|
||||
assert context["complete"] is True
|
||||
assert context["conditioning_mode"] == "fl2va"
|
||||
groups = context["groups"]
|
||||
assert len(groups) == 2
|
||||
assert groups[0]["logical_chunks"] == (1,)
|
||||
assert groups[1]["logical_chunks"] == (2, 3)
|
||||
assert groups[1]["physical_frames"] == 260
|
||||
assert groups[1]["physical_clip_index"] == 2
|
||||
assert groups[1]["context_frames"] == 22
|
||||
assert groups[1]["prompt_policy"] == "paired_timeline_v1"
|
||||
assert groups[1]["physical_prompt"] == (
|
||||
"[0-5s]\nmiddle\n\n[5-10s]\nlast"
|
||||
)
|
||||
assert groups[1]["source_video_shape"] == (1, 24, 77, 4, 6)
|
||||
assert torch.equal(groups[1]["first_image"], torch.zeros((1, 64, 96, 3)))
|
||||
assert torch.equal(groups[1]["last_image"], torch.ones((1, 64, 96, 3)))
|
||||
_, assembly_plan = prepare_physical_decode_entries(
|
||||
outputs[0],
|
||||
chunk_seconds=5.0,
|
||||
preserve_final_frame=True,
|
||||
terminal_merged=True,
|
||||
)
|
||||
assert validate_refine_context(context, assembly_plan) is context
|
||||
|
||||
|
||||
def test_reference_audio_is_captured_in_every_normal_physical_group(monkeypatch):
|
||||
outputs = _capture_sequence(
|
||||
monkeypatch,
|
||||
terminal=False,
|
||||
reference_audio=True,
|
||||
)
|
||||
groups = outputs[4]["groups"]
|
||||
assert [group["logical_chunks"] for group in groups] == [(1,), (2,)]
|
||||
for group in groups:
|
||||
refs = group["conditioning"][0][1]["minimax_refs"]
|
||||
assert [ref["kind"] for ref in refs].count("audio") == 1
|
||||
|
||||
|
||||
def test_reference_audio_is_captured_in_terminal_physical_group(monkeypatch):
|
||||
outputs = _capture_sequence(
|
||||
monkeypatch,
|
||||
terminal=True,
|
||||
reference_audio=True,
|
||||
)
|
||||
groups = outputs[4]["groups"]
|
||||
assert [group["logical_chunks"] for group in groups] == [(1,), (2, 3)]
|
||||
assert groups[1]["prompt_policy"] == "paired_timeline_v1"
|
||||
for group in groups:
|
||||
refs = group["conditioning"][0][1]["minimax_refs"]
|
||||
assert [ref["kind"] for ref in refs].count("audio") == 1
|
||||
|
||||
|
||||
def test_masked_av_preserves_image_and_audio_refs_in_every_normal_group(monkeypatch):
|
||||
outputs = _capture_sequence(
|
||||
monkeypatch,
|
||||
terminal=False,
|
||||
reference_image=True,
|
||||
reference_audio=True,
|
||||
continuation_transport=sequence.MASKED_AV_PREFIX_22_V1,
|
||||
)
|
||||
groups = outputs[4]["groups"]
|
||||
assert [group["logical_chunks"] for group in groups] == [(1,), (2,)]
|
||||
for group in groups:
|
||||
refs = group["conditioning"][0][1]["minimax_refs"]
|
||||
assert [ref["kind"] for ref in refs] == ["image", "audio"]
|
||||
|
||||
|
||||
def test_masked_av_preserves_image_and_audio_refs_in_terminal_groups(monkeypatch):
|
||||
outputs = _capture_sequence(
|
||||
monkeypatch,
|
||||
terminal=True,
|
||||
reference_image=True,
|
||||
reference_audio=True,
|
||||
continuation_transport=sequence.MASKED_AV_PREFIX_22_V1,
|
||||
)
|
||||
groups = outputs[4]["groups"]
|
||||
assert [group["logical_chunks"] for group in groups] == [(1,), (2, 3)]
|
||||
assert groups[1]["prompt_policy"] == "paired_timeline_v1"
|
||||
for group in groups:
|
||||
refs = group["conditioning"][0][1]["minimax_refs"]
|
||||
assert [ref["kind"] for ref in refs] == ["image", "audio"]
|
||||
|
||||
|
||||
def test_reused_session_reconstructs_complete_context_without_stopping(monkeypatch):
|
||||
first_outputs = _capture_sequence(monkeypatch, terminal=False)
|
||||
reused_outputs = _capture_sequence(
|
||||
monkeypatch,
|
||||
terminal=False,
|
||||
session=first_outputs[2],
|
||||
)
|
||||
context = reused_outputs[4]
|
||||
assert context["complete"] is True
|
||||
assert [group["logical_chunks"] for group in context["groups"]] == [(1,), (2,)]
|
||||
assert len(reused_outputs[0]) == 2
|
||||
assert context["notes"] == first_outputs[4]["notes"]
|
||||
|
||||
|
||||
def test_v35_full_memory_events_follow_physical_terminal_group_order(monkeypatch):
|
||||
outputs = _capture_sequence(
|
||||
monkeypatch,
|
||||
terminal=True,
|
||||
diagnostics=DIAGNOSTICS_FULL,
|
||||
memory_attribution=True,
|
||||
)
|
||||
memory_lines = [
|
||||
line for line in outputs[3].splitlines() if line.startswith("Memory [V3.5")
|
||||
]
|
||||
labels = [line.split("]: RSS", 1)[0] + "]" for line in memory_lines]
|
||||
assert labels == [
|
||||
"Memory [V3.5 sequence start]",
|
||||
"Memory [V3.5 physical group 1 logical=[1] before sampling]",
|
||||
"Memory [V3.5 physical group 1 logical=[1] after sampling]",
|
||||
"Memory [V3.5 physical group 1 logical=[1] after CPU commit]",
|
||||
"Memory [V3.5 physical group 2 logical=[2,3] before sampling]",
|
||||
"Memory [V3.5 physical group 2 logical=[2,3] after sampling]",
|
||||
"Memory [V3.5 physical group 2 logical=[2,3] after CPU commit]",
|
||||
"Memory [V3.5 sequence complete]",
|
||||
]
|
||||
performance_lines = [
|
||||
line
|
||||
for line in outputs[3].splitlines()
|
||||
if line.startswith("Performance [V3.5")
|
||||
]
|
||||
assert len(performance_lines) == 3
|
||||
assert performance_lines[0].startswith(
|
||||
"Performance [V3.5 physical group 1 logical=[1]]"
|
||||
)
|
||||
assert performance_lines[1].startswith(
|
||||
"Performance [V3.5 physical group 2 logical=[2,3]]"
|
||||
)
|
||||
assert performance_lines[2].startswith("Performance [V3.5 summary]")
|
||||
assert "sampling=2" in performance_lines[2]
|
||||
assert "conditioning_identity_video_vae=1" in performance_lines[2]
|
||||
assert "conditioning_prompt_clip=1" in performance_lines[2]
|
||||
assert "conditioning_reference_audio_vae=0" in performance_lines[2]
|
||||
assert "CUDA_synchronize=not_used" in performance_lines[2]
|
||||
|
||||
|
||||
def test_v35_reference_audio_conditioning_attribution_is_reported(monkeypatch):
|
||||
outputs = _capture_sequence(
|
||||
monkeypatch,
|
||||
terminal=False,
|
||||
reference_audio=True,
|
||||
diagnostics=DIAGNOSTICS_FULL,
|
||||
memory_attribution=True,
|
||||
)
|
||||
summary = next(
|
||||
line
|
||||
for line in outputs[3].splitlines()
|
||||
if line.startswith("Performance [V3.5 summary]")
|
||||
)
|
||||
assert "conditioning_reference_audio_vae=" in summary
|
||||
assert "conditioning_reference_audio_vae=1" in summary
|
||||
|
||||
|
||||
def test_memory_attribution_is_absent_when_private_flag_is_off(monkeypatch):
|
||||
outputs = _capture_sequence(
|
||||
monkeypatch,
|
||||
terminal=False,
|
||||
diagnostics=DIAGNOSTICS_FULL,
|
||||
memory_attribution=False,
|
||||
)
|
||||
assert "Memory [V3.5" not in outputs[3]
|
||||
assert "Memory [sequence start]" in outputs[3]
|
||||
assert "Memory [sequence complete]" in outputs[3]
|
||||
|
||||
|
||||
def test_v35_prompt_cache_reports_real_encode_elision_across_runs(monkeypatch):
|
||||
clip = _Clip()
|
||||
first = _capture_sequence(
|
||||
monkeypatch,
|
||||
terminal=False,
|
||||
diagnostics=DIAGNOSTICS_FULL,
|
||||
prompt_conditioning_cache=True,
|
||||
clip=clip,
|
||||
)
|
||||
assert clip.encode_calls == 1
|
||||
assert "Prompt/CLIP cache [V3.5]: hits=0, misses=1, bypasses=0, encode_calls=1." in first[3]
|
||||
|
||||
second = _capture_sequence(
|
||||
monkeypatch,
|
||||
terminal=False,
|
||||
diagnostics=DIAGNOSTICS_FULL,
|
||||
prompt_conditioning_cache=True,
|
||||
clip=clip,
|
||||
)
|
||||
assert clip.encode_calls == 1
|
||||
assert "Prompt/CLIP cache [V3.5]: hits=1, misses=0, bypasses=0, encode_calls=0." in second[3]
|
||||
|
||||
|
||||
def test_v35_terminal_prompt_cache_preserves_physical_prompt_set(monkeypatch):
|
||||
clip = _Clip()
|
||||
_capture_sequence(
|
||||
monkeypatch,
|
||||
terminal=True,
|
||||
diagnostics=DIAGNOSTICS_FULL,
|
||||
prompt_conditioning_cache=True,
|
||||
clip=clip,
|
||||
)
|
||||
assert clip.encode_calls == 4
|
||||
|
||||
second = _capture_sequence(
|
||||
monkeypatch,
|
||||
terminal=True,
|
||||
diagnostics=DIAGNOSTICS_FULL,
|
||||
prompt_conditioning_cache=True,
|
||||
clip=clip,
|
||||
)
|
||||
assert clip.encode_calls == 4
|
||||
assert "Prompt/CLIP cache [V3.5]: hits=4, misses=0, bypasses=0, encode_calls=0." in second[3]
|
||||
@@ -0,0 +1,567 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import sys
|
||||
import types
|
||||
|
||||
import pytest
|
||||
import torch
|
||||
|
||||
from ComfyUI_H3_Continuum_Join.v3.hires_fix_nodes import (
|
||||
NODE_CLASS_MAPPINGS,
|
||||
NODE_DISPLAY_NAME_MAPPINGS,
|
||||
)
|
||||
from ComfyUI_H3_Continuum_Join.v3.second_pass_nodes import (
|
||||
NODE_DISPLAY_NAME_MAPPINGS as SECOND_PASS_DISPLAY_NAME_MAPPINGS,
|
||||
)
|
||||
from ComfyUI_H3_Continuum_Join.v3.latent_resize_nodes import (
|
||||
NODE_DISPLAY_NAME_MAPPINGS as LATENT_RESIZE_DISPLAY_NAME_MAPPINGS,
|
||||
)
|
||||
from ComfyUI_H3_Continuum_Join.v3.hires_fix_nodes import (
|
||||
H3ContinuumHiResFixV35,
|
||||
align_h3_manual_canvas,
|
||||
resolve_h3_native_latent_target,
|
||||
)
|
||||
from ComfyUI_H3_Continuum_Join.v3.second_pass import SecondPassContractError
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def _stub_core_h3_canvas_module(monkeypatch):
|
||||
comfy_extras = types.ModuleType("comfy_extras")
|
||||
comfy_extras.__path__ = []
|
||||
nodes_minimax_h3 = types.ModuleType("comfy_extras.nodes_minimax_h3")
|
||||
nodes_minimax_h3.CANVAS_MULTIPLE = 32
|
||||
comfy_extras.nodes_minimax_h3 = nodes_minimax_h3
|
||||
monkeypatch.setitem(sys.modules, "comfy_extras", comfy_extras)
|
||||
monkeypatch.setitem(
|
||||
sys.modules,
|
||||
"comfy_extras.nodes_minimax_h3",
|
||||
nodes_minimax_h3,
|
||||
)
|
||||
|
||||
|
||||
def _video(marker: str, *, height: int = 4, width: int = 4) -> dict:
|
||||
return {
|
||||
"samples": torch.zeros((1, 24, 3, height, width)),
|
||||
"marker": marker,
|
||||
}
|
||||
|
||||
|
||||
def _audio(marker: str) -> dict:
|
||||
return {
|
||||
"samples": torch.zeros((1, 8, 12)),
|
||||
"marker": marker,
|
||||
}
|
||||
|
||||
|
||||
def _plan(
|
||||
*,
|
||||
width: int = 64,
|
||||
height: int = 64,
|
||||
latent_width: int = 4,
|
||||
latent_height: int = 4,
|
||||
) -> dict:
|
||||
return {
|
||||
"width": width,
|
||||
"height": height,
|
||||
"second_pass_contract": {
|
||||
"version": 1,
|
||||
"physical_groups": [
|
||||
{
|
||||
"group_id": 0,
|
||||
"source_width": width,
|
||||
"source_height": height,
|
||||
"source_batch": 1,
|
||||
"latent_channels": 24,
|
||||
"source_latent_t": 3,
|
||||
"source_latent_w": latent_width,
|
||||
"source_latent_h": latent_height,
|
||||
}
|
||||
]
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
def test_disabled_returns_first_pass_objects_without_resize_or_sampling(monkeypatch):
|
||||
def unexpected_call(*_args, **_kwargs):
|
||||
raise AssertionError("disabled Hi-res fix must not resize or sample")
|
||||
|
||||
monkeypatch.setattr(
|
||||
"ComfyUI_H3_Continuum_Join.v3.hires_fix_nodes.resize_video_latents_via_vae",
|
||||
unexpected_call,
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
"ComfyUI_H3_Continuum_Join.v3.hires_fix_nodes.run_second_pass_groups",
|
||||
unexpected_call,
|
||||
)
|
||||
videos = [_video("video")]
|
||||
audios = [_audio("audio")]
|
||||
plan = {"width": 640, "height": 640}
|
||||
|
||||
output_video, output_audio, output_plan, status = H3ContinuumHiResFixV35().apply(
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
videos,
|
||||
audios,
|
||||
[plan],
|
||||
[False],
|
||||
["bislerp"],
|
||||
[2.0],
|
||||
[7],
|
||||
["must", "not be unwrapped"],
|
||||
["must", "not be unwrapped"],
|
||||
)
|
||||
|
||||
assert output_video is videos
|
||||
assert output_audio is audios
|
||||
assert output_plan is plan
|
||||
assert "disabled" in status
|
||||
|
||||
|
||||
def test_enabled_pixel_vae_roundtrip_then_reuses_second_pass_contract(monkeypatch):
|
||||
videos = [_video("first-pass", height=40, width=40)]
|
||||
resized = [_video("reencoded", height=80, width=80)]
|
||||
audios = [_audio("first-pass")]
|
||||
plan = _plan(width=640, height=640, latent_width=40, latent_height=40)
|
||||
sentinel = (
|
||||
[_video("refined")],
|
||||
audios,
|
||||
{"width": 1280, "height": 1280},
|
||||
"sampled",
|
||||
)
|
||||
calls = []
|
||||
schedule = object()
|
||||
|
||||
def fake_roundtrip(video_latents, assembly_plan, **kwargs):
|
||||
calls.append(("roundtrip", video_latents, assembly_plan, kwargs))
|
||||
return resized
|
||||
|
||||
def fake_second_pass(**kwargs):
|
||||
calls.append(("second_pass", kwargs))
|
||||
return sentinel
|
||||
|
||||
monkeypatch.setattr(
|
||||
"ComfyUI_H3_Continuum_Join.v3.hires_fix_nodes.resize_video_latents_via_vae",
|
||||
fake_roundtrip,
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
"ComfyUI_H3_Continuum_Join.v3.hires_fix_nodes.run_second_pass_groups",
|
||||
fake_second_pass,
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
"ComfyUI_H3_Continuum_Join.v3.hires_fix_nodes.h3_core_native_canvas",
|
||||
lambda *_args, **_kwargs: (768, 768),
|
||||
)
|
||||
|
||||
result = H3ContinuumHiResFixV35().apply(
|
||||
["model"],
|
||||
["clip"],
|
||||
["sampler"],
|
||||
[torch.tensor([0.3, 0.0])],
|
||||
videos,
|
||||
audios,
|
||||
[plan],
|
||||
[True],
|
||||
["lanczos"],
|
||||
[2.0],
|
||||
[17],
|
||||
[{"context": True}],
|
||||
["video-vae"],
|
||||
schedule,
|
||||
)
|
||||
|
||||
assert result[:3] == sentinel[:3]
|
||||
assert "mode=manual_scale_by" in result[3]
|
||||
assert "backend=sequential_pixel_vae_roundtrip" in result[3]
|
||||
assert "target=1280x1280" in result[3]
|
||||
assert "INFO" in result[3]
|
||||
assert calls[0] == (
|
||||
"roundtrip",
|
||||
videos,
|
||||
plan,
|
||||
{
|
||||
"video_vae": "video-vae",
|
||||
"target_width": 1280,
|
||||
"target_height": 1280,
|
||||
"upscale_method": "lanczos",
|
||||
},
|
||||
)
|
||||
second_pass = calls[1][1]
|
||||
assert second_pass["model"] == "model"
|
||||
assert second_pass["clip"] == "clip"
|
||||
assert second_pass["sampler"] == "sampler"
|
||||
assert second_pass["video_latents"] is resized
|
||||
assert second_pass["audio_latents"] is audios
|
||||
assert second_pass["assembly_plan"] is plan
|
||||
assert second_pass["refine_seed"] == 17
|
||||
assert second_pass["refine_context"] == {"context": True}
|
||||
assert second_pass["video_vae"] == "video-vae"
|
||||
assert second_pass["conditioning_upscale_method"] == "bilinear"
|
||||
assert second_pass["refine_schedule"] is schedule
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("latent_width", "latent_height", "expected_width", "expected_height"),
|
||||
(
|
||||
(36, 36, 704, 704),
|
||||
(64, 36, 1216, 704),
|
||||
),
|
||||
)
|
||||
def test_manual_scale_1_2_aligns_to_core_h3_canvas(
|
||||
latent_width,
|
||||
latent_height,
|
||||
expected_width,
|
||||
expected_height,
|
||||
):
|
||||
target = align_h3_manual_canvas(
|
||||
latent_width,
|
||||
latent_height,
|
||||
1.2,
|
||||
pixel_scale_width=16,
|
||||
pixel_scale_height=16,
|
||||
canvas_multiple=32,
|
||||
)
|
||||
|
||||
assert target == {
|
||||
"target_width": expected_width,
|
||||
"target_height": expected_height,
|
||||
"target_latent_width": expected_width // 16,
|
||||
"target_latent_height": expected_height // 16,
|
||||
}
|
||||
assert target["target_latent_width"] % 2 == 0
|
||||
assert target["target_latent_height"] % 2 == 0
|
||||
|
||||
|
||||
def test_manual_scale_1_2_passes_core_aligned_target_to_pixel_vae(monkeypatch):
|
||||
videos = [_video("first-pass", height=36, width=36)]
|
||||
resized = [_video("reencoded", height=44, width=44)]
|
||||
audios = [_audio("first-pass")]
|
||||
plan = _plan(width=576, height=576, latent_width=36, latent_height=36)
|
||||
calls = []
|
||||
|
||||
def fake_roundtrip(video_latents, assembly_plan, **kwargs):
|
||||
calls.append(("roundtrip", video_latents, assembly_plan, kwargs))
|
||||
return resized
|
||||
|
||||
def fake_second_pass(**kwargs):
|
||||
calls.append(("second_pass", kwargs))
|
||||
return (
|
||||
[_video("refined", height=44, width=44)],
|
||||
audios,
|
||||
{"width": 704, "height": 704},
|
||||
"sampled",
|
||||
)
|
||||
|
||||
monkeypatch.setattr(
|
||||
"ComfyUI_H3_Continuum_Join.v3.hires_fix_nodes.h3_core_native_canvas",
|
||||
lambda *_args, **_kwargs: (768, 768),
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
"ComfyUI_H3_Continuum_Join.v3.hires_fix_nodes.resize_video_latents_via_vae",
|
||||
fake_roundtrip,
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
"ComfyUI_H3_Continuum_Join.v3.hires_fix_nodes.run_second_pass_groups",
|
||||
fake_second_pass,
|
||||
)
|
||||
|
||||
result = H3ContinuumHiResFixV35().apply(
|
||||
["model"],
|
||||
["clip"],
|
||||
["sampler"],
|
||||
[torch.tensor([0.3, 0.0])],
|
||||
videos,
|
||||
audios,
|
||||
[plan],
|
||||
[True],
|
||||
["lanczos"],
|
||||
[1.2],
|
||||
[17],
|
||||
[{"context": True}],
|
||||
["video-vae"],
|
||||
)
|
||||
|
||||
assert calls[0] == (
|
||||
"roundtrip",
|
||||
videos,
|
||||
plan,
|
||||
{
|
||||
"video_vae": "video-vae",
|
||||
"target_width": 704,
|
||||
"target_height": 704,
|
||||
"upscale_method": "lanczos",
|
||||
},
|
||||
)
|
||||
assert calls[1][1]["video_latents"] is resized
|
||||
assert "target=704x704" in result[3]
|
||||
|
||||
|
||||
def test_native_auto_resizes_to_exact_core_target_then_samples(monkeypatch):
|
||||
videos = [_video("first-pass")]
|
||||
resized = [_video("native", height=6, width=6)]
|
||||
audios = [_audio("first-pass")]
|
||||
plan = _plan()
|
||||
calls = []
|
||||
|
||||
def fake_roundtrip(video_latents, assembly_plan, **kwargs):
|
||||
calls.append(("roundtrip", video_latents, assembly_plan, kwargs))
|
||||
return resized
|
||||
|
||||
def fake_second_pass(**kwargs):
|
||||
calls.append(("second_pass", kwargs))
|
||||
return (
|
||||
[_video("refined", height=6, width=6)],
|
||||
audios,
|
||||
{"width": 96, "height": 96},
|
||||
"sampled",
|
||||
)
|
||||
|
||||
monkeypatch.setattr(
|
||||
"ComfyUI_H3_Continuum_Join.v3.hires_fix_nodes.h3_core_native_canvas",
|
||||
lambda *_args, **_kwargs: (96, 96),
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
"ComfyUI_H3_Continuum_Join.v3.hires_fix_nodes.resize_video_latents_via_vae",
|
||||
fake_roundtrip,
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
"ComfyUI_H3_Continuum_Join.v3.hires_fix_nodes.run_second_pass_groups",
|
||||
fake_second_pass,
|
||||
)
|
||||
|
||||
result = H3ContinuumHiResFixV35().apply(
|
||||
["model"],
|
||||
["clip"],
|
||||
["sampler"],
|
||||
[torch.tensor([0.3, 0.0])],
|
||||
videos,
|
||||
audios,
|
||||
[plan],
|
||||
[True],
|
||||
["bilinear"],
|
||||
[0.0],
|
||||
[17],
|
||||
None,
|
||||
["video-vae"],
|
||||
)
|
||||
|
||||
assert calls[0] == (
|
||||
"roundtrip",
|
||||
videos,
|
||||
plan,
|
||||
{
|
||||
"video_vae": "video-vae",
|
||||
"upscale_method": "bilinear",
|
||||
"target_width": 96,
|
||||
"target_height": 96,
|
||||
},
|
||||
)
|
||||
assert calls[1][1]["video_latents"] is resized
|
||||
assert calls[1][1]["conditioning_upscale_method"] == "bilinear"
|
||||
assert result[2]["width"] == 96
|
||||
assert "mode=h3_native_canvas_auto" in result[3]
|
||||
assert "source=64x64" in result[3]
|
||||
assert "target=96x96" in result[3]
|
||||
assert "WARNING" not in result[3]
|
||||
|
||||
|
||||
def test_native_target_uses_core_canvas_and_never_shrinks_existing_latent():
|
||||
source = [_video("source", height=36, width=36)]
|
||||
plan = _plan(width=576, height=576, latent_width=36, latent_height=36)
|
||||
|
||||
native = resolve_h3_native_latent_target(
|
||||
source,
|
||||
plan,
|
||||
adapt_canvas_fn=lambda _width, _height: (768, 768),
|
||||
)
|
||||
|
||||
assert native["target_latent_width"] == 48
|
||||
assert native["target_latent_height"] == 48
|
||||
assert native["target_width"] == 768
|
||||
assert native["target_height"] == 768
|
||||
assert native["preserved_current"] is False
|
||||
|
||||
oversized = [_video("oversized", height=64, width=64)]
|
||||
preserved = resolve_h3_native_latent_target(
|
||||
oversized,
|
||||
plan,
|
||||
adapt_canvas_fn=lambda _width, _height: (768, 768),
|
||||
)
|
||||
|
||||
assert preserved["target_latent_width"] == 64
|
||||
assert preserved["target_latent_height"] == 64
|
||||
assert preserved["target_width"] == 1024
|
||||
assert preserved["target_height"] == 1024
|
||||
assert preserved["preserved_current"] is True
|
||||
|
||||
|
||||
def test_native_target_uses_exact_core_landscape_geometry():
|
||||
source = [_video("landscape", height=36, width=64)]
|
||||
plan = _plan(width=1024, height=576, latent_width=64, latent_height=36)
|
||||
|
||||
native = resolve_h3_native_latent_target(
|
||||
source,
|
||||
plan,
|
||||
adapt_canvas_fn=lambda _width, _height: (1344, 768),
|
||||
)
|
||||
|
||||
assert native["target_latent_width"] == 84
|
||||
assert native["target_latent_height"] == 48
|
||||
assert native["target_width"] == 1344
|
||||
assert native["target_height"] == 768
|
||||
|
||||
|
||||
def test_enabled_requires_video_vae_without_legacy_latent_fallback(monkeypatch):
|
||||
def unexpected_call(*_args, **_kwargs):
|
||||
raise AssertionError("missing VAE must fail before resize or sampling")
|
||||
|
||||
monkeypatch.setattr(
|
||||
"ComfyUI_H3_Continuum_Join.v3.hires_fix_nodes.resize_video_latents_via_vae",
|
||||
unexpected_call,
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
"ComfyUI_H3_Continuum_Join.v3.hires_fix_nodes.run_second_pass_groups",
|
||||
unexpected_call,
|
||||
)
|
||||
|
||||
with pytest.raises(SecondPassContractError, match="requires video_vae"):
|
||||
H3ContinuumHiResFixV35().apply(
|
||||
["model"],
|
||||
["clip"],
|
||||
["sampler"],
|
||||
[torch.tensor([0.3, 0.0])],
|
||||
[_video("first-pass")],
|
||||
[_audio("first-pass")],
|
||||
[_plan()],
|
||||
[True],
|
||||
["lanczos"],
|
||||
[2.0],
|
||||
[17],
|
||||
)
|
||||
|
||||
|
||||
def test_manual_scale_below_one_rejects_before_vae_or_sampling(monkeypatch):
|
||||
def unexpected_call(*_args, **_kwargs):
|
||||
raise AssertionError("invalid manual scale must fail before expensive work")
|
||||
|
||||
monkeypatch.setattr(
|
||||
"ComfyUI_H3_Continuum_Join.v3.hires_fix_nodes.resize_video_latents_via_vae",
|
||||
unexpected_call,
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
"ComfyUI_H3_Continuum_Join.v3.hires_fix_nodes.run_second_pass_groups",
|
||||
unexpected_call,
|
||||
)
|
||||
|
||||
with pytest.raises(SecondPassContractError, match="at least 1.0"):
|
||||
H3ContinuumHiResFixV35().apply(
|
||||
["model"],
|
||||
["clip"],
|
||||
["sampler"],
|
||||
[torch.tensor([0.3, 0.0])],
|
||||
[_video("first-pass")],
|
||||
[_audio("first-pass")],
|
||||
[_plan()],
|
||||
[True],
|
||||
["lanczos"],
|
||||
[0.5],
|
||||
[17],
|
||||
None,
|
||||
["video-vae"],
|
||||
)
|
||||
|
||||
|
||||
def test_lazy_inputs_are_requested_only_when_enabled():
|
||||
node = H3ContinuumHiResFixV35()
|
||||
|
||||
assert node.check_lazy_status([False]) == []
|
||||
assert node.check_lazy_status(
|
||||
[False],
|
||||
refine_context=[None],
|
||||
video_vae=[None],
|
||||
) == []
|
||||
assert node.check_lazy_status([True]) == [
|
||||
"model",
|
||||
"clip",
|
||||
"sampler",
|
||||
"sigmas",
|
||||
]
|
||||
assert node.check_lazy_status(
|
||||
[True],
|
||||
model=(None,),
|
||||
clip=(None,),
|
||||
sampler=(None,),
|
||||
sigmas=(None,),
|
||||
) == ["model", "clip", "sampler", "sigmas"]
|
||||
assert node.check_lazy_status(
|
||||
[True],
|
||||
model=["model"],
|
||||
clip=["clip"],
|
||||
sampler=["sampler"],
|
||||
sigmas=["sigmas"],
|
||||
) == []
|
||||
assert node.check_lazy_status(
|
||||
[True],
|
||||
model=["model"],
|
||||
clip=["clip"],
|
||||
sampler=["sampler"],
|
||||
sigmas=["sigmas"],
|
||||
refine_context=[None],
|
||||
video_vae=[None],
|
||||
) == ["refine_context", "video_vae"]
|
||||
|
||||
|
||||
def test_three_v35_nodes_are_registered_with_final_display_names():
|
||||
assert NODE_CLASS_MAPPINGS["H3ContinuumHiResFixV35"] is H3ContinuumHiResFixV35
|
||||
assert NODE_DISPLAY_NAME_MAPPINGS["H3ContinuumHiResFixV35"] == (
|
||||
"H3 Continuum Hi-Res Fix V3.5"
|
||||
)
|
||||
assert SECOND_PASS_DISPLAY_NAME_MAPPINGS["H3ContinuumSecondPassV35"] == (
|
||||
"H3 Continuum Second Pass"
|
||||
)
|
||||
assert LATENT_RESIZE_DISPLAY_NAME_MAPPINGS["H3ContinuumLatentResizeV35"] == (
|
||||
"H3 Continuum Latent Resize V3.5"
|
||||
)
|
||||
assert H3ContinuumHiResFixV35.INPUT_IS_LIST is True
|
||||
assert H3ContinuumHiResFixV35.OUTPUT_IS_LIST == (True, True, False, False)
|
||||
|
||||
|
||||
def test_hires_fix_schema_exposes_one_node_controls_and_lazy_sampling_inputs():
|
||||
schema = H3ContinuumHiResFixV35.INPUT_TYPES()
|
||||
required = schema["required"]
|
||||
|
||||
assert required["enabled"][1]["default"] is True
|
||||
assert required["upscale_method"][0][0] == "lanczos"
|
||||
assert required["upscale_method"][1]["default"] == "lanczos"
|
||||
assert required["scale_by"][1] == {
|
||||
"default": 2.0,
|
||||
"min": 0.0,
|
||||
"max": 4.0,
|
||||
"step": 0.01,
|
||||
"tooltip": (
|
||||
"2.0 = validated 2x Pixel/VAE Hi-res Fix. 0 uses the "
|
||||
"ComfyUI Core H3 native canvas automatically. Manual "
|
||||
"values follow the existing Second Pass contract and must "
|
||||
"be 1.0 or greater."
|
||||
),
|
||||
}
|
||||
assert all(required[name][1]["lazy"] is True for name in (
|
||||
"model",
|
||||
"clip",
|
||||
"sampler",
|
||||
"sigmas",
|
||||
))
|
||||
assert schema["optional"] == {
|
||||
"refine_context": ("H3_CONTINUUM_REFINE_CONTEXT", {"lazy": True}),
|
||||
"video_vae": (
|
||||
"VAE",
|
||||
{
|
||||
"lazy": True,
|
||||
"tooltip": (
|
||||
"Required while enabled for the safe Pixel/VAE roundtrip; "
|
||||
"not evaluated while disabled."
|
||||
),
|
||||
},
|
||||
),
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import torch
|
||||
import torch.nn.functional as F
|
||||
|
||||
from ComfyUI_H3_Continuum_Join.v3.latent_resize_nodes import NODE_CLASS_MAPPINGS
|
||||
from ComfyUI_H3_Continuum_Join.v3.latent_resize_nodes import (
|
||||
H3ContinuumLatentResizeV35,
|
||||
UPSCALE_METHODS,
|
||||
resize_video_latents,
|
||||
resize_video_latents_to_size,
|
||||
)
|
||||
|
||||
|
||||
def _latent(shape: tuple[int, ...], *, marker: str) -> dict:
|
||||
return {
|
||||
"samples": torch.arange(torch.tensor(shape).prod().item(), dtype=torch.float32).reshape(shape),
|
||||
"marker": marker,
|
||||
}
|
||||
|
||||
|
||||
def _test_upscale(samples, width, height, upscale_method, crop):
|
||||
assert crop == "disabled"
|
||||
original = samples.shape
|
||||
flattened = samples.movedim(2, 1).reshape(
|
||||
-1,
|
||||
original[1],
|
||||
original[-2],
|
||||
original[-1],
|
||||
)
|
||||
mode = "bilinear" if upscale_method == "bislerp" else upscale_method
|
||||
output = F.interpolate(flattened, size=(height, width), mode=mode)
|
||||
return output.reshape((original[0], -1, original[1], height, width)).movedim(
|
||||
2,
|
||||
1,
|
||||
)
|
||||
|
||||
|
||||
def test_resize_preserves_physical_groups_bct_order_and_metadata() -> None:
|
||||
inputs = [
|
||||
_latent((1, 24, 37, 4, 5), marker="group-1"),
|
||||
_latent((1, 24, 77, 4, 5), marker="group-2"),
|
||||
]
|
||||
|
||||
outputs = resize_video_latents(
|
||||
inputs,
|
||||
upscale_method="bilinear",
|
||||
scale_by=2.0,
|
||||
upscale_fn=_test_upscale,
|
||||
)
|
||||
|
||||
assert [item["samples"].shape for item in outputs] == [
|
||||
(1, 24, 37, 8, 10),
|
||||
(1, 24, 77, 8, 10),
|
||||
]
|
||||
assert [item["marker"] for item in outputs] == ["group-1", "group-2"]
|
||||
assert all(after is not before for before, after in zip(inputs, outputs, strict=True))
|
||||
assert [item["samples"].shape for item in inputs] == [
|
||||
(1, 24, 37, 4, 5),
|
||||
(1, 24, 77, 4, 5),
|
||||
]
|
||||
|
||||
|
||||
def test_resize_delegates_dimensions_method_and_crop_to_core_boundary() -> None:
|
||||
latent = _latent((1, 24, 3, 4, 5), marker="core")
|
||||
calls = []
|
||||
|
||||
def capture(samples, width, height, upscale_method, crop):
|
||||
calls.append((samples, width, height, upscale_method, crop))
|
||||
return _test_upscale(samples, width, height, upscale_method, crop)
|
||||
|
||||
output = resize_video_latents(
|
||||
[latent],
|
||||
upscale_method="bicubic",
|
||||
scale_by=1.5,
|
||||
upscale_fn=capture,
|
||||
)[0]
|
||||
|
||||
assert calls == [(latent["samples"], 8, 6, "bicubic", "disabled")]
|
||||
assert output["samples"].shape == (1, 24, 3, 6, 8)
|
||||
|
||||
|
||||
def test_resize_to_exact_latent_geometry_preserves_groups_and_metadata() -> None:
|
||||
inputs = [
|
||||
_latent((1, 24, 37, 4, 5), marker="group-1"),
|
||||
_latent((1, 24, 77, 4, 5), marker="group-2"),
|
||||
]
|
||||
|
||||
outputs = resize_video_latents_to_size(
|
||||
inputs,
|
||||
upscale_method="bilinear",
|
||||
target_width=9,
|
||||
target_height=7,
|
||||
upscale_fn=_test_upscale,
|
||||
)
|
||||
|
||||
assert [item["samples"].shape for item in outputs] == [
|
||||
(1, 24, 37, 7, 9),
|
||||
(1, 24, 77, 7, 9),
|
||||
]
|
||||
assert [item["marker"] for item in outputs] == ["group-1", "group-2"]
|
||||
|
||||
|
||||
def test_bislerp_preserves_dtype_and_returns_finite_video_latent() -> None:
|
||||
latent = {"samples": torch.randn((1, 24, 2, 3, 3), dtype=torch.float32)}
|
||||
output = resize_video_latents(
|
||||
[latent],
|
||||
upscale_method="bislerp",
|
||||
scale_by=2.0,
|
||||
upscale_fn=_test_upscale,
|
||||
)[0]["samples"]
|
||||
|
||||
assert output.shape == (1, 24, 2, 6, 6)
|
||||
assert output.dtype == latent["samples"].dtype
|
||||
assert torch.isfinite(output).all()
|
||||
|
||||
|
||||
def test_latent_resize_node_is_registered_and_core_compatible() -> None:
|
||||
node_class = NODE_CLASS_MAPPINGS["H3ContinuumLatentResizeV35"]
|
||||
assert node_class is H3ContinuumLatentResizeV35
|
||||
assert node_class.DEPRECATED is False
|
||||
assert node_class.INPUT_IS_LIST is True
|
||||
assert node_class.OUTPUT_IS_LIST == (True,)
|
||||
assert list(UPSCALE_METHODS) == [
|
||||
"nearest-exact",
|
||||
"bilinear",
|
||||
"area",
|
||||
"bicubic",
|
||||
"bislerp",
|
||||
]
|
||||
|
||||
|
||||
def test_node_unwraps_widget_lists_but_preserves_physical_latent_list(monkeypatch) -> None:
|
||||
monkeypatch.setitem(
|
||||
H3ContinuumLatentResizeV35.resize.__globals__,
|
||||
"resize_video_latents",
|
||||
lambda video_latents, **kwargs: resize_video_latents(
|
||||
video_latents,
|
||||
upscale_fn=_test_upscale,
|
||||
**kwargs,
|
||||
),
|
||||
)
|
||||
inputs = [_latent((1, 24, 2, 2, 2), marker="one")]
|
||||
(outputs,) = H3ContinuumLatentResizeV35().resize(
|
||||
inputs,
|
||||
["nearest-exact"],
|
||||
[2.0],
|
||||
)
|
||||
|
||||
assert len(outputs) == 1
|
||||
assert outputs[0]["samples"].shape == (1, 24, 2, 4, 4)
|
||||
assert outputs[0]["marker"] == "one"
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user