Release V3.8 source, illustrated manual and Spectrum workflow

This commit is contained in:
ukr8b3g-cmyk
2026-09-07 21:25:51 +09:00
parent 0a7c6703b7
commit 315146946e
208 changed files with 74579 additions and 24542 deletions
@@ -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
}
+378 -378
View File
@@ -1,378 +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
"""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
+216
View File
@@ -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": ["Enable Audio", "audio", "audioUI"],
"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": ["Enable Audio", "audio", "audioUI"],
},
}
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
+300
View File
@@ -0,0 +1,300 @@
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": ["Enable Image", "image", "upload"],
"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": ["Enable Image", "image", "upload"],
},
}
def test_shared_bypass_helper_redraws_only_enable_row_at_full_opacity(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)
assert observed == {
"image": {
"bypassCalls": [
{"names": ["Enable Image", "file"], "alpha": 0.2},
{"names": ["Enable Image"], "alpha": 1},
],
"enabledCalls": [
{"names": ["Enable Image", "file"], "alpha": 1}
],
"mode": 0,
"toggle": True,
"clickable": True,
"visible": True,
},
"audio": {
"bypassCalls": [
{"names": ["Enable Audio", "file"], "alpha": 0.2},
{"names": ["Enable Audio"], "alpha": 1},
],
"enabledCalls": [
{"names": ["Enable Audio", "file"], "alpha": 1}
],
"mode": 0,
"toggle": True,
"clickable": True,
"visible": True,
},
"video": {
"bypassCalls": [
{"names": ["enable_video", "file"], "alpha": 0.2},
{"names": ["enable_video"], "alpha": 1},
],
"enabledCalls": [
{"names": ["enable_video", "file"], "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
+345
View File
@@ -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_video_bypass_appearance_uses_native_mode_without_hardcoded_color():
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 "configureExistingEasyBypassWidgetNode" in source
assert 'widgetNames: ["enable_video", "Enable Video"]' 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
+81 -81
View File
@@ -1,81 +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
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
+313
View File
@@ -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
+213
View File
@@ -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
+139
View File
@@ -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
+58 -58
View File
@@ -1,59 +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"
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"
)
+1 -1
View File
@@ -581,5 +581,5 @@ def test_v35_assembler_is_registered_without_replacing_v34():
H3ContinuumAssembleSeamV35
)
assert NODE_DISPLAY_NAME_MAPPINGS["H3ContinuumAssembleSeamV35"] == (
"H3 Continuum Assemble + Seam V3.5"
"H3 Continuum Finalize"
)
+1 -1
View File
@@ -6,7 +6,7 @@ import tomllib
ROOT = Path(__file__).resolve().parents[1]
EXPECTED_VERSION = "3.7.0"
EXPECTED_VERSION = "3.8.0"
def test_v35_release_metadata_is_consistent():
+113
View File
@@ -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]
+50
View File
@@ -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
+183 -183
View File
@@ -1,183 +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"
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"
+2 -6
View File
@@ -83,12 +83,8 @@ def test_v33_unifies_optional_timeline_video_and_keeps_v324_schema():
from ComfyUI_H3_Continuum_Join import nodes as root_nodes
assert root_nodes.NODE_DISPLAY_NAME_MAPPINGS["H3ContinuumSamplerTimelineVideo"] == (
"[Legacy] H3 Continuum Sampler V3.3"
)
assert root_nodes.NODE_DISPLAY_NAME_MAPPINGS["H3ContinuumSamplerProduction"] == (
"[Legacy] H3 Continuum Sampler V3.2.4"
)
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):
+126 -126
View File
@@ -1,120 +1,120 @@
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))
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 = {}
@@ -134,15 +134,15 @@ def test_v217_facade_ignores_sparse_override_outside_chunks(monkeypatch):
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_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.7.0"' in version_source
assert 'PACKAGE_VERSION = "3.8.0"' in version_source
+402 -402
View File
@@ -1,33 +1,33 @@
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,
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
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
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
@@ -163,379 +163,379 @@ def test_prompt_transparency_t8_unknown_future_syntax_is_literal():
)
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")
@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")
+2 -7
View File
@@ -2,16 +2,11 @@ from ComfyUI_H3_Continuum_Join.constants import (
PROMPT_FORMAT_OPTIONS,
SEAM_CORRECTION_AUTO,
)
from ComfyUI_H3_Continuum_Join.nodes import NODE_CLASS_MAPPINGS
from ComfyUI_H3_Continuum_Join.v2.nodes import NODE_CLASS_MAPPINGS
def test_v2_nodes_are_registered_without_removing_v1():
def test_v2_nodes_remain_available_in_the_internal_module():
expected = {
"H3ContinuumJoin",
"H3ContinuumFinish",
"H3ContinuumAssemble",
"H3ContinuumSaveState",
"H3ContinuumLoadState",
"H3ContinuumSamplerV2",
"H3ContinuumPromptPlanPreview",
"H3ContinuumSaveSession",
+98 -98
View File
@@ -1,105 +1,105 @@
import torch
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
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)
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)
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
+153 -153
View File
@@ -1,100 +1,100 @@
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,
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
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]
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
@@ -120,9 +120,9 @@ def test_two_chunk_terminal_cache_extended_to_three_reuses_one_generates_two():
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
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
@@ -150,61 +150,61 @@ def test_terminal_merge_keeps_prefix_with_matching_strategy():
@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
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
File diff suppressed because it is too large Load Diff
+53 -53
View File
@@ -1,47 +1,47 @@
from __future__ import annotations
import pytest
import torch
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,
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_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]
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())
@@ -74,8 +74,8 @@ def test_v323_third_reference_adds_only_the_image_3_extension():
"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)
@@ -86,21 +86,21 @@ def test_unavailable_picture_tags_warn_without_stopping_like_core():
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():
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
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,
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,
)
+2 -6
View File
@@ -151,12 +151,8 @@ def test_v34_public_schema_replaces_reference_audio_with_driving_audio():
from ComfyUI_H3_Continuum_Join import nodes as root_nodes
assert root_nodes.NODE_DISPLAY_NAME_MAPPINGS["H3ContinuumSamplerV34"] == (
"H3 Continuum Sampler V3.4"
)
assert root_nodes.NODE_DISPLAY_NAME_MAPPINGS[
"H3ContinuumSamplerTimelineVideo"
].startswith("[Legacy]")
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():
+112 -112
View File
@@ -1,54 +1,54 @@
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)]
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."],
@@ -79,64 +79,64 @@ def test_hybrid_prompt_validation_reports_the_missing_reference_number() -> None
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)
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)
+152 -152
View File
@@ -1,154 +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"] == (
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 (Optional)"
)
assert v35_optional["reference_audio_vae"][0] == "VAE"
assert v35_optional["reference_audio_vae"][1]["display_name"] == (
)
assert v35_optional["reference_audio_vae"][0] == "VAE"
assert v35_optional["reference_audio_vae"][1]["display_name"] == (
"Reference Audio VAE (Optional)"
)
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
)
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
+212 -212
View File
@@ -1,212 +1,212 @@
from __future__ import annotations
import json
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"
BRIDGE_WORKFLOW = (
ROOT
/ "examples"
/ "workflows"
/ "MiniMax_H3_Continuum_V351_LBH_Conditioning_Bridge.json"
)
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 (Optional)",
"Reference Audio VAE (Optional)",
],
);
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
def test_bundled_bridge_workflow_has_permanent_sockets_and_aligned_widgets():
workflow = json.loads(BRIDGE_WORKFLOW.read_text(encoding="utf-8"))
sampler = next(
node for node in workflow["nodes"] if node["type"] == "H3ContinuumSamplerV35"
)
expected = {
"prompt_mode": "Auto",
"chunks": 1,
"chunk_seconds": 5,
"width": 1344,
"height": 768,
"continuity": "Fast — 5 frames",
"base_seed": 783839598838387,
"control_after_generate": "randomize",
"audio_continuity": True,
"diagnostics": "Detailed Report",
"reroll_from_chunk": "Auto",
"reroll_nonce": 0,
"strict_compatibility": False,
"debug": False,
"show_preview": True,
"run_storage": "Off",
"run_name": "",
"reference_size": "Match Output",
"project_id": "d1c61168-c72e-44d1-9b78-1c9adb4eba0e",
"video_reference_size": "Efficient - 0.4 MP",
}
assert sampler["widgets_values"] == list(expected.values())
assert sampler["widgets_values_named"] == expected
input_names = [input_["name"] for input_ in sampler["inputs"]]
assert input_names[input_names.index("audio_vae") + 1 : input_names.index("width")] == [
"reference_audio_1",
"reference_audio_vae",
]
from __future__ import annotations
import json
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"
BRIDGE_WORKFLOW = (
ROOT
/ "examples"
/ "workflows"
/ "MiniMax_H3_Continuum_V351_LBH_Conditioning_Bridge.json"
)
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 (Optional)",
"Reference Audio VAE (Optional)",
],
);
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
def test_bundled_bridge_workflow_has_permanent_sockets_and_aligned_widgets():
workflow = json.loads(BRIDGE_WORKFLOW.read_text(encoding="utf-8"))
sampler = next(
node for node in workflow["nodes"] if node["type"] == "H3ContinuumSamplerV35"
)
expected = {
"prompt_mode": "Auto",
"chunks": 1,
"chunk_seconds": 5,
"width": 1344,
"height": 768,
"continuity": "Fast — 5 frames",
"base_seed": 783839598838387,
"control_after_generate": "randomize",
"audio_continuity": True,
"diagnostics": "Detailed Report",
"reroll_from_chunk": "Auto",
"reroll_nonce": 0,
"strict_compatibility": False,
"debug": False,
"show_preview": True,
"run_storage": "Off",
"run_name": "",
"reference_size": "Match Output",
"project_id": "d1c61168-c72e-44d1-9b78-1c9adb4eba0e",
"video_reference_size": "Efficient - 0.4 MP",
}
assert sampler["widgets_values"] == list(expected.values())
assert sampler["widgets_values_named"] == expected
input_names = [input_["name"] for input_ in sampler["inputs"]]
assert input_names[input_names.index("audio_vae") + 1 : input_names.index("width")] == [
"reference_audio_1",
"reference_audio_vae",
]
+3 -2
View File
@@ -92,13 +92,14 @@ def test_run_storage_off_normalizes_widgets_reload_and_queued_inputs(tmp_path):
_function_source(source, "findWidget", "setWidgetVisible"),
_function_source(source, "setWidgetVisible", "hidePersistentWidget"),
_function_source(source, "linkedInput", "attachRefresh"),
_function_source(source, "attachRefresh", "normalizeRunStorageState"),
_function_source(source, "attachRefresh", "normalizedV38View"),
_function_source(source, "normalizeRunStorageState", "configureConditionalWidgets"),
_function_source(source, "configureConditionalWidgets", "configureAssembler"),
]
)
script = f"""
const RUN_STORAGE_WIDGET = "run_storage";
const RUN_STORAGE_WIDGET = "run_storage";
const V38_NODE_CLASS = "H3ContinuumSamplerV38";
const REGENERATE_WIDGET = "reroll_from_chunk";
const REROLL_NONCE_WIDGET = "reroll_nonce";
const LEGACY_RUN_NAME_WIDGET = "run_name";
+1 -1
View File
@@ -2,7 +2,7 @@ from __future__ import annotations
import torch
from ComfyUI_H3_Continuum_Join.nodes import (
from ComfyUI_H3_Continuum_Join.v3.conditioning_bridge_nodes import (
NODE_CLASS_MAPPINGS,
NODE_DISPLAY_NAME_MAPPINGS,
)
+1 -3
View File
@@ -233,9 +233,7 @@ def test_v35_is_registered_with_v34_outputs_then_refine_context():
assert NODE_DISPLAY_NAME_MAPPINGS["H3ContinuumSamplerV35"] == (
"H3 Continuum Sampler V3.5"
)
assert root_nodes.NODE_CLASS_MAPPINGS["H3ContinuumSamplerV35"] is (
H3ContinuumSamplerV35
)
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"
+10 -4
View File
@@ -6,10 +6,16 @@ import types
import pytest
import torch
from ComfyUI_H3_Continuum_Join.nodes import (
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,
@@ -511,10 +517,10 @@ def test_three_v35_nodes_are_registered_with_final_display_names():
assert NODE_DISPLAY_NAME_MAPPINGS["H3ContinuumHiResFixV35"] == (
"H3 Continuum Hi-Res Fix V3.5"
)
assert NODE_DISPLAY_NAME_MAPPINGS["H3ContinuumSecondPassV35"] == (
"H3 Continuum Second Pass V3.5"
assert SECOND_PASS_DISPLAY_NAME_MAPPINGS["H3ContinuumSecondPassV35"] == (
"H3 Continuum Second Pass"
)
assert NODE_DISPLAY_NAME_MAPPINGS["H3ContinuumLatentResizeV35"] == (
assert LATENT_RESIZE_DISPLAY_NAME_MAPPINGS["H3ContinuumLatentResizeV35"] == (
"H3 Continuum Latent Resize V3.5"
)
assert H3ContinuumHiResFixV35.INPUT_IS_LIST is True
+1 -1
View File
@@ -3,7 +3,7 @@ from __future__ import annotations
import torch
import torch.nn.functional as F
from ComfyUI_H3_Continuum_Join.nodes import NODE_CLASS_MAPPINGS
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,
+2 -6
View File
@@ -36,12 +36,8 @@ def test_v36_is_registered_without_replacing_v35():
assert NODE_DISPLAY_NAME_MAPPINGS["H3ContinuumSamplerV36"] == (
"H3 Continuum Sampler V3.6"
)
assert root_nodes.NODE_CLASS_MAPPINGS["H3ContinuumSamplerV36"] is (
H3ContinuumSamplerV36
)
assert root_nodes.NODE_CLASS_MAPPINGS["H3ContinuumSamplerV35"] is (
H3ContinuumSamplerV35
)
assert "H3ContinuumSamplerV36" not in root_nodes.NODE_CLASS_MAPPINGS
assert "H3ContinuumSamplerV35" not in root_nodes.NODE_CLASS_MAPPINGS
assert H3ContinuumSamplerV36.RETURN_TYPES == H3ContinuumSamplerV35.RETURN_TYPES
assert H3ContinuumSamplerV36.RETURN_NAMES == H3ContinuumSamplerV35.RETURN_NAMES
+40
View File
@@ -0,0 +1,40 @@
from __future__ import annotations
import copy
import json
import zipfile
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
WORKFLOW_DIR = ROOT / "examples" / "workflows"
V36_PATH = WORKFLOW_DIR / "MiniMax_H3_Continuum_V36.json"
V37_PATH = WORKFLOW_DIR / "MiniMax_H3_Continuum_V37.json"
V37_ZIP_PATH = WORKFLOW_DIR / "MiniMax_H3_Continuum_V37.zip"
def _load(path: Path) -> dict:
return json.loads(path.read_text(encoding="utf-8"))
def test_v37_template_is_the_v36_graph_with_only_the_sampler_class_replaced():
v36 = _load(V36_PATH)
v37 = _load(V37_PATH)
sampler = next(node for node in v37["nodes"] if node["id"] == 305)
assert sampler["type"] == "H3ContinuumSamplerV37"
assert sampler["properties"]["Node name for S&R"] == "H3ContinuumSamplerV37"
assert sampler["widgets_values_named"]["continuation_backend"] == "Standard"
assert all(input_["name"] != "guide" for input_ in sampler["inputs"])
normalized = copy.deepcopy(v37)
normalized_sampler = next(node for node in normalized["nodes"] if node["id"] == 305)
normalized_sampler["type"] = "H3ContinuumSamplerV36"
normalized_sampler["properties"]["Node name for S&R"] = "H3ContinuumSamplerV36"
assert normalized == v36
def test_v37_zip_contains_the_exact_public_workflow_json():
with zipfile.ZipFile(V37_ZIP_PATH) as archive:
assert archive.namelist() == [V37_PATH.name]
assert archive.read(V37_PATH.name) == V37_PATH.read_bytes()
@@ -0,0 +1,253 @@
from __future__ import annotations
from pathlib import Path
import pytest
from ComfyUI_H3_Continuum_Join.v3.adaptive_continuity import (
ADAPTIVE_CONTINUITY_OBSERVER_VERSION,
ADAPTIVE_CONTINUITY_PLANNER_HASH,
AdaptiveContinuityObservationError,
AdaptiveContinuityObserver,
EXECUTION_APPLIED,
INITIAL_TRANSPORT,
adaptive_observer_event_fail_soft,
make_adaptive_continuity_decision,
)
ROOT = Path(__file__).resolve().parents[1]
def _entry(context_frames, motion_score):
return {
"context_frames": context_frames,
"motion_score": motion_score,
"video": object(),
"audio": object(),
}
def test_planner_contract_and_decision_hash_are_deterministic():
kwargs = {
"physical_group": 2,
"logical_chunks": (2,),
"observed_motion_score": 0.075,
"current_context_frames": 22,
"resolved_transport": "masked_av_prefix_22_v1",
"terminal_atomic": False,
"boundary_index": 1,
"boundary_count": 2,
"reason": "fixed profile",
}
first = make_adaptive_continuity_decision(**kwargs)
second = make_adaptive_continuity_decision(**kwargs)
assert ADAPTIVE_CONTINUITY_OBSERVER_VERSION == 1
assert len(ADAPTIVE_CONTINUITY_PLANNER_HASH) == 64
assert first == second
assert len(first["decision_hash"]) == 64
assert first["execution_applied"] is EXECUTION_APPLIED is False
assert first["issue_13_mitigation_claim"] is False
assert first["confidence_scope"].endswith("not mitigation efficacy")
def test_initial_group_is_trace_only_and_has_no_continuation_action():
decision = make_adaptive_continuity_decision(
physical_group=1,
logical_chunks=(1,),
observed_motion_score=0.0,
current_context_frames=0,
resolved_transport=INITIAL_TRANSPORT,
terminal_atomic=False,
boundary_index=0,
boundary_count=0,
reason="initial clip",
)
assert decision["recommendation"] == "no_continuation_action_initial_group"
assert decision["execution_applied"] is False
def test_reference_context_and_masked_contracts_are_only_recommended_not_applied():
common = {
"physical_group": 2,
"logical_chunks": (2,),
"observed_motion_score": 0.1,
"current_context_frames": 22,
"terminal_atomic": False,
"boundary_index": 1,
"boundary_count": 2,
"reason": "conservative balanced fallback",
}
reference = make_adaptive_continuity_decision(
**common, resolved_transport="reference_context_v1"
)
masked = make_adaptive_continuity_decision(
**common, resolved_transport="masked_av_prefix_22_v1"
)
assert reference["recommendation"] == "keep_current_reference_context_contract"
assert masked["recommendation"] == "keep_current_masked_prefix_contract"
assert reference["execution_applied"] is masked["execution_applied"] is False
def test_terminal_recommendation_keeps_atomic_fixed_contract():
decision = make_adaptive_continuity_decision(
physical_group=2,
logical_chunks=(2, 3),
observed_motion_score=0.05,
current_context_frames=22,
resolved_transport="masked_av_prefix_22_v1",
terminal_atomic=True,
boundary_index=1,
boundary_count=2,
reason="terminal merged 10-second sample",
)
assert decision["terminal_atomic"] is True
assert decision["recommendation"] == "keep_fixed_terminal_merge_contract"
assert decision["execution_applied"] is False
@pytest.mark.parametrize(
"override",
[
{"current_context_frames": 13},
{"resolved_transport": "dynamic_transport"},
{"observed_motion_score": float("nan")},
{"boundary_index": 3},
],
)
def test_malformed_observation_is_rejected_by_pure_builder(override):
kwargs = {
"physical_group": 2,
"logical_chunks": (2,),
"observed_motion_score": 0.1,
"current_context_frames": 22,
"resolved_transport": "masked_av_prefix_22_v1",
"terminal_atomic": False,
"boundary_index": 1,
"boundary_count": 2,
"reason": "fixed profile",
}
kwargs.update(override)
with pytest.raises(AdaptiveContinuityObservationError):
make_adaptive_continuity_decision(**kwargs)
def test_fail_soft_event_records_advisory_without_raising():
observer = AdaptiveContinuityObserver()
result = adaptive_observer_event_fail_soft(
observer,
"observe",
physical_group=2,
logical_chunks=(2,),
observed_motion_score=0.1,
current_context_frames=13,
resolved_transport="masked_av_prefix_22_v1",
terminal_atomic=False,
boundary_index=1,
boundary_count=2,
reason="invalid diagnostic input",
)
assert result is None
lines = observer.report_lines()
assert "observed_groups=0" in lines[0]
assert "unavailable/advisory" not in lines[0]
assert "Adaptive Continuity advisory [A8a v1]" in lines[1]
assert "execution_applied=false" in lines[1]
def test_replayed_normal_prefix_uses_metadata_without_retaining_payloads():
entries = [_entry(0, 0.0), _entry(22, 0.07), _entry(22, 0.08)]
observer = AdaptiveContinuityObserver()
observer.replay_prefix(
entries=entries,
total_chunks=3,
terminal_merge_enabled=False,
resolved_transport="masked_av_prefix_22_v1",
)
assert [record["physical_group"] for record in observer.records] == [1, 2, 3]
assert all(record["reused"] for record in observer.records)
assert all("video" not in record and "audio" not in record for record in observer.records)
def test_replayed_terminal_pair_is_one_atomic_physical_record():
entries = [_entry(0, 0.0), _entry(22, 0.09), _entry(22, 0.09)]
observer = AdaptiveContinuityObserver()
observer.replay_prefix(
entries=entries,
total_chunks=3,
terminal_merge_enabled=True,
resolved_transport="masked_av_prefix_22_v1",
)
records = observer.records
assert len(records) == 2
assert records[1]["logical_chunks"] == [2, 3]
assert records[1]["terminal_atomic"] is True
assert records[1]["boundary_index"] == 1
assert records[1]["boundary_count"] == 2
def test_report_contains_required_contract_fields_and_no_execution_claim():
observer = AdaptiveContinuityObserver()
observer.observe(
physical_group=1,
logical_chunks=(1,),
observed_motion_score=0.0,
current_context_frames=0,
resolved_transport=INITIAL_TRANSPORT,
terminal_atomic=False,
boundary_index=0,
boundary_count=2,
reason="initial clip",
)
text = "\n".join(observer.report_lines())
for token in (
"planner_hash=",
"motion=",
"context=",
"transport=",
"terminal_atomic=",
"boundary=",
"recommendation=",
"confidence=",
"reason=",
"fallback_reason=",
"execution_applied=false",
):
assert token in text
assert "Issue #13 mitigation claim=none" in text
def test_a8a_is_detailed_only_and_has_no_public_schema_or_identity_field():
sequence = (ROOT / "v2" / "sequence.py").read_text(encoding="utf-8")
observer_creation = sequence.index(
"adaptive_continuity_observer=AdaptiveContinuityObserver()"
)
detailed_guard = sequence.rindex(
"if diagnostics_mode==DIAGNOSTICS_FULL:", 0, observer_creation
)
assert detailed_guard < observer_creation
for path in (
ROOT / "v3" / "nodes.py",
ROOT / "v3" / "driving_nodes.py",
ROOT / "v3" / "second_pass_nodes.py",
):
assert "adaptive_continuity" not in path.read_text(encoding="utf-8")
storage = (ROOT / "run_storage.py").read_text(encoding="utf-8")
assert "adaptive_continuity" not in storage
def test_a8a_source_has_no_tensor_or_execution_mutation_api():
source = (ROOT / "v3" / "adaptive_continuity.py").read_text(encoding="utf-8")
for forbidden in (
"import torch",
".clone(",
".copy_(",
"noise_mask",
"prepare_conditioning",
"sample_chunk",
"unload_all_models",
"optimized_attention_override",
"PackedLayout",
):
assert forbidden not in source
+292
View File
@@ -0,0 +1,292 @@
from __future__ import annotations
import copy
import hashlib
from types import SimpleNamespace
import pytest
import torch
from ComfyUI_H3_Continuum_Join.v3 import targeted_refine_sampling
from ComfyUI_H3_Continuum_Join.v3.refine_schedule import make_tail_schedule
from ComfyUI_H3_Continuum_Join.v3.refine_target import (
MODE_AUDIO_ONLY,
derive_target_refine_seed,
)
from ComfyUI_H3_Continuum_Join.v3.second_pass import update_second_pass_geometry
from ComfyUI_H3_Continuum_Join.v3.targeted_refine_sampling import (
_prepare_audio_only_noise_and_mask,
sample_audio_only_refine_chunk,
)
from ComfyUI_H3_Continuum_Join.v3.targeted_second_pass import (
run_targeted_second_pass_groups,
)
class _Nested:
is_nested = True
def __init__(self, tensors):
self.tensors = list(tensors)
def unbind(self):
return self.tensors
def to(self, *_args, **_kwargs):
return self
def _sha(tensor: torch.Tensor) -> str:
value = tensor.detach().to(device="cpu").contiguous()
return hashlib.sha256(value.view(torch.uint8).numpy().tobytes()).hexdigest()
def test_audio_only_noise_is_random_for_audio_zero_for_video_with_minimal_masks():
video = torch.ones((1, 24, 3, 4, 5), dtype=torch.float16)
audio = torch.zeros((1, 32, 2, 12), dtype=torch.float16)
calls = []
def prepare_noise(samples, seed, batch_inds):
calls.append((samples, seed, batch_inds))
return torch.full_like(samples, 0.625, device="cpu")
noise, mask = _prepare_audio_only_noise_and_mask(
video,
audio,
seed=321,
batch_inds=[0],
prepare_noise_fn=prepare_noise,
nested_builder=_Nested,
)
video_noise, audio_noise = noise.unbind()
video_mask, audio_mask = mask.unbind()
assert calls == [(audio, 321, [0])]
assert torch.count_nonzero(video_noise) == 0
assert video_noise.dtype == video.dtype
assert torch.equal(audio_noise, torch.full_like(audio_noise, 0.625))
assert tuple(video_mask.shape) == (1, 1, 1, 1, 1)
assert tuple(audio_mask.shape) == (1, 1, 1, 1)
assert torch.all(video_mask == 0)
assert torch.all(audio_mask == 1)
def test_audio_only_sampler_passes_target_policy_and_exact_sigmas_to_core(monkeypatch):
video = torch.randn((1, 24, 3, 4, 4))
audio = torch.randn((1, 32, 2, 12))
latent_samples = _Nested((video, audio))
sigmas = torch.tensor([0.35, 0.2, 0.0])
captured = {}
class _Guider:
def sample(self, noise, latent_image, sampler, supplied_sigmas, **kwargs):
captured.update(
noise=noise,
latent_image=latent_image,
sampler=sampler,
sigmas=supplied_sigmas,
**kwargs,
)
return _Nested((video + 500.0, audio + 2.0))
def prepare_noise(samples, seed, batch_inds):
captured["prepare_noise"] = (samples, seed, batch_inds)
return torch.full_like(samples, 0.75, device="cpu")
fake_sample = SimpleNamespace(
fix_empty_latent_channels=lambda _model, samples, _spatial, _temporal: samples,
prepare_noise=prepare_noise,
)
fake_runtime = (
SimpleNamespace(intermediate_device=lambda: torch.device("cpu")),
SimpleNamespace(NestedTensor=_Nested),
fake_sample,
SimpleNamespace(PROGRESS_BAR_ENABLED=False),
SimpleNamespace(prepare_callback=lambda *_args: None),
)
monkeypatch.setattr(
targeted_refine_sampling,
"_load_runtime_modules",
lambda: fake_runtime,
)
monkeypatch.setattr(
targeted_refine_sampling,
"_make_basic_guider",
lambda *_args: _Guider(),
)
sampler = object()
output = sample_audio_only_refine_chunk(
model=object(),
conditioning=["conditioning"],
latent={"samples": latent_samples},
sampler=sampler,
sigmas=sigmas,
seed=654,
enable_preview=False,
)
assert captured["prepare_noise"] == (audio, 654, None)
assert captured["latent_image"] is latent_samples
assert captured["sigmas"] is sigmas
assert captured["sampler"] is sampler
video_noise, audio_noise = captured["noise"].unbind()
video_mask, audio_mask = captured["denoise_mask"].unbind()
assert torch.count_nonzero(video_noise) == 0
assert torch.equal(audio_noise, torch.full_like(audio_noise, 0.75))
assert torch.all(video_mask == 0)
assert torch.all(audio_mask == 1)
sampled_video, sampled_audio = output["samples"].unbind()
assert torch.equal(sampled_video, video + 500.0)
assert torch.equal(sampled_audio, audio + 2.0)
def _group(group_id: int, *, temporal: int, audio_t: int, terminal: bool) -> dict:
return {
"group_id": group_id,
"logical_chunks": [1] if group_id == 0 else [2, 3],
"physical_prompt": f"group {group_id + 1}",
"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": 128,
"source_height": 128,
"source_batch": 1,
"latent_channels": 24,
"source_latent_t": temporal,
"source_latent_h": 8,
"source_latent_w": 8,
"source_audio_shape": [1, 32, 2, audio_t],
}
def _fixture():
groups = [
_group(0, temporal=31, audio_t=207, terminal=False),
_group(1, temporal=65, audio_t=433, terminal=True),
]
videos = [
{
"samples": torch.arange(
24 * group["source_latent_t"] * 8 * 8,
dtype=torch.float32,
).reshape(1, 24, group["source_latent_t"], 8, 8)
}
for group in groups
]
audios = [
{
"samples": torch.arange(
32 * 2 * group["source_audio_shape"][-1],
dtype=torch.float32,
).reshape(group["source_audio_shape"])
}
for group in groups
]
plan = {
"width": 128,
"height": 128,
"existing_top_level": {"preserved": True},
"second_pass_contract": {
"version": 1,
"existing_contract_field": "preserved",
"physical_groups": groups,
},
}
return groups, videos, audios, plan
def test_audio_only_group_gate_preserves_video_and_samples_each_physical_group_once():
groups, videos, audios, plan = _fixture()
plan_before = copy.deepcopy(plan)
video_hashes = [_sha(item["samples"]) for item in videos]
source_sigmas = torch.tensor([0.6, 0.3, 0.0], dtype=torch.float32)
schedule = make_tail_schedule(source_sigmas, evaluation_count=1)
schedule_before = copy.deepcopy(dict(schedule.contract))
calls = []
def sample(**kwargs):
calls.append(kwargs)
return {
"video": kwargs["latent"]["video"] + 1000.0,
"audio": kwargs["latent"]["audio"] + float(len(calls)),
}
result = run_targeted_second_pass_groups(
model="model",
clip="clip",
sampler="sampler",
sigmas=source_sigmas,
video_latents=videos,
audio_latents=audios,
assembly_plan=plan,
refine_seed=91,
refine_target=MODE_AUDIO_ONLY,
encode_prompt_fn=lambda _clip, prompt, **_kwargs: [prompt],
latent_builder=lambda video, audio: {"video": video, "audio": audio},
sample_fn=sample,
stream_extractor=lambda value: (value["video"], value["audio"]),
clone_model_fn=lambda source, **kwargs: (source, kwargs),
refine_schedule=schedule,
enable_preview=False,
)
output_videos, output_audios, updated_plan, status = result
assert plan == plan_before
assert dict(schedule.contract) == schedule_before
assert all(
output is source
for output, source in zip(output_videos, videos, strict=True)
)
assert [_sha(item["samples"]) for item in output_videos] == video_hashes
assert [tuple(item["samples"].shape) for item in output_audios] == [
tuple(item["samples"].shape) for item in audios
]
assert all(
output is not source
for output, source in zip(output_audios, audios, strict=True)
)
assert [call["seed"] for call in calls] == [
derive_target_refine_seed(91, 0, MODE_AUDIO_ONLY),
derive_target_refine_seed(91, 1, MODE_AUDIO_ONLY),
]
assert all(call["sigmas"] is schedule.sigmas for call in calls)
assert [call["conditioning"] for call in calls] == [["group 1"], ["group 2"]]
assert len(calls) == len(groups) == 2
assert groups[1]["logical_chunks"] == [2, 3]
assert groups[1]["terminal_merged"] is True
assert "Production HOLD" in status
contract = updated_plan["second_pass_contract"]
assert contract["version"] == 1
assert contract["refine_target_contract"]["mode"] == MODE_AUDIO_ONLY
assert contract["video_output"] == "bit_exact_first_pass_passthrough"
assert contract["video_sampling"] == "zero_noise_mask_locked"
assert contract["audio_output"] == "sampled"
assert contract["audio_sampling"] == "seeded_random_mask_1"
assert contract["refine_group_seeds"] == [call["seed"] for call in calls]
assert contract["refine_schedule"]["schedule_hash"] == schedule.contract["schedule_hash"]
assert contract["refine_execution_contract"]["sigma_range"]["sigma_hash"] == (
schedule.contract["sigma_hash"]
)
expected_plan = update_second_pass_geometry(plan, videos)
normalized = copy.deepcopy(updated_plan)
normalized_contract = normalized["second_pass_contract"]
for key in (
"execution",
"conditioning_sources",
"refine_seed_base",
"refine_group_seeds",
"video_output",
"video_sampling",
"audio_output",
"audio_sampling",
"refine_schedule",
"refine_schedule_identity",
"refine_target_contract",
"refine_execution_contract",
):
normalized_contract.pop(key)
assert normalized == expected_plan
+114
View File
@@ -0,0 +1,114 @@
from __future__ import annotations
import pytest
from ComfyUI_H3_Continuum_Join.branch_provenance import (
BranchProvenanceError,
PhysicalGroup,
active_revision_map,
make_group_revision,
physical_groups,
resolve_chain,
validate_group_revision,
)
def _record(position: int, source: str, seed: int):
return {
"sequence_index": position,
"storage_revision_id": source,
"filename": f"chunk_{position + 1:04d}.safetensors",
"file_size": 100 + position,
"file_sha256": f"sha-{source}-{position}",
"entry": {"seed": seed, "prompt_hash": f"prompt-{position}"},
}
def _revision(group, *, parent=None, source="a", nonce=0, branch_cut=None):
return make_group_revision(
parent_revision_id=parent,
group=group,
variation_nonce=nonce,
created_utc="2026-09-03T00:00:00+00:00",
storage_revision_id=source,
generation_contract_sha256=f"contract-{source}",
lineage_sha256="lineage",
records=[
_record(position, source, 1000 + position + nonce)
for position in range(group.start - 1, group.end)
],
branch_cut=branch_cut,
)
def test_normal_and_terminal_physical_groups_are_atomic():
assert [(g.start, g.end) for g in physical_groups(chunks=3, terminal_merge_enabled=False)] == [
(1, 1),
(2, 2),
(3, 3),
]
assert [(g.start, g.end) for g in physical_groups(chunks=3, terminal_merge_enabled=True)] == [
(1, 1),
(2, 3),
]
def test_group_revision_identity_is_immutable_and_display_name_free():
group = PhysicalGroup(3, 3, 3)
first = _revision(group, source="take-b", nonce=2)
second = _revision(group, source="take-b", nonce=2)
assert first["revision_id"] == second["revision_id"]
assert "take" not in first
assert validate_group_revision(first)["revision_id"] == first["revision_id"]
changed = dict(first)
changed["variation_nonce"] = 3
with pytest.raises(BranchProvenanceError, match="identity"):
validate_group_revision(changed)
def test_branch_chain_keeps_both_takes_and_resolves_selected_parent():
r1 = _revision(PhysicalGroup(1, 1, 1), source="root")
r2 = _revision(PhysicalGroup(2, 2, 2), parent=r1["revision_id"], source="root")
r3a = _revision(PhysicalGroup(3, 3, 3), parent=r2["revision_id"], source="a", nonce=1)
r3b = _revision(PhysicalGroup(3, 3, 3), parent=r2["revision_id"], source="b", nonce=2)
r4b = _revision(
PhysicalGroup(4, 4, 4),
parent=r3b["revision_id"],
source="b2",
nonce=3,
branch_cut={
"selected_revision_id": r3b["revision_id"],
"after_physical_group": 3,
},
)
catalog = {item["revision_id"]: item for item in (r1, r2, r3a, r3b, r4b)}
chain = resolve_chain(catalog, r4b["revision_id"])
assert [item["revision_id"] for item in chain] == [
r1["revision_id"],
r2["revision_id"],
r3b["revision_id"],
r4b["revision_id"],
]
assert r3a["revision_id"] in catalog
assert active_revision_map(chain)["3"] == r3b["revision_id"]
def test_wrong_parent_and_terminal_half_are_rejected():
r1 = _revision(PhysicalGroup(1, 1, 1), source="root")
orphan = _revision(PhysicalGroup(3, 3, 3), parent=r1["revision_id"], source="bad")
with pytest.raises(BranchProvenanceError, match="contiguous"):
resolve_chain(
{r1["revision_id"]: r1, orphan["revision_id"]: orphan},
orphan["revision_id"],
)
with pytest.raises(BranchProvenanceError, match="non-atomic"):
make_group_revision(
parent_revision_id=r1["revision_id"],
group=PhysicalGroup(2, 3, 2),
variation_nonce=1,
created_utc="2026-09-03T00:00:00+00:00",
storage_revision_id="terminal",
generation_contract_sha256="contract",
lineage_sha256="lineage",
records=[_record(1, "terminal", 1)],
)
@@ -0,0 +1,334 @@
from __future__ import annotations
import inspect
import pytest
from ComfyUI_H3_Continuum_Join.temporal import audio_latent_t, context_slots
from ComfyUI_H3_Continuum_Join.v3.reliability_v38 import (
build_chunk_boundary_diagnostics,
)
def _chunk(index: int, *, context: int = 22, start: int | None = None):
if index == 1:
total = net = 124
trim = 0
else:
trim = context
total = context + 119
net = 119
if start is None:
start = 0 if index == 1 else 124 + (index - 2) * 119
return {
"sequence_index": index,
"chunk_index": index,
"total_frames": total,
"trim_frames": trim,
"net_frames": net,
"context_frames": trim,
"frame_start": start,
"frame_stop": start + net,
}
def _decode_group(chunk, *, logical=None, terminal=False):
group = dict(chunk)
group["logical_chunk_indices"] = list(logical or [chunk["chunk_index"]])
group["terminal_merged"] = bool(terminal)
return group
def _second_pass_group(group_id: int, group):
return {
"group_id": group_id,
"logical_chunks": list(group["logical_chunk_indices"]),
"physical_frames": group["total_frames"],
"trim_prefix_frames": group["trim_frames"],
"terminal_merged": bool(group.get("terminal_merged", False)),
}
def _plan(*chunks, groups=None, second_pass=True):
active_groups = (
list(groups)
if groups is not None
else [_decode_group(chunk) for chunk in chunks]
)
plan = {"chunks": list(chunks), "decode_groups": active_groups}
if second_pass:
plan["second_pass_contract"] = {
"version": 1,
"physical_groups": [
_second_pass_group(index, group)
for index, group in enumerate(active_groups)
],
}
return plan
def _diagnose(plan, *, video_count=None, audio_count=None):
groups = plan.get("decode_groups", plan.get("chunks", []))
return build_chunk_boundary_diagnostics(
video_latents=[object()] * (len(groups) if video_count is None else video_count),
audio_latents=[object()] * (len(groups) if audio_count is None else audio_count),
assembly_plan=plan,
)
def test_single_chunk_has_zero_boundaries_and_silent_basic():
result = _diagnose(_plan(_chunk(1)))
assert result.basic == ()
assert result.detailed == (
"Chunk boundary contract: structural diagnostic only; "
"no image/audio similarity measurement.",
"Second Pass contract: groups=1 PASS.",
)
@pytest.mark.parametrize(
("context", "expected_video", "expected_audio"),
(
(5, 2, 8),
(22, 7, 37),
(39, 12, 65),
),
)
def test_fast_balanced_strong_context_uses_shared_temporal_helpers(
context, expected_video, expected_audio
):
first = _chunk(1)
second = _chunk(2, context=context)
result = _diagnose(_plan(first, second))
assert context_slots(context) == expected_video
assert audio_latent_t(context) == expected_audio
assert result.basic == ()
assert len([line for line in result.detailed if line.startswith("Boundary ")]) == 1
assert (
f"context={context}f video={expected_video}T audio={expected_audio}T"
in result.detailed[-1]
)
assert result.detailed[-1].endswith("PASS.")
def test_three_chunks_have_two_boundaries_and_silent_basic():
result = _diagnose(_plan(_chunk(1), _chunk(2), _chunk(3)))
assert result.basic == ()
boundaries = [line for line in result.detailed if line.startswith("Boundary ")]
assert len(boundaries) == 2
assert boundaries[0].startswith("Boundary 1→2: physical;")
assert boundaries[1].startswith("Boundary 2→3: physical;")
@pytest.mark.parametrize(
("field", "value", "message"),
(
("trim_frames", 200, "trim_frames exceeds total_frames"),
("net_frames", 118, "total_frames - trim_frames differs from net_frames"),
),
)
def test_invalid_right_geometry_is_advisory(field, value, message):
right = _chunk(2)
right[field] = value
result = _diagnose(_plan(_chunk(1), right))
assert any(message in line for line in result.basic)
assert result.detailed[-1].endswith(").")
assert "ADVISORY" in result.detailed[-1]
@pytest.mark.parametrize(("right_start", "gap"), ((125, 1), (123, -1)))
def test_artificial_gap_or_overlap_is_advisory(right_start, gap):
result = _diagnose(_plan(_chunk(1), _chunk(2, start=right_start)))
assert any("non-contiguous visible range" in line for line in result.basic)
boundary = result.detailed[-1]
assert f"gap={gap}" in boundary
assert "ADVISORY" in boundary
def test_missing_geometry_is_unavailable_without_hard_failure():
right = _chunk(2)
del right["total_frames"]
result = _diagnose(_plan(_chunk(1), right, second_pass=False))
assert result.basic
assert "required geometry is unavailable" in "\n".join(result.basic)
assert "ADVISORY" in result.detailed[-1]
def test_non_contiguous_logical_order_is_advisory():
right = _chunk(2)
right["chunk_index"] = 3
groups = [_decode_group(_chunk(1)), _decode_group(right, logical=[2])]
result = _diagnose(_plan(_chunk(1), right, groups=groups, second_pass=False))
assert any("logical order" in line for line in result.basic)
def test_physical_mapping_missing_logical_chunk():
chunks = (_chunk(1), _chunk(2), _chunk(3))
groups = [_decode_group(chunks[0]), _decode_group(chunks[2])]
result = _diagnose(_plan(*chunks, groups=groups, second_pass=False))
assert any("does not cover all logical chunks" in line for line in result.basic)
assert any("UNAVAILABLE" in line for line in result.detailed)
def test_physical_mapping_duplicate_logical_chunk():
chunks = (_chunk(1), _chunk(2))
groups = [_decode_group(chunks[0]), _decode_group(chunks[1], logical=[1])]
result = _diagnose(_plan(*chunks, groups=groups, second_pass=False))
assert any("mapped more than once" in line for line in result.basic)
def test_physical_mapping_reversed_order():
chunks = (_chunk(1), _chunk(2))
group = _decode_group(chunks[0], logical=[2, 1], terminal=True)
result = _diagnose(_plan(*chunks, groups=[group], second_pass=False))
joined = "\n".join(result.basic)
assert "logical order is reversed" in joined
assert "Terminal Merge mapping is invalid" in joined
def test_physical_output_group_count_mismatch_is_summarized():
plan = _plan(_chunk(1), _chunk(2), second_pass=False)
result = _diagnose(plan, video_count=1, audio_count=2)
assert any("physical output/group counts differ" in line for line in result.basic)
def _terminal_plan(*, terminal_flag=True, second_pass=True):
chunks = [_chunk(1), _chunk(2), _chunk(3)]
terminal = dict(chunks[1])
terminal.update(
{
"total_frames": 260,
"trim_frames": 22,
"net_frames": 238,
"frame_start": 124,
"frame_stop": 362,
"logical_chunk_indices": [2, 3],
"terminal_merged": terminal_flag,
}
)
groups = [_decode_group(chunks[0]), terminal]
return _plan(*chunks, groups=groups, second_pass=second_pass)
def test_terminal_merge_is_shared_physical_boundary_not_external_seam():
result = _diagnose(_terminal_plan())
assert result.basic == ()
terminal = [line for line in result.detailed if line.startswith("Boundary 2→3")][0]
assert "shared physical group=2" in terminal
assert "terminal_merged=yes" in terminal
assert "no external decode boundary" in terminal
assert terminal.endswith("PASS.")
def test_terminal_flag_mismatch_is_advisory():
result = _diagnose(_terminal_plan(terminal_flag=False, second_pass=False))
assert any("without Terminal Merge" in line for line in result.basic)
terminal = [line for line in result.detailed if line.startswith("Boundary 2→3")][0]
assert "terminal_merged=no" in terminal
assert "ADVISORY" in terminal
@pytest.mark.parametrize(
("field", "value", "message"),
(
("logical_chunks", [1, 2], "logical_chunks differs"),
("physical_frames", 999, "physical_frames differs"),
("trim_prefix_frames", 5, "trim_prefix_frames differs"),
),
)
def test_second_pass_contract_mismatch_is_advisory(field, value, message):
plan = _terminal_plan()
plan["second_pass_contract"]["physical_groups"][1][field] = value
result = _diagnose(plan)
assert any(message in line for line in result.basic)
assert "Second Pass contract: groups=2 ADVISORY." in result.detailed
class _ReadOnlyTensorProbe:
shape = (1, 24, 37, 4, 4)
dtype = "probe-dtype"
device = "probe-device"
def data_ptr(self):
return 12345
def clone(self):
raise AssertionError("clone must not be called")
def cpu(self):
raise AssertionError("cpu must not be called")
def float(self):
raise AssertionError("float must not be called")
def numpy(self):
raise AssertionError("numpy must not be called")
def __hash__(self):
raise AssertionError("hash must not be called")
def test_diagnostic_is_read_only_and_preserves_all_objects():
video_tensor = _ReadOnlyTensorProbe()
audio_tensor = _ReadOnlyTensorProbe()
video_latents = [{"samples": video_tensor}]
audio_latents = [{"samples": audio_tensor}]
plan = _plan(_chunk(1))
before = (
id(video_latents),
id(audio_latents),
id(plan),
id(video_tensor),
id(audio_tensor),
video_tensor.data_ptr(),
video_tensor.dtype,
video_tensor.device,
video_tensor.shape,
)
build_chunk_boundary_diagnostics(
video_latents=video_latents,
audio_latents=audio_latents,
assembly_plan=plan,
)
after = (
id(video_latents),
id(audio_latents),
id(plan),
id(video_tensor),
id(audio_tensor),
video_tensor.data_ptr(),
video_tensor.dtype,
video_tensor.device,
video_tensor.shape,
)
assert after == before
def test_boundary_implementation_has_no_tensor_content_operations():
source = inspect.getsource(build_chunk_boundary_diagnostics)
for forbidden in (
".clone(",
".cpu(",
".float(",
".numpy(",
"ContextDiagnosticsTracker",
"torch.equal",
):
assert forbidden not in source
+437
View File
@@ -0,0 +1,437 @@
from __future__ import annotations
import copy
import pytest
import torch
from ComfyUI_H3_Continuum_Join.v3 import second_pass, second_pass_nodes
from ComfyUI_H3_Continuum_Join.v3 import targeted_second_pass
from ComfyUI_H3_Continuum_Join.v3.refine_scope import (
MAGIC,
MODE_ALL,
MODE_LOGICAL_CHUNK,
MODE_PHYSICAL_GROUP,
RefineScopeError,
resolve_refine_scope,
serializable_scope_contract,
)
from ComfyUI_H3_Continuum_Join.v3.refine_target import (
MODE_AUDIO_ONLY,
MODE_VIDEO_AUDIO,
MODE_VIDEO_ONLY,
derive_target_refine_seed,
)
from ComfyUI_H3_Continuum_Join.v3.second_pass_nodes import (
H3ContinuumSelectiveSecondPassExperimental,
REFINE_SCOPE_ALL,
REFINE_SCOPE_LOGICAL_CHUNK,
REFINE_SCOPE_PHYSICAL_GROUP,
REFINE_TARGET_VIDEO_ONLY,
)
from ComfyUI_H3_Continuum_Join.v3.targeted_second_pass import (
run_targeted_second_pass_groups,
)
def _group(
group_id: int,
logical_chunks: list[int],
*,
temporal: int,
audio_t: int,
terminal: bool = False,
) -> dict:
return {
"group_id": group_id,
"logical_chunks": logical_chunks,
"physical_prompt": f"group {group_id + 1}",
"prompt_policy": "paired_timeline_v1" if terminal else "single",
"physical_frames": 260 if terminal else 124,
"trim_prefix_frames": 22 if group_id else 0,
"terminal_merged": terminal,
"source_width": 128,
"source_height": 128,
"source_batch": 1,
"latent_channels": 24,
"source_latent_t": temporal,
"source_latent_h": 8,
"source_latent_w": 8,
"source_audio_shape": [1, 32, 2, audio_t],
}
def _fixture(*, terminal: bool = False):
if terminal:
groups = [
_group(0, [1], temporal=31, audio_t=207),
_group(1, [2, 3], temporal=65, audio_t=433, terminal=True),
]
else:
groups = [
_group(0, [1], temporal=31, audio_t=207),
_group(1, [2], temporal=36, audio_t=235),
_group(2, [3], temporal=36, audio_t=235),
]
videos = [
{
"samples": torch.full(
(1, 24, group["source_latent_t"], 8, 8),
float(index + 1),
)
}
for index, group in enumerate(groups)
]
audios = [
{
"samples": torch.full(
tuple(group["source_audio_shape"]),
float(index + 11),
)
}
for index, group in enumerate(groups)
]
plan = {
"width": 128,
"height": 128,
"existing_top_level": {"preserved": True},
"second_pass_contract": {
"version": 1,
"existing_contract_field": "preserved",
"physical_groups": groups,
},
}
return groups, videos, audios, plan
def _run(
target: str,
*,
scope: str = MODE_ALL,
scope_index: int = 1,
terminal: bool = False,
observers: dict | None = None,
):
groups, videos, audios, plan = _fixture(terminal=terminal)
calls = observers if observers is not None else {}
calls.setdefault("encode", [])
calls.setdefault("clone", [])
calls.setdefault("sample", [])
sigmas = torch.tensor([0.6, 0.3, 0.0], dtype=torch.float32)
def encode(_clip, prompt, **_kwargs):
calls["encode"].append(prompt)
return [prompt]
def clone(model, **kwargs):
calls["clone"].append(kwargs)
return model
def sample(**kwargs):
calls["sample"].append(kwargs)
return {
"video": kwargs["latent"]["video"] + 100.0,
"audio": kwargs["latent"]["audio"] + 200.0,
}
result = run_targeted_second_pass_groups(
model="model",
clip="clip",
sampler="sampler",
sigmas=sigmas,
video_latents=videos,
audio_latents=audios,
assembly_plan=plan,
refine_seed=91,
refine_target=target,
refine_scope=scope,
refine_scope_index=scope_index,
encode_prompt_fn=encode,
latent_builder=lambda video, audio: {"video": video, "audio": audio},
sample_fn=sample,
stream_extractor=lambda value: (value["video"], value["audio"]),
clone_model_fn=clone,
enable_preview=False,
)
return groups, videos, audios, plan, sigmas, calls, result
def test_scope_resolver_is_pure_and_terminal_logical_selection_is_atomic():
groups, _videos, _audios, plan = _fixture(terminal=True)
plan_before = copy.deepcopy(plan)
all_scope = resolve_refine_scope(MODE_ALL, 99, plan)
physical = resolve_refine_scope(MODE_PHYSICAL_GROUP, 2, plan)
logical = resolve_refine_scope(MODE_LOGICAL_CHUNK, 3, plan)
assert plan == plan_before
assert all_scope.selected_group_indices == (0, 1)
assert all_scope.contract["requested_index"] is None
assert physical.selected_group_indices == (1,)
assert physical.contract["selected_logical_chunks"] == (2, 3)
assert physical.contract["terminal_expanded"] is False
assert logical.selected_group_indices == (1,)
assert logical.contract["selected_logical_chunks"] == (2, 3)
assert logical.contract["terminal_expanded"] is True
assert logical.contract["magic"] == MAGIC
serialized = serializable_scope_contract(logical)
serialized["selected_logical_chunks"].append(99)
assert logical.contract["selected_logical_chunks"] == (2, 3)
assert groups[1]["logical_chunks"] == [2, 3]
@pytest.mark.parametrize(
("mode", "index", "match"),
(
("unknown", 1, "unsupported refine scope"),
(1, 1, "unsupported refine scope"),
(MODE_PHYSICAL_GROUP, 0, "positive integer"),
(MODE_PHYSICAL_GROUP, 1.5, "positive integer"),
(MODE_PHYSICAL_GROUP, 3, "outside"),
(MODE_LOGICAL_CHUNK, 4, "not present"),
),
)
def test_invalid_scope_fails_before_any_execution(mode, index, match):
_groups, _videos, _audios, plan = _fixture(terminal=True)
with pytest.raises(RefineScopeError, match=match):
resolve_refine_scope(mode, index, plan)
@pytest.mark.parametrize(
("target", "video_changed", "audio_changed"),
(
(MODE_VIDEO_ONLY, True, False),
(MODE_AUDIO_ONLY, False, True),
(MODE_VIDEO_AUDIO, True, True),
),
)
def test_physical_group_scope_does_no_work_for_unselected_groups(
monkeypatch,
target,
video_changed,
audio_changed,
):
derived_indices = []
if target == MODE_VIDEO_ONLY:
original = second_pass.derive_refine_seed
def derive(seed, index):
derived_indices.append(index)
return original(seed, index)
monkeypatch.setattr(second_pass, "derive_refine_seed", derive)
else:
original = targeted_second_pass.derive_target_refine_seed
def derive(seed, index, resolved_target):
derived_indices.append(index)
return original(seed, index, resolved_target)
monkeypatch.setattr(targeted_second_pass, "derive_target_refine_seed", derive)
groups, videos, audios, plan, sigmas, calls, result = _run(
target,
scope=MODE_PHYSICAL_GROUP,
scope_index=2,
)
output_videos, output_audios, updated_plan, status = result
assert len(groups) == 3
assert calls["encode"] == ["group 2"]
assert len(calls["clone"]) == len(calls["sample"]) == 1
assert derived_indices == [1]
assert calls["sample"][0]["sigmas"] is sigmas
assert calls["sample"][0]["seed"] == derive_target_refine_seed(91, 1, target)
for index in (0, 2):
assert output_videos[index] is videos[index]
assert output_audios[index] is audios[index]
assert (output_videos[1] is not videos[1]) is video_changed
assert (output_audios[1] is not audios[1]) is audio_changed
assert plan["existing_top_level"] == {"preserved": True}
assert plan["second_pass_contract"]["existing_contract_field"] == "preserved"
contract = updated_plan["second_pass_contract"]
assert contract["version"] == 1
assert contract["existing_contract_field"] == "preserved"
assert contract["physical_groups"][:3] != []
assert contract["refine_group_seeds"] == [calls["sample"][0]["seed"]]
assert "refine_scope_contract" not in contract
assert "no conditioning, MODEL clone, Sampling, or seed derivation" in status
def test_non_selected_refine_context_conditioning_is_not_adapted_or_cloned():
groups, videos, _audios, plan = _fixture()
calls = {"adapt": [], "clone": [], "consume": []}
def validate(_context, *, assembly_plan):
assert assembly_plan is plan
return {"complete": True, "groups": groups}
def adapt(group, **_kwargs):
calls["adapt"].append(group["group_id"])
return [[f"conditioning-{group['group_id']}", {}]], None
def clone(model, **kwargs):
calls["clone"].append(kwargs["chunk_index"])
return model
prepared = second_pass.prepare_physical_refine_groups(
model="model",
clip="clip",
video_latents=videos,
assembly_plan=plan,
refine_context=object(),
validate_refine_context_fn=validate,
adapt_group_conditioning_fn=adapt,
clone_model_fn=clone,
group_consumer_fn=lambda group_index, *_args: calls["consume"].append(
group_index
),
retain_group_outputs=False,
selected_group_indices=(1,),
)
assert calls == {"adapt": [1], "clone": [2], "consume": [1]}
assert prepared["selected_group_indices"] == [1]
assert prepared["selected_group_count"] == 1
def test_selected_group_seed_matches_all_mode_and_all_mode_has_a3c_plan_contract():
*_prefix, all_calls, all_result = _run(MODE_VIDEO_AUDIO)
*_scoped_prefix, scoped_calls, scoped_result = _run(
MODE_VIDEO_AUDIO,
scope=MODE_PHYSICAL_GROUP,
scope_index=2,
)
all_plan = all_result[2]
scoped_plan = scoped_result[2]
assert scoped_calls["sample"][0]["seed"] == all_calls["sample"][1]["seed"]
assert "refine_scope_contract" not in all_plan["second_pass_contract"]
assert set(scoped_plan["second_pass_contract"]) == set(
all_plan["second_pass_contract"]
)
assert "Refine Scope:" not in all_result[3]
assert scoped_plan["second_pass_contract"]["version"] == 1
@pytest.mark.parametrize("logical_chunk", (2, 3))
def test_terminal_logical_chunk_scope_expands_to_one_atomic_physical_pair(
logical_chunk,
):
groups, videos, audios, _plan, _sigmas, calls, result = _run(
MODE_VIDEO_AUDIO,
scope=MODE_LOGICAL_CHUNK,
scope_index=logical_chunk,
terminal=True,
)
output_videos, output_audios, updated_plan, status = result
assert groups[1]["logical_chunks"] == [2, 3]
assert groups[1]["terminal_merged"] is True
assert len(calls["encode"]) == len(calls["clone"]) == len(calls["sample"]) == 1
assert output_videos[0] is videos[0]
assert output_audios[0] is audios[0]
assert output_videos[1] is not videos[1]
assert output_audios[1] is not audios[1]
assert "refine_scope_contract" not in updated_plan["second_pass_contract"]
assert "selected_physical_groups=[2]" in status
assert "selected_logical_chunks=[2, 3]" in status
assert "terminal_expanded=true" in status
def test_public_scope_labels_forward_without_frontend_or_silent_fallback(monkeypatch):
calls = []
def fake_run(**kwargs):
calls.append(kwargs)
return kwargs["video_latents"], kwargs["audio_latents"], kwargs[
"assembly_plan"
], "ok"
monkeypatch.setattr(second_pass_nodes, "run_targeted_second_pass_groups", fake_run)
node = H3ContinuumSelectiveSecondPassExperimental()
common = {
"model": [object()],
"clip": [object()],
"sampler": [object()],
"sigmas": [object()],
"video_latents": [{"samples": object()}],
"audio_latents": [{"samples": object()}],
"assembly_plan": [{"second_pass_contract": {"version": 1}}],
"refine_seed": [7],
"refine_target": [REFINE_TARGET_VIDEO_ONLY],
}
node.refine(
**common,
refine_scope=[REFINE_SCOPE_PHYSICAL_GROUP],
refine_scope_index=[2],
)
node.refine(
**common,
refine_scope=[REFINE_SCOPE_LOGICAL_CHUNK],
refine_scope_index=[3],
)
node.refine(**common)
assert [(call["refine_scope"], call["refine_scope_index"]) for call in calls] == [
(MODE_PHYSICAL_GROUP, 2),
(MODE_LOGICAL_CHUNK, 3),
(MODE_ALL, 1),
]
with pytest.raises(ValueError, match="unsupported selective refine scope"):
node.refine(
**common,
refine_scope=["unknown"],
refine_scope_index=[1],
)
assert len(calls) == 3
def test_invalid_public_scope_fails_before_any_execution():
calls = {"encode": [], "clone": [], "sample": []}
with pytest.raises(RefineScopeError, match="not present"):
_run(
MODE_VIDEO_AUDIO,
scope=MODE_LOGICAL_CHUNK,
scope_index=99,
observers=calls,
)
assert calls == {"encode": [], "clone": [], "sample": []}
def test_terminal_logical_halves_resolve_to_the_same_group_seed():
*_, chunk_2_calls, _chunk_2_result = _run(
MODE_VIDEO_AUDIO,
scope=MODE_LOGICAL_CHUNK,
scope_index=2,
terminal=True,
)
*_, chunk_3_calls, _chunk_3_result = _run(
MODE_VIDEO_AUDIO,
scope=MODE_LOGICAL_CHUNK,
scope_index=3,
terminal=True,
)
assert len(chunk_2_calls["sample"]) == len(chunk_3_calls["sample"]) == 1
assert chunk_2_calls["sample"][0]["seed"] == chunk_3_calls["sample"][0][
"seed"
]
def test_scope_does_not_extend_assembly_plan_or_run_storage_contract():
*_all_prefix, all_result = _run(MODE_VIDEO_AUDIO)
*_scope_prefix, scoped_result = _run(
MODE_VIDEO_AUDIO,
scope=MODE_LOGICAL_CHUNK,
scope_index=2,
)
all_contract = all_result[2]["second_pass_contract"]
scoped_contract = scoped_result[2]["second_pass_contract"]
assert all_result[2].keys() == scoped_result[2].keys()
assert all_contract.keys() == scoped_contract.keys()
assert "refine_scope_contract" not in scoped_contract
assert "run_storage" not in targeted_second_pass.__dict__
+141
View File
@@ -0,0 +1,141 @@
"""Exercise the real frontend (not a copied visibility predicate) across its lifecycle."""
import shutil
import subprocess
from pathlib import Path
import pytest
def test_completed_review_lifecycle_with_real_frontend(tmp_path):
node = shutil.which("node")
assert node, "Node.js is required for this frontend gate"
source = (Path(__file__).resolve().parents[1] / "web/project_id.js").read_text(encoding="utf-8")
source = source.replace('import { app } from "../../scripts/app.js";',
'const app = globalThis.__app;').replace(
'import { normalizeReferenceAudioLabels } from "./reference_audio_ui.js";',
'function normalizeReferenceAudioLabels() {}')
harness = r'''
const assert = require("node:assert/strict");
let project = null;
let fetchMode = "ok";
globalThis.fetch = async () => {
if (fetchMode === "error") throw new Error("offline fixture");
return project ? {ok:true, status:200, json:async()=>structuredClone(project)} : {ok:false,status:404};
};
globalThis.__app = {
graph: {_nodes: [], links:{}, getNodeById:()=>null},
ui:{settings:{getSettingValue:(_id,fallback)=>fallback,addSetting(){}}},
registerExtension(extension){this.extension=extension;}
};
'''
cases = r'''
function makeNode() {
const values = {
prompt_mode:"Auto",chunks:2,chunk_seconds:5,aspect:"Auto from First Image",
preset:"Draft — 0.30 MP",custom_mp:0.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:"fixture",project_id:"fixture",
reference_size:"Match Output",video_reference_size:"Efficient - 0.4 MP",
diagnostics:"Detailed Report",strict_compatibility:false,debug:false,show_preview:true,
generation_mode:"Review Each Chunk",review_action:"Continue / Next",
take_group:0,take_revision_id:"",take_action:"Automatic",
size_source:"First Image",width:544,height:544
};
const n={comfyClass:"H3ContinuumSamplerV38",properties:{},inputs:[],
widgets:Object.entries(values).map(([name,value])=>({name,value,type:"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;},
serialize(){return {widgets_values:this.widgets.map(w=>w.value)};},
configure(info){info.widgets_values.forEach((v,i)=>{this.widgets[i].value=v;});},
setDirtyCanvas(){}
};
app.extension.nodeCreated(n);
return n;
}
const w=(n,name)=>n.widgets.find(w=>w.name===name);
const visible=(n,name)=>!w(n,name).hidden;
const buttons=["Use it and continue","Try this chunk again","Use it and finish the rest"];
function state(status,unit,id="revision-1") {
return {branch_provenance_version:1,canonical_storage_revision_id:id,
revisions:[{revision_id:id,status,...(unit?{review_unit:unit}:{})}],
canonical_head_revision_id:"take-1",active_revisions:{"1":"take-1"},
group_revisions:[{revision_id:"take-1",revision_order:"1",take_number:1,group:{start:1,end:1,physical_group:1}}]};
}
async function load(n,p) {project=p;await loadTakeHistory(n);n.__h3ContinuumIntuitiveUxRefresh?.();n.__h3ContinuumProductionUxRefresh();}
(async()=>{
const n=makeNode();await load(n,null);
assert(buttons.every(name=>!visible(n,name)),"initial is not review-ready");
for(const status of ["running","interrupted","unknown"]){
await load(n,state(status,{start:1,end:1,physical_group:1}));
assert(buttons.every(name=>!visible(n,name)),status);
}
await load(n,state("review_ready",{start:1,end:1,physical_group:1}));
assert(buttons.every(name=>visible(n,name)),"partial review has all actions");
for(const action of ["Use it and continue","Use it and finish the rest"]){
w(n,action).callback();const inputs={};prepareReviewQueueIntent(n,inputs);
assert.equal(inputs.review_action,action==="Use it and continue"?"Continue / Next":"Finish Remaining");
w(n,"review_action").afterQueued({isPartialExecution:false});
assert.equal(w(n,"review_action").value,"Continue / Next");
}
for(const count of [1,2,3,4,5,6]){
w(n,"chunks").value=count;
const p=state("complete",{start:count,end:count,physical_group:count},`done-${count}`);
await load(n,p);
assert(visible(n,"Try this chunk again"),`retry complete ${count}`);
assert(!visible(n,"Use it and continue")&&!visible(n,"Use it and finish the rest"),"no no-op continuation buttons");
assert(visible(n,"Render History"));
assert.match(w(n,"Review Ready").value,/Saved sequence is complete/);
const saved=n.serialize();
w(n,"Back to Settings").callback();
assert(visible(n,"Chunks")&&visible(n,"Return to Review"));
assert(!visible(n,"Try this chunk again"));
w(n,"Return to Review").callback();
assert(visible(n,"Try this chunk again")&&!visible(n,"Chunks"));
assert.deepEqual(n.serialize(),saved,"settings/review are presentation only");
w(n,"Render History").callback();assert(visible(n,"Render History / Takes"));
const drawn=[];
const ctx={save(){},restore(){},beginPath(){},rect(){},clip(){},fillText(text){drawn.push(text);}};
w(n,"Render History / Takes").draw(ctx,n,400,0,300);
assert(drawn.some(text=>text.startsWith("Selected:")),"selected Take is actually drawn, not an empty text widget");
w(n,"Render History").callback();assert(!visible(n,"Render History / Takes"));
w(n,"Try this chunk again").callback();
const inputs={};prepareReviewQueueIntent(n,inputs);
assert.equal(inputs.review_action,"Regenerate Current");
assert.equal(w(n,"base_seed").value,123);
assert.equal(w(n,"control_after_generate").value,"fixed");
assert.match(w(n,"Review Ready").value,new RegExp(`Chunk ${count}`));
w(n,"review_action").afterQueued({isPartialExecution:false});
assert.equal(inputs.review_action,"Regenerate Current","queued payload remains immutable");
assert.equal(w(n,"review_action").value,"Continue / Next","one-shot consumed once");
assert.deepEqual(project,p,"backend evidence not rewritten");
await load(n,state("complete",{start:count,end:count,physical_group:count},`retry-${count}`));
assert(visible(n,"Try this chunk again"),"retry completion still accessible");
}
await load(n,state("complete",{start:2,end:3,physical_group:2},"terminal"));
w(n,"Try this chunk again").callback();
assert.match(w(n,"Review Ready").value,/Chunks 2-3/);
await load(n,state("complete",null,"finish-without-unit"));
assert(!visible(n,"Try this chunk again"),"do not invent a retry unit for full-run completion");
assert(visible(n,"Render History")&&visible(n,"Back to Settings"));
await load(n,state("review_ready",{physical_group:1}));
assert(!visible(n,"Try this chunk again"),"incomplete metadata not actionable");
await load(n,state("complete",{start:1,end:1,physical_group:1}));
fetchMode="error";await loadTakeHistory(n);
assert(!visible(n,"Try this chunk again"),"failed fetch cannot retain stale retry controls");
fetchMode="ok";await loadTakeHistory(n);assert(visible(n,"Try this chunk again"));
const reloaded=makeNode();await load(reloaded,project);
assert(visible(reloaded,"Try this chunk again"),"reload restores completed review from backend");
w(reloaded,"generation_mode").value="Full Run";reloaded.__h3ContinuumProductionUxRefresh();
assert(buttons.every(name=>!visible(reloaded,name)),"full run does not expose review actions");
w(reloaded,"generation_mode").value="Review Each Chunk";
w(reloaded,"run_storage").value="Off";reloaded.__h3ContinuumProductionUxRefresh();
assert(buttons.every(name=>!visible(reloaded,name)),"storage off does not expose review actions");
console.log("PASS: real frontend completed-review lifecycle");
})().catch(e=>{console.error(e);process.exitCode=1;});
'''
script = tmp_path / "completed_review.cjs"
script.write_text(harness + source + cases, encoding="utf-8")
result = subprocess.run([node, str(script)], capture_output=True, text=True, timeout=30)
assert result.returncode == 0, result.stdout + result.stderr
assert "PASS: real frontend" in result.stdout
+592
View File
@@ -0,0 +1,592 @@
from __future__ import annotations
import json
from pathlib import Path
import shutil
import subprocess
import sys
from types import ModuleType
import pytest
import torch
from ComfyUI_H3_Continuum_Join import nodes as root_nodes
from ComfyUI_H3_Continuum_Join.reference import (
REFERENCE_SIZE_MATCH_OUTPUT,
prepare_reference_assets,
validate_reference_prompts,
)
from ComfyUI_H3_Continuum_Join.v2.sequence import _terminal_flf_merge_enabled
from ComfyUI_H3_Continuum_Join.v3.driving_nodes import H3ContinuumSamplerV37
from ComfyUI_H3_Continuum_Join.v3.easy_nodes import (
EASY_ASPECT_AUTO,
EASY_ASPECT_LANDSCAPE,
EASY_ASPECT_PORTRAIT,
EASY_ASPECT_SQUARE,
EASY_PRESET_BALANCED,
EASY_PRESET_CUSTOM,
EASY_PRESET_DRAFT,
EASY_PRESET_NATIVE,
EASY_REFERENCES_TYPE,
EASY_SEED_MODE_RANDOMIZE,
H3ContinuumEasyReferences,
H3ContinuumEasyV38,
NODE_CLASS_MAPPINGS,
NODE_DISPLAY_NAME_MAPPINGS,
make_easy_references,
resolve_easy_duration,
resolve_easy_references,
resolve_easy_resolution,
)
ROOT = Path(__file__).resolve().parents[1]
EASY_JS = ROOT / "web" / "easy_v38.js"
class _Image:
def __init__(self, height: int, width: int):
self.shape = (1, height, width, 3)
@pytest.mark.parametrize(
("duration", "chunks", "chunk_seconds"),
(
(4, 1, 4.0),
(10, 1, 10.0),
(15, 2, 7.5),
(20, 2, 10.0),
(30, 3, 10.0),
(160, 16, 10.0),
(480, 16, 30.0),
),
)
def test_duration_resolver_uses_approved_ten_second_policy(
duration,
chunks,
chunk_seconds,
):
plan = resolve_easy_duration(duration)
assert plan.duration_seconds == duration
assert plan.chunks == chunks
assert plan.chunk_seconds == chunk_seconds
assert plan.chunks * plan.chunk_seconds == duration
@pytest.mark.parametrize("duration", (3, 481, True, 10.5))
def test_duration_resolver_rejects_values_outside_integer_production_contract(duration):
with pytest.raises((TypeError, ValueError)):
resolve_easy_duration(duration)
def test_decimal_mp_presets_follow_first_image_aspect_and_32_pixel_grid():
first = _Image(1200, 900)
draft = resolve_easy_resolution(
aspect=EASY_ASPECT_AUTO,
preset=EASY_PRESET_DRAFT,
first_frame=first,
)
balanced = resolve_easy_resolution(
aspect=EASY_ASPECT_AUTO,
preset=EASY_PRESET_BALANCED,
first_frame=first,
)
assert (draft.width, draft.height) == (480, 640)
assert (balanced.width, balanced.height) == (672, 896)
assert draft.aspect_source == "First Image"
assert draft.width % 32 == draft.height % 32 == 0
assert balanced.width % 32 == balanced.height % 32 == 0
@pytest.mark.parametrize(
("aspect", "expected"),
(
(EASY_ASPECT_SQUARE, (768, 768)),
(EASY_ASPECT_LANDSCAPE, (1344, 768)),
(EASY_ASPECT_PORTRAIT, (768, 1344)),
),
)
def test_native_768_representative_dimensions(aspect, expected):
plan = resolve_easy_resolution(aspect=aspect, preset=EASY_PRESET_NATIVE)
assert (plan.width, plan.height) == expected
def test_native_768_preserves_extreme_aspect_by_prioritizing_long_edge_cap():
landscape = resolve_easy_resolution(
aspect=EASY_ASPECT_AUTO,
preset=EASY_PRESET_NATIVE,
first_frame=_Image(900, 2100),
)
portrait = resolve_easy_resolution(
aspect=EASY_ASPECT_AUTO,
preset=EASY_PRESET_NATIVE,
first_frame=_Image(2100, 900),
)
assert (landscape.width, landscape.height) == (1344, 576)
assert (portrait.width, portrait.height) == (576, 1344)
def test_auto_without_first_image_falls_back_to_landscape():
auto = resolve_easy_resolution(
aspect=EASY_ASPECT_AUTO,
preset=EASY_PRESET_DRAFT,
)
explicit = resolve_easy_resolution(
aspect=EASY_ASPECT_LANDSCAPE,
preset=EASY_PRESET_DRAFT,
)
assert (auto.width, auto.height) == (explicit.width, explicit.height)
assert auto.aspect_source == "Landscape 16:9 fallback"
def test_custom_mp_is_not_clamped_to_native_and_reports_diagnostics():
plan = resolve_easy_resolution(
aspect=EASY_ASPECT_SQUARE,
preset=EASY_PRESET_CUSTOM,
custom_mp=3.0,
)
assert plan.width > 768
assert plan.height > 768
assert len(plan.warnings) == 2
assert "Above Native 768" in plan.warnings[0]
assert "High Custom MP" in plan.warnings[1]
def test_easy_schema_keeps_driving_audio_optional_and_scheduler_out():
schema = H3ContinuumEasyV38.INPUT_TYPES()
required = schema["required"]
optional = schema["optional"]
assert tuple(required)[:5] == ("model", "clip", "video_vae", "sampler", "sigmas")
assert "scheduler" not in required
assert "audio_vae" not in required
assert optional["driving_audio"][0] == "AUDIO"
assert optional["driving_audio"][1]["display_name"] == "Driving Audio"
assert optional["audio_vae"][0] == "VAE"
assert optional["audio_vae"][1]["display_name"] == "Driving Audio VAE"
assert "first_frame" in optional
assert "last_frame" in optional
assert optional["references"][0] == EASY_REFERENCES_TYPE
assert not {
"driving_audio_vae",
"reference_audio_1",
"reference_audio_vae",
"reference_video_1",
"still_image_guide",
"timeline_video",
} & set(optional)
assert required["duration"][1]["default"] == 10
assert required["seed_mode"][1]["default"] == EASY_SEED_MODE_RANDOMIZE
assert required["run_storage"][1]["default"] == "Off"
assert required["prompt_text"][1]["multiline"] is True
def test_easy_node_is_registered_without_replacing_v37():
assert NODE_CLASS_MAPPINGS["H3ContinuumEasyReferences"] is (
H3ContinuumEasyReferences
)
assert NODE_DISPLAY_NAME_MAPPINGS["H3ContinuumEasyReferences"] == (
"H3 Continuum Easy References"
)
assert NODE_CLASS_MAPPINGS["H3ContinuumEasyV38"] is H3ContinuumEasyV38
assert NODE_DISPLAY_NAME_MAPPINGS["H3ContinuumEasyV38"] == (
"H3 Continuum Easy V3.8"
)
assert "H3ContinuumEasyV38" not in root_nodes.NODE_CLASS_MAPPINGS
assert "H3ContinuumSamplerV37" not in root_nodes.NODE_CLASS_MAPPINGS
assert "H3ContinuumEasyReferences" not in root_nodes.NODE_CLASS_MAPPINGS
assert H3ContinuumEasyReferences.DEPRECATED is False
assert H3ContinuumEasyV38.DEPRECATED is False
def test_easy_references_schema_has_three_fixed_optional_image_sockets_only():
schema = H3ContinuumEasyReferences.INPUT_TYPES()
assert "required" not in schema
assert tuple(schema["optional"]) == (
"reference_image_1",
"reference_image_2",
"reference_image_3",
)
assert all(value[0] == "IMAGE" for value in schema["optional"].values())
assert H3ContinuumEasyReferences.RETURN_TYPES == (EASY_REFERENCES_TYPE,)
@pytest.mark.parametrize(
"active_slots",
((), (1,), (1, 2), (1, 2, 3), (2,)),
)
def test_easy_references_preserve_fixed_slots_for_v37_mapping(active_slots):
images = {index: object() for index in range(1, 4)}
kwargs = {
f"reference_image_{index}": images[index]
for index in active_slots
}
bundle = H3ContinuumEasyReferences().pack(**kwargs)[0]
resolved = resolve_easy_references(bundle)
assert resolved == tuple(
images[index] if index in active_slots else None
for index in range(1, 4)
)
def test_easy_references_none_and_invalid_payload_contract():
assert resolve_easy_references(None) == (None, None, None)
with pytest.raises(TypeError, match="H3 Continuum Easy References"):
resolve_easy_references("not-a-reference-bundle")
with pytest.raises(ValueError, match="schema version"):
resolve_easy_references({"schema_version": 999})
@pytest.mark.parametrize(
("duration", "expected_chunks", "expected_seconds"),
((10, 1, 10.0), (15, 2, 7.5), (20, 2, 10.0), (30, 3, 10.0)),
)
def test_easy_facade_maps_to_v37_without_copying_sampling(
monkeypatch,
duration,
expected_chunks,
expected_seconds,
):
captured = {}
def fake_v37_run(_self, **kwargs):
captured.update(kwargs)
return "video", "audio", {"plan": True}, "V3.7 status", None, "refine"
monkeypatch.setattr(H3ContinuumSamplerV37, "run", fake_v37_run)
outputs = H3ContinuumEasyV38().run(
model="model",
clip="clip",
video_vae="video-vae",
sampler="sampler",
sigmas="sigmas",
prompt_text="<|caption|> literal embedding:example",
duration=duration,
seed=42,
aspect=EASY_ASPECT_AUTO,
preset=EASY_PRESET_DRAFT,
first_frame=_Image(1200, 900),
last_frame=_Image(1200, 900),
)
assert captured["chunks"] == expected_chunks
assert captured["chunk_seconds"] == expected_seconds
assert captured["sequence_prompt"] == "<|caption|> literal embedding:example"
assert captured["prompt_mode"] == "Auto"
assert (captured["width"], captured["height"]) == (480, 640)
assert captured["first_frame"] is not None
assert captured["last_frame"] is not None
assert captured["base_seed"] == 42
assert captured["run_storage"] == "Off"
assert captured["driving_audio"] is None
assert captured["audio_vae"] is None
assert len(outputs) == 5
assert "FL2VA + Continuation" in outputs[3]
assert "V3.7 status" in outputs[3]
def test_easy_driving_audio_and_vae_map_directly_to_v37(monkeypatch):
captured = {}
driving_audio = {"waveform": object(), "sample_rate": 32000}
audio_vae = object()
def fake_v37_run(_self, **kwargs):
captured.update(kwargs)
return "video", "audio", {"plan": True}, "V3.7 status", driving_audio
monkeypatch.setattr(H3ContinuumSamplerV37, "run", fake_v37_run)
outputs = H3ContinuumEasyV38().run(
model="model",
clip="clip",
video_vae="video-vae",
sampler="sampler",
sigmas="sigmas",
prompt_text="prompt",
duration=10,
seed=42,
driving_audio=driving_audio,
audio_vae=audio_vae,
)
assert captured["driving_audio"] is driving_audio
assert captured["audio_vae"] is audio_vae
assert outputs[4] is driving_audio
def test_easy_audio_vae_only_remains_normal_generation(monkeypatch):
captured = {}
audio_vae = object()
def fake_v37_run(_self, **kwargs):
captured.update(kwargs)
return "video", "generated-audio", {"plan": True}, "V3.7 status", None
monkeypatch.setattr(H3ContinuumSamplerV37, "run", fake_v37_run)
outputs = H3ContinuumEasyV38().run(
model="model",
clip="clip",
video_vae="video-vae",
sampler="sampler",
sigmas="sigmas",
prompt_text="prompt",
duration=10,
seed=42,
audio_vae=audio_vae,
)
assert captured["driving_audio"] is None
assert captured["audio_vae"] is audio_vae
assert outputs[1] == "generated-audio"
assert outputs[4] is None
def test_easy_audio_without_vae_keeps_v37_validation(monkeypatch):
def fake_v37_run(_self, **kwargs):
if kwargs["driving_audio"] is not None and kwargs["audio_vae"] is None:
raise ValueError("anchoring guide audio needs the audio_vae input")
raise AssertionError("expected the existing V3.7 validation path")
monkeypatch.setattr(H3ContinuumSamplerV37, "run", fake_v37_run)
with pytest.raises(ValueError, match="audio_vae input"):
H3ContinuumEasyV38().run(
model="model",
clip="clip",
video_vae="video-vae",
sampler="sampler",
sigmas="sigmas",
prompt_text="prompt",
duration=10,
seed=42,
driving_audio={"waveform": object(), "sample_rate": 32000},
)
def test_easy_reference_mapping_matches_direct_v37_slots_and_output_geometry(
monkeypatch,
):
captured = {}
first_ref, second_ref, third_ref = object(), object(), object()
def fake_v37_run(_self, **kwargs):
captured.update(kwargs)
return "video", "audio", {"plan": True}, "V3.7 status", None, "refine"
monkeypatch.setattr(H3ContinuumSamplerV37, "run", fake_v37_run)
references = make_easy_references(first_ref, second_ref, third_ref)
H3ContinuumEasyV38().run(
model="model",
clip="clip",
video_vae="video-vae",
sampler="sampler",
sigmas="sigmas",
prompt_text="Use <Picture 1>, <Picture 2>, and <Picture 3>.",
duration=10,
seed=42,
aspect=EASY_ASPECT_PORTRAIT,
preset=EASY_PRESET_DRAFT,
references=references,
)
direct_v37_reference_kwargs = {
"reference_image_1": first_ref,
"reference_image_2": second_ref,
"reference_image_3": third_ref,
}
assert {
key: captured[key] for key in direct_v37_reference_kwargs
} == direct_v37_reference_kwargs
assert captured["reference_size"] == REFERENCE_SIZE_MATCH_OUTPUT
assert (captured["width"], captured["height"]) == (416, 736)
@pytest.mark.parametrize(
("first_frame", "last_frame", "expected_mode"),
(
(_Image(640, 480), None, "Hybrid I2VA + Reference + Continuation"),
(
_Image(640, 480),
_Image(640, 480),
"Hybrid FL2VA + Reference + Continuation",
),
),
)
def test_easy_status_reports_first_last_with_reference(
monkeypatch,
first_frame,
last_frame,
expected_mode,
):
def fake_v37_run(_self, **_kwargs):
return "video", "audio", {"plan": True}, "V3.7 status", None, "refine"
monkeypatch.setattr(H3ContinuumSamplerV37, "run", fake_v37_run)
outputs = H3ContinuumEasyV38().run(
model="model",
clip="clip",
video_vae="video-vae",
sampler="sampler",
sigmas="sigmas",
prompt_text="Use <Picture 1>.",
duration=10,
seed=42,
first_frame=first_frame,
last_frame=last_frame,
references=make_easy_references(object()),
)
assert expected_mode in outputs[3]
def test_easy_reference_gap_compacts_to_picture_one_in_existing_v37_preprocessing():
second = torch.ones((1, 32, 32, 3))
refs = resolve_easy_references(
make_easy_references(reference_image_2=second)
)
assets = prepare_reference_assets(
reference_image_1=refs[0],
reference_image_2=refs[1],
reference_image_3=refs[2],
output_width=480,
output_height=640,
size_mode=REFERENCE_SIZE_MATCH_OUTPUT,
)
assert assets is not None
assert assets.count == 1
assert torch.equal(assets.images[0], second)
assert validate_reference_prompts(["Use <Picture 1>."], assets.count) == ""
assert "unavailable <Picture 2>" in validate_reference_prompts(
["Use <Picture 2>."], assets.count
)
def test_easy_reference_size_uses_existing_v37_output_geometry_policy(monkeypatch):
comfy_module = ModuleType("comfy")
comfy_utils_module = ModuleType("comfy.utils")
def common_upscale(image, width, height, _method, _crop):
return torch.nn.functional.interpolate(
image,
size=(height, width),
mode="bilinear",
align_corners=False,
)
comfy_utils_module.common_upscale = common_upscale
comfy_module.utils = comfy_utils_module
monkeypatch.setitem(sys.modules, "comfy", comfy_module)
monkeypatch.setitem(sys.modules, "comfy.utils", comfy_utils_module)
source = torch.zeros((1, 512, 1024, 3))
refs = resolve_easy_references(make_easy_references(source))
assets = prepare_reference_assets(
reference_image_1=refs[0],
reference_image_2=refs[1],
reference_image_3=refs[2],
output_width=320,
output_height=320,
size_mode=REFERENCE_SIZE_MATCH_OUTPUT,
)
assert assets is not None
height, width = assets.images[0].shape[1:3]
assert width * height <= 320 * 320
assert width % 32 == height % 32 == 0
assert width == 2 * height
@pytest.mark.parametrize("duration", (10, 15, 20, 30))
def test_approved_easy_fl2va_durations_do_not_enter_five_second_terminal_merge(
duration,
):
plan = resolve_easy_duration(duration)
enabled = _terminal_flf_merge_enabled(
multi_chunk_flf=plan.chunks >= 2,
chunks=plan.chunks,
chunk_seconds=plan.chunk_seconds,
prompt_hashes=["p"] * plan.chunks,
timeline_video_source=None,
)
assert enabled is False
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_easy_frontend_maps_only_randomize_fixed_and_hides_conditional_widgets(tmp_path):
node_executable = shutil.which("node")
if node_executable is None:
pytest.skip("Node.js is required for the frontend behavior regression")
source = EASY_JS.read_text(encoding="utf-8")
functions = "\n".join(
(
_function_source(source, "findWidget", "setWidgetVisible"),
_function_source(source, "setWidgetVisible", "attachRefresh"),
_function_source(source, "attachRefresh", "createProjectId"),
_function_source(source, "createProjectId", "seedControlWidget"),
_function_source(source, "seedControlWidget", "configureEasyNode"),
_function_source(source, "configureEasyNode", "configureEasyNodeAfterSetup"),
)
)
script = f"""
const EASY_NODE_CLASS = "H3ContinuumEasyV38";
const CUSTOM_PRESET = "Custom";
const STORAGE_ENABLED = "Save + Auto Resume";
{functions}
function widget(name, value) {{
return {{ name, value, type: "combo", options: {{}}, computeSize: () => [120, 20] }};
}}
const node = {{
comfyClass: EASY_NODE_CLASS,
widgets: [
widget("preset", "Draft — 0.30 MP"),
widget("custom_mp", 0.3),
widget("run_storage", "Off"),
widget("run_name", ""),
widget("seed_mode", "Randomize"),
widget("control_after_generate", "fixed"),
widget("project_id", "test-project"),
],
setDirtyCanvas() {{}},
}};
configureEasyNode(node);
const observed = {{
initialControl: findWidget(node, "control_after_generate").value,
controlHidden: findWidget(node, "control_after_generate").hidden,
customHidden: findWidget(node, "custom_mp").hidden,
runNameHidden: findWidget(node, "run_name").hidden,
projectHidden: findWidget(node, "project_id").hidden,
}};
findWidget(node, "seed_mode").value = "Fixed";
findWidget(node, "seed_mode").callback("Fixed");
findWidget(node, "preset").value = "Custom";
findWidget(node, "preset").callback("Custom");
findWidget(node, "run_storage").value = "Save + Auto Resume";
findWidget(node, "run_storage").callback("Save + Auto Resume");
observed.fixedControl = findWidget(node, "control_after_generate").value;
observed.customVisible = !findWidget(node, "custom_mp").hidden;
observed.runNameVisible = !findWidget(node, "run_name").hidden;
console.log(JSON.stringify(observed));
"""
script_path = tmp_path / "easy-v38-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 == {
"initialControl": "randomize",
"controlHidden": True,
"customHidden": True,
"runNameHidden": True,
"projectHidden": True,
"fixedControl": "fixed",
"customVisible": True,
"runNameVisible": True,
}
+214
View File
@@ -0,0 +1,214 @@
from __future__ import annotations
import json
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
WORKFLOW_PATH = (
ROOT / "examples" / "workflows" / "MiniMax_H3_Continuum_Easy_V38.json"
)
def _workflow() -> dict:
return json.loads(WORKFLOW_PATH.read_text(encoding="utf-8"))
def _one_node(workflow: dict, node_type: str) -> dict:
values = [node for node in workflow["nodes"] if node["type"] == node_type]
assert len(values) == 1
return values[0]
def _link_map(workflow: dict) -> dict[int, list]:
return {int(link[0]): link for link in workflow["links"]}
FORBIDDEN_MINIMAL_MARKERS = (
"power lora loader",
"rgthree",
"easy cleangpuused",
"spectrum",
"hires",
"hi-res",
"second pass",
"secondpass",
"upscale",
"minimaxchunkfeedforward",
"sageattention",
)
def test_v38_easy_public_workflow_uses_the_approved_default_contract():
workflow = _workflow()
easy = _one_node(workflow, "H3ContinuumEasyV38")
helper = _one_node(workflow, "H3ContinuumEasyReferences")
assert easy["widgets_values"][:10] == [
"",
10,
0,
"randomize",
"Randomize",
"Auto from First Image",
"Draft — 0.30 MP",
0.3,
"Off",
"",
]
easy_widget_names = [
"prompt_text",
"duration",
"seed",
"control_after_generate",
"seed_mode",
"aspect",
"preset",
"custom_mp",
"run_storage",
"run_name",
"project_id",
]
assert easy["widgets_values"] == [
easy["widgets_values_named"][name] for name in easy_widget_names
]
assert [item["name"] for item in easy["inputs"]] == [
"model",
"clip",
"video_vae",
"sampler",
"sigmas",
"first_frame",
"last_frame",
"references",
"driving_audio",
"audio_vae",
"prompt_text",
]
assert helper["outputs"][0]["type"] == "H3_CONTINUUM_EASY_REFERENCES"
assert [item["name"] for item in helper["inputs"]] == [
"reference_image_1",
"reference_image_2",
"reference_image_3",
]
assert not {
"reference_audio_1",
"reference_video_1",
"timeline_video",
"guide",
} & {item["name"] for item in easy["inputs"]}
assert len(workflow["nodes"]) == 20
assert len([node for node in workflow["nodes"] if node["type"] == "H3EasyLoadImage"]) == 5
audio_loader = _one_node(workflow, "H3EasyLoadAudio")
assert int(audio_loader["mode"]) == 4
assert audio_loader.get("title", "") == ""
assert [output["type"] for output in audio_loader["outputs"]] == ["AUDIO"]
assert not [node for node in workflow["nodes"] if node["type"] == "LoadImage"]
assert workflow["extra"] == {
"frontendVersion": "1.49.6",
"ds": workflow["extra"]["ds"],
}
def test_v38_easy_public_workflow_is_strict_minimal():
workflow = _workflow()
node_types = [str(node["type"]) for node in workflow["nodes"]]
searchable = "\n".join(node_types).lower()
assert not [marker for marker in FORBIDDEN_MINIMAL_MARKERS if marker in searchable]
assert not [
node
for node in workflow["nodes"]
if node.get("properties", {}).get("cnr_id")
not in {None, "", "comfy-core"}
]
assert "PreviewAny" not in node_types
assert "MarkdownNote" not in node_types
scheduler = _one_node(workflow, "BasicScheduler")
assert scheduler["widgets_values_named"] == {
"scheduler": "simple",
"steps": 20,
"denoise": 1,
}
def test_v38_easy_public_workflow_defaults_to_t2va_with_optional_hybrids():
workflow = _workflow()
nodes = {int(node["id"]): node for node in workflow["nodes"]}
links = _link_map(workflow)
easy = _one_node(workflow, "H3ContinuumEasyV38")
helper = _one_node(workflow, "H3ContinuumEasyReferences")
helper_inputs = {item["name"]: item for item in helper["inputs"]}
source_modes = {}
for name, input_ in helper_inputs.items():
link = links[int(input_["link"])]
source_modes[name] = int(nodes[int(link[1])]["mode"])
assert source_modes == {
"reference_image_1": 4,
"reference_image_2": 4,
"reference_image_3": 4,
}
easy_inputs = {item["name"]: item for item in easy["inputs"]}
first_source = nodes[int(links[int(easy_inputs["first_frame"]["link"])][1])]
last_source = nodes[int(links[int(easy_inputs["last_frame"]["link"])][1])]
assert int(first_source["mode"]) == 4
assert int(last_source["mode"]) == 4
assert links[int(easy_inputs["references"]["link"])][1] == helper["id"]
prompt_link = links[int(easy_inputs["prompt_text"]["link"])]
prompt_node = nodes[int(prompt_link[1])]
assert "<Picture" not in prompt_node["widgets_values"][0]
def test_v38_easy_public_workflow_keeps_core_display_titles_standard():
workflow = _workflow()
core_nodes = [
node
for node in workflow["nodes"]
if node.get("properties", {}).get("cnr_id") == "comfy-core"
]
assert core_nodes
assert all(not node.get("title") for node in core_nodes)
def test_v38_easy_public_workflow_links_are_closed_and_unique():
workflow = _workflow()
nodes = {int(node["id"]) for node in workflow["nodes"]}
links = _link_map(workflow)
assert len(links) == len(workflow["links"])
for link_id, link in links.items():
assert int(link[0]) == link_id
assert int(link[1]) in nodes
assert int(link[3]) in nodes
for node in workflow["nodes"]:
for input_ in node.get("inputs", []):
if input_.get("link") is not None:
assert int(input_["link"]) in links
for output in node.get("outputs", []):
for link_id in output.get("links") or []:
assert int(link_id) in links
assert json.loads(json.dumps(workflow, ensure_ascii=False)) == workflow
assert len({int(node["id"]) for node in workflow["nodes"]}) == len(
workflow["nodes"]
)
def test_easy_image_loaders_use_native_modes_without_custom_titles():
workflow = _workflow()
loaders = {
int(node["id"]): node
for node in workflow["nodes"]
if node["type"] == "H3EasyLoadImage"
}
assert {node_id: int(node["mode"]) for node_id, node in loaders.items()} == {
114: 4,
290: 4,
258: 4,
257: 4,
264: 4,
}
for node in loaders.values():
assert node.get("title", "") == ""
assert node["properties"] == {"Node name for S&R": "H3EasyLoadImage"}
assert [output["type"] for output in node["outputs"]] == ["IMAGE", "MASK"]
+181
View File
@@ -0,0 +1,181 @@
import json
from pathlib import Path
import shutil
import subprocess
import pytest
from ComfyUI_H3_Continuum_Join.v3.driving_nodes import H3ContinuumSamplerV38
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_v38_public_sampler_inputs_all_have_hover_help():
schema = H3ContinuumSamplerV38.INPUT_TYPES()
missing = []
for group in ("required", "optional"):
for name, definition in schema[group].items():
metadata = definition[1] if len(definition) > 1 else {}
if not str(metadata.get("tooltip", "")).strip():
missing.append(f"{group}.{name}")
assert missing == []
def test_v38_main_facade_help_covers_every_visible_control():
source = PROJECT_ID_JS.read_text(encoding="utf-8")
facade_names = (
"FACADE_PROMPT_FORMAT_WIDGET",
"FACADE_CONTINUITY_WIDGET",
"FACADE_BASE_SEED_WIDGET",
"FACADE_CONTROL_AFTER_WIDGET",
"FACADE_AUDIO_CONTINUITY_WIDGET",
"FACADE_CHUNKS_WIDGET",
"FACADE_SECONDS_WIDGET",
"FACADE_TOTAL_LENGTH_WIDGET",
"FACADE_GENERATE_WIDGET",
"FACADE_SIZE_SOURCE_WIDGET",
"FACADE_RESOLUTION_WIDGET",
"FACADE_CUSTOM_MP_WIDGET",
"FACADE_WIDTH_WIDGET",
"FACADE_HEIGHT_WIDGET",
"FACADE_SAVE_WIDGET",
"FACADE_READY_WIDGET",
"FACADE_REFERENCE_SIZE_WIDGET",
"FACADE_VIDEO_SIZE_WIDGET",
"FACADE_ADVANCED_WIDGET",
)
for name in facade_names:
assert f"[{name}]" in source
assert "function setWidgetTooltip(widget, tooltip)" in source
assert "widget.tooltip = tooltip;" in source
assert "widget.options.tooltip = tooltip;" in source
assert "function facadeWidgetTooltip(node, name)" in source
assert "function applyV38WidgetHelp(node)" in source
assert "applyV38WidgetHelp(node);" in source
def test_v38_size_help_explains_t2va_i2va_and_resolution_choices():
source = PROJECT_ID_JS.read_text(encoding="utf-8")
for marker in (
"Use this for T2VA",
"Use this for I2VA or FL2VA",
"Draft — 0.30 MP",
"Balanced — 0.60 MP",
"Native 768",
"Efficient - 0.4 MP",
"Match Output",
"Review Each Chunk",
"Render History",
):
assert marker in source
def test_v38_hover_help_is_attached_and_updates_with_current_selection(tmp_path):
node_executable = shutil.which("node")
if node_executable is None:
pytest.skip("Node.js is required for the frontend tooltip regression")
source = PROJECT_ID_JS.read_text(encoding="utf-8")
constants = source[
source.index("const PROJECT_WIDGET") : source.index("const V38_VIEW_PROPERTY")
]
functions = "\n".join(
(
_function_source(source, "findWidget", "setWidgetVisible"),
_function_source(source, "linkedInput", "attachRefresh"),
_function_source(
source, "facadeProductionWidgets", "addFacadeWidget"
),
_function_source(source, "setWidgetTooltip", "facadeWidgetTooltip"),
_function_source(source, "facadeWidgetTooltip", "applyV38WidgetHelp"),
_function_source(
source, "applyV38WidgetHelp", "installCompactNumberDisplay"
),
)
)
script = f"""
{constants}
{functions}
const facadeNames = [
FACADE_PROMPT_FORMAT_WIDGET, FACADE_CONTINUITY_WIDGET, FACADE_BASE_SEED_WIDGET,
FACADE_CONTROL_AFTER_WIDGET, FACADE_AUDIO_CONTINUITY_WIDGET,
FACADE_CHUNKS_WIDGET, FACADE_SECONDS_WIDGET, FACADE_TOTAL_LENGTH_WIDGET,
FACADE_SIZE_SOURCE_WIDGET, FACADE_RESOLUTION_WIDGET, FACADE_CUSTOM_MP_WIDGET,
FACADE_WIDTH_WIDGET, FACADE_HEIGHT_WIDGET, FACADE_SAVE_WIDGET,
FACADE_GENERATE_WIDGET, FACADE_READY_WIDGET, FACADE_REFERENCE_SIZE_WIDGET,
FACADE_VIDEO_SIZE_WIDGET, FACADE_ADVANCED_WIDGET,
];
const sourceValues = {{
[GENERATION_MODE_WIDGET]: GENERATION_MODE_REVIEW,
[SIZE_SOURCE_WIDGET]: SIZE_SOURCE_FIRST_IMAGE,
[RESOLUTION_PRESET_WIDGET]: RESOLUTION_PRESET_DRAFT,
[RUN_STORAGE_WIDGET]: "Save + Auto Resume",
[REFERENCE_SIZE_WIDGET]: "Match Output",
[VIDEO_REFERENCE_SIZE_WIDGET]: "Efficient - 0.4 MP",
}};
const node = {{
widgets: [],
inputs: [{{ name: "first_frame", link: 1 }}],
}};
for (const [name, value] of Object.entries(sourceValues)) {{
node.widgets.push({{ name, value, options: {{}} }});
}}
for (const name of Object.keys(ADVANCED_WIDGET_HELP)) {{
if (!node.widgets.some((widget) => widget.name === name)) {{
node.widgets.push({{ name, value: null, options: {{}} }});
}}
}}
for (const name of facadeNames) {{
node.widgets.push({{ name, value: null, options: {{}}, [FACADE_TRANSIENT_WIDGET]: true }});
}}
applyV38WidgetHelp(node);
const firstImageHelp = findWidget(node, FACADE_SIZE_SOURCE_WIDGET).tooltip;
const firstPass = {{
missingFacade: facadeProductionWidgets(node).filter((widget) => !widget.tooltip).map((widget) => widget.name),
missingFacadeOptions: facadeProductionWidgets(node).filter((widget) => !widget.options.tooltip).map((widget) => widget.name),
missingAdvanced: Object.keys(ADVANCED_WIDGET_HELP).filter((name) => !findWidget(node, name)?.tooltip),
firstImageHelp,
reviewHelp: findWidget(node, FACADE_GENERATE_WIDGET).tooltip,
}};
findWidget(node, SIZE_SOURCE_WIDGET).value = SIZE_SOURCE_MANUAL;
findWidget(node, RESOLUTION_PRESET_WIDGET).value = RESOLUTION_PRESET_NATIVE;
findWidget(node, RUN_STORAGE_WIDGET).value = "Off";
applyV38WidgetHelp(node);
console.log(JSON.stringify({{
firstPass,
manualHelp: findWidget(node, FACADE_SIZE_SOURCE_WIDGET).tooltip,
nativeHelp: findWidget(node, FACADE_RESOLUTION_WIDGET).tooltip,
storageOffHelp: findWidget(node, FACADE_SAVE_WIDGET).tooltip,
}}));
"""
script_path = tmp_path / "v38-hover-help.mjs"
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["firstPass"]["missingFacade"] == []
assert observed["firstPass"]["missingFacadeOptions"] == []
assert observed["firstPass"]["missingAdvanced"] == []
assert "I2VA or FL2VA" in observed["firstPass"]["firstImageHelp"]
assert "Review Each Chunk" in observed["firstPass"]["reviewHelp"]
assert "Set Chunks to 2 or more" in observed["firstPass"]["reviewHelp"]
assert "T2VA" in observed["manualHelp"]
assert "Native 768" in observed["nativeHelp"]
assert "does not keep resumable chunk history" in observed["storageOffHelp"]
+261
View File
@@ -0,0 +1,261 @@
from __future__ import annotations
import ast
from pathlib import Path
import torch
from ComfyUI_H3_Continuum_Join import nodes as root_nodes
from ComfyUI_H3_Continuum_Join.reference import (
REFERENCE_SIZE_MATCH_OUTPUT,
REFERENCE_SIZE_MAX_IDENTITY,
combine_hybrid_visual_identity,
prepare_reference_assets,
)
from ComfyUI_H3_Continuum_Join.reference_video import (
REFERENCE_VIDEO_SIZE_BALANCED,
REFERENCE_VIDEO_SIZE_EFFICIENT,
REFERENCE_VIDEO_SIZE_MATCH_OUTPUT,
)
from ComfyUI_H3_Continuum_Join.v3.driving_nodes import (
H3ContinuumMemoryActionPolicyExperimental,
H3ContinuumSamplerV38,
H3ContinuumSamplerV38MemoryPolicyExperimental,
NODE_CLASS_MAPPINGS,
NODE_DISPLAY_NAME_MAPPINGS,
)
from ComfyUI_H3_Continuum_Join.v3.memory_action_policy import (
ACTION_DISABLED,
ACTION_REDUCE_REFERENCES_ONE_STEP,
MEMORY_ACTION_POLICY_VERSION,
format_memory_action_status,
make_memory_action_policy,
resolve_memory_action_policy,
)
ROOT = Path(__file__).resolve().parents[1]
def _resolve(policy, *, image=True, video=True, image_mode=None, video_mode=None):
return resolve_memory_action_policy(
policy,
image_mode=image_mode or REFERENCE_SIZE_MAX_IDENTITY,
video_mode=video_mode or REFERENCE_VIDEO_SIZE_MATCH_OUTPUT,
has_reference_images=image,
has_video_guide=video,
)
def test_policy_contract_is_versioned_deterministic_and_tamper_evident():
first = make_memory_action_policy(ACTION_REDUCE_REFERENCES_ONE_STEP)
second = make_memory_action_policy(ACTION_REDUCE_REFERENCES_ONE_STEP)
assert first == second
assert first["memory_action_policy_version"] == MEMORY_ACTION_POLICY_VERSION
assert len(first["contract_hash"]) == 64
assert first["auto_unload"] == "advisory_only"
assert first["backend_switch"] == "advisory_only"
assert first["same_run_actual_row_trigger"] is False
modified = dict(first, action="unsupported")
decision = _resolve(modified)
assert decision.enabled is False
assert decision.warning is not None
assert decision.effective_image_mode == REFERENCE_SIZE_MAX_IDENTITY
assert decision.effective_video_mode == REFERENCE_VIDEO_SIZE_MATCH_OUTPUT
def test_disabled_and_disconnected_are_complete_resolver_noops():
disconnected = _resolve(None)
disabled = _resolve(make_memory_action_policy(ACTION_DISABLED))
for decision in (disconnected, disabled):
assert decision.enabled is False
assert decision.applied is False
assert decision.effective_image_mode == REFERENCE_SIZE_MAX_IDENTITY
assert decision.effective_video_mode == REFERENCE_VIDEO_SIZE_MATCH_OUTPUT
assert format_memory_action_status(decision) is None
def test_one_step_reference_resolver_uses_only_existing_presets():
policy = make_memory_action_policy(ACTION_REDUCE_REFERENCES_ONE_STEP)
first = _resolve(policy)
assert first.effective_image_mode == REFERENCE_SIZE_MATCH_OUTPUT
assert first.effective_video_mode == REFERENCE_VIDEO_SIZE_BALANCED
assert first.image_applied is True
assert first.video_applied is True
second = _resolve(
policy,
image_mode=REFERENCE_SIZE_MATCH_OUTPUT,
video_mode=REFERENCE_VIDEO_SIZE_BALANCED,
)
assert second.effective_image_mode == REFERENCE_SIZE_MATCH_OUTPUT
assert second.effective_video_mode == REFERENCE_VIDEO_SIZE_EFFICIENT
assert second.image_applied is False
assert second.video_applied is True
minimum = _resolve(
policy,
image_mode=REFERENCE_SIZE_MATCH_OUTPUT,
video_mode=REFERENCE_VIDEO_SIZE_EFFICIENT,
)
assert minimum.applied is False
def test_one_step_policy_changes_only_connected_reference_kinds():
policy = make_memory_action_policy(ACTION_REDUCE_REFERENCES_ONE_STEP)
image_only = _resolve(policy, video=False)
assert image_only.image_applied is True
assert image_only.video_applied is False
assert image_only.effective_video_mode == REFERENCE_VIDEO_SIZE_MATCH_OUTPUT
video_only = _resolve(policy, image=False)
assert video_only.image_applied is False
assert video_only.video_applied is True
assert video_only.effective_image_mode == REFERENCE_SIZE_MAX_IDENTITY
def test_effective_reference_contract_changes_existing_run_storage_identity():
image = torch.zeros((1, 32, 32, 3), dtype=torch.float32)
original = prepare_reference_assets(
reference_image_1=image,
reference_image_2=None,
output_width=32,
output_height=32,
size_mode=REFERENCE_SIZE_MAX_IDENTITY,
)
downgraded = prepare_reference_assets(
reference_image_1=image,
reference_image_2=None,
output_width=32,
output_height=32,
size_mode=REFERENCE_SIZE_MATCH_OUTPUT,
)
assert original is not None and downgraded is not None
assert original.contract["size_mode"] == REFERENCE_SIZE_MAX_IDENTITY
assert downgraded.contract["size_mode"] == REFERENCE_SIZE_MATCH_OUTPUT
assert original.combined_hash != downgraded.combined_hash
base = "a" * 64
assert combine_hybrid_visual_identity(
keyframe_identity_hash=base,
reference_assets=original,
has_first=False,
has_last=False,
) != combine_hybrid_visual_identity(
keyframe_identity_hash=base,
reference_assets=downgraded,
has_first=False,
has_last=False,
)
def test_existing_v38_schema_is_unchanged_and_experimental_input_is_additive():
production = H3ContinuumSamplerV38.INPUT_TYPES()
experimental = H3ContinuumSamplerV38MemoryPolicyExperimental.INPUT_TYPES()
assert "memory_action_policy" not in production.get("required", {})
assert "memory_action_policy" not in production.get("optional", {})
assert production["required"] == experimental["required"]
expected_optional = dict(production.get("optional", {}))
actual_optional = dict(experimental.get("optional", {}))
policy_input = actual_optional.pop("memory_action_policy")
assert actual_optional == expected_optional
assert policy_input[0] == "H3_CONTINUUM_MEMORY_ACTION_POLICY"
def test_nodes_are_additively_registered_under_advanced_category():
policy_id = "H3ContinuumMemoryActionPolicyExperimental"
sampler_id = "H3ContinuumSamplerV38MemoryPolicyExperimental"
assert NODE_CLASS_MAPPINGS[policy_id] is H3ContinuumMemoryActionPolicyExperimental
assert NODE_CLASS_MAPPINGS[sampler_id] is (
H3ContinuumSamplerV38MemoryPolicyExperimental
)
assert policy_id not in root_nodes.NODE_CLASS_MAPPINGS
assert sampler_id not in root_nodes.NODE_CLASS_MAPPINGS
assert NODE_DISPLAY_NAME_MAPPINGS[policy_id].endswith("(Experimental)")
assert NODE_DISPLAY_NAME_MAPPINGS[sampler_id].endswith("(Experimental)")
assert H3ContinuumMemoryActionPolicyExperimental.CATEGORY.endswith("/Advanced")
assert H3ContinuumSamplerV38MemoryPolicyExperimental.CATEGORY.endswith(
"/Advanced"
)
def test_experimental_disabled_delegates_exact_kwargs_and_output(monkeypatch):
captured = []
sentinel = object()
def fake_run(self, **kwargs):
captured.append(kwargs)
return sentinel
monkeypatch.setattr(H3ContinuumSamplerV38, "run", fake_run)
node = H3ContinuumSamplerV38MemoryPolicyExperimental()
kwargs = {
"reference_size": REFERENCE_SIZE_MAX_IDENTITY,
"video_reference_size": REFERENCE_VIDEO_SIZE_MATCH_OUTPUT,
"reference_image_1": object(),
"reference_video_1": object(),
"base_seed": 123,
"sigmas": object(),
}
assert node.run(**kwargs) is sentinel
assert captured[-1] == kwargs
assert node.run(
memory_action_policy=make_memory_action_policy(ACTION_DISABLED),
**kwargs,
) is sentinel
assert captured[-1] == kwargs
def test_experimental_active_changes_only_effective_reference_modes(monkeypatch):
captured = {}
video = object()
audio = object()
plan = {"groups": [[1]]}
def fake_run(self, **kwargs):
captured.update(kwargs)
return (video, audio, plan, "Production status", "driving")
monkeypatch.setattr(H3ContinuumSamplerV38, "run", fake_run)
seed = 42
sigmas = object()
result = H3ContinuumSamplerV38MemoryPolicyExperimental().run(
memory_action_policy=make_memory_action_policy(
ACTION_REDUCE_REFERENCES_ONE_STEP
),
reference_size=REFERENCE_SIZE_MAX_IDENTITY,
video_reference_size=REFERENCE_VIDEO_SIZE_BALANCED,
reference_image_1=object(),
reference_video_1=object(),
base_seed=seed,
sigmas=sigmas,
)
assert captured["reference_size"] == REFERENCE_SIZE_MATCH_OUTPUT
assert captured["video_reference_size"] == REFERENCE_VIDEO_SIZE_EFFICIENT
assert captured["base_seed"] == seed
assert captured["sigmas"] is sigmas
assert result[:3] == (video, audio, plan)
assert result[4] == "driving"
assert "automatic MODEL unload was not executed" in result[3]
assert "external MODEL wrapper was preserved" in result[3]
def test_policy_code_has_no_runtime_unload_or_backend_switch_calls():
called_names = set()
for path in (ROOT / "v3" / "memory_action_policy.py", ROOT / "v3" / "driving_nodes.py"):
tree = ast.parse(path.read_text(encoding="utf-8"))
for node in ast.walk(tree):
if not isinstance(node, ast.Call):
continue
if isinstance(node.func, ast.Name):
called_names.add(node.func.id)
elif isinstance(node.func, ast.Attribute):
called_names.add(node.func.attr)
assert called_names.isdisjoint(
{
"unload_all_models",
"unload_model_and_clones",
"soft_empty_cache",
"optimized_attention_override",
}
)
+312
View File
@@ -0,0 +1,312 @@
from __future__ import annotations
from types import SimpleNamespace
import pytest
import torch
from ComfyUI_H3_Continuum_Join import nodes as root_nodes
from ComfyUI_H3_Continuum_Join.graph_contract import build_upstream_graph_contract
from ComfyUI_H3_Continuum_Join.reference import ReferenceAssets, encode_reference_prompt
from ComfyUI_H3_Continuum_Join.reference_audio import (
H3ContinuumReferenceAudios,
REFERENCE_AUDIOS_TYPE,
ReferenceAudioError,
combine_reference_audio_identity,
encode_reference_audio_input,
prepare_reference_audio_bundle,
prepare_reference_audio_source,
resolve_reference_audio_input,
validate_reference_audio_prompts,
)
from ComfyUI_H3_Continuum_Join.v2.h3_builder import encode_prompt_conditioning
from ComfyUI_H3_Continuum_Join.v3.driving_nodes import (
H3ContinuumSamplerV37,
H3ContinuumSamplerV38,
)
def _audio(value: float) -> dict:
return {
"waveform": torch.full((1, 2, 320), value, dtype=torch.float32),
"sample_rate": 32000,
}
class _AudioVAE:
audio_sample_rate = 32000
def __init__(self):
self.inputs = []
def encode(self, waveform):
self.inputs.append(waveform.clone())
value = float(waveform.mean().item())
return torch.full((1, 32, 2, len(self.inputs)), value, dtype=torch.float32)
class _Clip:
def __init__(self):
self.options = None
def tokenize(self, prompt, **kwargs):
self.options = kwargs
return prompt
def encode_from_tokens_scheduled(self, tokens):
return [[torch.zeros((1, 1, 2)), {}]]
def test_public_helper_and_v38_socket_are_the_only_surface_additions():
helper_id = "H3ContinuumReferenceAudios"
helper_schema = H3ContinuumReferenceAudios.INPUT_TYPES()
v37 = H3ContinuumSamplerV37.INPUT_TYPES()
v38 = H3ContinuumSamplerV38.INPUT_TYPES()
assert root_nodes.NODE_CLASS_MAPPINGS[helper_id] is H3ContinuumReferenceAudios
assert root_nodes.NODE_DISPLAY_NAME_MAPPINGS[helper_id] == (
"H3 Continuum Reference Audios"
)
assert tuple(helper_schema) == ("optional",)
assert tuple(helper_schema["optional"]) == (
"reference_audio_1",
"reference_audio_2",
"reference_audio_3",
"reference_audio_vae",
)
assert H3ContinuumReferenceAudios.RETURN_TYPES == (REFERENCE_AUDIOS_TYPE,)
assert "audio_references" not in v37["optional"]
assert list(v38["optional"])[:-1] == list(v37["optional"])
assert v38["optional"]["audio_references"][0] == REFERENCE_AUDIOS_TYPE
def test_helper_preserves_order_and_requires_contiguous_core_numbering():
vae = _AudioVAE()
bundle = H3ContinuumReferenceAudios().pack(
_audio(0.1), _audio(0.2), _audio(0.3), vae
)[0]
assert bundle.count == 3
assert bundle.reference_audio_vae is vae
assert [item.source_sha256 for item in bundle.sources] == [
item["reference_audio"]["source_sha256"]
for item in bundle.contract["items"]
]
assert [item["audio_index"] for item in bundle.contract["items"]] == [1, 2, 3]
with pytest.raises(ReferenceAudioError, match="without gaps"):
prepare_reference_audio_bundle(_audio(0.1), None, _audio(0.3), vae)
assert prepare_reference_audio_bundle(None, None, None, vae) is None
def test_bundle_order_changes_run_identity_and_legacy_identity_stays_v1():
vae = _AudioVAE()
first = prepare_reference_audio_bundle(_audio(0.1), _audio(0.2), None, vae)
swapped = prepare_reference_audio_bundle(_audio(0.2), _audio(0.1), None, vae)
assert first is not None and swapped is not None
first_identity = combine_reference_audio_identity("visual", first)
swapped_identity = combine_reference_audio_identity("visual", swapped)
assert first_identity != swapped_identity
assert first.contract != swapped.contract
legacy = SimpleNamespace(combined_hash="audio")
assert combine_reference_audio_identity("visual", legacy) == (
"59fa60ba2a9a19525222c867aa2c2b8350dbf6af1e24ad34056317bcd40c81cb"
)
def test_legacy_and_bundle_inputs_cannot_be_mixed():
vae = _AudioVAE()
bundle = prepare_reference_audio_bundle(_audio(0.1), _audio(0.2), None, vae)
with pytest.raises(ReferenceAudioError, match="not both"):
resolve_reference_audio_input(_audio(0.1), vae, bundle)
resolved, resolved_vae = resolve_reference_audio_input(None, object(), bundle)
assert resolved is bundle
assert resolved_vae is vae
def test_each_reference_is_encoded_independently_in_order():
vae = _AudioVAE()
bundle = prepare_reference_audio_bundle(_audio(0.1), _audio(0.2), _audio(0.3), vae)
assert bundle is not None
assets = encode_reference_audio_input(vae, bundle, cache_enabled=False)
assert isinstance(assets, tuple)
assert len(assets) == 3
assert len(vae.inputs) == 3
assert [round(float(item.audio_latent.mean().item()), 3) for item in assets] == [
0.1,
0.2,
0.3,
]
def test_three_assets_follow_core_tokenizer_and_packed_ref_order():
latents = tuple(
SimpleNamespace(audio_latent=torch.full((1, 32, 2, index), float(index)))
for index in (1, 2, 3)
)
clip = _Clip()
conditioning = encode_prompt_conditioning(
clip,
"<Audio 1> woman; <Audio 2> man; <Audio 3> ambience.",
first_image=None,
last_image=None,
reference_audio_assets=latents,
)
assert [item["type"] for item in clip.options["minimax_ref_items"]] == [
"audio",
"audio",
"audio",
]
refs = conditioning[0][1]["minimax_refs"]
assert [item["kind"] for item in refs] == ["audio", "audio", "audio"]
assert [item["ref_audio_t"] for item in refs] == [1, 2, 3]
assert [float(item["audio_latent"].mean().item()) for item in refs] == [1.0, 2.0, 3.0]
def test_reference_images_and_three_audio_assets_share_ordered_core_payloads():
image = torch.full((1, 32, 32, 3), 0.5, dtype=torch.float32)
image_assets = ReferenceAssets(
images=(image,),
latents=(torch.zeros((1, 24, 2, 2, 2)),),
image_hashes=("reference-image",),
combined_hash="reference-images",
size_mode="Match Output",
)
audio_assets = tuple(
SimpleNamespace(audio_latent=torch.full((1, 32, 2, index), float(index)))
for index in (1, 2, 3)
)
clip = _Clip()
conditioning = encode_reference_prompt(
clip,
"<Picture 1> with <Audio 1>, <Audio 2>, and <Audio 3>.",
image_assets,
reference_audio_assets=audio_assets,
)
assert [item["type"] for item in clip.options["minimax_ref_items"]] == [
"image",
"audio",
"audio",
"audio",
]
refs = conditioning[0][1]["minimax_refs"]
assert [item["kind"] for item in refs] == ["image", "audio", "audio", "audio"]
assert [item["ref_audio_t"] for item in refs[1:]] == [1, 2, 3]
def test_one_item_helper_conditioning_matches_legacy_single_item():
latent = torch.arange(64, dtype=torch.float32).reshape(1, 32, 2, 1)
asset = SimpleNamespace(audio_latent=latent)
legacy_clip = _Clip()
helper_clip = _Clip()
legacy = encode_prompt_conditioning(
legacy_clip,
"Use <Audio 1>.",
first_image=None,
last_image=None,
reference_audio_assets=asset,
)
helper = encode_prompt_conditioning(
helper_clip,
"Use <Audio 1>.",
first_image=None,
last_image=None,
reference_audio_assets=(asset,),
)
assert legacy_clip.options == helper_clip.options
assert legacy[0][1].keys() == helper[0][1].keys()
assert legacy[0][1]["minimax_refs"][0]["ref_audio_t"] == 1
assert torch.equal(
legacy[0][1]["minimax_refs"][0]["audio_latent"],
helper[0][1]["minimax_refs"][0]["audio_latent"],
)
def test_prompt_warnings_follow_connected_audio_count():
vae = _AudioVAE()
bundle = prepare_reference_audio_bundle(_audio(0.1), _audio(0.2), None, vae)
assert bundle is not None
warning = validate_reference_audio_prompts(
["<Audio 1> speaks while <Audio 3> answers."], bundle
)
assert "unavailable <Audio 3>" in warning
assert "no <Audio 2> tag" in warning
assert "no <Audio 1> tag" not in warning
def test_run_storage_graph_contract_fingerprints_helper_vae_and_sources():
prompt = {
"sampler": {
"class_type": "H3ContinuumSamplerV38",
"inputs": {
"model": ["model", 0],
"clip": ["clip", 0],
"audio_references": ["refs", 0],
},
},
"model": {"class_type": "UNETLoader", "inputs": {"name": "model.safetensors"}},
"clip": {"class_type": "CLIPLoader", "inputs": {"name": "text.safetensors"}},
"refs": {
"class_type": "H3ContinuumReferenceAudios",
"inputs": {
"reference_audio_1": ["audio1", 0],
"reference_audio_2": ["audio2", 0],
"reference_audio_vae": ["vae", 0],
},
},
"audio1": {"class_type": "LoadAudio", "inputs": {"audio": "one.wav"}},
"audio2": {"class_type": "LoadAudio", "inputs": {"audio": "two.wav"}},
"vae": {"class_type": "VAELoader", "inputs": {"vae_name": "audio.safetensors"}},
}
contract, safe, reasons = build_upstream_graph_contract(
prompt,
"sampler",
require_video_vae=False,
require_reference_audio_vae=True,
)
assert safe, reasons
route = contract["routes"]["reference_audio_vae"]
assert route["node"]["class_type"] == "H3ContinuumReferenceAudios"
assert route["node"]["inputs"]["reference_audio_vae"]["node"]["class_type"] == (
"VAELoader"
)
assert route["node"]["inputs"]["reference_audio_2"]["node"]["inputs"]["audio"] == (
"two.wav"
)
def test_v38_facade_forwards_bundle_socket_without_touching_v37(monkeypatch):
captured = {}
def fake_v37_run(_self, **kwargs):
captured.update(kwargs)
return "ok"
monkeypatch.setattr(H3ContinuumSamplerV37, "run", fake_v37_run)
marker = object()
result = H3ContinuumSamplerV38().run(audio_references=marker)
assert result == "ok"
assert captured["audio_references"] is marker
def test_legacy_source_preparation_remains_available_unchanged():
vae = _AudioVAE()
source = prepare_reference_audio_source(_audio(0.25), vae)
assert source is not None
assert source.contract["reference_audio_contract_version"] == 1
assert "reference_audio_bundle_contract_version" not in source.contract
+248
View File
@@ -0,0 +1,248 @@
from __future__ import annotations
import ast
import copy
from pathlib import Path
import pytest
import torch
from ComfyUI_H3_Continuum_Join.v3.driving_nodes import (
H3ContinuumAssembleSeamV35,
)
from ComfyUI_H3_Continuum_Join.v3.plan import _attach_second_pass_contract
from ComfyUI_H3_Continuum_Join.v3.second_pass import (
SecondPassContractError,
passthrough_audio_latents,
update_second_pass_geometry,
validate_second_pass_inputs,
)
from ComfyUI_H3_Continuum_Join.v3.second_pass_nodes import (
H3ContinuumSecondPassV35,
)
def _entry(t: int, audio_t: int, *, prompt: str) -> dict:
return {
"video": torch.zeros((1, 24, t, 40, 40)),
"audio": torch.zeros((1, 8, audio_t)),
"prompt": prompt,
}
def _terminal_fixture():
logical = [
_entry(31, 100, prompt="first"),
_entry(35, 110, prompt="middle"),
_entry(35, 110, prompt="last"),
]
physical = [logical[0], _entry(65, 220, prompt="terminal")]
plan = {
"width": 640,
"height": 640,
"chunks": [
{"total_frames": 124, "trim_frames": 0},
{"total_frames": 141, "trim_frames": 22},
{"total_frames": 141, "trim_frames": 22},
],
"decode_groups": [
{
"logical_chunk_indices": [1],
"terminal_merged": False,
"total_frames": 124,
"trim_frames": 0,
},
{
"logical_chunk_indices": [2, 3],
"terminal_merged": True,
"total_frames": 260,
"trim_frames": 22,
},
],
}
_attach_second_pass_contract(
plan,
logical_entries=logical,
physical_entries=physical,
chunk_seconds=5.0,
)
videos = [{"samples": entry["video"]} for entry in physical]
audios = [{"samples": entry["audio"]} for entry in physical]
return plan, videos, audios
def _external_spatial_processor(video_latents, *, target_h: int, target_w: int):
return [
{
**latent,
"samples": latent["samples"].new_zeros(
(*latent["samples"].shape[:3], target_h, target_w)
),
}
for latent in video_latents
]
def _without_target_geometry(plan: dict) -> dict:
normalized = copy.deepcopy(plan)
normalized.pop("width", None)
normalized.pop("height", None)
contract = normalized["second_pass_contract"]
contract.pop("target_width", None)
contract.pop("target_height", None)
for group in contract["physical_groups"]:
for key in (
"target_latent_h",
"target_latent_w",
"target_width",
"target_height",
):
group.pop(key, None)
return normalized
def test_external_processor_may_change_only_common_spatial_video_geometry():
plan, videos, audios = _terminal_fixture()
processed = _external_spatial_processor(videos, target_h=60, target_w=64)
result = validate_second_pass_inputs(processed, audios, plan)
assert result == {
"physical_group_count": 2,
"target_latent_h": 60,
"target_latent_w": 64,
"audio_passthrough": True,
}
terminal = plan["second_pass_contract"]["physical_groups"][1]
assert terminal["logical_chunks"] == [2, 3]
assert terminal["terminal_merged"] is True
@pytest.mark.parametrize(
("mutation", "message"),
(
(lambda values: values[:1], "group count"),
(
lambda values: [
{"samples": torch.zeros((24, 31, 40, 40))},
values[1],
],
r"shape \[B,C,T,H,W\]",
),
(
lambda values: [
values[0],
{"samples": torch.zeros((1, 24, 64, 40, 40))},
],
"temporal length",
),
(
lambda values: [
values[0],
{"samples": torch.zeros((1, 24, 65, 39, 40))},
],
"preserved or enlarged",
),
),
)
def test_external_processor_rejects_group_temporal_or_downscale_changes(
mutation,
message,
):
plan, videos, audios = _terminal_fixture()
with pytest.raises(SecondPassContractError, match=message):
validate_second_pass_inputs(mutation(videos), audios, plan)
@pytest.mark.parametrize(
("stream", "bad_value"),
(("video", float("nan")), ("audio", float("inf"))),
)
def test_external_processor_rejects_nonfinite_latents_before_sampling(
stream,
bad_value,
):
plan, videos, audios = _terminal_fixture()
target = videos if stream == "video" else audios
target[0]["samples"].view(-1)[0] = bad_value
with pytest.raises(SecondPassContractError, match="contains NaN or Inf"):
validate_second_pass_inputs(videos, audios, plan)
def test_external_processor_rejects_changed_audio_shape():
plan, videos, audios = _terminal_fixture()
audios[1] = {"samples": torch.zeros((1, 8, 219))}
with pytest.raises(SecondPassContractError, match="audio latent shape"):
validate_second_pass_inputs(videos, audios, plan)
def test_first_pass_audio_objects_and_input_plan_are_not_mutated():
plan, videos, audios = _terminal_fixture()
before = copy.deepcopy(plan)
processed = _external_spatial_processor(videos, target_h=60, target_w=60)
output_audio = passthrough_audio_latents(audios)
updated = update_second_pass_geometry(plan, processed)
assert plan == before
assert updated is not plan
assert all(left is right for left, right in zip(audios, output_audio, strict=True))
assert _without_target_geometry(updated) == _without_target_geometry(plan)
def test_public_second_pass_and_finalize_keep_existing_comfy_type_boundary():
second_pass = H3ContinuumSecondPassV35.INPUT_TYPES()
finalize = H3ContinuumAssembleSeamV35.INPUT_TYPES()
assert tuple(second_pass["required"]) == (
"model",
"clip",
"sampler",
"sigmas",
"video_latents",
"audio_latents",
"assembly_plan",
"refine_seed",
)
assert second_pass["required"]["video_latents"] == ("LATENT",)
assert second_pass["required"]["audio_latents"] == ("LATENT",)
assert tuple(second_pass["optional"]) == ("refine_context", "video_vae")
assert finalize["required"]["images"] == ("IMAGE",)
assert finalize["required"]["audio"] == ("AUDIO",)
assert "video_vae" not in finalize["required"]
assert "audio_vae" not in finalize["required"]
def test_integration_modules_do_not_import_optional_accelerators_or_run_storage():
root = Path(__file__).resolve().parents[1]
forbidden_accelerators = {"sageattention", "sol_attn", "spectrum", "tensorrt"}
modules = (
root / "compatibility.py",
root / "model_patch.py",
root / "v3" / "second_pass.py",
)
for path in modules:
tree = ast.parse(path.read_text(encoding="utf-8"))
imports = set()
for node in ast.walk(tree):
if isinstance(node, ast.Import):
imports.update(
alias.name.split(".", 1)[0].lower() for alias in node.names
)
elif isinstance(node, ast.ImportFrom) and node.module:
imports.add(node.module.split(".", 1)[0].lower())
assert imports.isdisjoint(forbidden_accelerators)
second_pass_tree = ast.parse(
(root / "v3" / "second_pass.py").read_text(encoding="utf-8")
)
imported_names = set()
for node in ast.walk(second_pass_tree):
if isinstance(node, ast.Import):
imported_names.update(alias.name.lower() for alias in node.names)
elif isinstance(node, ast.ImportFrom) and node.module:
imported_names.add(node.module.lower())
assert not any("run_storage" in name for name in imported_names)
+206
View File
@@ -0,0 +1,206 @@
from __future__ import annotations
from pathlib import Path
from types import SimpleNamespace
import pytest
from ComfyUI_H3_Continuum_Join.model_patch import _wrapper_factory
from ComfyUI_H3_Continuum_Join.v3.packed_row_planner import (
MAX_CONCURRENT_PHYSICAL_GROUPS,
MemoryObservation,
PackedRowPlanner,
PackedRowPlanningError,
analyze_packed_layout,
planner_event_fail_soft,
)
ROOT = Path(__file__).resolve().parents[1]
def _layout(*segments):
return SimpleNamespace(seq_len=segments[-1][1], segments=list(segments))
def _baseline_layout(*, reference_rows=0, target_video_rows=20):
cursor = 0
segments = [(cursor, cursor + 4, "text")]
cursor += 4
if reference_rows:
segments.append((cursor, cursor + reference_rows, "ref_img"))
cursor += reference_rows
segments.append((cursor, cursor + 6, "audio"))
cursor += 6
segments.append((cursor, cursor + target_video_rows, "video"))
return _layout(*segments)
def _memory(value):
return MemoryObservation(
system_available_bytes=value,
cuda_allocated_bytes=value + 1,
cuda_reserved_bytes=value + 2,
core_visible_free_bytes=value + 3,
)
def test_actual_segment_accounting_uses_core_layout_partition():
layout = _layout(
(0, 5, "text"),
(5, 9, "cond"),
(9, 12, "ref_img"),
(12, 14, "cond_audio"),
(14, 18, "ref_audio"),
(18, 26, "audio"),
(26, 56, "video"),
)
result = analyze_packed_layout(layout)
assert result.seq_len == 56
assert result.text_rows == 5
assert result.condition_video_rows == 7
assert result.condition_audio_rows == 6
assert result.target_audio_rows == 8
assert result.target_video_rows == 30
assert result.condition_rows == 13
assert result.target_rows == 38
assert result.condition_to_target_ratio == pytest.approx(13 / 38)
assert sum(stop - start for start, stop, _ in result.segment_signature) == 56
@pytest.mark.parametrize(
"layout",
[
SimpleNamespace(seq_len=10, segments=[]),
_layout((0, 3, "text"), (4, 6, "audio"), (6, 10, "video")),
SimpleNamespace(
seq_len=11,
segments=[(0, 3, "text"), (3, 6, "audio"), (6, 10, "video")],
),
_layout((0, 3, "text"), (3, 6, "audio"), (6, 8, "video"), (8, 10, "video")),
],
)
def test_invalid_layout_accounting_is_diagnostic_error(layout):
with pytest.raises(PackedRowPlanningError):
analyze_packed_layout(layout)
def test_unknown_segment_is_counted_without_changing_core_layout():
layout = _layout(
(0, 2, "text"),
(2, 5, "future_core_segment"),
(5, 9, "audio"),
(9, 15, "video"),
)
before = tuple(layout.segments)
result = analyze_packed_layout(layout)
assert result.unknown_rows == 3
assert tuple(layout.segments) == before
def test_planner_keeps_fixed_order_terminal_atomicity_and_earliest_peak_tie():
planner = PackedRowPlanner(memory_reader=lambda: _memory(1024))
for group, logical, terminal, layout in (
(1, (1,), False, _baseline_layout(target_video_rows=20)),
(2, (2,), False, _baseline_layout(reference_rows=4, target_video_rows=24)),
(3, (3, 4), True, _baseline_layout(reference_rows=4, target_video_rows=24)),
):
planner.begin_group(
physical_group=group,
logical_chunks=logical,
terminal_atomic=terminal,
)
planner.observe_layout(layout)
planner.observe_layout(layout)
planner.finish_group()
lines = planner.report_lines()
assert MAX_CONCURRENT_PHYSICAL_GROUPS == 1
assert "execution_order=[1, 2, 3]" in lines[0]
assert "peak_candidate=2" in lines[0]
assert "VRAM/time prediction=not provided" in lines[0]
assert "physical_group=3" in lines[3]
assert "logical_chunks=[3, 4]" in lines[3]
assert "terminal_atomic=true" in lines[3]
def test_topology_change_within_group_becomes_unavailable_advisory():
planner = PackedRowPlanner(memory_reader=lambda: MemoryObservation())
planner.begin_group(physical_group=1, logical_chunks=(1,), terminal_atomic=False)
planner.observe_layout(_baseline_layout())
planner.observe_layout(_baseline_layout(reference_rows=2))
planner.finish_group()
lines = planner.report_lines()
assert "observed_groups=0/1" in lines[0]
assert "unavailable/advisory=PackedLayout topology changed" in lines[1]
def test_missing_layout_and_memory_counter_failure_are_fail_soft():
def unavailable_memory():
raise RuntimeError("counter unavailable")
planner = PackedRowPlanner(memory_reader=unavailable_memory)
planner.begin_group(physical_group=1, logical_chunks=(1,), terminal_atomic=False)
planner.observe_layout(None)
planner.finish_group()
lines = planner.report_lines()
assert "peak_candidate=unavailable" in lines[0]
assert "Core PackedLayout is unavailable" in lines[1]
def test_model_wrapper_observes_target_only_layout_before_normal_passthrough():
class Executor:
def __call__(self, *args, **kwargs):
return kwargs["minimax_payload"]
planner = PackedRowPlanner(memory_reader=lambda: MemoryObservation())
planner.begin_group(physical_group=1, logical_chunks=(1,), terminal_atomic=False)
payload = {"layout": _baseline_layout(), "seed": 7}
wrapper = _wrapper_factory(
strict=True,
debug=False,
packed_row_planner=planner,
)
result = wrapper(Executor(), object(), minimax_payload=payload)
planner.finish_group()
assert result is payload
assert result == {"layout": payload["layout"], "seed": 7}
assert planner.records[0]["breakdown"].seq_len == payload["layout"].seq_len
def test_lifecycle_helper_never_propagates_diagnostic_failure():
class BrokenPlanner:
def explode(self):
raise RuntimeError("diagnostic failure")
def note_observation_failure(self, exc):
raise RuntimeError("secondary diagnostic failure")
assert planner_event_fail_soft(BrokenPlanner(), "explode") is None
def test_a7a_source_has_no_execution_or_allocator_mutation_calls():
source = (ROOT / "v3" / "packed_row_planner.py").read_text(encoding="utf-8")
for forbidden in (
".synchronize(",
".empty_cache(",
".reset_peak_memory_stats(",
"unload_all_models(",
"pynvml",
):
assert forbidden not in source
def test_a7a_is_detailed_only_and_has_no_public_widget():
sequence = (ROOT / "v2" / "sequence.py").read_text(encoding="utf-8")
planner_creation = sequence.index("packed_row_planner=PackedRowPlanner()")
detailed_guard = sequence.rindex(
"if diagnostics_mode==DIAGNOSTICS_FULL:", 0, planner_creation
)
assert detailed_guard < planner_creation
public_nodes = (ROOT / "v3" / "nodes.py").read_text(encoding="utf-8")
selective_node = (ROOT / "v3" / "second_pass_nodes.py").read_text(
encoding="utf-8"
)
assert "Packed-row" not in public_nodes
assert "Packed-row" not in selective_node
+637
View File
@@ -0,0 +1,637 @@
from __future__ import annotations
import hashlib
import json
from pathlib import Path
import shutil
import subprocess
import pytest
from ComfyUI_H3_Continuum_Join import nodes as root_nodes
from ComfyUI_H3_Continuum_Join.v3 import driving_nodes
from ComfyUI_H3_Continuum_Join.v3 import easy_nodes
from ComfyUI_H3_Continuum_Join.v3 import second_pass_nodes
ROOT = Path(__file__).resolve().parents[1]
PUBLIC_DISPLAY_NAMES = {
"H3ContinuumSamplerV38": "H3 Continuum Sampler V3.8",
"H3ContinuumReferenceAudios": "H3 Continuum Reference Audios",
"H3ContinuumAssembleSeamV35": "H3 Continuum Finalize",
"H3EasyLoadImage": "H3 Continuum Load Image",
"H3EasyLoadAudio": "H3 Continuum Load Audio",
"H3ContinuumLoadVideo": "H3 Continuum Load Video",
"H3ContinuumSecondPassV35": "H3 Continuum Second Pass",
}
def test_public_export_is_exactly_the_seven_node_v38_allowlist():
assert set(root_nodes.NODE_CLASS_MAPPINGS) == set(PUBLIC_DISPLAY_NAMES)
assert root_nodes.NODE_DISPLAY_NAME_MAPPINGS == PUBLIC_DISPLAY_NAMES
def test_labs_and_unreleased_easy_implementations_remain_internal():
assert "H3ContinuumMemoryActionPolicyExperimental" in (
driving_nodes.NODE_CLASS_MAPPINGS
)
assert "H3ContinuumSamplerV38MemoryPolicyExperimental" in (
driving_nodes.NODE_CLASS_MAPPINGS
)
assert "H3ContinuumSelectiveSecondPassExperimental" in (
second_pass_nodes.NODE_CLASS_MAPPINGS
)
assert "H3ContinuumEasyReferences" in easy_nodes.NODE_CLASS_MAPPINGS
assert "H3ContinuumEasyV38" in easy_nodes.NODE_CLASS_MAPPINGS
assert not set(
(
"H3ContinuumMemoryActionPolicyExperimental",
"H3ContinuumSamplerV38MemoryPolicyExperimental",
"H3ContinuumSelectiveSecondPassExperimental",
"H3ContinuumEasyReferences",
"H3ContinuumEasyV38",
)
) & set(root_nodes.NODE_CLASS_MAPPINGS)
def test_v38_schema_and_serialized_widget_order_are_unchanged():
schema = driving_nodes.H3ContinuumSamplerV38.INPUT_TYPES()
assert list(schema["required"]) == [
"model",
"clip",
"video_vae",
"sampler",
"sigmas",
"sequence_prompt",
"prompt_mode",
"chunks",
"chunk_seconds",
"aspect",
"preset",
"custom_mp",
"continuity",
"base_seed",
"audio_continuity",
"diagnostics",
"reroll_from_chunk",
"reroll_nonce",
"strict_compatibility",
"debug",
"show_preview",
"run_storage",
"run_name",
"reference_size",
"project_id",
"video_reference_size",
"continuation_backend",
"generation_mode",
"review_action",
"take_group",
"take_revision_id",
"take_action",
"size_source",
"width",
"height",
]
assert list(schema["optional"]) == [
"first_frame",
"last_frame",
"reference_image_1",
"reference_image_2",
"reference_image_3",
"reference_video_1",
"driving_audio",
"audio_vae",
"reference_audio_1",
"reference_audio_vae",
"guide",
"audio_references",
]
def test_registry_package_keeps_one_workflow_and_excludes_development_assets():
rules = (ROOT / ".comfyignore").read_text(encoding="utf-8").splitlines()
assert "tests/" in rules
assert "tools/*" in rules
assert "!tools/__init__.py" in rules
assert "!tools/p20_file_backed_tensor_poc.py" in rules
assert "tools/" not in rules
assert "AGENTS.md" in rules
assert "PROJECT_STATE.md" in rules
assert "WORKLOG.md" in rules
assert "MANIFEST.sha256" in rules
assert "examples/*" in rules
assert "!examples/workflows/" in rules
assert "examples/workflows/*" in rules
assert "!examples/workflows/MiniMax_H3_Continuum_V38.json" in rules
assert "!examples/workflows/MiniMax_H3_Continuum_V38.zip" in rules
assert "*.zip" in rules
workflow = json.loads(
(ROOT / "examples/workflows/MiniMax_H3_Continuum_V38.json").read_text(
encoding="utf-8"
)
)
custom_types = {
node["type"] for node in workflow["nodes"] if node["type"].startswith("H3")
}
assert custom_types <= set(PUBLIC_DISPLAY_NAMES)
sampler = next(
node for node in workflow["nodes"] if node["type"] == "H3ContinuumSamplerV38"
)
assert sampler["properties"]["H3 Continuum View"] == "Basic"
# The user-approved Spectrum distribution preserves its saved Core titles.
# Exact bytes, dependencies and graph topology are tested in the workflow suite.
assert any(node["type"] == "SpectrumApplyMiniMaxH3" for node in workflow["nodes"])
def test_registry_manifest_matches_every_declared_source_file():
manifest = ROOT / "REGISTRY_MANIFEST.sha256"
entries = {}
for line in manifest.read_text(encoding="utf-8").splitlines():
digest, relative_path = line.split(" ", 1)
entries[relative_path] = digest
assert "REGISTRY_MANIFEST.sha256" not in entries
assert "MANIFEST.sha256" not in entries
assert "AGENTS.md" not in entries
assert "PROJECT_STATE.md" not in entries
assert "WORKLOG.md" not in entries
assert "tools/__init__.py" in entries
assert "tools/p20_file_backed_tensor_poc.py" in entries
assert "tools/verify_runtime.py" in entries
assert not {
path for path in entries if path.startswith("tools/")
} - {
"tools/__init__.py",
"tools/p20_file_backed_tensor_poc.py",
"tools/verify_runtime.py",
}
assert {
path for path in entries if path.startswith("examples/")
} == {
"examples/workflows/MiniMax_H3_Continuum_V38.json",
"examples/workflows/MiniMax_H3_Continuum_V38.zip",
}
for relative_path, expected_digest in entries.items():
payload = (ROOT / relative_path).read_bytes()
assert hashlib.sha256(payload).hexdigest() == expected_digest
def test_intuitive_facade_is_discoverable_and_presentation_only(tmp_path):
node_executable = shutil.which("node")
if node_executable is None:
pytest.skip("Node.js is required for the frontend behavior regression")
source = (ROOT / "web/project_id.js").read_text(encoding="utf-8")
source = source.replace(
'import { app } from "../../scripts/app.js";',
"const app = globalThis.__app;",
).replace(
'import { normalizeReferenceAudioLabels } from "./reference_audio_ui.js";',
"function normalizeReferenceAudioLabels() {}",
)
script = f"""
globalThis.__extension = null;
const sourceNodes = {{
101: {{ id: 101, mode: 0, widgets: [{{ name: "Enable Image", value: true }}] }},
102: {{ id: 102, mode: 0, widgets: [{{ name: "Enable Video", value: true }}] }},
103: {{ id: 103, mode: 4, widgets: [{{ name: "Enable Audio", value: true }}] }},
104: {{ id: 104, mode: 0, widgets: [{{ name: "Enable Audio", value: true }}] }},
}};
globalThis.__app = {{
graph: {{
_nodes: [],
links: {{
2: {{ origin_id: 102 }}, 3: {{ origin_id: 101 }},
4: {{ origin_id: 103 }}, 5: {{ origin_id: 104 }},
}},
getNodeById(id) {{ return sourceNodes[id] || null; }},
}},
ui: {{ settings: {{ getSettingValue: (_id, fallback) => fallback, addSetting() {{}} }} }},
registerExtension(extension) {{ globalThis.__extension = extension; }},
}};
globalThis.fetch = async () => ({{ status: 404, ok: false }});
{source}
function widget(name, value) {{
return {{
name, value, type: "combo",
options: {{ values: [] }},
computeSize: () => [120, 20],
}};
}}
const node = {{
comfyClass: "H3ContinuumSamplerV38",
properties: {{ "H3 Continuum View": "Basic" }},
widgets: [
widget("prompt_mode", "Auto"),
widget("chunks", 3), widget("chunk_seconds", 5),
widget("aspect", "Auto from First Image"),
widget("preset", "Draft — 0.30 MP"), widget("custom_mp", 0.3),
widget("continuity", "Balanced — 22 frames"),
widget("base_seed", 0), widget("control_after_generate", "randomize"),
widget("audio_continuity", true),
widget("continuation_backend", "Standard"),
widget("run_storage", "Save + Auto Resume"),
widget("reroll_from_chunk", "Chunk 2"), widget("reroll_nonce", 7),
widget("run_name", "keep-me"), widget("reference_size", "Match Output"),
widget("video_reference_size", "Efficient - 0.4 MP"),
widget("diagnostics", "Detailed Report"), widget("strict_compatibility", false),
widget("debug", true), widget("show_preview", false),
widget("project_id", "stable-project"),
widget("generation_mode", "Full Run"), widget("review_action", "Continue / Next"),
widget("take_group", 0), widget("take_revision_id", ""),
widget("take_action", "Automatic"),
widget("size_source", "First Image"), widget("width", 480), widget("height", 640),
],
inputs: [
{{ name: "model", link: 10 }},
{{ name: "clip", link: 11 }},
{{ name: "video_vae", link: 12 }},
{{ name: "sampler", link: 13 }},
{{ name: "sigmas", link: 14 }},
{{ name: "prompt_overrides", link: null }},
{{ name: "first_frame", link: 3 }},
{{ name: "last_frame", link: null }},
{{ name: "reference_image_1", link: 1 }},
{{ name: "reference_video_1", link: 2 }},
{{ name: "driving_audio", link: null }},
{{ name: "audio_references", link: null }},
{{ name: "guide", link: null }},
],
addWidget(type, name, value, callback, options) {{
const item = {{ name, value, callback, type, options: options || {{}}, computeSize: () => [120, 20] }};
this.widgets.push(item);
return item;
}},
addCustomWidget(item) {{
this.widgets.push(item);
return item;
}},
serialize() {{ return {{ widgets_values: this.widgets.map((item) => item.value) }}; }},
configure(info) {{
info.widgets_values.forEach((value, index) => {{ this.widgets[index].value = value; }});
}},
setDirtyCanvas() {{}},
}};
globalThis.__app.graph._nodes.push(node);
globalThis.__extension.nodeCreated(node);
setTimeout(() => {{
const savedBefore = node.serialize().widgets_values;
const facade = Object.fromEntries([
"Prompt Format", "Continuity", "Base Seed", "Control After Generate", "Audio Continuity",
"Chunks", "Seconds per Chunk", "Total Length",
"Size Source", "Resolution", "Custom MP", "Width", "Height",
"Run", "Progress", "Ready to Queue", "Advanced Settings",
"Reference Image Size", "Video Guide Size",
].map((name) => [name, node.widgets.find((item) => item.name === name)]));
const normalVisibleBeforeReview = [
"Prompt Format", "Continuity", "Base Seed", "Control After Generate", "Audio Continuity",
"Chunks", "Seconds per Chunk", "Total Length", "Size Source", "Resolution",
"Run", "Progress", "Ready to Queue", "Advanced Settings",
].every((name) => facade[name] && !facade[name].hidden);
const coreMainOrder = node.widgets.slice(0, 5).map((item) => item.name);
const corePersistentHidden = [
"prompt_mode", "continuity", "base_seed", "control_after_generate", "audio_continuity",
].every((name) => node.widgets.find((item) => item.name === name).hidden);
const dimensionsInitiallyHidden = facade.Width.hidden && facade.Height.hidden;
const drawMetrics = (widget) => {{
let rect = null;
const textYs = [];
const ctx = {{
save() {{}}, restore() {{}}, beginPath() {{}}, closePath() {{}},
fill() {{}}, stroke() {{}}, moveTo() {{}}, lineTo() {{}}, quadraticCurveTo() {{}},
roundRect(x, y, width, height, radius) {{ rect = {{ x, y, width, height, radius }}; }},
fillText(_text, _x, y) {{ textYs.push(y); }},
}};
widget.draw(ctx, node, 400, 100, 20);
return {{ rectHeight: rect.height, firstTextY: textYs[0], secondTextY: textYs[1] }};
}};
const readyCardMetrics = drawMetrics(facade["Ready to Queue"]);
const reviewActionHidden = node.widgets.find((item) => item.name === "review_action").hidden;
const advancedSource = node.widgets.find((item) => item.name === "continuation_backend");
const advancedInitiallyHidden = advancedSource.hidden;
const advancedClosedLabel = facade["Advanced Settings"].label;
facade["Advanced Settings"].callback();
const advancedVisible = !advancedSource.hidden;
const conditionalSizesVisibleInAdvanced = (
!facade["Reference Image Size"].hidden && !facade["Video Guide Size"].hidden
);
const advancedOpenLabel = facade["Advanced Settings"].label;
facade["Advanced Settings"].callback();
facade["Seconds per Chunk"].value = 10;
facade["Seconds per Chunk"].callback(10);
const chunksAfterSecondsChange = node.widgets.find((item) => item.name === "chunks").value;
const secondsAfterSecondsChange = node.widgets.find((item) => item.name === "chunk_seconds").value;
const totalAfterSecondsChange = facade["Total Length"].value;
facade.Chunks.value = 2;
facade.Chunks.callback(2);
const secondsAfterChunksChange = node.widgets.find((item) => item.name === "chunk_seconds").value;
const totalAfterChunksChange = facade["Total Length"].value;
facade["Size Source"].value = "Manual";
facade["Size Source"].callback("Manual");
const manualSizeSource = node.widgets.find((item) => item.name === "size_source").value;
const manualResolutionHidden = facade.Resolution.hidden;
const manualDimensionsVisible = !facade.Width.hidden && !facade.Height.hidden;
facade["Size Source"].value = "First Image";
facade["Size Source"].callback("First Image");
sourceNodes[101].mode = 4;
node.__h3ContinuumIntuitiveUxRefresh();
const bypassedSizeSource = facade["Size Source"].value;
const bypassedReady = facade["Ready to Queue"].value;
const bypassedResolutionVisible = !facade.Resolution.hidden;
const bypassedDimensionsHidden = facade.Width.hidden && facade.Height.hidden;
sourceNodes[101].mode = 0;
node.__h3ContinuumIntuitiveUxRefresh();
facade.Run.value = "Review Each Chunk";
facade.Run.callback("Review Each Chunk");
const reviewMapped = node.widgets.find((item) => item.name === "generation_mode").value;
const saveMapped = node.widgets.find((item) => item.name === "run_storage").value;
facade.Chunks.value = 1;
facade.Chunks.callback(1);
const singleChunkReviewGuidance = facade["Ready to Queue"].value;
const singleChunkReviewHelp = facade.Chunks.tooltip;
facade.Chunks.value = 2;
facade.Chunks.callback(2);
const autoFixedReviewGuidance = facade["Ready to Queue"].value;
facade["Control After Generate"].value = "fixed";
facade["Control After Generate"].callback("fixed");
const fixedReviewReady = facade["Ready to Queue"].value;
const reviewButtonsHiddenBeforeReady = [
"Use it and continue", "Try this chunk again", "Use it and finish the rest",
].every((name) => node.widgets.find((item) => item.name === name).hidden);
const historyHiddenBeforeTake = node.widgets.find(
(item) => item.name === "Render History",
).hidden;
node.__h3ContinuumTakeProject = {{
branch_provenance_version: 1,
canonical_storage_revision_id: "storage-ready",
revisions: [{{
revision_id: "storage-ready", status: "review_ready",
review_unit: {{ start: 1, end: 1, physical_group: 1 }},
}}],
canonical_head_revision_id: "take-1",
active_revisions: {{ "1": "take-1" }},
group_revisions: [{{
revision_id: "take-1", revision_order: "1",
group: {{ start: 1, end: 1, physical_group: 1 }},
}}],
}};
node.__h3ContinuumProductionUxRefresh();
const reviewButtonsVisibleWhenReady = [
"Use it and continue", "Try this chunk again", "Use it and finish the rest",
].every((name) => !node.widgets.find((item) => item.name === name).hidden);
const setupHiddenWhenReady = [
"Prompt Format", "Continuity", "Base Seed", "Control After Generate", "Audio Continuity",
"Chunks", "Seconds per Chunk", "Total Length", "Size Source", "Resolution",
"Run", "Progress", "Ready to Queue",
].every((name) => node.widgets.find((item) => item.name === name).hidden);
const reviewStatus = node.widgets.find((item) => item.name === "Review Ready");
const reviewCardMetrics = drawMetrics(reviewStatus);
const reviewStatusBeforeSelection = reviewStatus.value;
const backToSettings = node.widgets.find((item) => item.name === "Back to Settings");
const returnToReview = node.widgets.find((item) => item.name === "Return to Review");
const backToSettingsVisibleWhenReady = !backToSettings.hidden;
const returnToReviewHiddenWhenReady = returnToReview.hidden;
backToSettings.callback();
const setupVisibleAfterBack = [
"Prompt Format", "Continuity", "Base Seed", "Control After Generate", "Audio Continuity",
"Chunks", "Seconds per Chunk", "Total Length", "Size Source", "Resolution",
"Run", "Progress", "Ready to Queue",
].every((name) => !node.widgets.find((item) => item.name === name).hidden);
const reviewButtonsHiddenAfterBack = [
"Use it and continue", "Try this chunk again", "Use it and finish the rest",
].every((name) => node.widgets.find((item) => item.name === name).hidden);
const returnToReviewVisibleAfterBack = !returnToReview.hidden;
const backToSettingsHiddenAfterBack = backToSettings.hidden;
const settingsReviewCard = node.widgets.find((item) => item.name === "Ready to Queue");
const settingsReviewStatusAfterBack = settingsReviewCard.value;
const settingsReviewVariantAfterBack = settingsReviewCard.__h3ContinuumInfoVariant;
returnToReview.callback();
const setupHiddenAfterReturn = [
"Prompt Format", "Continuity", "Base Seed", "Control After Generate", "Audio Continuity",
"Chunks", "Seconds per Chunk", "Total Length", "Size Source", "Resolution",
"Run", "Progress", "Ready to Queue",
].every((name) => node.widgets.find((item) => item.name === name).hidden);
const reviewButtonsVisibleAfterReturn = [
"Use it and continue", "Try this chunk again", "Use it and finish the rest",
].every((name) => !node.widgets.find((item) => item.name === name).hidden);
const continueButton = node.widgets.find((item) => item.name === "Use it and continue");
continueButton.callback();
const selectedContinueLabel = continueButton.label;
const reviewStatusAfterSelection = reviewStatus.value;
const historyVisibleWithTake = !node.widgets.find(
(item) => item.name === "Render History",
).hidden;
const savedAfter = node.serialize().widgets_values;
console.log(JSON.stringify({{
facadeNames: Object.keys(facade),
normalVisible: normalVisibleBeforeReview,
coreMainOrder,
corePersistentHidden,
promptFormat: facade["Prompt Format"].value,
continuity: facade.Continuity.value,
baseSeed: facade["Base Seed"].value,
controlAfter: facade["Control After Generate"].value,
audioContinuity: facade["Audio Continuity"].value,
readyCardMetrics,
reviewCardMetrics,
dimensionsInitiallyHidden,
chunks: facade.Chunks.value,
secondsPerChunk: facade["Seconds per Chunk"].value,
totalLength: facade["Total Length"].value,
sizeSource: facade["Size Source"].value,
resolution: facade.Resolution.value,
progress: facade.Progress.value,
ready: facade["Ready to Queue"].value,
reviewActionHidden,
advancedInitiallyHidden,
advancedVisible,
conditionalSizesVisibleInAdvanced,
advancedClosedLabel,
advancedOpenLabel,
legacyPropertyRemoved: !("H3 Continuum View" in node.properties),
reviewMapped,
saveMapped,
singleChunkReviewGuidance,
singleChunkReviewHelp,
autoFixedReviewGuidance,
fixedReviewReady,
chunksAfterSecondsChange,
secondsAfterSecondsChange,
totalAfterSecondsChange,
secondsAfterChunksChange,
totalAfterChunksChange,
manualSizeSource,
manualResolutionHidden,
manualDimensionsVisible,
bypassedSizeSource,
bypassedReady,
bypassedResolutionVisible,
bypassedDimensionsHidden,
reviewButtonsHiddenBeforeReady,
reviewButtonsVisibleWhenReady,
setupHiddenWhenReady,
backToSettingsVisibleWhenReady,
returnToReviewHiddenWhenReady,
setupVisibleAfterBack,
reviewButtonsHiddenAfterBack,
returnToReviewVisibleAfterBack,
backToSettingsHiddenAfterBack,
settingsReviewStatusAfterBack,
settingsReviewVariantAfterBack,
setupHiddenAfterReturn,
reviewButtonsVisibleAfterReturn,
reviewStatusBeforeSelection,
selectedContinueLabel,
reviewStatusAfterSelection,
historyHiddenBeforeTake,
historyVisibleWithTake,
serializedCountStable: savedBefore.length === savedAfter.length,
inputs: node.inputs.map((item) => item.name),
}}));
}}, 150);
"""
script_path = tmp_path / "v38-public-surface-ui.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 == {
"facadeNames": [
"Prompt Format",
"Continuity",
"Base Seed",
"Control After Generate",
"Audio Continuity",
"Chunks",
"Seconds per Chunk",
"Total Length",
"Size Source",
"Resolution",
"Custom MP",
"Width",
"Height",
"Run",
"Progress",
"Ready to Queue",
"Advanced Settings",
"Reference Image Size",
"Video Guide Size",
],
"normalVisible": True,
"coreMainOrder": [
"Prompt Format",
"Continuity",
"Base Seed",
"Control After Generate",
"Audio Continuity",
],
"corePersistentHidden": True,
"promptFormat": "Auto",
"continuity": "Balanced — 22 frames",
"baseSeed": 0,
"controlAfter": "fixed",
"audioContinuity": True,
"readyCardMetrics": {
"rectHeight": 56,
"firstTextY": 122,
"secondTextY": 145,
},
"reviewCardMetrics": {
"rectHeight": 62,
"firstTextY": 122,
"secondTextY": 145,
},
"dimensionsInitiallyHidden": True,
"chunks": 2,
"secondsPerChunk": 10,
"totalLength": "20 seconds",
"sizeSource": "First Image",
"resolution": "Draft — 0.30 MP",
"progress": "On — Resume and Takes available",
"ready": "Ready to Queue\n2 × 10s = 20 seconds • First Image • Review each chunk",
"reviewActionHidden": True,
"advancedInitiallyHidden": True,
"advancedVisible": True,
"conditionalSizesVisibleInAdvanced": True,
"advancedClosedLabel": "Show Advanced Settings",
"advancedOpenLabel": "Hide Advanced Settings",
"legacyPropertyRemoved": True,
"reviewMapped": "Review Each Chunk",
"saveMapped": "Save + Auto Resume",
"singleChunkReviewGuidance": (
"Set Chunks to 2 or more\nChunks is 1, so the first 10s chunk is also the last. "
"Set Chunks to 2 or more before Queue to use Review and Continue."
),
"singleChunkReviewHelp": (
"Chunks is 1, so there is no next chunk to continue. Set Chunks to 2 or more "
"before Queue when using Review Each Chunk."
),
"autoFixedReviewGuidance": (
"Ready to Queue\n2 × 10s = 20 seconds • First Image • Review each chunk"
),
"fixedReviewReady": (
"Ready to Queue\n2 × 10s = 20 seconds • First Image • Review each chunk"
),
"chunksAfterSecondsChange": 3,
"secondsAfterSecondsChange": 10,
"totalAfterSecondsChange": "30 seconds",
"secondsAfterChunksChange": 10,
"totalAfterChunksChange": "20 seconds",
"manualSizeSource": "Manual",
"manualResolutionHidden": True,
"manualDimensionsVisible": True,
"bypassedSizeSource": "First Image",
"bypassedReady": (
"Check First Image\nSize Source is First Image, but no active image is "
"connected. Queue fallback: 480 × 640."
),
"bypassedResolutionVisible": True,
"bypassedDimensionsHidden": True,
"reviewButtonsHiddenBeforeReady": True,
"reviewButtonsVisibleWhenReady": True,
"setupHiddenWhenReady": True,
"backToSettingsVisibleWhenReady": True,
"returnToReviewHiddenWhenReady": True,
"setupVisibleAfterBack": True,
"reviewButtonsHiddenAfterBack": True,
"returnToReviewVisibleAfterBack": True,
"backToSettingsHiddenAfterBack": True,
"settingsReviewStatusAfterBack": (
"Chunk 1 is ready for review\nChoose what happens next, then press Queue."
),
"settingsReviewVariantAfterBack": "review",
"setupHiddenAfterReturn": True,
"reviewButtonsVisibleAfterReturn": True,
"reviewStatusBeforeSelection": (
"Chunk 1 is ready for review\nChoose what happens next, then press Queue."
),
"selectedContinueLabel": "✓ Use it and continue",
"reviewStatusAfterSelection": (
"Chunk 1 is ready for review\nSelected: Use it and continue. Press Queue to run this action."
),
"historyHiddenBeforeTake": True,
"historyVisibleWithTake": True,
"serializedCountStable": True,
"inputs": [
"model",
"clip",
"video_vae",
"sampler",
"sigmas",
"prompt_overrides",
"first_frame",
"last_frame",
"reference_image_1",
"reference_video_1",
"driving_audio",
"audio_references",
"guide",
],
}
+223
View File
@@ -0,0 +1,223 @@
from __future__ import annotations
import hashlib
import json
from pathlib import Path
from zipfile import ZipFile
ROOT = Path(__file__).resolve().parents[1]
WORKFLOW_PATH = ROOT / "examples" / "workflows" / "MiniMax_H3_Continuum_V38.json"
# User-approved final distribution. Do not sanitize or reserialize this graph.
WORKFLOW_SHA256 = "e490c87e4995930f95c8fffc4c678111d7897e74003e1962b9b4a247ba43f4ac"
ZIP_SHA256 = "83d28cc0cd549066962dc21ceae05d2b189fe22391b556887eab2cc1800e1e80"
EXTERNAL_PACKAGES = {
"comfyui-spectrum-minimax-h3",
"rgthree-comfy",
"comfyui-kjnodes",
"comfyui-easy-use",
}
def _workflow() -> dict:
return json.loads(WORKFLOW_PATH.read_text(encoding="utf-8"))
def _one_node(workflow: dict, node_type: str) -> dict:
values = [node for node in workflow["nodes"] if node["type"] == node_type]
assert len(values) == 1
return values[0]
def _graph(workflow: dict) -> tuple[dict[int, dict], dict[int, list]]:
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"])
assert len(links) == len(workflow["links"])
for link_id, link in links.items():
assert int(link[0]) == link_id
source = nodes[int(link[1])]
target = nodes[int(link[3])]
assert link_id in (source["outputs"][int(link[2])].get("links") or [])
assert int(target["inputs"][int(link[4])]["link"]) == link_id
for node_id, node in nodes.items():
for slot, item in enumerate(node.get("inputs", [])):
if item.get("link") is not None:
assert links[int(item["link"])][3:5] == [node_id, slot]
for slot, item in enumerate(node.get("outputs", [])):
for link_id in item.get("links") or []:
assert links[int(link_id)][1:3] == [node_id, slot]
return nodes, links
def test_v38_public_workflow_declares_external_dependencies_and_is_reloadable():
workflow = _workflow()
assert len(workflow["nodes"]) == 32
assert len(workflow["links"]) == 38
packages = {
node.get("properties", {}).get("cnr_id") for node in workflow["nodes"]
} - {None, "", "comfy-core"}
assert packages == EXTERNAL_PACKAGES
node_types = {node["type"] for node in workflow["nodes"]}
assert {
"SpectrumApplyMiniMaxH3", "Power Lora Loader (rgthree)",
"Fast Groups Bypasser (rgthree)", "easy cleanGpuUsed",
"MiniMaxH3MemoryEfficientSageAttentionPatch",
} <= node_types
assert not any("hires" in name.lower() for name in node_types)
_graph(workflow)
assert json.loads(json.dumps(workflow, ensure_ascii=False)) == workflow
assert int(workflow["last_node_id"]) >= max(int(node["id"]) for node in workflow["nodes"])
assert int(workflow["last_link_id"]) >= max(int(link[0]) for link in workflow["links"])
def test_v38_public_workflow_and_zip_preserve_supplied_bytes():
payload = WORKFLOW_PATH.read_bytes()
archive_path = WORKFLOW_PATH.with_suffix(".zip")
assert hashlib.sha256(payload).hexdigest() == WORKFLOW_SHA256
assert hashlib.sha256(archive_path.read_bytes()).hexdigest() == ZIP_SHA256
with ZipFile(archive_path) as archive:
assert archive.namelist() == [WORKFLOW_PATH.name]
assert archive.testzip() is None
assert archive.read(WORKFLOW_PATH.name) == payload
def test_v38_public_workflow_preserves_sampler_widget_positions():
workflow = _workflow()
sampler = _one_node(workflow, "H3ContinuumSamplerV38")
names = [
"prompt_mode",
"chunks",
"chunk_seconds",
"aspect",
"preset",
"custom_mp",
"continuity",
"base_seed",
"control_after_generate",
"audio_continuity",
"diagnostics",
"reroll_from_chunk",
"reroll_nonce",
"strict_compatibility",
"debug",
"show_preview",
"run_storage",
"run_name",
"reference_size",
"project_id",
"video_reference_size",
"continuation_backend",
"generation_mode",
"review_action",
"take_group",
"take_revision_id",
"take_action",
"size_source",
"width",
"height",
]
assert len(sampler["widgets_values"]) == len(names) == 30
assert sampler["widgets_values"] == [
sampler["widgets_values_named"][name] for name in names
]
assert sampler["widgets_values_named"]["generation_mode"] == "Full Run"
assert sampler["widgets_values_named"]["review_action"] == "Continue / Next"
assert sampler["widgets_values_named"]["run_storage"] == "Off"
assert sampler["widgets_values_named"]["aspect"] == "Auto from First Image"
assert sampler["widgets_values_named"]["preset"] == "Draft — 0.30 MP"
assert sampler["widgets_values_named"]["size_source"] == "First Image"
assert sampler["widgets_values_named"]["width"] == 640
assert sampler["widgets_values_named"]["height"] == 640
assert sampler["widgets_values_named"]["chunks"] == 2
assert sampler["widgets_values_named"]["chunk_seconds"] == 5
assert sampler["widgets_values_named"]["control_after_generate"] == "fixed"
assert sampler["widgets_values_named"]["continuation_backend"] == "Standard"
def test_v38_public_workflow_keeps_required_and_optional_connections():
workflow = _workflow()
nodes, links = _graph(workflow)
sampler = _one_node(workflow, "H3ContinuumSamplerV38")
inputs = {item["name"]: item for item in sampler["inputs"]}
required = {"model", "clip", "video_vae", "sampler", "sigmas", "sequence_prompt"}
optional = {
"first_frame",
"last_frame",
"reference_image_1",
"reference_image_2",
"reference_image_3",
"driving_audio",
"audio_vae",
"reference_video_1",
"audio_references",
}
assert required | optional <= set(inputs)
assert all(inputs[name]["link"] is not None for name in required | optional)
source_types = {}
source_modes = {}
for name in required | optional:
link = links[int(inputs[name]["link"])]
source = nodes[int(link[1])]
source_types[name] = source["type"]
source_modes[name] = int(source["mode"])
assert source_types["model"] == "SpectrumApplyMiniMaxH3"
assert source_types["sampler"] == "KSamplerSelect"
assert source_types["sigmas"] == "BasicScheduler"
assert source_types["sequence_prompt"] == "PrimitiveStringMultiline"
assert source_types["first_frame"] == "easy cleanGpuUsed"
assert source_modes["first_frame"] == 0
assert source_modes["last_frame"] == 4
assert source_modes["reference_image_1"] == 0
assert source_modes["reference_image_2"] == 0
assert source_modes["reference_image_3"] == 0
assert source_modes["driving_audio"] == 4
assert source_modes["reference_video_1"] == 4
assert source_types["audio_references"] == "H3ContinuumReferenceAudios"
def test_v38_public_workflow_preserves_spectrum_default_and_model_chain():
workflow = _workflow()
nodes, links = _graph(workflow)
def source(node, name):
item = next(item for item in node["inputs"] if item["name"] == name)
return nodes[links[item["link"]][1]]
sampler = _one_node(workflow, "H3ContinuumSamplerV38")
spectrum = source(sampler, "model")
assert spectrum["type"] == "SpectrumApplyMiniMaxH3"
assert spectrum["widgets_values"][0] is True
lora = source(spectrum, "model")
assert lora["type"] == "Power Lora Loader (rgthree)"
loras = [item for item in lora["widgets_values"] if isinstance(item, dict) and "lora" in item]
assert len(loras) == 4
assert all(item["on"] is False for item in loras)
sage = source(lora, "model")
assert sage["type"] == "MiniMaxH3MemoryEfficientSageAttentionPatch"
assert source(sage, "model")["type"] == "UNETLoader"
assert _one_node(workflow, "KSamplerSelect")["widgets_values"] == ["res_multistep"]
scheduler = _one_node(workflow, "BasicScheduler")
assert scheduler["widgets_values"] == ["simple", 20, 1]
assert source(scheduler, "model")["id"] == spectrum["id"]
def test_v38_public_workflow_keeps_decode_finalize_create_save_chain():
workflow = _workflow()
nodes, links = _graph(workflow)
save = _one_node(workflow, "SaveVideo")
cleanup = nodes[links[int(save["inputs"][0]["link"])][1]]
assert cleanup["type"] == "easy cleanGpuUsed"
create_link = links[int(cleanup["inputs"][0]["link"])]
assert nodes[int(create_link[1])]["type"] == "CreateVideo"
create = nodes[int(create_link[1])]
assert all(item["link"] is not None for item in create["inputs"][:2])
finalize = _one_node(workflow, "H3ContinuumAssembleSeamV35")
assert [links[item["link"]][1] for item in create["inputs"][:2]] == [finalize["id"]] * 2
incoming = [nodes[links[item["link"]][1]]["type"] for item in finalize["inputs"][:3]]
assert incoming == ["VAEDecode", "VAEDecodeAudio", "H3ContinuumSamplerV38"]
for node_type in ("VAEDecode", "VAEDecodeAudio"):
decode = _one_node(workflow, node_type)
assert nodes[links[decode["inputs"][0]["link"]][1]]["type"] == "H3ContinuumSamplerV38"
+492
View File
@@ -0,0 +1,492 @@
from __future__ import annotations
from concurrent.futures import ThreadPoolExecutor
import gc
import inspect
from pathlib import Path
import threading
import weakref
import pytest
import torch
from ComfyUI_H3_Continuum_Join import reference, reference_audio, reference_video
from ComfyUI_H3_Continuum_Join.reference import ReferenceAssets
from ComfyUI_H3_Continuum_Join.reference_audio import (
ReferenceAudioAssets,
ReferenceAudioSource,
)
from ComfyUI_H3_Continuum_Join.temporal import video_latent_t
from ComfyUI_H3_Continuum_Join.v3 import driving_nodes
from ComfyUI_H3_Continuum_Join.v3.ref_encode_cache import (
RefEncodeCache,
clear_ref_encode_cache,
format_ref_encode_cache_diagnostics,
get_ref_encode_cache,
inspect_ref_encode_cache,
make_ref_encode_cache_key,
)
ROOT = Path(__file__).resolve().parents[1]
@pytest.fixture(autouse=True)
def _clear_global_cache():
clear_ref_encode_cache()
yield
clear_ref_encode_cache()
class ImageVAE:
def __init__(self):
self.calls = 0
def encode(self, image):
self.calls += 1
value = float(image.mean().item())
return torch.full((1, 24, 7, 2, 2), value, dtype=torch.float32)
class VideoVAE:
def __init__(self):
self.calls = 0
def encode(self, frames):
self.calls += 1
latent_t = video_latent_t(int(frames.shape[0]))
value = float(frames.mean().item())
return torch.full((1, 24, latent_t, 2, 2), value, dtype=torch.float32)
class AudioVAE:
audio_sample_rate = 32000
def __init__(self):
self.calls = 0
def encode(self, waveform):
self.calls += 1
return torch.full(
(1, 32, 2, 9),
float(waveform.mean().item()),
dtype=torch.float32,
)
def _key(identity: str, *, kind: str = "reference_image"):
return make_ref_encode_cache_key(kind, 1, identity)
def _image_assets(*hashes: str) -> ReferenceAssets:
images = tuple(
torch.full((1, 32, 32, 3), float(index), dtype=torch.float32)
for index in range(len(hashes))
)
return ReferenceAssets(
images=images,
latents=tuple(None for _ in images),
image_hashes=tuple(hashes),
combined_hash="combined",
size_mode=reference.REFERENCE_SIZE_MATCH_OUTPUT,
)
def _video_source(
*,
frames: int = 40,
target_frames: int = 22,
size_mode: str = reference_video.REFERENCE_VIDEO_SIZE_EFFICIENT,
value: float = 0.25,
):
return reference_video.prepare_reference_video_source(
torch.full((frames, 32, 32, 3), value, dtype=torch.float32),
target_frames=target_frames,
output_width=64,
output_height=64,
size_mode=size_mode,
)
def _audio_source(identity: str = "audio-a") -> ReferenceAudioSource:
waveform = torch.zeros((1, 2, 3200), dtype=torch.float32)
return ReferenceAudioSource(
waveform=waveform,
source_sample_rate=32000,
source_shape=tuple(waveform.shape),
source_dtype=str(waveform.dtype),
source_sha256=f"source-{identity}",
resolved_vae_sample_rate=32000,
resampled_shape=tuple(waveform.shape),
resampled_dtype=str(waveform.dtype),
resampled_sha256=f"resampled-{identity}",
combined_hash=identity,
)
def test_cache_core_miss_store_hit_returns_private_clone():
cache = RefEncodeCache()
vae = ImageVAE()
key = _key("a")
source = torch.arange(8, dtype=torch.float32)
events = []
assert cache.lookup(vae, key, event_sink=events.append) is None
assert cache.store(vae, key, source, event_sink=events.append)
hit = cache.lookup(vae, key, event_sink=events.append)
assert [event.action for event in events] == ["miss", "store", "hit"]
assert torch.equal(hit, source)
assert hit is not source
assert hit.data_ptr() != source.data_ptr()
hit.add_(100)
assert torch.equal(cache.lookup(vae, key), source)
def test_cache_namespace_requires_same_vae_object():
cache = RefEncodeCache()
first = ImageVAE()
second = ImageVAE()
key = _key("same")
cache.store(first, key, torch.ones(2))
assert cache.lookup(first, key) is not None
assert cache.lookup(second, key) is None
def test_cache_lru_evicts_global_oldest_entry():
cache = RefEncodeCache(max_entries=2, max_bytes=1024)
vae = ImageVAE()
first, second, third = _key("1"), _key("2"), _key("3")
cache.store(vae, first, torch.ones(1))
cache.store(vae, second, torch.ones(1) * 2)
assert cache.lookup(vae, first) is not None
cache.store(vae, third, torch.ones(1) * 3)
assert cache.lookup(vae, first) is not None
assert cache.lookup(vae, second) is None
assert cache.lookup(vae, third) is not None
assert cache.inspect()["resident_entries"] == 2
def test_cache_byte_limit_and_oversize_bypass():
cache = RefEncodeCache(max_entries=16, max_bytes=16)
vae = ImageVAE()
events = []
assert not cache.store(
vae,
_key("too-large"),
torch.ones(5, dtype=torch.float32),
event_sink=events.append,
)
assert events[-1].action == "bypass"
assert events[-1].reason == "entry_exceeds_byte_limit"
assert cache.inspect()["resident_entries"] == 0
def test_cache_clear_resets_entries_and_stats():
cache = RefEncodeCache()
vae = ImageVAE()
cache.store(vae, _key("a"), torch.ones(1))
cache.lookup(vae, _key("a"))
cache.clear()
assert cache.inspect()["resident_entries"] == 0
assert cache.inspect()["stats"] == {}
def test_weak_vae_cleanup_releases_namespace():
cache = RefEncodeCache()
vae = ImageVAE()
cache.store(vae, _key("a"), torch.ones(1))
vae_ref = weakref.ref(vae)
del vae
gc.collect()
assert vae_ref() is None
assert cache.inspect()["resident_entries"] == 0
assert cache.inspect()["vae_namespaces"] == 0
@pytest.mark.parametrize("vae", [object(), []])
def test_unweakrefable_or_unhashable_vae_is_bypassed(vae):
cache = RefEncodeCache()
events = []
assert cache.lookup(vae, _key("a"), event_sink=events.append) is None
assert events[-1].action == "bypass"
assert events[-1].reason == "vae_not_weakrefable_or_hashable"
def test_concurrent_hits_do_not_share_returned_tensor_or_corrupt_cache():
cache = RefEncodeCache()
vae = ImageVAE()
key = _key("threaded")
expected = torch.arange(64, dtype=torch.float32)
cache.store(vae, key, expected)
barrier = threading.Barrier(8)
def lookup_and_mutate(index):
barrier.wait()
value = cache.lookup(vae, key)
assert value is not None
original_ptr = value.data_ptr()
value.add_(index)
return original_ptr
with ThreadPoolExecutor(max_workers=8) as pool:
pointers = list(pool.map(lookup_and_mutate, range(8)))
assert len(set(pointers)) == 8
assert torch.equal(cache.lookup(vae, key), expected)
def test_reference_image_cold_then_warm_skips_encode_and_is_exact():
vae = ImageVAE()
assets = _image_assets("a" * 64)
cold = reference.encode_reference_latents_cached(vae, assets)
warm = reference.encode_reference_latents_cached(vae, assets)
assert vae.calls == 1
assert torch.equal(cold.latents[0], warm.latents[0])
assert cold.latents[0] is not warm.latents[0]
def test_reference_image_hit_mutation_does_not_damage_cache_master():
vae = ImageVAE()
assets = _image_assets("a" * 64)
reference.encode_reference_latents_cached(vae, assets)
first_hit = reference.encode_reference_latents_cached(vae, assets)
first_hit.latents[0].add_(99)
second_hit = reference.encode_reference_latents_cached(vae, assets)
assert vae.calls == 1
assert not torch.equal(first_hit.latents[0], second_hit.latents[0])
assert torch.equal(second_hit.latents[0], torch.zeros_like(second_hit.latents[0]))
def test_reference_image_changed_preprocessed_hash_misses():
vae = ImageVAE()
reference.encode_reference_latents_cached(vae, _image_assets("size-a"))
reference.encode_reference_latents_cached(vae, _image_assets("size-b"))
assert vae.calls == 2
def test_three_reference_images_cache_independently():
vae = ImageVAE()
assets = _image_assets("one", "two", "three")
events = []
reference.encode_reference_latents_cached(vae, assets, cache_event=events.append)
reference.encode_reference_latents_cached(vae, assets, cache_event=events.append)
assert vae.calls == 3
assert sum(event.action == "hit" for event in events) == 3
assert sum(event.action == "miss" for event in events) == 3
def test_reference_video_same_combined_hash_hits_and_preserves_presentation():
vae = VideoVAE()
source = _video_source()
cold = reference_video.encode_reference_video_cached(vae, source)
warm = reference_video.encode_reference_video_cached(vae, source)
assert vae.calls == 1
assert torch.equal(cold.block["latent"], warm.block["latent"])
assert cold.block["latent"].data_ptr() != warm.block["latent"].data_ptr()
assert torch.equal(cold.item["data"], warm.item["data"])
assert cold.item["timestamps"] == warm.item["timestamps"]
def test_reference_video_frame_size_and_source_identity_changes_miss():
vae = VideoVAE()
sources = [
_video_source(target_frames=22),
_video_source(target_frames=39),
_video_source(
target_frames=22,
size_mode=reference_video.REFERENCE_VIDEO_SIZE_MATCH_OUTPUT,
),
_video_source(target_frames=22, value=0.5),
]
assert len({source.combined_hash for source in sources}) == len(sources)
for source in sources:
reference_video.encode_reference_video_cached(vae, source)
assert vae.calls == len(sources)
def test_reference_video_cache_does_not_retain_source_frames():
vae = VideoVAE()
source = _video_source()
frames_ref = weakref.ref(source.frames)
assets = reference_video.encode_reference_video_cached(vae, source)
del assets
del source
gc.collect()
assert frames_ref() is None
assert inspect_ref_encode_cache()["resident_entries"] == 1
def test_reference_audio_cpu_output_cold_then_warm_is_exact():
vae = AudioVAE()
source = _audio_source()
cold = reference_audio.encode_reference_audio_cached(vae, source)
warm = reference_audio.encode_reference_audio_cached(vae, source)
assert vae.calls == 1
assert torch.equal(cold.audio_latent, warm.audio_latent)
assert cold.audio_latent.data_ptr() != warm.audio_latent.data_ptr()
def test_reference_audio_source_or_vae_change_misses():
first_vae = AudioVAE()
second_vae = AudioVAE()
reference_audio.encode_reference_audio_cached(first_vae, _audio_source("a"))
reference_audio.encode_reference_audio_cached(first_vae, _audio_source("b"))
reference_audio.encode_reference_audio_cached(second_vae, _audio_source("a"))
assert first_vae.calls == 2
assert second_vae.calls == 1
def test_reference_audio_non_cpu_output_is_safely_bypassed(monkeypatch):
vae = AudioVAE()
source = _audio_source()
calls = []
def fake_encode(_vae, active_source):
calls.append(active_source.combined_hash)
return ReferenceAudioAssets(
source=active_source,
audio_latent=torch.empty((1, 32, 2, 9), device="meta"),
)
monkeypatch.setattr(reference_audio, "encode_reference_audio", fake_encode)
events = []
first = reference_audio.encode_reference_audio_cached(
vae, source, cache_event=events.append
)
second = reference_audio.encode_reference_audio_cached(
vae, source, cache_event=events.append
)
assert first.audio_latent.device.type == "meta"
assert second.audio_latent.device.type == "meta"
assert calls == [source.combined_hash, source.combined_hash]
assert [event.action for event in events] == [
"miss",
"bypass",
"miss",
"bypass",
]
assert all(
event.reason == "payload_not_cpu"
for event in events
if event.action == "bypass"
)
def test_detailed_cache_report_has_kind_totals_and_resident_limits():
vae = ImageVAE()
events = []
assets = _image_assets("a")
reference.encode_reference_latents_cached(vae, assets, cache_event=events.append)
reference.encode_reference_latents_cached(vae, assets, cache_event=events.append)
line = format_ref_encode_cache_diagnostics(events)
assert line.startswith("Reference encode cache:")
assert "image hit=1/miss=1/store=1/bypass=0" in line
assert "total hits=1, misses=1, stores=1, bypasses=0" in line
assert "MiB/512.0 MiB" in line
assert "1/16 entries" in line
def test_v38_enables_internal_cache_without_public_schema_change(monkeypatch):
captured = {}
sentinel = object()
def fake_v37_run(_self, **kwargs):
captured.update(kwargs)
return sentinel
monkeypatch.setattr(driving_nodes.H3ContinuumSamplerV37, "run", fake_v37_run)
result = driving_nodes.H3ContinuumSamplerV38().run(
aspect="Square 1:1",
preset="Custom",
custom_mp=0.3,
chunks=1,
chunk_seconds=5.0,
diagnostics="Off",
)
schema = driving_nodes.H3ContinuumSamplerV38.INPUT_TYPES()
assert result is sentinel
assert captured["reference_encode_cache"] is True
assert all(
"reference_encode_cache" not in group
for group in (
schema.get("required", {}),
schema.get("optional", {}),
schema.get("hidden", {}),
)
)
def test_production_facade_accepts_internal_cache_flag():
signature = inspect.signature(driving_nodes.H3ContinuumSamplerProduction.run)
assert "reference_encode_cache" in signature.parameters
assert signature.parameters["reference_encode_cache"].default is False
source = inspect.getsource(driving_nodes.H3ContinuumSamplerProduction.run)
assert "reference_encode_cache=bool(reference_encode_cache)" in source
def test_v37_and_older_do_not_enable_internal_cache(monkeypatch):
captured = {}
def fake_v36_run(_self, **kwargs):
captured.update(kwargs)
return (), (), {}, "status", None, None
monkeypatch.setattr(driving_nodes.H3ContinuumSamplerV36, "run", fake_v36_run)
driving_nodes.H3ContinuumSamplerV37().run(
guide=None,
width=32,
height=32,
)
assert "reference_encode_cache" not in captured
for sampler in (
driving_nodes.H3ContinuumSamplerV34,
driving_nodes.H3ContinuumSamplerV35,
driving_nodes.H3ContinuumSamplerV36,
driving_nodes.H3ContinuumSamplerV37,
):
schema = sampler.INPUT_TYPES()
assert "reference_encode_cache" not in schema.get("required", {})
assert "reference_encode_cache" not in schema.get("optional", {})
def test_cache_flag_is_not_part_of_run_storage_or_public_workflow_identity():
assert "reference_encode_cache" not in (ROOT / "run_storage.py").read_text(
encoding="utf-8"
)
assert "reference_encode_cache" not in (
ROOT / "examples" / "workflows" / "MiniMax_H3_Continuum_V38.json"
).read_text(encoding="utf-8")
def test_full_reuse_skips_cache_and_partial_regenerate_enters_cached_encode_stage():
source = (ROOT / "v2" / "sequence.py").read_text(encoding="utf-8")
partial_regenerate_guard = source.index("if len(preserved)<chunks:")
image = source.index("encode_reference_latents_cached", partial_regenerate_guard)
audio = source.index("encode_reference_audio_input", partial_regenerate_guard)
video = source.index("encode_reference_video_cached", partial_regenerate_guard)
entries = source.index("entries=preserved[:]", partial_regenerate_guard)
assert partial_regenerate_guard < image < entries
assert partial_regenerate_guard < audio < entries
assert partial_regenerate_guard < video < entries
+312
View File
@@ -0,0 +1,312 @@
from __future__ import annotations
import copy
import hashlib
import pytest
import torch
from ComfyUI_H3_Continuum_Join.v3.refine_schedule import (
AUDIO_POLICY_LOCKED_PASSTHROUGH,
NOISE_MODE_VIDEO_RANDOM_AUDIO_ZERO,
make_tail_schedule,
)
from ComfyUI_H3_Continuum_Join.v3.refine_target import (
AUDIO_ONLY_SEED_NAMESPACE,
MODE_AUDIO_ONLY,
MODE_VIDEO_AUDIO,
MODE_VIDEO_ONLY,
OUTPUT_INPUT_PASSTHROUGH,
OUTPUT_SAMPLED,
VIDEO_AUDIO_SEED_NAMESPACE,
VIDEO_ONLY_SEED_NAMESPACE,
RefineTargetError,
build_target_execution_contract,
derive_target_refine_seed,
make_refine_target,
)
from ComfyUI_H3_Continuum_Join.v3.second_pass import (
derive_refine_seed,
run_second_pass_groups,
)
from ComfyUI_H3_Continuum_Join.v3.second_pass_nodes import (
H3ContinuumSecondPassV35,
)
from ComfyUI_H3_Continuum_Join.v3.targeted_refine_sampling import (
sample_targeted_refine_chunk,
)
from ComfyUI_H3_Continuum_Join.v3.targeted_second_pass import (
run_targeted_second_pass_groups,
)
def _sha(tensor: torch.Tensor) -> str:
value = tensor.detach().to(device="cpu").contiguous()
return hashlib.sha256(value.view(torch.uint8).numpy().tobytes()).hexdigest()
@pytest.mark.parametrize(
"mode,video_policy,audio_policy,namespace",
[
(
MODE_VIDEO_ONLY,
("seeded_random", 1, OUTPUT_SAMPLED),
("zero", 0, OUTPUT_INPUT_PASSTHROUGH),
VIDEO_ONLY_SEED_NAMESPACE,
),
(
MODE_AUDIO_ONLY,
("zero", 0, OUTPUT_INPUT_PASSTHROUGH),
("seeded_random", 1, OUTPUT_SAMPLED),
AUDIO_ONLY_SEED_NAMESPACE,
),
(
MODE_VIDEO_AUDIO,
("seeded_random", 1, OUTPUT_SAMPLED),
("seeded_random", 1, OUTPUT_SAMPLED),
VIDEO_AUDIO_SEED_NAMESPACE,
),
],
)
def test_refine_target_v1_freezes_all_three_stream_policies(
mode,
video_policy,
audio_policy,
namespace,
):
target = make_refine_target(mode)
assert target.contract["magic"] == "H3_CONTINUUM_REFINE_TARGET"
assert target.contract["schema_version"] == 1
assert target.contract["mode"] == mode
assert (
target.contract["video"]["noise"],
target.contract["video"]["mask"],
target.contract["video"]["output"],
) == video_policy
assert (
target.contract["audio"]["noise"],
target.contract["audio"]["mask"],
target.contract["audio"]["output"],
) == audio_policy
assert target.contract["seed_namespace"] == namespace
assert len(target.contract["target_hash"]) == 64
def test_target_seed_namespaces_are_stable_and_video_only_is_legacy_exact():
assert derive_target_refine_seed(42, 0, MODE_VIDEO_ONLY) == derive_refine_seed(42, 0)
seeds = {
derive_target_refine_seed(42, 0, mode)
for mode in (MODE_VIDEO_ONLY, MODE_AUDIO_ONLY, MODE_VIDEO_AUDIO)
}
assert len(seeds) == 3
assert derive_target_refine_seed(42, 1, MODE_VIDEO_ONLY) != derive_refine_seed(42, 0)
def test_target_execution_uses_sigma_range_without_mutating_schedule_v1():
sigmas = torch.tensor([0.9, 0.6, 0.3, 0.0], dtype=torch.float32)
schedule = make_tail_schedule(sigmas, evaluation_count=2)
before = copy.deepcopy(dict(schedule.contract))
execution = build_target_execution_contract(
make_refine_target(MODE_VIDEO_ONLY),
schedule.contract,
)
assert dict(schedule.contract) == before
assert schedule.contract["noise_mode"] == NOISE_MODE_VIDEO_RANDOM_AUDIO_ZERO
assert schedule.contract["audio_policy"] == AUDIO_POLICY_LOCKED_PASSTHROUGH
assert execution["policy_authority"] == "refine_target_contract_v1"
assert execution["sigma_range"]["sigma_hash"] == schedule.contract["sigma_hash"]
assert execution["sigma_range"]["source_schedule_hash"] == schedule.contract["schedule_hash"]
assert "noise_mode" not in execution["sigma_range"]
assert "audio_policy" not in execution["sigma_range"]
def test_invalid_target_contracts_fail_before_sampling():
with pytest.raises(RefineTargetError, match="unsupported"):
make_refine_target("unknown")
called = False
def forbidden(**_kwargs):
nonlocal called
called = True
raise AssertionError("future target must stop before Sampling")
with pytest.raises(RefineTargetError, match="unsupported"):
sample_targeted_refine_chunk(
model=object(),
conditioning=[],
latent={"samples": object()},
sampler=object(),
sigmas=torch.tensor([0.2, 0.0]),
seed=1,
refine_target="unknown",
legacy_sample_fn=forbidden,
)
assert called is False
def test_targeted_video_only_sampler_delegates_every_argument_unchanged():
captured = {}
sentinel = {"samples": object()}
inputs = {
"model": object(),
"conditioning": [[torch.zeros((1, 1, 1)), {}]],
"latent": {"samples": object()},
"sampler": object(),
"sigmas": torch.tensor([0.4, 0.0]),
"seed": 99,
"enable_preview": False,
}
def delegate(**kwargs):
captured.update(kwargs)
return sentinel
result = sample_targeted_refine_chunk(
**inputs,
refine_target=MODE_VIDEO_ONLY,
legacy_sample_fn=delegate,
)
assert result is sentinel
assert captured == inputs
def _group(group_id: int, *, temporal: int, audio_t: int, terminal: bool) -> dict:
return {
"group_id": group_id,
"logical_chunks": [1] if group_id == 0 else [2, 3],
"physical_prompt": f"group {group_id + 1}",
"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": 128,
"source_height": 128,
"source_batch": 1,
"latent_channels": 24,
"source_latent_t": temporal,
"source_latent_h": 8,
"source_latent_w": 8,
"source_audio_shape": [1, 32, 2, audio_t],
}
def _fixture():
groups = [
_group(0, temporal=31, audio_t=207, terminal=False),
_group(1, temporal=65, audio_t=433, terminal=True),
]
videos = [
{"samples": torch.arange(24 * group["source_latent_t"] * 8 * 8, dtype=torch.float32).reshape(1, 24, group["source_latent_t"], 8, 8)}
for group in groups
]
audios = [
{"samples": torch.arange(32 * 2 * group["source_audio_shape"][-1], dtype=torch.float32).reshape(group["source_audio_shape"])}
for group in groups
]
plan = {
"width": 128,
"height": 128,
"second_pass_contract": {"version": 1, "physical_groups": groups},
}
return groups, videos, audios, plan
def _run(*, targeted: bool):
groups, videos, audios, plan = _fixture()
calls = []
def sample(**kwargs):
calls.append(kwargs)
return {
"video": kwargs["latent"]["video"] + float(len(calls)),
"audio": kwargs["latent"]["audio"] + 100.0,
}
common = dict(
model="model",
clip="clip",
sampler="sampler",
sigmas=torch.tensor([0.6, 0.3, 0.0], dtype=torch.float32),
video_latents=videos,
audio_latents=audios,
assembly_plan=plan,
refine_seed=73,
encode_prompt_fn=lambda _clip, prompt, **_kwargs: [prompt],
latent_builder=lambda video, audio: {"video": video, "audio": audio},
sample_fn=sample,
stream_extractor=lambda value: (value["video"], value["audio"]),
clone_model_fn=lambda source, **kwargs: (source, kwargs),
enable_preview=False,
)
if targeted:
result = run_targeted_second_pass_groups(
**common,
refine_target=MODE_VIDEO_ONLY,
)
else:
result = run_second_pass_groups(**common)
return groups, videos, audios, common["sigmas"], calls, result
def test_targeted_video_only_is_exact_legacy_second_pass_parity():
legacy = _run(targeted=False)
targeted = _run(targeted=True)
legacy_groups, _legacy_inputs, legacy_audio_inputs, legacy_sigmas, legacy_calls, legacy_result = legacy
targeted_groups, _targeted_inputs, targeted_audio_inputs, targeted_sigmas, targeted_calls, targeted_result = targeted
legacy_videos, legacy_audios, legacy_plan, legacy_status = legacy_result
targeted_videos, targeted_audios, targeted_plan, targeted_status = targeted_result
assert [_sha(item["samples"]) for item in targeted_videos] == [
_sha(item["samples"]) for item in legacy_videos
]
assert all(
output is source
for output, source in zip(targeted_audios, targeted_audio_inputs, strict=True)
)
assert all(
output is source
for output, source in zip(legacy_audios, legacy_audio_inputs, strict=True)
)
assert [call["seed"] for call in targeted_calls] == [
call["seed"] for call in legacy_calls
] == [derive_refine_seed(73, 0), derive_refine_seed(73, 1)]
assert all(call["sigmas"] is targeted_sigmas for call in targeted_calls)
assert all(call["sigmas"] is legacy_sigmas for call in legacy_calls)
assert [call["conditioning"] for call in targeted_calls] == [
call["conditioning"] for call in legacy_calls
] == [["group 1"], ["group 2"]]
assert len(targeted_calls) == len(legacy_calls) == len(legacy_groups) == len(targeted_groups) == 2
assert legacy_status == targeted_status
normalized_targeted = copy.deepcopy(targeted_plan)
target_contract = normalized_targeted["second_pass_contract"].pop(
"refine_target_contract"
)
execution_contract = normalized_targeted["second_pass_contract"].pop(
"refine_execution_contract"
)
assert normalized_targeted == legacy_plan
assert target_contract["mode"] == MODE_VIDEO_ONLY
assert execution_contract["target"] == target_contract
assert execution_contract["sigma_range"]["sigma_hash"] == (
legacy_plan["second_pass_contract"]["refine_schedule"]["sigma_hash"]
)
def test_existing_v35_public_schema_remains_frozen():
schema = H3ContinuumSecondPassV35.INPUT_TYPES()
assert list(schema["required"]) == [
"model",
"clip",
"sampler",
"sigmas",
"video_latents",
"audio_latents",
"assembly_plan",
"refine_seed",
]
assert list(schema["optional"]) == ["refine_context", "video_vae"]
assert "refine_target" not in schema["required"]
assert "refine_target" not in schema["optional"]
+522
View File
@@ -0,0 +1,522 @@
from __future__ import annotations
import inspect
import pytest
import torch
from ComfyUI_H3_Continuum_Join import reference, reference_video
from ComfyUI_H3_Continuum_Join.v3 import driving_nodes, reliability_v38
from ComfyUI_H3_Continuum_Join.v3.driving_nodes import (
H3ContinuumSamplerV37,
H3ContinuumSamplerV38,
)
from ComfyUI_H3_Continuum_Join.v3.reliability_v38 import (
V38Diagnostics,
append_v38_status,
build_frame_alignment_diagnostics,
collect_core_compatibility_advisory,
estimate_visual_conditioning_load,
format_v38_diagnostics,
validate_audio_latent_lengths,
)
def _group(
frames: int,
*,
trim: int = 0,
video_t: int,
audio_t: int,
logical=(1,),
terminal=False,
):
return {
"sequence_index": 1,
"chunk_index": 1,
"total_frames": frames,
"trim_frames": trim,
"net_frames": frames - trim,
"context_frames": trim,
"expected_video_latent_t": video_t,
"expected_audio_latent_t": audio_t,
"logical_chunk_indices": list(logical),
"terminal_merged": terminal,
}
def _plan(*groups, terminal=False):
if terminal:
return {
"chunks": [
_group(124, video_t=37, audio_t=207),
_group(141, trim=22, video_t=42, audio_t=235),
],
"decode_groups": list(groups),
}
return {"chunks": list(groups)}
def _video_latent(t: int):
return {"samples": torch.zeros(1, 24, t, 2, 2)}
def _audio_latent(t: int, *, channels=32, stereo=2):
return {"samples": torch.zeros(1, channels, stereo, t)}
def test_current_v38_public_schema_is_preserved_exactly():
v37 = H3ContinuumSamplerV37.INPUT_TYPES()
v38 = H3ContinuumSamplerV38.INPUT_TYPES()
expected_required = []
for name in v37["required"]:
if name == "width":
expected_required.extend(("aspect", "preset", "custom_mp"))
elif name != "height":
expected_required.append(name)
expected_required.extend(
(
"generation_mode",
"review_action",
"take_group",
"take_revision_id",
"take_action",
"size_source",
"width",
"height",
)
)
assert tuple(v38["required"]) == tuple(expected_required)
assert list(v38["optional"])[:-1] == list(v37["optional"])
assert list(v38["optional"])[-1] == "audio_references"
assert v38["optional"]["audio_references"][0] == (
"H3_CONTINUUM_AUDIO_REFERENCES"
)
assert v38.get("hidden") == v37.get("hidden")
assert tuple(v38["required"])[-8:] == (
"generation_mode",
"review_action",
"take_group",
"take_revision_id",
"take_action",
"size_source",
"width",
"height",
)
def test_reference_preprocessing_uses_the_new_shared_pure_size_resolver(monkeypatch):
calls = []
def fake_resolver(source_width, source_height, **kwargs):
calls.append((source_width, source_height, kwargs))
return source_width, source_height
monkeypatch.setattr(reference, "resolve_reference_image_size", fake_resolver)
image = torch.zeros(1, 64, 96, 3)
assets = reference.prepare_reference_assets(
reference_image_1=image,
reference_image_2=None,
output_width=96,
output_height=64,
size_mode=reference.REFERENCE_SIZE_MATCH_OUTPUT,
)
assert assets is not None
assert assets.images[0].shape == image.shape
assert calls == [
(
96,
64,
{
"output_width": 96,
"output_height": 64,
"size_mode": reference.REFERENCE_SIZE_MATCH_OUTPUT,
},
)
]
def test_reference_video_preprocessing_uses_shared_frame_and_size_resolvers(
monkeypatch,
):
assert reference_video._resolved_size is reference_video.resolve_reference_video_size
assert (
reference_video._resolve_reference_frame_count
is reference_video.resolve_reference_video_frame_count
)
frame_calls = []
size_calls = []
def fake_frames(source_frames, target_frames):
frame_calls.append((source_frames, target_frames))
return 5
def fake_size(source_width, source_height, **kwargs):
size_calls.append((source_width, source_height, kwargs))
return source_width, source_height
monkeypatch.setattr(
reference_video,
"resolve_reference_video_frame_count",
fake_frames,
)
monkeypatch.setattr(
reference_video,
"resolve_reference_video_size",
fake_size,
)
source = reference_video.prepare_reference_video_source(
torch.zeros(5, 32, 64, 3),
target_frames=124,
output_width=64,
output_height=32,
size_mode=reference_video.REFERENCE_VIDEO_SIZE_EFFICIENT,
)
assert source is not None
assert frame_calls == [(5, 124)]
assert size_calls == [
(
64,
32,
{
"output_width": 64,
"output_height": 32,
"size_mode": reference_video.REFERENCE_VIDEO_SIZE_EFFICIENT,
},
)
]
@pytest.mark.parametrize(
("source_frames", "expected_action"),
(
(120, "120 -> 124 (final-frame pad"),
(124, "124 -> 124 (unchanged"),
(180, "180 -> 124 (trimmed to one-chunk H3 limit"),
),
)
def test_video_guide_alignment_reports_existing_pad_unchanged_and_cap(
source_frames,
expected_action,
):
section = build_frame_alignment_diagnostics(
video_latents=[_video_latent(37)],
assembly_plan=_plan(_group(124, video_t=37, audio_t=207)),
video_guide=torch.zeros(source_frames, 32, 64, 3),
chunk_seconds=5.0,
)
assert expected_action in "\n".join(section.detailed)
if source_frames == 124:
assert not section.basic
else:
assert expected_action in "\n".join(section.basic)
def test_frame_grid_uses_terminal_physical_group_and_advises_on_actual_t_mismatch():
terminal = _group(
260,
trim=22,
video_t=77,
audio_t=433,
logical=(2, 3),
terminal=True,
)
passed = build_frame_alignment_diagnostics(
video_latents=[_video_latent(77)],
assembly_plan=_plan(terminal, terminal=True),
chunk_seconds=5.0,
)
assert not passed.basic
assert "frames=260" in passed.detailed[0]
assert "video_t=77" in passed.detailed[0]
assert passed.detailed[0].endswith("PASS.")
failed = build_frame_alignment_diagnostics(
video_latents=[_video_latent(76)],
assembly_plan=_plan(terminal, terminal=True),
chunk_seconds=5.0,
)
assert "actual T differs" in "\n".join(failed.basic)
assert failed.detailed[0].endswith("ADVISORY.")
def test_frame_grid_advises_on_physical_output_count_mismatch():
section = build_frame_alignment_diagnostics(
video_latents=[],
assembly_plan=_plan(_group(124, video_t=37, audio_t=207)),
chunk_seconds=5.0,
)
assert "output count 0 does not match group count 1" in "\n".join(section.basic)
def test_audio_validation_passes_normal_and_terminal_physical_groups():
first = _group(124, video_t=37, audio_t=207)
terminal = _group(
260,
trim=22,
video_t=77,
audio_t=433,
logical=(2, 3),
terminal=True,
)
section = validate_audio_latent_lengths(
audio_latents=[_audio_latent(207), _audio_latent(433)],
assembly_plan=_plan(first, terminal, terminal=True),
)
assert not section.basic
assert len(section.detailed) == 2
assert all(line.endswith("PASS.") for line in section.detailed)
assert "phase=0.333333" in section.detailed[0]
assert "phase=-0.333333" in section.detailed[1]
@pytest.mark.parametrize(
("latent", "expected"),
(
({}, "samples are missing"),
({"samples": "not-a-tensor"}, "not a Tensor"),
({"samples": torch.zeros(1, 32, 207)}, "rank is 3"),
(_audio_latent(207, channels=31), "channels=31"),
(_audio_latent(207, stereo=1), "stereo=1"),
(_audio_latent(0), "T must be positive"),
),
)
def test_audio_validation_reports_shape_advisories(latent, expected):
section = validate_audio_latent_lengths(
audio_latents=[latent],
assembly_plan=_plan(_group(124, video_t=37, audio_t=207)),
)
assert expected in "\n".join(section.basic)
def test_audio_validation_reports_metadata_delta_phase_and_count():
section = validate_audio_latent_lengths(
audio_latents=[_audio_latent(206)],
assembly_plan=_plan(
_group(124, video_t=37, audio_t=207),
_group(141, trim=22, video_t=42, audio_t=235),
),
)
text = "\n".join(section.basic)
assert "output count 1 does not match group count 2" in text
assert "metadata=207 actual=206 delta=-1" in text
assert "phase=-0.666667" in text
def test_audio_validation_does_not_copy_or_modify_tensor():
samples = torch.arange(1 * 32 * 2 * 207, dtype=torch.float32).reshape(
1, 32, 2, 207
)
before = samples.clone()
pointer = samples.data_ptr()
latents = [{"samples": samples}]
section = validate_audio_latent_lengths(
audio_latents=latents,
assembly_plan=_plan(_group(124, video_t=37, audio_t=207)),
)
assert not section.basic
assert latents[0]["samples"] is samples
assert samples.data_ptr() == pointer
assert torch.equal(samples, before)
source = inspect.getsource(validate_audio_latent_lengths)
for forbidden in (".clone(", ".cpu(", ".to(", ".numpy(", "contiguous("):
assert forbidden not in source
def test_core_advisory_basic_detailed_deduplicates_and_never_gates():
compatible = collect_core_compatibility_advisory(lambda: [])
assert compatible.basic == ()
assert "native MiniMax H3 contracts detected" in compatible.detailed[0]
issues = collect_core_compatibility_advisory(
lambda: ["PackedLayout changed", "PackedLayout changed", "rows missing"]
)
assert "2 native H3 contract difference" in issues.basic[0]
assert len(issues.detailed) == 2
unavailable = collect_core_compatibility_advisory(
lambda: (_ for _ in ()).throw(RuntimeError("probe failed"))
)
assert "generation result was preserved" in unavailable.basic[0]
assert "RuntimeError: probe failed" in unavailable.detailed[0]
@pytest.mark.parametrize(
("value", "expected"),
(
(0.749999, "Low"),
(0.75, "Medium"),
(1.749999, "Medium"),
(1.75, "High"),
),
)
def test_visual_load_classification_boundaries(value, expected):
assert reliability_v38._visual_load_class(value) == expected
def test_visual_load_uses_existing_efficient_geometry_and_temporal_ratio():
section = estimate_visual_conditioning_load(
output_width=1344,
output_height=768,
reference_images=(),
reference_size=reference.REFERENCE_SIZE_MATCH_OUTPUT,
video_guide=torch.zeros(120, 1080, 1920, 3),
video_guide_size=reference_video.REFERENCE_VIDEO_SIZE_EFFICIENT,
chunk_seconds=5.0,
still_guide_active=False,
)
assert section.basic == (
"Visual conditioning load: Low (peak per physical group).",
)
assert "total=0.387 class=Low" in section.detailed[0]
assert "Video Guide=832x480/124f=0.387" in section.detailed[0]
def test_visual_load_adds_reference_images_but_excludes_still_guide():
reference_image = torch.zeros(1, 768, 1024, 3)
section = estimate_visual_conditioning_load(
output_width=1024,
output_height=768,
reference_images=(reference_image, reference_image, reference_image),
reference_size=reference.REFERENCE_SIZE_MATCH_OUTPUT,
video_guide=None,
chunk_seconds=5.0,
still_guide_active=True,
)
assert "High" in section.basic[0]
assert "Still Guide active" in section.basic[0]
assert "total=3.000" in section.detailed[0]
assert "Still Guide=active" in section.detailed[0]
assert "Ref1=1024x768=1.000" in section.detailed[0]
assert "Ref3=1024x768=1.000" in section.detailed[0]
def test_still_guide_only_is_reported_without_numeric_total():
section = estimate_visual_conditioning_load(
output_width=1024,
output_height=768,
reference_images=(),
reference_size=reference.REFERENCE_SIZE_MATCH_OUTPUT,
video_guide=None,
chunk_seconds=5.0,
still_guide_active=True,
)
assert section.basic == ("Still Guide: active.",)
assert "excluded from numeric visual load" in section.detailed[0]
def test_visual_load_inspects_shapes_only_and_has_no_chunk_or_storage_input():
signature = inspect.signature(estimate_visual_conditioning_load)
assert "chunks" not in signature.parameters
assert "run_storage" not in signature.parameters
source = inspect.getsource(estimate_visual_conditioning_load)
for forbidden in (
".clone(",
".cpu(",
".to(",
".numpy(",
"encode(",
"_tensor_hash",
"common_upscale",
):
assert forbidden not in source
def test_basic_detailed_and_off_status_formatting():
diagnostics = V38Diagnostics(
basic=("Basic issue.",),
detailed=("Detailed PASS.",),
)
assert format_v38_diagnostics(diagnostics, mode="Basic") == (
"V3.8 Reliability\nBasic issue."
)
assert format_v38_diagnostics(diagnostics, mode="Detailed Report") == (
"V3.8 Reliability\nDetailed PASS."
)
assert format_v38_diagnostics(diagnostics, mode="Off") == ""
assert append_v38_status("Original", diagnostics, mode="Off") == "Original"
assert append_v38_status("Original", diagnostics, mode="Basic") == (
"Original\nV3.8 Reliability\nBasic issue."
)
def test_v38_wrapper_preserves_every_non_status_output_identity(monkeypatch):
video = [_video_latent(37)]
audio = [_audio_latent(207)]
plan = _plan(_group(124, video_t=37, audio_t=207))
driving_audio = object()
refine_context = object()
def fake_v37_run(self, **kwargs):
return video, audio, plan, "Original status", driving_audio, refine_context
monkeypatch.setattr(H3ContinuumSamplerV37, "run", fake_v37_run)
monkeypatch.setattr(
driving_nodes,
"build_v38_diagnostics",
lambda **kwargs: V38Diagnostics(("Basic diagnostic.",), ("Detailed.",)),
)
outputs = H3ContinuumSamplerV38().run(
chunk_seconds=5.0,
diagnostics="Basic",
)
assert outputs[0] is video
assert outputs[1] is audio
assert outputs[2] is plan
assert outputs[4] is driving_audio
assert outputs[5] is refine_context
assert outputs[3] == (
"Original status\nV3.8 Reliability\nBasic diagnostic."
)
def test_v38_wrapper_preserves_generation_when_diagnostics_raise(monkeypatch):
outputs = (
[_video_latent(37)],
[_audio_latent(207)],
_plan(_group(124, video_t=37, audio_t=207)),
"Original status",
object(),
)
monkeypatch.setattr(H3ContinuumSamplerV37, "run", lambda self, **kwargs: outputs)
monkeypatch.setattr(
driving_nodes,
"build_v38_diagnostics",
lambda **kwargs: (_ for _ in ()).throw(RuntimeError("diagnostic failed")),
)
result = H3ContinuumSamplerV38().run(
chunk_seconds=5.0,
diagnostics="Detailed Report",
)
assert result[0] is outputs[0]
assert result[1] is outputs[1]
assert result[2] is outputs[2]
assert result[4] is outputs[4]
assert "generation result was preserved" in result[3]
assert "RuntimeError: diagnostic failed" in result[3]
def test_v38_wrapper_keeps_non_tuple_test_double_unchanged(monkeypatch):
monkeypatch.setattr(H3ContinuumSamplerV37, "run", lambda self, **kwargs: "ok")
assert H3ContinuumSamplerV38().run() == "ok"
def test_v38_wrapper_diagnostics_off_skips_all_reliability_work(monkeypatch):
outputs = (
[_video_latent(37)],
[_audio_latent(207)],
_plan(_group(124, video_t=37, audio_t=207)),
"Original status",
)
monkeypatch.setattr(H3ContinuumSamplerV37, "run", lambda self, **kwargs: outputs)
def fail_if_called(**kwargs):
raise AssertionError("diagnostics must not run when Report Detail is Off")
monkeypatch.setattr(driving_nodes, "build_v38_diagnostics", fail_if_called)
result = H3ContinuumSamplerV38().run(
chunk_seconds=5.0,
diagnostics="Off",
)
assert result is outputs
+542
View File
@@ -0,0 +1,542 @@
from __future__ import annotations
import json
from pathlib import Path
import shutil
import subprocess
import pytest
from ComfyUI_H3_Continuum_Join import nodes as root_nodes
from ComfyUI_H3_Continuum_Join.v3.driving_nodes import (
H3ContinuumSamplerV37,
H3ContinuumSamplerV38,
NODE_CLASS_MAPPINGS,
NODE_DISPLAY_NAME_MAPPINGS,
)
from ComfyUI_H3_Continuum_Join.v3.easy_nodes import resolve_easy_resolution
from ComfyUI_H3_Continuum_Join.v3.resolution import (
H3_ASPECT_AUTO,
H3_ASPECT_LANDSCAPE,
H3_ASPECT_OPTIONS,
H3_ASPECT_PORTRAIT,
H3_ASPECT_SQUARE,
H3_CANVAS_MAX,
H3_CANVAS_MIN,
H3_CANVAS_MULTIPLE,
H3_CUSTOM_MP_MAX,
H3_CUSTOM_MP_MIN,
H3_MANUAL_HEIGHT_DEFAULT,
H3_MANUAL_WIDTH_DEFAULT,
H3_PRESET_BALANCED,
H3_PRESET_CUSTOM,
H3_PRESET_DRAFT,
H3_PRESET_NATIVE,
H3_PRESET_OPTIONS,
H3_SIZE_SOURCE_FIRST_IMAGE,
H3_SIZE_SOURCE_LEGACY,
H3_SIZE_SOURCE_MANUAL,
H3_SIZE_SOURCE_OPTIONS,
resolve_h3_resolution,
resolve_h3_size_source,
)
ROOT = Path(__file__).resolve().parents[1]
class _Image:
def __init__(self, height: int, width: int):
self.shape = (1, height, width, 3)
@pytest.mark.parametrize("aspect", H3_ASPECT_OPTIONS)
@pytest.mark.parametrize("preset", H3_PRESET_OPTIONS)
def test_main_and_easy_share_exact_resolution_results(aspect, preset):
first = _Image(900, 1200)
custom_mp = 1.23
main = resolve_h3_resolution(
aspect=aspect,
preset=preset,
custom_mp=custom_mp,
first_frame=first,
)
easy = resolve_easy_resolution(
aspect=aspect,
preset=preset,
custom_mp=custom_mp,
first_frame=first,
)
assert main == easy
assert main.width % 32 == 0
assert main.height % 32 == 0
@pytest.mark.parametrize(
("first", "orientation"),
(
(_Image(720, 1280), "landscape"),
(_Image(1280, 720), "portrait"),
(_Image(900, 900), "square"),
),
)
def test_auto_uses_first_image_geometry(first, orientation):
plan = resolve_h3_resolution(
aspect=H3_ASPECT_AUTO,
preset=H3_PRESET_DRAFT,
first_frame=first,
)
assert plan.aspect_source == "First Image"
if orientation == "landscape":
assert plan.width > plan.height
elif orientation == "portrait":
assert plan.width < plan.height
else:
assert plan.width == plan.height
def test_auto_without_first_image_preserves_easy_landscape_fallback():
auto = resolve_h3_resolution(
aspect=H3_ASPECT_AUTO,
preset=H3_PRESET_DRAFT,
)
landscape = resolve_h3_resolution(
aspect=H3_ASPECT_LANDSCAPE,
preset=H3_PRESET_DRAFT,
)
assert (auto.width, auto.height) == (landscape.width, landscape.height)
assert auto.aspect_source == "Landscape 16:9 fallback"
@pytest.mark.parametrize(
("preset", "target_mp", "tolerance"),
(
(H3_PRESET_DRAFT, 0.30, 0.04),
(H3_PRESET_BALANCED, 0.60, 0.05),
),
)
def test_decimal_mp_presets_are_near_their_targets(preset, target_mp, tolerance):
for aspect in (
H3_ASPECT_LANDSCAPE,
H3_ASPECT_PORTRAIT,
H3_ASPECT_SQUARE,
):
plan = resolve_h3_resolution(aspect=aspect, preset=preset)
assert abs(plan.actual_mp - target_mp) <= tolerance
@pytest.mark.parametrize("custom_mp", (H3_CUSTOM_MP_MIN, 0.37, 2.50, H3_CUSTOM_MP_MAX))
def test_custom_mp_range_and_alignment(custom_mp):
plan = resolve_h3_resolution(
aspect=H3_ASPECT_PORTRAIT,
preset=H3_PRESET_CUSTOM,
custom_mp=custom_mp,
)
assert plan.width % 32 == plan.height % 32 == 0
assert plan.preset == H3_PRESET_CUSTOM
@pytest.mark.parametrize("custom_mp", (H3_CUSTOM_MP_MIN - 0.01, H3_CUSTOM_MP_MAX + 0.01, True))
def test_custom_mp_validation_matches_easy(custom_mp):
with pytest.raises((TypeError, ValueError)):
resolve_h3_resolution(
aspect=H3_ASPECT_SQUARE,
preset=H3_PRESET_CUSTOM,
custom_mp=custom_mp,
)
def test_invalid_aspect_and_preset_preserve_existing_easy_fallback_contract():
invalid_aspect = resolve_h3_resolution(
aspect="invalid",
preset=H3_PRESET_DRAFT,
)
landscape = resolve_h3_resolution(
aspect=H3_ASPECT_LANDSCAPE,
preset=H3_PRESET_DRAFT,
)
invalid_preset = resolve_h3_resolution(
aspect=H3_ASPECT_SQUARE,
preset="invalid",
custom_mp=0.42,
)
custom = resolve_h3_resolution(
aspect=H3_ASPECT_SQUARE,
preset=H3_PRESET_CUSTOM,
custom_mp=0.42,
)
assert (invalid_aspect.width, invalid_aspect.height) == (
landscape.width,
landscape.height,
)
assert invalid_preset == custom
def test_v38_schema_keeps_legacy_aspect_and_appends_size_source_contract():
v37 = H3ContinuumSamplerV37.INPUT_TYPES()
v38 = H3ContinuumSamplerV38.INPUT_TYPES()
assert "width" in v37["required"]
assert "height" in v37["required"]
assert list(v38["required"])[-3:] == ["size_source", "width", "height"]
assert tuple(name for name in v38["required"] if name in {"aspect", "preset", "custom_mp"}) == (
"aspect",
"preset",
"custom_mp",
)
assert v38["required"]["aspect"][0] == H3_ASPECT_OPTIONS
assert v38["required"]["preset"][0] == H3_PRESET_OPTIONS
assert v38["required"]["custom_mp"][1]["min"] == H3_CUSTOM_MP_MIN
assert v38["required"]["custom_mp"][1]["max"] == H3_CUSTOM_MP_MAX
assert v38["required"]["aspect"][1]["advanced"] is True
assert v38["required"]["size_source"][0] == H3_SIZE_SOURCE_OPTIONS
assert v38["required"]["size_source"][1]["default"] == H3_SIZE_SOURCE_LEGACY
assert v38["required"]["width"][1] == {
"default": H3_MANUAL_WIDTH_DEFAULT,
"min": H3_CANVAS_MIN,
"max": H3_CANVAS_MAX,
"step": H3_CANVAS_MULTIPLE,
"display_name": "Width",
"tooltip": (
"Exact output width in Manual mode. Use a multiple of 32. Manual mode is "
"the normal choice for T2VA or workflows without a First Image."
),
}
assert list(v38["optional"])[:-1] == list(v37["optional"])
assert list(v38["optional"])[-1] == "audio_references"
assert v38["optional"]["audio_references"][0] == (
"H3_CONTINUUM_AUDIO_REFERENCES"
)
assert v38.get("hidden") == v37.get("hidden")
def test_v38_registration_is_the_public_sampler_surface():
assert NODE_CLASS_MAPPINGS["H3ContinuumSamplerV38"] is H3ContinuumSamplerV38
assert NODE_DISPLAY_NAME_MAPPINGS["H3ContinuumSamplerV38"] == (
"H3 Continuum Sampler V3.8"
)
assert root_nodes.NODE_CLASS_MAPPINGS["H3ContinuumSamplerV38"] is (
H3ContinuumSamplerV38
)
assert H3ContinuumSamplerV38.DEPRECATED is False
assert "H3ContinuumSamplerV37" not in root_nodes.NODE_CLASS_MAPPINGS
def test_v38_facade_passes_only_resolved_geometry_to_v37(monkeypatch):
captured = {}
def fake_v37_run(self, **kwargs):
captured.update(kwargs)
return "ok"
monkeypatch.setattr(H3ContinuumSamplerV37, "run", fake_v37_run)
result = H3ContinuumSamplerV38().run(
size_source=H3_SIZE_SOURCE_FIRST_IMAGE,
aspect=H3_ASPECT_AUTO,
preset=H3_PRESET_NATIVE,
custom_mp=0.30,
first_frame=_Image(1200, 900),
project_id="stable-project",
)
expected = resolve_h3_size_source(
size_source=H3_SIZE_SOURCE_FIRST_IMAGE,
preset=H3_PRESET_NATIVE,
first_frame=_Image(1200, 900),
)
assert result == "ok"
assert (captured["width"], captured["height"]) == (
expected.width,
expected.height,
)
assert captured["project_id"] == "stable-project"
assert "aspect" not in captured
assert "preset" not in captured
assert "custom_mp" not in captured
assert "size_source" not in captured
def test_run_storage_resolution_identity_uses_resolved_width_and_height(monkeypatch):
captured = []
def fake_v37_run(self, **kwargs):
captured.append(kwargs)
return "ok"
monkeypatch.setattr(H3ContinuumSamplerV37, "run", fake_v37_run)
node = H3ContinuumSamplerV38()
node.run(
size_source=H3_SIZE_SOURCE_MANUAL,
width=768,
height=768,
preset=H3_PRESET_BALANCED,
)
node.run(
size_source=H3_SIZE_SOURCE_MANUAL,
width=768,
height=768,
preset=H3_PRESET_CUSTOM,
custom_mp=0.589824,
)
assert [(value["width"], value["height"]) for value in captured] == [
(768, 768),
(768, 768),
]
assert all("preset" not in value for value in captured)
@pytest.mark.parametrize(
("height", "width"),
((720, 1280), (1280, 720), (900, 900), (800, 1200), (1200, 800)),
)
@pytest.mark.parametrize(
"preset",
(H3_PRESET_DRAFT, H3_PRESET_BALANCED, H3_PRESET_NATIVE),
)
def test_first_image_size_source_preserves_unusual_aspects(height, width, preset):
image = _Image(height, width)
plan = resolve_h3_size_source(
size_source=H3_SIZE_SOURCE_FIRST_IMAGE,
preset=preset,
first_frame=image,
)
legacy = resolve_h3_resolution(
aspect=H3_ASPECT_AUTO,
preset=preset,
first_frame=image,
)
assert plan == legacy
assert plan.width % 32 == plan.height % 32 == 0
assert abs(plan.aspect_ratio - width / height) < 1e-12
def test_first_image_missing_fails_open_to_visible_manual_canvas():
plan = resolve_h3_size_source(
size_source=H3_SIZE_SOURCE_FIRST_IMAGE,
width=704,
height=1024,
preset=H3_PRESET_BALANCED,
)
assert (plan.width, plan.height) == (704, 1024)
assert plan.aspect_source == "Manual Width / Height"
assert "First Image is unavailable" in plan.warnings[0]
def test_v38_status_reports_exact_resolved_canvas_and_missing_image_fallback(monkeypatch):
def fake_v37_run(self, **kwargs):
return ("video", "audio", {}, "Base status", None, None)
monkeypatch.setattr(H3ContinuumSamplerV37, "run", fake_v37_run)
outputs = H3ContinuumSamplerV38().run(
size_source=H3_SIZE_SOURCE_FIRST_IMAGE,
width=704,
height=1024,
diagnostics="Off",
)
assert "Resolution: 704 x 1024 (0.72 MP)" in outputs[3]
assert "source=Manual Width / Height" in outputs[3]
assert "First Image is unavailable" in outputs[3]
@pytest.mark.parametrize(
("width", "height"),
((1024, 576), (576, 1024), (768, 768), (704, 1024), (960, 640)),
)
def test_manual_size_source_uses_exact_aligned_dimensions(width, height):
plan = resolve_h3_size_source(
size_source=H3_SIZE_SOURCE_MANUAL,
width=width,
height=height,
preset=H3_PRESET_DRAFT,
)
assert (plan.width, plan.height) == (width, height)
assert plan.target_mp is None
assert plan.preset == "Manual"
@pytest.mark.parametrize("width,height", ((703, 1024), (704, 1023), (0, 32), (32, 16416)))
def test_manual_size_source_rejects_unaligned_or_out_of_range_canvas(width, height):
with pytest.raises(ValueError):
resolve_h3_size_source(
size_source=H3_SIZE_SOURCE_MANUAL,
width=width,
height=height,
)
@pytest.mark.parametrize("aspect", H3_ASPECT_OPTIONS)
def test_legacy_size_source_remains_bit_exact_for_old_api_prompts(aspect):
legacy = resolve_h3_size_source(
size_source=H3_SIZE_SOURCE_LEGACY,
aspect=aspect,
preset=H3_PRESET_BALANCED,
first_frame=_Image(900, 1200),
)
expected = resolve_h3_resolution(
aspect=aspect,
preset=H3_PRESET_BALANCED,
first_frame=_Image(900, 1200),
)
assert legacy == expected
def test_project_frontend_applies_v37_controls_and_custom_mp_visibility_to_v38():
source = (ROOT / "web" / "project_id.js").read_text(encoding="utf-8")
assert 'const V38_NODE_CLASS = "H3ContinuumSamplerV38";' in source
assert "isV35 || isV36 || isV37 || isV38" in source
assert 'node.comfyClass === V38_NODE_CLASS' in source
assert 'presetWidget?.value === CUSTOM_RESOLUTION_PRESET' in source
assert 'attachRefresh(presetWidget, "__h3ContinuumResolutionPresetCallback", refresh);' in source
assert 'const SIZE_SOURCE_WIDGET = "size_source";' in source
assert "migrateLegacyAspect();" in source
assert "sizeSourceWidget.options.values = [SIZE_SOURCE_FIRST_IMAGE, SIZE_SOURCE_MANUAL]" in source
assert "widthWidget.disabled = firstImage" in source
def _js_function(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_size_source_frontend_migrates_legacy_and_disables_the_correct_widgets(tmp_path):
node_executable = shutil.which("node")
if node_executable is None:
pytest.skip("Node.js is required for the frontend behavior regression")
source = (ROOT / "web" / "project_id.js").read_text(encoding="utf-8")
functions = "\n".join(
(
_js_function(source, "findWidget", "setWidgetVisible"),
_js_function(source, "setWidgetVisible", "hidePersistentWidget"),
_js_function(source, "hidePersistentWidget", "settingValue"),
_js_function(source, "attachRefresh", "transientProductionWidgets"),
_js_function(
source,
"configureResolutionPresetWidgets",
"isOneShotReviewAction",
),
)
)
script = f"""
const V38_NODE_CLASS = "H3ContinuumSamplerV38";
const RESOLUTION_PRESET_WIDGET = "preset";
const CUSTOM_MP_WIDGET = "custom_mp";
const CUSTOM_RESOLUTION_PRESET = "Custom";
const LEGACY_ASPECT_WIDGET = "aspect";
const SIZE_SOURCE_WIDGET = "size_source";
const WIDTH_WIDGET = "width";
const HEIGHT_WIDGET = "height";
const SIZE_SOURCE_FIRST_IMAGE = "First Image";
const SIZE_SOURCE_MANUAL = "Manual";
const SIZE_SOURCE_LEGACY = "Legacy Aspect";
const RESOLUTION_PRESET_DRAFT = "Draft — 0.30 MP";
const RESOLUTION_PRESET_BALANCED = "Balanced — 0.60 MP";
const RESOLUTION_PRESET_NATIVE = "Native 768";
const CANVAS_MULTIPLE = 32;
const NATIVE_SHORT_EDGE = 768;
const NATIVE_LONG_EDGE_CAP = 1344;
const imageSource = {{ mode: 0, imgs: [{{ naturalWidth: 1200, naturalHeight: 800 }}] }};
const app = {{ graph: {{ links: {{ 1: {{ origin_id: 9 }} }}, getNodeById: () => imageSource }} }};
{functions}
function widget(name, value) {{
return {{ name, value, type: "combo", options: {{}}, computeSize: () => [120, 20] }};
}}
function makeNode(aspect, sizeSource, width, height, linked = false) {{
return {{
comfyClass: V38_NODE_CLASS,
widgets: [
widget(LEGACY_ASPECT_WIDGET, aspect),
widget(RESOLUTION_PRESET_WIDGET, RESOLUTION_PRESET_BALANCED),
widget(CUSTOM_MP_WIDGET, 0.3),
widget(SIZE_SOURCE_WIDGET, sizeSource),
widget(WIDTH_WIDGET, width),
widget(HEIGHT_WIDGET, height),
],
inputs: [{{ name: "first_frame", link: linked ? 1 : null }}],
configure(info) {{
info.widgets_values.forEach((value, index) => {{
this.widgets[index].value = value;
}});
}},
setDirtyCanvas() {{}},
}};
}}
const legacy = makeNode("Landscape 16:9", SIZE_SOURCE_LEGACY, 736, 416);
configureResolutionPresetWidgets(legacy);
const first = makeNode("Auto from First Image", SIZE_SOURCE_FIRST_IMAGE, 736, 416, true);
configureResolutionPresetWidgets(first);
const manual = makeNode("Auto from First Image", SIZE_SOURCE_MANUAL, 704, 1024);
configureResolutionPresetWidgets(manual);
const oldLoad = makeNode("Auto from First Image", SIZE_SOURCE_LEGACY, 736, 416);
configureResolutionPresetWidgets(oldLoad);
oldLoad.configure({{ widgets_values: [
"Landscape 16:9",
RESOLUTION_PRESET_BALANCED,
0.3,
] }});
const savedManual = makeNode("Auto from First Image", SIZE_SOURCE_LEGACY, 736, 416);
configureResolutionPresetWidgets(savedManual);
savedManual.configure({{ widgets_values: [
"Auto from First Image",
RESOLUTION_PRESET_BALANCED,
0.3,
SIZE_SOURCE_MANUAL,
704,
1024,
] }});
function observed(node) {{
return {{
source: findWidget(node, SIZE_SOURCE_WIDGET).value,
sourceOptions: findWidget(node, SIZE_SOURCE_WIDGET).options.values,
width: findWidget(node, WIDTH_WIDGET).value,
height: findWidget(node, HEIGHT_WIDGET).value,
widthDisabled: findWidget(node, WIDTH_WIDGET).disabled,
presetDisabled: findWidget(node, RESOLUTION_PRESET_WIDGET).disabled,
aspectHidden: findWidget(node, LEGACY_ASPECT_WIDGET).hidden,
}};
}}
console.log(JSON.stringify({{
legacy: observed(legacy),
first: observed(first),
manual: observed(manual),
oldLoad: observed(oldLoad),
savedManual: observed(savedManual),
}}));
"""
script_path = tmp_path / "resolution_ux.mjs"
script_path.write_text(script, encoding="utf-8")
completed = subprocess.run(
[node_executable, str(script_path)],
check=True,
capture_output=True,
text=True,
encoding="utf-8",
)
observed = json.loads(completed.stdout)
assert observed["legacy"] == {
"source": "Manual",
"sourceOptions": ["First Image", "Manual"],
"width": 1024,
"height": 576,
"widthDisabled": False,
"presetDisabled": True,
"aspectHidden": True,
}
assert observed["first"] == {
"source": "First Image",
"sourceOptions": ["First Image", "Manual"],
"width": 960,
"height": 640,
"widthDisabled": True,
"presetDisabled": False,
"aspectHidden": True,
}
assert observed["manual"] == {
"source": "Manual",
"sourceOptions": ["First Image", "Manual"],
"width": 704,
"height": 1024,
"widthDisabled": False,
"presetDisabled": True,
"aspectHidden": True,
}
assert observed["oldLoad"] == observed["legacy"]
assert observed["savedManual"] == observed["manual"]
+219
View File
@@ -0,0 +1,219 @@
from __future__ import annotations
import json
import math
import os
from pathlib import Path
import subprocess
import sys
import textwrap
import pytest
from ComfyUI_H3_Continuum_Join.v3.driving_nodes import (
H3ContinuumSamplerV37,
H3ContinuumSamplerV38,
)
from ComfyUI_H3_Continuum_Join.v3.easy_nodes import H3ContinuumEasyV38
from ComfyUI_H3_Continuum_Join.v3.review_control import (
GENERATION_MODE_FULL_RUN,
GENERATION_MODE_REVIEW,
REVIEW_ACTION_CONTINUE,
REVIEW_ACTION_FINISH_REMAINING,
REVIEW_ACTION_REGENERATE_CURRENT,
)
ROOT = Path(__file__).resolve().parents[1]
DEFAULT_COMFY_ROOT = Path(
os.environ.get(
"H3_CONTINUUM_COMFY_ROOT",
r"D:\StabilityMatrix\Data\Packages\ComfyUI_W",
)
)
@pytest.mark.parametrize(
"review_action",
(
REVIEW_ACTION_CONTINUE,
REVIEW_ACTION_REGENERATE_CURRENT,
REVIEW_ACTION_FINISH_REMAINING,
),
)
def test_v38_review_is_always_changed_for_every_review_action(review_action):
first = H3ContinuumSamplerV38.IS_CHANGED(
generation_mode=GENERATION_MODE_REVIEW,
review_action=review_action,
unrelated_current_input="accepted through Core kwargs",
)
second = H3ContinuumSamplerV38.IS_CHANGED(
generation_mode=GENERATION_MODE_REVIEW,
review_action=review_action,
)
assert math.isnan(first)
assert math.isnan(second)
assert first != second
@pytest.mark.parametrize(
"review_action",
(
REVIEW_ACTION_CONTINUE,
REVIEW_ACTION_REGENERATE_CURRENT,
REVIEW_ACTION_FINISH_REMAINING,
),
)
def test_v38_full_run_keeps_stable_core_cache_behavior(review_action):
assert H3ContinuumSamplerV38.IS_CHANGED(
generation_mode=GENERATION_MODE_FULL_RUN,
review_action=review_action,
) is False
def test_v37_and_easy_do_not_inherit_the_v38_cache_contract():
assert "IS_CHANGED" not in H3ContinuumSamplerV37.__dict__
assert "IS_CHANGED" not in H3ContinuumEasyV38.__dict__
assert not hasattr(H3ContinuumSamplerV37, "IS_CHANGED")
assert not hasattr(H3ContinuumEasyV38, "IS_CHANGED")
def test_real_comfy_cache_signature_is_stable_only_for_full_run(tmp_path):
comfy_root = DEFAULT_COMFY_ROOT
if not (comfy_root / "execution.py").is_file():
pytest.skip("A real ComfyUI runtime is required for the Core cache harness")
harness = tmp_path / "v38-review-core-cache-harness.py"
harness.write_text(
textwrap.dedent(
f"""
import asyncio
import importlib.util
import json
import os
from pathlib import Path
import sys
def block_cuda(*args, **kwargs):
raise BaseException("CPU cache harness requested CUDA initialization")
def early_profile(frame, event, arg):
if event == "c_call" and getattr(arg, "__name__", "") == "_cuda_init":
block_cuda()
sys.setprofile(early_profile)
import torch
assert not torch.cuda.is_initialized()
torch.cuda._lazy_init = block_cuda
torch._C._cuda_init = block_cuda
sys.setprofile(None)
comfy_root = Path({str(comfy_root)!r})
plugin_root = Path({str(ROOT)!r})
os.chdir(comfy_root)
sys.path.insert(0, str(comfy_root))
# Core imports must stay CPU-only; Kitchen's import-time INT8
# capability check otherwise asks for GPU capability even in CPU mode.
sys.argv = [str(__file__), "--cpu"]
import comfy.options
comfy.options.enable_args_parsing()
from comfy.cli_args import args
assert args.cpu
# This harness tests Core cache keys, not a GPU attention kernel.
# Optional SageAttention probes GPU capability at import time even
# with Core --cpu. Model an absent optional extension in this child
# only; leave installed packages and all CUDA tripwires unchanged.
sys.modules["sageattention"] = None
if importlib.util.find_spec("comfy_kitchen") is not None:
import comfy_kitchen
comfy_kitchen.int8_attention_is_available = lambda *a, **k: False
import nodes as comfy_nodes
from comfy_execution.caching import CacheKeySetInputSignature
from comfy_execution.graph import DynamicPrompt
from execution import IsChangedCache
package_name = "H3ContinuumPhaseFR1Source"
spec = importlib.util.spec_from_file_location(
package_name,
plugin_root / "__init__.py",
submodule_search_locations=[str(plugin_root)],
)
package = importlib.util.module_from_spec(spec)
package.__path__ = [str(plugin_root)]
sys.modules[package_name] = package
spec.loader.exec_module(package)
class_type = "H3ContinuumSamplerV38PhaseFR1Probe"
comfy_nodes.NODE_CLASS_MAPPINGS[class_type] = (
package.NODE_CLASS_MAPPINGS["H3ContinuumSamplerV38"]
)
async def signature(mode, action):
prompt = {{
"305": {{
"class_type": class_type,
"inputs": {{
"generation_mode": mode,
"review_action": action,
}},
}}
}}
dynprompt = DynamicPrompt(prompt)
changed = IsChangedCache("phase-f-r1", dynprompt, None)
keys = CacheKeySetInputSignature(dynprompt, ["305"], changed)
await keys.add_keys(["305"])
return keys.get_data_key("305")
async def main():
full_1 = await signature("Full Run", "Continue / Next")
full_2 = await signature("Full Run", "Continue / Next")
review_continue_1 = await signature(
"Review Each Chunk", "Continue / Next"
)
review_continue_2 = await signature(
"Review Each Chunk", "Continue / Next"
)
review_regen_1 = await signature(
"Review Each Chunk", "Regenerate Current"
)
review_regen_2 = await signature(
"Review Each Chunk", "Regenerate Current"
)
review_finish_1 = await signature(
"Review Each Chunk", "Finish Remaining"
)
review_finish_2 = await signature(
"Review Each Chunk", "Finish Remaining"
)
print(json.dumps({{
"full_stable": full_1 == full_2,
"review_continue_changed": review_continue_1 != review_continue_2,
"review_regenerate_changed": review_regen_1 != review_regen_2,
"review_finish_changed": review_finish_1 != review_finish_2,
"cpu_mode": args.cpu,
"cuda_initialized": torch.cuda.is_initialized(),
}}))
asyncio.run(main())
"""
),
encoding="utf-8",
)
result = subprocess.run(
[sys.executable, str(harness)],
cwd=comfy_root,
check=True,
capture_output=True,
text=True,
)
observed = json.loads(result.stdout.strip().splitlines()[-1])
assert observed == {
"full_stable": True,
"review_continue_changed": True,
"review_regenerate_changed": True,
"review_finish_changed": True,
"cpu_mode": True,
"cuda_initialized": False,
}
+451
View File
@@ -0,0 +1,451 @@
from __future__ import annotations
import pytest
from ComfyUI_H3_Continuum_Join.v3.review_control import (
EXECUTION_MODE_FULL_RUN,
EXECUTION_MODE_REVIEW_CONTINUE,
EXECUTION_MODE_REVIEW_FINISH,
EXECUTION_MODE_REVIEW_REGENERATE,
EXECUTION_MODE_REVIEW_CONTINUE_FROM_TAKE,
EXECUTION_MODE_REVIEW_USE_TAKE,
GENERATION_MODE_FULL_RUN,
GENERATION_MODE_REVIEW,
NONCE_POLICY_ADVANCE,
NONCE_POLICY_INHERIT,
REVIEW_ACTION_CONTINUE,
REVIEW_ACTION_FINISH_REMAINING,
REVIEW_ACTION_REGENERATE_CURRENT,
REVIEW_PAUSE_REASON,
REVISION_STATUS_COMPLETE,
REVISION_STATUS_IN_PROGRESS,
REVISION_STATUS_INTERRUPTED,
REVISION_STATUS_REVIEW_READY,
RUN_STORAGE_OFF,
RUN_STORAGE_SAVE_AUTO_RESUME,
ReviewControlError,
ReviewUnit,
make_review_pause_metadata,
resolve_next_review_unit,
resolve_review_execution,
resolve_take_execution,
)
from ComfyUI_H3_Continuum_Join.branch_provenance import (
TAKE_ACTION_CONTINUE,
TAKE_ACTION_USE,
)
def _resolve(**overrides):
values = {
"generation_mode": GENERATION_MODE_REVIEW,
"review_action": REVIEW_ACTION_CONTINUE,
"configured_chunks": 6,
"validated_prefix_count": 0,
"terminal_merge_enabled": False,
"terminal_pair_start": None,
"manual_regenerate_from": "Auto",
"run_storage_mode": RUN_STORAGE_SAVE_AUTO_RESUME,
"latest_review_unit": None,
"latest_revision_status": None,
"latest_effective_nonce": 0,
"latest_branch_regenerate_from": 0,
}
values.update(overrides)
return resolve_review_execution(**values)
def _review_unit(start, end=None):
end = start if end is None else end
return {"start": start, "end": end, "physical_group": start}
def test_full_run_has_no_review_execution_limit_or_storage_requirement():
result = _resolve(
generation_mode=GENERATION_MODE_FULL_RUN,
run_storage_mode=RUN_STORAGE_OFF,
)
assert result.execution_mode == EXECUTION_MODE_FULL_RUN
assert result.max_new_physical_groups is None
assert result.requires_run_storage is False
assert result.partial_review is False
@pytest.mark.parametrize(
("prefix", "expected"),
((0, 1), (1, 2), (2, 3), (5, 6)),
)
def test_normal_review_resolves_one_next_chunk(prefix, expected):
result = _resolve(
validated_prefix_count=prefix,
latest_revision_status=(REVISION_STATUS_REVIEW_READY if prefix else None),
latest_review_unit=(_review_unit(prefix) if prefix else None),
)
assert result.execution_mode == EXECUTION_MODE_REVIEW_CONTINUE
assert result.max_new_physical_groups == 1
assert (result.next_review_unit_start, result.next_review_unit_end) == (
expected,
expected,
)
def test_review_complete_has_no_next_unit():
result = _resolve(
validated_prefix_count=6,
latest_revision_status=REVISION_STATUS_COMPLETE,
latest_review_unit=_review_unit(6),
)
assert result.next_review_unit_start is None
assert result.next_review_unit_end is None
assert result.projected_prefix_count == 6
assert result.partial_review is False
assert "complete" in result.status_hint.lower()
def test_finish_remaining_removes_physical_group_limit_and_is_one_shot():
result = _resolve(
review_action=REVIEW_ACTION_FINISH_REMAINING,
validated_prefix_count=3,
latest_revision_status=REVISION_STATUS_REVIEW_READY,
latest_review_unit=_review_unit(3),
)
assert result.execution_mode == EXECUTION_MODE_REVIEW_FINISH
assert result.max_new_physical_groups is None
assert result.finish_remaining is True
assert result.one_shot_reset_required is True
assert result.projected_prefix_count == 6
assert result.partial_review is False
@pytest.mark.parametrize(
("prefix", "expected"),
(
(0, (1, 1)),
(1, (2, 3)),
(3, None),
),
)
def test_terminal_merge_next_unit_is_atomic(prefix, expected):
unit = resolve_next_review_unit(
configured_chunks=3,
validated_prefix_count=prefix,
terminal_merge_enabled=True,
terminal_pair_start=2,
)
if expected is None:
assert unit is None
else:
assert unit is not None
assert (unit.start, unit.end) == expected
def test_terminal_pair_partial_prefix_is_an_invariant_error():
with pytest.raises(ReviewControlError, match="inside the atomic Terminal Merge pair"):
resolve_next_review_unit(
configured_chunks=3,
validated_prefix_count=2,
terminal_merge_enabled=True,
terminal_pair_start=2,
)
def test_terminal_merge_must_be_the_final_two_chunks():
with pytest.raises(ReviewControlError, match="final two"):
resolve_next_review_unit(
configured_chunks=5,
validated_prefix_count=0,
terminal_merge_enabled=True,
terminal_pair_start=3,
)
def test_smart_regenerate_resolves_current_normal_unit():
result = _resolve(
review_action=REVIEW_ACTION_REGENERATE_CURRENT,
validated_prefix_count=3,
latest_revision_status=REVISION_STATUS_REVIEW_READY,
latest_review_unit=_review_unit(3),
)
assert result.execution_mode == EXECUTION_MODE_REVIEW_REGENERATE
assert result.effective_regenerate_from == 3
assert result.max_new_physical_groups == 1
assert result.smart_regenerate is True
assert result.one_shot_reset_required is True
assert result.requested_effective_nonce == 1
def test_smart_regenerate_resolves_terminal_pair_start():
result = _resolve(
review_action=REVIEW_ACTION_REGENERATE_CURRENT,
configured_chunks=3,
validated_prefix_count=3,
terminal_merge_enabled=True,
terminal_pair_start=2,
latest_revision_status=REVISION_STATUS_COMPLETE,
latest_review_unit=_review_unit(2, 3),
)
assert result.effective_regenerate_from == 2
assert (result.next_review_unit_start, result.next_review_unit_end) == (2, 3)
assert result.next_review_physical_group == 2
assert result.partial_review is False
def test_regenerate_current_rejects_empty_prefix():
with pytest.raises(ReviewControlError, match="existing reviewed unit"):
_resolve(review_action=REVIEW_ACTION_REGENERATE_CURRENT)
def test_regenerate_current_rejects_missing_review_unit():
with pytest.raises(ReviewControlError, match="review_unit metadata"):
_resolve(
review_action=REVIEW_ACTION_REGENERATE_CURRENT,
validated_prefix_count=2,
latest_revision_status=REVISION_STATUS_REVIEW_READY,
)
def test_regenerate_current_rejects_manual_regenerate_from():
with pytest.raises(ReviewControlError, match="cannot be combined"):
_resolve(
review_action=REVIEW_ACTION_REGENERATE_CURRENT,
validated_prefix_count=2,
manual_regenerate_from=1,
latest_revision_status=REVISION_STATUS_REVIEW_READY,
latest_review_unit=_review_unit(2),
)
def test_review_requires_run_storage():
with pytest.raises(ReviewControlError, match="requires Run Storage"):
_resolve(run_storage_mode=RUN_STORAGE_OFF)
@pytest.mark.parametrize(
"status",
(REVISION_STATUS_IN_PROGRESS, REVISION_STATUS_INTERRUPTED),
)
def test_regenerate_current_rejects_unready_revision(status):
with pytest.raises(ReviewControlError, match="review_ready revision"):
_resolve(
review_action=REVIEW_ACTION_REGENERATE_CURRENT,
validated_prefix_count=2,
latest_revision_status=status,
latest_review_unit=_review_unit(2),
)
def test_review_complete_with_review_unit_can_regenerate():
result = _resolve(
review_action=REVIEW_ACTION_REGENERATE_CURRENT,
validated_prefix_count=6,
latest_revision_status=REVISION_STATUS_COMPLETE,
latest_review_unit=_review_unit(6),
)
assert result.effective_regenerate_from == 6
def test_full_complete_without_review_unit_cannot_smart_regenerate():
with pytest.raises(ReviewControlError, match="review_unit metadata"):
_resolve(
review_action=REVIEW_ACTION_REGENERATE_CURRENT,
validated_prefix_count=6,
latest_revision_status=REVISION_STATUS_COMPLETE,
latest_review_unit=None,
)
def test_review_unit_must_be_the_validated_prefix_head():
with pytest.raises(ReviewControlError, match="head of the validated prefix"):
_resolve(
review_action=REVIEW_ACTION_REGENERATE_CURRENT,
validated_prefix_count=4,
latest_revision_status=REVISION_STATUS_REVIEW_READY,
latest_review_unit=_review_unit(3),
)
def test_review_pause_metadata_is_non_identity_shape():
metadata = make_review_pause_metadata(ReviewUnit(4, 5, 4))
assert metadata == {
"review_unit": {"start": 4, "end": 5, "physical_group": 4},
"review_pause_reason": REVIEW_PAUSE_REASON,
}
assert "sampling" not in metadata
def test_review_pause_metadata_rejects_mismatched_physical_group():
with pytest.raises(ReviewControlError, match="physical group"):
make_review_pause_metadata(ReviewUnit(4, 5, 5))
@pytest.mark.parametrize(
"status",
(
REVISION_STATUS_IN_PROGRESS,
REVISION_STATUS_INTERRUPTED,
REVISION_STATUS_REVIEW_READY,
),
)
def test_continue_inherits_existing_regenerate_branch_without_new_nonce(status):
result = _resolve(
validated_prefix_count=2,
latest_revision_status=status,
latest_review_unit=(
_review_unit(2) if status == REVISION_STATUS_REVIEW_READY else None
),
latest_effective_nonce=2,
latest_branch_regenerate_from=2,
)
assert result.nonce_policy == NONCE_POLICY_INHERIT
assert result.effective_regenerate_from == 2
assert result.branch_regenerate_from == 2
assert result.requested_effective_nonce == 2
@pytest.mark.parametrize(
("latest_nonce", "next_nonce"),
((0, 1), (1, 2), (2, 3)),
)
def test_consecutive_smart_regenerate_advances_current_branch_nonce(
latest_nonce,
next_nonce,
):
result = _resolve(
review_action=REVIEW_ACTION_REGENERATE_CURRENT,
validated_prefix_count=2,
latest_revision_status=REVISION_STATUS_REVIEW_READY,
latest_review_unit=_review_unit(2),
latest_effective_nonce=latest_nonce,
latest_branch_regenerate_from=(2 if latest_nonce else 0),
)
assert result.nonce_policy == NONCE_POLICY_ADVANCE
assert result.branch_regenerate_from == 2
assert result.requested_effective_nonce == next_nonce
def test_smart_regenerate_rejects_effective_nonce_overflow():
with pytest.raises(ReviewControlError, match="variation space is exhausted"):
_resolve(
review_action=REVIEW_ACTION_REGENERATE_CURRENT,
validated_prefix_count=2,
latest_revision_status=REVISION_STATUS_REVIEW_READY,
latest_review_unit=_review_unit(2),
latest_effective_nonce=0xFFFFFFFF,
latest_branch_regenerate_from=2,
)
def test_regenerate_then_continue_keeps_the_regenerated_branch():
regenerate = _resolve(
review_action=REVIEW_ACTION_REGENERATE_CURRENT,
validated_prefix_count=2,
latest_revision_status=REVISION_STATUS_REVIEW_READY,
latest_review_unit=_review_unit(2),
latest_effective_nonce=1,
latest_branch_regenerate_from=2,
)
assert regenerate.requested_effective_nonce == 2
continued = _resolve(
validated_prefix_count=2,
latest_revision_status=REVISION_STATUS_REVIEW_READY,
latest_review_unit=_review_unit(2),
latest_effective_nonce=regenerate.requested_effective_nonce,
latest_branch_regenerate_from=regenerate.branch_regenerate_from,
)
assert continued.effective_regenerate_from == 2
assert continued.requested_effective_nonce == 2
assert (continued.next_review_unit_start, continued.next_review_unit_end) == (3, 3)
def test_positive_nonce_without_branch_boundary_is_rejected():
with pytest.raises(ReviewControlError, match="requires its regenerate branch"):
_resolve(
validated_prefix_count=2,
latest_revision_status=REVISION_STATUS_REVIEW_READY,
latest_review_unit=_review_unit(2),
latest_effective_nonce=2,
latest_branch_regenerate_from=0,
)
def test_manual_review_regeneration_maps_terminal_second_chunk_to_atomic_pair():
result = _resolve(
configured_chunks=3,
validated_prefix_count=3,
terminal_merge_enabled=True,
terminal_pair_start=2,
manual_regenerate_from=3,
latest_revision_status=REVISION_STATUS_COMPLETE,
latest_review_unit=_review_unit(2, 3),
)
assert result.effective_regenerate_from == 3
assert (result.next_review_unit_start, result.next_review_unit_end) == (2, 3)
def test_partial_review_describes_the_projected_output_prefix():
partial = _resolve()
terminal_completion = _resolve(
configured_chunks=3,
validated_prefix_count=1,
terminal_merge_enabled=True,
terminal_pair_start=2,
latest_revision_status=REVISION_STATUS_REVIEW_READY,
latest_review_unit=_review_unit(1),
)
assert partial.partial_review is True
assert partial.projected_prefix_count == 1
assert terminal_completion.partial_review is False
assert terminal_completion.projected_prefix_count == 3
def test_use_take_selects_without_generating_and_continue_starts_new_boundary():
selected = resolve_take_execution(
take_action=TAKE_ACTION_USE,
configured_chunks=5,
selected_prefix_count=3,
terminal_merge_enabled=False,
terminal_pair_start=None,
selected_review_unit=_review_unit(3),
selected_effective_nonce=1,
selected_branch_regenerate_from=3,
next_effective_nonce=2,
)
assert selected.execution_mode == EXECUTION_MODE_REVIEW_USE_TAKE
assert selected.max_new_physical_groups == 0
assert selected.projected_prefix_count == 3
continued = resolve_take_execution(
take_action=TAKE_ACTION_CONTINUE,
configured_chunks=5,
selected_prefix_count=3,
terminal_merge_enabled=False,
terminal_pair_start=None,
selected_review_unit=_review_unit(3),
selected_effective_nonce=1,
selected_branch_regenerate_from=3,
next_effective_nonce=2,
)
assert continued.execution_mode == EXECUTION_MODE_REVIEW_CONTINUE_FROM_TAKE
assert continued.effective_regenerate_from == 4
assert continued.requested_effective_nonce == 2
assert continued.max_new_physical_groups == 1
def test_continue_from_take_keeps_terminal_merge_atomic():
continued = resolve_take_execution(
take_action=TAKE_ACTION_CONTINUE,
configured_chunks=3,
selected_prefix_count=1,
terminal_merge_enabled=True,
terminal_pair_start=2,
selected_review_unit=_review_unit(1),
selected_effective_nonce=0,
selected_branch_regenerate_from=0,
next_effective_nonce=1,
)
assert (
continued.next_review_unit_start,
continued.next_review_unit_end,
continued.next_review_physical_group,
) == (2, 3, 2)
+630
View File
@@ -0,0 +1,630 @@
from __future__ import annotations
import copy
from types import SimpleNamespace
import pytest
import torch
from ComfyUI_H3_Continuum_Join.constants import (
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 import sequence
from ComfyUI_H3_Continuum_Join.v2.h3_builder import IdentityAssets
from ComfyUI_H3_Continuum_Join.v2.nodes import H3ContinuumSamplerV2
from ComfyUI_H3_Continuum_Join.v2.prompts import make_prompt_plan
from ComfyUI_H3_Continuum_Join.v3.driving_nodes import (
H3ContinuumSamplerV37,
H3ContinuumSamplerV38,
)
from ComfyUI_H3_Continuum_Join.v3.nodes import (
H3ContinuumSamplerProduction,
H3ContinuumSamplerV3,
)
from ComfyUI_H3_Continuum_Join.v3.plan import prepare_physical_decode_entries
class _Nested:
def __init__(self, parts):
self.parts = list(parts)
def unbind(self):
return self.parts
class _FakeClip:
def tokenize(self, prompt, images=None, **_kwargs):
return prompt
def encode_from_tokens_scheduled(self, tokens):
return [[torch.zeros(1, 1, 2), {"prompt": tokens}]]
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)),
)
)
}
def _install_fake_runtime(monkeypatch, *, first_frame=None, last_frame=None, timeline=None):
width, height = 96, 64
timeline = [] if timeline is None else timeline
first_latent = (
torch.full((1, 24, 1, height // 16, width // 16), 0.25)
if first_frame is not None
else None
)
last_latent = (
torch.full((1, 24, 1, height // 16, width // 16), 0.75)
if last_frame is not None
else None
)
assets = IdentityAssets(
first_frame,
first_latent,
last_frame,
last_latent,
"review-cap-identity" if first_frame is not None else "none",
)
model = SimpleNamespace(
model=SimpleNamespace(diffusion_model=SimpleNamespace()),
model_options={},
wrappers={},
model_dtype=lambda: torch.bfloat16,
model_size=lambda: 0,
)
samples = []
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, "accelerator_summary", lambda _model: "accelerators")
monkeypatch.setattr(sequence, "clone_model_for_chunk", lambda model, **_kwargs: model)
monkeypatch.setattr(
sequence,
"latent_from_cpu",
lambda video, audio: {"samples": _Nested((video, audio))},
)
def sample_chunk(**kwargs):
video, audio = kwargs["latent"]["samples"].unbind()
video = video.clone()
audio = audio.clone()
value = float(int(kwargs["seed"]) % 251 + 1)
video.fill_(value)
audio.fill_(value + 0.5)
metadata = kwargs["conditioning"][0][1]
keyframes = list(metadata.get("minimax_keyframes") or [])
event = {
"seed": int(kwargs["seed"]),
"keyframes": keyframes,
"video_shape": tuple(video.shape),
"audio_shape": tuple(audio.shape),
}
samples.append(event)
timeline.append(("sample", int(kwargs["seed"])))
return {"samples": _Nested((video, audio))}
monkeypatch.setattr(sequence, "sample_chunk", sample_chunk)
return SimpleNamespace(
width=width,
height=height,
model=model,
clip=_FakeClip(),
assets=assets,
samples=samples,
timeline=timeline,
)
def _run_sequence(
runtime,
*,
chunks,
chunk_seconds=5.0,
session=None,
limit=None,
first_frame=None,
last_frame=None,
capture_refine_context=False,
):
plan = make_prompt_plan(
mode=PROMPT_MODE_FIXED,
script="continuous shot",
chunks=chunks,
chunk_seconds=chunk_seconds,
)
return sequence.run_sequence(
model=runtime.model,
clip=runtime.clip,
video_vae=object(),
audio_vae=None,
sampler=object(),
sigmas=torch.tensor([1.0, 0.0]),
first_frame=first_frame,
last_frame=last_frame,
prompt_plan=plan,
width=runtime.width,
height=runtime.height,
continuity=V2_CONTINUITY_OPTIONS[1],
base_seed=42,
audio_continuity=True,
exact_total_duration=False,
diagnostics_mode=DIAGNOSTICS_BASIC,
reroll_from_chunk=0,
reroll_nonce=0,
strict_compatibility=False,
debug=False,
session=session,
latent_only=True,
capture_refine_context=capture_refine_context,
max_new_physical_groups=limit,
)
def _run_v3_node(
runtime,
*,
chunks,
session=None,
limit=None,
first_frame=None,
last_frame=None,
):
advanced = {"last_frame": last_frame}
if session is not None:
advanced["session"] = session
return H3ContinuumSamplerV3().run(
model=runtime.model,
clip=runtime.clip,
video_vae=object(),
sampler=object(),
sigmas=torch.tensor([1.0, 0.0]),
sequence_prompt="continuous shot",
prompt_mode=PROMPT_MODE_FIXED,
chunks=chunks,
chunk_seconds=5.0,
width=runtime.width,
height=runtime.height,
continuity=V2_CONTINUITY_OPTIONS[1],
base_seed=42,
first_frame=first_frame,
advanced=advanced,
max_new_physical_groups=limit,
)
def _entry_contract(entries):
return [
{
"seed": entry["seed"],
"prompt_hash": entry["prompt_hash"],
"plan": entry["plan"],
"video": entry["video"],
"audio": entry["audio"],
}
for entry in entries
]
def _assert_entry_parity(left, right):
left_contract = _entry_contract(left)
right_contract = _entry_contract(right)
assert len(left_contract) == len(right_contract)
for left_entry, right_entry in zip(left_contract, right_contract, strict=True):
assert left_entry["seed"] == right_entry["seed"]
assert left_entry["prompt_hash"] == right_entry["prompt_hash"]
assert left_entry["plan"] == right_entry["plan"]
assert torch.equal(left_entry["video"], right_entry["video"])
assert torch.equal(left_entry["audio"], right_entry["audio"])
def test_full_run_none_keeps_all_six_chunks(monkeypatch):
runtime = _install_fake_runtime(monkeypatch)
entries, last_state, session, report = _run_sequence(
runtime,
chunks=6,
limit=None,
)
assert len(entries) == len(session["chunks"]) == 6
assert last_state["clip_index"] == 6
assert len(runtime.samples) == 6
assert "Physical review execution" not in report
def test_limit_one_returns_one_new_chunk_and_prefix_assembly(monkeypatch):
runtime = _install_fake_runtime(monkeypatch)
entries, last_state, session, report = _run_sequence(
runtime,
chunks=6,
limit=1,
)
decode_entries, assembly_plan = prepare_physical_decode_entries(
entries,
chunk_seconds=5.0,
preserve_final_frame=False,
terminal_merged=False,
)
assert len(entries) == len(session["chunks"]) == len(decode_entries) == 1
assert last_state["clip_index"] == 1
assert len(runtime.samples) == 1
assert len(assembly_plan["chunks"]) == 1
assert assembly_plan["target_frames"] == 120
assert assembly_plan["preserve_final_frame"] is False
assert "max_new_physical_groups" not in session["settings"]
assert "1 new physical group(s) completed; 1/6 logical chunks" in report
def test_reused_prefix_does_not_consume_physical_group_budget(monkeypatch):
runtime = _install_fake_runtime(monkeypatch)
first_entries, _, first_session, _ = _run_sequence(
runtime,
chunks=6,
limit=1,
)
first_video = first_entries[0]["video"].clone()
before = len(runtime.samples)
entries, last_state, session, report = _run_sequence(
runtime,
chunks=6,
session=first_session,
limit=1,
)
assert len(entries) == len(session["chunks"]) == 2
assert len(runtime.samples) - before == 1
assert entries[0]["reused"] is True
assert torch.equal(entries[0]["video"], first_video)
assert last_state["clip_index"] == 2
assert "1 new physical group(s) completed; 2/6 logical chunks" in report
def test_prefix_five_generates_only_chunk_six_and_completes(monkeypatch):
runtime = _install_fake_runtime(monkeypatch)
session = None
entries = None
for expected in range(1, 6):
entries, _, session, _ = _run_sequence(
runtime,
chunks=6,
session=session,
limit=1,
)
assert len(entries) == expected
before = len(runtime.samples)
entries, last_state, session, _ = _run_sequence(
runtime,
chunks=6,
session=session,
limit=1,
)
assert len(entries) == len(session["chunks"]) == 6
assert len(runtime.samples) - before == 1
assert last_state["clip_index"] == 6
def test_incremental_normal_run_matches_full_run_latents_and_assembly(monkeypatch):
runtime = _install_fake_runtime(monkeypatch)
full_entries, _, _, _ = _run_sequence(runtime, chunks=6, limit=None)
session = None
incremental_entries = None
for _ in range(6):
incremental_entries, _, session, _ = _run_sequence(
runtime,
chunks=6,
session=session,
limit=1,
)
_assert_entry_parity(full_entries, incremental_entries)
_, full_plan = prepare_physical_decode_entries(
full_entries,
chunk_seconds=5.0,
preserve_final_frame=False,
terminal_merged=False,
)
_, incremental_plan = prepare_physical_decode_entries(
incremental_entries,
chunk_seconds=5.0,
preserve_final_frame=False,
terminal_merged=False,
)
assert incremental_plan == full_plan
def test_v3_node_returns_partial_latents_and_assembly_plan(monkeypatch):
runtime = _install_fake_runtime(monkeypatch)
video, audio, plan, result = _run_v3_node(runtime, chunks=6, limit=1)
assert len(video) == len(audio) == len(plan["chunks"]) == 1
assert plan["target_frames"] == 120
assert plan["preserve_final_frame"] is False
assert len(result["session"]["chunks"]) == 1
assert "1/6 logical chunks" in result["report"]
def test_fl2va_review_stops_before_terminal_then_completes_atomic_pair(monkeypatch):
first = torch.zeros(1, 64, 96, 3)
last = torch.ones(1, 64, 96, 3)
runtime = _install_fake_runtime(
monkeypatch,
first_frame=first,
last_frame=last,
)
video1, audio1, plan1, result1 = _run_v3_node(
runtime,
chunks=3,
limit=1,
first_frame=first,
last_frame=last,
)
assert len(video1) == len(audio1) == len(plan1["chunks"]) == 1
assert plan1["preserve_final_frame"] is False
assert plan1["target_frames"] == 120
assert len(runtime.samples) == 1
assert all(
keyframe["latent"] is not runtime.assets.last_latent
for keyframe in runtime.samples[0]["keyframes"]
)
before = len(runtime.samples)
video2, audio2, plan2, result2 = _run_v3_node(
runtime,
chunks=3,
session=result1["session"],
limit=1,
first_frame=first,
last_frame=last,
)
assert len(runtime.samples) - before == 1
assert len(result2["session"]["chunks"]) == 3
assert len(video2) == len(audio2) == 2
assert len(plan2["chunks"]) == 3
assert plan2["target_frames"] == 360
assert plan2["preserve_final_frame"] is True
assert plan2["physical_decode_group_count"] == 2
terminal_group = plan2["decode_groups"][-1]
assert terminal_group["logical_chunk_indices"] == [2, 3]
assert terminal_group["terminal_merged"] is True
assert any(
keyframe["latent"] is runtime.assets.last_latent
for keyframe in runtime.samples[-1]["keyframes"]
)
def test_partial_terminal_session_is_atomically_reset_not_returned(monkeypatch):
first = torch.zeros(1, 64, 96, 3)
last = torch.ones(1, 64, 96, 3)
runtime = _install_fake_runtime(
monkeypatch,
first_frame=first,
last_frame=last,
)
_, _, complete_session, _ = _run_sequence(
runtime,
chunks=3,
limit=None,
first_frame=first,
last_frame=last,
)
partial_pair_session = copy.deepcopy(complete_session)
partial_pair_session["chunks"] = partial_pair_session["chunks"][:2]
before = len(runtime.samples)
entries, _, session, report = _run_sequence(
runtime,
chunks=3,
session=partial_pair_session,
limit=1,
first_frame=first,
last_frame=last,
)
assert len(runtime.samples) - before == 1
assert len(entries) == len(session["chunks"]) == 3
assert "terminal merged pair is atomic" in report
assert entries[1]["reused"] is False
assert entries[2]["reused"] is False
def test_incremental_terminal_run_matches_full_run(monkeypatch):
first = torch.zeros(1, 64, 96, 3)
last = torch.ones(1, 64, 96, 3)
runtime = _install_fake_runtime(
monkeypatch,
first_frame=first,
last_frame=last,
)
full_entries, _, _, _ = _run_sequence(
runtime,
chunks=3,
limit=None,
first_frame=first,
last_frame=last,
)
first_entries, _, first_session, _ = _run_sequence(
runtime,
chunks=3,
limit=1,
first_frame=first,
last_frame=last,
)
assert len(first_entries) == 1
incremental_entries, _, _, _ = _run_sequence(
runtime,
chunks=3,
session=first_session,
limit=1,
first_frame=first,
last_frame=last,
)
_assert_entry_parity(full_entries, incremental_entries)
full_decode, full_plan = prepare_physical_decode_entries(
full_entries,
chunk_seconds=5.0,
preserve_final_frame=True,
terminal_merged=True,
)
incremental_decode, incremental_plan = prepare_physical_decode_entries(
incremental_entries,
chunk_seconds=5.0,
preserve_final_frame=True,
terminal_merged=True,
)
assert incremental_plan == full_plan
assert len(incremental_decode) == len(full_decode) == 2
for left, right in zip(full_decode, incremental_decode, strict=True):
assert torch.equal(left["video"], right["video"])
assert torch.equal(left["audio"], right["audio"])
class _CommitRecorder:
effective_reroll_nonce = 0
reused_count = 0
review_execution = None
def __init__(self, timeline):
self.timeline = timeline
self.prepare_kwargs = None
self.review_groups = []
def prepare(self, **kwargs):
self.prepare_kwargs = kwargs
return None
def commit_chunk(self, entry, *, position):
self.timeline.append(("commit", position))
def mark_review_group(self, *, start, end, physical_group):
self.review_groups.append((start, end, physical_group))
def test_storage_review_execution_drives_internal_cap_and_group_marker(monkeypatch):
timeline = []
runtime = _install_fake_runtime(monkeypatch, timeline=timeline)
storage = _CommitRecorder(timeline)
storage.review_execution = SimpleNamespace(
effective_regenerate_from=0,
max_new_physical_groups=1,
)
import ComfyUI_H3_Continuum_Join.run_storage as run_storage
monkeypatch.setattr(run_storage, "get_active_run_storage", lambda: storage)
entries, _, _, _ = _run_sequence(runtime, chunks=3, limit=None)
assert len(entries) == 1
assert storage.review_groups == [(1, 1, 1)]
def test_storage_use_take_returns_validated_prefix_without_sampling(monkeypatch):
runtime = _install_fake_runtime(monkeypatch)
_, _, selected_session, _ = _run_sequence(runtime, chunks=3, limit=2)
selected_session["settings"]["run_storage_validated_prefix"] = True
runtime.samples.clear()
runtime.timeline.clear()
storage = _CommitRecorder(runtime.timeline)
storage.review_execution = SimpleNamespace(
effective_regenerate_from=2,
max_new_physical_groups=0,
)
def prepare(**kwargs):
storage.prepare_kwargs = kwargs
return selected_session
storage.prepare = prepare
import ComfyUI_H3_Continuum_Join.run_storage as run_storage
monkeypatch.setattr(run_storage, "get_active_run_storage", lambda: storage)
entries, _, session, report = _run_sequence(runtime, chunks=3, limit=None)
assert len(entries) == len(session["chunks"]) == 2
assert runtime.samples == []
assert runtime.timeline == []
assert storage.review_groups == []
assert "0 new physical group(s) completed; 2/3 logical chunks" in report
def test_normal_group_stops_only_after_commit(monkeypatch):
timeline = []
runtime = _install_fake_runtime(monkeypatch, timeline=timeline)
storage = _CommitRecorder(timeline)
import ComfyUI_H3_Continuum_Join.run_storage as run_storage
monkeypatch.setattr(run_storage, "get_active_run_storage", lambda: storage)
entries, _, _, _ = _run_sequence(runtime, chunks=3, limit=1)
assert len(entries) == 1
assert [event[0] for event in timeline] == ["sample", "commit"]
assert timeline[-1] == ("commit", 0)
assert "max_new_physical_groups" not in storage.prepare_kwargs
def test_terminal_group_counts_once_after_both_logical_commits(monkeypatch):
first = torch.zeros(1, 64, 96, 3)
last = torch.ones(1, 64, 96, 3)
timeline = []
runtime = _install_fake_runtime(
monkeypatch,
first_frame=first,
last_frame=last,
timeline=timeline,
)
storage = _CommitRecorder(timeline)
import ComfyUI_H3_Continuum_Join.run_storage as run_storage
monkeypatch.setattr(run_storage, "get_active_run_storage", lambda: storage)
entries, _, _, report = _run_sequence(
runtime,
chunks=2,
limit=1,
first_frame=first,
last_frame=last,
)
assert len(entries) == 2
assert [event[0] for event in timeline] == ["sample", "commit", "commit"]
assert timeline[-2:] == [("commit", 0), ("commit", 1)]
assert "1 new physical group(s) completed; 2/2 logical chunks" in report
assert "max_new_physical_groups" not in storage.prepare_kwargs
def test_partial_refine_context_is_explicitly_incomplete(monkeypatch):
runtime = _install_fake_runtime(monkeypatch)
entries, _, session, report, refine_context = _run_sequence(
runtime,
chunks=3,
limit=1,
capture_refine_context=True,
)
assert len(entries) == len(session["chunks"]) == 1
assert refine_context["complete"] is False
assert len(refine_context["groups"]) == 1
assert any("physical review execution" in note for note in refine_context["notes"])
assert "1/3 logical chunks" in report
@pytest.mark.parametrize("invalid", (0, -1, True, 1.5))
def test_invalid_physical_group_limit_is_rejected(monkeypatch, invalid):
runtime = _install_fake_runtime(monkeypatch)
with pytest.raises(sequence.SequenceRuntimeError, match="positive integer"):
_run_sequence(runtime, chunks=3, limit=invalid)
def test_physical_group_limit_is_internal_and_not_a_public_widget():
for node_class in (
H3ContinuumSamplerV2,
H3ContinuumSamplerV3,
H3ContinuumSamplerProduction,
H3ContinuumSamplerV37,
H3ContinuumSamplerV38,
):
schema = node_class.INPUT_TYPES()
assert "max_new_physical_groups" not in schema.get("required", {})
assert "max_new_physical_groups" not in schema.get("optional", {})
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,368 @@
from __future__ import annotations
import copy
import json
from pathlib import Path
import pytest
from ComfyUI_H3_Continuum_Join import nodes as root_nodes
from ComfyUI_H3_Continuum_Join.v3 import second_pass_nodes
from ComfyUI_H3_Continuum_Join.v3.driving_nodes import H3ContinuumSamplerV38
from ComfyUI_H3_Continuum_Join.v3.refine_target import (
MODE_AUDIO_ONLY,
MODE_VIDEO_AUDIO,
MODE_VIDEO_ONLY,
)
from ComfyUI_H3_Continuum_Join.v3.second_pass_nodes import (
H3ContinuumSecondPassV35,
H3ContinuumSelectiveSecondPassExperimental,
NODE_CLASS_MAPPINGS,
NODE_DISPLAY_NAME_MAPPINGS,
REFINE_TARGET_AUDIO_ONLY,
REFINE_TARGET_OPTIONS,
REFINE_TARGET_VIDEO_AUDIO,
REFINE_TARGET_VIDEO_ONLY,
REFINE_SCOPE_ALL,
REFINE_SCOPE_LOGICAL_CHUNK,
REFINE_SCOPE_OPTIONS,
REFINE_SCOPE_PHYSICAL_GROUP,
REFINE_SCOPE_TIME_WINDOW,
)
_V35_SCHEMA_BEFORE_SELECTIVE_NODE = copy.deepcopy(
H3ContinuumSecondPassV35.INPUT_TYPES()
)
_V38_SAMPLER_SCHEMA_BEFORE_SELECTIVE_NODE = copy.deepcopy(
H3ContinuumSamplerV38.INPUT_TYPES()
)
def _node_arguments(target: str, *, video_latents=None, audio_latents=None, plan=None):
return {
"model": [object()],
"clip": [object()],
"sampler": [object()],
"sigmas": [object()],
"video_latents": video_latents or [{"samples": object()}],
"audio_latents": audio_latents or [{"samples": object()}],
"assembly_plan": [plan or {"second_pass_contract": {"version": 1}}],
"refine_seed": [73],
"refine_target": [target],
}
def test_selective_node_public_schema_registration_and_display_contract():
node_id = "H3ContinuumSelectiveSecondPassExperimental"
schema = H3ContinuumSelectiveSecondPassExperimental.INPUT_TYPES()
assert NODE_CLASS_MAPPINGS[node_id] is H3ContinuumSelectiveSecondPassExperimental
assert node_id not in root_nodes.NODE_CLASS_MAPPINGS
assert NODE_DISPLAY_NAME_MAPPINGS[node_id] == (
"H3 Continuum Selective Second Pass (Experimental)"
)
assert node_id not in root_nodes.NODE_DISPLAY_NAME_MAPPINGS
assert H3ContinuumSelectiveSecondPassExperimental.DEPRECATED is False
assert H3ContinuumSelectiveSecondPassExperimental.CATEGORY == (
"MiniMax H3/Continuum/Advanced"
)
assert tuple(schema["required"]) == (
"model",
"clip",
"sampler",
"sigmas",
"video_latents",
"audio_latents",
"assembly_plan",
"refine_seed",
"refine_target",
"refine_scope",
"refine_scope_index",
"window_start_sec",
"window_end_sec",
)
assert tuple(schema["optional"]) == ("refine_context", "video_vae")
assert schema["required"]["refine_target"] == (
REFINE_TARGET_OPTIONS,
{"default": REFINE_TARGET_VIDEO_ONLY},
)
assert REFINE_TARGET_OPTIONS == (
"Video Only",
"Audio Only",
"Video + Audio",
)
assert schema["required"]["refine_scope"] == (
REFINE_SCOPE_OPTIONS,
{"default": REFINE_SCOPE_ALL},
)
assert REFINE_SCOPE_OPTIONS == (
"All",
"Physical Group",
"Logical Chunk",
REFINE_SCOPE_TIME_WINDOW,
)
assert schema["required"]["refine_scope_index"][0] == "INT"
assert schema["required"]["refine_scope_index"][1]["default"] == 1
assert schema["required"]["window_start_sec"][1]["default"] == 0.0
assert schema["required"]["window_end_sec"][1]["default"] == 5.0
assert H3ContinuumSelectiveSecondPassExperimental.INPUT_IS_LIST is True
assert H3ContinuumSelectiveSecondPassExperimental.RETURN_TYPES == (
"LATENT",
"LATENT",
"H3_CONTINUUM_ASSEMBLY_PLAN",
"STRING",
)
assert H3ContinuumSelectiveSecondPassExperimental.RETURN_NAMES == (
"refined_video_latents",
"audio_latents",
"updated_assembly_plan",
"status",
)
assert H3ContinuumSelectiveSecondPassExperimental.OUTPUT_IS_LIST == (
True,
True,
False,
False,
)
assert "Experimental" in H3ContinuumSelectiveSecondPassExperimental.DESCRIPTION
assert "denoise-mask" in H3ContinuumSelectiveSecondPassExperimental.DESCRIPTION
def test_a3c_saved_workflow_loads_missing_a4_tail_widgets_as_all_defaults():
fixture_path = (
Path(__file__).parent
/ "fixtures"
/ "v38_a3c_selective_refine_saved_workflow.json"
)
workflow = json.loads(fixture_path.read_text(encoding="utf-8"))
saved = workflow["nodes"][0]
assert saved["type"] == "H3ContinuumSelectiveSecondPassExperimental"
assert saved["widgets_values"] == [73, REFINE_TARGET_VIDEO_AUDIO]
schema = H3ContinuumSelectiveSecondPassExperimental.INPUT_TYPES()["required"]
widget_names = (
"refine_seed",
"refine_target",
"refine_scope",
"refine_scope_index",
"window_start_sec",
"window_end_sec",
)
restored = {}
for index, name in enumerate(widget_names):
if index < len(saved["widgets_values"]):
restored[name] = saved["widgets_values"][index]
else:
restored[name] = schema[name][1]["default"]
assert restored == {
"refine_seed": 73,
"refine_target": REFINE_TARGET_VIDEO_AUDIO,
"refine_scope": REFINE_SCOPE_ALL,
"refine_scope_index": 1,
"window_start_sec": 0.0,
"window_end_sec": 5.0,
}
def test_selective_schema_does_not_mutate_v35_or_v38_sampler_schema():
H3ContinuumSelectiveSecondPassExperimental.INPUT_TYPES()
assert H3ContinuumSecondPassV35.INPUT_TYPES() == _V35_SCHEMA_BEFORE_SELECTIVE_NODE
assert H3ContinuumSamplerV38.INPUT_TYPES() == (
_V38_SAMPLER_SCHEMA_BEFORE_SELECTIVE_NODE
)
@pytest.mark.parametrize(
("label", "expected_mode", "status_fragment"),
(
(REFINE_TARGET_VIDEO_ONLY, MODE_VIDEO_ONLY, "Audio=bit-exact passthrough"),
(
REFINE_TARGET_AUDIO_ONLY,
MODE_AUDIO_ONLY,
"Experimental / Production HOLD",
),
(
REFINE_TARGET_VIDEO_AUDIO,
MODE_VIDEO_AUDIO,
"GPU Experimental PASS / Production HOLD",
),
),
)
def test_selective_node_resolves_each_ui_label_to_canonical_target(
monkeypatch,
label,
expected_mode,
status_fragment,
):
captured = {}
output_videos = [{"video": label}]
output_audios = [{"audio": label}]
output_plan = {"plan": label}
def fake_run(**kwargs):
captured.update(kwargs)
return output_videos, output_audios, output_plan, "internal status"
monkeypatch.setattr(second_pass_nodes, "run_targeted_second_pass_groups", fake_run)
result = H3ContinuumSelectiveSecondPassExperimental().refine(
**_node_arguments(label)
)
assert captured["refine_target"] == expected_mode
assert result[:3] == (output_videos, output_audios, output_plan)
assert result[0] is output_videos
assert result[1] is output_audios
assert result[2] is output_plan
assert result[3].startswith(f"Selective Refine: {label};")
assert status_fragment in result[3]
assert result[3].endswith("internal status")
def test_selective_node_rejects_unknown_target_without_silent_fallback(monkeypatch):
called = False
def fake_run(**_kwargs):
nonlocal called
called = True
raise AssertionError("targeted runner must not be called")
monkeypatch.setattr(second_pass_nodes, "run_targeted_second_pass_groups", fake_run)
with pytest.raises(ValueError, match="unsupported selective refine target"):
H3ContinuumSelectiveSecondPassExperimental().refine(
**_node_arguments("unknown")
)
assert called is False
def test_video_only_adapter_matches_v35_inputs_and_preserves_output_objects(monkeypatch):
video_output = [{"samples": object()}]
audio_output = [{"samples": object()}]
plan_output = {"second_pass_contract": {"version": 1}}
legacy_calls = []
targeted_calls = []
def result_for(kwargs, calls):
calls.append(kwargs)
return video_output, audio_output, plan_output, "legacy status"
monkeypatch.setattr(
second_pass_nodes,
"run_second_pass_groups",
lambda **kwargs: result_for(kwargs, legacy_calls),
)
monkeypatch.setattr(
second_pass_nodes,
"run_targeted_second_pass_groups",
lambda **kwargs: result_for(kwargs, targeted_calls),
)
shared = _node_arguments(REFINE_TARGET_VIDEO_ONLY)
legacy_result = H3ContinuumSecondPassV35().refine(
**{key: value for key, value in shared.items() if key != "refine_target"}
)
selective_result = H3ContinuumSelectiveSecondPassExperimental().refine(**shared)
assert legacy_result[:3] == selective_result[:3]
assert all(
selective_result[index] is legacy_result[index] for index in range(3)
)
assert audio_output[0] is selective_result[1][0]
assert targeted_calls[0]["refine_target"] == MODE_VIDEO_ONLY
for name in (
"model",
"clip",
"sampler",
"sigmas",
"video_latents",
"audio_latents",
"assembly_plan",
"refine_seed",
"refine_context",
"video_vae",
"refine_schedule",
):
assert targeted_calls[0][name] is legacy_calls[0][name] or (
targeted_calls[0][name] == legacy_calls[0][name]
)
@pytest.mark.parametrize(
("label", "mode", "video_is_source", "audio_is_source"),
(
(REFINE_TARGET_AUDIO_ONLY, MODE_AUDIO_ONLY, True, False),
(REFINE_TARGET_VIDEO_AUDIO, MODE_VIDEO_AUDIO, False, False),
),
)
def test_experimental_target_outputs_are_forwarded_without_adapter_copies(
monkeypatch,
label,
mode,
video_is_source,
audio_is_source,
):
source_videos = [{"samples": object()}]
source_audios = [{"samples": object()}]
output_videos = source_videos if video_is_source else [{"samples": object()}]
output_audios = source_audios if audio_is_source else [{"samples": object()}]
output_plan = {"second_pass_contract": {"version": 1}}
def fake_run(**kwargs):
assert kwargs["refine_target"] == mode
return output_videos, output_audios, output_plan, "target status"
monkeypatch.setattr(second_pass_nodes, "run_targeted_second_pass_groups", fake_run)
result = H3ContinuumSelectiveSecondPassExperimental().refine(
**_node_arguments(
label,
video_latents=source_videos,
audio_latents=source_audios,
)
)
assert result[0] is output_videos
assert result[1] is output_audios
assert result[2] is output_plan
assert (result[0] is source_videos) is video_is_source
assert (result[1] is source_audios) is audio_is_source
def test_terminal_physical_group_lists_remain_atomic_through_public_adapter(
monkeypatch,
):
videos = [{"group": 1}, {"group": "terminal-2-3"}]
audios = [{"group": 1}, {"group": "terminal-2-3"}]
plan = {
"second_pass_contract": {
"version": 1,
"physical_groups": [
{"logical_chunks": [1], "terminal_merged": False},
{"logical_chunks": [2, 3], "terminal_merged": True},
],
}
}
def fake_run(**kwargs):
assert kwargs["video_latents"] is videos
assert kwargs["audio_latents"] is audios
assert kwargs["assembly_plan"] is plan
assert len(kwargs["video_latents"]) == 2
assert plan["second_pass_contract"]["physical_groups"][1][
"logical_chunks"
] == [2, 3]
return videos, audios, plan, "terminal atomic"
monkeypatch.setattr(second_pass_nodes, "run_targeted_second_pass_groups", fake_run)
result = H3ContinuumSelectiveSecondPassExperimental().refine(
**_node_arguments(
REFINE_TARGET_VIDEO_AUDIO,
video_latents=videos,
audio_latents=audios,
plan=plan,
)
)
assert result[0] is videos
assert result[1] is audios
assert result[2] is plan
assert "physical groups=2" in result[3]
+402
View File
@@ -0,0 +1,402 @@
from __future__ import annotations
import copy
import math
import pytest
import torch
from ComfyUI_H3_Continuum_Join.temporal import audio_latent_t, video_latent_t
from ComfyUI_H3_Continuum_Join.v3.refine_target import (
MODE_AUDIO_ONLY,
MODE_VIDEO_AUDIO,
MODE_VIDEO_ONLY,
)
from ComfyUI_H3_Continuum_Join.v3.refine_window import (
MAGIC,
MODE_TIME_WINDOW,
GroupTemporalWindow,
RefineWindowError,
resolve_refine_window,
serializable_window_contract,
)
from ComfyUI_H3_Continuum_Join.v3.second_pass_nodes import (
H3ContinuumSelectiveSecondPassExperimental,
REFINE_SCOPE_TIME_WINDOW,
)
from ComfyUI_H3_Continuum_Join.v3.targeted_refine_sampling import (
_prepare_audio_only_noise_and_mask,
_prepare_video_audio_noise_and_mask,
_prepare_video_only_noise_and_mask,
_restore_outside_temporal_ranges,
sample_targeted_refine_chunk,
)
from ComfyUI_H3_Continuum_Join.v3.targeted_second_pass import (
run_targeted_second_pass_groups,
)
def _physical_group(
group_id: int,
logical_chunks: list[int],
physical_frames: int,
trim_frames: int,
*,
terminal: bool = False,
) -> dict:
return {
"group_id": group_id,
"logical_chunks": logical_chunks,
"physical_prompt": f"group {group_id + 1}",
"prompt_policy": "paired_timeline_v1" if terminal else "single",
"physical_frames": physical_frames,
"trim_prefix_frames": trim_frames,
"terminal_merged": terminal,
"source_width": 128,
"source_height": 128,
"source_batch": 1,
"latent_channels": 24,
"source_latent_t": video_latent_t(physical_frames),
"source_latent_h": 8,
"source_latent_w": 8,
"source_audio_shape": [1, 32, 2, audio_latent_t(physical_frames)],
}
def _logical_chunks() -> list[dict]:
values = ((124, 0), (141, 22), (141, 22))
cursor = 0
chunks = []
for index, (total, trim) in enumerate(values, start=1):
net = total - trim
chunks.append(
{
"sequence_index": index,
"chunk_index": index,
"total_frames": total,
"trim_frames": trim,
"net_frames": net,
"context_frames": trim,
"expected_video_latent_t": video_latent_t(total),
"expected_audio_latent_t": audio_latent_t(total),
"frame_start": cursor,
"frame_stop": cursor + net,
}
)
cursor += net
return chunks
def _plan(*, terminal: bool = False, preserve_final_frame: bool = False) -> dict:
chunks = _logical_chunks()
if terminal:
groups = [
_physical_group(0, [1], 124, 0),
_physical_group(1, [2, 3], 260, 22, terminal=True),
]
decode_groups = [
{
**chunks[0],
"logical_chunk_indices": [1],
"terminal_merged": False,
},
{
"total_frames": 260,
"trim_frames": 22,
"net_frames": 238,
"context_frames": 22,
"expected_video_latent_t": video_latent_t(260),
"expected_audio_latent_t": audio_latent_t(260),
"frame_start": 124,
"frame_stop": 362,
"logical_chunk_indices": [2, 3],
"terminal_merged": True,
},
]
else:
groups = [
_physical_group(0, [1], 124, 0),
_physical_group(1, [2], 141, 22),
_physical_group(2, [3], 141, 22),
]
decode_groups = [
{
**chunk,
"logical_chunk_indices": [index],
"terminal_merged": False,
}
for index, chunk in enumerate(chunks, start=1)
]
return {
"magic": "H3_CONTINUUM_ASSEMBLY_PLAN",
"schema_version": 1,
"fps": 24,
"width": 128,
"height": 128,
"chunk_seconds": 5.0,
"target_frames": 360,
"natural_frames": 362,
"preserve_final_frame": preserve_final_frame,
"chunks": chunks,
"decode_groups": decode_groups,
"second_pass_contract": {"version": 1, "physical_groups": groups},
}
def _latents(plan: dict):
groups = plan["second_pass_contract"]["physical_groups"]
videos = [
{
"samples": torch.full(
(
1,
24,
group["source_latent_t"],
8,
8,
),
float(index + 1),
)
}
for index, group in enumerate(groups)
]
audios = [
{
"samples": torch.full(
tuple(group["source_audio_shape"]),
float(index + 11),
)
}
for index, group in enumerate(groups)
]
return videos, audios
def test_visible_window_resolves_across_groups_without_selecting_prefix():
plan = _plan()
before = copy.deepcopy(plan)
window = resolve_refine_window(5.0, 10.0, plan)
assert plan == before
assert window.selected_group_indices == (0, 1)
assert window.contract["magic"] == MAGIC
assert window.contract["output_frame_range"] == [120, 240]
assert window.groups[0].physical_frame_ranges == ((120, 124),)
assert window.groups[1].physical_frame_ranges == ((22, 138),)
assert window.groups[1].video_slot_ranges[0][0] >= 7
assert window.groups[1].audio_tick_ranges[0][0] == audio_latent_t(22)
assert window.contract["continuation_prefix_policy"] == "always_protected"
serialized = serializable_window_contract(window)
serialized["groups"][0]["physical_frame_ranges"].append([0, 1])
assert window.groups[0].physical_frame_ranges == ((120, 124),)
def test_full_visible_window_clamps_and_excludes_non_visible_tail():
window = resolve_refine_window(-1.0, 20.0, _plan())
assert window.contract["output_frame_range"] == [0, 360]
assert window.selected_group_indices == (0, 1, 2)
assert window.groups[1].physical_frame_ranges == ((22, 141),)
assert window.groups[2].physical_frame_ranges == ((22, 139),)
def test_preserved_final_anchor_maps_to_natural_final_frame():
window = resolve_refine_window(0.0, 15.0, _plan(preserve_final_frame=True))
assert window.contract["natural_frame_ranges"] == [[0, 359], [361, 362]]
assert window.groups[2].physical_frame_ranges == ((22, 138), (140, 141))
def test_terminal_logical_half_window_keeps_physical_pair_atomic():
window = resolve_refine_window(243 / 24, 15.0, _plan(terminal=True))
assert window.selected_group_indices == (1,)
group = window.groups[0]
assert group.logical_chunks == (2, 3)
assert group.terminal_merged is True
assert group.physical_frame_ranges == ((141, 258),)
@pytest.mark.parametrize(
("start", "end", "match"),
(
(5.0, 5.0, "start must be less"),
(6.0, 5.0, "start must be less"),
(math.nan, 5.0, "finite"),
(20.0, 30.0, "does not overlap"),
),
)
def test_invalid_or_empty_window_fails_before_execution(start, end, match):
with pytest.raises(RefineWindowError, match=match):
resolve_refine_window(start, end, _plan())
def _small_group_window() -> GroupTemporalWindow:
return GroupTemporalWindow(
group_index=0,
logical_chunks=(1,),
terminal_merged=False,
visible_frame_ranges=((0, 1),),
physical_frame_ranges=((0, 1),),
video_slot_ranges=((2, 4),),
audio_tick_ranges=((3, 6),),
)
def _noise(tensor, _seed, _batch_inds):
return torch.ones_like(tensor)
def test_target_masks_apply_only_selected_video_and_audio_ranges():
video = torch.zeros(1, 24, 6, 2, 2)
audio = torch.zeros(1, 32, 2, 8)
window = _small_group_window()
nested = lambda values: values
_noise_value, video_only_mask = _prepare_video_only_noise_and_mask(
video,
audio,
seed=1,
prepare_noise_fn=_noise,
nested_builder=nested,
temporal_window=window,
)
assert torch.count_nonzero(video_only_mask[0][:, :, :2]) == 0
assert torch.all(video_only_mask[0][:, :, 2:4] == 1)
assert torch.count_nonzero(video_only_mask[0][:, :, 4:]) == 0
assert torch.count_nonzero(video_only_mask[1]) == 0
_noise_value, audio_only_mask = _prepare_audio_only_noise_and_mask(
video,
audio,
seed=1,
prepare_noise_fn=_noise,
nested_builder=nested,
temporal_window=window,
)
assert torch.count_nonzero(audio_only_mask[0]) == 0
assert torch.all(audio_only_mask[1][..., 3:6] == 1)
assert torch.count_nonzero(audio_only_mask[1][..., :3]) == 0
assert torch.count_nonzero(audio_only_mask[1][..., 6:]) == 0
_noise_value, both_mask = _prepare_video_audio_noise_and_mask(
video,
audio,
seed=1,
prepare_noise_fn=_noise,
nested_builder=nested,
temporal_window=window,
)
assert torch.equal(both_mask[0], video_only_mask[0])
assert torch.equal(both_mask[1], audio_only_mask[1])
def test_outside_window_restore_is_bit_exact():
source = torch.arange(6, dtype=torch.float32).reshape(1, 1, 6, 1, 1)
sampled = torch.full_like(source, 99.0)
restored = _restore_outside_temporal_ranges(
sampled,
source,
((2, 4),),
time_dim=2,
name="Video",
)
assert torch.equal(restored[:, :, :2], source[:, :, :2])
assert torch.equal(restored[:, :, 4:], source[:, :, 4:])
assert torch.all(restored[:, :, 2:4] == 99.0)
assert torch.equal(source, torch.arange(6, dtype=torch.float32).reshape(1, 1, 6, 1, 1))
def test_target_dispatch_passes_window_without_changing_no_window_path():
calls = []
window = _small_group_window()
def fake(**kwargs):
calls.append(kwargs)
return kwargs["latent"]
base = dict(
model="model",
conditioning=[],
latent={"samples": "samples"},
sampler="sampler",
sigmas=torch.tensor([1.0, 0.0]),
seed=7,
enable_preview=False,
)
sample_targeted_refine_chunk(
**base,
refine_target=MODE_VIDEO_ONLY,
legacy_sample_fn=fake,
)
sample_targeted_refine_chunk(
**base,
refine_target=MODE_VIDEO_ONLY,
temporal_window=window,
video_only_window_sample_fn=fake,
)
assert "temporal_window" not in calls[0]
assert calls[1]["temporal_window"] is window
@pytest.mark.parametrize("target", (MODE_VIDEO_ONLY, MODE_AUDIO_ONLY, MODE_VIDEO_AUDIO))
def test_temporal_window_skips_outside_groups_before_any_work(target):
plan = _plan()
videos, audios = _latents(plan)
calls = {"encode": [], "clone": [], "sample": []}
def encode(_clip, prompt, **_kwargs):
calls["encode"].append(prompt)
return [prompt]
def clone(model, **kwargs):
calls["clone"].append(kwargs)
return model
def sample(**kwargs):
calls["sample"].append(kwargs)
return {
"video": kwargs["latent"]["video"] + 100.0,
"audio": kwargs["latent"]["audio"] + 200.0,
}
output_videos, output_audios, updated_plan, status = run_targeted_second_pass_groups(
model="model",
clip="clip",
sampler="sampler",
sigmas=torch.tensor([0.6, 0.3, 0.0]),
video_latents=videos,
audio_latents=audios,
assembly_plan=plan,
refine_seed=91,
refine_target=target,
refine_scope=MODE_TIME_WINDOW,
window_start_sec=5.0,
window_end_sec=10.0,
encode_prompt_fn=encode,
latent_builder=lambda video, audio: {"video": video, "audio": audio},
sample_fn=sample,
stream_extractor=lambda value: (value["video"], value["audio"]),
clone_model_fn=clone,
enable_preview=False,
)
assert len(calls["encode"]) == len(calls["clone"]) == len(calls["sample"]) == 2
assert [call["temporal_window"].group_index for call in calls["sample"]] == [0, 1]
assert output_videos[2] is videos[2]
assert output_audios[2] is audios[2]
assert "Refine Window: timeline=final_visible_output" in status
assert "refine_window_contract" not in updated_plan["second_pass_contract"]
def test_experimental_node_appends_time_window_inputs_without_changing_default():
required = H3ContinuumSelectiveSecondPassExperimental.INPUT_TYPES()["required"]
assert REFINE_SCOPE_TIME_WINDOW in required["refine_scope"][0]
assert required["refine_scope"][1]["default"] == "All"
assert required["window_start_sec"][1]["default"] == 0.0
assert required["window_end_sec"][1]["default"] == 5.0
+339
View File
@@ -0,0 +1,339 @@
from __future__ import annotations
import copy
import hashlib
from types import SimpleNamespace
import pytest
import torch
from ComfyUI_H3_Continuum_Join.v3.refine_schedule import make_tail_schedule
from ComfyUI_H3_Continuum_Join.v3.refine_target import (
MODE_VIDEO_AUDIO,
VIDEO_AUDIO_SEED_NAMESPACE,
derive_target_refine_seed,
)
from ComfyUI_H3_Continuum_Join.v3.second_pass import (
SecondPassContractError,
update_second_pass_geometry,
)
from ComfyUI_H3_Continuum_Join.v3 import targeted_refine_sampling
from ComfyUI_H3_Continuum_Join.v3.targeted_refine_sampling import (
_prepare_video_audio_noise_and_mask,
sample_video_audio_refine_chunk,
)
from ComfyUI_H3_Continuum_Join.v3.targeted_second_pass import (
run_targeted_second_pass_groups,
)
class _Nested:
def __init__(self, tensors):
self.tensors = tuple(tensors)
def unbind(self):
return self.tensors
def to(self, *_args, **_kwargs):
return self
def _sha(tensor: torch.Tensor) -> str:
value = tensor.detach().to(device="cpu").contiguous()
return hashlib.sha256(value.view(torch.uint8).numpy().tobytes()).hexdigest()
def test_video_audio_noise_is_random_and_mask_one_for_both_streams():
video = torch.zeros((1, 24, 3, 4, 4))
audio = torch.zeros((1, 32, 2, 12))
calls = []
def prepare_noise(samples, seed, batch_inds):
calls.append((samples, seed, batch_inds))
fill = 0.25 if samples.ndim == 5 else 0.75
return torch.full_like(samples, fill, device="cpu")
noise, noise_mask = _prepare_video_audio_noise_and_mask(
video,
audio,
seed=321,
batch_inds=[0],
prepare_noise_fn=prepare_noise,
nested_builder=_Nested,
)
video_noise, audio_noise = noise.unbind()
video_mask, audio_mask = noise_mask.unbind()
assert calls == [(video, 321, [0]), (audio, 321, [0])]
assert torch.equal(video_noise, torch.full_like(video, 0.25))
assert torch.equal(audio_noise, torch.full_like(audio, 0.75))
assert tuple(video_mask.shape) == (1, 1, 1, 1, 1)
assert tuple(audio_mask.shape) == (1, 1, 1, 1)
assert torch.all(video_mask == 1)
assert torch.all(audio_mask == 1)
def test_video_audio_sampler_passes_both_random_streams_and_exact_sigmas(monkeypatch):
video = torch.randn((1, 24, 3, 4, 4))
audio = torch.randn((1, 32, 2, 12))
latent_samples = _Nested((video, audio))
sigmas = torch.tensor([0.35, 0.2, 0.0])
captured = {"prepare_noise": []}
class _Guider:
def sample(self, noise, latent_image, sampler, supplied_sigmas, **kwargs):
captured.update(
noise=noise,
latent_image=latent_image,
sampler=sampler,
sigmas=supplied_sigmas,
**kwargs,
)
return _Nested((video + 3.0, audio + 5.0))
def prepare_noise(samples, seed, batch_inds):
captured["prepare_noise"].append((samples, seed, batch_inds))
fill = 0.2 if samples.ndim == 5 else 0.8
return torch.full_like(samples, fill, device="cpu")
fake_runtime = (
SimpleNamespace(intermediate_device=lambda: torch.device("cpu")),
SimpleNamespace(NestedTensor=_Nested),
SimpleNamespace(
fix_empty_latent_channels=lambda _model, samples, _spatial, _temporal: samples,
prepare_noise=prepare_noise,
),
SimpleNamespace(PROGRESS_BAR_ENABLED=False),
SimpleNamespace(prepare_callback=lambda *_args: None),
)
monkeypatch.setattr(
targeted_refine_sampling,
"_load_runtime_modules",
lambda: fake_runtime,
)
monkeypatch.setattr(
targeted_refine_sampling,
"_make_basic_guider",
lambda *_args: _Guider(),
)
sampler = object()
output = sample_video_audio_refine_chunk(
model=object(),
conditioning=["conditioning"],
latent={"samples": latent_samples},
sampler=sampler,
sigmas=sigmas,
seed=654,
enable_preview=False,
)
assert captured["prepare_noise"] == [(video, 654, None), (audio, 654, None)]
assert captured["latent_image"] is latent_samples
assert captured["sigmas"] is sigmas
assert captured["sampler"] is sampler
video_noise, audio_noise = captured["noise"].unbind()
video_mask, audio_mask = captured["denoise_mask"].unbind()
assert torch.equal(video_noise, torch.full_like(video_noise, 0.2))
assert torch.equal(audio_noise, torch.full_like(audio_noise, 0.8))
assert torch.all(video_mask == 1)
assert torch.all(audio_mask == 1)
sampled_video, sampled_audio = output["samples"].unbind()
assert torch.equal(sampled_video, video + 3.0)
assert torch.equal(sampled_audio, audio + 5.0)
def _group(group_id: int, *, temporal: int, audio_t: int, terminal: bool) -> dict:
return {
"group_id": group_id,
"logical_chunks": [1] if group_id == 0 else [2, 3],
"physical_prompt": f"group {group_id + 1}",
"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": 128,
"source_height": 128,
"source_batch": 1,
"latent_channels": 24,
"source_latent_t": temporal,
"source_latent_h": 8,
"source_latent_w": 8,
"source_audio_shape": [1, 32, 2, audio_t],
}
def _fixture():
groups = [
_group(0, temporal=31, audio_t=207, terminal=False),
_group(1, temporal=65, audio_t=433, terminal=True),
]
videos = [
{
"samples": torch.arange(
24 * group["source_latent_t"] * 8 * 8,
dtype=torch.float32,
).reshape(1, 24, group["source_latent_t"], 8, 8)
}
for group in groups
]
audios = [
{
"samples": torch.arange(
32 * 2 * group["source_audio_shape"][-1],
dtype=torch.float32,
).reshape(group["source_audio_shape"])
}
for group in groups
]
plan = {
"width": 128,
"height": 128,
"existing_top_level": {"preserved": True},
"second_pass_contract": {
"version": 1,
"existing_contract_field": "preserved",
"physical_groups": groups,
},
}
return groups, videos, audios, plan
def _run_video_audio(sample_fn):
groups, videos, audios, plan = _fixture()
source_sigmas = torch.tensor([0.6, 0.3, 0.0], dtype=torch.float32)
schedule = make_tail_schedule(source_sigmas, evaluation_count=1)
result = run_targeted_second_pass_groups(
model="model",
clip="clip",
sampler="sampler",
sigmas=source_sigmas,
video_latents=videos,
audio_latents=audios,
assembly_plan=plan,
refine_seed=91,
refine_target=MODE_VIDEO_AUDIO,
encode_prompt_fn=lambda _clip, prompt, **_kwargs: [prompt],
latent_builder=lambda video, audio: {"video": video, "audio": audio},
sample_fn=sample_fn,
stream_extractor=lambda value: (value["video"], value["audio"]),
clone_model_fn=lambda source, **kwargs: (source, kwargs),
refine_schedule=schedule,
enable_preview=False,
)
return groups, videos, audios, plan, source_sigmas, schedule, result
def test_video_audio_group_gate_adopts_both_streams_once_per_physical_group():
calls = []
def sample(**kwargs):
calls.append(kwargs)
return {
"video": kwargs["latent"]["video"] + float(len(calls)),
"audio": kwargs["latent"]["audio"] + 100.0 + float(len(calls)),
}
groups, videos, audios, plan, _sigmas, schedule, result = _run_video_audio(
sample
)
plan_before = copy.deepcopy(plan)
output_videos, output_audios, updated_plan, status = result
assert plan == plan_before
assert len(calls) == len(groups) == 2
assert groups[1]["logical_chunks"] == [2, 3]
assert groups[1]["terminal_merged"] is True
assert all(call["sigmas"] is schedule.sigmas for call in calls)
assert [call["seed"] for call in calls] == [
derive_target_refine_seed(91, 0, MODE_VIDEO_AUDIO),
derive_target_refine_seed(91, 1, MODE_VIDEO_AUDIO),
]
assert all(
output is not source
for output, source in zip(output_videos, videos, strict=True)
)
assert all(
output is not source
for output, source in zip(output_audios, audios, strict=True)
)
assert [_sha(item["samples"]) for item in output_videos] != [
_sha(item["samples"]) for item in videos
]
assert [_sha(item["samples"]) for item in output_audios] != [
_sha(item["samples"]) for item in audios
]
assert [tuple(item["samples"].shape) for item in output_videos] == [
tuple(item["samples"].shape) for item in videos
]
assert [tuple(item["samples"].shape) for item in output_audios] == [
tuple(item["samples"].shape) for item in audios
]
assert "GPU Experimental PASS / Production HOLD" in status
assert status.count("sampled_video_adopted=true") == 2
contract = updated_plan["second_pass_contract"]
assert contract["version"] == 1
assert contract["refine_target_contract"]["mode"] == MODE_VIDEO_AUDIO
assert (
contract["refine_target_contract"]["seed_namespace"]
== VIDEO_AUDIO_SEED_NAMESPACE
)
assert contract["video_output"] == "sampled"
assert contract["video_sampling"] == "seeded_random_mask_1"
assert contract["audio_output"] == "sampled"
assert contract["audio_sampling"] == "seeded_random_mask_1"
assert contract["refine_group_seeds"] == [call["seed"] for call in calls]
assert contract["refine_schedule"]["schedule_hash"] == schedule.contract[
"schedule_hash"
]
assert contract["refine_execution_contract"]["target"] == contract[
"refine_target_contract"
]
expected_plan = update_second_pass_geometry(plan, output_videos)
normalized = copy.deepcopy(updated_plan)
normalized_contract = normalized["second_pass_contract"]
for key in (
"execution",
"conditioning_sources",
"refine_seed_base",
"refine_group_seeds",
"video_output",
"video_sampling",
"audio_output",
"audio_sampling",
"refine_schedule",
"refine_schedule_identity",
"refine_target_contract",
"refine_execution_contract",
):
normalized_contract.pop(key)
assert normalized == expected_plan
@pytest.mark.parametrize(
"defect,match",
[
("video_shape", "video group 0 changed"),
("audio_shape", "audio group 0 changed"),
("video_nan", "video group 0 contains NaN or Inf"),
("audio_nan", "audio group 0 contains NaN or Inf"),
],
)
def test_video_audio_rejects_invalid_sampled_streams(defect, match):
def sample(**kwargs):
video = kwargs["latent"]["video"].clone()
audio = kwargs["latent"]["audio"].clone()
if defect == "video_shape":
video = video[..., :-1]
elif defect == "audio_shape":
audio = audio[..., :-1]
elif defect == "video_nan":
video.reshape(-1)[0] = float("nan")
elif defect == "audio_nan":
audio.reshape(-1)[0] = float("inf")
return {"video": video, "audio": audio}
with pytest.raises(SecondPassContractError, match=match):
_run_video_audio(sample)
+38 -1
View File
@@ -153,6 +153,43 @@ def test_storage_stats_deduplicate_shared_storage():
assert stats["unique_storages"] == 1
def test_memory_snapshot_does_not_probe_uninitialized_cuda(monkeypatch):
def forbidden(*args, **kwargs):
raise BaseException("CPU diagnostics must not query CUDA counters")
monkeypatch.setattr(torch.cuda, "is_initialized", lambda: False)
for name in ("is_available", "memory_allocated", "memory_reserved", "mem_get_info"):
monkeypatch.setattr(torch.cuda, name, forbidden)
tensor = torch.zeros((2, 3))
original = tensor.clone()
rng = torch.random.get_rng_state().clone()
text = hardening.format_memory_snapshot("CPU", tensor)
assert "CUDA_allocated=n/a, CUDA_reserved=n/a, CUDA_free=n/a" in text
assert "CPU_storage=" in text
assert torch.equal(tensor, original)
assert torch.equal(torch.random.get_rng_state(), rng)
def test_memory_snapshot_preserves_initialized_cuda_counters(monkeypatch):
monkeypatch.setattr(torch.cuda, "is_initialized", lambda: True)
monkeypatch.setattr(torch.cuda, "memory_allocated", lambda: 2 * 1024**2)
monkeypatch.setattr(torch.cuda, "memory_reserved", lambda: 3 * 1024**2)
monkeypatch.setattr(torch.cuda, "mem_get_info", lambda: (4 * 1024**2, 8 * 1024**2))
text = hardening.format_memory_snapshot("mock initialized CUDA")
assert "CUDA_allocated=2.0 MiB, CUDA_reserved=3.0 MiB, CUDA_free=4.0 MiB" in text
def test_memory_snapshot_counter_failure_is_diagnostic_only(monkeypatch):
def unavailable():
raise RuntimeError("counter unavailable")
monkeypatch.setattr(torch.cuda, "is_initialized", lambda: True)
monkeypatch.setattr(torch.cuda, "memory_allocated", unavailable)
text = hardening.format_memory_snapshot("counter failure", torch.zeros(1))
assert "CUDA_allocated=n/a, CUDA_reserved=n/a, CUDA_free=n/a" in text
assert "tensor_refs=1" in text
def test_session_storage_audit_reports_shared_cpu_storage():
video = torch.zeros((1, 2, 3))
audio = torch.zeros((1, 2, 4))
@@ -180,4 +217,4 @@ def test_core_chunked_io_capability_is_optional():
)
== "Unsupported"
)
assert hardening.core_video_vae_chunked_io_status(object()) == "Unknown"
assert hardening.core_video_vae_chunked_io_status(object()) == "Unknown"
+144 -144
View File
@@ -1,153 +1,153 @@
from __future__ import annotations
import pytest
import torch
from ComfyUI_H3_Continuum_Join.v3 import plan as plan_module
from __future__ import annotations
import pytest
import torch
from ComfyUI_H3_Continuum_Join.v3 import plan as plan_module
def _logical_plan():
return {
"width": 1,
"height": 1,
"chunks": [
{
"sequence_index": 0,
"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,
"frame_start": 0,
"frame_stop": 124,
},
{
"sequence_index": 1,
"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,
"frame_start": 124,
"frame_stop": 243,
},
],
"target_frames": 240,
}
def _terminal_entries():
physical_video = torch.arange(72, dtype=torch.float32).reshape(1, 1, 72, 1, 1)
physical_audio = torch.arange(405, dtype=torch.float32).reshape(1, 1, 405)
entries = [
{
"video": physical_video[:, :, 0:37].clone(),
"audio": physical_audio[..., 0:207].clone(),
},
{
"video": physical_video[:, :, 30:72].clone(),
"audio": physical_audio[..., 170:405].clone(),
},
]
return entries, physical_video, physical_audio
def test_terminal_logical_entries_recombine_bit_exact(monkeypatch):
entries, physical_video, physical_audio = _terminal_entries()
monkeypatch.setattr(
plan_module,
"make_assembly_plan",
lambda *args, **kwargs: _logical_plan(),
)
monkeypatch.setattr(plan_module, "validate_assembly_plan", lambda plan: plan)
decode_entries, assembly_plan = plan_module.prepare_physical_decode_entries(
entries,
chunk_seconds=5.0,
preserve_final_frame=True,
terminal_merged=True,
)
assert len(decode_entries) == 1
assert torch.equal(decode_entries[0]["video"], physical_video)
assert torch.equal(decode_entries[0]["audio"], physical_audio)
assert assembly_plan["logical_chunk_count"] == 2
assert assembly_plan["physical_decode_group_count"] == 1
assert assembly_plan["decode_groups"][0]["logical_chunk_indices"] == [1, 2]
assert assembly_plan["decode_groups"][0]["total_frames"] == 243
assert assembly_plan["decode_groups"][0]["trim_frames"] == 0
assert assembly_plan["decode_groups"][0]["net_frames"] == 243
def test_terminal_recombine_rejects_changed_overlap(monkeypatch):
entries, _, _ = _terminal_entries()
entries[1]["video"][:, :, 0].add_(1.0)
monkeypatch.setattr(
plan_module,
"make_assembly_plan",
lambda *args, **kwargs: _logical_plan(),
)
with pytest.raises(ValueError, match="overlap differs"):
plan_module.prepare_physical_decode_entries(
entries,
chunk_seconds=5.0,
preserve_final_frame=True,
terminal_merged=True,
)
def test_three_logical_chunks_use_two_physical_decode_groups(monkeypatch):
from ComfyUI_H3_Continuum_Join.v2.sequence import (
_split_terminal_merged_latents,
_terminal_pair_contract,
)
contract = _terminal_pair_contract(initial_pair=False, chunk_seconds=5.0)
video_t = contract["video_slices"][-1][1]
audio_t = contract["audio_slices"][-1][1]
physical_video = torch.arange(video_t, dtype=torch.float32).reshape(1, 1, video_t, 1, 1)
physical_audio = torch.arange(audio_t, dtype=torch.float32).reshape(1, 1, audio_t)
terminal_parts = _split_terminal_merged_latents(physical_video, physical_audio, contract)
first_entry = {
"video": torch.zeros((1, 1, 37, 1, 1), dtype=torch.float32),
"audio": torch.zeros((1, 1, 207), dtype=torch.float32),
}
{
"sequence_index": 0,
"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,
"frame_start": 0,
"frame_stop": 124,
},
{
"sequence_index": 1,
"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,
"frame_start": 124,
"frame_stop": 243,
},
],
"target_frames": 240,
}
def _terminal_entries():
physical_video = torch.arange(72, dtype=torch.float32).reshape(1, 1, 72, 1, 1)
physical_audio = torch.arange(405, dtype=torch.float32).reshape(1, 1, 405)
entries = [
{
"video": physical_video[:, :, 0:37].clone(),
"audio": physical_audio[..., 0:207].clone(),
},
{
"video": physical_video[:, :, 30:72].clone(),
"audio": physical_audio[..., 170:405].clone(),
},
]
return entries, physical_video, physical_audio
def test_terminal_logical_entries_recombine_bit_exact(monkeypatch):
entries, physical_video, physical_audio = _terminal_entries()
monkeypatch.setattr(
plan_module,
"make_assembly_plan",
lambda *args, **kwargs: _logical_plan(),
)
monkeypatch.setattr(plan_module, "validate_assembly_plan", lambda plan: plan)
decode_entries, assembly_plan = plan_module.prepare_physical_decode_entries(
entries,
chunk_seconds=5.0,
preserve_final_frame=True,
terminal_merged=True,
)
assert len(decode_entries) == 1
assert torch.equal(decode_entries[0]["video"], physical_video)
assert torch.equal(decode_entries[0]["audio"], physical_audio)
assert assembly_plan["logical_chunk_count"] == 2
assert assembly_plan["physical_decode_group_count"] == 1
assert assembly_plan["decode_groups"][0]["logical_chunk_indices"] == [1, 2]
assert assembly_plan["decode_groups"][0]["total_frames"] == 243
assert assembly_plan["decode_groups"][0]["trim_frames"] == 0
assert assembly_plan["decode_groups"][0]["net_frames"] == 243
def test_terminal_recombine_rejects_changed_overlap(monkeypatch):
entries, _, _ = _terminal_entries()
entries[1]["video"][:, :, 0].add_(1.0)
monkeypatch.setattr(
plan_module,
"make_assembly_plan",
lambda *args, **kwargs: _logical_plan(),
)
with pytest.raises(ValueError, match="overlap differs"):
plan_module.prepare_physical_decode_entries(
entries,
chunk_seconds=5.0,
preserve_final_frame=True,
terminal_merged=True,
)
def test_three_logical_chunks_use_two_physical_decode_groups(monkeypatch):
from ComfyUI_H3_Continuum_Join.v2.sequence import (
_split_terminal_merged_latents,
_terminal_pair_contract,
)
contract = _terminal_pair_contract(initial_pair=False, chunk_seconds=5.0)
video_t = contract["video_slices"][-1][1]
audio_t = contract["audio_slices"][-1][1]
physical_video = torch.arange(video_t, dtype=torch.float32).reshape(1, 1, video_t, 1, 1)
physical_audio = torch.arange(audio_t, dtype=torch.float32).reshape(1, 1, audio_t)
terminal_parts = _split_terminal_merged_latents(physical_video, physical_audio, contract)
first_entry = {
"video": torch.zeros((1, 1, 37, 1, 1), dtype=torch.float32),
"audio": torch.zeros((1, 1, 207), dtype=torch.float32),
}
logical_plan = {
"width": 1,
"height": 1,
"chunks": [
{"sequence_index": 0, "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, "frame_start": 0, "frame_stop": 124},
{"sequence_index": 1, "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, "frame_start": 124, "frame_stop": 243},
{"sequence_index": 2, "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, "frame_start": 243, "frame_stop": 362},
],
"target_frames": 360,
}
entries = [
first_entry,
{"video": terminal_parts[0][0], "audio": terminal_parts[0][1]},
{"video": terminal_parts[1][0], "audio": terminal_parts[1][1]},
]
monkeypatch.setattr(plan_module, "make_assembly_plan", lambda *args, **kwargs: logical_plan)
monkeypatch.setattr(plan_module, "validate_assembly_plan", lambda plan: plan)
decode_entries, assembly_plan = plan_module.prepare_physical_decode_entries(
entries,
chunk_seconds=5.0,
preserve_final_frame=True,
terminal_merged=True,
)
assert len(decode_entries) == 2
assert torch.equal(decode_entries[1]["video"], physical_video)
assert torch.equal(decode_entries[1]["audio"], physical_audio)
assert assembly_plan["physical_decode_group_count"] == 2
terminal_group = assembly_plan["decode_groups"][1]
assert terminal_group["logical_chunk_indices"] == [2, 3]
assert terminal_group["total_frames"] == 260
assert terminal_group["trim_frames"] == 22
assert terminal_group["net_frames"] == 238
{"sequence_index": 0, "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, "frame_start": 0, "frame_stop": 124},
{"sequence_index": 1, "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, "frame_start": 124, "frame_stop": 243},
{"sequence_index": 2, "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, "frame_start": 243, "frame_stop": 362},
],
"target_frames": 360,
}
entries = [
first_entry,
{"video": terminal_parts[0][0], "audio": terminal_parts[0][1]},
{"video": terminal_parts[1][0], "audio": terminal_parts[1][1]},
]
monkeypatch.setattr(plan_module, "make_assembly_plan", lambda *args, **kwargs: logical_plan)
monkeypatch.setattr(plan_module, "validate_assembly_plan", lambda plan: plan)
decode_entries, assembly_plan = plan_module.prepare_physical_decode_entries(
entries,
chunk_seconds=5.0,
preserve_final_frame=True,
terminal_merged=True,
)
assert len(decode_entries) == 2
assert torch.equal(decode_entries[1]["video"], physical_video)
assert torch.equal(decode_entries[1]["audio"], physical_audio)
assert assembly_plan["physical_decode_group_count"] == 2
terminal_group = assembly_plan["decode_groups"][1]
assert terminal_group["logical_chunk_indices"] == [2, 3]
assert terminal_group["total_frames"] == 260
assert terminal_group["trim_frames"] == 22
assert terminal_group["net_frames"] == 238
+4 -16
View File
@@ -345,21 +345,9 @@ def test_experimental_seam_analyzer_is_registered_separately():
assert NODE_CLASS_MAPPINGS["H3ContinuumAssembleV3"] is not H3ContinuumAssembleSeamExperimental
def test_v34_seam_is_public_and_experimental_seam_is_legacy():
def test_v34_and_experimental_seam_remain_internal_only():
from ComfyUI_H3_Continuum_Join import nodes as root_nodes
legacy_class = root_nodes.NODE_CLASS_MAPPINGS["H3ContinuumAssembleSeamExperimental"]
assert getattr(legacy_class, "DEPRECATED", False)
assert legacy_class.CATEGORY == "MiniMax H3/Continuum/Legacy"
assert root_nodes.NODE_DISPLAY_NAME_MAPPINGS["H3ContinuumAssembleSeamExperimental"] == (
"[Legacy] H3 Continuum Assemble + Seam"
)
node_class = root_nodes.NODE_CLASS_MAPPINGS["H3ContinuumAssembleSeamV34"]
assert not getattr(node_class, "DEPRECATED", False)
assert node_class.CATEGORY == "MiniMax H3/Continuum"
assert root_nodes.NODE_DISPLAY_NAME_MAPPINGS["H3ContinuumAssembleSeamV34"] == (
"H3 Continuum Assemble + Seam V3.4"
)
assert root_nodes.NODE_DISPLAY_NAME_MAPPINGS["H3ContinuumAssembleV3"] == (
"[Legacy] H3 Continuum Assemble V3.2.4"
)
assert "H3ContinuumAssembleSeamExperimental" not in root_nodes.NODE_CLASS_MAPPINGS
assert "H3ContinuumAssembleSeamV34" not in root_nodes.NODE_CLASS_MAPPINGS
assert "H3ContinuumAssembleV3" not in root_nodes.NODE_CLASS_MAPPINGS