Problem
detectLoops (js/loops.js:52-69) calls evalFormula to probe formula signs. When math.js is not available (CLI without npm install), evalFormula returns 0 for all expressions using math.js functions (max(), min(), round(), etc.). The probe returns null (no measurable influence), the formula edge is silently dropped, and the loop table is incomplete with no error.
This is currently masked by the legacy new Function() fallback handling simple arithmetic but NOT math.js-specific functions. After #42 removes the legacy fallback, the problem extends to ALL arithmetic — even simple formulas like 10 - gold return 0 without math.js, making the loop detector silently useless in the CLI.
Fix
Add a guard at the top of detectLoops():
function detectLoops(diagram, opts = {}) {
if (typeof math === 'undefined' || !math.compile) {
console.warn('detectLoops: math.js not available; loop detection will be incomplete. npm install mathjs.');
}
// ... existing code ...
}
In the browser, math.js is always loaded so this only fires in CLI/test without npm install. The warning is actionable rather than silently producing wrong results.
Dependencies
Best applied after #42 (legacy evalFormula removal) since that makes the math.js dependency explicit.
Effort
~10 minutes. 1 file (js/loops.js). 3 lines added.
Problem
detectLoops(js/loops.js:52-69) callsevalFormulato probe formula signs. When math.js is not available (CLI withoutnpm install),evalFormulareturns 0 for all expressions using math.js functions (max(),min(),round(), etc.). The probe returnsnull(no measurable influence), the formula edge is silently dropped, and the loop table is incomplete with no error.This is currently masked by the legacy
new Function()fallback handling simple arithmetic but NOT math.js-specific functions. After #42 removes the legacy fallback, the problem extends to ALL arithmetic — even simple formulas like10 - goldreturn 0 without math.js, making the loop detector silently useless in the CLI.Fix
Add a guard at the top of
detectLoops():In the browser, math.js is always loaded so this only fires in CLI/test without
npm install. The warning is actionable rather than silently producing wrong results.Dependencies
Best applied after #42 (legacy evalFormula removal) since that makes the math.js dependency explicit.
Effort
~10 minutes. 1 file (
js/loops.js). 3 lines added.