P11.6 wiki regen + Phase 10 private-test rewrites where applicable

For all 11 nodes with auto-gen markers: wiki/Home.md sections 5 (topic
contract) and 9 (data model) regenerated via npm run wiki:all. New
Unit column shows '<measure> (default <unit>)' for declared topics,
'—' otherwise. Effect column now uses descriptor.description (P11.2
field) overriding the generic per-prefix fallback.

For rotatingMachine + reactor: Phase 10 test rewrites — 3 + 8 files
moved off private nodeClass internals (_attachInputHandler, _commands,
_pendingExtras, _registerChild, _tick, etc.) to the public
BaseNodeAdapter surface (node.handlers.input, node.source.*).
+6 / +7 net new tests.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
znetsixe
2026-05-11 19:44:09 +02:00
parent 1aa2d92083
commit c84dd781a3
9 changed files with 636 additions and 285 deletions

View File

@@ -1,103 +1,156 @@
'use strict';
// Phase 10 rewrite: drives only the public BaseNodeAdapter surface.
// The pre-refactor _tick / _startTickLoop methods are gone — periodic
// emission lives in `_emitOutputs()` (overridden in the reactor nodeClass
// to preserve the Fluent / GridProfile Port-0 contract; delta-compressed
// payloads can't carry the C-vector). The override is part of the
// documented BaseNodeAdapter override surface, so we exercise it
// directly. The fully-constructed adapter wires `inst.source.engine`,
// `inst._output`, etc. so we don't have to assemble stub bags.
const test = require('node:test');
const assert = require('node:assert/strict');
const NodeClass = require('../../src/nodeClass');
const { makeNodeStub } = require('../helpers/factories');
const nodeClass = require('../../src/nodeClass');
const { makeUiConfig } = 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).
function makeRED() { return { nodes: { getNode: () => null } }; }
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 {}; },
function makeNode(id = 'reactor-node-1') {
const sends = [];
const statuses = [];
const handlers = {};
return {
id, sends, statuses, handlers,
send(arr) { sends.push(arr); },
status(b) { statuses.push(b); },
on(ev, fn) { handlers[ev] = fn; },
warn() {}, error() {},
};
}
inst._emitOutputs();
function closeNode(node) {
if (node.handlers.close) node.handlers.close(() => {});
}
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);
function pickEffluentSends(node) {
return node.sends.filter((s) => Array.isArray(s) && s[0] && s[0].topic === 'Fluent');
}
function pickGridSends(node) {
return node.sends.filter((s) => Array.isArray(s) && s[0] && s[0].topic === 'GridProfile');
}
test('_emitOutputs sends the effluent message on process output (CSTR)', () => {
const node = makeNode();
const inst = new nodeClass(
makeUiConfig({ reactor_type: 'CSTR' }),
makeRED(),
node,
'reactor',
);
try {
// Reset sends so any construction-time emissions don't pollute the
// assertion (the registration triple lands on the same buffer).
node.sends.length = 0;
inst._emitOutputs();
const fluentSends = pickEffluentSends(node);
assert.equal(fluentSends.length, 1, 'exactly one Fluent message');
const triple = fluentSends[0];
assert.equal(triple[0].topic, 'Fluent');
assert.ok(triple[0].payload && Array.isArray(triple[0].payload.C));
// CSTR has no grid profile.
assert.equal(pickGridSends(node).length, 0);
} finally {
closeNode(node);
}
});
test('_emitOutputs emits reactor telemetry on influx output', () => {
const inst = Object.create(NodeClass.prototype);
const node = makeNodeStub();
let captured = null;
test('_emitOutputs emits a GridProfile message when engine exposes one (PFR)', () => {
const node = makeNode();
const inst = new nodeClass(
makeUiConfig({ reactor_type: 'PFR' }),
makeRED(),
node,
'reactor',
);
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;
},
};
try {
node.sends.length = 0;
inst._emitOutputs();
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);
assert.equal(pickGridSends(node).length, 1, 'exactly one GridProfile message');
assert.equal(pickEffluentSends(node).length, 1, 'exactly one Fluent message');
} finally {
closeNode(node);
}
});
test('_emitOutputs also emits GridProfile when engine exposes one', () => {
const inst = Object.create(NodeClass.prototype);
const node = makeNodeStub();
test('_emitOutputs formats per-species influx telemetry via outputUtils', () => {
const node = makeNode();
const inst = new nodeClass(
makeUiConfig({ reactor_type: 'CSTR' }),
makeRED(),
node,
'reactor',
);
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 {}; },
};
try {
// Stub updateState so the engine integration does not overwrite the
// engineered state we want the telemetry formatter to see.
inst.source.updateState = () => {};
inst.source.engine.setInfluent = {
payload: { inlet: 0, F: 42, C: [2.1, 30, 100, 16, 0, 1, 8, 25, 75, 1500, 0, 15, 2500] },
};
inst.source.engine.state = [2.1, 30, 100, 16, 0, 1, 8, 25, 75, 1500, 0, 15, 2500];
inst.source.engine.temperature = 19.5;
inst._emitOutputs();
let captured = null;
const realFormat = inst._output.formatMsg.bind(inst._output);
inst._output.formatMsg = (output, cfg, format) => {
if (format === 'influxdb') captured = { output, format };
return realFormat(output, cfg, format);
};
assert.equal(node._sent.length, 2);
assert.equal(node._sent[0][0].topic, 'GridProfile');
assert.equal(node._sent[1][0].topic, 'Fluent');
node.sends.length = 0;
inst._emitOutputs();
assert.ok(captured, 'formatMsg was called with influxdb format');
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);
} finally {
closeNode(node);
}
});
test('Reactor.tick(dt) drives the kinetics engine and advances state', () => {
const node = makeNode();
const inst = new nodeClass(
makeUiConfig({ reactor_type: 'CSTR' }),
makeRED(),
node,
'reactor',
);
try {
// Feed an influent so the integrator has something to chew on.
inst.source.engine.setInfluent = {
payload: { inlet: 0, F: 5, C: [0,30,100,16,0,0,5,25,75,30,0,0.001,125] },
};
const stateBefore = JSON.stringify(inst.source.engine.state);
inst.source.tick(0.001);
const stateAfter = JSON.stringify(inst.source.engine.state);
assert.notEqual(stateBefore, stateAfter, 'engine state should advance after tick(dt)');
} finally {
closeNode(node);
}
});