fix: preserve loader state and migrate audio/video workflow inputs

Refs #23. Keep Image Enable, delegate Core mode accessors, and remove widget-array mutation. Use Core Audio and Core Video with an Enable-free FPS adapter. Legacy loader IDs remain compatible. Focused CPU tests pass; Windows/browser acceptance remains pending.
This commit is contained in:
github-actions[bot]
2026-09-21 03:45:54 +00:00
parent 3d7c2fd692
commit f8eb40d8b4
27 changed files with 576 additions and 316 deletions
+2 -2
View File
@@ -164,7 +164,7 @@ console.log(JSON.stringify({{ initial, off, onAgain, externalBypass, reloaded }}
observed = json.loads(result.stdout)
assert observed == {
"initial": {
"names": ["Enable Audio", "audio", "audioUI"],
"names": ["audio", "audioUI", "Enable Audio"],
"saved": {
"mode": 0,
"widgets_values": [
@@ -201,7 +201,7 @@ console.log(JSON.stringify({{ initial, off, onAgain, externalBypass, reloaded }}
"toggle": False,
"audio": "reloaded.wav",
"player": {"position": 2.5, "volume": 0.6},
"names": ["Enable Audio", "audio", "audioUI"],
"names": ["audio", "audioUI", "Enable Audio"],
},
}
+9 -40
View File
@@ -150,7 +150,7 @@ console.log(JSON.stringify({{ initial, toggledOff, externalUnbypass, externalByp
observed = json.loads(result.stdout)
assert observed == {
"initial": {
"names": ["Enable Image", "image", "upload"],
"names": ["image", "upload", "Enable Image"],
"toggle": True,
"saved": {"mode": 0, "widgets_values": ["first.png", "image"]},
},
@@ -166,12 +166,12 @@ console.log(JSON.stringify({{ initial, toggledOff, externalUnbypass, externalByp
"toggle": False,
"image": "reloaded.png",
"upload": "image",
"names": ["Enable Image", "image", "upload"],
"names": ["image", "upload", "Enable Image"],
},
}
def test_shared_bypass_helper_redraws_only_enable_row_at_full_opacity(tmp_path):
def test_shared_bypass_helper_preserves_core_widget_collection_when_drawing(tmp_path):
node_executable = shutil.which("node")
if node_executable is None:
pytest.skip("Node.js is required for the frontend drawing regression")
@@ -246,47 +246,16 @@ console.log(JSON.stringify({{
text=True,
)
observed = json.loads(result.stdout)
assert observed == {
"image": {
"bypassCalls": [
{"names": ["Enable Image", "file"], "alpha": 0.2},
{"names": ["Enable Image"], "alpha": 1},
],
"enabledCalls": [
{"names": ["Enable Image", "file"], "alpha": 1}
],
for kind, result in observed.items():
names = ["enable_video", "file"] if kind == "video" else ["file", f"Enable {kind.title()}"]
assert result == {
"bypassCalls": [{"names": names, "alpha": 0.2}],
"enabledCalls": [{"names": names, "alpha": 1}],
"mode": 0,
"toggle": True,
"clickable": True,
"visible": True,
},
"audio": {
"bypassCalls": [
{"names": ["Enable Audio", "file"], "alpha": 0.2},
{"names": ["Enable Audio"], "alpha": 1},
],
"enabledCalls": [
{"names": ["Enable Audio", "file"], "alpha": 1}
],
"mode": 0,
"toggle": True,
"clickable": True,
"visible": True,
},
"video": {
"bypassCalls": [
{"names": ["enable_video", "file"], "alpha": 0.2},
{"names": ["enable_video"], "alpha": 1},
],
"enabledCalls": [
{"names": ["enable_video", "file"], "alpha": 1}
],
"mode": 0,
"toggle": True,
"clickable": True,
"visible": True,
},
}
}
def test_easy_load_image_frontend_has_no_backend_boolean_or_polling():
+4 -4
View File
@@ -332,12 +332,12 @@ console.log(JSON.stringify({{ initial, enabled, externalBypass, externalUnbypass
}
def test_video_bypass_appearance_uses_native_mode_without_hardcoded_color():
def test_legacy_video_has_no_frontend_enable_bridge():
source = FRONTEND_PATH.read_text(encoding="utf-8")
common = COMMON_FRONTEND_PATH.read_text(encoding="utf-8")
assert 'from "./easy_bypass_toggle.js"' in source
assert "configureExistingEasyBypassWidgetNode" in source
assert 'widgetNames: ["enable_video", "Enable Video"]' in source
assert 'from "./easy_bypass_toggle.js"' not in source
assert "configureExistingEasyBypassWidgetNode" not in source
assert 'widgetNames: ["enable_video", "Enable Video"]' not in source
assert "NODE_MODE_BYPASS" in common
assert "node.color" not in source
assert "node.bgcolor" not in source
+116
View File
@@ -0,0 +1,116 @@
"""Regressions for Core's prototype mode accessor and stable widgets view.
This models the persistence boundary; it is not a real-browser acceptance test.
"""
from __future__ import annotations
import json
from pathlib import Path
import shutil
import subprocess
import pytest
ROOT = Path(__file__).resolve().parents[1]
@pytest.mark.parametrize("store_backed", [False, True], ids=["legacy", "store"])
@pytest.mark.parametrize("kind", ["image", "audio", "video"])
def test_loader_state_survives_draw_save_and_workflow_roundtrip(tmp_path, kind, store_backed):
node = shutil.which("node")
if node is None:
pytest.skip("Node.js is required for frontend regression tests")
source = (ROOT / "web/easy_bypass_toggle.js").read_text(encoding="utf-8").replace("export ", "")
script = source + "\n" + r'''
const storeBacked = STORE_BACKED;
const kind = KIND;
const nodeClass = {image: "H3EasyLoadImage", audio: "H3EasyLoadAudio", video: "H3ContinuumLoadVideo"}[kind];
const enableName = {image: "Enable Image", audio: "Enable Audio", video: "enable_video"}[kind];
const fileName = {image: "image", audio: "audio", video: "file"}[kind];
const selectedFile = {image: "selected-b.png", audio: "selected-b.wav", video: "selected-b.mp4"}[kind];
function plainWidget(name, value) { return {name, value, options: {}, serialize: true}; }
class StoreNode {
constructor() {
this.comfyClass = nodeClass;
this._state = {mode: 0};
this.drawCalls = 0;
const widgets = [];
// Like Core widgetsView: assignment mutates the same array/view.
Object.defineProperty(this, "widgets", {
configurable: true,
get() { return widgets; },
set(value) { widgets.splice(0, widgets.length, ...value); },
});
if (!storeBacked) {
Object.defineProperty(this, "mode", {value: 0, writable: true, configurable: true});
Object.defineProperty(this, "widgets", {value: [], writable: true, configurable: true});
}
if (kind === "video") this.widgets.push(plainWidget(enableName, true));
this.widgets.push(plainWidget(fileName, "default-file"));
if (kind === "video") this.widgets.push(plainWidget("force_rate", 30));
}
get mode() { return this._state.mode; }
set mode(value) { this._state.mode = value; }
setDirtyCanvas() {}
addWidget(type, name, value, callback, options) {
const w = {type, name, value, callback, options}; this.widgets.push(w); return w;
}
drawWidgets() { this.drawCalls++; }
serializeFromStoreState(state) {
const ws = this.widgets.filter(w => w.serialize !== false);
return {mode: state.mode, widgets_values: ws.map(w => w.value),
widgets_values_named: Object.fromEntries(ws.map(w => [w.name, w.value]))};
}
serialize() { return this.serializeFromStoreState(storeBacked ? this._state : {mode:this.mode}); }
configure(info) {
this.mode = info.mode;
for (const w of this.widgets) {
if (w.serialize !== false && Object.hasOwn(info.widgets_values_named, w.name))
w.value = info.widgets_values_named[w.name];
}
}
}
function configure(n) {
if (kind === "video") configureExistingEasyBypassWidgetNode(n, {nodeClass, widgetNames:[enableName]});
else configureEasyBypassToggleNode(n, {nodeClass, widgetName:enableName, tooltip:"test"});
}
function saveGraph(n) {
// Core 1.53 may bypass node.serialize() and use the store directly.
return storeBacked ? n.serializeFromStoreState(n._state) : n.serialize();
}
const a = new StoreNode(); configure(a); configure(a);
a.widgets.find(w => w.name === fileName).value = selectedFile;
findEasyBypassWidget(a).callback(false);
const beforeDraw = a.widgets.map(w => w.name);
for (let i=0; i<4; i++) a.drawWidgets({}, {editorAlpha:0.2});
const afterDraw = a.widgets.map(w => w.name);
const saved = saveGraph(a);
const b = new StoreNode(); configure(b); b.configure(saved); configure(b);
const reopened = saveGraph(b);
b.mode = 0;
const externalOn = findEasyBypassWidget(b).value;
b.mode = 4;
const externalOff = findEasyBypassWidget(b).value;
console.log(JSON.stringify({beforeDraw, afterDraw, liveMode:a.mode, storeMode:a._state.mode,
saved, reopened, reopenedEnable:findEasyBypassWidget(b).value, externalOn, externalOff,
selectedFile, fileName, kind, drawCalls:a.drawCalls}));
'''
script = script.replace("STORE_BACKED", str(store_backed).lower()).replace("KIND", json.dumps(kind))
file = tmp_path / "loader-store.js"
file.write_text(script, encoding="utf-8")
result = subprocess.run([node, str(file)], capture_output=True, text=True, check=True)
observed = json.loads(result.stdout)
assert observed["beforeDraw"] == observed["afterDraw"], observed
assert observed["liveMode"] == observed["saved"]["mode"] == 4, observed
if store_backed:
assert observed["storeMode"] == 4, observed
assert observed["saved"]["widgets_values_named"][observed["fileName"]] == observed["selectedFile"]
if kind == "video":
assert observed["saved"]["widgets_values_named"]["force_rate"] == 30
assert observed["saved"]["widgets_values_named"]["enable_video"] is False
else:
assert not any(name.startswith("Enable") for name in observed["saved"]["widgets_values_named"])
assert observed["reopened"] == observed["saved"]
assert observed["reopenedEnable"] is False
assert observed["externalOn"] is True
assert observed["externalOff"] is False
+2 -1
View File
@@ -22,13 +22,14 @@ PUBLIC_DISPLAY_NAMES = {
"H3EasyLoadImage": "H3 Continuum Load Image",
"H3EasyLoadAudio": "H3 Continuum Load Audio",
"H3ContinuumLoadVideo": "H3 Continuum Load Video",
"H3ContinuumVideoAdapter": "H3 Continuum Video Adapter",
"H3ContinuumSecondPassV35": "H3 Continuum Second Pass",
"H3ContinuumReferenceImages": "H3 Continuum Reference Images",
"H3DecodeCacheHelper": "Decode Cache Helper",
}
def test_public_export_is_exactly_the_v38x2_nine_node_allowlist():
def test_public_export_keeps_legacy_loaders_and_adds_video_adapter():
assert set(root_nodes.NODE_CLASS_MAPPINGS) == set(PUBLIC_DISPLAY_NAMES)
assert root_nodes.NODE_DISPLAY_NAME_MAPPINGS == PUBLIC_DISPLAY_NAMES
+29 -5
View File
@@ -9,9 +9,9 @@ from zipfile import ZipFile
ROOT = Path(__file__).resolve().parents[1]
WORKFLOW_PATH = ROOT / "examples" / "workflows" / "MiniMax_H3_Continuum_V38X2.json"
# User-approved final distribution. Do not sanitize or reserialize this graph.
WORKFLOW_SHA256 = "6c445d62979632bc1a801b1c28dbd639c23b51cc156ebae18837baaa757e592b"
ZIP_SHA256 = "29e8ea19cf7c7e8a8a5e98577905d8fd01fc800bb8edb4f4218a638fe39e69d0"
# User-approved loader migration (2026-09-21); non-loader graph values are protected.
WORKFLOW_SHA256 = "1b2212b7511fac0b63dfa6e9f006cd8644c72d08c6945ab0e4ed0e722c97a730"
ZIP_SHA256 = "8f839a955859bffa0d9cf0b15e91ee484dd911aca5ae31f1787debd56afdc7da"
ZIP_WORKFLOW_NAME = "MiniMax_H3_Continuum_V38X2.json"
EXTERNAL_PACKAGES = {
"comfyui-spectrum-minimax-h3",
@@ -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"]) == 33
assert len(workflow["links"]) == 39
packages = {
node.get("properties", {}).get("cnr_id") for node in workflow["nodes"]
} - {None, "", "comfy-core"}
@@ -243,3 +243,27 @@ def test_v38x2_public_workflow_keeps_helper_finalize_create_save_chain():
"audio_samples": "H3ContinuumSamplerV38",
"audio_vae": "VAELoader",
}
def test_current_workflow_uses_core_audio_and_enable_free_video_adapter():
workflow = _workflow()
nodes, links = _graph(workflow)
types = {node["type"] for node in workflow["nodes"]}
assert "H3EasyLoadAudio" not in types
assert "H3ContinuumLoadVideo" not in types
audio = _one_node(workflow, "LoadAudio")
video = _one_node(workflow, "LoadVideo")
adapter = _one_node(workflow, "H3ContinuumVideoAdapter")
for core, title in ((audio, "Load Audio"), (video, "Load Video")):
assert core.get("title", title) == title
assert core["properties"]["cnr_id"] == "comfy-core"
assert core["mode"] == 4
assert audio["widgets_values_named"]["audio"] == "prnas_.mp3"
assert video["widgets_values_named"]["file"] == "MiniMax_H3_00001_.mp4"
assert adapter["widgets_values_named"] == {"force_rate": 24}
assert adapter["widgets_values"] == [24]
assert adapter["mode"] == 4
assert links[adapter["inputs"][0]["link"]][1:3] == [video["id"], 0]
sampler = _one_node(workflow, "H3ContinuumSamplerV38")
guide = next(x for x in sampler["inputs"] if x["name"] == "reference_video_1")
assert nodes[links[guide["link"]][1]]["type"] == "H3ContinuumVideoAdapter"
+49
View File
@@ -0,0 +1,49 @@
from __future__ import annotations
from fractions import Fraction
from types import SimpleNamespace
import pytest
import torch
from ComfyUI_H3_Continuum_Join import nodes as root_nodes
from ComfyUI_H3_Continuum_Join.v3.easy_video_nodes import ExecutionBlocker, _resample_video_frames
from ComfyUI_H3_Continuum_Join.v3.video_adapter_nodes import H3ContinuumVideoAdapter
def _outputs(output):
return output.args if hasattr(output, "args") else output.result
def test_video_adapter_is_registered_without_file_upload_or_enable():
assert root_nodes.NODE_CLASS_MAPPINGS["H3ContinuumVideoAdapter"] is H3ContinuumVideoAdapter
schema = H3ContinuumVideoAdapter.define_schema()
assert [x.id for x in schema.inputs] == ["video", "force_rate"]
assert schema.inputs[1].default == 24.0
assert len(schema.outputs) == 2
@pytest.mark.parametrize("source_rate,count", [(Fraction(24),240), (Fraction(30),300), (Fraction(30000,1001),300)])
def test_adapter_keeps_existing_resampling_and_exact_audio(source_rate, count):
images = torch.arange(count, dtype=torch.float32).view(count, 1, 1, 1).expand(-1, 2, 2, 3).clone()
audio = {"waveform": torch.arange(64, dtype=torch.float32).reshape(1, 1, 64), "sample_rate":32000}
calls = []
class Video:
def get_components(self):
calls.append(True)
return SimpleNamespace(images=images, audio=audio, frame_rate=source_rate)
output_images, output_audio = _outputs(H3ContinuumVideoAdapter.execute(Video(), 24.0))
assert len(calls) == 1
assert torch.equal(output_images, _resample_video_frames(images, source_rate, 24.0))
assert output_images.shape[0] == 240
assert output_audio is audio
if source_rate == 24:
assert output_images is images
def test_adapter_source_rate_and_silent_video_contract():
images = torch.zeros(30, 2, 2, 3)
video = SimpleNamespace(get_components=lambda: SimpleNamespace(images=images, audio=None, frame_rate=Fraction(30)))
out_images, audio = _outputs(H3ContinuumVideoAdapter.execute(video, 0))
assert out_images is images
assert isinstance(audio, ExecutionBlocker)