specificClass._setupCurves now calls assetResolver.resolveAssetMetadata to derive supplier/type/units from the model id, instead of trusting denormalized fields on the node config. If the model isn't in the registry, installs a null-predictor stub and logs a clear "pick a model from the asset menu" error rather than crashing. rotatingMachine.html: defaults block trimmed (supplier/category/assetType were stale copies of registry data). Tests: - New test/basic/assetMetadata.basic.test.js covers the registry-resolve path and the missing-model fallback. - nodeClass-config / error-paths / nodeClass-routing / factories / abort-deadlock fixtures updated to the trimmed asset shape. - 209/209 tests pass. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
62 lines
2.4 KiB
JavaScript
62 lines
2.4 KiB
JavaScript
'use strict';
|
|
|
|
const test = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
|
|
const Machine = require('../../src/specificClass');
|
|
|
|
// Phase 4 regression: after the AssetResolver cutover the node must
|
|
// (a) derive supplier/type/units from the registry, not from saved config,
|
|
// (b) hard-fail with a clear log if asset.model is missing,
|
|
// (c) hard-fail if asset.unit is missing or not in registry's allowed set,
|
|
// (d) succeed with a known good model + unit.
|
|
|
|
function makeConfig({ model = 'hidrostal-H05K-S03R', unit = 'm3/h' } = {}) {
|
|
return {
|
|
general: { id: 'test-node', name: 'Pump-T', logging: { enabled: false } },
|
|
asset: { model, unit, curveUnits: { pressure: 'mbar', flow: unit, power: 'kW', control: '%' } },
|
|
functionality: { softwareType: 'rotatingmachine' },
|
|
};
|
|
}
|
|
|
|
test('asset metadata is derived from the registry, not from config', () => {
|
|
const m = new Machine(makeConfig());
|
|
assert.ok(m.assetMetadata, 'expected assetMetadata to be populated');
|
|
assert.equal(m.assetMetadata.supplier, 'Hidrostal');
|
|
assert.equal(m.assetMetadata.type, 'Centrifugal');
|
|
assert.ok(Array.isArray(m.assetMetadata.units));
|
|
assert.ok(m.assetMetadata.units.length > 0);
|
|
});
|
|
|
|
test('valid model + unit yields working curve predictors', () => {
|
|
const m = new Machine(makeConfig());
|
|
assert.equal(m.hasCurve, true);
|
|
assert.equal(typeof m.predictFlow, 'object');
|
|
assert.equal(typeof m.predictPower, 'object');
|
|
});
|
|
|
|
test('missing model installs null predictors (degraded mode)', () => {
|
|
const m = new Machine(makeConfig({ model: null }));
|
|
assert.equal(m.hasCurve, false);
|
|
assert.equal(m.predictFlow, null);
|
|
assert.equal(m.predictPower, null);
|
|
});
|
|
|
|
test('unknown model installs null predictors and logs', () => {
|
|
const m = new Machine(makeConfig({ model: 'no-such-model-xyz' }));
|
|
assert.equal(m.hasCurve, false);
|
|
assert.equal(m.assetMetadata, null);
|
|
});
|
|
|
|
test('unit not in registry allowed-set installs null predictors', () => {
|
|
const m = new Machine(makeConfig({ unit: 'furlongs-per-fortnight' }));
|
|
assert.equal(m.hasCurve, false);
|
|
});
|
|
|
|
test('two machines with the same model get independent assetMetadata instances', () => {
|
|
const a = new Machine(makeConfig());
|
|
const b = new Machine(makeConfig());
|
|
assert.notStrictEqual(a, b);
|
|
assert.equal(a.assetMetadata.supplier, b.assetMetadata.supplier);
|
|
});
|