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>
66 lines
2.7 KiB
JavaScript
66 lines
2.7 KiB
JavaScript
const test = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
|
|
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.
|
|
|
|
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',
|
|
}),
|
|
);
|
|
|
|
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('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('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);
|
|
});
|