const test = require('node:test'); const assert = require('node:assert/strict'); const NodeClass = require('../../src/nodeClass'); const { makeNodeStub } = require('../helpers/factories'); // Post-refactor: BaseNodeAdapter drives tick + status loops. The reactor // nodeClass overrides _emitOutputs to preserve the Fluent / GridProfile // Port-0 contract (delta-compressed payloads can't carry the C-vector). test('_emitOutputs emits effluent on process output', () => { const inst = Object.create(NodeClass.prototype); const node = makeNodeStub(); inst.node = node; inst.config = { functionality: { softwareType: 'reactor' }, general: { id: 'r-1' } }; inst._output = { formatMsg() { return null; } }; inst.source = { engine: { temperature: 18, getEffluent: { topic: 'Fluent', payload: { inlet: 0, F: 1, C: [] }, timestamp: 1 }, get getGridProfile() { return null; } }, config: inst.config, updateState() {}, get getEffluent() { return this.engine.getEffluent; }, get getGridProfile() { return this.engine.getGridProfile; }, getOutput() { return {}; }, }; inst._emitOutputs(); assert.equal(node._sent.length, 1); assert.equal(node._sent[0][0].topic, 'Fluent'); assert.equal(node._sent[0][1], null); assert.equal(node._sent[0][2], null); }); test('_emitOutputs emits reactor telemetry on influx output', () => { const inst = Object.create(NodeClass.prototype); const node = makeNodeStub(); let captured = null; inst.node = node; inst.config = { functionality: { softwareType: 'reactor' }, general: { id: 'reactor-node-1' } }; inst._output = { formatMsg(output, _config, format) { captured = { output, format }; return { topic: `reactor_${inst.config.general.id}`, payload: { measurement: 'reactor', fields: output } }; }, }; const effluent = { topic: 'Fluent', payload: { inlet: 0, F: 42, C: [2.1, 30, 100, 16, 0, 1, 8, 25, 75, 1500, 0, 15, 2500] }, timestamp: 1 }; inst.source = { engine: { temperature: 19.5, getEffluent: effluent, get getGridProfile() { return null; } }, config: inst.config, updateState() {}, get getEffluent() { return this.engine.getEffluent; }, get getGridProfile() { return this.engine.getGridProfile; }, getOutput() { const C = effluent.payload.C; const out = { flow_total: effluent.payload.F, temperature: 19.5 }; const keys = ['S_O','S_I','S_S','S_NH','S_N2','S_NO','S_HCO','X_I','X_S','X_H','X_STO','X_A','X_TS']; for (let i = 0; i < keys.length; i += 1) out[keys[i]] = C[i]; return out; }, }; inst._emitOutputs(); assert.equal(node._sent.length, 1); assert.equal(node._sent[0][0].topic, 'Fluent'); assert.equal(node._sent[0][1].topic, 'reactor_reactor-node-1'); assert.equal(captured.format, 'influxdb'); assert.equal(captured.output.flow_total, 42); assert.equal(captured.output.temperature, 19.5); assert.equal(captured.output.S_O, 2.1); assert.equal(captured.output.S_NH, 16); assert.equal(captured.output.X_TS, 2500); }); test('_emitOutputs also emits GridProfile when engine exposes one', () => { const inst = Object.create(NodeClass.prototype); const node = makeNodeStub(); inst.node = node; inst.config = { functionality: { softwareType: 'reactor' }, general: { id: 'r-1' } }; inst._output = { formatMsg() { return null; } }; const grid = { grid: [[0]], n_x: 1, d_x: 1, length: 1, species: [], timestamp: 1 }; inst.source = { engine: { temperature: 18, getEffluent: { topic: 'Fluent', payload: { inlet: 0, F: 1, C: [] }, timestamp: 1 }, get getGridProfile() { return grid; }, }, config: inst.config, updateState() {}, get getEffluent() { return this.engine.getEffluent; }, get getGridProfile() { return this.engine.getGridProfile; }, getOutput() { return {}; }, }; inst._emitOutputs(); assert.equal(node._sent.length, 2); assert.equal(node._sent[0][0].topic, 'GridProfile'); assert.equal(node._sent[1][0].topic, 'Fluent'); });