Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion tools/loop-cost/dist/estimator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 5 additions & 1 deletion tools/loop-cost/src/estimator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
4 changes: 4 additions & 0 deletions tools/loop-cost/test/estimator.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down