diff --git a/tools/loop-cost/dist/estimator.js b/tools/loop-cost/dist/estimator.js index 8e83acf5..90146650 100644 --- a/tools/loop-cost/dist/estimator.js +++ b/tools/loop-cost/dist/estimator.js @@ -47,7 +47,11 @@ export function parseInterval(token) { if (!m) throw new Error(`Invalid cadence interval: ${token}`); const unit = m[2]; - return Number(m[1]) * INTERVAL_MS[unit]; + const value = Number(m[1]); + if (value <= 0) { + throw new Error(`Invalid cadence interval: ${token}. The interval value must be greater than zero.`); + } + return value * INTERVAL_MS[unit]; } /** Runs per day for a single interval like 15m or 1d. */ export function runsPerDayForInterval(interval) { diff --git a/tools/loop-cost/src/estimator.ts b/tools/loop-cost/src/estimator.ts index a7fd91ac..83415846 100644 --- a/tools/loop-cost/src/estimator.ts +++ b/tools/loop-cost/src/estimator.ts @@ -113,7 +113,11 @@ export function parseInterval(token: string): number { const m = token.match(/^(\d+)([mhd])$/); if (!m) throw new Error(`Invalid cadence interval: ${token}`); const unit = m[2] as keyof typeof INTERVAL_MS; - return Number(m[1]) * INTERVAL_MS[unit]; + const value = Number(m[1]); + if (value <= 0) { + throw new Error(`Invalid cadence interval: ${token}. The interval value must be greater than zero.`); + } + return value * INTERVAL_MS[unit]; } /** Runs per day for a single interval like 15m or 1d. */ diff --git a/tools/loop-cost/test/estimator.test.mjs b/tools/loop-cost/test/estimator.test.mjs index cd65a869..992839cc 100644 --- a/tools/loop-cost/test/estimator.test.mjs +++ b/tools/loop-cost/test/estimator.test.mjs @@ -30,6 +30,10 @@ test('runsPerDayForInterval: 1d = 1', () => { assert.equal(runsPerDayForInterval('1d'), 1); }); +test('runsPerDayForInterval rejects a zero cadence', () => { + assert.throws(() => runsPerDayForInterval('0m'), /greater than zero/); +}); + test('cadenceToRunsPerDay: range uses fastest by default', () => { assert.equal(cadenceToRunsPerDay('5m-15m'), 288); });