Release v3.7.0 refinement foundation
This commit is contained in:
@@ -12,6 +12,7 @@ from ComfyUI_H3_Continuum_Join.constants import (
|
||||
MARK_VIDEO_CONTEXT,
|
||||
)
|
||||
from ComfyUI_H3_Continuum_Join.model_patch import (
|
||||
LayoutValidationProfiler,
|
||||
_wrapper_factory,
|
||||
clone_model_for_chunk,
|
||||
patch_model,
|
||||
@@ -135,6 +136,75 @@ def test_apply_model_wrapper_fails_when_actual_topology_changes():
|
||||
wrapper(Executor(), torch.zeros(1), transformer_options=options, minimax_payload=payload)
|
||||
|
||||
|
||||
def test_layout_validation_profiler_records_full_calls_groups_and_step_contribution():
|
||||
profiler = LayoutValidationProfiler(route_markers="Sage + Sol + Spectrum")
|
||||
token = profiler.begin_sampling_group(
|
||||
physical_group=2,
|
||||
logical_chunks=(2,),
|
||||
sampling_steps=20,
|
||||
)
|
||||
profiler.record_validation(
|
||||
{"status": "baseline_created"},
|
||||
0.01,
|
||||
full_validation=True,
|
||||
)
|
||||
profiler.record_validation(
|
||||
{"status": "baseline_matched"},
|
||||
0.03,
|
||||
full_validation=True,
|
||||
)
|
||||
profiler.finish_sampling_group(token)
|
||||
|
||||
report = "\n".join(profiler.report_lines())
|
||||
assert "route_markers=Sage + Sol + Spectrum" in report
|
||||
assert "validation_calls=2" in report
|
||||
assert "full_validation_count=2" in report
|
||||
assert "cumulative_wall_including_existing_device_to_host_sync=0.040000s" in report
|
||||
assert "sampling_steps_total=20" in report
|
||||
assert "validated_sampling_steps=20" in report
|
||||
assert "calls_per_validated_step=0.100" in report
|
||||
assert "wall_per_validated_step=2.000ms" in report
|
||||
assert "physical_group=2" in report
|
||||
|
||||
|
||||
def test_apply_model_wrapper_reports_validator_status_without_changing_payload():
|
||||
video = torch.zeros(1, 24, 1, 1, 1)
|
||||
audio = torch.zeros(1, 32, 2, 1)
|
||||
ref = {
|
||||
"kind": "video_audio",
|
||||
"latent_t": 1,
|
||||
"latent_h": 1,
|
||||
"latent_w": 1,
|
||||
"ref_audio_t": 1,
|
||||
"latent": video,
|
||||
"audio_latent": audio,
|
||||
MARK_VIDEO_CONTEXT: True,
|
||||
MARK_CONTEXT_FRAMES: 1,
|
||||
MARK_AUDIO_CONTEXT: True,
|
||||
MARK_AUDIO_END_FRAME: 1.0,
|
||||
MARK_AUDIO_OVERHANG: 0.0,
|
||||
}
|
||||
payload = {"layout": _layout(), "keyframes": [], "refs": [ref]}
|
||||
profiler = LayoutValidationProfiler(route_markers="Sage")
|
||||
wrapper = _wrapper_factory(
|
||||
strict=True,
|
||||
debug=False,
|
||||
validation_profiler=profiler,
|
||||
)
|
||||
|
||||
first = wrapper(Executor(), torch.zeros(1), minimax_payload=payload)
|
||||
second = wrapper(Executor(), torch.zeros(1), minimax_payload=payload)
|
||||
|
||||
assert first["cond_video_latents"] == [video]
|
||||
assert second["cond_audio_latents"] == [audio]
|
||||
assert profiler.validation_calls == 2
|
||||
assert profiler.full_validation_count == 2
|
||||
assert profiler.status_counts == {
|
||||
"baseline_created": 1,
|
||||
"baseline_matched": 1,
|
||||
}
|
||||
|
||||
|
||||
class FakeModelPatcher:
|
||||
def __init__(self):
|
||||
inner_type = type(
|
||||
|
||||
@@ -6,7 +6,7 @@ import tomllib
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
EXPECTED_VERSION = "3.6.1"
|
||||
EXPECTED_VERSION = "3.7.0"
|
||||
|
||||
|
||||
def test_v35_release_metadata_is_consistent():
|
||||
|
||||
@@ -145,4 +145,4 @@ def test_v217_result_pack_expands_legacy_outputs():
|
||||
def test_v217_has_no_frontend_display_controller():
|
||||
assert not (ROOT / "web" / "h3_continuum_v2.js").exists()
|
||||
version_source = (ROOT / "version.py").read_text(encoding="utf-8")
|
||||
assert 'PACKAGE_VERSION = "3.6.1"' in version_source
|
||||
assert 'PACKAGE_VERSION = "3.7.0"' in version_source
|
||||
|
||||
@@ -16,6 +16,7 @@ from ComfyUI_H3_Continuum_Join.v2.prompts import (
|
||||
detect_prompt_mode,
|
||||
make_prompt_plan,
|
||||
parse_sparse_prompt_overrides,
|
||||
prompt_hash,
|
||||
prompt_plan_report,
|
||||
validate_sparse_prompt_overrides,
|
||||
validate_prompt_plan,
|
||||
@@ -30,6 +31,140 @@ def test_fixed_prompt_repeats_without_mutation():
|
||||
assert validate_prompt_plan(plan) is plan
|
||||
|
||||
|
||||
def test_prompt_transparency_t1_fixed_passthrough():
|
||||
script = "\n".join(
|
||||
[
|
||||
"<d>Hello world</d>",
|
||||
"embedding:character_style",
|
||||
"<Picture 1>",
|
||||
"<FutureH3Token>",
|
||||
"日本語 text:01",
|
||||
"symbols +=[]{}()",
|
||||
]
|
||||
)
|
||||
plan = make_prompt_plan(
|
||||
mode=PROMPT_MODE_FIXED,
|
||||
script=script,
|
||||
chunks=2,
|
||||
chunk_seconds=5,
|
||||
)
|
||||
assert plan["prompts"] == [script, script]
|
||||
|
||||
|
||||
def test_prompt_transparency_t2_list_passthrough():
|
||||
plan = make_prompt_plan(
|
||||
mode=PROMPT_MODE_LIST,
|
||||
script=(
|
||||
"<d>first dialogue</d>\n"
|
||||
"embedding:style_a\n"
|
||||
"---\n"
|
||||
"<d>second dialogue</d>\n"
|
||||
"<FutureToken>"
|
||||
),
|
||||
chunks=2,
|
||||
chunk_seconds=5,
|
||||
)
|
||||
assert plan["prompts"] == [
|
||||
"<d>first dialogue</d>\nembedding:style_a",
|
||||
"<d>second dialogue</d>\n<FutureToken>",
|
||||
]
|
||||
|
||||
|
||||
def test_prompt_transparency_t3_timeline_passthrough():
|
||||
plan = make_prompt_plan(
|
||||
mode=PROMPT_MODE_TIMELINE,
|
||||
script=(
|
||||
"Shared <FutureToken>\n"
|
||||
"embedding:global_style\n\n"
|
||||
"[0-5s]\n"
|
||||
"<d>first line</d>\n\n"
|
||||
"[5-10s]\n"
|
||||
"<d>second line</d>\n"
|
||||
"<Picture 2>"
|
||||
),
|
||||
chunks=2,
|
||||
chunk_seconds=5,
|
||||
)
|
||||
assert plan["prompts"] == [
|
||||
"Shared <FutureToken>\nembedding:global_style\n\n<d>first line</d>",
|
||||
"Shared <FutureToken>\nembedding:global_style\n\n<d>second line</d>\n<Picture 2>",
|
||||
]
|
||||
|
||||
|
||||
def test_prompt_transparency_t4_timeline_preamble_passthrough():
|
||||
preamble = "embedding:character_x\n<FutureToken>\n<d>shared instruction</d>"
|
||||
plan = make_prompt_plan(
|
||||
mode=PROMPT_MODE_TIMELINE,
|
||||
script=f"{preamble}\n\n[Chunk 1]\nfirst\n[Chunk 2]\nsecond",
|
||||
chunks=2,
|
||||
chunk_seconds=5,
|
||||
)
|
||||
assert plan["prompts"] == [
|
||||
f"{preamble}\n\nfirst",
|
||||
f"{preamble}\n\nsecond",
|
||||
]
|
||||
|
||||
|
||||
def test_prompt_transparency_t5_external_override_passthrough_and_rehash():
|
||||
plan = make_prompt_plan(
|
||||
mode=PROMPT_MODE_FIXED,
|
||||
script="base",
|
||||
chunks=2,
|
||||
chunk_seconds=5,
|
||||
)
|
||||
override = "<d>override dialogue</d>\nembedding:new_style\n<UnknownSpecial>"
|
||||
updated = apply_prompt_overrides(plan, [None, override])
|
||||
assert updated["prompts"] == ["base", override]
|
||||
assert updated["hashes"][0] == plan["hashes"][0]
|
||||
assert updated["hashes"][1] == prompt_hash(override)
|
||||
assert updated["hashes"][1] != plan["hashes"][1]
|
||||
|
||||
|
||||
def test_prompt_transparency_t6_invalid_timeline_fallback_passthrough():
|
||||
script = "[0 to 5s]\n<d>Hello</d>\nembedding:style\n<UnknownSpecial>"
|
||||
plan = make_prompt_plan(
|
||||
mode=PROMPT_MODE_TIMELINE,
|
||||
script=script,
|
||||
chunks=2,
|
||||
chunk_seconds=5,
|
||||
)
|
||||
assert plan["mode"] == PROMPT_MODE_FIXED
|
||||
assert plan["prompts"] == [script, script]
|
||||
assert plan["diagnostics"][0]["code"] == "H3C-P100"
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("left", "right"),
|
||||
[
|
||||
("<d>Hello</d>", "<d>hello</d>"),
|
||||
("embedding:a", "embedding:b"),
|
||||
("<FutureA>", "<FutureB>"),
|
||||
],
|
||||
)
|
||||
def test_prompt_transparency_t7_hash_sensitivity(left, right):
|
||||
assert prompt_hash(left) == prompt_hash(left)
|
||||
assert prompt_hash(left) != prompt_hash(right)
|
||||
|
||||
|
||||
def test_prompt_transparency_t8_unknown_future_syntax_is_literal():
|
||||
script = "\n".join(
|
||||
[
|
||||
'<h3_future_control value="1">',
|
||||
"<future:abc>",
|
||||
"[[SPECIAL_X]]",
|
||||
"token://future/value",
|
||||
]
|
||||
)
|
||||
plan = make_prompt_plan(
|
||||
mode=PROMPT_MODE_FIXED,
|
||||
script=script,
|
||||
chunks=2,
|
||||
chunk_seconds=5,
|
||||
)
|
||||
assert plan["prompts"] == [script, script]
|
||||
assert "diagnostics" not in plan
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("script", "expected"),
|
||||
[
|
||||
|
||||
@@ -11,6 +11,7 @@ from ComfyUI_H3_Continuum_Join.v2.sequence import (
|
||||
_terminal_physical_seed_plan,
|
||||
_terminal_pair_contract,
|
||||
_terminal_sampling_plan,
|
||||
_terminal_strategy_mismatch,
|
||||
)
|
||||
from ComfyUI_H3_Continuum_Join.v2.seeds import derive_chunk_seed
|
||||
|
||||
@@ -97,6 +98,27 @@ def test_rerolling_final_chunk_regenerates_both_terminal_chunks():
|
||||
assert reset is True
|
||||
|
||||
|
||||
def test_two_chunk_terminal_cache_extended_to_three_reuses_one_generates_two():
|
||||
preserved = [{"chunk": 1}, {"chunk": 2}]
|
||||
|
||||
reusable, reset = _atomic_terminal_prefix(
|
||||
preserved,
|
||||
chunks=3,
|
||||
reroll_from_chunk=3,
|
||||
)
|
||||
normal, terminal = _terminal_sampling_plan(
|
||||
chunks=3,
|
||||
completed=len(reusable),
|
||||
merge_enabled=True,
|
||||
)
|
||||
|
||||
assert reusable == preserved[:1]
|
||||
assert reset is True
|
||||
assert normal == ()
|
||||
assert terminal is True
|
||||
assert (len(reusable), 2) == (1, 2)
|
||||
|
||||
|
||||
def test_complete_terminal_pair_remains_reusable_without_reroll():
|
||||
preserved = [{"chunk": 1}, {"chunk": 2}, {"chunk": 3}]
|
||||
result, reset = _atomic_terminal_prefix(preserved, chunks=3, reroll_from_chunk=0)
|
||||
@@ -104,6 +126,29 @@ def test_complete_terminal_pair_remains_reusable_without_reroll():
|
||||
assert reset is False
|
||||
|
||||
|
||||
def test_non_terminal_flf_keeps_run_storage_validated_prefix_without_terminal_strategy():
|
||||
session = {"settings": {"run_storage_validated_prefix": True}}
|
||||
|
||||
assert not _terminal_strategy_mismatch(session, merge_enabled=False)
|
||||
|
||||
|
||||
def test_terminal_merge_rejects_prefix_without_matching_strategy():
|
||||
session = {"settings": {"run_storage_validated_prefix": True}}
|
||||
|
||||
assert _terminal_strategy_mismatch(session, merge_enabled=True)
|
||||
|
||||
|
||||
def test_terminal_merge_keeps_prefix_with_matching_strategy():
|
||||
session = {
|
||||
"settings": {
|
||||
"run_storage_validated_prefix": True,
|
||||
"flf_execution": "terminal_merged_10s_seed_v2",
|
||||
}
|
||||
}
|
||||
|
||||
assert not _terminal_strategy_mismatch(session, merge_enabled=True)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("base_seed", [42, 123456789])
|
||||
def test_initial_terminal_pair_uses_base_seed_directly(base_seed):
|
||||
plan = _terminal_physical_seed_plan(
|
||||
|
||||
@@ -10,6 +10,7 @@ import ctypes
|
||||
|
||||
from ComfyUI_H3_Continuum_Join.run_storage import (
|
||||
RunStorageController,
|
||||
_hash,
|
||||
_resume_session_settings,
|
||||
_apply_nonce_contract,
|
||||
_fsync_file,
|
||||
@@ -297,7 +298,9 @@ def _sampling_contract(
|
||||
execution_semantics=None,
|
||||
reference_audio_contract=None,
|
||||
reference_audio_vae=None, prompt_hashes=None,
|
||||
chunks=3, reroll_from_chunk=2,
|
||||
):
|
||||
default_hashes = [str(index) * 64 for index in range(1, int(chunks) + 1)]
|
||||
return build_sampling_contract(
|
||||
model=model or _Model(),
|
||||
model_fingerprint_value="f" * 64,
|
||||
@@ -306,8 +309,8 @@ def _sampling_contract(
|
||||
sampler=sampler or _Sampler(),
|
||||
sigmas=torch.tensor([1.0, 0.0]),
|
||||
prompt_plan={
|
||||
"chunks": 3,
|
||||
"hashes": list(prompt_hashes or ["1" * 64, "2" * 64, "3" * 64]),
|
||||
"chunks": int(chunks),
|
||||
"hashes": list(prompt_hashes or default_hashes),
|
||||
"mode": "list",
|
||||
},
|
||||
width=96,
|
||||
@@ -316,7 +319,7 @@ def _sampling_contract(
|
||||
continuity="Balanced",
|
||||
audio_continuity=True,
|
||||
base_seed=1,
|
||||
reroll_from_chunk=2,
|
||||
reroll_from_chunk=int(reroll_from_chunk),
|
||||
reroll_nonce=reroll_nonce,
|
||||
first_frame_hash=first_frame_hash,
|
||||
last_frame_hash=last_frame_hash,
|
||||
@@ -332,6 +335,194 @@ def _sampling_contract(
|
||||
)
|
||||
|
||||
|
||||
def _persist_contract_prefix(tmp_path, contract, *, count):
|
||||
controller = RunStorageController("extend-prefix")
|
||||
controller.revisions_root = tmp_path / "revisions"
|
||||
controller.revision_id, controller.contract_sha256 = revision_identity(contract)
|
||||
controller.revision_root = controller.revisions_root / controller.revision_id
|
||||
controller.contract = contract
|
||||
controller.prompts = [f"prompt {index + 1}" for index in range(int(count))]
|
||||
controller.manifest = {
|
||||
"contract": contract,
|
||||
"chunks": [],
|
||||
"status": "in_progress",
|
||||
}
|
||||
for position in range(int(count)):
|
||||
controller.commit_chunk(
|
||||
_entry(position, prompt=controller.prompts[position]),
|
||||
position=position,
|
||||
)
|
||||
return controller
|
||||
|
||||
|
||||
def _load_compatible_prefix(tmp_path, stored, current):
|
||||
controller = RunStorageController("extend-prefix")
|
||||
controller.revisions_root = tmp_path / "revisions"
|
||||
controller.contract = current
|
||||
controller.prompts = [
|
||||
f"prompt {index + 1}" for index in range(int(current["chunk_count"]))
|
||||
]
|
||||
entries, records = controller._valid_prefix(
|
||||
stored.manifest, current["chunk_contract_hashes"]
|
||||
)
|
||||
return controller, entries, records
|
||||
|
||||
|
||||
def _legacy_none_final_contract(contract):
|
||||
legacy = copy.deepcopy(contract)
|
||||
legacy["last_frame_hash"] = "none"
|
||||
legacy["chunk_contracts"][-1]["last_frame_hash"] = "none"
|
||||
legacy["chunk_contract_hashes"][-1] = _hash(legacy["chunk_contracts"][-1])
|
||||
return legacy
|
||||
|
||||
|
||||
@pytest.mark.parametrize("absent", [None, "", "none", "null", " NONE ", " NULL "])
|
||||
def test_absent_last_frame_hash_is_canonical_for_every_chunk(absent):
|
||||
contract, safe, reasons = _sampling_contract(
|
||||
last_frame_hash=absent,
|
||||
chunks=3,
|
||||
reroll_from_chunk=3,
|
||||
)
|
||||
|
||||
assert safe, reasons
|
||||
assert contract["last_frame_hash"] == ""
|
||||
assert [item["last_frame_hash"] for item in contract["chunk_contracts"]] == [
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
]
|
||||
|
||||
|
||||
def test_i2va_two_to_three_reuses_both_canonical_prefix_chunks(tmp_path):
|
||||
model, clip, video_vae, sampler = _Model(), _Clip(), _VideoVAE(), _Sampler()
|
||||
common = {
|
||||
"model": model,
|
||||
"clip": clip,
|
||||
"video_vae": video_vae,
|
||||
"sampler": sampler,
|
||||
}
|
||||
stored_contract, safe, reasons = _sampling_contract(
|
||||
**common, chunks=2, reroll_from_chunk=0, last_frame_hash=""
|
||||
)
|
||||
assert safe, reasons
|
||||
current_contract, safe, reasons = _sampling_contract(
|
||||
**common, chunks=3, reroll_from_chunk=3, last_frame_hash=""
|
||||
)
|
||||
assert safe, reasons
|
||||
stored = _persist_contract_prefix(tmp_path, stored_contract, count=2)
|
||||
|
||||
controller, entries, records = _load_compatible_prefix(
|
||||
tmp_path, stored, current_contract
|
||||
)
|
||||
|
||||
assert len(entries) == len(records) == 2
|
||||
assert not controller.notes
|
||||
|
||||
|
||||
def test_i2va_two_to_three_reuses_legacy_none_final_chunk(tmp_path):
|
||||
model, clip, video_vae, sampler = _Model(), _Clip(), _VideoVAE(), _Sampler()
|
||||
common = {
|
||||
"model": model,
|
||||
"clip": clip,
|
||||
"video_vae": video_vae,
|
||||
"sampler": sampler,
|
||||
}
|
||||
canonical_stored, safe, reasons = _sampling_contract(
|
||||
**common, chunks=2, reroll_from_chunk=0, last_frame_hash=""
|
||||
)
|
||||
assert safe, reasons
|
||||
legacy_stored = _legacy_none_final_contract(canonical_stored)
|
||||
current_contract, safe, reasons = _sampling_contract(
|
||||
**common, chunks=3, reroll_from_chunk=3, last_frame_hash=""
|
||||
)
|
||||
assert safe, reasons
|
||||
stored = _persist_contract_prefix(tmp_path, legacy_stored, count=2)
|
||||
|
||||
controller, entries, records = _load_compatible_prefix(
|
||||
tmp_path, stored, current_contract
|
||||
)
|
||||
|
||||
assert len(entries) == len(records) == 2
|
||||
assert controller.notes == [
|
||||
"stored chunk 2 reused through V3.6.1 absent Last Frame compatibility"
|
||||
]
|
||||
|
||||
|
||||
def test_legacy_none_cache_exact_resume_reuses_every_chunk(tmp_path):
|
||||
model, clip, video_vae, sampler = _Model(), _Clip(), _VideoVAE(), _Sampler()
|
||||
common = {
|
||||
"model": model,
|
||||
"clip": clip,
|
||||
"video_vae": video_vae,
|
||||
"sampler": sampler,
|
||||
}
|
||||
canonical, safe, reasons = _sampling_contract(
|
||||
**common, chunks=2, reroll_from_chunk=0, last_frame_hash=""
|
||||
)
|
||||
assert safe, reasons
|
||||
legacy = _legacy_none_final_contract(canonical)
|
||||
current, safe, reasons = _sampling_contract(
|
||||
**common, chunks=2, reroll_from_chunk=0, last_frame_hash=""
|
||||
)
|
||||
assert safe, reasons
|
||||
stored = _persist_contract_prefix(tmp_path, legacy, count=2)
|
||||
|
||||
_, entries, records = _load_compatible_prefix(tmp_path, stored, current)
|
||||
|
||||
assert len(entries) == len(records) == 2
|
||||
|
||||
|
||||
def test_real_last_frame_two_to_three_invalidates_old_final_chunk(tmp_path):
|
||||
model, clip, video_vae, sampler = _Model(), _Clip(), _VideoVAE(), _Sampler()
|
||||
common = {
|
||||
"model": model,
|
||||
"clip": clip,
|
||||
"video_vae": video_vae,
|
||||
"sampler": sampler,
|
||||
"conditioning_mode": "fl2va",
|
||||
"last_frame_hash": "b" * 64,
|
||||
}
|
||||
stored_contract, safe, reasons = _sampling_contract(
|
||||
**common, chunks=2, reroll_from_chunk=0
|
||||
)
|
||||
assert safe, reasons
|
||||
current_contract, safe, reasons = _sampling_contract(
|
||||
**common, chunks=3, reroll_from_chunk=3
|
||||
)
|
||||
assert safe, reasons
|
||||
stored = _persist_contract_prefix(tmp_path, stored_contract, count=2)
|
||||
|
||||
_, entries, records = _load_compatible_prefix(tmp_path, stored, current_contract)
|
||||
|
||||
assert len(entries) == len(records) == 1
|
||||
|
||||
|
||||
def test_absent_last_frame_compatibility_rejects_any_other_chunk_difference(tmp_path):
|
||||
model, clip, video_vae, sampler = _Model(), _Clip(), _VideoVAE(), _Sampler()
|
||||
common = {
|
||||
"model": model,
|
||||
"clip": clip,
|
||||
"video_vae": video_vae,
|
||||
"sampler": sampler,
|
||||
}
|
||||
canonical, safe, reasons = _sampling_contract(
|
||||
**common, chunks=2, reroll_from_chunk=0, last_frame_hash=""
|
||||
)
|
||||
assert safe, reasons
|
||||
legacy = _legacy_none_final_contract(canonical)
|
||||
legacy["chunk_contracts"][1]["prompt_hash"] = "f" * 64
|
||||
legacy["chunk_contract_hashes"][1] = _hash(legacy["chunk_contracts"][1])
|
||||
current, safe, reasons = _sampling_contract(
|
||||
**common, chunks=3, reroll_from_chunk=3, last_frame_hash=""
|
||||
)
|
||||
assert safe, reasons
|
||||
stored = _persist_contract_prefix(tmp_path, legacy, count=2)
|
||||
|
||||
_, entries, records = _load_compatible_prefix(tmp_path, stored, current)
|
||||
|
||||
assert len(entries) == len(records) == 1
|
||||
|
||||
|
||||
def test_mixed_timeline_normalization_separates_run_storage_revision():
|
||||
script = "[Chunk 1]\nA\n[Chunk 2]\nB\n---\nC"
|
||||
normalized = make_prompt_plan(
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
from pathlib import Path
|
||||
import json
|
||||
import shutil
|
||||
import subprocess
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
@@ -45,6 +50,23 @@ def test_v36_sampler_uses_compact_settings_without_hiding_backend_choice():
|
||||
assert 'hidePersistentWidget(findWidget(node, "continuation_backend"))' not in configure
|
||||
|
||||
|
||||
def test_v37_sampler_inherits_v36_compact_frontend_and_queue_normalization():
|
||||
source = PROJECT_ID_JS.read_text(encoding="utf-8")
|
||||
configure = _function_source(source, "configureNode", "configureNodeAfterSetup")
|
||||
before_queue = source[source.index("async beforeQueuePrompt") :]
|
||||
|
||||
assert 'const V37_NODE_CLASS = "H3ContinuumSamplerV37";' in source
|
||||
assert "const isV37 = node.comfyClass === V37_NODE_CLASS;" in configure
|
||||
assert (
|
||||
"!isProduction && !isTimeline && !isV34 && !isV35 && !isV36 && !isV37"
|
||||
in configure
|
||||
)
|
||||
assert "isProduction || isV34 || isV35 || isV36 || isV37" in configure
|
||||
assert "isV35 || isV36 || isV37" in configure
|
||||
assert "node.comfyClass === V37_NODE_CLASS" in before_queue
|
||||
assert 'hidePersistentWidget(findWidget(node, "continuation_backend"))' not in configure
|
||||
|
||||
|
||||
def test_v35_assembler_uses_existing_compact_runtime_settings_path():
|
||||
source = PROJECT_ID_JS.read_text(encoding="utf-8")
|
||||
configure = _function_source(source, "configureAssembler", "configureNode")
|
||||
@@ -57,3 +79,99 @@ def test_v35_assembler_uses_existing_compact_runtime_settings_path():
|
||||
assert "node.comfyClass !== V35_ASSEMBLE_SEAM_NODE_CLASS" in configure
|
||||
assert "node.comfyClass === V35_ASSEMBLE_SEAM_NODE_CLASS" in before_queue
|
||||
assert 'hidePersistentWidget(findWidget(node, "diagnostics"))' in configure
|
||||
|
||||
|
||||
def test_run_storage_off_normalizes_widgets_reload_and_queued_inputs(tmp_path):
|
||||
node_executable = shutil.which("node")
|
||||
if node_executable is None:
|
||||
pytest.skip("Node.js is required for the frontend behavior regression")
|
||||
|
||||
source = PROJECT_ID_JS.read_text(encoding="utf-8")
|
||||
functions = "\n".join(
|
||||
[
|
||||
_function_source(source, "findWidget", "setWidgetVisible"),
|
||||
_function_source(source, "setWidgetVisible", "hidePersistentWidget"),
|
||||
_function_source(source, "linkedInput", "attachRefresh"),
|
||||
_function_source(source, "attachRefresh", "normalizeRunStorageState"),
|
||||
_function_source(source, "normalizeRunStorageState", "configureConditionalWidgets"),
|
||||
_function_source(source, "configureConditionalWidgets", "configureAssembler"),
|
||||
]
|
||||
)
|
||||
script = f"""
|
||||
const RUN_STORAGE_WIDGET = "run_storage";
|
||||
const REGENERATE_WIDGET = "reroll_from_chunk";
|
||||
const REROLL_NONCE_WIDGET = "reroll_nonce";
|
||||
const LEGACY_RUN_NAME_WIDGET = "run_name";
|
||||
const REFERENCE_SIZE_WIDGET = "reference_size";
|
||||
const TIMELINE_SIZE_WIDGET = "timeline_video_size";
|
||||
const VIDEO_REFERENCE_SIZE_WIDGET = "video_reference_size";
|
||||
{functions}
|
||||
|
||||
function widget(name, value) {{
|
||||
return {{ name, value, type: "combo", options: {{}}, computeSize: () => [120, 20] }};
|
||||
}}
|
||||
function makeNode(storage, regenerate, nonce) {{
|
||||
return {{
|
||||
widgets: [
|
||||
widget(RUN_STORAGE_WIDGET, storage),
|
||||
widget(REGENERATE_WIDGET, regenerate),
|
||||
widget(REROLL_NONCE_WIDGET, nonce),
|
||||
widget(LEGACY_RUN_NAME_WIDGET, "phase1-test"),
|
||||
widget(REFERENCE_SIZE_WIDGET, "Match Output"),
|
||||
widget(TIMELINE_SIZE_WIDGET, "Efficient"),
|
||||
widget(VIDEO_REFERENCE_SIZE_WIDGET, "Efficient"),
|
||||
],
|
||||
inputs: [],
|
||||
setDirtyCanvas() {{}},
|
||||
}};
|
||||
}}
|
||||
|
||||
const live = makeNode("Save + Auto Resume", "Auto", 0);
|
||||
configureConditionalWidgets(live);
|
||||
const liveStorage = findWidget(live, RUN_STORAGE_WIDGET);
|
||||
const liveRegenerate = findWidget(live, REGENERATE_WIDGET);
|
||||
const liveNonce = findWidget(live, REROLL_NONCE_WIDGET);
|
||||
liveRegenerate.value = "Chunk 2";
|
||||
liveRegenerate.callback("Chunk 2");
|
||||
liveNonce.value = 5;
|
||||
liveStorage.value = "Off";
|
||||
liveStorage.callback("Off");
|
||||
|
||||
const queued = {{ reroll_from_chunk: "Chunk 2", reroll_nonce: 5 }};
|
||||
normalizeRunStorageState(live, queued);
|
||||
|
||||
const reloaded = makeNode("Off", "Chunk 3", 9);
|
||||
configureConditionalWidgets(reloaded);
|
||||
const reloadRegenerate = findWidget(reloaded, REGENERATE_WIDGET);
|
||||
const reloadNonce = findWidget(reloaded, REROLL_NONCE_WIDGET);
|
||||
|
||||
console.log(JSON.stringify({{
|
||||
live: {{ regenerate: liveRegenerate.value, nonce: liveNonce.value }},
|
||||
queued,
|
||||
reloaded: {{
|
||||
regenerate: reloadRegenerate.value,
|
||||
nonce: reloadNonce.value,
|
||||
regenerateHidden: reloadRegenerate.hidden,
|
||||
nonceHidden: reloadNonce.hidden,
|
||||
}},
|
||||
}}));
|
||||
"""
|
||||
script_path = tmp_path / "run-storage-frontend-regression.js"
|
||||
script_path.write_text(script, encoding="utf-8")
|
||||
|
||||
result = subprocess.run(
|
||||
[node_executable, str(script_path)],
|
||||
check=True,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
)
|
||||
observed = json.loads(result.stdout)
|
||||
|
||||
assert observed["live"] == {"regenerate": "Auto", "nonce": 0}
|
||||
assert observed["queued"] == {"reroll_from_chunk": "Auto", "reroll_nonce": 0}
|
||||
assert observed["reloaded"] == {
|
||||
"regenerate": "Auto",
|
||||
"nonce": 0,
|
||||
"regenerateHidden": True,
|
||||
"nonceHidden": True,
|
||||
}
|
||||
|
||||
@@ -125,6 +125,7 @@ def test_enabled_pixel_vae_roundtrip_then_reuses_second_pass_contract(monkeypatc
|
||||
"sampled",
|
||||
)
|
||||
calls = []
|
||||
schedule = object()
|
||||
|
||||
def fake_roundtrip(video_latents, assembly_plan, **kwargs):
|
||||
calls.append(("roundtrip", video_latents, assembly_plan, kwargs))
|
||||
@@ -161,6 +162,7 @@ def test_enabled_pixel_vae_roundtrip_then_reuses_second_pass_contract(monkeypatc
|
||||
[17],
|
||||
[{"context": True}],
|
||||
["video-vae"],
|
||||
schedule,
|
||||
)
|
||||
|
||||
assert result[:3] == sentinel[:3]
|
||||
@@ -190,6 +192,7 @@ def test_enabled_pixel_vae_roundtrip_then_reuses_second_pass_contract(monkeypatc
|
||||
assert second_pass["refine_context"] == {"context": True}
|
||||
assert second_pass["video_vae"] == "video-vae"
|
||||
assert second_pass["conditioning_upscale_method"] == "bilinear"
|
||||
assert second_pass["refine_schedule"] is schedule
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
||||
@@ -6,6 +6,7 @@ import pytest
|
||||
import torch
|
||||
|
||||
from ComfyUI_H3_Continuum_Join.constants import MARK_VIDEO_CONTEXT
|
||||
from ComfyUI_H3_Continuum_Join.guide_timeline import MARK_STILL_IMAGE_GUIDE
|
||||
from ComfyUI_H3_Continuum_Join.v3 import refine_context as rc
|
||||
|
||||
|
||||
@@ -170,6 +171,71 @@ def test_keyframes_reencode_images_with_core_first_last_crop_rules(monkeypatch):
|
||||
assert stats["warnings"] == ()
|
||||
|
||||
|
||||
def test_arbitrary_guide_keyframe_reencodes_from_owned_source_image(monkeypatch):
|
||||
calls = []
|
||||
|
||||
def upscale(samples, width, height, method, crop):
|
||||
calls.append((width, height, method, crop, samples.clone()))
|
||||
return torch.nn.functional.interpolate(samples, size=(height, width), mode="nearest")
|
||||
|
||||
monkeypatch.setattr(rc, "_common_upscale", upscale)
|
||||
conditioning = _conditioning()
|
||||
conditioning[0][1]["minimax_keyframes"].append(
|
||||
{
|
||||
"resolved_frame_index": 60,
|
||||
"latent": torch.zeros((1, 24, 1, 2, 3)),
|
||||
MARK_STILL_IMAGE_GUIDE: True,
|
||||
}
|
||||
)
|
||||
guide_image = torch.full((1, 20, 30, 3), 0.625)
|
||||
group = _group(
|
||||
conditioning=conditioning,
|
||||
guide_images={60: guide_image},
|
||||
)
|
||||
vae = _FakeVAE()
|
||||
|
||||
adapted, stats = rc.adapt_group_conditioning(group, 4, 6, video_vae=vae)
|
||||
|
||||
guide_keyframe = adapted[0][1]["minimax_keyframes"][2]
|
||||
assert torch.all(guide_keyframe["latent"] == 3)
|
||||
assert calls[2][:4] == (96, 64, "lanczos", "center")
|
||||
assert torch.all(calls[2][4] == 0.625)
|
||||
assert stats["keyframes_reencoded"] == 3
|
||||
assert stats["guide_keyframes_reencoded"] == 1
|
||||
assert stats["keyframes_latent_fallback"] == 0
|
||||
assert group["guide_images"][60].device.type == "cpu"
|
||||
assert group["guide_images"][60].data_ptr() != guide_image.data_ptr()
|
||||
|
||||
|
||||
@pytest.mark.parametrize("frame_index", [0, 123])
|
||||
def test_guide_role_wins_when_guide_shares_first_or_last_frame(monkeypatch, frame_index):
|
||||
monkeypatch.setattr(rc, "_common_upscale", _upscale)
|
||||
conditioning = _conditioning()
|
||||
conditioning[0][1]["minimax_keyframes"].append(
|
||||
{
|
||||
"resolved_frame_index": frame_index,
|
||||
"latent": torch.full((1, 24, 1, 2, 3), 9.0),
|
||||
MARK_STILL_IMAGE_GUIDE: True,
|
||||
}
|
||||
)
|
||||
guide_image = torch.full((1, 32, 48, 3), 0.75)
|
||||
vae = _FakeVAE()
|
||||
|
||||
adapted, stats = rc.adapt_group_conditioning(
|
||||
_group(conditioning=conditioning, guide_images={frame_index: guide_image}),
|
||||
4,
|
||||
6,
|
||||
video_vae=vae,
|
||||
)
|
||||
|
||||
keyframes = adapted[0][1]["minimax_keyframes"]
|
||||
assert torch.all(keyframes[2]["latent"] == 3)
|
||||
assert torch.all(vae.inputs[2] == 0.75)
|
||||
assert not torch.equal(vae.inputs[2], vae.inputs[0])
|
||||
assert not torch.equal(vae.inputs[2], vae.inputs[1])
|
||||
assert stats["guide_keyframes_reencoded"] == 1
|
||||
|
||||
|
||||
def test_context_validation_matches_physical_group_assembly_contract():
|
||||
group = _group()
|
||||
context = rc.make_refine_context(
|
||||
|
||||
@@ -14,6 +14,7 @@ from ComfyUI_H3_Continuum_Join.v3.refine_context import (
|
||||
MAGIC as REFINE_CONTEXT_MAGIC,
|
||||
RefineConditioningAdaptationError,
|
||||
)
|
||||
from ComfyUI_H3_Continuum_Join.v3.refine_schedule import make_tail_schedule
|
||||
from ComfyUI_H3_Continuum_Join.v3.second_pass_nodes import (
|
||||
H3ContinuumSecondPassV35,
|
||||
)
|
||||
@@ -81,6 +82,7 @@ def _run_fixture(groups: list[dict]):
|
||||
def sample(**kwargs):
|
||||
calls[-1]["seed"] = kwargs["seed"]
|
||||
calls[-1]["conditioning"] = kwargs["conditioning"]
|
||||
calls[-1]["sigmas"] = kwargs["sigmas"]
|
||||
nested = kwargs["latent"]
|
||||
return {
|
||||
"video": nested["video"] + 1,
|
||||
@@ -151,12 +153,63 @@ def test_second_pass_uses_plan_prompts_one_seed_per_physical_group_and_audio_pas
|
||||
assert updated["second_pass_contract"]["audio_sampling"] == (
|
||||
"zero_noise_mask_locked"
|
||||
)
|
||||
schedule = updated["second_pass_contract"]["refine_schedule"]
|
||||
assert schedule["mode"] == "external"
|
||||
assert schedule["evaluation_count"] == 1
|
||||
assert updated["second_pass_contract"]["refine_schedule_identity"] == (
|
||||
schedule["schedule_hash"]
|
||||
)
|
||||
assert all(call["sigmas"] is calls[0]["sigmas"] for call in calls)
|
||||
assert "temporary_audio_discarded=true" in report
|
||||
assert "audio zero noise/mask=0" in report
|
||||
assert "refine_seed=" in report
|
||||
assert videos[1]["samples"].shape[2] == 65
|
||||
|
||||
|
||||
def test_internal_tail_schedule_passes_the_exact_suffix_and_records_identity():
|
||||
group = _group(0, temporal=31, prompt="physical prompt")
|
||||
video = _latent(torch.zeros((1, 24, 31, 48, 48)))
|
||||
audio = _latent(torch.ones(tuple(group["source_audio_shape"])))
|
||||
base_sigmas = torch.tensor([1.0, 0.75, 0.5, 0.25, 0.0])
|
||||
tail = make_tail_schedule(base_sigmas, evaluation_count=2)
|
||||
captured = {}
|
||||
|
||||
def sample(**kwargs):
|
||||
captured.update(kwargs)
|
||||
return kwargs["latent"]
|
||||
|
||||
_video, output_audio, updated, report = run_second_pass_groups(
|
||||
model=object(),
|
||||
clip=object(),
|
||||
sampler=object(),
|
||||
sigmas=base_sigmas,
|
||||
video_latents=[video],
|
||||
audio_latents=[audio],
|
||||
assembly_plan=_plan([group]),
|
||||
refine_seed=17,
|
||||
refine_schedule=tail,
|
||||
encode_prompt_fn=lambda *_args, **_kwargs: ["conditioning"],
|
||||
latent_builder=lambda video_samples, audio_samples: {
|
||||
"video": video_samples,
|
||||
"audio": audio_samples,
|
||||
},
|
||||
sample_fn=sample,
|
||||
stream_extractor=lambda sampled: (sampled["video"], sampled["audio"]),
|
||||
clone_model_fn=lambda source, **_kwargs: source,
|
||||
)
|
||||
|
||||
assert captured["sigmas"] is tail.sigmas
|
||||
assert torch.equal(captured["sigmas"], base_sigmas[2:])
|
||||
schedule = updated["second_pass_contract"]["refine_schedule"]
|
||||
assert schedule["mode"] == "tail"
|
||||
assert schedule["evaluation_count"] == 2
|
||||
assert schedule["start_index"] == 2
|
||||
assert schedule["noise_mode"] == "video_random_mask_1_audio_zero_mask_0"
|
||||
assert schedule["audio_policy"] == "locked_first_pass_bit_exact_passthrough"
|
||||
assert output_audio[0] is audio
|
||||
assert "mode=tail" in report
|
||||
|
||||
|
||||
def test_second_pass_defaults_to_audio_locked_refine_sampler(monkeypatch):
|
||||
group = _group(0, temporal=31, prompt="physical prompt")
|
||||
video = _latent(torch.zeros((1, 24, 31, 48, 48)))
|
||||
@@ -469,6 +522,7 @@ def test_second_pass_node_forwards_optional_refine_context_and_video_vae(monkeyp
|
||||
)
|
||||
context = {"context": True}
|
||||
video_vae = object()
|
||||
schedule = object()
|
||||
result = H3ContinuumSecondPassV35().refine(
|
||||
["model"],
|
||||
["clip"],
|
||||
@@ -480,11 +534,13 @@ def test_second_pass_node_forwards_optional_refine_context_and_video_vae(monkeyp
|
||||
[7],
|
||||
[context],
|
||||
[video_vae],
|
||||
schedule,
|
||||
)
|
||||
|
||||
assert result == sentinel
|
||||
assert captured["refine_context"] is context
|
||||
assert captured["video_vae"] is video_vae
|
||||
assert captured["refine_schedule"] is schedule
|
||||
|
||||
|
||||
def test_second_pass_node_is_registered_and_not_deprecated():
|
||||
|
||||
@@ -0,0 +1,328 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import copy
|
||||
|
||||
import pytest
|
||||
import torch
|
||||
|
||||
from ComfyUI_H3_Continuum_Join import guide_timeline as guide_module
|
||||
from ComfyUI_H3_Continuum_Join import run_storage as run_storage_module
|
||||
from ComfyUI_H3_Continuum_Join.guide_timeline import (
|
||||
GUIDE_MODE_STILL_IMAGE,
|
||||
GUIDE_SCHEMA_VERSION,
|
||||
GUIDE_TYPE,
|
||||
MARK_STILL_IMAGE_GUIDE,
|
||||
GuideTargetError,
|
||||
StillImageGuideAssets,
|
||||
attach_still_image_guide,
|
||||
combine_guide_identity,
|
||||
make_still_image_guide,
|
||||
prepare_still_image_guide_source,
|
||||
resolve_guide_for_physical_group,
|
||||
)
|
||||
from ComfyUI_H3_Continuum_Join.v3.driving_nodes import (
|
||||
H3ContinuumSamplerV36,
|
||||
H3ContinuumSamplerV37,
|
||||
H3ContinuumStillImageGuideV37,
|
||||
NODE_CLASS_MAPPINGS,
|
||||
)
|
||||
from ComfyUI_H3_Continuum_Join.v2 import nodes as v2_nodes_module
|
||||
from ComfyUI_H3_Continuum_Join.v2.nodes import H3ContinuumSamplerV2
|
||||
from ComfyUI_H3_Continuum_Join.run_storage import (
|
||||
build_sampling_contract,
|
||||
revision_identity,
|
||||
)
|
||||
|
||||
|
||||
def _prepare(monkeypatch, image, frame):
|
||||
monkeypatch.setattr(
|
||||
guide_module,
|
||||
"_resize_guide_image",
|
||||
lambda value, width, height: value[:1, ..., :3].contiguous(),
|
||||
)
|
||||
return prepare_still_image_guide_source(
|
||||
make_still_image_guide(image, frame),
|
||||
output_width=576,
|
||||
output_height=576,
|
||||
)
|
||||
|
||||
|
||||
def test_public_guide_payload_is_frame_based_and_versioned():
|
||||
image = torch.zeros((1, 4, 4, 3), dtype=torch.float32)
|
||||
payload = H3ContinuumStillImageGuideV37().pack(image, 183)[0]
|
||||
assert payload["schema_version"] == GUIDE_SCHEMA_VERSION
|
||||
assert payload["mode"] == GUIDE_MODE_STILL_IMAGE
|
||||
assert payload["absolute_frame"] == 183
|
||||
assert payload["image"] is image
|
||||
assert H3ContinuumStillImageGuideV37.RETURN_TYPES == (GUIDE_TYPE,)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("absolute_frame", [-1, 1.5, True])
|
||||
def test_public_guide_rejects_non_strict_frames(absolute_frame):
|
||||
image = torch.zeros((1, 4, 4, 3), dtype=torch.float32)
|
||||
with pytest.raises(GuideTargetError, match="absolute_frame"):
|
||||
make_still_image_guide(image, absolute_frame)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("batch", [0, 2, 5])
|
||||
def test_public_guide_rejects_non_single_image_batches(batch):
|
||||
image = torch.zeros((batch, 4, 4, 3), dtype=torch.float32)
|
||||
with pytest.raises(GuideTargetError, match="batch must be exactly 1"):
|
||||
make_still_image_guide(image, 0)
|
||||
|
||||
|
||||
def test_prepare_rejects_non_single_image_batch_defensively(monkeypatch):
|
||||
image = torch.zeros((2, 4, 4, 3), dtype=torch.float32)
|
||||
payload = {
|
||||
"schema_version": GUIDE_SCHEMA_VERSION,
|
||||
"mode": GUIDE_MODE_STILL_IMAGE,
|
||||
"absolute_frame": 0,
|
||||
"image": image,
|
||||
}
|
||||
with pytest.raises(GuideTargetError, match="batch must be exactly 1"):
|
||||
prepare_still_image_guide_source(
|
||||
payload, output_width=576, output_height=576
|
||||
)
|
||||
|
||||
|
||||
def test_run_storage_identity_scopes_image_frame_mode_and_schema(monkeypatch):
|
||||
image = torch.zeros((1, 4, 4, 3), dtype=torch.float32)
|
||||
source_a = _prepare(monkeypatch, image, 60)
|
||||
source_same = _prepare(monkeypatch, image.clone(), 60)
|
||||
source_frame = _prepare(monkeypatch, image.clone(), 61)
|
||||
changed = image.clone()
|
||||
changed[0, 0, 0, 0] = 1.0
|
||||
source_image = _prepare(monkeypatch, changed, 60)
|
||||
|
||||
identity = combine_guide_identity("base", source_a)
|
||||
assert identity == combine_guide_identity("base", source_same)
|
||||
assert identity != combine_guide_identity("base", source_frame)
|
||||
assert identity != combine_guide_identity("base", source_image)
|
||||
assert source_a.contract["mode"] == GUIDE_MODE_STILL_IMAGE
|
||||
assert source_a.contract["schema_version"] == GUIDE_SCHEMA_VERSION
|
||||
assert source_a.contract["absolute_frame"] == 60
|
||||
assert source_a.contract["source_image_sha256"]
|
||||
|
||||
|
||||
def test_prepared_guide_owns_the_original_source_image(monkeypatch):
|
||||
image = torch.rand((1, 6, 8, 3), dtype=torch.float32)
|
||||
source = _prepare(monkeypatch, image, 60)
|
||||
assert source.source_image is not image
|
||||
assert source.source_image.device.type == "cpu"
|
||||
assert torch.equal(source.source_image, image)
|
||||
image.fill_(0)
|
||||
assert not bool((source.source_image == 0).all())
|
||||
assert source.contract["source_width"] == 8
|
||||
assert source.contract["source_height"] == 6
|
||||
|
||||
|
||||
def test_prepare_rejects_future_mode_or_schema(monkeypatch):
|
||||
image = torch.zeros((1, 4, 4, 3), dtype=torch.float32)
|
||||
payload = make_still_image_guide(image, 0)
|
||||
bad_schema = dict(payload, schema_version=GUIDE_SCHEMA_VERSION + 1)
|
||||
bad_mode = dict(payload, mode="audio")
|
||||
with pytest.raises(GuideTargetError, match="schema"):
|
||||
prepare_still_image_guide_source(
|
||||
bad_schema, output_width=576, output_height=576
|
||||
)
|
||||
with pytest.raises(GuideTargetError, match="mode"):
|
||||
prepare_still_image_guide_source(
|
||||
bad_mode, output_width=576, output_height=576
|
||||
)
|
||||
|
||||
|
||||
def test_runtime_group_resolver_uses_context_prefix_and_visible_tail():
|
||||
target = resolve_guide_for_physical_group(
|
||||
183,
|
||||
target_frames=360,
|
||||
physical_group_index=1,
|
||||
logical_chunks=(2,),
|
||||
global_visible_start=124,
|
||||
natural_visible_stop=243,
|
||||
context_prefix_frames=22,
|
||||
physical_frames=141,
|
||||
terminal_merged=False,
|
||||
)
|
||||
assert target["local_visible_frame"] == 59
|
||||
assert target["resolved_frame_index"] == 81
|
||||
assert resolve_guide_for_physical_group(
|
||||
359,
|
||||
target_frames=360,
|
||||
physical_group_index=2,
|
||||
logical_chunks=(3,),
|
||||
global_visible_start=243,
|
||||
natural_visible_stop=362,
|
||||
context_prefix_frames=22,
|
||||
physical_frames=141,
|
||||
terminal_merged=False,
|
||||
)["resolved_frame_index"] == 138
|
||||
|
||||
|
||||
def test_runtime_group_resolver_supports_terminal_merge():
|
||||
target = resolve_guide_for_physical_group(
|
||||
243,
|
||||
target_frames=360,
|
||||
physical_group_index=1,
|
||||
logical_chunks=(2, 3),
|
||||
global_visible_start=124,
|
||||
natural_visible_stop=362,
|
||||
context_prefix_frames=22,
|
||||
physical_frames=260,
|
||||
terminal_merged=True,
|
||||
)
|
||||
assert target["logical_chunks"] == [2, 3]
|
||||
assert target["resolved_frame_index"] == 141
|
||||
assert target["terminal_merged"] is True
|
||||
|
||||
|
||||
def test_keyframe_injection_clones_and_preserves_existing_order():
|
||||
original = [[torch.zeros(1), {"minimax_keyframes": [
|
||||
{"resolved_frame_index": 0, "latent": torch.tensor([1.0])},
|
||||
{"resolved_frame_index": 123, "latent": torch.tensor([2.0])},
|
||||
], "minimax_frame_count": 124}]]
|
||||
before = copy.deepcopy(original)
|
||||
source = guide_module.StillImageGuideSource(
|
||||
image=torch.zeros((1, 4, 4, 3)),
|
||||
absolute_frame=60,
|
||||
contract={
|
||||
"schema_version": GUIDE_SCHEMA_VERSION,
|
||||
"mode": GUIDE_MODE_STILL_IMAGE,
|
||||
"absolute_frame": 60,
|
||||
"image_sha256": "x",
|
||||
},
|
||||
)
|
||||
assets = StillImageGuideAssets(source=source, latent=torch.tensor([3.0]))
|
||||
output = attach_still_image_guide(
|
||||
original,
|
||||
assets,
|
||||
{"resolved_frame_index": 60},
|
||||
)
|
||||
assert output is not original
|
||||
assert [item["resolved_frame_index"] for item in output[0][1]["minimax_keyframes"]] == [0, 123, 60]
|
||||
assert torch.equal(
|
||||
original[0][1]["minimax_keyframes"][0]["latent"],
|
||||
before[0][1]["minimax_keyframes"][0]["latent"],
|
||||
)
|
||||
assert len(original[0][1]["minimax_keyframes"]) == 2
|
||||
assert output[0][1]["minimax_keyframes"][2][MARK_STILL_IMAGE_GUIDE] is True
|
||||
|
||||
|
||||
def test_v36_schema_is_unchanged_and_v37_adds_only_typed_guide():
|
||||
v36 = H3ContinuumSamplerV36.INPUT_TYPES()
|
||||
v37 = H3ContinuumSamplerV37.INPUT_TYPES()
|
||||
assert "guide" not in v36.get("required", {})
|
||||
assert "guide" not in v36.get("optional", {})
|
||||
assert v37["required"] == v36["required"]
|
||||
expected_optional = dict(v36["optional"])
|
||||
expected_optional["guide"] = v37["optional"]["guide"]
|
||||
assert v37["optional"] == expected_optional
|
||||
assert v37["optional"]["guide"][0] == GUIDE_TYPE
|
||||
|
||||
|
||||
def test_v37_nodes_are_registered_without_replacing_v36():
|
||||
assert NODE_CLASS_MAPPINGS["H3ContinuumSamplerV36"] is H3ContinuumSamplerV36
|
||||
assert NODE_CLASS_MAPPINGS["H3ContinuumSamplerV37"] is H3ContinuumSamplerV37
|
||||
assert (
|
||||
NODE_CLASS_MAPPINGS["H3ContinuumStillImageGuideV37"]
|
||||
is H3ContinuumStillImageGuideV37
|
||||
)
|
||||
|
||||
|
||||
def test_v2_orchestration_forwards_guide_source_to_sequence(monkeypatch):
|
||||
captured = {}
|
||||
guide_source = object()
|
||||
|
||||
def fake_run_sequence(**kwargs):
|
||||
captured.update(kwargs)
|
||||
return "ok"
|
||||
|
||||
monkeypatch.setattr(v2_nodes_module, "run_sequence", fake_run_sequence)
|
||||
result = H3ContinuumSamplerV2().run(
|
||||
model=object(),
|
||||
clip=object(),
|
||||
video_vae=object(),
|
||||
audio_vae=None,
|
||||
sampler=object(),
|
||||
sigmas=torch.tensor([1.0, 0.0]),
|
||||
prompt_mode="Fixed",
|
||||
prompt_script="Prompt",
|
||||
chunks=1,
|
||||
chunk_seconds=5.0,
|
||||
width=384,
|
||||
height=384,
|
||||
continuity="Balanced — 22 frames",
|
||||
base_seed=1,
|
||||
audio_continuity=True,
|
||||
exact_total_duration=False,
|
||||
diagnostics="Off",
|
||||
reroll_from_chunk=0,
|
||||
reroll_nonce=0,
|
||||
strict_compatibility=False,
|
||||
debug=False,
|
||||
guide_source=guide_source,
|
||||
)
|
||||
assert result == "ok"
|
||||
assert captured["guide_source"] is guide_source
|
||||
|
||||
|
||||
def test_run_storage_revision_tracks_every_guide_identity_field(monkeypatch):
|
||||
monkeypatch.setattr(
|
||||
run_storage_module, "_model_signature", lambda model, value: ({}, True)
|
||||
)
|
||||
monkeypatch.setattr(run_storage_module, "_clip_signature", lambda clip: ({}, True))
|
||||
monkeypatch.setattr(
|
||||
run_storage_module,
|
||||
"_video_vae_signature",
|
||||
lambda vae, required: ({}, True),
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
run_storage_module, "_sampler_signature", lambda sampler: ({}, True)
|
||||
)
|
||||
|
||||
base_guide = {
|
||||
"schema_version": GUIDE_SCHEMA_VERSION,
|
||||
"mode": GUIDE_MODE_STILL_IMAGE,
|
||||
"absolute_frame": 60,
|
||||
"image_sha256": "a" * 64,
|
||||
"width": 384,
|
||||
"height": 384,
|
||||
}
|
||||
|
||||
def build(guide_contract):
|
||||
contract, safe, reasons = build_sampling_contract(
|
||||
model=object(),
|
||||
model_fingerprint_value="m" * 64,
|
||||
clip=object(),
|
||||
video_vae=object(),
|
||||
sampler=object(),
|
||||
sigmas=torch.tensor([1.0, 0.0]),
|
||||
prompt_plan={"chunks": 1, "hashes": ["p" * 64], "mode": "fixed"},
|
||||
width=384,
|
||||
height=384,
|
||||
chunk_seconds=5.0,
|
||||
continuity="Balanced — 22 frames",
|
||||
audio_continuity=True,
|
||||
base_seed=1,
|
||||
reroll_from_chunk=0,
|
||||
reroll_nonce=0,
|
||||
first_frame_hash="none",
|
||||
last_frame_hash="none",
|
||||
strict_compatibility=False,
|
||||
conditioning_mode="t2va",
|
||||
guide_contract=guide_contract,
|
||||
)
|
||||
assert safe is True
|
||||
assert reasons == []
|
||||
return contract
|
||||
|
||||
baseline = build(base_guide)
|
||||
assert baseline["global"]["guide"] == base_guide
|
||||
baseline_revision = revision_identity(baseline)
|
||||
for field, changed_value in (
|
||||
("absolute_frame", 61),
|
||||
("image_sha256", "b" * 64),
|
||||
("mode", "video"),
|
||||
("schema_version", GUIDE_SCHEMA_VERSION + 1),
|
||||
):
|
||||
changed = dict(base_guide, **{field: changed_value})
|
||||
assert revision_identity(build(changed)) != baseline_revision
|
||||
@@ -0,0 +1,151 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
|
||||
from ComfyUI_H3_Continuum_Join.guide_timeline import (
|
||||
GuideTargetError,
|
||||
resolve_guide_target,
|
||||
)
|
||||
|
||||
|
||||
def _standard_three_chunk_plan() -> dict[str, Any]:
|
||||
return {
|
||||
"target_frames": 360,
|
||||
"chunks": [
|
||||
{
|
||||
"chunk_index": 1,
|
||||
"frame_start": 0,
|
||||
"frame_stop": 124,
|
||||
"total_frames": 124,
|
||||
"trim_frames": 0,
|
||||
"context_frames": 0,
|
||||
"net_frames": 124,
|
||||
},
|
||||
{
|
||||
"chunk_index": 2,
|
||||
"frame_start": 124,
|
||||
"frame_stop": 243,
|
||||
"total_frames": 141,
|
||||
"trim_frames": 22,
|
||||
"context_frames": 22,
|
||||
"net_frames": 119,
|
||||
},
|
||||
{
|
||||
"chunk_index": 3,
|
||||
"frame_start": 243,
|
||||
"frame_stop": 362,
|
||||
"total_frames": 141,
|
||||
"trim_frames": 22,
|
||||
"context_frames": 22,
|
||||
"net_frames": 119,
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("absolute_frame", "group_index", "local_frame", "context", "resolved"),
|
||||
[
|
||||
(0, 0, 0, 0, 0),
|
||||
(60, 0, 60, 0, 60),
|
||||
(123, 0, 123, 0, 123),
|
||||
(124, 1, 0, 22, 22),
|
||||
(183, 1, 59, 22, 81),
|
||||
(242, 1, 118, 22, 140),
|
||||
(243, 2, 0, 22, 22),
|
||||
(302, 2, 59, 22, 81),
|
||||
(359, 2, 116, 22, 138),
|
||||
],
|
||||
)
|
||||
def test_standard_three_chunk_absolute_mapping(
|
||||
absolute_frame,
|
||||
group_index,
|
||||
local_frame,
|
||||
context,
|
||||
resolved,
|
||||
):
|
||||
result = resolve_guide_target(absolute_frame, _standard_three_chunk_plan())
|
||||
assert result["physical_group_index"] == group_index
|
||||
assert result["local_visible_frame"] == local_frame
|
||||
assert result["context_prefix_frames"] == context
|
||||
assert result["resolved_frame_index"] == resolved
|
||||
assert result["resolved_frame_index"] >= result["context_prefix_frames"]
|
||||
|
||||
|
||||
def test_single_group_uses_visible_target_not_native_tail():
|
||||
plan = {
|
||||
"target_frames": 120,
|
||||
"chunks": [
|
||||
{
|
||||
"chunk_index": 1,
|
||||
"frame_start": 0,
|
||||
"frame_stop": 124,
|
||||
"total_frames": 124,
|
||||
"trim_frames": 0,
|
||||
"net_frames": 124,
|
||||
}
|
||||
],
|
||||
}
|
||||
result = resolve_guide_target(119, plan)
|
||||
assert result["resolved_frame_index"] == 119
|
||||
with pytest.raises(GuideTargetError, match="outside visible range"):
|
||||
resolve_guide_target(120, plan)
|
||||
|
||||
|
||||
def test_negative_and_total_duration_overflow_are_rejected():
|
||||
plan = _standard_three_chunk_plan()
|
||||
with pytest.raises(GuideTargetError, match="absolute_frame"):
|
||||
resolve_guide_target(-1, plan)
|
||||
with pytest.raises(GuideTargetError, match="outside visible range"):
|
||||
resolve_guide_target(360, plan)
|
||||
|
||||
|
||||
def test_physical_boundaries_are_owned_by_the_following_group():
|
||||
plan = _standard_three_chunk_plan()
|
||||
assert resolve_guide_target(123, plan)["physical_group_index"] == 0
|
||||
assert resolve_guide_target(124, plan)["physical_group_index"] == 1
|
||||
assert resolve_guide_target(242, plan)["physical_group_index"] == 1
|
||||
assert resolve_guide_target(243, plan)["physical_group_index"] == 2
|
||||
|
||||
|
||||
def test_terminal_merge_uses_physical_group_mapping():
|
||||
plan = {
|
||||
"target_frames": 360,
|
||||
"decode_groups": [
|
||||
{
|
||||
"logical_chunk_indices": [1],
|
||||
"frame_start": 0,
|
||||
"frame_stop": 124,
|
||||
"total_frames": 124,
|
||||
"trim_frames": 0,
|
||||
"net_frames": 124,
|
||||
"terminal_merged": False,
|
||||
},
|
||||
{
|
||||
"logical_chunk_indices": [2, 3],
|
||||
"frame_start": 124,
|
||||
"frame_stop": 362,
|
||||
"total_frames": 260,
|
||||
"trim_frames": 22,
|
||||
"net_frames": 238,
|
||||
"terminal_merged": True,
|
||||
},
|
||||
],
|
||||
}
|
||||
start = resolve_guide_target(124, plan)
|
||||
logical_boundary = resolve_guide_target(243, plan)
|
||||
final = resolve_guide_target(359, plan)
|
||||
assert start["physical_group_index"] == 1
|
||||
assert start["logical_chunks"] == [2, 3]
|
||||
assert start["resolved_frame_index"] == 22
|
||||
assert logical_boundary["physical_group_index"] == 1
|
||||
assert logical_boundary["resolved_frame_index"] == 141
|
||||
assert final["resolved_frame_index"] == 257
|
||||
assert final["resolved_frame_index"] < final["physical_frames"]
|
||||
|
||||
|
||||
def test_contradictory_physical_group_is_rejected():
|
||||
plan = _standard_three_chunk_plan()
|
||||
plan["chunks"][1]["frame_start"] = 120
|
||||
with pytest.raises(GuideTargetError, match="not contiguous"):
|
||||
resolve_guide_target(124, plan)
|
||||
@@ -0,0 +1,119 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
import torch
|
||||
|
||||
from ComfyUI_H3_Continuum_Join.v3.refine_schedule import (
|
||||
AUDIO_POLICY_LOCKED_PASSTHROUGH,
|
||||
MODE_EXTERNAL,
|
||||
MODE_FULL,
|
||||
MODE_PARTIAL,
|
||||
MODE_TAIL,
|
||||
NOISE_MODE_VIDEO_RANDOM_AUDIO_ZERO,
|
||||
RefineScheduleError,
|
||||
make_external_schedule,
|
||||
make_full_schedule,
|
||||
make_partial_schedule,
|
||||
make_tail_schedule,
|
||||
resolve_refine_schedule,
|
||||
sigma_hash,
|
||||
)
|
||||
|
||||
|
||||
BASE = torch.tensor(
|
||||
[
|
||||
0.86998779,
|
||||
0.85072654,
|
||||
0.82778585,
|
||||
0.80000001,
|
||||
0.76671618,
|
||||
0.72347587,
|
||||
0.66692579,
|
||||
0.59232169,
|
||||
0.48214287,
|
||||
0.30945560,
|
||||
0.0,
|
||||
],
|
||||
dtype=torch.float32,
|
||||
)
|
||||
|
||||
|
||||
def test_external_preserves_the_exact_existing_sigmas_object():
|
||||
schedule = make_external_schedule(BASE)
|
||||
resolved = resolve_refine_schedule(BASE, schedule)
|
||||
assert schedule.sigmas is BASE
|
||||
assert resolved is schedule
|
||||
assert schedule.contract["mode"] == MODE_EXTERNAL
|
||||
assert schedule.contract["sigma_hash"] == sigma_hash(BASE)
|
||||
assert schedule.contract["evaluation_count"] == 10
|
||||
assert schedule.contract["noise_mode"] == NOISE_MODE_VIDEO_RANDOM_AUDIO_ZERO
|
||||
assert schedule.contract["audio_policy"] == AUDIO_POLICY_LOCKED_PASSTHROUGH
|
||||
|
||||
|
||||
def test_missing_schedule_is_external_compatibility():
|
||||
resolved = resolve_refine_schedule(BASE)
|
||||
assert resolved.sigmas is BASE
|
||||
assert resolved.contract["mode"] == MODE_EXTERNAL
|
||||
|
||||
|
||||
def test_full_preserves_values_but_has_distinct_semantic_identity():
|
||||
external = make_external_schedule(BASE)
|
||||
full = make_full_schedule(BASE)
|
||||
assert full.sigmas is BASE
|
||||
assert full.contract["mode"] == MODE_FULL
|
||||
assert full.contract["sigma_hash"] == external.contract["sigma_hash"]
|
||||
assert full.contract["schedule_hash"] != external.contract["schedule_hash"]
|
||||
|
||||
|
||||
def test_tail_10_and_tail_6_are_exact_suffixes_of_the_baseline():
|
||||
tail10 = make_tail_schedule(BASE, evaluation_count=10)
|
||||
tail6 = make_tail_schedule(BASE, evaluation_count=6)
|
||||
assert tail10.sigmas is BASE
|
||||
assert tail10.contract["mode"] == MODE_TAIL
|
||||
assert tail10.contract["start_index"] == 0
|
||||
assert torch.equal(tail6.sigmas, BASE[4:])
|
||||
assert tail6.contract["start_index"] == 4
|
||||
assert tail6.contract["end_index"] == 10
|
||||
assert tail6.contract["evaluation_count"] == 6
|
||||
assert tail6.contract["start_sigma"] == pytest.approx(float(BASE[4]))
|
||||
assert tail6.contract["end_sigma"] == 0.0
|
||||
|
||||
|
||||
def test_partial_uses_the_requested_inclusive_sigma_range():
|
||||
partial = make_partial_schedule(BASE, start_index=2, end_index=7)
|
||||
assert partial.contract["mode"] == MODE_PARTIAL
|
||||
assert partial.contract["evaluation_count"] == 5
|
||||
assert torch.equal(partial.sigmas, BASE[2:8])
|
||||
|
||||
|
||||
def test_schedule_rejects_a_different_source_even_when_shape_matches():
|
||||
schedule = make_tail_schedule(BASE, evaluation_count=6)
|
||||
changed = BASE.clone()
|
||||
changed[0] += 0.01
|
||||
with pytest.raises(RefineScheduleError, match="different source"):
|
||||
resolve_refine_schedule(changed, schedule)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"value, message",
|
||||
[
|
||||
(torch.tensor([1.0]), "at least two"),
|
||||
(torch.tensor([0.0, 1.0]), "non-increasing"),
|
||||
(torch.tensor([1.0, float("nan")]), "NaN or Inf"),
|
||||
],
|
||||
)
|
||||
def test_invalid_sigmas_are_rejected(value, message):
|
||||
with pytest.raises(RefineScheduleError, match=message):
|
||||
make_external_schedule(value)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("count", [0, 11, True])
|
||||
def test_invalid_tail_counts_are_rejected(count):
|
||||
with pytest.raises(RefineScheduleError, match="evaluation_count"):
|
||||
make_tail_schedule(BASE, evaluation_count=count)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("start, end", [(-1, 2), (2, 2), (2, 11)])
|
||||
def test_invalid_partial_ranges_are_rejected(start, end):
|
||||
with pytest.raises(RefineScheduleError, match="outside"):
|
||||
make_partial_schedule(BASE, start_index=start, end_index=end)
|
||||
Reference in New Issue
Block a user