feat(pumpingstation): warn when control engages with no machine group registered
A station engaged above startLevel computes a real demand, but if no machine group is registered (e.g. the Port 2 parent↔group registration was dropped by a partial redeploy) the demand is silently forwarded nowhere and the pumps never react — invisible to the operator. levelBased now warns once when engaged with an empty machineGroups map (throttled via host._warnedNoMachineGroup, re-arms when a group reappears); manual.forwardDemand warns when neither a group nor a direct machine is registered. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -182,3 +182,51 @@ test('no valid level → warns and returns without mutating percControl or calli
|
||||
assert.equal(g._calls.handleInput.length, 0);
|
||||
}
|
||||
});
|
||||
|
||||
// Regression: a station engaged above startLevel but with no machine group
|
||||
// registered (e.g. the Port 2 parent↔group registration was dropped by a
|
||||
// partial redeploy) computes a real demand that goes nowhere. The strategy
|
||||
// must surface this once, not fail silently. See the 2026-05-27 "PS not
|
||||
// reacting to level" trace.
|
||||
test('engaged with NO machine group registered → warns once (throttled via host)', async () => {
|
||||
const ctx = makeCtx(3, { levelbased: { holdLevel: 2 } }); // level 3 > startLevel 2 → engaged
|
||||
ctx.machineGroups = {}; // registration lost
|
||||
ctx.host = {};
|
||||
const warns = [];
|
||||
ctx.logger.warn = (m) => warns.push(m);
|
||||
|
||||
const state = { percControl: 0 };
|
||||
await levelBased.run(ctx, state);
|
||||
|
||||
assert.ok(state.percControl > 0, 'demand is computed even though there is no group');
|
||||
assert.equal(warns.length, 1, 'warns exactly once');
|
||||
assert.match(warns[0], /no machine group is registered/i);
|
||||
assert.equal(ctx.host._warnedNoMachineGroup, true);
|
||||
|
||||
// Subsequent ticks while still group-less stay quiet (no log spam).
|
||||
await levelBased.run(ctx, state);
|
||||
assert.equal(warns.length, 1, 'throttled: no repeat warning on the next tick');
|
||||
});
|
||||
|
||||
test('warning re-arms after a group reappears then disappears again', async () => {
|
||||
const ctx = makeCtx(3, { levelbased: { holdLevel: 2 } });
|
||||
ctx.host = {};
|
||||
const warns = [];
|
||||
ctx.logger.warn = (m) => warns.push(m);
|
||||
const state = { percControl: 0 };
|
||||
|
||||
ctx.machineGroups = {};
|
||||
await levelBased.run(ctx, state);
|
||||
assert.equal(warns.length, 1);
|
||||
|
||||
// Group registers again → flag clears, no new warning.
|
||||
ctx.machineGroups = { a: makeGroup('A') };
|
||||
await levelBased.run(ctx, state);
|
||||
assert.equal(warns.length, 1);
|
||||
assert.equal(ctx.host._warnedNoMachineGroup, false);
|
||||
|
||||
// Group lost again → warns once more.
|
||||
ctx.machineGroups = {};
|
||||
await levelBased.run(ctx, state);
|
||||
assert.equal(warns.length, 2, 're-armed after recovery');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user