Skip to content

Commit dd2ac8a

Browse files
authored
fix(loop-cost): reject zero cadence intervals (#526)
1 parent 476d418 commit dd2ac8a

3 files changed

Lines changed: 14 additions & 2 deletions

File tree

tools/loop-cost/dist/estimator.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,11 @@ export function parseInterval(token) {
4747
if (!m)
4848
throw new Error(`Invalid cadence interval: ${token}`);
4949
const unit = m[2];
50-
return Number(m[1]) * INTERVAL_MS[unit];
50+
const value = Number(m[1]);
51+
if (value <= 0) {
52+
throw new Error(`Invalid cadence interval: ${token}. The interval value must be greater than zero.`);
53+
}
54+
return value * INTERVAL_MS[unit];
5155
}
5256
/** Runs per day for a single interval like 15m or 1d. */
5357
export function runsPerDayForInterval(interval) {

tools/loop-cost/src/estimator.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,11 @@ export function parseInterval(token: string): number {
113113
const m = token.match(/^(\d+)([mhd])$/);
114114
if (!m) throw new Error(`Invalid cadence interval: ${token}`);
115115
const unit = m[2] as keyof typeof INTERVAL_MS;
116-
return Number(m[1]) * INTERVAL_MS[unit];
116+
const value = Number(m[1]);
117+
if (value <= 0) {
118+
throw new Error(`Invalid cadence interval: ${token}. The interval value must be greater than zero.`);
119+
}
120+
return value * INTERVAL_MS[unit];
117121
}
118122

119123
/** Runs per day for a single interval like 15m or 1d. */

tools/loop-cost/test/estimator.test.mjs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ test('runsPerDayForInterval: 1d = 1', () => {
3030
assert.equal(runsPerDayForInterval('1d'), 1);
3131
});
3232

33+
test('runsPerDayForInterval rejects a zero cadence', () => {
34+
assert.throws(() => runsPerDayForInterval('0m'), /greater than zero/);
35+
});
36+
3337
test('cadenceToRunsPerDay: range uses fastest by default', () => {
3438
assert.equal(cadenceToRunsPerDay('5m-15m'), 288);
3539
});

0 commit comments

Comments
 (0)