Release H3 Continuum V3.3.0

This commit is contained in:
ukr8b3g-cmyk
2026-08-16 20:32:47 +09:00
parent a908e4884f
commit fb22c20149
38 changed files with 3598 additions and 363 deletions
+24
View File
@@ -81,6 +81,30 @@ def test_apply_model_wrapper_repairs_payload_before_executor():
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_fails_when_actual_topology_changes():
video = torch.zeros(1, 24, 1, 1, 1)
audio = torch.zeros(1, 32, 2, 1)
+210
View File
@@ -0,0 +1,210 @@
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_timeline_node_is_separate_and_stable_schema_is_unchanged():
stable = H3ContinuumSamplerProduction.INPUT_TYPES()
experimental = H3ContinuumSamplerTimelineVideo.INPUT_TYPES()
assert "timeline_video" not in stable["required"]
assert "timeline_video_size" not in stable["required"]
assert "timeline_video" not in experimental["required"]
assert experimental["optional"]["timeline_video"][0] == "VIDEO"
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) == ""
+1 -1
View File
@@ -139,4 +139,4 @@ def test_v217_result_pack_expands_legacy_outputs():
def test_v217_has_no_frontend_display_controller():
assert not (ROOT / "web" / "h3_continuum_v2.js").exists()
version_source = (ROOT / "version.py").read_text(encoding="utf-8")
assert 'PACKAGE_VERSION = "3.2.1"' in version_source
assert 'PACKAGE_VERSION = "3.3.0"' in version_source
+89 -3
View File
@@ -14,6 +14,7 @@ from ComfyUI_H3_Continuum_Join.v2.prompts import (
detect_prompt_mode,
make_prompt_plan,
parse_sparse_prompt_overrides,
prompt_plan_report,
validate_sparse_prompt_overrides,
validate_prompt_plan,
)
@@ -72,14 +73,94 @@ def test_timeline_prompt_maps_ranges_and_chunk_headers():
assert plan["prompts"] == ["one", "two", "three"]
def test_timeline_requires_coverage():
with pytest.raises(PromptPlanError):
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_reports_actionable_diagnostic(script, code):
with pytest.raises(PromptPlanError) as captured:
make_prompt_plan(
mode=PROMPT_MODE_TIMELINE,
script="[0-5s]\none",
script=script,
chunks=2,
chunk_seconds=5,
)
message = str(captured.value)
assert code in message
assert "Suggested fix:" in message
def test_duplicate_chunk_section_is_an_error():
with pytest.raises(PromptPlanError, match="H3C-P003"):
make_prompt_plan(
mode=PROMPT_MODE_TIMELINE,
script="[Chunk 1]\none\n[Chunk 1]\ntwo",
chunks=2,
chunk_seconds=5,
)
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():
@@ -148,3 +229,8 @@ def test_sparse_override_rejects_out_of_range_clip():
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")
+37 -1
View File
@@ -3,7 +3,7 @@ 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
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
@@ -19,6 +19,18 @@ class FakeClip:
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
@@ -28,6 +40,30 @@ def test_identity_fingerprint_hashes_full_resized_rgb_tensor():
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)
+62
View File
@@ -18,6 +18,10 @@ from ComfyUI_H3_Continuum_Join.run_storage import (
resolve_run_storage_name,
revision_identity,
)
from ComfyUI_H3_Continuum_Join.reference import (
REFERENCE_SIZE_MATCH_OUTPUT,
ReferenceAssets,
)
from ComfyUI_H3_Continuum_Join.graph_contract import (
CHECKPOINT_FL2VA,
CHECKPOINT_REF2VA,
@@ -311,6 +315,64 @@ def _sampling_contract(
)
def test_v322_golden_reference_contract_preserves_revision_identity():
model = _Model()
clip = _Clip()
video_vae = _VideoVAE()
sampler = _Sampler()
no_reference, safe, reasons = _sampling_contract(
model=model,
clip=clip,
video_vae=video_vae,
sampler=sampler,
conditioning_mode="t2va",
first_frame_hash="",
reference_contract=None,
)
assert safe, reasons
assert "reference" not in no_reference["global"]
for count in (1, 2):
hashes = tuple(str(index) * 64 for index in range(1, count + 1))
expected_reference = {
"reference_contract_version": 1,
"count": count,
"size_mode": REFERENCE_SIZE_MATCH_OUTPUT,
"image_hashes": list(hashes),
"combined_hash": "a" * 64,
}
actual_reference = ReferenceAssets(
images=tuple(torch.zeros((1, 32, 32, 3)) for _ in range(count)),
latents=tuple(None for _ in range(count)),
image_hashes=hashes,
combined_hash="a" * 64,
size_mode=REFERENCE_SIZE_MATCH_OUTPUT,
).contract
expected, expected_safe, expected_reasons = _sampling_contract(
model=model,
clip=clip,
video_vae=video_vae,
sampler=sampler,
conditioning_mode="reference",
first_frame_hash="",
reference_contract=expected_reference,
)
actual, actual_safe, actual_reasons = _sampling_contract(
model=model,
clip=clip,
video_vae=video_vae,
sampler=sampler,
conditioning_mode="reference",
first_frame_hash="",
reference_contract=actual_reference,
)
assert expected_safe, expected_reasons
assert actual_safe, actual_reasons
assert actual == expected
assert revision_identity(actual) == revision_identity(expected)
def test_clip_and_required_video_vae_are_part_of_sampling_contract():
clip = _Clip()
vae = _VideoVAE()
+126 -11
View File
@@ -10,6 +10,7 @@ from ComfyUI_H3_Continuum_Join.reference import (
prepare_reference_assets,
validate_reference_prompts,
)
from ComfyUI_H3_Continuum_Join.reference_audio import validate_reference_audio_prompts
from ComfyUI_H3_Continuum_Join.v3.nodes import _validate_reference_checkpoint
@@ -44,14 +45,52 @@ def test_reference_contract_contains_metadata_only():
assert not any(torch.is_tensor(value) for value in contract.values())
def test_picture_tags_must_match_connected_references():
@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) == ""
with pytest.raises(ReferenceConditioningError, match="Picture 2"):
validate_reference_prompts(["Use <Picture 2>."], 1)
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
@@ -66,6 +105,83 @@ def test_reference_socket_rejects_image_batches():
)
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 _reference_prompt(checkpoint_name: str) -> dict:
return {
"1": {
@@ -79,20 +195,19 @@ def _reference_prompt(checkpoint_name: str) -> dict:
}
def test_strict_reference_requires_ref2va_checkpoint():
def test_reference_checkpoint_classification_is_diagnostic_only():
assert _validate_reference_checkpoint(
_reference_prompt("minimax_h3_ref2va_pruned_int8.safetensors"),
"2",
strict_compatibility=True,
) == "ref2va"
with pytest.raises(ValueError, match="FL2VA checkpoint"):
_validate_reference_checkpoint(
_reference_prompt("minimax_h3_fl2va_pruned_int8.safetensors"),
"2",
strict_compatibility=True,
)
assert _validate_reference_checkpoint(
_reference_prompt("minimax_h3_fl2va_pruned_int8.safetensors"),
"2",
strict_compatibility=False,
strict_compatibility=True,
) == "fl2va"
assert _validate_reference_checkpoint(
_reference_prompt("minimax_h3_unknown.safetensors"),
"2",
strict_compatibility=True,
) == "unknown"
+96
View File
@@ -0,0 +1,96 @@
import torch
from ComfyUI_H3_Continuum_Join.constants import DIAGNOSTICS_OPTIONS
from ComfyUI_H3_Continuum_Join.v3.assembly import (
H3ContinuumAssembleSeamExperimental,
VIDEO_SEAM_ANALYZE,
VIDEO_SEAM_AUTO,
VIDEO_SEAM_AUTO_2,
)
from ComfyUI_H3_Continuum_Join.v3.nodes import NODE_CLASS_MAPPINGS
from ComfyUI_H3_Continuum_Join.v3.seam_test_source import (
H3ContinuumSeamTestSource,
TEST_SIZE_256,
)
from ComfyUI_H3_Continuum_Join.v3.video_seam import analyze_decoded_boundaries
def _source_outputs():
image = torch.full((1, 256, 256, 3), 0.5, dtype=torch.float32)
return H3ContinuumSeamTestSource().create(
image,
exposure_change=0.08,
test_resolution=TEST_SIZE_256,
)
def test_seam_test_source_is_registered():
assert NODE_CLASS_MAPPINGS["H3ContinuumSeamTestSource"] is H3ContinuumSeamTestSource
def test_seam_test_source_is_public_in_root_registration():
from ComfyUI_H3_Continuum_Join import nodes as root_nodes
node_class = root_nodes.NODE_CLASS_MAPPINGS["H3ContinuumSeamTestSource"]
assert not getattr(node_class, "DEPRECATED", False)
assert node_class.CATEGORY == "MiniMax H3/Continuum/Testing"
assert root_nodes.NODE_DISPLAY_NAME_MAPPINGS["H3ContinuumSeamTestSource"] == (
"H3 Continuum Seam Test Source (Experimental)"
)
def test_seam_test_source_emits_realistic_three_chunk_contract():
images, audio, plan, instructions = _source_outputs()
assert [tuple(item.shape) for item in images] == [
(124, 256, 256, 3),
(141, 256, 256, 3),
(141, 256, 256, 3),
]
assert len(audio) == 3
assert plan["target_frames"] == 360
assert [item["trim_frames"] for item in plan["chunks"]] == [0, 22, 22]
assert "Analyze Only" in instructions
assert "Auto 2" in instructions
def test_controlled_boundaries_are_classified_as_exposure_ramps():
images, _audio, plan, _instructions = _source_outputs()
analyses = analyze_decoded_boundaries(images=images, assembly_plan=plan)
assert len(analyses) == 2
assert all(item.exposure_ramp_candidate for item in analyses)
assert [item.classification for item in analyses] == [
"exposure_ramp",
"exposure_ramp",
]
def test_auto_two_corrects_only_the_controlled_ramp_frames():
images, audio, plan, _instructions = _source_outputs()
node = H3ContinuumAssembleSeamExperimental()
common = {
"images": images,
"audio": audio,
"assembly_plan": [plan],
"exact_total_duration": [False],
"audio_seam": ["Off"],
"diagnostics": [DIAGNOSTICS_OPTIONS[0]],
}
analyzed_images, _analyzed_audio, analyzed_report = node.assemble(
video_seam=[VIDEO_SEAM_ANALYZE],
**common,
)
auto_images, _auto_audio, auto_report = node.assemble(
video_seam=[VIDEO_SEAM_AUTO],
**common,
)
auto_two_images, _auto_two_audio, auto_two_report = node.assemble(
video_seam=[VIDEO_SEAM_AUTO_2],
**common,
)
assert torch.equal(auto_images, analyzed_images)
assert "class=exposure_ramp" in analyzed_report
assert "action=kept native boundary" in auto_report
assert not torch.equal(auto_two_images, analyzed_images)
assert auto_two_report.count(
"normalized exposure/color on 4 exposure ramp boundary frame(s)"
) == 2
+356
View File
@@ -0,0 +1,356 @@
import torch
from ComfyUI_H3_Continuum_Join.constants import DIAGNOSTICS_OPTIONS
from ComfyUI_H3_Continuum_Join.hardening import enrich_assembly_plan
from ComfyUI_H3_Continuum_Join.v3.assembly import (
H3ContinuumAssembleSeamExperimental,
VIDEO_SEAM_ANALYZE,
VIDEO_SEAM_AUTO,
VIDEO_SEAM_OFF,
)
from ComfyUI_H3_Continuum_Join.v3.nodes import NODE_CLASS_MAPPINGS
from ComfyUI_H3_Continuum_Join.v3.plan import ASSEMBLY_PLAN_MAGIC
from ComfyUI_H3_Continuum_Join.v3.video_seam import analyze_video_boundary
def _frames(values, *, height=8, width=8):
return (
torch.tensor(values, dtype=torch.float32)
.reshape(-1, 1, 1, 1)
.expand(-1, height, width, 3)
.clone()
)
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": 32,
"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": 36,
"expected_audio_latent_t": 235,
},
],
}
)
def _decoded():
images = [
torch.full((124, 8, 8, 3), 0.25, dtype=torch.float32),
torch.full((141, 8, 8, 3), 0.25, dtype=torch.float32),
]
audio = [
{"waveform": torch.zeros((1, 2, 190000)), "sample_rate": 32000},
{"waveform": torch.zeros((1, 2, 190000)), "sample_rate": 32000},
]
return images, audio
def test_clean_boundary_keeps_the_nominal_cut():
previous = _frames([0.1, 0.2, 0.3, 0.4, 0.5, 0.6])
current = _frames([0.5, 0.6, 0.7, 0.8, 0.9])
analysis = analyze_video_boundary(previous, current, trim_frames=2)
assert analysis.recommended_rewind == 0
assert not analysis.scene_cut
assert not analysis.transient_flash_candidate
assert analysis.classification == "clean_boundary"
def test_single_frame_flash_recommends_an_earlier_candidate():
previous = _frames([0.1, 0.2, 0.3, 0.4, 0.5, 0.6])
current = _frames([0.5, 0.6, 1.0, 0.8, 0.9])
analysis = analyze_video_boundary(previous, current, trim_frames=2)
assert analysis.recommended_rewind == 1
assert analysis.improvement >= 0.06
assert not analysis.scene_cut
assert analysis.transient_flash_candidate
assert analysis.flash_reversal >= 0.35
assert analysis.flash_global_fraction >= 0.75
assert analysis.classification == "transient_flash"
def test_persistent_content_change_is_guarded_as_a_scene_cut():
previous = _frames([0.1, 0.2, 0.3, 0.4, 0.5, 0.6])
current = _frames([0.5, 0.6, 0.95, 0.95, 0.95])
analysis = analyze_video_boundary(previous, current, trim_frames=2)
assert analysis.scene_cut
assert analysis.recommended_rewind == 0
assert not analysis.transient_flash_candidate
assert analysis.classification == "scene_cut"
def test_small_global_reversal_is_classified_as_micro_flash():
previous = _frames([0.4, 0.4, 0.4, 0.4, 0.4, 0.4])
current = _frames([0.4, 0.4, 0.408, 0.4, 0.4, 0.4])
analysis = analyze_video_boundary(previous, current, trim_frames=2)
assert not analysis.transient_flash_candidate
assert analysis.micro_flash_candidate
assert analysis.classification == "micro_flash"
def test_persistent_global_change_is_classified_as_exposure_ramp():
previous = _frames([0.4, 0.4, 0.4, 0.4, 0.4, 0.4])
current = _frames([0.4, 0.4, 0.42, 0.44, 0.46, 0.48])
analysis = analyze_video_boundary(previous, current, trim_frames=2)
assert not analysis.transient_flash_candidate
assert analysis.exposure_ramp_candidate
assert analysis.classification == "exposure_ramp"
def test_local_velocity_jump_is_classified_as_motion_hitch():
def moving_bar(position):
frame = torch.zeros((16, 16, 3), dtype=torch.float32)
frame[:, position : position + 2, :] = 1.0
return frame
previous = torch.stack([moving_bar(position) for position in [1, 2, 3, 4, 5, 6]])
current = torch.stack([moving_bar(position) for position in [4, 5, 9, 10, 11, 12]])
analysis = analyze_video_boundary(previous, current, trim_frames=2)
assert not analysis.transient_flash_candidate
assert not analysis.micro_flash_candidate
assert analysis.motion_hitch_candidate
assert analysis.motion_jump_ratio >= 1.60
assert analysis.classification == "motion_hitch"
def test_local_motion_is_not_reported_as_a_global_flash():
previous = torch.full((6, 8, 8, 3), 0.4, dtype=torch.float32)
current = torch.full((5, 8, 8, 3), 0.4, dtype=torch.float32)
current[2, :2, :2, :] = 1.0
analysis = analyze_video_boundary(previous, current, trim_frames=2)
assert analysis.flash_global_fraction < 0.75
assert not analysis.transient_flash_candidate
def test_analyze_only_preserves_assembled_image_and_audio_content():
images, audio = _decoded()
node = H3ContinuumAssembleSeamExperimental()
common = {
"images": images,
"audio": audio,
"assembly_plan": [_plan()],
"exact_total_duration": [False],
"audio_seam": ["Off"],
"diagnostics": [DIAGNOSTICS_OPTIONS[0]],
}
off_images, off_audio, _off_report = node.assemble(
video_seam=[VIDEO_SEAM_OFF],
**common,
)
analyzed_images, analyzed_audio, report = node.assemble(
video_seam=[VIDEO_SEAM_ANALYZE],
**common,
)
assert torch.equal(analyzed_images, off_images)
assert torch.equal(analyzed_audio["waveform"], off_audio["waveform"])
assert analyzed_audio["sample_rate"] == off_audio["sample_rate"]
assert "action=analysis only" in report
assert "decoded frames and audio are unchanged" in report
def test_auto_replaces_only_qualified_transient_boundary_frame():
images, audio = _decoded()
images[1][22] = 1.0
node = H3ContinuumAssembleSeamExperimental()
common = {
"images": images,
"audio": audio,
"assembly_plan": [_plan()],
"exact_total_duration": [False],
"audio_seam": ["Off"],
"diagnostics": [DIAGNOSTICS_OPTIONS[0]],
}
off_images, off_audio, _ = node.assemble(
video_seam=[VIDEO_SEAM_OFF],
**common,
)
corrected_images, corrected_audio, report = node.assemble(
video_seam=[VIDEO_SEAM_AUTO],
**common,
)
assert float(off_images[124].mean().item()) == 1.0
assert float(corrected_images[124].mean().item()) == 0.25
assert torch.equal(corrected_images[:124], off_images[:124])
assert torch.equal(corrected_images[125:], off_images[125:])
assert torch.equal(corrected_audio["waveform"], off_audio["waveform"])
assert "Video Seam: Auto" in report
assert (
"action=normalized exposure/color on 1 transient flash boundary frame(s)"
in report
)
def test_auto_normalizes_only_the_micro_flash_boundary_frame():
images, audio = _decoded()
images[1][22] = 0.258
node = H3ContinuumAssembleSeamExperimental()
common = {
"images": images,
"audio": audio,
"assembly_plan": [_plan()],
"exact_total_duration": [False],
"audio_seam": ["Off"],
"diagnostics": [DIAGNOSTICS_OPTIONS[0]],
}
off_images, off_audio, _ = node.assemble(
video_seam=[VIDEO_SEAM_OFF],
**common,
)
corrected_images, corrected_audio, report = node.assemble(
video_seam=[VIDEO_SEAM_AUTO],
**common,
)
assert torch.allclose(off_images[124], torch.full_like(off_images[124], 0.258))
assert torch.allclose(
corrected_images[124],
torch.full_like(corrected_images[124], 0.25),
atol=1.0e-6,
)
assert torch.equal(corrected_images[:124], off_images[:124])
assert torch.equal(corrected_images[125:], off_images[125:])
assert torch.equal(corrected_audio["waveform"], off_audio["waveform"])
assert "class=micro_flash" in report
assert "action=normalized exposure/color on 1 micro-flash boundary frame(s)" in report
def test_auto_2_smooths_exposure_ramp_without_changing_frame_count():
images, audio = _decoded()
images[1][22:] = 0.33
images[1][22:26] = torch.tensor([0.27, 0.29, 0.31, 0.33]).view(4, 1, 1, 1)
node = H3ContinuumAssembleSeamExperimental()
common = {
"images": images,
"audio": audio,
"assembly_plan": [_plan()],
"exact_total_duration": [False],
"audio_seam": ["Off"],
"diagnostics": ["Off"],
}
native_images, native_audio, _ = node.assemble(video_seam=["Auto"], **common)
corrected_images, corrected_audio, report = node.assemble(
video_seam=["Auto 2"], **common
)
assert corrected_images.shape == native_images.shape
assert torch.equal(corrected_images[:124], native_images[:124])
assert torch.equal(corrected_images[128:], native_images[128:])
corrected_means = corrected_images[124:128].mean(dim=(1, 2, 3))
assert torch.all(corrected_means[1:] >= corrected_means[:-1])
assert float(corrected_means[0]) < 0.27
assert float(corrected_means[-1]) < 0.33
assert torch.equal(corrected_audio["waveform"], native_audio["waveform"])
assert "Video Seam: Auto 2 (Experimental)" in report
assert "class=exposure_ramp" in report
assert "action=normalized exposure/color on 4 exposure ramp boundary frame(s)" in report
def test_auto_1_keeps_exposure_ramp_native():
images, audio = _decoded()
images[1][22:] = 0.33
images[1][22:26] = torch.tensor([0.27, 0.29, 0.31, 0.33]).view(4, 1, 1, 1)
node = H3ContinuumAssembleSeamExperimental()
output_images, _, report = node.assemble(
images=images,
audio=audio,
assembly_plan=[_plan()],
exact_total_duration=[False],
audio_seam=["Off"],
video_seam=["Auto"],
diagnostics=["Off"],
)
expected = torch.tensor([0.27, 0.29, 0.31, 0.33])
actual = output_images[124:128].mean(dim=(1, 2, 3))
assert torch.allclose(actual, expected)
assert "Video Seam: Auto;" in report
assert "class=exposure_ramp" in report
assert "action=kept native boundary" in report
def test_auto_preserves_spatial_detail_in_corrected_frame():
images, audio = _decoded()
detail = torch.linspace(0.15, 0.35, 8 * 8 * 3).reshape(8, 8, 3)
images[0][-1] = detail
images[1][21] = detail
images[1][22] = detail + 0.2
images[1][23] = detail
node = H3ContinuumAssembleSeamExperimental()
corrected_images, _corrected_audio, report = node.assemble(
images=images,
audio=audio,
assembly_plan=[_plan()],
exact_total_duration=[False],
audio_seam=["Off"],
video_seam=[VIDEO_SEAM_AUTO],
diagnostics=[DIAGNOSTICS_OPTIONS[0]],
)
assert torch.allclose(corrected_images[124], detail, atol=1.0e-6)
assert "action=normalized exposure/color" in report
def test_auto_preserves_clean_boundary():
images, audio = _decoded()
node = H3ContinuumAssembleSeamExperimental()
common = {
"images": images,
"audio": audio,
"assembly_plan": [_plan()],
"exact_total_duration": [False],
"audio_seam": ["Off"],
"diagnostics": [DIAGNOSTICS_OPTIONS[0]],
}
off_images, off_audio, _ = node.assemble(
video_seam=[VIDEO_SEAM_OFF],
**common,
)
corrected_images, corrected_audio, report = node.assemble(
video_seam=[VIDEO_SEAM_AUTO],
**common,
)
assert torch.equal(corrected_images, off_images)
assert torch.equal(corrected_audio["waveform"], off_audio["waveform"])
assert "action=kept native boundary" in report
def test_experimental_seam_analyzer_is_registered_separately():
assert (
NODE_CLASS_MAPPINGS["H3ContinuumAssembleSeamExperimental"]
is H3ContinuumAssembleSeamExperimental
)
assert NODE_CLASS_MAPPINGS["H3ContinuumAssembleV3"] is not H3ContinuumAssembleSeamExperimental
def test_experimental_seam_analyzer_is_public_in_root_registration():
from ComfyUI_H3_Continuum_Join import nodes as root_nodes
node_class = root_nodes.NODE_CLASS_MAPPINGS["H3ContinuumAssembleSeamExperimental"]
assert not getattr(node_class, "DEPRECATED", False)
assert node_class.CATEGORY == "MiniMax H3/Continuum"
assert root_nodes.NODE_DISPLAY_NAME_MAPPINGS["H3ContinuumAssembleSeamExperimental"] == (
"H3 Continuum Assemble + Seam"
)