release: publish H3 Continuum V3.8X (3.8.1)
This commit is contained in:
@@ -52,7 +52,7 @@ function environment() {
|
||||
.replace(/import \{ app \} from "\.\.\/\.\.\/scripts\/app.js";/,'')
|
||||
.replace(/import \{ api \} from "\.\.\/\.\.\/scripts\/api.js";/,'')
|
||||
.replace(/import \{ normalizeReferenceAudioLabels \} from "\.\/reference_audio_ui.js";/,'function normalizeReferenceAudioLabels() {}');
|
||||
vm.runInNewContext(src+`\nglobalThis.testFns={configureNode,loadTakeHistory,prepareReviewQueueIntent,takeCatalog,selectTakeOffset,selectTakeAction,reviewStatus,reviewSettingsChanged,synchronizeReviewQueue};`,sandbox);
|
||||
vm.runInNewContext(src+`\nglobalThis.testFns={configureNode,loadTakeHistory,takeCatalog,selectTakeOffset,selectTakeAction,reviewStatus,reviewSettingsChanged,synchronizeReviewQueue};`,sandbox);
|
||||
app.extension.setup();
|
||||
const f=sandbox.testFns;
|
||||
function makeNode(id=312,run='fixture'){
|
||||
@@ -292,12 +292,14 @@ await test('removing one sampler does not discard another accepted sampler',asyn
|
||||
e.setSaved(project(1,3,'two-r1','two'));await e.emit('execution_success',{prompt_id:q.prompt_id});
|
||||
assert(e.visible(b,'Use it and continue'));
|
||||
});
|
||||
await test('same setup request is not mutated by legacy preparation then API preparation',async e=>{
|
||||
await test('queue adapter owns setup preparation without mutating the caller payload',async e=>{
|
||||
const n=e.makeNode();await e.load(n,project(3,3));e.w(n,'chunks').value=5;e.w(n,'Run').callback('Review Each Chunk');
|
||||
const inputs=await e.inputs(n);e.f.prepareReviewQueueIntent(n,inputs);const once=JSON.stringify(inputs);
|
||||
e.f.prepareReviewQueueIntent(n,inputs);assert.equal(JSON.stringify(inputs),once);
|
||||
const inputs=await e.inputs(n);const before=JSON.stringify(inputs);
|
||||
await e.api.queuePrompt(0,{output:{'312':{class_type:n.comfyClass,inputs}},workflow:{}});
|
||||
assert.equal(JSON.stringify(e.submissions.at(-1).data.output['312'].inputs),once);
|
||||
assert.equal(JSON.stringify(inputs),before);
|
||||
const sent=e.submissions.at(-1).data.output['312'].inputs;
|
||||
assert.equal(sent.reroll_from_chunk,'Auto');assert.equal(sent.review_action,'Continue / Next');
|
||||
assert.equal(sent.take_action,'Automatic');
|
||||
});
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,165 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import importlib.util
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import sys
|
||||
import time
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
PACKAGE_NAME = "ComfyUI_H3_Continuum_Join"
|
||||
if PACKAGE_NAME not in sys.modules:
|
||||
spec = importlib.util.spec_from_file_location(
|
||||
PACKAGE_NAME,
|
||||
ROOT / "__init__.py",
|
||||
submodule_search_locations=[str(ROOT)],
|
||||
)
|
||||
package = importlib.util.module_from_spec(spec)
|
||||
package.__path__ = [str(ROOT)]
|
||||
sys.modules[PACKAGE_NAME] = package
|
||||
|
||||
import ComfyUI_H3_Continuum_Join.run_storage as storage_runtime
|
||||
|
||||
|
||||
def _load_storage_cases():
|
||||
path = ROOT / "tests" / "test_v38_review_run_storage.py"
|
||||
spec = importlib.util.spec_from_file_location("r5_worker_storage_cases", path)
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
sys.modules[spec.name] = module
|
||||
spec.loader.exec_module(module)
|
||||
return module
|
||||
|
||||
|
||||
def main() -> None:
|
||||
scenario_root = Path(sys.argv[1]).resolve()
|
||||
stage = sys.argv[2]
|
||||
scenario_root.mkdir(parents=True, exist_ok=True)
|
||||
signal = scenario_root / "reached.json"
|
||||
|
||||
def reached() -> None:
|
||||
signal.write_text(
|
||||
json.dumps({"stage": stage, "pid": os.getpid()}),
|
||||
encoding="utf-8",
|
||||
)
|
||||
while True:
|
||||
time.sleep(1)
|
||||
|
||||
cases = _load_storage_cases()
|
||||
contract = cases._contract(chunks=2, terminal=True)
|
||||
controller = cases._controller(scenario_root, contract)
|
||||
controller.revision_root.mkdir(parents=True, exist_ok=True)
|
||||
controller._write_manifest()
|
||||
entries = (cases._entry(0, contract), cases._entry(1, contract))
|
||||
|
||||
if stage == "raw_before":
|
||||
reached()
|
||||
|
||||
if stage == "raw_mid":
|
||||
def partial_save(tensors, filename, *, metadata):
|
||||
with open(filename, "wb") as handle:
|
||||
handle.write(b"partial-r5-raw")
|
||||
handle.flush()
|
||||
os.fsync(handle.fileno())
|
||||
reached()
|
||||
|
||||
storage_runtime.save_file = partial_save
|
||||
|
||||
if stage == "first_raw_done":
|
||||
original_hash = storage_runtime._file_sha256
|
||||
hash_calls = 0
|
||||
|
||||
def observed_hash(path):
|
||||
nonlocal hash_calls
|
||||
value = original_hash(path)
|
||||
hash_calls += 1
|
||||
if hash_calls == 2:
|
||||
reached()
|
||||
return value
|
||||
|
||||
storage_runtime._file_sha256 = observed_hash
|
||||
|
||||
if stage == "before_manifest":
|
||||
original_write_manifest = controller._write_manifest
|
||||
|
||||
def before_manifest():
|
||||
reached()
|
||||
return original_write_manifest()
|
||||
|
||||
controller._write_manifest = before_manifest
|
||||
|
||||
if stage == "manifest_temp_mid":
|
||||
def partial_json_dump(payload, handle, **kwargs):
|
||||
handle.write('{"partial":')
|
||||
handle.flush()
|
||||
os.fsync(handle.fileno())
|
||||
reached()
|
||||
|
||||
storage_runtime.json.dump = partial_json_dump
|
||||
|
||||
if stage in {"before_replace", "after_replace"}:
|
||||
original_replace = storage_runtime._replace_json_atomically
|
||||
|
||||
def observed_replace(temporary, destination):
|
||||
if Path(destination).name != "manifest.json":
|
||||
return original_replace(temporary, destination)
|
||||
if stage == "before_replace":
|
||||
reached()
|
||||
result = original_replace(temporary, destination)
|
||||
reached()
|
||||
return result
|
||||
|
||||
storage_runtime._replace_json_atomically = observed_replace
|
||||
|
||||
if stage == "after_directory_durability":
|
||||
original_fsync_dir = storage_runtime._fsync_dir
|
||||
|
||||
def observed_fsync_dir(path):
|
||||
result = original_fsync_dir(path)
|
||||
if Path(path).resolve() == controller.revision_root.resolve():
|
||||
reached()
|
||||
return result
|
||||
|
||||
storage_runtime._fsync_dir = observed_fsync_dir
|
||||
|
||||
controller.commit_group(entries, positions=(0, 1))
|
||||
|
||||
if stage in {"finalize_manifest_1", "finalize_manifest_2"}:
|
||||
original_finalize_write = controller._write_manifest
|
||||
finalize_writes = 0
|
||||
|
||||
def observed_finalize_write():
|
||||
nonlocal finalize_writes
|
||||
result = original_finalize_write()
|
||||
finalize_writes += 1
|
||||
expected = 1 if stage == "finalize_manifest_1" else 2
|
||||
if finalize_writes == expected:
|
||||
reached()
|
||||
return result
|
||||
|
||||
controller._write_manifest = observed_finalize_write
|
||||
|
||||
if stage in {"project_before_replace", "project_after_replace"}:
|
||||
original_project_replace = storage_runtime._replace_json_atomically
|
||||
|
||||
def observed_project_replace(temporary, destination):
|
||||
if Path(destination).name != "project.json":
|
||||
return original_project_replace(temporary, destination)
|
||||
if stage == "project_before_replace":
|
||||
reached()
|
||||
result = original_project_replace(temporary, destination)
|
||||
reached()
|
||||
return result
|
||||
|
||||
storage_runtime._replace_json_atomically = observed_project_replace
|
||||
|
||||
controller.finalize(
|
||||
session={"session_id": "r5-crash-worker", "chunks": list(entries)},
|
||||
report="r5 process crash fixture",
|
||||
)
|
||||
raise RuntimeError(f"stage did not block: {stage}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,226 @@
|
||||
from collections.abc import Mapping
|
||||
import copy
|
||||
import json
|
||||
|
||||
import pytest
|
||||
import torch
|
||||
|
||||
from ComfyUI_H3_Continuum_Join.graph_contract import build_upstream_graph_contract
|
||||
from ComfyUI_H3_Continuum_Join.v2.prompts import make_prompt_plan
|
||||
from ComfyUI_H3_Continuum_Join.v2.session import make_session
|
||||
from ComfyUI_H3_Continuum_Join.constants import PROMPT_MODE_LIST
|
||||
from . import test_v38_review_execution_cap as cap
|
||||
from .test_v36_masked_video_prefix import _install_nested_tensor
|
||||
from .test_v35_context_sampler import _capture_sequence
|
||||
from .test_v31_run_storage import _controller
|
||||
|
||||
|
||||
def test_v3_reference_video_imports_the_shared_temporal_helper():
|
||||
from ComfyUI_H3_Continuum_Join.temporal import align_frame_count_up as shared
|
||||
from ComfyUI_H3_Continuum_Join.v3.reference_video import align_frame_count_up
|
||||
|
||||
assert align_frame_count_up is shared
|
||||
|
||||
|
||||
def test_reference_bundle_fingerprint_ignores_unused_legacy_vae():
|
||||
graph = {
|
||||
"1": {"class_type": "H3ContinuumSamplerV38", "inputs": {
|
||||
"model": ["2", 0], "clip": ["3", 0],
|
||||
"audio_references": ["4", 0], "reference_audio_vae": ["5", 0]}},
|
||||
"2": {"class_type": "UNETLoader", "inputs": {"unet_name": "model"}},
|
||||
"3": {"class_type": "CLIPLoader", "inputs": {"clip_name": "clip"}},
|
||||
"4": {"class_type": "H3ContinuumReferenceAudios", "inputs": {
|
||||
"reference_audio_vae": ["6", 0], "reference_audio_1": ["7", 0]}},
|
||||
"5": {"class_type": "VAELoader", "inputs": {"vae_name": "unused"}},
|
||||
"6": {"class_type": "VAELoader", "inputs": {"vae_name": "active"}},
|
||||
"7": {"class_type": "LoadAudio", "inputs": {"audio": "voice.wav"}},
|
||||
}
|
||||
|
||||
def contract(value):
|
||||
result, safe, _ = build_upstream_graph_contract(
|
||||
value, "1", require_video_vae=False, require_reference_audio_vae=True)
|
||||
assert safe
|
||||
return result
|
||||
|
||||
original = contract(graph)
|
||||
assert original["routes"]["reference_audio_vae"]["node"]["node_id"] == "4"
|
||||
active = copy.deepcopy(graph)
|
||||
active["6"]["inputs"]["vae_name"] = "new-active"
|
||||
assert contract(active)["sha256"] != original["sha256"]
|
||||
unused = copy.deepcopy(graph)
|
||||
unused["5"]["inputs"]["vae_name"] = "new-unused"
|
||||
assert contract(unused) == original
|
||||
legacy = copy.deepcopy(graph)
|
||||
del legacy["1"]["inputs"]["audio_references"]
|
||||
assert contract(legacy)["routes"]["reference_audio_vae"]["node"]["node_id"] == "5"
|
||||
|
||||
# A connected but empty bundle can return None; execution then uses legacy
|
||||
# audio. Run Storage supplies this resolved route, not just graph priority.
|
||||
resolved, safe, _ = build_upstream_graph_contract(
|
||||
graph, "1", require_video_vae=False, require_reference_audio_vae=True,
|
||||
reference_audio_route="reference_audio_vae")
|
||||
assert safe
|
||||
assert resolved["routes"]["reference_audio_vae"]["node"]["node_id"] == "5"
|
||||
|
||||
|
||||
def assert_nested_equal(actual, expected):
|
||||
if torch.is_tensor(expected):
|
||||
torch.testing.assert_close(actual, expected, rtol=0, atol=0)
|
||||
elif isinstance(expected, Mapping):
|
||||
assert actual.keys() == expected.keys()
|
||||
for key in expected:
|
||||
assert_nested_equal(actual[key], expected[key])
|
||||
elif isinstance(expected, (tuple, list)):
|
||||
assert len(actual) == len(expected)
|
||||
for a, b in zip(actual, expected, strict=True):
|
||||
assert_nested_equal(a, b)
|
||||
else:
|
||||
assert actual == expected
|
||||
|
||||
|
||||
@pytest.mark.parametrize("transport", ["reference_context_v1", "masked_av_prefix_22_v1", "masked_video_prefix_v1"])
|
||||
@pytest.mark.parametrize("anchors", ["none", "first", "first_last"])
|
||||
@pytest.mark.parametrize("chunks", [1, 3, 6])
|
||||
def test_review_and_complete_reuse_preserve_full_refine_context(monkeypatch, transport, anchors, chunks):
|
||||
_install_nested_tensor(monkeypatch)
|
||||
first = torch.zeros(1, 64, 96, 3) if anchors != "none" else None
|
||||
last = torch.ones(1, 64, 96, 3) if anchors == "first_last" else None
|
||||
runtime = cap._install_fake_runtime(monkeypatch, first_frame=first, last_frame=last)
|
||||
real = cap.sequence.run_sequence
|
||||
|
||||
def run(**kwargs):
|
||||
kwargs["continuation_transport"] = transport
|
||||
return real(**kwargs)
|
||||
|
||||
monkeypatch.setattr(cap.sequence, "run_sequence", run)
|
||||
options = dict(chunks=chunks, first_frame=first, last_frame=last, capture_refine_context=True)
|
||||
full = cap._run_sequence(runtime, **options)
|
||||
assert full[4]["complete"]
|
||||
expected_sample_count = len(runtime.samples)
|
||||
runtime.samples.clear()
|
||||
session = None
|
||||
for _ in range(chunks):
|
||||
before = len(runtime.samples)
|
||||
reviewed = cap._run_sequence(runtime, **options, limit=1, session=session)
|
||||
session = reviewed[2]
|
||||
assert len(runtime.samples) - before == 1
|
||||
if len(reviewed[0]) == chunks:
|
||||
break
|
||||
assert not reviewed[4]["complete"]
|
||||
assert len(runtime.samples) == expected_sample_count
|
||||
cap._assert_entry_parity(reviewed[0], full[0])
|
||||
assert reviewed[4]["complete"]
|
||||
assert_nested_equal(reviewed[4], full[4])
|
||||
runtime.samples.clear()
|
||||
reused = cap._run_sequence(runtime, **options, session=session)
|
||||
assert runtime.samples == []
|
||||
cap._assert_entry_parity(reused[0], full[0])
|
||||
assert_nested_equal(reused[4], full[4])
|
||||
|
||||
|
||||
def test_review_does_not_encode_future_prompts(monkeypatch):
|
||||
runtime = cap._install_fake_runtime(monkeypatch)
|
||||
real = cap.sequence.run_sequence
|
||||
encoded = []
|
||||
encoder = runtime.clip.encode_from_tokens_scheduled
|
||||
monkeypatch.setattr(runtime.clip, "encode_from_tokens_scheduled",
|
||||
lambda prompt: (encoded.append(prompt), encoder(prompt))[1])
|
||||
|
||||
def run(**kwargs):
|
||||
kwargs["prompt_plan"] = make_prompt_plan(
|
||||
mode=PROMPT_MODE_LIST, script=json.dumps([f"action {i}" for i in range(6)]),
|
||||
chunks=6, chunk_seconds=5.0)
|
||||
return real(**kwargs)
|
||||
|
||||
monkeypatch.setattr(cap.sequence, "run_sequence", run)
|
||||
cap._run_sequence(runtime, chunks=6, limit=1, capture_refine_context=True)
|
||||
assert len(runtime.samples) == 1
|
||||
assert encoded == ["action 0"]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("transport", ["reference_context_v1", "masked_av_prefix_22_v1", "masked_video_prefix_v1"])
|
||||
@pytest.mark.parametrize("terminal", [False, True])
|
||||
@pytest.mark.parametrize("image,audio", [(True, False), (False, True), (True, True)])
|
||||
def test_review_reconstructs_reference_conditions(monkeypatch, transport, terminal, image, audio):
|
||||
real = cap.sequence.run_sequence
|
||||
state = {"limit": None, "samples": 0}
|
||||
|
||||
def run(**kwargs):
|
||||
sample = cap.sequence.sample_chunk
|
||||
|
||||
def counted(**sample_kwargs):
|
||||
state["samples"] += 1
|
||||
return sample(**sample_kwargs)
|
||||
|
||||
monkeypatch.setattr(cap.sequence, "sample_chunk", counted)
|
||||
kwargs["max_new_physical_groups"] = state["limit"]
|
||||
return real(**kwargs)
|
||||
|
||||
monkeypatch.setattr(cap.sequence, "run_sequence", run)
|
||||
options = dict(terminal=terminal, reference_image=image, reference_audio=audio,
|
||||
continuation_transport=transport)
|
||||
full = _capture_sequence(monkeypatch, **options)
|
||||
assert state["samples"] == 2
|
||||
state.update(limit=1, samples=0)
|
||||
first = _capture_sequence(monkeypatch, **options)
|
||||
assert state["samples"] == 1
|
||||
assert not first[4]["complete"]
|
||||
final = _capture_sequence(monkeypatch, **options, session=first[2])
|
||||
assert state["samples"] == 2
|
||||
assert_nested_equal(final[4], full[4])
|
||||
state.update(limit=None, samples=0)
|
||||
reused = _capture_sequence(monkeypatch, **options, session=final[2])
|
||||
assert state["samples"] == 0
|
||||
assert_nested_equal(reused[4], full[4])
|
||||
|
||||
|
||||
def test_full_reuse_without_refine_capture_does_not_encode_or_sample(monkeypatch):
|
||||
runtime = cap._install_fake_runtime(monkeypatch)
|
||||
full = cap._run_sequence(runtime, chunks=3)
|
||||
runtime.samples.clear()
|
||||
|
||||
def unexpected(*args, **kwargs):
|
||||
pytest.fail("Full reuse without refine capture must not encode or sample")
|
||||
|
||||
monkeypatch.setattr(cap.sequence, "encode_identity_latents", unexpected)
|
||||
monkeypatch.setattr(runtime.clip, "encode_from_tokens_scheduled", unexpected)
|
||||
monkeypatch.setattr(cap.sequence, "sample_chunk", unexpected)
|
||||
reused = cap._run_sequence(runtime, chunks=3, session=full[2])
|
||||
assert len(reused) == 4
|
||||
cap._assert_entry_parity(reused[0], full[0])
|
||||
|
||||
|
||||
@pytest.mark.parametrize("terminal", [False, True])
|
||||
def test_refine_context_rebuild_after_safetensors_storage_roundtrip(monkeypatch, tmp_path, terminal):
|
||||
_install_nested_tensor(monkeypatch)
|
||||
first = torch.zeros(1, 64, 96, 3) if terminal else None
|
||||
last = torch.ones(1, 64, 96, 3) if terminal else None
|
||||
runtime = cap._install_fake_runtime(monkeypatch, first_frame=first, last_frame=last)
|
||||
options = dict(chunks=3, first_frame=first, last_frame=last, capture_refine_context=True)
|
||||
full = cap._run_sequence(runtime, **options)
|
||||
writer, hashes = _controller(tmp_path)
|
||||
writer.prompts = ["continuous shot"] * 3
|
||||
for index, entry in enumerate(full[0]):
|
||||
writer.commit_chunk(entry, position=index)
|
||||
reader, _ = _controller(tmp_path)
|
||||
reader.prompts = writer.prompts[:]
|
||||
reader.manifest = json.loads(writer._manifest_path().read_text(encoding="utf-8"))
|
||||
loaded, records = reader._valid_prefix(reader.manifest, hashes)
|
||||
assert len(records) == len(loaded) == 3
|
||||
assert loaded[0]["video"].data_ptr() != full[0][0]["video"].data_ptr()
|
||||
prior = full[2]
|
||||
# The normal storage adapter invokes make_session to convert disk positions
|
||||
# (zero-based) to Session indices (one-based); exercise that owner as well.
|
||||
session = make_session(
|
||||
chunks=loaded, width=prior["width"], height=prior["height"],
|
||||
chunk_seconds=prior["chunk_seconds"], identity_hash=prior["identity_hash"],
|
||||
model_fingerprint_value=prior["model_fingerprint"],
|
||||
parent_session_id=prior["session_id"], reroll_from_chunk=0,
|
||||
settings=prior["settings"])
|
||||
runtime.samples.clear()
|
||||
before = {path: path.read_bytes() for path in tmp_path.rglob("*") if path.is_file()}
|
||||
restored = cap._run_sequence(runtime, **options, session=session)
|
||||
assert runtime.samples == []
|
||||
assert_nested_equal(restored[4], full[4])
|
||||
cap._assert_entry_parity(restored[0], full[0])
|
||||
assert {path: path.read_bytes() for path in tmp_path.rglob("*") if path.is_file()} == before
|
||||
@@ -6,7 +6,7 @@ import tomllib
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
EXPECTED_VERSION = "3.8.0"
|
||||
EXPECTED_VERSION = "3.8.1"
|
||||
|
||||
|
||||
def test_v35_release_metadata_is_consistent():
|
||||
@@ -25,6 +25,7 @@ def test_v35_public_documents_identify_the_current_release():
|
||||
readme_ja = (ROOT / "README_JA.md").read_text(encoding="utf-8")
|
||||
changelog = (ROOT / "CHANGELOG.md").read_text(encoding="utf-8")
|
||||
|
||||
assert readme.startswith(f"# ComfyUI-H3-Continuum {EXPECTED_VERSION}\n")
|
||||
assert readme_ja.startswith(f"# ComfyUI-H3-Continuum {EXPECTED_VERSION}\n")
|
||||
expected_heading = f"# ComfyUI-H3-Continuum {EXPECTED_VERSION} — V3.8X\n"
|
||||
assert readme.startswith(expected_heading)
|
||||
assert readme_ja.startswith(expected_heading)
|
||||
assert f"## {EXPECTED_VERSION}" in changelog
|
||||
|
||||
@@ -0,0 +1,403 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
from types import SimpleNamespace
|
||||
|
||||
import pytest
|
||||
|
||||
import ComfyUI_H3_Continuum_Join.run_storage as storage_runtime
|
||||
from ComfyUI_H3_Continuum_Join.run_storage import RunStorageController, RunStorageError
|
||||
from ComfyUI_H3_Continuum_Join.v2 import sequence
|
||||
from ComfyUI_H3_Continuum_Join.v2.session import entry_to_state
|
||||
from ComfyUI_H3_Continuum_Join.v3.review_control import (
|
||||
GENERATION_MODE_REVIEW,
|
||||
REVIEW_ACTION_CONTINUE,
|
||||
REVISION_STATUS_REVIEW_READY,
|
||||
)
|
||||
|
||||
from . import test_v38_review_execution_cap as cap
|
||||
from . import test_v38_review_run_storage as storage_cases
|
||||
|
||||
|
||||
def _run_with_sources(
|
||||
monkeypatch,
|
||||
runtime,
|
||||
*,
|
||||
chunks: int,
|
||||
session=None,
|
||||
initial_state=None,
|
||||
reroll_from_chunk: int = 0,
|
||||
continuity: str | None = None,
|
||||
limit: int | None = None,
|
||||
):
|
||||
"""Exercise the unchanged public run_sequence contract with extra sources."""
|
||||
|
||||
original = cap.sequence.run_sequence
|
||||
|
||||
def forwarded(**kwargs):
|
||||
kwargs["initial_state"] = initial_state
|
||||
kwargs["reroll_from_chunk"] = reroll_from_chunk
|
||||
if continuity is not None:
|
||||
kwargs["continuity"] = continuity
|
||||
return original(**kwargs)
|
||||
|
||||
with monkeypatch.context() as local:
|
||||
local.setattr(cap.sequence, "run_sequence", forwarded)
|
||||
return cap._run_sequence(
|
||||
runtime,
|
||||
chunks=chunks,
|
||||
session=session,
|
||||
limit=limit,
|
||||
)
|
||||
|
||||
|
||||
def _state_from_session(session: dict, *, clip_index: int = 9) -> dict:
|
||||
state = dict(entry_to_state(session["chunks"][-1]))
|
||||
state["clip_index"] = clip_index
|
||||
return state
|
||||
|
||||
|
||||
def test_r0_storage_off_plain_full_run_uses_no_review_policy_or_filesystem(
|
||||
monkeypatch, tmp_path
|
||||
):
|
||||
runtime = cap._install_fake_runtime(monkeypatch)
|
||||
|
||||
def unexpected(*args, **kwargs):
|
||||
pytest.fail("Storage OFF Full Run must not resolve Run Storage Review policy")
|
||||
|
||||
monkeypatch.setattr(storage_runtime, "resolve_review_execution", unexpected)
|
||||
entries, last_state, session, _ = cap._run_sequence(runtime, chunks=3)
|
||||
|
||||
assert len(entries) == len(session["chunks"]) == len(runtime.samples) == 3
|
||||
assert last_state["clip_index"] == 3
|
||||
assert list(tmp_path.rglob("*")) == []
|
||||
|
||||
|
||||
def test_r0_storage_off_compatible_session_restores_prefix(monkeypatch):
|
||||
runtime = cap._install_fake_runtime(monkeypatch)
|
||||
_, _, saved, _ = cap._run_sequence(runtime, chunks=1)
|
||||
runtime.samples.clear()
|
||||
|
||||
entries, last_state, session, _ = cap._run_sequence(
|
||||
runtime,
|
||||
chunks=2,
|
||||
session=saved,
|
||||
)
|
||||
|
||||
assert len(entries) == len(session["chunks"]) == 2
|
||||
assert entries[0]["reused"] is True
|
||||
assert len(runtime.samples) == 1
|
||||
assert last_state["clip_index"] == 2
|
||||
|
||||
|
||||
def test_r0_storage_off_session_regenerate_from_preserves_only_prior_prefix(monkeypatch):
|
||||
runtime = cap._install_fake_runtime(monkeypatch)
|
||||
_, _, saved, _ = cap._run_sequence(runtime, chunks=3)
|
||||
runtime.samples.clear()
|
||||
|
||||
entries, last_state, session, _ = _run_with_sources(
|
||||
monkeypatch,
|
||||
runtime,
|
||||
chunks=3,
|
||||
session=saved,
|
||||
reroll_from_chunk=2,
|
||||
)
|
||||
|
||||
assert len(entries) == len(session["chunks"]) == 3
|
||||
assert [entry["reused"] for entry in entries] == [True, False, False]
|
||||
assert len(runtime.samples) == 2
|
||||
assert last_state["clip_index"] == 3
|
||||
|
||||
|
||||
def test_r0_storage_off_incompatible_session_is_advisory_and_starts_fresh(monkeypatch):
|
||||
runtime = cap._install_fake_runtime(monkeypatch)
|
||||
_, _, saved, _ = cap._run_sequence(runtime, chunks=1)
|
||||
incompatible = dict(saved)
|
||||
incompatible["width"] = 128
|
||||
runtime.samples.clear()
|
||||
|
||||
entries, last_state, session, report = cap._run_sequence(
|
||||
runtime,
|
||||
chunks=1,
|
||||
session=incompatible,
|
||||
)
|
||||
|
||||
assert len(entries) == len(session["chunks"]) == len(runtime.samples) == 1
|
||||
assert entries[0]["reused"] is False
|
||||
assert last_state["clip_index"] == 1
|
||||
assert "saved session was ignored; generated a fresh run" in report
|
||||
|
||||
|
||||
def test_r0_storage_off_invalid_session_suppresses_valid_state_without_fallback(
|
||||
monkeypatch,
|
||||
):
|
||||
runtime = cap._install_fake_runtime(monkeypatch)
|
||||
_, _, source, _ = cap._run_sequence(runtime, chunks=1)
|
||||
state = _state_from_session(source)
|
||||
runtime.samples.clear()
|
||||
|
||||
entries, last_state, session, report = _run_with_sources(
|
||||
monkeypatch,
|
||||
runtime,
|
||||
chunks=1,
|
||||
session={"magic": "not-a-session"},
|
||||
initial_state=state,
|
||||
)
|
||||
|
||||
# Current V3.8 behavior is advisory, not an exception: the invalid Session
|
||||
# is rejected, the simultaneously supplied State remains suppressed, and a
|
||||
# fresh Chunk 1 is generated. R0 records this fact without changing it.
|
||||
assert len(entries) == len(session["chunks"]) == len(runtime.samples) == 1
|
||||
assert last_state["clip_index"] == 1
|
||||
assert entries[0]["plan"]["continuation"] is False
|
||||
assert "saved session was ignored; generated a fresh run" in report
|
||||
|
||||
|
||||
def test_r0_storage_off_compatible_session_suppresses_initial_state(monkeypatch, caplog):
|
||||
runtime = cap._install_fake_runtime(monkeypatch)
|
||||
_, _, saved, _ = cap._run_sequence(runtime, chunks=1)
|
||||
state = _state_from_session(saved)
|
||||
runtime.samples.clear()
|
||||
|
||||
entries, last_state, _, _ = _run_with_sources(
|
||||
monkeypatch,
|
||||
runtime,
|
||||
chunks=2,
|
||||
session=saved,
|
||||
initial_state=state,
|
||||
)
|
||||
|
||||
assert len(entries) == 2
|
||||
assert entries[0]["reused"] is True
|
||||
assert len(runtime.samples) == 1
|
||||
assert last_state["clip_index"] == 2
|
||||
assert "using the session and ignoring initial_state" in caplog.text
|
||||
|
||||
|
||||
def test_r0_storage_off_initial_state_continues_without_session(monkeypatch):
|
||||
runtime = cap._install_fake_runtime(monkeypatch)
|
||||
_, _, source, _ = cap._run_sequence(runtime, chunks=1)
|
||||
state = _state_from_session(source)
|
||||
runtime.samples.clear()
|
||||
|
||||
entries, last_state, session, _ = _run_with_sources(
|
||||
monkeypatch,
|
||||
runtime,
|
||||
chunks=1,
|
||||
initial_state=state,
|
||||
)
|
||||
|
||||
assert len(entries) == len(session["chunks"]) == len(runtime.samples) == 1
|
||||
assert entries[0]["plan"]["continuation"] is True
|
||||
assert entries[0]["plan"]["clip_index"] == 10
|
||||
assert last_state["clip_index"] == 10
|
||||
|
||||
|
||||
def test_r0_storage_off_initial_state_rejects_invalid_regenerate_from(monkeypatch):
|
||||
runtime = cap._install_fake_runtime(monkeypatch)
|
||||
_, _, source, _ = cap._run_sequence(runtime, chunks=1)
|
||||
state = _state_from_session(source)
|
||||
|
||||
with pytest.raises(
|
||||
sequence.SequenceRuntimeError,
|
||||
match="with initial_state, reroll_from_chunk can only be 0 or 1",
|
||||
):
|
||||
_run_with_sources(
|
||||
monkeypatch,
|
||||
runtime,
|
||||
chunks=3,
|
||||
initial_state=state,
|
||||
reroll_from_chunk=2,
|
||||
)
|
||||
|
||||
|
||||
def test_r0_run_storage_on_rejects_explicit_session_before_filesystem_io(
|
||||
monkeypatch, tmp_path
|
||||
):
|
||||
runtime = cap._install_fake_runtime(monkeypatch)
|
||||
_, _, saved, _ = cap._run_sequence(runtime, chunks=1)
|
||||
monkeypatch.setattr(storage_runtime, "_output_root", lambda: tmp_path)
|
||||
controller = RunStorageController("r0-explicit-session")
|
||||
monkeypatch.setattr(storage_runtime, "get_active_run_storage", lambda: controller)
|
||||
|
||||
with pytest.raises(
|
||||
RunStorageError,
|
||||
match="Run Storage cannot be combined with an explicit Session",
|
||||
):
|
||||
cap._run_sequence(runtime, chunks=2, session=saved)
|
||||
|
||||
assert list(tmp_path.rglob("*")) == []
|
||||
|
||||
|
||||
def test_r0_run_storage_saved_prefix_precedes_initial_state(monkeypatch):
|
||||
runtime = cap._install_fake_runtime(monkeypatch)
|
||||
_, _, saved, _ = cap._run_sequence(runtime, chunks=1)
|
||||
state = _state_from_session(saved)
|
||||
runtime.samples.clear()
|
||||
storage = cap._CommitRecorder(runtime.timeline)
|
||||
storage.prepare = lambda **kwargs: saved
|
||||
monkeypatch.setattr(storage_runtime, "get_active_run_storage", lambda: storage)
|
||||
|
||||
entries, last_state, _, _ = _run_with_sources(
|
||||
monkeypatch,
|
||||
runtime,
|
||||
chunks=2,
|
||||
initial_state=state,
|
||||
)
|
||||
|
||||
assert len(entries) == 2
|
||||
assert entries[0]["reused"] is True
|
||||
assert len(runtime.samples) == 1
|
||||
assert last_state["clip_index"] == 2
|
||||
|
||||
|
||||
def test_r0_run_storage_without_prefix_uses_initial_state(monkeypatch):
|
||||
runtime = cap._install_fake_runtime(monkeypatch)
|
||||
_, _, source, _ = cap._run_sequence(runtime, chunks=1)
|
||||
state = _state_from_session(source)
|
||||
runtime.samples.clear()
|
||||
storage = cap._CommitRecorder(runtime.timeline)
|
||||
monkeypatch.setattr(storage_runtime, "get_active_run_storage", lambda: storage)
|
||||
|
||||
entries, last_state, _, _ = _run_with_sources(
|
||||
monkeypatch,
|
||||
runtime,
|
||||
chunks=1,
|
||||
initial_state=state,
|
||||
)
|
||||
|
||||
assert len(entries) == len(runtime.samples) == 1
|
||||
assert entries[0]["plan"]["continuation"] is True
|
||||
assert last_state["clip_index"] == 10
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("continuity", "expected_context"),
|
||||
(("Balanced — 22 frames", 22), ("Strong — 39 frames (Experimental)", 39)),
|
||||
)
|
||||
def test_r0_continuity_modes_keep_their_context_contract(
|
||||
monkeypatch, continuity, expected_context
|
||||
):
|
||||
runtime = cap._install_fake_runtime(monkeypatch)
|
||||
entries, _, _, _ = _run_with_sources(
|
||||
monkeypatch,
|
||||
runtime,
|
||||
chunks=2,
|
||||
continuity=continuity,
|
||||
)
|
||||
|
||||
assert entries[0]["plan"]["context_frames"] == 5
|
||||
assert entries[1]["plan"]["context_frames"] == expected_context
|
||||
assert entries[1]["plan"]["state_capacity_frames"] == 39
|
||||
|
||||
|
||||
def _failure_controller(tmp_path, contract: dict) -> RunStorageController:
|
||||
controller = storage_cases._controller(tmp_path, contract)
|
||||
controller.lock = storage_runtime._RunLock(controller.run_root / ".lock")
|
||||
controller.revision_root.mkdir(parents=True, exist_ok=True)
|
||||
controller._write_manifest()
|
||||
return controller
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("stage", "committed"),
|
||||
(
|
||||
("before sampling", 0),
|
||||
("after sampling before chunk commit", 0),
|
||||
("after manifest update", 1),
|
||||
("before output projection", 1),
|
||||
("during output projection", 1),
|
||||
("before storage finalize", 1),
|
||||
),
|
||||
)
|
||||
def test_r0_failure_baseline_marks_revision_interrupted(
|
||||
tmp_path, stage, committed
|
||||
):
|
||||
contract = storage_cases._contract(chunks=1)
|
||||
controller = _failure_controller(tmp_path, contract)
|
||||
|
||||
with pytest.raises(RuntimeError, match=stage):
|
||||
with controller:
|
||||
if committed:
|
||||
controller.commit_chunk(storage_cases._entry(0, contract), position=0)
|
||||
raise RuntimeError(stage)
|
||||
|
||||
manifest = json.loads(controller._manifest_path().read_text(encoding="utf-8"))
|
||||
assert manifest["status"] == "interrupted"
|
||||
assert len(manifest["chunks"]) == committed
|
||||
assert stage in manifest["last_error"]
|
||||
|
||||
|
||||
def test_r5_terminal_entry_cannot_expose_an_interrupted_half_group(
|
||||
tmp_path,
|
||||
):
|
||||
contract = storage_cases._contract(chunks=2, terminal=True)
|
||||
controller = _failure_controller(tmp_path, contract)
|
||||
|
||||
with pytest.raises(RunStorageError, match="physical group is incomplete"):
|
||||
with controller:
|
||||
controller.commit_chunk(storage_cases._entry(0, contract), position=0)
|
||||
|
||||
manifest = json.loads(controller._manifest_path().read_text(encoding="utf-8"))
|
||||
assert manifest["status"] == "interrupted"
|
||||
assert manifest["chunks"] == []
|
||||
project = json.loads((controller.run_root / "project.json").read_text(encoding="utf-8"))
|
||||
assert project["canonical_storage_revision_id"] is None
|
||||
|
||||
|
||||
def test_r0_failure_before_manifest_update_is_recovered_by_exception_handler(
|
||||
monkeypatch, tmp_path
|
||||
):
|
||||
contract = storage_cases._contract(chunks=1)
|
||||
controller = _failure_controller(tmp_path, contract)
|
||||
original = controller._write_manifest
|
||||
calls = 0
|
||||
|
||||
def fail_once():
|
||||
nonlocal calls
|
||||
calls += 1
|
||||
if calls == 1:
|
||||
raise RuntimeError("before manifest update")
|
||||
return original()
|
||||
|
||||
monkeypatch.setattr(controller, "_write_manifest", fail_once)
|
||||
with pytest.raises(RuntimeError, match="before manifest update"):
|
||||
with controller:
|
||||
controller.commit_chunk(storage_cases._entry(0, contract), position=0)
|
||||
|
||||
manifest = json.loads(controller._manifest_path().read_text(encoding="utf-8"))
|
||||
assert manifest["status"] == "interrupted"
|
||||
assert len(manifest["chunks"]) == 1
|
||||
assert calls == 2
|
||||
|
||||
|
||||
def test_r0_failure_before_canonical_update_keeps_current_recovery_semantics(
|
||||
monkeypatch, tmp_path
|
||||
):
|
||||
contract = storage_cases._contract(chunks=1)
|
||||
controller = _failure_controller(tmp_path, contract)
|
||||
entry = storage_cases._entry(0, contract)
|
||||
original = controller._write_project
|
||||
calls = 0
|
||||
|
||||
def fail_once(*, set_canonical=False):
|
||||
nonlocal calls
|
||||
calls += 1
|
||||
if calls == 1:
|
||||
raise RuntimeError("before canonical pointer update")
|
||||
return original(set_canonical=set_canonical)
|
||||
|
||||
monkeypatch.setattr(controller, "_write_project", fail_once)
|
||||
with pytest.raises(RuntimeError, match="before canonical pointer update"):
|
||||
with controller:
|
||||
controller.commit_chunk(entry, position=0)
|
||||
controller.finalize(
|
||||
session={"session_id": "r0", "chunks": [entry]},
|
||||
report="r0 failure baseline",
|
||||
)
|
||||
|
||||
manifest = json.loads(controller._manifest_path().read_text(encoding="utf-8"))
|
||||
project = json.loads((controller.run_root / "project.json").read_text(encoding="utf-8"))
|
||||
assert manifest["status"] == "interrupted"
|
||||
assert calls == 2
|
||||
assert project["canonical_storage_revision_id"] is None
|
||||
@@ -0,0 +1,214 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import FrozenInstanceError
|
||||
|
||||
import pytest
|
||||
|
||||
import ComfyUI_H3_Continuum_Join.run_storage as storage_runtime
|
||||
from ComfyUI_H3_Continuum_Join.run_storage import (
|
||||
EmptyValidatedPrefix,
|
||||
RunStorageController,
|
||||
ValidatedPrefix,
|
||||
)
|
||||
from ComfyUI_H3_Continuum_Join.v3.planning_types import PrefixFacts
|
||||
from ComfyUI_H3_Continuum_Join.v3.review_control import (
|
||||
GENERATION_MODE_REVIEW,
|
||||
REVIEW_ACTION_CONTINUE,
|
||||
)
|
||||
|
||||
from . import test_v38_review_run_storage as cases
|
||||
|
||||
|
||||
def _review_controller(tmp_path, contract: dict) -> RunStorageController:
|
||||
controller = RunStorageController("phase-d-review")
|
||||
controller.run_root = tmp_path / "run"
|
||||
controller.revisions_root = controller.run_root / "revisions"
|
||||
controller.prompts = [
|
||||
f"prompt {index + 1}" for index in range(contract["chunk_count"])
|
||||
]
|
||||
controller.configure_review(
|
||||
generation_mode=GENERATION_MODE_REVIEW,
|
||||
review_action=REVIEW_ACTION_CONTINUE,
|
||||
)
|
||||
return controller
|
||||
|
||||
|
||||
def test_r2_raw_prefix_is_loaded_before_the_single_review_decision(
|
||||
monkeypatch, tmp_path
|
||||
):
|
||||
contract = cases._contract(chunks=3)
|
||||
cases._persist(
|
||||
tmp_path,
|
||||
contract,
|
||||
prefix=1,
|
||||
review_unit=(1, 1),
|
||||
updated_utc="2026-09-14T00:00:00+00:00",
|
||||
)
|
||||
controller = _review_controller(tmp_path, contract)
|
||||
events = []
|
||||
original_load = controller._load_entry
|
||||
original_resolve = storage_runtime.resolve_review_execution
|
||||
|
||||
def load(*args, **kwargs):
|
||||
events.append("raw_loaded")
|
||||
return original_load(*args, **kwargs)
|
||||
|
||||
def resolve(**kwargs):
|
||||
events.append("review_decision")
|
||||
return original_resolve(**kwargs)
|
||||
|
||||
monkeypatch.setattr(controller, "_load_entry", load)
|
||||
monkeypatch.setattr(storage_runtime, "resolve_review_execution", resolve)
|
||||
|
||||
prefix = controller._load_validated_review_prefix(contract, resume_safe=True)
|
||||
assert isinstance(prefix, ValidatedPrefix)
|
||||
assert events == ["raw_loaded"]
|
||||
controller._resolve_review_contract(
|
||||
contract,
|
||||
requested_nonce=0,
|
||||
resume_safe=True,
|
||||
validated_prefix=prefix,
|
||||
)
|
||||
|
||||
assert events == ["raw_loaded", "review_decision"]
|
||||
assert controller.review_runtime_metrics == {
|
||||
"review_decision_created": 1,
|
||||
"review_reconcile": 0,
|
||||
}
|
||||
assert not hasattr(controller, "_reconcile_review_execution_with_reused_prefix")
|
||||
|
||||
|
||||
def test_r2_validated_prefix_is_structurally_immutable_and_defensive(tmp_path):
|
||||
contract = cases._contract(chunks=3)
|
||||
cases._persist(
|
||||
tmp_path,
|
||||
contract,
|
||||
prefix=1,
|
||||
review_unit=(1, 1),
|
||||
updated_utc="2026-09-14T00:00:00+00:00",
|
||||
)
|
||||
controller = _review_controller(tmp_path, contract)
|
||||
candidate = controller.find_latest_review_head(contract)
|
||||
prefix = controller._freeze_validated_prefix(candidate, contract=contract)
|
||||
|
||||
assert isinstance(prefix.entries, tuple)
|
||||
assert isinstance(prefix.records, tuple)
|
||||
assert prefix.physical_group_boundaries == ((1, 1),)
|
||||
with pytest.raises(FrozenInstanceError):
|
||||
prefix.status = "changed"
|
||||
with pytest.raises(TypeError):
|
||||
prefix.manifest["status"] = "changed"
|
||||
candidate["manifest"]["status"] = "changed-after-freeze"
|
||||
assert prefix.manifest["status"] != "changed-after-freeze"
|
||||
|
||||
facts = prefix.to_planning_facts()
|
||||
assert isinstance(facts, PrefixFacts)
|
||||
assert facts.accepted_chunks == 1
|
||||
assert facts.configured_chunks == 3
|
||||
assert facts.review_unit.start == facts.review_unit.end == 1
|
||||
|
||||
|
||||
def test_r2_empty_validated_prefix_only_means_no_run_storage_prefix():
|
||||
prefix = EmptyValidatedPrefix(configured_chunks=3)
|
||||
facts = prefix.to_planning_facts()
|
||||
|
||||
assert prefix.entries == prefix.records == ()
|
||||
assert facts == PrefixFacts(
|
||||
accepted_chunks=0,
|
||||
configured_chunks=3,
|
||||
revision_id=None,
|
||||
status=None,
|
||||
review_unit=None,
|
||||
effective_nonce=0,
|
||||
branch_regenerate_from=0,
|
||||
physical_group_boundaries=(),
|
||||
)
|
||||
|
||||
|
||||
def test_r2_repository_validation_and_finalize_do_not_create_review_decisions(
|
||||
monkeypatch, tmp_path
|
||||
):
|
||||
contract = cases._contract(chunks=3)
|
||||
|
||||
def unexpected(**kwargs):
|
||||
pytest.fail("metadata validation must not create a Review Decision")
|
||||
|
||||
monkeypatch.setattr(storage_runtime, "resolve_review_execution", unexpected)
|
||||
cases._persist(
|
||||
tmp_path,
|
||||
contract,
|
||||
prefix=1,
|
||||
review_unit=(1, 1),
|
||||
updated_utc="2026-09-14T00:00:00+00:00",
|
||||
)
|
||||
controller = _review_controller(tmp_path, contract)
|
||||
prefix = controller._load_validated_review_prefix(contract, resume_safe=True)
|
||||
|
||||
assert isinstance(prefix, ValidatedPrefix)
|
||||
assert controller.review_runtime_metrics["review_decision_created"] == 0
|
||||
|
||||
|
||||
def test_r2_a_second_review_decision_is_rejected(tmp_path):
|
||||
contract = cases._contract(chunks=3)
|
||||
controller = _review_controller(tmp_path, contract)
|
||||
prefix = controller._load_validated_review_prefix(contract, resume_safe=True)
|
||||
controller._resolve_review_contract(
|
||||
contract,
|
||||
requested_nonce=0,
|
||||
resume_safe=True,
|
||||
validated_prefix=prefix,
|
||||
)
|
||||
|
||||
with pytest.raises(storage_runtime.RunStorageError, match="already created"):
|
||||
controller._resolve_review_contract(
|
||||
contract,
|
||||
requested_nonce=0,
|
||||
resume_safe=True,
|
||||
validated_prefix=prefix,
|
||||
)
|
||||
|
||||
|
||||
def test_r2_fixed_prefix_cannot_be_replaced_before_decision(tmp_path):
|
||||
contract = cases._contract(chunks=3)
|
||||
controller = _review_controller(tmp_path, contract)
|
||||
fixed = controller._load_validated_review_prefix(contract, resume_safe=True)
|
||||
replacement = EmptyValidatedPrefix(configured_chunks=3)
|
||||
|
||||
assert replacement is not fixed
|
||||
with pytest.raises(storage_runtime.RunStorageError, match="cannot replace"):
|
||||
controller._resolve_review_contract(
|
||||
contract,
|
||||
requested_nonce=0,
|
||||
resume_safe=True,
|
||||
validated_prefix=replacement,
|
||||
)
|
||||
assert controller.review_runtime_metrics == {
|
||||
"review_decision_created": 0,
|
||||
"review_reconcile": 0,
|
||||
}
|
||||
|
||||
|
||||
def test_r2_take_policy_also_creates_exactly_one_decision(tmp_path):
|
||||
contract = cases._contract(chunks=3, boundary=2, nonce=1)
|
||||
saved = cases._persist(
|
||||
tmp_path,
|
||||
contract,
|
||||
prefix=2,
|
||||
review_unit=(2, 2),
|
||||
updated_utc="2026-09-14T00:00:01+00:00",
|
||||
)
|
||||
revision = cases._take(cases._project(saved), group=2, nonce=1)
|
||||
|
||||
controller, _, _, _ = cases._resolve(
|
||||
tmp_path,
|
||||
cases._contract(chunks=3),
|
||||
take_action=storage_runtime.TAKE_ACTION_CONTINUE,
|
||||
take_group=2,
|
||||
take_revision_id=revision["revision_id"],
|
||||
)
|
||||
|
||||
assert isinstance(controller.validated_prefix, ValidatedPrefix)
|
||||
assert controller.review_runtime_metrics == {
|
||||
"review_decision_created": 1,
|
||||
"review_reconcile": 0,
|
||||
}
|
||||
@@ -0,0 +1,220 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import ast
|
||||
import inspect
|
||||
from pathlib import Path
|
||||
|
||||
import ComfyUI_H3_Continuum_Join.run_storage as storage_runtime
|
||||
from ComfyUI_H3_Continuum_Join.run_storage import EmptyValidatedPrefix
|
||||
from ComfyUI_H3_Continuum_Join.v3.runtime_coordinator import (
|
||||
project_selected_continuation_source,
|
||||
)
|
||||
from ComfyUI_H3_Continuum_Join.v3.execution_planner import (
|
||||
PROJECTION_CURRENT_REVIEW_UNIT,
|
||||
PROJECTION_FULL_ACCEPTED_PREFIX,
|
||||
build_execution_plan,
|
||||
)
|
||||
from ComfyUI_H3_Continuum_Join.v3.planning_types import (
|
||||
ContinuationSourceFacts,
|
||||
PrefixFacts,
|
||||
)
|
||||
from ComfyUI_H3_Continuum_Join.v3.review_control import (
|
||||
GENERATION_MODE_REVIEW,
|
||||
REVIEW_ACTION_CONTINUE,
|
||||
REVISION_STATUS_COMPLETE,
|
||||
REVISION_STATUS_REVIEW_READY,
|
||||
RUN_STORAGE_SAVE_AUTO_RESUME,
|
||||
ReviewUnit,
|
||||
resolve_review_execution,
|
||||
)
|
||||
|
||||
from . import test_v38_review_execution_cap as cap
|
||||
|
||||
|
||||
def _source(
|
||||
kind: str,
|
||||
*,
|
||||
accepted: int,
|
||||
reroll: int,
|
||||
boundaries: tuple[tuple[int, int], ...],
|
||||
) -> ContinuationSourceFacts:
|
||||
return project_selected_continuation_source(
|
||||
kind=kind,
|
||||
selected_source={
|
||||
"accepted_chunks": accepted,
|
||||
"reroll_from_chunk": reroll,
|
||||
"physical_group_boundaries": boundaries,
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
def _review_continue(*, chunks: int, prefix: int, terminal: bool):
|
||||
return resolve_review_execution(
|
||||
generation_mode=GENERATION_MODE_REVIEW,
|
||||
review_action=REVIEW_ACTION_CONTINUE,
|
||||
configured_chunks=chunks,
|
||||
validated_prefix_count=prefix,
|
||||
terminal_merge_enabled=terminal,
|
||||
terminal_pair_start=(chunks - 1 if terminal else None),
|
||||
manual_regenerate_from=0,
|
||||
run_storage_mode=RUN_STORAGE_SAVE_AUTO_RESUME,
|
||||
latest_review_unit=(
|
||||
None
|
||||
if prefix == 0
|
||||
else ReviewUnit(start=prefix, end=prefix, physical_group=prefix)
|
||||
),
|
||||
latest_revision_status=(
|
||||
None if prefix == 0 else REVISION_STATUS_REVIEW_READY
|
||||
),
|
||||
latest_effective_nonce=0,
|
||||
)
|
||||
|
||||
|
||||
def test_r3_projects_each_already_selected_continuation_source_kind():
|
||||
run_storage = _source(
|
||||
"run_storage",
|
||||
accepted=2,
|
||||
reroll=0,
|
||||
boundaries=((1, 1), (2, 2)),
|
||||
)
|
||||
explicit_session = _source(
|
||||
"explicit_session",
|
||||
accepted=1,
|
||||
reroll=2,
|
||||
boundaries=((1, 1),),
|
||||
)
|
||||
initial_state = _source(
|
||||
"initial_state",
|
||||
accepted=0,
|
||||
reroll=1,
|
||||
boundaries=(),
|
||||
)
|
||||
none = project_selected_continuation_source(
|
||||
kind="none",
|
||||
selected_source=None,
|
||||
)
|
||||
|
||||
assert run_storage == ContinuationSourceFacts(
|
||||
"run_storage", 2, 0, ((1, 1), (2, 2))
|
||||
)
|
||||
assert explicit_session == ContinuationSourceFacts(
|
||||
"explicit_session", 1, 2, ((1, 1),)
|
||||
)
|
||||
assert initial_state == ContinuationSourceFacts(
|
||||
"initial_state", 0, 1, ()
|
||||
)
|
||||
assert none == ContinuationSourceFacts("none", 0, 0, ())
|
||||
|
||||
|
||||
def test_r3_projection_boundary_has_no_selection_policy_calls():
|
||||
tree = ast.parse(inspect.getsource(project_selected_continuation_source))
|
||||
called_names = {
|
||||
node.func.id
|
||||
for node in ast.walk(tree)
|
||||
if isinstance(node, ast.Call) and isinstance(node.func, ast.Name)
|
||||
}
|
||||
assert called_names.isdisjoint(
|
||||
{
|
||||
"find_latest_review_head",
|
||||
"resolve_review_execution",
|
||||
"resolve_take_execution",
|
||||
"validate_session",
|
||||
"validate_state",
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
def test_r3_full_plan_owns_all_pending_physical_groups():
|
||||
plan = build_execution_plan(
|
||||
continuation_source_facts=ContinuationSourceFacts("none", 0, 0, ()),
|
||||
configured_chunks=3,
|
||||
terminal_merge_enabled=False,
|
||||
max_new_physical_groups=None,
|
||||
review_execution=None,
|
||||
)
|
||||
|
||||
assert [group.logical_chunks for group in plan.groups_to_generate] == [
|
||||
(1,),
|
||||
(2,),
|
||||
(3,),
|
||||
]
|
||||
assert plan.expected_status == REVISION_STATUS_COMPLETE
|
||||
assert plan.expected_review_unit is None
|
||||
assert plan.projection.kind == PROJECTION_FULL_ACCEPTED_PREFIX
|
||||
|
||||
|
||||
def test_r3_review_plan_generates_one_group_and_projects_only_that_unit():
|
||||
execution = _review_continue(chunks=3, prefix=1, terminal=False)
|
||||
plan = build_execution_plan(
|
||||
continuation_source_facts=ContinuationSourceFacts(
|
||||
"run_storage", 1, 0, ((1, 1),)
|
||||
),
|
||||
configured_chunks=3,
|
||||
terminal_merge_enabled=False,
|
||||
max_new_physical_groups=execution.max_new_physical_groups,
|
||||
review_execution=execution,
|
||||
retained_review_unit=ReviewUnit(1, 1, 1),
|
||||
)
|
||||
|
||||
assert [group.logical_chunks for group in plan.groups_to_generate] == [(2,)]
|
||||
assert plan.expected_status == REVISION_STATUS_REVIEW_READY
|
||||
assert plan.expected_review_unit == ReviewUnit(2, 2, 2)
|
||||
assert plan.projection.kind == PROJECTION_CURRENT_REVIEW_UNIT
|
||||
assert (plan.projection.start_chunk, plan.projection.end_chunk) == (2, 2)
|
||||
|
||||
|
||||
def test_r3_terminal_group_is_atomic_and_completion_projects_full_prefix():
|
||||
execution = _review_continue(chunks=3, prefix=1, terminal=True)
|
||||
plan = build_execution_plan(
|
||||
continuation_source_facts=ContinuationSourceFacts(
|
||||
"run_storage", 1, 0, ((1, 1),)
|
||||
),
|
||||
configured_chunks=3,
|
||||
terminal_merge_enabled=True,
|
||||
max_new_physical_groups=execution.max_new_physical_groups,
|
||||
review_execution=execution,
|
||||
retained_review_unit=ReviewUnit(1, 1, 1),
|
||||
)
|
||||
|
||||
assert len(plan.groups_to_generate) == 1
|
||||
assert plan.groups_to_generate[0].logical_chunks == (2, 3)
|
||||
assert plan.groups_to_generate[0].terminal_atomic is True
|
||||
assert plan.expected_status == REVISION_STATUS_COMPLETE
|
||||
assert plan.expected_review_unit == ReviewUnit(2, 3, 2)
|
||||
assert plan.projection.kind == PROJECTION_FULL_ACCEPTED_PREFIX
|
||||
|
||||
|
||||
def test_r3_planner_api_accepts_only_one_selected_source():
|
||||
parameters = inspect.signature(build_execution_plan).parameters
|
||||
assert "continuation_source_facts" in parameters
|
||||
assert "storage_prefix_facts" not in parameters
|
||||
assert "explicit_session_facts" not in parameters
|
||||
assert "initial_state_facts" not in parameters
|
||||
|
||||
|
||||
def test_r3_planner_module_imports_no_torch_or_comfyui():
|
||||
module_path = Path(inspect.getsourcefile(build_execution_plan))
|
||||
tree = ast.parse(module_path.read_text(encoding="utf-8"))
|
||||
imported = []
|
||||
for node in ast.walk(tree):
|
||||
if isinstance(node, ast.Import):
|
||||
imported.extend(alias.name for alias in node.names)
|
||||
elif isinstance(node, ast.ImportFrom) and node.module:
|
||||
imported.append(node.module)
|
||||
assert not any(name == "torch" or name.startswith("torch.") for name in imported)
|
||||
assert not any("comfy" in name.lower() for name in imported)
|
||||
|
||||
|
||||
def test_r3_validated_prefix_projection_contract_remains_prefix_facts():
|
||||
facts = EmptyValidatedPrefix(configured_chunks=3).to_planning_facts()
|
||||
assert isinstance(facts, PrefixFacts)
|
||||
assert not isinstance(facts, ContinuationSourceFacts)
|
||||
|
||||
|
||||
def test_r3_storage_off_runtime_consumes_the_pure_group_plan(monkeypatch):
|
||||
runtime = cap._install_fake_runtime(monkeypatch)
|
||||
entries, _, session, _ = cap._run_sequence(runtime, chunks=3)
|
||||
|
||||
assert len(entries) == len(session["chunks"]) == 3
|
||||
assert len(runtime.samples) == 3
|
||||
assert storage_runtime.get_active_run_storage() is None
|
||||
@@ -0,0 +1,209 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import ast
|
||||
import inspect
|
||||
|
||||
import pytest
|
||||
|
||||
from ComfyUI_H3_Continuum_Join.run_storage import RunStorageError
|
||||
from ComfyUI_H3_Continuum_Join.v2 import sequence
|
||||
from ComfyUI_H3_Continuum_Join.v3 import runtime_coordinator as coordinator_module
|
||||
from ComfyUI_H3_Continuum_Join.v3.runtime_coordinator import (
|
||||
InternalRuntimeCoordinator,
|
||||
)
|
||||
from ComfyUI_H3_Continuum_Join.v3.sampling_engine import sample_physical_group
|
||||
|
||||
|
||||
EXPECTED_RUN_SEQUENCE_PARAMETERS = (
|
||||
"model", "clip", "video_vae", "audio_vae", "sampler", "sigmas",
|
||||
"first_frame", "last_frame", "prompt_plan", "width", "height",
|
||||
"continuity", "base_seed", "audio_continuity", "exact_total_duration",
|
||||
"diagnostics_mode", "reroll_from_chunk", "reroll_nonce",
|
||||
"strict_compatibility", "debug", "seam_correction", "enable_preview",
|
||||
"session", "initial_state", "latent_only", "reference_assets",
|
||||
"reference_audio_source", "reference_audio_vae",
|
||||
"driving_audio_source", "driving_audio_vae", "reference_video_source",
|
||||
"timeline_video_source", "guide_source", "capture_refine_context",
|
||||
"memory_attribution", "prompt_conditioning_cache",
|
||||
"reference_encode_cache", "continuation_transport",
|
||||
"max_new_physical_groups", "_memory_attribution_collector",
|
||||
"_diagnostic_continuation_policy",
|
||||
)
|
||||
|
||||
|
||||
def _coordinator(*, storage=False, session=None, state=None):
|
||||
return InternalRuntimeCoordinator(
|
||||
storage_controller=(object() if storage else None),
|
||||
input_session=session,
|
||||
initial_state=state,
|
||||
)
|
||||
|
||||
|
||||
def test_r4_run_sequence_keeps_the_exact_explicit_41_keyword_signature():
|
||||
public = inspect.signature(sequence.run_sequence)
|
||||
internal = inspect.signature(sequence._run_runtime_internal)
|
||||
|
||||
assert tuple(public.parameters) == EXPECTED_RUN_SEQUENCE_PARAMETERS
|
||||
assert tuple(internal.parameters) == EXPECTED_RUN_SEQUENCE_PARAMETERS
|
||||
assert public == internal
|
||||
assert all(
|
||||
parameter.kind is inspect.Parameter.KEYWORD_ONLY
|
||||
for parameter in public.parameters.values()
|
||||
)
|
||||
|
||||
|
||||
def test_r4_storage_plus_explicit_session_keeps_existing_error():
|
||||
coordinator = _coordinator(storage=True, session={"session": True})
|
||||
|
||||
with pytest.raises(
|
||||
RunStorageError,
|
||||
match="Run Storage cannot be combined with an explicit Session",
|
||||
):
|
||||
coordinator.assert_storage_session_compatible()
|
||||
|
||||
|
||||
def test_r4_explicit_session_suppresses_state_before_session_validation(caplog):
|
||||
state = {"would": "otherwise be considered"}
|
||||
coordinator = _coordinator(
|
||||
session={"invalid": "session payload"},
|
||||
state=state,
|
||||
)
|
||||
|
||||
session, effective_state = coordinator.prepare_inputs()
|
||||
|
||||
assert session == {"invalid": "session payload"}
|
||||
assert effective_state is None
|
||||
assert coordinator.initial_state is None
|
||||
assert "using the session and ignoring initial_state" in caplog.text
|
||||
|
||||
|
||||
def test_r4_usable_storage_prefix_precedes_initial_state(monkeypatch):
|
||||
state = {"state": True}
|
||||
coordinator = _coordinator(storage=True, state=state)
|
||||
monkeypatch.setattr(
|
||||
coordinator_module,
|
||||
"entry_to_state",
|
||||
lambda entry: {"width": 64, "height": 64, "source": entry["source"]},
|
||||
)
|
||||
|
||||
selected = coordinator.select_continuation_source(
|
||||
preserved=[{"source": "storage"}],
|
||||
initial_state=state,
|
||||
chunks=2,
|
||||
width=64,
|
||||
height=64,
|
||||
reroll_from_chunk=0,
|
||||
effective_reroll_from_chunk=0,
|
||||
terminal_merge_enabled=False,
|
||||
)
|
||||
|
||||
assert selected.continuation_source_facts.kind == "run_storage"
|
||||
assert selected.continuation_source_facts.accepted_chunks == 1
|
||||
assert selected.previous_state["source"] == "storage"
|
||||
|
||||
|
||||
def test_r4_initial_state_is_considered_only_without_usable_prefix(monkeypatch):
|
||||
state = {"state": True}
|
||||
coordinator = _coordinator(storage=True, state=state)
|
||||
monkeypatch.setattr(
|
||||
coordinator_module,
|
||||
"validate_state",
|
||||
lambda value: {"width": 64, "height": 64, "source": value["state"]},
|
||||
)
|
||||
|
||||
selected = coordinator.select_continuation_source(
|
||||
preserved=[],
|
||||
initial_state=state,
|
||||
chunks=2,
|
||||
width=64,
|
||||
height=64,
|
||||
reroll_from_chunk=0,
|
||||
effective_reroll_from_chunk=0,
|
||||
terminal_merge_enabled=False,
|
||||
)
|
||||
|
||||
assert selected.continuation_source_facts.kind == "initial_state"
|
||||
assert selected.continuation_source_facts.accepted_chunks == 0
|
||||
assert selected.previous_state["source"] is True
|
||||
|
||||
|
||||
def test_r4_sampling_engine_owns_one_sample_and_preserves_observer_order():
|
||||
events = []
|
||||
|
||||
class Sigmas:
|
||||
shape = (5,)
|
||||
|
||||
class LayoutProfiler:
|
||||
def begin_sampling_group(self, **kwargs):
|
||||
events.append(("layout_begin", kwargs))
|
||||
return "layout-token"
|
||||
|
||||
def finish_sampling_group(self, token):
|
||||
events.append(("layout_finish", token))
|
||||
|
||||
class DiagnosticPolicy:
|
||||
def before_sampling(self, **kwargs):
|
||||
events.append(("diagnostic_before", kwargs))
|
||||
return "diagnostic-token"
|
||||
|
||||
def planner_event(_planner, event, **kwargs):
|
||||
events.append((f"planner_{event}", kwargs))
|
||||
|
||||
def sample_callable(**kwargs):
|
||||
events.append(("sample", kwargs))
|
||||
return "sampled"
|
||||
|
||||
sampled, diagnostic_token = sample_physical_group(
|
||||
sample_callable=sample_callable,
|
||||
model="model",
|
||||
conditioning="conditioning",
|
||||
latent="latent",
|
||||
sampler="sampler",
|
||||
sigmas=Sigmas(),
|
||||
seed=42,
|
||||
enable_preview=True,
|
||||
physical_group=2,
|
||||
logical_chunks=(2,),
|
||||
terminal_atomic=False,
|
||||
layout_validation_profiler=LayoutProfiler(),
|
||||
packed_row_planner="planner",
|
||||
planner_event=planner_event,
|
||||
diagnostic_policy=DiagnosticPolicy(),
|
||||
context_frames=22,
|
||||
)
|
||||
|
||||
assert sampled == "sampled"
|
||||
assert diagnostic_token == "diagnostic-token"
|
||||
assert [name for name, _ in events] == [
|
||||
"layout_begin",
|
||||
"diagnostic_before",
|
||||
"planner_begin_group",
|
||||
"sample",
|
||||
"planner_finish_group",
|
||||
"layout_finish",
|
||||
]
|
||||
|
||||
|
||||
def test_r4_runtime_uses_sampling_engine_and_engine_has_no_storage_import():
|
||||
runtime_tree = ast.parse(inspect.getsource(sequence._run_runtime_internal))
|
||||
calls = [
|
||||
node.func.id
|
||||
for node in ast.walk(runtime_tree)
|
||||
if isinstance(node, ast.Call) and isinstance(node.func, ast.Name)
|
||||
]
|
||||
engine_source = inspect.getsource(inspect.getmodule(sample_physical_group))
|
||||
|
||||
assert calls.count("sample_physical_group") == 2
|
||||
assert calls.count("sample_chunk") == 0
|
||||
assert "run_storage" not in engine_source.lower()
|
||||
|
||||
|
||||
def test_r4_continuation_priority_branches_have_one_owner():
|
||||
runtime_source = inspect.getsource(coordinator_module)
|
||||
sequence_source = inspect.getsource(sequence._run_runtime_internal)
|
||||
|
||||
assert runtime_source.count("class InternalRuntimeCoordinator") == 1
|
||||
assert runtime_source.count("def project_selected_continuation_source") == 1
|
||||
assert "selected_kind" in runtime_source
|
||||
assert "selected_source_kind" not in sequence_source
|
||||
assert "validate_state(initial_state)" not in sequence_source
|
||||
@@ -0,0 +1,318 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import hashlib
|
||||
import json
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
|
||||
import pytest
|
||||
|
||||
import ComfyUI_H3_Continuum_Join.run_storage as storage_runtime
|
||||
from ComfyUI_H3_Continuum_Join.run_storage import RunStorageError
|
||||
from ComfyUI_H3_Continuum_Join.v2.session import SessionValidationError
|
||||
|
||||
from . import test_v38_review_run_storage as storage_cases
|
||||
|
||||
|
||||
def _ready_controller(tmp_path, *, chunks: int = 2, terminal: bool = False):
|
||||
contract = storage_cases._contract(chunks=chunks, terminal=terminal)
|
||||
controller = storage_cases._controller(tmp_path, contract)
|
||||
controller.lock = storage_runtime._RunLock(controller.run_root / ".lock")
|
||||
controller.revision_root.mkdir(parents=True, exist_ok=True)
|
||||
controller._write_manifest()
|
||||
return controller, contract
|
||||
|
||||
|
||||
def _raw_path(controller, record: dict) -> Path:
|
||||
return controller.revision_root / "chunks" / record["filename"]
|
||||
|
||||
|
||||
def test_r5_retry_uses_a_new_raw_without_overwriting_the_accepted_raw(tmp_path):
|
||||
controller, contract = _ready_controller(tmp_path, chunks=1)
|
||||
controller.commit_group(
|
||||
(storage_cases._entry(0, contract),), positions=(0,)
|
||||
)
|
||||
first = dict(controller.manifest["chunks"][0])
|
||||
first_path = _raw_path(controller, first)
|
||||
first_bytes = first_path.read_bytes()
|
||||
|
||||
replacement = storage_cases._entry(0, contract)
|
||||
replacement["video"] = replacement["video"] + 1
|
||||
controller.commit_group((replacement,), positions=(0,))
|
||||
second = dict(controller.manifest["chunks"][0])
|
||||
|
||||
assert second["filename"] != first["filename"]
|
||||
assert first_path.read_bytes() == first_bytes
|
||||
assert hashlib.sha256(first_bytes).hexdigest() == first["file_sha256"]
|
||||
assert _raw_path(controller, second).is_file()
|
||||
|
||||
|
||||
def test_r5_terminal_group_uses_one_transaction_and_one_manifest_switch(
|
||||
monkeypatch, tmp_path
|
||||
):
|
||||
controller, contract = _ready_controller(tmp_path, terminal=True)
|
||||
writes = 0
|
||||
original = controller._write_manifest
|
||||
|
||||
def counted_write():
|
||||
nonlocal writes
|
||||
writes += 1
|
||||
return original()
|
||||
|
||||
monkeypatch.setattr(controller, "_write_manifest", counted_write)
|
||||
controller.commit_group(
|
||||
(
|
||||
storage_cases._entry(0, contract),
|
||||
storage_cases._entry(1, contract),
|
||||
),
|
||||
positions=(0, 1),
|
||||
)
|
||||
|
||||
records = controller.manifest["chunks"]
|
||||
assert writes == 1
|
||||
assert [record["sequence_index"] for record in records] == [0, 1]
|
||||
transaction_parts = [
|
||||
record["filename"].split("-txn-", 1)[1].split("-chunk-", 1)[0]
|
||||
for record in records
|
||||
]
|
||||
assert len(set(transaction_parts)) == 1
|
||||
|
||||
|
||||
def test_r5_terminal_half_is_rejected_before_any_raw_write(tmp_path):
|
||||
controller, contract = _ready_controller(tmp_path, terminal=True)
|
||||
|
||||
with pytest.raises(RunStorageError, match="physical group is incomplete"):
|
||||
controller.commit_chunk(storage_cases._entry(0, contract), position=0)
|
||||
|
||||
assert controller.manifest["chunks"] == []
|
||||
assert not list((controller.revision_root / "chunks").glob("*.safetensors"))
|
||||
|
||||
|
||||
def test_r5_validates_every_entry_before_writing_group_raw(tmp_path):
|
||||
controller, contract = _ready_controller(tmp_path, terminal=True)
|
||||
invalid = dict(storage_cases._entry(1, contract))
|
||||
invalid.pop("video")
|
||||
|
||||
with pytest.raises(SessionValidationError):
|
||||
controller.commit_group(
|
||||
(storage_cases._entry(0, contract), invalid), positions=(0, 1)
|
||||
)
|
||||
|
||||
assert controller.manifest["chunks"] == []
|
||||
assert not list((controller.revision_root / "chunks").glob("*.safetensors"))
|
||||
|
||||
|
||||
def test_r5_second_raw_failure_leaves_only_unreferenced_orphan(
|
||||
monkeypatch, tmp_path
|
||||
):
|
||||
controller, contract = _ready_controller(tmp_path, terminal=True)
|
||||
original = storage_runtime.save_file
|
||||
calls = 0
|
||||
|
||||
def fail_second(tensors, filename, *, metadata):
|
||||
nonlocal calls
|
||||
calls += 1
|
||||
if calls == 2:
|
||||
raise RuntimeError("synthetic second raw failure")
|
||||
return original(tensors, filename, metadata=metadata)
|
||||
|
||||
monkeypatch.setattr(storage_runtime, "save_file", fail_second)
|
||||
with pytest.raises(RuntimeError, match="second raw failure"):
|
||||
controller.commit_group(
|
||||
(
|
||||
storage_cases._entry(0, contract),
|
||||
storage_cases._entry(1, contract),
|
||||
),
|
||||
positions=(0, 1),
|
||||
)
|
||||
|
||||
persisted = json.loads(controller._manifest_path().read_text(encoding="utf-8"))
|
||||
assert persisted["chunks"] == []
|
||||
assert controller.manifest["chunks"] == []
|
||||
assert len(list((controller.revision_root / "chunks").glob("*.safetensors"))) == 1
|
||||
|
||||
|
||||
def test_r5_catchable_manifest_failure_recovers_only_the_complete_group(
|
||||
monkeypatch, tmp_path
|
||||
):
|
||||
controller, contract = _ready_controller(tmp_path, terminal=True)
|
||||
original = controller._write_manifest
|
||||
calls = 0
|
||||
|
||||
def fail_once():
|
||||
nonlocal calls
|
||||
calls += 1
|
||||
if calls == 1:
|
||||
raise RuntimeError("synthetic manifest switch failure")
|
||||
return original()
|
||||
|
||||
monkeypatch.setattr(controller, "_write_manifest", fail_once)
|
||||
with pytest.raises(RuntimeError, match="manifest switch failure"):
|
||||
with controller:
|
||||
controller.commit_group(
|
||||
(
|
||||
storage_cases._entry(0, contract),
|
||||
storage_cases._entry(1, contract),
|
||||
),
|
||||
positions=(0, 1),
|
||||
)
|
||||
|
||||
persisted = json.loads(controller._manifest_path().read_text(encoding="utf-8"))
|
||||
assert calls == 2
|
||||
assert persisted["status"] == "interrupted"
|
||||
assert [record["sequence_index"] for record in persisted["chunks"]] == [0, 1]
|
||||
|
||||
|
||||
def test_r5_commit_group_does_not_write_the_canonical_project(monkeypatch, tmp_path):
|
||||
controller, contract = _ready_controller(tmp_path, chunks=1)
|
||||
project_writes = 0
|
||||
|
||||
def unexpected_project_write(*, set_canonical=False):
|
||||
nonlocal project_writes
|
||||
project_writes += 1
|
||||
|
||||
monkeypatch.setattr(controller, "_write_project", unexpected_project_write)
|
||||
controller.commit_group(
|
||||
(storage_cases._entry(0, contract),), positions=(0,)
|
||||
)
|
||||
|
||||
assert project_writes == 0
|
||||
assert not (controller.run_root / "project.json").exists()
|
||||
|
||||
|
||||
def test_r5_reader_keeps_legacy_chunk_filename_compatibility(tmp_path):
|
||||
controller, contract = _ready_controller(tmp_path, chunks=1)
|
||||
controller.commit_group(
|
||||
(storage_cases._entry(0, contract),), positions=(0,)
|
||||
)
|
||||
record = controller.manifest["chunks"][0]
|
||||
current_path = _raw_path(controller, record)
|
||||
legacy_path = current_path.with_name("chunk_0001.safetensors")
|
||||
current_path.replace(legacy_path)
|
||||
record["filename"] = legacy_path.name
|
||||
record["file_size"] = legacy_path.stat().st_size
|
||||
record["file_sha256"] = hashlib.sha256(legacy_path.read_bytes()).hexdigest()
|
||||
controller._write_manifest()
|
||||
|
||||
entries, records = controller._valid_prefix(
|
||||
controller.manifest,
|
||||
list(contract["chunk_contract_hashes"]),
|
||||
current_contract=contract,
|
||||
)
|
||||
|
||||
assert len(entries) == len(records) == 1
|
||||
assert records[0]["filename"] == "chunk_0001.safetensors"
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("stage", "expected_records", "expected_raws"),
|
||||
(
|
||||
("raw_before", 0, 0),
|
||||
("raw_mid", 0, 0),
|
||||
("first_raw_done", 0, 1),
|
||||
("before_manifest", 0, 2),
|
||||
("manifest_temp_mid", 0, 2),
|
||||
("before_replace", 0, 2),
|
||||
("after_replace", 2, 2),
|
||||
("after_directory_durability", 2, 2),
|
||||
),
|
||||
)
|
||||
def test_r5_fresh_process_kill_never_exposes_a_partial_terminal_group(
|
||||
tmp_path, stage, expected_records, expected_raws
|
||||
):
|
||||
worker = (
|
||||
Path(__file__).parent / "helpers" / "r5_process_crash_worker.py"
|
||||
)
|
||||
scenario_root = tmp_path / stage
|
||||
process = subprocess.Popen(
|
||||
[sys.executable, str(worker), str(scenario_root), stage],
|
||||
cwd=str(Path(__file__).resolve().parents[1]),
|
||||
)
|
||||
signal = scenario_root / "reached.json"
|
||||
deadline = time.monotonic() + 30
|
||||
try:
|
||||
while time.monotonic() < deadline and not signal.exists():
|
||||
if process.poll() is not None:
|
||||
raise AssertionError(
|
||||
f"crash worker exited before {stage}: {process.returncode}"
|
||||
)
|
||||
time.sleep(0.05)
|
||||
assert signal.exists(), f"crash worker did not reach {stage}"
|
||||
process.terminate()
|
||||
process.wait(timeout=15)
|
||||
finally:
|
||||
if process.poll() is None:
|
||||
process.kill()
|
||||
process.wait(timeout=15)
|
||||
|
||||
manifest_paths = list((scenario_root / "run" / "revisions").glob("*/manifest.json"))
|
||||
assert len(manifest_paths) == 1
|
||||
manifest = json.loads(manifest_paths[0].read_text(encoding="utf-8"))
|
||||
assert len(manifest["chunks"]) == expected_records
|
||||
raw_paths = list((manifest_paths[0].parent / "chunks").glob("*.safetensors"))
|
||||
assert len(raw_paths) == expected_raws
|
||||
for record in manifest["chunks"]:
|
||||
raw = manifest_paths[0].parent / "chunks" / record["filename"]
|
||||
assert raw.is_file()
|
||||
assert raw.stat().st_size == record["file_size"]
|
||||
assert hashlib.sha256(raw.read_bytes()).hexdigest() == record["file_sha256"]
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("stage", "project_exists"),
|
||||
(
|
||||
("finalize_manifest_1", False),
|
||||
("finalize_manifest_2", False),
|
||||
("project_before_replace", False),
|
||||
("project_after_replace", True),
|
||||
),
|
||||
)
|
||||
def test_r5_finalize_and_canonical_kill_windows_preserve_fresh_reader_selection(
|
||||
tmp_path, stage, project_exists
|
||||
):
|
||||
worker = Path(__file__).parent / "helpers" / "r5_process_crash_worker.py"
|
||||
scenario_root = tmp_path / stage
|
||||
process = subprocess.Popen(
|
||||
[sys.executable, str(worker), str(scenario_root), stage],
|
||||
cwd=str(Path(__file__).resolve().parents[1]),
|
||||
)
|
||||
signal = scenario_root / "reached.json"
|
||||
deadline = time.monotonic() + 30
|
||||
try:
|
||||
while time.monotonic() < deadline and not signal.exists():
|
||||
if process.poll() is not None:
|
||||
raise AssertionError(
|
||||
f"crash worker exited before {stage}: {process.returncode}"
|
||||
)
|
||||
time.sleep(0.05)
|
||||
assert signal.exists(), f"crash worker did not reach {stage}"
|
||||
process.terminate()
|
||||
process.wait(timeout=15)
|
||||
finally:
|
||||
if process.poll() is None:
|
||||
process.kill()
|
||||
process.wait(timeout=15)
|
||||
|
||||
run_root = scenario_root / "run"
|
||||
project_path = run_root / "project.json"
|
||||
assert project_path.exists() is project_exists
|
||||
manifests = list((run_root / "revisions").glob("*/manifest.json"))
|
||||
assert len(manifests) == 1
|
||||
manifest = json.loads(manifests[0].read_text(encoding="utf-8"))
|
||||
assert len(manifest["chunks"]) == 2
|
||||
|
||||
fresh = storage_runtime.RunStorageController("phase-d-review")
|
||||
fresh.run_root = run_root
|
||||
fresh.revisions_root = run_root / "revisions"
|
||||
_, catalog, chains = fresh._provenance_catalog()
|
||||
selected_revision, selected_chain = fresh._canonical_project_selection(
|
||||
catalog=catalog,
|
||||
chains=chains,
|
||||
)
|
||||
# The R0 fallback selects a complete legacy-style manifest even before its
|
||||
# provenance and project pointer are published. R5 preserves that exact
|
||||
# fresh-reader behavior; only commit_group raw publication changes.
|
||||
assert selected_revision == manifest["revision_id"]
|
||||
assert selected_chain
|
||||
@@ -0,0 +1,204 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import ast
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from ComfyUI_H3_Continuum_Join.v3 import driving_nodes
|
||||
from ComfyUI_H3_Continuum_Join.v3.node_facade import (
|
||||
RuntimeOutput,
|
||||
execute_v38_runtime_request,
|
||||
make_runtime_request,
|
||||
)
|
||||
from ComfyUI_H3_Continuum_Join.v3.resolution import (
|
||||
H3_SIZE_SOURCE_LEGACY,
|
||||
H3_SIZE_SOURCE_MANUAL,
|
||||
)
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class _Resolution:
|
||||
width: int = 704
|
||||
height: int = 1024
|
||||
actual_mp: float = 0.720896
|
||||
aspect_source: str = "Manual Width / Height"
|
||||
warnings: tuple[str, ...] = ()
|
||||
|
||||
|
||||
def _request(*, mode="Off", size_source=H3_SIZE_SOURCE_LEGACY, inputs=None):
|
||||
return make_runtime_request(
|
||||
runtime_kwargs={"marker": object()},
|
||||
fixed_runtime_kwargs={"width": 704, "height": 1024},
|
||||
resolution=_Resolution(),
|
||||
size_source=size_source,
|
||||
diagnostics_mode=mode,
|
||||
diagnostics_inputs={"chunk_seconds": 5.0, **(inputs or {})},
|
||||
)
|
||||
|
||||
|
||||
def _append(status, diagnostics, *, mode):
|
||||
return f"{status}|{mode}|{diagnostics}"
|
||||
|
||||
|
||||
def test_r6_request_freezes_keyword_containers_without_copying_runtime_objects():
|
||||
marker = object()
|
||||
request = make_runtime_request(
|
||||
runtime_kwargs={"marker": marker},
|
||||
fixed_runtime_kwargs={"width": 704},
|
||||
resolution=_Resolution(),
|
||||
size_source=H3_SIZE_SOURCE_LEGACY,
|
||||
diagnostics_mode="Off",
|
||||
diagnostics_inputs={"chunk_seconds": 5.0, "reference": marker},
|
||||
)
|
||||
|
||||
assert request.runtime_kwargs["marker"] is marker
|
||||
assert request.diagnostics_inputs["reference"] is marker
|
||||
with pytest.raises(TypeError):
|
||||
request.runtime_kwargs["other"] = object()
|
||||
with pytest.raises(TypeError):
|
||||
request.diagnostics_inputs["other"] = object()
|
||||
|
||||
|
||||
def test_r6_request_rejects_duplicate_runtime_keywords():
|
||||
with pytest.raises(TypeError, match="multiple values"):
|
||||
make_runtime_request(
|
||||
runtime_kwargs={"width": 1},
|
||||
fixed_runtime_kwargs={"width": 704},
|
||||
resolution=_Resolution(),
|
||||
size_source=H3_SIZE_SOURCE_LEGACY,
|
||||
diagnostics_mode="Off",
|
||||
diagnostics_inputs={},
|
||||
)
|
||||
|
||||
|
||||
def test_r6_runtime_output_preserves_nonstandard_values_and_tuple_identity():
|
||||
marker = object()
|
||||
assert RuntimeOutput(marker).as_public_tuple() is marker
|
||||
|
||||
output = (object(), object(), object(), "status", object())
|
||||
request = _request()
|
||||
result = execute_v38_runtime_request(
|
||||
request,
|
||||
runtime_adapter=lambda **kwargs: output,
|
||||
legacy_size_source=H3_SIZE_SOURCE_LEGACY,
|
||||
diagnostics_off="Off",
|
||||
diagnostics_full="Detailed Report",
|
||||
reference_video_size_default="Efficient",
|
||||
build_diagnostics=lambda **kwargs: pytest.fail("must not run"),
|
||||
append_status=_append,
|
||||
)
|
||||
assert result is output
|
||||
|
||||
|
||||
def test_r6_facade_decorates_status_only_after_existing_runtime_returns():
|
||||
video, audio, plan, tail = object(), object(), object(), object()
|
||||
output = (video, audio, plan, "base", tail)
|
||||
seen = {}
|
||||
request = _request(
|
||||
mode="Basic",
|
||||
size_source=H3_SIZE_SOURCE_MANUAL,
|
||||
inputs={
|
||||
"reference_image_1": "image-1",
|
||||
"reference_size": "Match Output",
|
||||
"reference_video_1": "guide",
|
||||
"guide": "still",
|
||||
},
|
||||
)
|
||||
|
||||
def build(**kwargs):
|
||||
seen.update(kwargs)
|
||||
return "diagnostics"
|
||||
|
||||
result = execute_v38_runtime_request(
|
||||
request,
|
||||
runtime_adapter=lambda **kwargs: output,
|
||||
legacy_size_source=H3_SIZE_SOURCE_LEGACY,
|
||||
diagnostics_off="Off",
|
||||
diagnostics_full="Detailed Report",
|
||||
reference_video_size_default="Efficient",
|
||||
build_diagnostics=build,
|
||||
append_status=_append,
|
||||
)
|
||||
|
||||
assert result[:3] == output[:3]
|
||||
assert result[4] is tail
|
||||
assert "Resolution: 704 x 1024 (0.72 MP)" in result[3]
|
||||
assert result[3].endswith("|Basic|diagnostics")
|
||||
assert seen["video_latents"] is video
|
||||
assert seen["audio_latents"] is audio
|
||||
assert seen["assembly_plan"] is plan
|
||||
assert seen["reference_images"] == ("image-1", None, None)
|
||||
assert seen["still_guide_active"] is True
|
||||
|
||||
|
||||
def test_r6_diagnostic_failure_keeps_runtime_payloads_and_returns_status_warning():
|
||||
payload = (object(), object(), object(), "base", object())
|
||||
result = execute_v38_runtime_request(
|
||||
_request(mode="Detailed Report"),
|
||||
runtime_adapter=lambda **kwargs: payload,
|
||||
legacy_size_source=H3_SIZE_SOURCE_LEGACY,
|
||||
diagnostics_off="Off",
|
||||
diagnostics_full="Detailed Report",
|
||||
reference_video_size_default="Efficient",
|
||||
build_diagnostics=lambda **kwargs: (_ for _ in ()).throw(RuntimeError("bad")),
|
||||
append_status=_append,
|
||||
)
|
||||
|
||||
assert result[:3] == payload[:3]
|
||||
assert result[4] is payload[4]
|
||||
assert "generation result was preserved" in result[3]
|
||||
assert "RuntimeError: bad" in result[3]
|
||||
|
||||
|
||||
def test_r6_v38_node_builds_one_request_then_delegates_to_existing_runtime_adapter(monkeypatch):
|
||||
captured = {}
|
||||
|
||||
def facade(request, **kwargs):
|
||||
captured["request"] = request
|
||||
captured["adapter"] = kwargs["runtime_adapter"]
|
||||
return "facade-result"
|
||||
|
||||
monkeypatch.setattr(driving_nodes, "execute_v38_runtime_request", facade)
|
||||
result = driving_nodes.H3ContinuumSamplerV38().run(
|
||||
chunk_seconds=5.0,
|
||||
size_source=H3_SIZE_SOURCE_MANUAL,
|
||||
width=704,
|
||||
height=1024,
|
||||
project_id="stable-project",
|
||||
)
|
||||
|
||||
request = captured["request"]
|
||||
assert result == "facade-result"
|
||||
assert request.runtime_kwargs["width"] == 704
|
||||
assert request.runtime_kwargs["height"] == 1024
|
||||
assert request.runtime_kwargs["project_id"] == "stable-project"
|
||||
assert request.runtime_kwargs["reference_encode_cache"] is True
|
||||
assert "size_source" not in request.runtime_kwargs
|
||||
assert callable(captured["adapter"])
|
||||
|
||||
|
||||
def test_r6_facade_module_has_no_runtime_owner_imports():
|
||||
tree = ast.parse((ROOT / "v3" / "node_facade.py").read_text(encoding="utf-8"))
|
||||
imported = set()
|
||||
for node in ast.walk(tree):
|
||||
if isinstance(node, ast.Import):
|
||||
imported.update(alias.name for alias in node.names)
|
||||
elif isinstance(node, ast.ImportFrom) and node.module:
|
||||
imported.add(node.module)
|
||||
forbidden = {
|
||||
"torch",
|
||||
"run_storage",
|
||||
"runtime_coordinator",
|
||||
"execution_planner",
|
||||
"sampling_engine",
|
||||
}
|
||||
assert not any(
|
||||
name == forbidden_name or name.endswith(f".{forbidden_name}")
|
||||
for name in imported
|
||||
for forbidden_name in forbidden
|
||||
)
|
||||
@@ -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.8.0"' in version_source
|
||||
assert 'PACKAGE_VERSION = "3.8.1"' in version_source
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
from ComfyUI_H3_Continuum_Join.constants import DIAGNOSTICS_BASIC
|
||||
from ComfyUI_H3_Continuum_Join.v2.nodes import _repair_v200_example_widget_shift
|
||||
|
||||
@@ -29,13 +26,3 @@ def test_valid_v2_widget_values_are_unchanged():
|
||||
debug=True,
|
||||
)
|
||||
assert values == (False, False, DIAGNOSTICS_BASIC, 2, 7, True, True)
|
||||
|
||||
|
||||
def test_bundled_v2_example_serializes_control_after_generate_slot():
|
||||
root = Path(__file__).resolve().parents[1]
|
||||
data = json.loads((root / "examples" / "H3_Continuum_V2_3x5s.json").read_text(encoding="utf-8"))
|
||||
node = next(n for n in data["nodes"] if n["type"] == "H3ContinuumSamplerV2")
|
||||
values = node["widgets_values"]
|
||||
assert len(values) == 16
|
||||
assert values[8] in {"fixed", "increment", "decrement", "randomize"}
|
||||
assert values[11] in {"Basic", "Full", "Off"}
|
||||
|
||||
@@ -109,11 +109,14 @@ def test_three_chunks_are_committed_to_distinct_files(tmp_path):
|
||||
controller.commit_chunk(entry, position=position)
|
||||
|
||||
chunks_root = controller.revision_root / "chunks"
|
||||
assert [path.name for path in sorted(chunks_root.glob("*.safetensors"))] == [
|
||||
"chunk_0001.safetensors",
|
||||
"chunk_0002.safetensors",
|
||||
"chunk_0003.safetensors",
|
||||
]
|
||||
raw_names = [path.name for path in chunks_root.glob("*.safetensors")]
|
||||
assert len(raw_names) == 3
|
||||
assert all(name.startswith("rev-revision-test-txn-") for name in raw_names)
|
||||
assert sorted(name.rsplit("-", 2)[-2] for name in raw_names) == [
|
||||
"chunk",
|
||||
"chunk",
|
||||
"chunk",
|
||||
]
|
||||
records = controller.manifest["chunks"]
|
||||
assert [record["sequence_index"] for record in records] == [0, 1, 2]
|
||||
assert [record["entry"]["sequence_index"] for record in records] == [0, 1, 2]
|
||||
@@ -121,11 +124,14 @@ def test_three_chunks_are_committed_to_distinct_files(tmp_path):
|
||||
assert [entry["sequence_index"] for entry in source_entries] == [0, 0, 0]
|
||||
|
||||
persisted = json.loads(controller._manifest_path().read_text(encoding="utf-8"))
|
||||
assert [record["filename"] for record in persisted["chunks"]] == [
|
||||
"chunk_0001.safetensors",
|
||||
"chunk_0002.safetensors",
|
||||
"chunk_0003.safetensors",
|
||||
]
|
||||
assert [record["filename"] for record in persisted["chunks"]] == [
|
||||
record["filename"] for record in records
|
||||
]
|
||||
assert [name[-22:] for name in (record["filename"] for record in records)] == [
|
||||
"chunk-0001.safetensors",
|
||||
"chunk-0002.safetensors",
|
||||
"chunk-0003.safetensors",
|
||||
]
|
||||
|
||||
|
||||
def test_interrupted_fixed_prompt_run_resumes_the_correct_prefix(tmp_path):
|
||||
@@ -139,17 +145,17 @@ def test_interrupted_fixed_prompt_run_resumes_the_correct_prefix(tmp_path):
|
||||
|
||||
assert [entry["seed"] for entry in entries] == [100, 101]
|
||||
assert [entry["clip_index"] for entry in entries] == [1, 2]
|
||||
assert [record["filename"] for record in records] == [
|
||||
"chunk_0001.safetensors",
|
||||
"chunk_0002.safetensors",
|
||||
]
|
||||
assert [record["filename"][-22:] for record in records] == [
|
||||
"chunk-0001.safetensors",
|
||||
"chunk-0002.safetensors",
|
||||
]
|
||||
|
||||
resumed.commit_chunk(_entry(2), position=2)
|
||||
assert [record["filename"] for record in resumed.manifest["chunks"]] == [
|
||||
"chunk_0001.safetensors",
|
||||
"chunk_0002.safetensors",
|
||||
"chunk_0003.safetensors",
|
||||
]
|
||||
assert [record["filename"][-22:] for record in resumed.manifest["chunks"]] == [
|
||||
"chunk-0001.safetensors",
|
||||
"chunk-0002.safetensors",
|
||||
"chunk-0003.safetensors",
|
||||
]
|
||||
|
||||
|
||||
def test_fsync_file_accepts_a_completed_file_on_windows(tmp_path):
|
||||
|
||||
@@ -1,23 +1,14 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import shutil
|
||||
import subprocess
|
||||
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():
|
||||
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")
|
||||
|
||||
@@ -173,40 +164,3 @@ assert.deepEqual(
|
||||
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",
|
||||
]
|
||||
|
||||
@@ -404,7 +404,7 @@ def test_masked_av_preserves_image_and_audio_refs_in_terminal_groups(monkeypatch
|
||||
assert [ref["kind"] for ref in refs] == ["image", "audio"]
|
||||
|
||||
|
||||
def test_reused_session_returns_incomplete_context_without_stopping(monkeypatch):
|
||||
def test_reused_session_reconstructs_complete_context_without_stopping(monkeypatch):
|
||||
first_outputs = _capture_sequence(monkeypatch, terminal=False)
|
||||
reused_outputs = _capture_sequence(
|
||||
monkeypatch,
|
||||
@@ -412,10 +412,10 @@ def test_reused_session_returns_incomplete_context_without_stopping(monkeypatch)
|
||||
session=first_outputs[2],
|
||||
)
|
||||
context = reused_outputs[4]
|
||||
assert context["complete"] is False
|
||||
assert context["groups"] == ()
|
||||
assert context["complete"] is True
|
||||
assert [group["logical_chunks"] for group in context["groups"]] == [(1,), (2,)]
|
||||
assert len(reused_outputs[0]) == 2
|
||||
assert any("Run Storage" in note for note in context["notes"])
|
||||
assert context["notes"] == first_outputs[4]["notes"]
|
||||
|
||||
|
||||
def test_v35_full_memory_events_follow_physical_terminal_group_order(monkeypatch):
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from ComfyUI_H3_Continuum_Join import nodes as root_nodes
|
||||
@@ -28,9 +25,6 @@ from ComfyUI_H3_Continuum_Join.constants import (
|
||||
from ComfyUI_H3_Continuum_Join.v3.nodes import H3ContinuumSamplerProduction
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
|
||||
|
||||
def test_v36_is_registered_without_replacing_v35():
|
||||
assert NODE_CLASS_MAPPINGS["H3ContinuumSamplerV36"] is H3ContinuumSamplerV36
|
||||
assert NODE_DISPLAY_NAME_MAPPINGS["H3ContinuumSamplerV36"] == (
|
||||
@@ -189,29 +183,3 @@ def test_v36_non_balanced_fallback_uses_legacy_reference_revision_identity():
|
||||
|
||||
assert reference_identity == base_identity
|
||||
assert masked_identity != reference_identity
|
||||
|
||||
|
||||
def test_v36_template_uses_standard_backend_and_v35_template_is_unchanged():
|
||||
v36 = json.loads(
|
||||
(ROOT / "examples/workflows/MiniMax_H3_Continuum_V36.json").read_text(
|
||||
encoding="utf-8"
|
||||
)
|
||||
)
|
||||
v35 = json.loads(
|
||||
(ROOT / "examples/workflows/MiniMax_H3_Continuum_V35.json").read_text(
|
||||
encoding="utf-8"
|
||||
)
|
||||
)
|
||||
v36_sampler = next(node for node in v36["nodes"] if node["id"] == 305)
|
||||
v35_sampler = next(node for node in v35["nodes"] if node["id"] == 305)
|
||||
|
||||
assert v36_sampler["type"] == "H3ContinuumSamplerV36"
|
||||
assert v36_sampler["properties"]["Node name for S&R"] == (
|
||||
"H3ContinuumSamplerV36"
|
||||
)
|
||||
assert v36_sampler["widgets_values"][-1] == CONTINUATION_BACKEND_STANDARD
|
||||
assert v36_sampler["widgets_values_named"]["continuation_backend"] == (
|
||||
CONTINUATION_BACKEND_STANDARD
|
||||
)
|
||||
assert v35_sampler["type"] == "H3ContinuumSamplerV35"
|
||||
assert "continuation_backend" not in v35_sampler["widgets_values_named"]
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
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()
|
||||
@@ -6,6 +6,6 @@ def test_completed_review_lifecycle_with_real_frontend(review_queue_results):
|
||||
"same completed revision reuse exits setup without new Sampling",
|
||||
"three review queues advance without any executed events",
|
||||
"settings edited during execution remain out of date after readback",
|
||||
"same setup request is not mutated by legacy preparation then API preparation",
|
||||
"queue adapter owns setup preparation without mutating the caller payload",
|
||||
):
|
||||
assert review_queue_results[case]["pass"]
|
||||
|
||||
@@ -1,214 +0,0 @@
|
||||
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"]
|
||||
@@ -123,12 +123,12 @@ def test_registry_package_keeps_one_workflow_and_excludes_development_assets():
|
||||
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 "!examples/workflows/MiniMax_H3_Continuum_V38x.json" in rules
|
||||
assert "!examples/workflows/MiniMax_H3_Continuum_V38x.zip" in rules
|
||||
assert "*.zip" in rules
|
||||
|
||||
workflow = json.loads(
|
||||
(ROOT / "examples/workflows/MiniMax_H3_Continuum_V38.json").read_text(
|
||||
(ROOT / "examples/workflows/MiniMax_H3_Continuum_V38x.json").read_text(
|
||||
encoding="utf-8"
|
||||
)
|
||||
)
|
||||
@@ -170,8 +170,8 @@ def test_registry_manifest_matches_every_declared_source_file():
|
||||
assert {
|
||||
path for path in entries if path.startswith("examples/")
|
||||
} == {
|
||||
"examples/workflows/MiniMax_H3_Continuum_V38.json",
|
||||
"examples/workflows/MiniMax_H3_Continuum_V38.zip",
|
||||
"examples/workflows/MiniMax_H3_Continuum_V38x.json",
|
||||
"examples/workflows/MiniMax_H3_Continuum_V38x.zip",
|
||||
}
|
||||
|
||||
for relative_path, expected_digest in entries.items():
|
||||
|
||||
@@ -7,16 +7,16 @@ from zipfile import ZipFile
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
WORKFLOW_PATH = ROOT / "examples" / "workflows" / "MiniMax_H3_Continuum_V38.json"
|
||||
WORKFLOW_PATH = ROOT / "examples" / "workflows" / "MiniMax_H3_Continuum_V38x.json"
|
||||
|
||||
# User-approved final distribution. Do not sanitize or reserialize this graph.
|
||||
WORKFLOW_SHA256 = "e490c87e4995930f95c8fffc4c678111d7897e74003e1962b9b4a247ba43f4ac"
|
||||
ZIP_SHA256 = "83d28cc0cd549066962dc21ceae05d2b189fe22391b556887eab2cc1800e1e80"
|
||||
WORKFLOW_SHA256 = "26bbca92b5f7cac4cbde89290b3f801b7a895df76a07493ca6f65c18d5b1154a"
|
||||
ZIP_SHA256 = "df4e0e355020d2e731932cff86a4b00932b4f193ec7ed513be0db994ec0e71bb"
|
||||
ZIP_WORKFLOW_NAME = "MiniMax_H3_Continuum_V38x.json"
|
||||
EXTERNAL_PACKAGES = {
|
||||
"comfyui-spectrum-minimax-h3",
|
||||
"rgthree-comfy",
|
||||
"comfyui-kjnodes",
|
||||
"comfyui-easy-use",
|
||||
}
|
||||
|
||||
|
||||
@@ -53,8 +53,8 @@ def _graph(workflow: dict) -> tuple[dict[int, dict], dict[int, list]]:
|
||||
|
||||
def test_v38_public_workflow_declares_external_dependencies_and_is_reloadable():
|
||||
workflow = _workflow()
|
||||
assert len(workflow["nodes"]) == 32
|
||||
assert len(workflow["links"]) == 38
|
||||
assert len(workflow["nodes"]) == 30
|
||||
assert len(workflow["links"]) == 36
|
||||
packages = {
|
||||
node.get("properties", {}).get("cnr_id") for node in workflow["nodes"]
|
||||
} - {None, "", "comfy-core"}
|
||||
@@ -62,7 +62,7 @@ def test_v38_public_workflow_declares_external_dependencies_and_is_reloadable():
|
||||
node_types = {node["type"] for node in workflow["nodes"]}
|
||||
assert {
|
||||
"SpectrumApplyMiniMaxH3", "Power Lora Loader (rgthree)",
|
||||
"Fast Groups Bypasser (rgthree)", "easy cleanGpuUsed",
|
||||
"Fast Groups Bypasser (rgthree)",
|
||||
"MiniMaxH3MemoryEfficientSageAttentionPatch",
|
||||
} <= node_types
|
||||
assert not any("hires" in name.lower() for name in node_types)
|
||||
@@ -78,9 +78,9 @@ def test_v38_public_workflow_and_zip_preserve_supplied_bytes():
|
||||
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.namelist() == [ZIP_WORKFLOW_NAME]
|
||||
assert archive.testzip() is None
|
||||
assert archive.read(WORKFLOW_PATH.name) == payload
|
||||
assert archive.read(ZIP_WORKFLOW_NAME) == payload
|
||||
|
||||
|
||||
def test_v38_public_workflow_preserves_sampler_widget_positions():
|
||||
@@ -128,11 +128,11 @@ def test_v38_public_workflow_preserves_sampler_widget_positions():
|
||||
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"]["width"] == 448
|
||||
assert sampler["widgets_values_named"]["height"] == 672
|
||||
assert sampler["widgets_values_named"]["chunks"] == 1
|
||||
assert sampler["widgets_values_named"]["chunk_seconds"] == 10
|
||||
assert sampler["widgets_values_named"]["control_after_generate"] == "randomize"
|
||||
assert sampler["widgets_values_named"]["continuation_backend"] == "Standard"
|
||||
|
||||
|
||||
@@ -167,18 +167,18 @@ def test_v38_public_workflow_keeps_required_and_optional_connections():
|
||||
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_types["first_frame"] == "H3EasyLoadImage"
|
||||
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["reference_image_1"] == 4
|
||||
assert source_modes["reference_image_2"] == 4
|
||||
assert source_modes["reference_image_3"] == 4
|
||||
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():
|
||||
def test_v38_public_workflow_preserves_accelerator_defaults_and_model_chain():
|
||||
workflow = _workflow()
|
||||
nodes, links = _graph(workflow)
|
||||
|
||||
@@ -189,7 +189,7 @@ def test_v38_public_workflow_preserves_spectrum_default_and_model_chain():
|
||||
sampler = _one_node(workflow, "H3ContinuumSamplerV38")
|
||||
spectrum = source(sampler, "model")
|
||||
assert spectrum["type"] == "SpectrumApplyMiniMaxH3"
|
||||
assert spectrum["widgets_values"][0] is True
|
||||
assert spectrum["widgets_values"][0] is False
|
||||
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]
|
||||
@@ -208,11 +208,9 @@ 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_link = links[int(save["inputs"][0]["link"])]
|
||||
create = nodes[int(create_link[1])]
|
||||
assert create["type"] == "CreateVideo"
|
||||
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
|
||||
|
||||
@@ -475,18 +475,18 @@ def test_cache_flag_is_not_part_of_run_storage_or_public_workflow_identity():
|
||||
encoding="utf-8"
|
||||
)
|
||||
assert "reference_encode_cache" not in (
|
||||
ROOT / "examples" / "workflows" / "MiniMax_H3_Continuum_V38.json"
|
||||
ROOT / "examples" / "workflows" / "MiniMax_H3_Continuum_V38x.json"
|
||||
).read_text(encoding="utf-8")
|
||||
|
||||
|
||||
def test_full_reuse_skips_cache_and_partial_regenerate_enters_cached_encode_stage():
|
||||
def test_encode_stage_is_required_for_new_groups_or_refine_context_reconstruction():
|
||||
source = (ROOT / "v2" / "sequence.py").read_text(encoding="utf-8")
|
||||
partial_regenerate_guard = source.index("if len(preserved)<chunks:")
|
||||
planner = source.index("execution_plan=build_execution_plan(")
|
||||
partial_regenerate_guard = source.index("if len(preserved)<chunks or capture_refine_context:")
|
||||
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
|
||||
assert planner < partial_regenerate_guard < image
|
||||
assert planner < partial_regenerate_guard < audio
|
||||
assert planner < partial_regenerate_guard < video
|
||||
|
||||
@@ -23,6 +23,7 @@ from ComfyUI_H3_Continuum_Join.v3.driving_nodes import (
|
||||
from ComfyUI_H3_Continuum_Join.v3.nodes import (
|
||||
H3ContinuumSamplerProduction,
|
||||
H3ContinuumSamplerV3,
|
||||
_apply_review_decode_scope,
|
||||
)
|
||||
from ComfyUI_H3_Continuum_Join.v3.plan import prepare_physical_decode_entries
|
||||
|
||||
@@ -502,8 +503,8 @@ class _CommitRecorder:
|
||||
self.prepare_kwargs = kwargs
|
||||
return None
|
||||
|
||||
def commit_chunk(self, entry, *, position):
|
||||
self.timeline.append(("commit", position))
|
||||
def commit_group(self, entries, *, positions):
|
||||
self.timeline.append(("commit_group", tuple(positions)))
|
||||
|
||||
def mark_review_group(self, *, start, end, physical_group):
|
||||
self.review_groups.append((start, end, physical_group))
|
||||
@@ -562,8 +563,8 @@ def test_normal_group_stops_only_after_commit(monkeypatch):
|
||||
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 [event[0] for event in timeline] == ["sample", "commit_group"]
|
||||
assert timeline[-1] == ("commit_group", (0,))
|
||||
assert "max_new_physical_groups" not in storage.prepare_kwargs
|
||||
|
||||
|
||||
@@ -589,12 +590,56 @@ def test_terminal_group_counts_once_after_both_logical_commits(monkeypatch):
|
||||
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 [event[0] for event in timeline] == ["sample", "commit_group"]
|
||||
assert timeline[-1] == ("commit_group", (0, 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_terminal_retry_scope_keeps_the_physical_pair_together(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,
|
||||
)
|
||||
outputs = _run_v3_node(
|
||||
runtime,
|
||||
chunks=3,
|
||||
first_frame=first,
|
||||
last_frame=last,
|
||||
)
|
||||
storage = SimpleNamespace(
|
||||
review_generation_mode="Review Each Chunk",
|
||||
review_execution=SimpleNamespace(
|
||||
finish_remaining=False,
|
||||
next_review_unit_start=2,
|
||||
next_review_unit_end=3,
|
||||
partial_review=False,
|
||||
smart_regenerate=True,
|
||||
),
|
||||
)
|
||||
|
||||
scoped = _apply_review_decode_scope(
|
||||
outputs,
|
||||
storage=storage,
|
||||
capture_refine_context=False,
|
||||
configured_chunks=3,
|
||||
chunk_seconds=5.0,
|
||||
first_frame=first,
|
||||
last_frame=last,
|
||||
timeline_video_source=None,
|
||||
)
|
||||
|
||||
assert len(scoped[0]) == len(scoped[1]) == 1
|
||||
assert scoped[2]["logical_chunk_count"] == 2
|
||||
assert scoped[2]["physical_decode_group_count"] == 1
|
||||
assert scoped[2]["decode_groups"][0]["logical_chunk_indices"] == [2, 3]
|
||||
assert len(scoped[3]["session"]["chunks"]) == 3
|
||||
assert scoped[3]["report"].endswith("Decode preview: Chunks 2-3")
|
||||
|
||||
|
||||
def test_partial_refine_context_is_explicitly_incomplete(monkeypatch):
|
||||
runtime = _install_fake_runtime(monkeypatch)
|
||||
entries, _, session, report, refine_context = _run_sequence(
|
||||
|
||||
@@ -21,12 +21,21 @@ from ComfyUI_H3_Continuum_Join.run_storage import (
|
||||
from ComfyUI_H3_Continuum_Join.branch_provenance import (
|
||||
TAKE_ACTION_CONTINUE,
|
||||
TAKE_ACTION_USE,
|
||||
physical_groups,
|
||||
)
|
||||
from ComfyUI_H3_Continuum_Join.state import make_plan
|
||||
from ComfyUI_H3_Continuum_Join.v2.seeds import derive_chunk_seed
|
||||
from ComfyUI_H3_Continuum_Join.v2.session import make_chunk_entry
|
||||
from ComfyUI_H3_Continuum_Join.v3.nodes import H3ContinuumSamplerProduction
|
||||
from ComfyUI_H3_Continuum_Join.v3.nodes import H3ContinuumSamplerV3
|
||||
from ComfyUI_H3_Continuum_Join.v3.nodes import (
|
||||
H3ContinuumSamplerProduction,
|
||||
H3ContinuumSamplerV3,
|
||||
PROJECTION_CURRENT_REVIEW_UNIT,
|
||||
PROJECTION_FULL_ACCEPTED_PREFIX,
|
||||
_apply_review_decode_scope,
|
||||
_review_decode_chunk_range,
|
||||
resolve_projection_decision,
|
||||
)
|
||||
from ComfyUI_H3_Continuum_Join.v3.plan import prepare_physical_decode_entries
|
||||
from ComfyUI_H3_Continuum_Join.v3.review_control import (
|
||||
GENERATION_MODE_FULL_RUN,
|
||||
GENERATION_MODE_REVIEW,
|
||||
@@ -186,11 +195,23 @@ def _persist(
|
||||
updated_utc: str,
|
||||
) -> RunStorageController:
|
||||
controller = _controller(tmp_path, contract)
|
||||
entries = []
|
||||
for position in range(prefix):
|
||||
entry = _entry(position, contract)
|
||||
entries.append(entry)
|
||||
controller.commit_chunk(entry, position=position)
|
||||
entries = [_entry(position, contract) for position in range(prefix)]
|
||||
terminal = bool(
|
||||
((contract.get("global") or {}).get("execution_semantics") or {}).get(
|
||||
"flf_execution"
|
||||
) == "terminal_merged_10s_seed_v2"
|
||||
)
|
||||
for group in physical_groups(
|
||||
chunks=int(contract["chunk_count"]),
|
||||
terminal_merge_enabled=terminal,
|
||||
):
|
||||
if group.end > prefix:
|
||||
break
|
||||
positions = tuple(range(group.start - 1, group.end))
|
||||
controller.commit_group(
|
||||
tuple(entries[position] for position in positions),
|
||||
positions=positions,
|
||||
)
|
||||
if review_unit is not None:
|
||||
start, end = review_unit
|
||||
controller.review_generation_mode = GENERATION_MODE_REVIEW
|
||||
@@ -1225,6 +1246,220 @@ def test_production_internal_review_configures_storage_and_finalizes_metadata(
|
||||
assert "review status" in outputs[3]
|
||||
|
||||
|
||||
def test_production_uses_reconciled_review_unit_for_decode_scope(monkeypatch):
|
||||
import ComfyUI_H3_Continuum_Join.run_storage as run_storage
|
||||
|
||||
contract = _contract(chunks=3)
|
||||
entries = [_entry(position, contract) for position in range(3)]
|
||||
full_decode, full_plan = prepare_physical_decode_entries(
|
||||
entries,
|
||||
chunk_seconds=5.0,
|
||||
preserve_final_frame=False,
|
||||
terminal_merged=False,
|
||||
)
|
||||
|
||||
class _Storage:
|
||||
review_generation_mode = None
|
||||
review_execution = None
|
||||
finalized = None
|
||||
|
||||
def __enter__(self):
|
||||
return self
|
||||
|
||||
def __exit__(self, exc_type, exc, traceback):
|
||||
return False
|
||||
|
||||
def configure_review(self, **kwargs):
|
||||
self.review_generation_mode = kwargs["generation_mode"]
|
||||
|
||||
def summary(self, *, detailed=False):
|
||||
return "storage summary"
|
||||
|
||||
def review_pause_metadata(self):
|
||||
return {
|
||||
"review_unit": {"start": 2, "end": 2, "physical_group": 2},
|
||||
"review_pause_reason": "review_each_chunk",
|
||||
}
|
||||
|
||||
def finalize(self, **kwargs):
|
||||
self.finalized = kwargs
|
||||
|
||||
storage = _Storage()
|
||||
monkeypatch.setattr(run_storage, "run_storage_scope", lambda *a, **k: storage)
|
||||
monkeypatch.setattr(run_storage, "automatic_project_key", lambda *a, **k: "key")
|
||||
|
||||
def fake_v3_run(self, **kwargs):
|
||||
storage.review_execution = SimpleNamespace(
|
||||
status_hint="review status",
|
||||
finish_remaining=False,
|
||||
next_review_unit_start=2,
|
||||
next_review_unit_end=2,
|
||||
partial_review=True,
|
||||
smart_regenerate=False,
|
||||
)
|
||||
return (
|
||||
[{"samples": entry["video"]} for entry in full_decode],
|
||||
[{"samples": entry["audio"]} for entry in full_decode],
|
||||
full_plan,
|
||||
{
|
||||
"last_state": {},
|
||||
"session": {"session_id": "session", "chunks": entries},
|
||||
"report": "sampling report",
|
||||
},
|
||||
)
|
||||
|
||||
monkeypatch.setattr(H3ContinuumSamplerV3, "run", fake_v3_run)
|
||||
kwargs = _production_kwargs()
|
||||
kwargs["chunks"] = 3
|
||||
outputs = H3ContinuumSamplerProduction().run(**kwargs)
|
||||
|
||||
assert len(outputs[0]) == len(outputs[1]) == 1
|
||||
assert torch.equal(outputs[0][0]["samples"], entries[1]["video"])
|
||||
assert outputs[2]["target_frames"] == 120
|
||||
assert outputs[2]["chunks"][0]["chunk_index"] == 2
|
||||
assert len(storage.finalized["session"]["chunks"]) == 3
|
||||
assert "Decode preview: Chunk 2" in outputs[3]
|
||||
|
||||
|
||||
def test_review_decode_range_only_selects_a_current_review_unit():
|
||||
execution = SimpleNamespace(
|
||||
finish_remaining=False,
|
||||
next_review_unit_start=2,
|
||||
next_review_unit_end=2,
|
||||
partial_review=True,
|
||||
smart_regenerate=False,
|
||||
)
|
||||
storage = SimpleNamespace(
|
||||
review_generation_mode=GENERATION_MODE_REVIEW,
|
||||
review_execution=execution,
|
||||
)
|
||||
assert _review_decode_chunk_range(
|
||||
storage,
|
||||
capture_refine_context=False,
|
||||
) == (2, 2)
|
||||
assert _review_decode_chunk_range(
|
||||
storage,
|
||||
capture_refine_context=True,
|
||||
) == (2, 2)
|
||||
|
||||
execution.partial_review = False
|
||||
assert _review_decode_chunk_range(
|
||||
storage,
|
||||
capture_refine_context=False,
|
||||
) is None
|
||||
execution.smart_regenerate = True
|
||||
assert _review_decode_chunk_range(
|
||||
storage,
|
||||
capture_refine_context=False,
|
||||
) == (2, 2)
|
||||
execution.finish_remaining = True
|
||||
assert _review_decode_chunk_range(
|
||||
storage,
|
||||
capture_refine_context=False,
|
||||
) is None
|
||||
|
||||
|
||||
def test_projection_decision_is_pure_and_refuses_to_split_physical_groups():
|
||||
session = {"chunks": [{}, {}, {}]}
|
||||
execution = SimpleNamespace(
|
||||
finish_remaining=False,
|
||||
next_review_unit_start=2,
|
||||
next_review_unit_end=3,
|
||||
partial_review=False,
|
||||
smart_regenerate=True,
|
||||
)
|
||||
|
||||
decision = resolve_projection_decision(
|
||||
review_execution=execution,
|
||||
effective_result_status=REVISION_STATUS_REVIEW_READY,
|
||||
session=session,
|
||||
physical_group_facts=((1,), (2, 3)),
|
||||
)
|
||||
assert decision.kind == PROJECTION_CURRENT_REVIEW_UNIT
|
||||
assert (decision.start_chunk, decision.end_chunk) == (2, 3)
|
||||
|
||||
split_terminal_group = resolve_projection_decision(
|
||||
review_execution=SimpleNamespace(
|
||||
finish_remaining=False,
|
||||
next_review_unit_start=2,
|
||||
next_review_unit_end=2,
|
||||
partial_review=True,
|
||||
smart_regenerate=False,
|
||||
),
|
||||
effective_result_status=REVISION_STATUS_REVIEW_READY,
|
||||
session=session,
|
||||
physical_group_facts=((1,), (2, 3)),
|
||||
)
|
||||
assert split_terminal_group.kind == PROJECTION_FULL_ACCEPTED_PREFIX
|
||||
|
||||
complete = resolve_projection_decision(
|
||||
review_execution=execution,
|
||||
effective_result_status=REVISION_STATUS_COMPLETE,
|
||||
session=session,
|
||||
physical_group_facts=((1,), (2, 3)),
|
||||
)
|
||||
assert complete.kind == PROJECTION_FULL_ACCEPTED_PREFIX
|
||||
|
||||
|
||||
def test_partial_review_rebuilds_decode_outputs_without_truncating_session():
|
||||
contract = _contract(chunks=3)
|
||||
entries = [_entry(position, contract) for position in range(3)]
|
||||
full_decode, full_plan = prepare_physical_decode_entries(
|
||||
entries,
|
||||
chunk_seconds=5.0,
|
||||
preserve_final_frame=False,
|
||||
terminal_merged=False,
|
||||
)
|
||||
result = {
|
||||
"last_state": {},
|
||||
"session": {"session_id": "session", "chunks": entries},
|
||||
"report": "sampling report",
|
||||
}
|
||||
outputs = (
|
||||
[{"samples": entry["video"]} for entry in full_decode],
|
||||
[{"samples": entry["audio"]} for entry in full_decode],
|
||||
full_plan,
|
||||
result,
|
||||
{"full_refine_context": True},
|
||||
)
|
||||
refine_context = outputs[4]
|
||||
storage = SimpleNamespace(
|
||||
review_generation_mode=GENERATION_MODE_REVIEW,
|
||||
review_execution=SimpleNamespace(
|
||||
finish_remaining=False,
|
||||
next_review_unit_start=2,
|
||||
next_review_unit_end=2,
|
||||
partial_review=True,
|
||||
smart_regenerate=False,
|
||||
),
|
||||
)
|
||||
|
||||
scoped = _apply_review_decode_scope(
|
||||
outputs,
|
||||
storage=storage,
|
||||
capture_refine_context=True,
|
||||
configured_chunks=3,
|
||||
chunk_seconds=5.0,
|
||||
first_frame=None,
|
||||
last_frame=None,
|
||||
timeline_video_source=None,
|
||||
)
|
||||
|
||||
assert len(scoped[0]) == len(scoped[1]) == 1
|
||||
assert torch.equal(scoped[0][0]["samples"], entries[1]["video"])
|
||||
assert torch.equal(scoped[1][0]["samples"], entries[1]["audio"])
|
||||
assert scoped[2]["target_frames"] == 120
|
||||
assert scoped[2]["chunks"][0]["sequence_index"] == 1
|
||||
assert scoped[2]["chunks"][0]["chunk_index"] == 2
|
||||
assert scoped[2]["second_pass_contract"]["physical_groups"][0][
|
||||
"logical_chunks"
|
||||
] == [2]
|
||||
assert len(scoped[3]["session"]["chunks"]) == 3
|
||||
assert scoped[3]["session"] is result["session"]
|
||||
assert scoped[3]["report"].endswith("Decode preview: Chunk 2")
|
||||
assert scoped[4] is refine_context
|
||||
|
||||
|
||||
def test_production_review_mode_rejects_run_storage_off():
|
||||
kwargs = _production_kwargs()
|
||||
kwargs["run_storage"] = "Off"
|
||||
|
||||
@@ -260,12 +260,14 @@ def test_f0_f7_frontend_review_lifecycle(review_queue_results):
|
||||
):
|
||||
assert review_queue_results[case]["pass"]
|
||||
|
||||
def test_frontend_uses_scoped_acceptance_adapter_without_app_queue_override():
|
||||
def test_api_queue_adapter_is_the_single_v38_review_intent_owner():
|
||||
source = PROJECT_ID_JS.read_text(encoding="utf-8")
|
||||
assert "actionWidget.afterQueued = function" in source
|
||||
assert "prepareReviewQueueIntent(node, apiNode.inputs);" in source
|
||||
assert "const inputs = buildReviewQueueInputs(node, normalizedInputs);" in source
|
||||
assert "prepareReviewQueueIntent" not in source
|
||||
assert "normalizeReviewActionOnLoad(node);" in source
|
||||
assert "app.queuePrompt =" not in source
|
||||
assert "api.queuePrompt = async function" in source
|
||||
assert "api.__h3ContinuumReviewQueueAdapter" in source
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user