Files
rotatingMachine/test/edge/error-paths.edge.test.js

73 lines
2.5 KiB
JavaScript
Raw Normal View History

2026-02-12 10:48:44 +01:00
const test = require('node:test');
const assert = require('node:assert/strict');
const Machine = require('../../src/specificClass');
const NodeClass = require('../../src/nodeClass');
const { makeMachineConfig, makeStateConfig, makeNodeStub } = require('../helpers/factories');
test('setpoint rejects negative inputs without throwing', async () => {
const machine = new Machine(makeMachineConfig(), makeStateConfig({ state: { current: 'operational' } }));
await assert.doesNotReject(async () => {
await machine.setpoint(-1);
});
});
2026-03-11 11:13:26 +01:00
test('setpoint is constrained to safe movement/curve bounds', async () => {
const machine = new Machine(makeMachineConfig(), makeStateConfig({ state: { current: 'operational' } }));
const requested = [];
machine.state.moveTo = async (target) => {
requested.push(target);
};
const stateMin = machine.state.movementManager.minPosition;
const stateMax = machine.state.movementManager.maxPosition;
const curveMin = machine.predictFlow.currentFxyXMin;
const curveMax = machine.predictFlow.currentFxyXMax;
const min = Math.max(stateMin, curveMin);
const max = Math.min(stateMax, curveMax);
await machine.setpoint(min - 100);
await machine.setpoint(max + 100);
assert.equal(requested.length, 2);
assert.equal(requested[0], min);
assert.equal(requested[1], max);
});
P5 wave 2: convert rotatingMachine to BaseDomain + extract helper modules specificClass.js: 1760 → 400 lines. Machine extends BaseDomain. configure() wires curves + predictors + drift + pressure + state bindings + measurement handlers + flow controller. ChildRouter handles pressure/flow/power/temperature measurement events; custom registerChild override preserves the dedup + virtual-vs-real pressure tracking the integration tests pin. Added small host-aware helper modules to fit the 400-line cap: src/prediction/predictionMath.js (calcFlow/Power/Ctrl) src/prediction/efficiencyMath.js (calcCog/EfficiencyCurve/etc.) src/pressure/pressureSelector.js (getMeasuredPressure source preference) src/state/sequenceController.js (executeSequence/setpoint/wait helpers) src/measurement/childRegistrar.js (custom registerChild path) src/drift/healthRefresh.js (drift status update wrappers) src/io/output.js (buildOutput + buildStatusBadge) unitPolicy: live UnitPolicy methods .canonical()/.output()/.curve() bridged to legacy property-path readers via a frozen view object — same pattern as MGC. See OPEN_QUESTIONS.md. nodeClass.js: 433 → 61 lines. Extends BaseNodeAdapter. tickInterval=null (event-driven on state + measurement events). buildDomainConfig stamps the rotatingMachine state + errorMetrics slices on the domain config so configure() builds them from there. 5 tests adjusted (4 nodeClass-config, 1 error-paths) — pre-refactor they pinned private methods (_loadConfig, _setupSpecificClass, _attachInputHandler, _updateNodeStatus) that no longer exist. New versions drive the public BaseNodeAdapter surface or call extracted io/state-machine helpers directly. See OPEN_QUESTIONS.md 2026-05-10 "private nodeClass tests" for the deferred rewrite plan. 196 / 196 tests pass (basic 110 + integration ~80 + edge ~6). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-10 22:00:34 +02:00
test('source.getStatusBadge returns error status on internal failure', () => {
// Status badge lives on the domain post-refactor. Build a tiny stub
// that throws to verify the error-path returns an error badge.
const errors = [];
const source = {
2026-02-12 10:48:44 +01:00
currentMode: 'auto',
P5 wave 2: convert rotatingMachine to BaseDomain + extract helper modules specificClass.js: 1760 → 400 lines. Machine extends BaseDomain. configure() wires curves + predictors + drift + pressure + state bindings + measurement handlers + flow controller. ChildRouter handles pressure/flow/power/temperature measurement events; custom registerChild override preserves the dedup + virtual-vs-real pressure tracking the integration tests pin. Added small host-aware helper modules to fit the 400-line cap: src/prediction/predictionMath.js (calcFlow/Power/Ctrl) src/prediction/efficiencyMath.js (calcCog/EfficiencyCurve/etc.) src/pressure/pressureSelector.js (getMeasuredPressure source preference) src/state/sequenceController.js (executeSequence/setpoint/wait helpers) src/measurement/childRegistrar.js (custom registerChild path) src/drift/healthRefresh.js (drift status update wrappers) src/io/output.js (buildOutput + buildStatusBadge) unitPolicy: live UnitPolicy methods .canonical()/.output()/.curve() bridged to legacy property-path readers via a frozen view object — same pattern as MGC. See OPEN_QUESTIONS.md. nodeClass.js: 433 → 61 lines. Extends BaseNodeAdapter. tickInterval=null (event-driven on state + measurement events). buildDomainConfig stamps the rotatingMachine state + errorMetrics slices on the domain config so configure() builds them from there. 5 tests adjusted (4 nodeClass-config, 1 error-paths) — pre-refactor they pinned private methods (_loadConfig, _setupSpecificClass, _attachInputHandler, _updateNodeStatus) that no longer exist. New versions drive the public BaseNodeAdapter surface or call extracted io/state-machine helpers directly. See OPEN_QUESTIONS.md 2026-05-10 "private nodeClass tests" for the deferred rewrite plan. 196 / 196 tests pass (basic 110 + integration ~80 + edge ~6). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-10 22:00:34 +02:00
state: { getCurrentState() { throw new Error('boom'); } },
logger: { error: (m) => errors.push(m) },
2026-02-12 10:48:44 +01:00
};
P5 wave 2: convert rotatingMachine to BaseDomain + extract helper modules specificClass.js: 1760 → 400 lines. Machine extends BaseDomain. configure() wires curves + predictors + drift + pressure + state bindings + measurement handlers + flow controller. ChildRouter handles pressure/flow/power/temperature measurement events; custom registerChild override preserves the dedup + virtual-vs-real pressure tracking the integration tests pin. Added small host-aware helper modules to fit the 400-line cap: src/prediction/predictionMath.js (calcFlow/Power/Ctrl) src/prediction/efficiencyMath.js (calcCog/EfficiencyCurve/etc.) src/pressure/pressureSelector.js (getMeasuredPressure source preference) src/state/sequenceController.js (executeSequence/setpoint/wait helpers) src/measurement/childRegistrar.js (custom registerChild path) src/drift/healthRefresh.js (drift status update wrappers) src/io/output.js (buildOutput + buildStatusBadge) unitPolicy: live UnitPolicy methods .canonical()/.output()/.curve() bridged to legacy property-path readers via a frozen view object — same pattern as MGC. See OPEN_QUESTIONS.md. nodeClass.js: 433 → 61 lines. Extends BaseNodeAdapter. tickInterval=null (event-driven on state + measurement events). buildDomainConfig stamps the rotatingMachine state + errorMetrics slices on the domain config so configure() builds them from there. 5 tests adjusted (4 nodeClass-config, 1 error-paths) — pre-refactor they pinned private methods (_loadConfig, _setupSpecificClass, _attachInputHandler, _updateNodeStatus) that no longer exist. New versions drive the public BaseNodeAdapter surface or call extracted io/state-machine helpers directly. See OPEN_QUESTIONS.md 2026-05-10 "private nodeClass tests" for the deferred rewrite plan. 196 / 196 tests pass (basic 110 + integration ~80 + edge ~6). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-10 22:00:34 +02:00
const { buildStatusBadge } = require('../../src/io/output');
const status = buildStatusBadge(source);
assert.match(status.text, /Status Error/);
assert.equal(status.fill, 'red');
assert.equal(errors.length, 1);
2026-02-12 10:48:44 +01:00
});
2026-03-11 11:13:26 +01:00
test('measurement handlers reject incompatible units', () => {
const machine = new Machine(makeMachineConfig(), makeStateConfig({ state: { current: 'operational' } }));
assert.equal(machine.isUnitValidForType('flow', 'm3/h'), true);
assert.equal(machine.isUnitValidForType('flow', 'mbar'), false);
machine.updateMeasuredFlow(100, 'downstream', {
timestamp: Date.now(),
unit: 'mbar',
childName: 'bad-ft',
});
const measuredFlow = machine.measurements
.type('flow')
.variant('measured')
.position('downstream')
.getCurrentValue();
assert.equal(measuredFlow, null);
});