// 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; })();