const test = require('node:test'); const assert = require('node:assert/strict'); const NodeClass = require('../../src/nodeClass'); const commands = require('../../src/commands'); const { createRegistry } = require('generalFunctions'); const { makeNodeStub, makeREDStub } = require('../helpers/factories'); // Post-refactor: dispatch goes through the commands registry built by // BaseNodeAdapter (this._commands). We seed the registry on a prototype- // derived instance, then drive _attachInputHandler the same way the live // adapter would. test('input handler routes legacy topic aliases to engine setters', async () => { const inst = Object.create(NodeClass.prototype); const node = makeNodeStub(); const calls = []; const source = { logger: { warn: () => {}, info: () => {}, debug: () => {}, error: () => {} }, updateState(t) { calls.push(['clock', t]); }, childRegistrationUtils: { registerChild(childSource, position) { calls.push(['registerChild', childSource, position]); }, }, }; Object.defineProperty(source, 'setInfluent', { set(v) { calls.push(['Fluent', v]); } }); Object.defineProperty(source, 'setOTR', { set(v) { calls.push(['OTR', v]); } }); Object.defineProperty(source, 'setTemperature', { set(v) { calls.push(['Temperature', v]); } }); Object.defineProperty(source, 'setDispersion', { set(v) { calls.push(['Dispersion', v]); } }); inst.node = node; inst.RED = makeREDStub({ childA: { source: { id: 'child-source-A' } } }); inst.source = source; inst._commands = createRegistry(commands, { logger: source.logger }); inst._attachInputHandler(); const onInput = node._handlers.input; let doneCount = 0; const done = () => { doneCount += 1; }; await onInput({ topic: 'clock', timestamp: 1000 }, () => {}, done); await onInput({ topic: 'Fluent', payload: { inlet: 0, F: 10, C: [] } }, () => {}, done); await onInput({ topic: 'OTR', payload: 3.5 }, () => {}, done); await onInput({ topic: 'Temperature', payload: 18.2 }, () => {}, done); await onInput({ topic: 'Dispersion', payload: 0.2 }, () => {}, done); await onInput({ topic: 'registerChild', payload: 'childA', positionVsParent: 'upstream' }, () => {}, done); assert.equal(doneCount, 6); assert.deepEqual(calls[0], ['clock', 1000]); assert.equal(calls.some((x) => x[0] === 'Fluent'), true); assert.equal(calls.some((x) => x[0] === 'OTR'), true); assert.equal(calls.some((x) => x[0] === 'Temperature'), true); assert.equal(calls.some((x) => x[0] === 'Dispersion'), true); assert.deepEqual(calls.at(-1), ['registerChild', { id: 'child-source-A' }, 'upstream']); });