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,65 +1,83 @@
'use strict';
// Phase 10 rewrite: drives only the public BaseNodeAdapter surface.
// The pre-refactor _loadConfig / _setupClass private methods are gone —
// config build is exposed via buildDomainConfig (override hook in
// CONTRACTS.md §2), and engine selection is observable via
// `inst.source.engine instanceof Reactor_CSTR | Reactor_PFR` after a
// full `new nodeClass(...)` construction.
const test = require('node:test');
const assert = require('node:assert/strict');
const NodeClass = require('../../src/nodeClass');
const nodeClass = require('../../src/nodeClass');
const { Reactor_CSTR, Reactor_PFR } = require('../../src/specificClass');
const { makeUiConfig } = require('../helpers/factories');
// These tests pinned the old private _loadConfig / _setupClass methods on
// the pre-refactor nodeClass. After the BaseNodeAdapter migration the
// same logic lives in buildDomainConfig + the Reactor wrapper's engine
// selector. We exercise both surfaces directly.
function makeRED() { return { nodes: { getNode: () => null } }; }
function makeNode(id = 'reactor-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() {},
};
}
function closeNode(node) {
if (node.handlers.close) node.handlers.close(() => {});
}
test('buildDomainConfig coerces numeric fields and builds initial state vector', () => {
const inst = Object.create(NodeClass.prototype);
inst.node = { id: 'n-reactor-1' };
inst.name = 'reactor';
const dc = inst.buildDomainConfig(
makeUiConfig({
volume: '12.5',
length: '9',
resolution_L: '7',
alpha: '0.5',
n_inlets: '3',
timeStep: '2',
S_O_init: '1.1',
}),
);
const node = makeNode();
const inst = new nodeClass(makeUiConfig(), makeRED(), node, 'reactor');
try {
const dc = inst.buildDomainConfig(
makeUiConfig({
volume: '12.5',
length: '9',
resolution_L: '7',
alpha: '0.5',
n_inlets: '3',
timeStep: '2',
S_O_init: '1.1',
}),
);
assert.equal(dc.reactor.volume, 12.5);
assert.equal(dc.reactor.length, 9);
assert.equal(dc.reactor.resolution_L, 7);
assert.equal(dc.reactor.alpha, 0.5);
assert.equal(dc.reactor.n_inlets, 3);
assert.equal(dc.reactor.timeStep, 2);
assert.equal(Object.keys(dc.initialState).length, 13);
assert.equal(dc.initialState.S_O, 1.1);
assert.equal(dc.reactor.volume, 12.5);
assert.equal(dc.reactor.length, 9);
assert.equal(dc.reactor.resolution_L, 7);
assert.equal(dc.reactor.alpha, 0.5);
assert.equal(dc.reactor.n_inlets, 3);
assert.equal(dc.reactor.timeStep, 2);
assert.equal(Object.keys(dc.initialState).length, 13);
assert.equal(dc.initialState.S_O, 1.1);
} finally {
closeNode(node);
}
});
test('Reactor wrapper instantiates CSTR engine when configured as CSTR', () => {
const Reactor = require('../../src/specificClass');
const config = {
general: { name: 'reactor', id: 'n', logging: { enabled: false, logLevel: 'error' } },
functionality: { softwareType: 'reactor', positionVsParent: 'atEquipment' },
reactor: { reactor_type: 'CSTR', volume: 100, length: 10, resolution_L: 5, alpha: 0,
n_inlets: 1, kla: NaN, timeStep: 1 },
initialState: { S_O: 0, S_I: 30, S_S: 100, S_NH: 16, S_N2: 0, S_NO: 0, S_HCO: 5,
X_I: 25, X_S: 75, X_H: 30, X_STO: 0, X_A: 0.001, X_TS: 125 },
};
const r = new Reactor(config);
assert.ok(r.engine instanceof Reactor_CSTR);
const node = makeNode();
const inst = new nodeClass(makeUiConfig({ reactor_type: 'CSTR' }), makeRED(), node, 'reactor');
try {
assert.ok(inst.source.engine instanceof Reactor_CSTR);
} finally {
closeNode(node);
}
});
test('Reactor wrapper instantiates PFR engine when configured as PFR', () => {
const Reactor = require('../../src/specificClass');
const config = {
general: { name: 'reactor', id: 'n', logging: { enabled: false, logLevel: 'error' } },
functionality: { softwareType: 'reactor', positionVsParent: 'atEquipment' },
reactor: { reactor_type: 'PFR', volume: 100, length: 10, resolution_L: 5, alpha: 0,
n_inlets: 1, kla: NaN, timeStep: 1 },
initialState: { S_O: 0, S_I: 30, S_S: 100, S_NH: 16, S_N2: 0, S_NO: 0, S_HCO: 5,
X_I: 25, X_S: 75, X_H: 30, X_STO: 0, X_A: 0.001, X_TS: 125 },
};
const r = new Reactor(config);
assert.ok(r.engine instanceof Reactor_PFR);
const node = makeNode();
const inst = new nodeClass(makeUiConfig({ reactor_type: 'PFR' }), makeRED(), node, 'reactor');
try {
assert.ok(inst.source.engine instanceof Reactor_PFR);
} finally {
closeNode(node);
}
});