fix: reduce Issue #30 frontend overhead and release 3.9.2

This commit is contained in:
Miura Yoshiki
2026-10-12 17:18:07 +00:00
parent 120ca6c9ea
commit e9b1294ccd
21 changed files with 485 additions and 54 deletions
+131
View File
@@ -0,0 +1,131 @@
// Exercise the complete production scripts through the existing Queue fixture.
// DOM, graph and server responses are fixtures; no ComfyUI service or GPU is used.
const assert = require('node:assert/strict');
const fs = require('node:fs');
const path = require('node:path');
const vm = require('node:vm');
const ROOT = process.env.H3_TEST_ROOT || path.resolve(__dirname, '..');
const harness = fs.readFileSync(path.join(ROOT, 'tests/frontend_review_queue.cjs'), 'utf8');
const marker = harness.indexOf('\n(async()=>{');
assert(marker > 0);
function dom(tag) {
return { tag, children: [], style: {}, textContent: '',
append(...items) { this.children.push(...items); },
replaceChildren(...items) { this.children = items; },
addEventListener() {}, setAttribute(name, value) { this[name] = value; } };
}
const scope = { require, process, console, __dirname: path.join(ROOT, 'tests'),
setTimeout, clearTimeout, setImmediate, structuredClone,
document: { createElement: dom } };
const prefix = harness.slice(0, marker)
.replace('globalThis:null,', 'globalThis:null,document,')
.replace('reviewSettingsChanged,synchronizeReviewQueue};',
'reviewSettingsChanged,reviewSettingsSnapshot,synchronizeReviewQueue};');
vm.runInNewContext(prefix + '\nglobalThis.fixtures={environment,project};', scope);
const { environment, project } = scope.fixtures;
const results = [];
async function test(name, body, knownIssue = null) {
const e = environment();
try { await body(e); results.push({ name, pass: true, knownIssue }); }
catch (error) { results.push({ name, pass: false, knownIssue, error: error.stack }); }
finally { e.close(); }
}
function upstream(e, n, count = 20) {
let previous = n;
for (let i = 0; i < count; i++) {
const source = { id: 900 + i, comfyClass: 'FixtureSource', mode: 0,
widgets: [{ name: 'text', value: `source-${i}`, options: {} }], inputs: [] };
e.app.graph._nodes.push(source);
previous.inputs.push({ name: 'source', link: 70 + i });
e.app.graph.links[70 + i] = { origin_id: source.id, origin_slot: 0 };
previous = source;
}
return previous;
}
function helper(e, n) {
const h = e.makeNode(391, 'helper', 'H3ContinuumReferenceImagesV39', false);
h.widgets = [{ name: 'reference_use', value: 'Per chunk', options: {} },
...Array.from({ length: 9 }, (_, i) => ({ name: `reference_r${i + 1}_chunks`, value: 'off', options: {} }))];
h.inputs = [{ name: 'reference_image_1', link: 600 }];
h.outputs = [{ name: 'reference_images', links: [900] }];
h.addDOMWidget = function(_name, _type, host, options) {
this.panel = host.children[0]; this.display = { options }; return this.display;
};
h.computeSize = function() { return [this.size[0], 310 + this.display.computeSize(this.size[0])[1]]; };
h.setSize = function(size) { this.size = size; };
e.app.graph.links[900] = { origin_id: h.id, target_id: n.id, origin_slot: 0 };
n.inputs.push({ name: 'reference_images', link: 900 });
e.f.configureNode(h);
return h;
}
(async () => {
await test('no Review baseline: draw does not traverse upstream settings', async e => {
const n = e.makeNode(); upstream(e, n);
let lookups = 0, refreshes = 0;
const get = e.app.graph.getNodeById;
e.app.graph.getNodeById = function(...args) { lookups++; return get.apply(this, args); };
n.__h3ContinuumIntuitiveUxRefresh = n.__h3ContinuumProductionUxRefresh = () => { refreshes++; };
for (const baseline of [undefined, null]) {
n.__h3ContinuumReviewedSettings = baseline;
n.__h3ContinuumReviewDrawChanged = false;
for (let i = 0; i < 600; i++) n.onDrawForeground();
assert.equal(e.f.reviewSettingsChanged(n), false);
}
assert.equal(lookups, 0); assert.equal(refreshes, 0);
n.__h3ContinuumReviewedSettings = '';
assert.equal(e.f.reviewSettingsChanged(n), true, 'an existing empty baseline still requires comparison');
assert.equal(lookups, 20);
});
await test('Review baseline: every draw still detects upstream edits', async e => {
const n = e.makeNode(), last = upstream(e, n);
n.__h3ContinuumReviewedSettings = e.f.reviewSettingsSnapshot(n);
n.__h3ContinuumReviewDrawChanged = false;
let lookups = 0, refreshes = 0;
const get = e.app.graph.getNodeById;
e.app.graph.getNodeById = function(...args) { lookups++; return get.apply(this, args); };
n.__h3ContinuumIntuitiveUxRefresh = n.__h3ContinuumProductionUxRefresh = () => { refreshes++; };
for (let i = 0; i < 600; i++) n.onDrawForeground();
assert.equal(lookups, 12000); assert.equal(refreshes, 0);
last.widgets[0].value = 'edited';
n.onDrawForeground();
assert.equal(n.__h3ContinuumReviewDrawChanged, true);
assert.equal(refreshes, 2);
});
for (const nodeClass of ['H3ContinuumSamplerV38', 'H3ContinuumSamplerV39']) {
for (const change of ['widget', 'link']) {
await test(`${nodeClass}: ${change} edit keeps immediate Take and draw guards`, async e => {
const n = e.makeNode(312, 'fixture', nodeClass), source = upstream(e, n, 1);
e.w(n, 'generation_mode').value = 'Review Each Chunk';
await e.load(n, project(1));
delete n.__h3ContinuumModeSetup;
n.__h3ContinuumReviewedSettings = e.f.reviewSettingsSnapshot(n);
n.__h3ContinuumProductionUxRefresh(); n.onDrawForeground();
assert(e.visible(n, 'Use it and continue'));
if (change === 'widget') source.widgets[0].value = 'edited';
else e.app.graph.links[70].origin_slot = 1;
assert(e.visible(n, 'Use it and continue'), 'no draw has occurred yet');
e.f.selectTakeAction(n, 'Use This Take');
assert.equal(e.w(n, 'take_action').value, 'Automatic');
assert.equal(e.w(n, 'take_revision_id').value, '');
n.onDrawForeground();
assert(!e.visible(n, 'Use it and continue'));
assert.match(e.w(n, 'Review Ready').headline, /Settings changed/);
assert.equal(e.submissions.length, 0);
});
}
}
for (const passes of [1, 2, 100]) {
await test(`Reference Inspector stays current after ${passes} configure passes`, async e => {
const n = e.makeNode(312, 'fixture', 'H3ContinuumSamplerV39', false), h = helper(e, n);
for (let i = 0; i < passes; i++) e.f.configureNode(n);
n.onExecuted({ h3_reference_plan: ['fixture verified plan'] });
const plan = e.w(n, 'Reference Plan Inspector');
assert.equal(plan.value, 'fixture verified plan');
h.widgets[1].value = '1'; h.widgets[1].callback('1');
assert.equal(n.__h3ContinuumReferencePlan, null);
assert.notEqual(plan.value, 'fixture verified plan', 'an invalidated plan must not keep its verified display');
}, passes > 1 ? 'inspector-reconfigure' : null);
}
console.log(JSON.stringify(results));
if (results.some(item => !item.pass && !item.knownIssue)) process.exitCode = 1;
})();
+80 -1
View File
@@ -24,8 +24,11 @@ const {
configureV39ReferenceImages, refreshV39ReferenceImagesForSampler,
connectedV39LegacyReferenceInputs, pruneV39LegacyReferenceInputs,
} = sandbox.v39;
const nativeCalls = [];
let resizeCalls = 0;
const selectors = Array.from({ length: 9 }, (_, i) => ({
name: `reference_r${i + 1}_chunks`, value: 'off', type: 'text', options: {},
callback(...args) { nativeCalls.push({ receiver: this, args }); return 'native-result'; },
}));
const mode = { name: 'reference_use', value: 'All chunks', type: 'combo', options: {} };
const helper = {
@@ -36,13 +39,15 @@ const helper = {
outputs: [{ name: 'reference_images', links: [10] }],
addDOMWidget(_name, _type, host, options) { this.host = host; this.panel = host.children[0]; this.domOptions = options; this.display = { options: {} }; return this.display; },
computeSize() { return [this.size[0], 310 + this.display.computeSize(this.size[0])[1]]; },
setSize(size) { this.size = size; },
setSize(size) { resizeCalls++; this.size = size; },
setDirtyCanvas() {},
};
const chunks = { name: 'chunks', value: 6 };
const sampler = {
id: 2, graph, comfyClass: 'H3ContinuumSamplerV39',
widgets: [chunks], inputs: [{ name: 'reference_images', link: 10 }],
refreshes: 0,
__h3ContinuumIntuitiveUxRefresh() { this.refreshes++; },
__h3ContinuumReferencePlan: 'verified', setDirtyCanvas() {},
};
graph.nodes.set(1, helper); graph.nodes.set(2, sampler);
@@ -72,7 +77,14 @@ function click(slot, chunk) {
const box = visit(helper.panel, (item) => item.tag === 'input'
&& item['aria-label'] === `Image ${slot}, Chunk ${chunk}`);
assert(box, `missing Image ${slot} / Chunk ${chunk}`);
const before = { notifications: sampler.refreshes, native: nativeCalls.length, sizes: resizeCalls, width: helper.size[0] };
box.checked = !box.checked; box.onchange();
assert.equal(sampler.refreshes, before.notifications + 1, 'one synchronous Sampler notification per checkbox');
assert.equal(nativeCalls.length, before.native + 1, 'preserve the native callback exactly once');
assert.equal(nativeCalls.at(-1).receiver, selectors[slot - 1]);
assert.equal(nativeCalls.at(-1).args[0], selectors[slot - 1].value);
assert.equal(resizeCalls, before.sizes, 'selection changes must not resize an unchanged layout');
assert.equal(helper.size[0], before.width, 'keep the manually chosen width');
}
for (const chunk of [1, 3, 6]) click(1, chunk);
assert.equal(selectors[0].value, '1,3,6');
@@ -80,6 +92,28 @@ assert.equal(sampler.__h3ContinuumReferencePlan, null);
chunks.value = 3; refreshV39ReferenceImagesForSampler(sampler);
assert.match(helper.panel.children.find((item) => item.textContent.startsWith('Image 1 →')).textContent, /saved beyond range: 6/);
assert.equal(selectors[0].value, '1,3,6');
function action(label) {
const row = visit(helper.panel, (item) => item.tag === 'tr'
&& item.children[0]?.textContent === 'Image 1 · @R1');
const button = visit(row, (item) => item.tag === 'button' && item.textContent === label);
assert(button && !button.disabled);
const before = { notifications: sampler.refreshes, native: nativeCalls.length, sizes: resizeCalls };
button.onclick();
assert.equal(sampler.refreshes, before.notifications + 1, 'one notification per All / Off');
assert.equal(nativeCalls.length, before.native + 1);
assert.equal(resizeCalls, before.sizes);
}
action('All');
assert.equal(selectors[0].value, '1,2,3,6', 'All preserves saved chunks beyond the current range');
action('Off');
assert.equal(selectors[0].value, '6', 'Off preserves saved chunks beyond the current range');
selectors[0].value = '1,3,6';
const nativeBefore = nativeCalls.length;
const refreshBefore = sampler.refreshes;
assert.equal(selectors[0].callback('1,3,6', 'native-edit'), 'native-result');
assert.equal(nativeCalls.length, nativeBefore + 1);
assert.equal(nativeCalls.at(-1).args[1], 'native-edit');
assert.equal(sampler.refreshes, refreshBefore + 1);
chunks.value = 6; refreshV39ReferenceImagesForSampler(sampler);
assert.equal(selectors[0].value, '1,3,6');
mode.value = 'All chunks'; mode.callback('All chunks');
@@ -92,6 +126,51 @@ chunks.value = 16;
helper.__h3ReferenceImagesRefresh();
assert.equal(helper.display.computeSize(440)[1], 368);
assert.equal(helper.panel.style.height, '360px');
const stableSizes = resizeCalls;
const wrappedCallback = selectors[0].callback;
for (let i = 0; i < 100; i++) configureV39ReferenceImages(helper);
assert.equal(selectors[0].callback, wrappedCallback, 'helper reconfiguration must not stack callbacks');
assert.equal(resizeCalls, stableSizes);
helper.size[0] = 620;
click(1, 2);
assert.equal(helper.size[0], 620);
// Check another connected Sampler independently of the manually chosen width.
helper.size[0] = 440;
const secondSampler = { ...sampler, id: 3, refreshes: 0, widgets: [{ name: 'chunks', value: 16 }] };
graph.nodes.set(3, secondSampler);
graph.links[11] = { origin_id: 1, target_id: 3 };
helper.outputs[0].links.push(11);
click(1, 3);
assert.equal(secondSampler.refreshes, 1, 'each connected Sampler receives the selection');
assert.equal(secondSampler.__h3ContinuumReferencePlan, null);
const separateSampler = { ...sampler, id: 5, refreshes: 0, widgets: [{ name: 'chunks', value: 16 }],
__h3ContinuumReferencePlan: 'verified' };
const separateHelper = {
id: 4, graph, comfyClass: helper.comfyClass, size: [440, 500],
widgets: [{ name: 'reference_use', value: 'Per chunk', options: {} },
...Array.from({ length: 9 }, (_, i) => ({ name: `reference_r${i + 1}_chunks`, value: 'off', options: {} }))],
inputs: helper.inputs.map((input) => ({ ...input })),
outputs: [{ name: 'reference_images', links: [12] }],
addDOMWidget: helper.addDOMWidget, computeSize: helper.computeSize,
setSize: helper.setSize, setDirtyCanvas() {},
};
graph.nodes.set(4, separateHelper); graph.nodes.set(5, separateSampler);
graph.links[12] = { origin_id: 4, target_id: 5 };
configureV39ReferenceImages(separateHelper);
const firstBefore = sampler.refreshes;
click(1, 4);
const separateBox = visit(separateHelper.panel, (item) => item.tag === 'input'
&& item['aria-label'] === 'Image 1, Chunk 5');
separateBox.checked = true; separateBox.onchange();
assert.equal(sampler.refreshes, firstBefore + 1);
assert.equal(separateSampler.refreshes, 1, 'independent helpers must not cancel each other');
assert.equal(separateHelper.widgets[1].value, '5');
assert.equal(separateSampler.__h3ContinuumReferencePlan, null);
delete graph.links[12]; separateHelper.outputs[0].links = [];
separateHelper.onConnectionsChange();
const detachedRefreshes = separateSampler.refreshes;
separateHelper.widgets[1].value = '6'; separateHelper.widgets[1].callback('6');
assert.equal(separateSampler.refreshes, detachedRefreshes, 'disconnected Samplers are not notified');
const oldSampler = {
comfyClass: 'H3ContinuumSamplerV39',
__h3ContinuumReferencePlan: 'old plan',
+54
View File
@@ -0,0 +1,54 @@
"""Issue #30 overhead regression, with the independent Inspector bug tracked."""
import json
import os
from pathlib import Path
import shutil
import subprocess
import pytest
ROOT = Path(__file__).resolve().parents[1]
def run_frontend(filename):
node = shutil.which("node")
assert node, "Node.js is required for frontend regression tests"
return subprocess.run(
[node, str(ROOT / "tests" / filename)],
env={**os.environ, "H3_TEST_ROOT": str(ROOT)},
capture_output=True, text=True, encoding="utf-8", timeout=45,
)
def test_reference_selection_notifications_and_layout():
result = run_frontend("frontend_reference_images_v39.cjs")
assert result.returncode == 0, result.stdout + result.stderr
@pytest.fixture(scope="module")
def issue30_results():
result = run_frontend("frontend_issue30_ui.cjs")
assert result.returncode == 0, result.stdout + result.stderr
records = json.loads(result.stdout)
assert len(records) == 9
for record in records:
if record["knownIssue"] and not record["pass"]:
assert "an invalidated plan must not keep its verified display" in record.get("error", ""), record
return {record["name"]: record for record in records}
@pytest.mark.parametrize("name", [
"no Review baseline: draw does not traverse upstream settings",
"Review baseline: every draw still detects upstream edits",
*[f"{node_class}: {change} edit keeps immediate Take and draw guards"
for node_class in ("H3ContinuumSamplerV38", "H3ContinuumSamplerV39")
for change in ("widget", "link")],
"Reference Inspector stays current after 1 configure passes",
pytest.param("Reference Inspector stays current after 2 configure passes", marks=pytest.mark.xfail(
strict=True, reason="Independent Inspector refresh hook is lost on Sampler reconfigure")),
pytest.param("Reference Inspector stays current after 100 configure passes", marks=pytest.mark.xfail(
strict=True, reason="Independent Inspector refresh hook is lost on Sampler reconfigure")),
])
def test_issue30_frontend_paths(issue30_results, name):
record = issue30_results[name]
assert record["pass"], record.get("error", name)
+1 -1
View File
@@ -6,7 +6,7 @@ import tomllib
ROOT = Path(__file__).resolve().parents[1]
EXPECTED_VERSION = "3.9.1"
EXPECTED_VERSION = "3.9.2"
def test_v35_release_metadata_is_consistent():
+1 -1
View File
@@ -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.9.1"' in version_source
assert 'PACKAGE_VERSION = "3.9.2"' in version_source