Fix V3.5 Reference Audio workflow compatibility

This commit is contained in:
ukr8b3g-cmyk
2026-08-25 03:01:33 +09:00
parent d6671cb6b3
commit 4ce4829477
4 changed files with 132 additions and 353 deletions
+3 -3
View File
@@ -117,7 +117,7 @@ eb5b27f8f0d79529c56ef344a5601703642c3cba5388c9768116223e2ed58a36 tests/test_v3_
3af78ab85c8e19dee8d0a98bfd11a2c0e88c30d87256da1f9699c49a19a684e9 tests/test_v32_reference.py
72719bcd6686d84f518d80751e3754b875d34c2aa72e2183dfa05ac9158a9eb0 tests/test_v34_driving_audio.py
5003c5f5ce1a4b4c77deb47011431e4a15fe0cecaeb6d689e0d0878567c42f5a tests/test_v351_reference_audio.py
850858ce53943124bd01c8d80a2bd1ba8ce28a6de291619c851757257e758ab8 tests/test_v351_reference_audio_ui.py
8e6aff0d79d628044d8355be69b9fe04ed5e8f957539e686d3a81b6bc3a5dd06 tests/test_v351_reference_audio_ui.py
9cf7dfa6cceba0efb95b4900aacc1ddfbec86c0e1645209bbf4c7908337138da tests/test_v351_last_queued_seed_frontend.py
cf1ca6342a89e4cb02b398b32edbe91b6c1353535383e9f51d459466305a0114 tests/test_v35_conditioning_bridge.py
8b75c23dccfd1ac302596187f2fbbd1c9b71fddcb5e666aa4f9eedfd8b5b4b93 tests/test_v35_compact_ui_frontend.py
@@ -168,5 +168,5 @@ da5edf3b4392c41e12ef73a0cd21799be42a327b18bd5a6989447b75163dcab1 v3/second_pass
2f07ace1462644f0bee553827b3571535de4d0c2d9ef847bd9e0ca73a4eed5cb v3/video_seam.py
e981f75faff574b8e9ab3e9be8b68559e3e7a22f6220d3d073e7769f5fc0dc74 version.py
dac5dc14e432956c44e11cc672c3a7a050375e0fdae2f2b7a738da10ad23f837 web/last_queued_seed.js
9305b91d766a8a922f352c466829781bda38d8ce1f5c3c51e824649bebdce210 web/project_id.js
8fa2aeba8a7e963fa627c25f484c0d375fedfff18d62800e7e11663fc292472d web/reference_audio_ui.js
a8f3ec6309c6daeaec6a0f7fa4f1d6203fda93613fdcb899af35b553c0103086 web/project_id.js
3892ee8f98538d261ead86f711e0f32bc0999d944092c897d021599707b840ca web/reference_audio_ui.js
+122 -119
View File
@@ -10,18 +10,21 @@ PROJECT_ID_JS = ROOT / "web" / "project_id.js"
REFERENCE_AUDIO_UI_JS = ROOT / "web" / "reference_audio_ui.js"
def test_v35_wires_reference_audio_visibility_after_node_setup():
source = PROJECT_ID_JS.read_text(encoding="utf-8")
def test_v35_keeps_reference_audio_inputs_permanent_after_node_setup():
project_source = PROJECT_ID_JS.read_text(encoding="utf-8")
reference_source = REFERENCE_AUDIO_UI_JS.read_text(encoding="utf-8")
assert 'from "./reference_audio_ui.js";' in source
assert "if (node.comfyClass === V35_NODE_CLASS)" in source
assert "configureReferenceAudioInputs(node);" in source
assert "setTimeout(configureDeferred, 0);" in source
assert "node.__h3ContinuumLoadedGraphNode = true;" in source
assert "node.__h3ContinuumAfterConfigureGraph = true;" in source
assert 'import { normalizeReferenceAudioLabels } from "./reference_audio_ui.js";' in project_source
assert "normalizeReferenceAudioLabels(node);" in project_source
assert "configureReferenceAudioInputs" not in project_source
assert "Reference Audio Inputs" not in reference_source
assert "addInput" not in reference_source
assert "removeInput" not in reference_source
assert "addWidget" not in reference_source
assert "onSerialize" not in reference_source
def test_reference_audio_visibility_with_real_javascript_module(tmp_path):
def test_reference_audio_labels_do_not_change_inputs_or_widgets(tmp_path):
node = shutil.which("node")
assert node is not None, "Node.js is required for frontend behavior validation"
@@ -31,126 +34,126 @@ def test_reference_audio_visibility_with_real_javascript_module(tmp_path):
harness_path.write_text(
r'''
import assert from "node:assert/strict";
import { configureReferenceAudioInputs } from "./reference_audio_ui.mjs";
import { normalizeReferenceAudioLabels } from "./reference_audio_ui.mjs";
function makeNode({ referenceLink = null, vaeLink = null, includeReferenceInputs = true } = {}) {
const widgets = [];
const inputs = [
{ name: "reference_video_1", type: "IMAGE", label: "Video Reference", link: null },
{ name: "driving_audio", type: "AUDIO", link: null },
{ name: "audio_vae", type: "VAE", link: null },
];
if (includeReferenceInputs) {
inputs.push(
{ name: "reference_audio_1", type: "AUDIO", label: "Reference Audio", shape: 7, link: referenceLink },
{ name: "reference_audio_vae", type: "VAE", label: "Reference Audio VAE", shape: 7, link: vaeLink },
);
}
inputs.push(
{ name: "prompt_mode", type: "COMBO", link: null },
{ name: "chunks", type: "INT", link: null },
);
let previousConnectionCalls = 0;
const node = {
inputs,
widgets,
size: [320, 600],
addWidget(type, name, value, callback, options) {
const widget = { type, name, value, callback, options };
this.widgets.push(widget);
return widget;
},
addInput(name, type, options = {}) {
const input = { name, type, link: null, ...options };
this.inputs.push(input);
return input;
},
removeInput(index) {
assert.ok(this.inputs[index].link === null || this.inputs[index].link === -1);
this.inputs.splice(index, 1);
},
computeSize() {
return [320, 400 + this.inputs.length * 10];
},
setSize(size) {
this.size = size;
},
setDirtyCanvas() {},
onConnectionsChange() {
previousConnectionCalls += 1;
},
};
return { node, previousConnectionCalls: () => previousConnectionCalls };
}
const inputs = [
{ name: "reference_video_1", type: "IMAGE", label: "Video Reference", link: null },
{ name: "driving_audio", type: "AUDIO", label: "driving_audio", link: null },
{ name: "audio_vae", type: "VAE", label: "audio_vae", link: null },
{ name: "reference_audio_1", type: "AUDIO", label: "Reference Audio", link: null },
{ name: "reference_audio_vae", type: "VAE", label: "Reference Audio VAE", link: null },
{ name: "prompt_mode", type: "COMBO", link: null },
];
const widgets = [{ name: "prompt_mode", value: "Auto" }];
const node = { inputs, widgets };
const originalInputs = [...inputs];
const originalWidgets = [...widgets];
function widget(node) {
return node.widgets.find((item) => item.name === "Reference Audio Inputs");
}
assert.equal(normalizeReferenceAudioLabels(node), true);
assert.deepEqual(node.inputs, originalInputs);
assert.deepEqual(node.widgets, originalWidgets);
assert.deepEqual(
node.inputs.slice(0, 5).map((input) => input.label),
[
"Video Guide Frames",
"Driving Audio",
"Driving Audio VAE",
"Reference Audio (Optional)",
"Reference Audio VAE (Optional)",
],
);
assert.equal(node.inputs[3].name, "reference_audio_1");
assert.equal(node.inputs[4].name, "reference_audio_vae");
''',
encoding="utf-8",
)
result = subprocess.run(
[node, str(harness_path)],
cwd=tmp_path,
capture_output=True,
text=True,
check=False,
)
assert result.returncode == 0, result.stdout + result.stderr
def test_workflow_save_reload_preserves_v35_widget_value_alignment(tmp_path):
node = shutil.which("node")
assert node is not None, "Node.js is required for frontend behavior validation"
function input(node, name) {
return node.inputs.find((item) => item.name === name);
}
module_path = tmp_path / "reference_audio_ui.mjs"
module_path.write_text(REFERENCE_AUDIO_UI_JS.read_text(encoding="utf-8"), encoding="utf-8")
harness_path = tmp_path / "workflow_reload_harness.mjs"
harness_path.write_text(
r'''
import assert from "node:assert/strict";
import { normalizeReferenceAudioLabels } from "./reference_audio_ui.mjs";
{
const { node } = makeNode();
assert.equal(configureReferenceAudioInputs(node), true);
assert.equal(widget(node).value, "Hidden");
assert.equal(widget(node).options.serialize, false);
assert.equal(widget(node).serializeValue(), undefined);
assert.equal(input(node, "reference_audio_1"), undefined);
assert.equal(input(node, "reference_audio_vae"), undefined);
assert.equal(input(node, "reference_video_1").label, "Video Guide Frames");
assert.equal(input(node, "audio_vae").label, "Driving Audio VAE");
const serialized = { widgets_values: node.widgets.map((item) => item.value) };
node.onSerialize(serialized);
assert.deepEqual(serialized.widgets_values, []);
const widgetValues = {
prompt_mode: "Auto",
chunks: 3,
chunk_seconds: 5.0,
width: 1344,
height: 768,
continuity: "Balanced — 22 frames",
base_seed: 123456789,
control_after_generate: "randomize",
audio_continuity: true,
diagnostics: "Detailed Report",
reroll_from_chunk: "Auto",
reroll_nonce: 7,
strict_compatibility: false,
debug: false,
show_preview: true,
run_storage: "Off",
run_name: "alignment-test",
reference_size: "Match Output",
project_id: "workflow-save-reload",
video_reference_size: "Efficient - 0.4 MP",
};
widget(node).value = "Show";
widget(node).callback("Show");
assert.deepEqual(
node.inputs.slice(3, 5).map((item) => [item.name, item.label]),
[
["reference_audio_1", "Reference Audio (Optional)"],
["reference_audio_vae", "Reference Audio VAE (Optional)"],
function makeNode(values) {
return {
inputs: [
{ name: "reference_video_1", type: "IMAGE", link: null },
{ name: "driving_audio", type: "AUDIO", link: null },
{ name: "audio_vae", type: "VAE", link: null },
{ name: "reference_audio_1", type: "AUDIO", link: null },
{ name: "reference_audio_vae", type: "VAE", link: null },
],
);
widgets: Object.entries(values).map(([name, value]) => ({ name, value })),
};
}
input(node, "reference_audio_1").link = 42;
widget(node).value = "Hidden";
widget(node).callback("Hidden");
assert.equal(widget(node).value, "Show");
assert.equal(input(node, "reference_audio_1").link, 42);
}
const original = makeNode(widgetValues);
normalizeReferenceAudioLabels(original);
const saved = JSON.parse(JSON.stringify({
inputs: original.inputs.map(({ name, type, link }) => ({ name, type, link })),
widgets_values: original.widgets
.filter((widget) => widget.serialize !== false)
.map((widget) => widget.value),
}));
{
const { node, previousConnectionCalls } = makeNode({ referenceLink: 7, vaeLink: 8 });
assert.equal(configureReferenceAudioInputs(node), true);
assert.equal(widget(node).value, "Show");
assert.equal(input(node, "reference_audio_1").link, 7);
assert.equal(input(node, "reference_audio_vae").link, 8);
node.onConnectionsChange();
await new Promise((resolve) => setTimeout(resolve, 1));
assert.equal(previousConnectionCalls(), 1);
assert.equal(widget(node).value, "Show");
}
assert.equal(saved.inputs[3].name, "reference_audio_1");
assert.equal(saved.inputs[4].name, "reference_audio_vae");
assert.equal(saved.widgets_values.length, Object.keys(widgetValues).length);
{
const { node } = makeNode({ referenceLink: -1, vaeLink: -1 });
assert.equal(configureReferenceAudioInputs(node), true);
assert.equal(widget(node).value, "Hidden");
assert.equal(input(node, "reference_audio_1"), undefined);
assert.equal(input(node, "reference_audio_vae"), undefined);
}
const reloaded = makeNode(Object.fromEntries(Object.keys(widgetValues).map((name) => [name, null])));
saved.widgets_values.forEach((value, index) => {
reloaded.widgets[index].value = value;
});
normalizeReferenceAudioLabels(reloaded);
{
const { node } = makeNode({ includeReferenceInputs: false });
assert.equal(configureReferenceAudioInputs(node), true);
assert.equal(widget(node).value, "Hidden");
widget(node).value = "Show";
widget(node).callback("Show");
assert.equal(input(node, "reference_audio_1").type, "AUDIO");
assert.equal(input(node, "reference_audio_vae").type, "VAE");
}
assert.deepEqual(
Object.fromEntries(reloaded.widgets.map(({ name, value }) => [name, value])),
widgetValues,
);
assert.equal(reloaded.widgets.some((widget) => widget.name === "Reference Audio Inputs"), false);
assert.deepEqual(
reloaded.inputs.map((input) => input.name),
original.inputs.map((input) => input.name),
);
''',
encoding="utf-8",
)
+3 -15
View File
@@ -3,7 +3,7 @@ import {
captureLastQueuedSeed,
configureLastQueuedSeedReuse,
} from "./last_queued_seed.js";
import { configureReferenceAudioInputs } from "./reference_audio_ui.js";
import { normalizeReferenceAudioLabels } from "./reference_audio_ui.js";
const PRODUCTION_NODE_CLASS = "H3ContinuumSamplerProduction";
const TIMELINE_NODE_CLASS = "H3ContinuumSamplerTimelineVideo";
@@ -245,6 +245,7 @@ function configureNode(node) {
applyRuntimeSettings(node);
if (isV35) {
configureLastQueuedSeedReuse(node);
normalizeReferenceAudioLabels(node);
}
hidePersistentWidget(findWidget(node, "diagnostics"));
hidePersistentWidget(findWidget(node, "strict_compatibility"));
@@ -259,18 +260,7 @@ function configureNode(node) {
function configureNodeAfterSetup(node) {
configureNode(node);
const configureDeferred = () => {
configureNode(node);
if (
node.comfyClass === V35_NODE_CLASS
&& (
!node.__h3ContinuumLoadedGraphNode
|| node.__h3ContinuumAfterConfigureGraph
)
) {
configureReferenceAudioInputs(node);
}
};
const configureDeferred = () => configureNode(node);
setTimeout(configureDeferred, 0);
setTimeout(configureDeferred, 100);
}
@@ -311,13 +301,11 @@ app.registerExtension({
},
loadedGraphNode(node) {
node.__h3ContinuumLoadedGraphNode = true;
configureNodeAfterSetup(node);
},
afterConfigureGraph() {
for (const node of app.graph?._nodes || []) {
node.__h3ContinuumAfterConfigureGraph = true;
configureNodeAfterSetup(node);
}
},
+4 -216
View File
@@ -1,22 +1,3 @@
const REFERENCE_AUDIO_WIDGET = "Reference Audio Inputs";
const REFERENCE_AUDIO_HIDDEN = "Hidden";
const REFERENCE_AUDIO_SHOW = "Show";
const INPUT_DEFINITIONS = [
{
name: "reference_audio_1",
type: "AUDIO",
label: "Reference Audio (Optional)",
shape: 7,
},
{
name: "reference_audio_vae",
type: "VAE",
label: "Reference Audio VAE (Optional)",
shape: 7,
},
];
const NORMALIZED_INPUT_LABELS = {
reference_video_1: "Video Guide Frames",
driving_audio: "Driving Audio",
@@ -25,208 +6,15 @@ const NORMALIZED_INPUT_LABELS = {
reference_audio_vae: "Reference Audio VAE (Optional)",
};
function findInput(node, name) {
return node.inputs?.find((input) => input.name === name);
}
function findWidget(node) {
return node.widgets?.find((widget) => widget.name === REFERENCE_AUDIO_WIDGET);
}
function normalizeInputLabels(node) {
export function normalizeReferenceAudioLabels(node) {
if (!node) {
return false;
}
for (const input of node.inputs || []) {
const label = NORMALIZED_INPUT_LABELS[input.name];
if (label) {
input.label = label;
}
}
}
function inputHasLink(input) {
return input?.link != null && input.link !== -1;
}
function hasReferenceAudioLink(node) {
return INPUT_DEFINITIONS.some(({ name }) => inputHasLink(findInput(node, name)));
}
function rememberInputDefinitions(node) {
node.__h3ContinuumReferenceAudioDefinitions ||= {};
for (const definition of INPUT_DEFINITIONS) {
const input = findInput(node, definition.name);
if (!input || node.__h3ContinuumReferenceAudioDefinitions[definition.name]) {
continue;
}
node.__h3ContinuumReferenceAudioDefinitions[definition.name] = {
name: definition.name,
type: input.type || definition.type,
label: definition.label,
shape: input.shape ?? definition.shape,
index: node.inputs.indexOf(input),
};
}
}
function inputDefinition(node, name) {
const remembered = node.__h3ContinuumReferenceAudioDefinitions?.[name];
return remembered || INPUT_DEFINITIONS.find((definition) => definition.name === name);
}
function resizeNode(node) {
const computed = node.computeSize?.();
if (computed && node.setSize) {
const width = Math.max(Number(node.size?.[0]) || 0, Number(computed[0]) || 0);
node.setSize([width, computed[1]]);
}
node.setDirtyCanvas?.(true, true);
}
function showReferenceAudioInputs(node) {
for (const expected of INPUT_DEFINITIONS) {
if (findInput(node, expected.name)) {
continue;
}
const definition = inputDefinition(node, expected.name);
const input = node.addInput?.(definition.name, definition.type, {
label: definition.label,
shape: definition.shape,
});
const addedIndex = node.inputs?.indexOf(input) ?? -1;
const rememberedIndex = Number(definition.index);
const firstWidgetInput = node.inputs?.findIndex(
(candidate) => candidate.name === "prompt_mode",
) ?? -1;
const requestedIndex = Number.isInteger(rememberedIndex)
? rememberedIndex
: (firstWidgetInput >= 0 ? firstWidgetInput : node.inputs.length - 1);
const targetIndex = Math.min(
Math.max(0, requestedIndex),
Math.max(0, node.inputs.length - 1),
);
if (addedIndex >= 0 && addedIndex !== targetIndex) {
node.inputs.splice(addedIndex, 1);
node.inputs.splice(targetIndex, 0, input);
}
}
normalizeInputLabels(node);
return INPUT_DEFINITIONS.every(({ name }) => Boolean(findInput(node, name)));
}
function hideReferenceAudioInputs(node) {
if (hasReferenceAudioLink(node)) {
return false;
}
const indices = INPUT_DEFINITIONS.map(({ name }) =>
node.inputs?.findIndex((input) => input.name === name) ?? -1
);
for (const index of indices.filter((index) => index >= 0).sort((left, right) => right - left)) {
node.removeInput?.(index);
}
return INPUT_DEFINITIONS.every(({ name }) => !findInput(node, name));
}
function setReferenceAudioVisibility(node, widget, show) {
rememberInputDefinitions(node);
const applied = show
? showReferenceAudioInputs(node)
: hideReferenceAudioInputs(node);
if (!applied) {
showReferenceAudioInputs(node);
widget.value = REFERENCE_AUDIO_SHOW;
}
resizeNode(node);
return applied;
}
function ensureVisibilityWidget(node) {
let widget = findWidget(node);
if (widget) {
return widget;
}
if (!node.addWidget) {
return null;
}
const initialValue = hasReferenceAudioLink(node)
? REFERENCE_AUDIO_SHOW
: REFERENCE_AUDIO_HIDDEN;
widget = node.addWidget(
"combo",
REFERENCE_AUDIO_WIDGET,
initialValue,
(value) => {
setReferenceAudioVisibility(
node,
widget,
value === REFERENCE_AUDIO_SHOW,
);
},
{ values: [REFERENCE_AUDIO_HIDDEN, REFERENCE_AUDIO_SHOW] },
);
widget.options ||= {};
widget.options.serialize = false;
widget.serializeValue = () => undefined;
return widget;
}
function attachWorkflowSerializationGuard(node, widget) {
if (node.__h3ContinuumReferenceAudioSerializationGuard) {
return;
}
const previous = node.onSerialize;
node.onSerialize = function(info, ...args) {
const result = previous?.call(this, info, ...args);
const widgetIndex = node.widgets?.indexOf(widget) ?? -1;
if (
widgetIndex >= 0
&& Array.isArray(info?.widgets_values)
&& widgetIndex === node.widgets.length - 1
&& info.widgets_values.length === node.widgets.length
) {
info.widgets_values.pop();
}
return result;
};
node.__h3ContinuumReferenceAudioSerializationGuard = true;
}
function attachConnectionRefresh(node, widget) {
if (node.__h3ContinuumReferenceAudioConnectionCallback) {
return;
}
const previous = node.onConnectionsChange;
node.onConnectionsChange = function(...args) {
const result = previous?.apply(this, args);
setTimeout(() => {
normalizeInputLabels(node);
if (hasReferenceAudioLink(node)) {
widget.value = REFERENCE_AUDIO_SHOW;
setReferenceAudioVisibility(node, widget, true);
}
}, 0);
return result;
};
node.__h3ContinuumReferenceAudioConnectionCallback = true;
}
export function configureReferenceAudioInputs(node) {
if (!node) {
return false;
}
normalizeInputLabels(node);
rememberInputDefinitions(node);
const widget = ensureVisibilityWidget(node);
if (!widget) {
return false;
}
attachWorkflowSerializationGuard(node, widget);
if (hasReferenceAudioLink(node)) {
widget.value = REFERENCE_AUDIO_SHOW;
}
setReferenceAudioVisibility(
node,
widget,
widget.value === REFERENCE_AUDIO_SHOW,
);
attachConnectionRefresh(node, widget);
return true;
}