Release V2.1.4 UI simplification

This commit is contained in:
ukr8b3g-cmyk
2026-08-10 16:28:20 +09:00
commit 83590a3935
76 changed files with 10956 additions and 0 deletions
+17
View File
@@ -0,0 +1,17 @@
from __future__ import annotations
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
+83
View File
@@ -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)
+156
View File
@@ -0,0 +1,156 @@
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):
# 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 + 74)
segments.append((*audio_ref, "ref_audio"))
row += 74
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 + 37, 0] = torch.arange(37, dtype=torch.float64) + 3.0
pos[a0 + 37 : a1, 0] = torch.arange(37, 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 = text 3 + max(audio 37, video span 36 2/3) = 40.
ta0, ta1 = target_audio
pos[ta0 : ta0 + 10, 0] = torch.arange(10, dtype=torch.float64) + 40.0
pos[ta0 + 10 : ta1, 0] = torch.arange(10, dtype=torch.float64) + 40.0
tv0, _tv1 = target_video
for slot, value in enumerate(_video_times(40.0)):
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)
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")
# Reference cursor shift is 37.
assert torch.all(layout.position_ids[cond_start : cond_start + 2, 0] == 75.0)
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),
)
+219
View File
@@ -0,0 +1,219 @@
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 (
_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, 1, 1, 1))
def test_apply_model_wrapper_repairs_payload_before_executor():
video = torch.zeros(1, 24, 1, 1, 1)
audio = torch.zeros(1, 32, 2, 1)
ref = {
"kind": "video_audio",
"latent_t": 1,
"latent_h": 1,
"latent_w": 1,
"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_fails_when_actual_topology_changes():
video = torch.zeros(1, 24, 1, 1, 1)
audio = torch.zeros(1, 32, 2, 1)
ref = {
"kind": "video_audio",
"latent_t": 1,
"latent_h": 1,
"latent_w": 1,
"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,
)
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()
source.model_options = {"transformer_options": {"existing": "kept"}}
base = patch_model(source, strict=True, debug=False)
first = clone_model_for_chunk(
base,
strict=True,
debug=False,
chunk_index=1,
context_frames=None,
)
second = clone_model_for_chunk(
base,
strict=True,
debug=False,
chunk_index=2,
context_frames=22,
)
third = clone_model_for_chunk(
base,
strict=True,
debug=False,
chunk_index=3,
context_frames=22,
)
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 base.model_options["transformer_options"]
+95
View File
@@ -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
+20
View File
@@ -0,0 +1,20 @@
from ComfyUI_H3_Continuum_Join import public_api
def test_public_api_is_v2_ready_and_complete():
assert public_api.PUBLIC_API_VERSION == 2
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))
+69
View File
@@ -0,0 +1,69 @@
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_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)
+49
View File
@@ -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
+82
View File
@@ -0,0 +1,82 @@
import pytest
from ComfyUI_H3_Continuum_Join.temporal import (
align_frame_count_nearest,
audio_grid_offset,
audio_latent_t,
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)
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(5, 151):
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
+32
View File
@@ -0,0 +1,32 @@
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
def test_v214_frontend_collapses_advanced_controls_without_reordering_outputs():
source = (ROOT / "web" / "h3_continuum_v214.js").read_text(encoding="utf-8")
assert 'const ADVANCED_PROPERTY = "h3_show_advanced"' in source
assert '["last_frame", "IMAGE"]' in source
assert '["prompt_plan", "H3_CONTINUUM_PROMPT_PLAN"]' in source
assert '["last_state", "H3_CONTINUUM_STATE"]' in source
assert "hasAdvancedConnection(node)" in source
assert "removeUnlinkedAdvancedSlots(node)" in source
assert "Advanced Settings ▸" in source
assert "placeAdvancedButton(node, button, expanded)" in source
def test_all_non_primary_nodes_use_native_comfyui_deprecation():
source = (ROOT / "nodes.py").read_text(encoding="utf-8")
assert 'if _node_id == "H3ContinuumSamplerV2"' in source
assert "_node_class.DEPRECATED = True" in source
assert 'f"{CATEGORY}/Legacy"' in source
assert 'f"[Legacy] {_display_name}"' in source
def test_v214_version_metadata_matches():
assert 'PACKAGE_VERSION = "2.1.4"' in (ROOT / "version.py").read_text(encoding="utf-8")
assert "version = 2.1.4" in (ROOT / "metadata.ini").read_text(encoding="utf-8")
assert 'version = "2.1.4"' in (ROOT / "pyproject.toml").read_text(encoding="utf-8")
+59
View File
@@ -0,0 +1,59 @@
import torch
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)
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
+169
View File
@@ -0,0 +1,169 @@
import pytest
from ComfyUI_H3_Continuum_Join.constants import (
PROMPT_FORMAT_AUTO,
PROMPT_FORMAT_FIXED,
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,
validate_prompt_plan,
)
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
@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"]
def test_timeline_requires_coverage():
with pytest.raises(PromptPlanError):
make_prompt_plan(
mode=PROMPT_MODE_TIMELINE,
script="[0-5s]\none",
chunks=2,
chunk_seconds=5,
)
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_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,
)
updated = apply_prompt_overrides(plan, [None, "same"])
assert updated["hashes"] == plan["hashes"]
def test_external_prompt_rejects_empty_connected_text():
plan = make_prompt_plan(
mode=PROMPT_MODE_FIXED,
script="fallback",
chunks=1,
chunk_seconds=5,
)
with pytest.raises(PromptPlanError):
apply_prompt_overrides(plan, [" "])
def test_sequence_prompt_precedes_connected_plan_and_legacy_script():
connected = make_prompt_plan(
mode=PROMPT_MODE_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_MODE_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 is connected
+56
View File
@@ -0,0 +1,56 @@
from pathlib import Path
from ComfyUI_H3_Continuum_Join.nodes import NODE_CLASS_MAPPINGS
from ComfyUI_H3_Continuum_Join.constants import (
PROMPT_FORMAT_OPTIONS,
SEAM_CORRECTION_OFF,
)
def test_v2_nodes_are_registered_without_removing_v1():
expected = {
"H3ContinuumJoin",
"H3ContinuumFinish",
"H3ContinuumAssemble",
"H3ContinuumSaveState",
"H3ContinuumLoadState",
"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_the_legacy_seam_path():
schema = NODE_CLASS_MAPPINGS["H3ContinuumSamplerV2"].INPUT_TYPES()
assert schema["required"]["seam_correction"][1]["default"] == SEAM_CORRECTION_OFF
def test_v2_interface_keeps_sequence_socket_and_collapsible_overrides():
root = Path(__file__).resolve().parents[1]
source = (root / "web" / "h3_continuum_v2.js").read_text(encoding="utf-8")
assert 'const SEQUENCE_PROMPT_INPUT = "sequence_prompt"' in source
assert "Individual Clip Overrides" in source
assert "!inputIsConnected(input)" in source
+86
View File
@@ -0,0 +1,86 @@
import torch
from ComfyUI_H3_Continuum_Join.v2.seam_guard import (
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_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
+46
View File
@@ -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
+159
View File
@@ -0,0 +1,159 @@
from types import SimpleNamespace
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
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), {}]]
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: [])
monkeypatch.setattr(sequence, "patch_model", lambda model, strict, debug: model)
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"])))
images = torch.zeros(362, 2, 2, 3)
audio = {"waveform": torch.zeros(1, 2, round(362 / 24 * 32000)), "sample_rate": 32000}
return images, audio, []
monkeypatch.setattr(sequence, "sample_chunk", sample_chunk)
monkeypatch.setattr(sequence, "decode_sequence", decode_sequence)
def unexpected_seam_decode(**kwargs):
raise AssertionError("Off must not enter the V2.1 seam decoder")
monkeypatch.setattr(sequence, "decode_sequence_with_seam", unexpected_seam_decode)
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, event in enumerate(events) if event[0] == "sample"]
decode_position = next(i for i, event in enumerate(events) if event[0] == "decode")
assert len(sample_positions) == 3
assert max(sample_positions) < decode_position
sample_events = [event for event in events if event[0] == "sample"]
assert sample_events[0][3] is None
assert sample_events[1][3]["min_actual_prefix_steps"] == 2
assert sample_events[2][3]["min_actual_prefix_steps"] == 2
clone_events = [event for event in events if event[0] == "clone"]
assert [event[2] for event in clone_events] == [None, 22, 22]
# Fixed mode encodes its shared text conditioning only once.
assert sum(event[0] == "encode" for event in events) == 1
assert images.shape[0] == 360
assert audio["waveform"].shape[-1] == 480000
assert last_state["clip_index"] == 3
assert len(session["chunks"]) == 3
assert "call-local MODEL clone per chunk" in report
+79
View File
@@ -0,0 +1,79 @@
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"]
+41
View File
@@ -0,0 +1,41 @@
import json
from pathlib import Path
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)
def test_bundled_v2_example_serializes_control_after_generate_slot():
root = Path(__file__).resolve().parents[1]
data = json.loads((root / "examples" / "H3_Continuum_V2_3x5s.json").read_text(encoding="utf-8"))
node = next(n for n in data["nodes"] if n["type"] == "H3ContinuumSamplerV2")
values = node["widgets_values"]
assert len(values) == 16
assert values[8] in {"fixed", "increment", "decrement", "randomize"}
assert values[11] in {"Basic", "Full", "Off"}