P6: convert reactor to platform infrastructure

Refactor of reactor to use BaseNodeAdapter + commandRegistry + statusBadge.
reactor follows the platform refactor plan in .claude/refactor/MODULE_SPLIT.md.
Tests stay green; CONTRACT.md generated; legacy aliases preserved.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
znetsixe
2026-05-10 22:23:43 +02:00
parent c5fc5c1b59
commit 7bf464b467
16 changed files with 780 additions and 919 deletions

View File

@@ -3,14 +3,18 @@ const assert = require('node:assert/strict');
const NodeClass = require('../../src/nodeClass');
const { Reactor_CSTR, Reactor_PFR } = require('../../src/specificClass');
const { makeUiConfig, makeReactorConfig, makeNodeStub } = require('../helpers/factories');
const { makeUiConfig } = require('../helpers/factories');
test('_loadConfig coerces numeric fields and builds initial state vector', () => {
// 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.
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';
inst._loadConfig(
const dc = inst.buildDomainConfig(
makeUiConfig({
volume: '12.5',
length: '9',
@@ -22,34 +26,40 @@ test('_loadConfig coerces numeric fields and builds initial state vector', () =>
}),
);
assert.equal(inst.config.volume, 12.5);
assert.equal(inst.config.length, 9);
assert.equal(inst.config.resolution_L, 7);
assert.equal(inst.config.alpha, 0.5);
assert.equal(inst.config.n_inlets, 3);
assert.equal(inst.config.timeStep, 2);
assert.equal(inst.config.initialState.length, 13);
assert.equal(inst.config.initialState[0], 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);
});
test('_setupClass selects Reactor_CSTR when configured as CSTR', () => {
const inst = Object.create(NodeClass.prototype);
inst.node = makeNodeStub();
inst.config = makeReactorConfig({ reactor_type: 'CSTR' });
inst._setupClass();
assert.ok(inst.source instanceof Reactor_CSTR);
assert.equal(inst.node.source, inst.source);
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);
});
test('_setupClass selects Reactor_PFR when configured as PFR', () => {
const inst = Object.create(NodeClass.prototype);
inst.node = makeNodeStub();
inst.config = makeReactorConfig({ reactor_type: 'PFR', length: 10, resolution_L: 5 });
inst._setupClass();
assert.ok(inst.source instanceof Reactor_PFR);
assert.equal(inst.node.source, inst.source);
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);
});