Compare commits

..

2 Commits

Author SHA1 Message Date
znetsixe
ddf2b07424 test: point structure check at renamed 02-Dashboard.json
Example flows were renamed to the numbered-tier convention
(01-Basic.json / 02-Dashboard.json). The structure test still pointed
at the old basic.flow.json path. Rewire to the current filename.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-23 15:29:49 +02:00
znetsixe
c982c9bef7 refactor(units): route _canonicalToOutputFlow + setDemand through UnitPolicy.convert
Drop the direct convert() import — both call sites now go through
this.unitPolicy.convert. setDemand keeps its try/catch around the
absolute-flow branch (legitimate Bucket-2 case: % vs flow demux
prevents declaring `units:` on the dispatcher). Matches the
contract direction in .claude/refactor/CONTRACTS.md §6.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-23 13:43:44 +02:00
2 changed files with 9 additions and 7 deletions

View File

@@ -11,7 +11,7 @@
'use strict';
const { BaseDomain, UnitPolicy, POSITIONS, interpolation, convert } = require('generalFunctions');
const { BaseDomain, UnitPolicy, POSITIONS, interpolation } = require('generalFunctions');
const GroupOperatingPoint = require('./groupOps/groupOperatingPoint');
const groupCurves = require('./groupOps/groupCurves');
const TotalsCalculator = require('./totals/totalsCalculator');
@@ -383,7 +383,7 @@ class MachineGroup extends BaseDomain {
v, 0, 100, dt.flow.min, dt.flow.max);
} else {
try {
canonical = convert(v).from(unit).to('m3/s');
canonical = this.unitPolicy.convert(v, unit, 'm3/s', 'setDemand absolute flow');
} catch (err) {
this.logger?.error?.(`setDemand: cannot convert ${v} ${unit} -> m3/s: ${err?.message || err}`);
return undefined;
@@ -446,10 +446,12 @@ class MachineGroup extends BaseDomain {
}
_canonicalToOutputFlow(value) {
const from = this.unitPolicy.canonical.flow;
const to = this.unitPolicy.output.flow;
if (!from || !to || from === to) return value;
return convert(value).from(from).to(to);
return this.unitPolicy.convert(
value,
this.unitPolicy.canonical.flow,
this.unitPolicy.output.flow,
'canonical->output flow',
);
}
getOutput() { return io.getOutput(this); }

View File

@@ -3,7 +3,7 @@ const assert = require('node:assert/strict');
const fs = require('node:fs');
const path = require('node:path');
const flow = JSON.parse(fs.readFileSync(path.resolve(__dirname, '../../examples/basic.flow.json'), 'utf8'));
const flow = JSON.parse(fs.readFileSync(path.resolve(__dirname, '../../examples/02-Dashboard.json'), 'utf8'));
test('basic example includes node type machineGroupControl', () => {
const count = flow.filter((n) => n && n.type === 'machineGroupControl').length;