Skip to content

Commit e6202b8

Browse files
committed
address comments
1 parent 3ac8e80 commit e6202b8

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/sdk/scenario-builder.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -435,8 +435,8 @@ export class ScenarioBuilder {
435435
}
436436

437437
private addScorer(name: string, weight: number, scorer: ScoringFunction['scorer']): this {
438-
if (weight <= 0) {
439-
throw new Error(`Scorer weight must be positive, got ${weight}`);
438+
if (!Number.isFinite(weight) || weight <= 0) {
439+
throw new Error(`Scorer weight must be a finite positive number, got ${weight}`);
440440
}
441441
this._scorers.push({ name, weight, scorer });
442442
return this;

tests/objects/scenario-builder.test.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,15 +185,23 @@ describe('ScenarioBuilder', () => {
185185
expect(() => builder.build()).toThrow('At least one scorer is required');
186186
});
187187

188-
it('should throw when scorer weight is not positive', () => {
188+
it('should throw when scorer weight is not a finite positive number', () => {
189189
const builder = new ScenarioBuilder('test', mockClient);
190190

191191
expect(() => builder.addShellCommandScorer('s', { command: 'echo 1', weight: 0 })).toThrow(
192-
'Scorer weight must be positive',
192+
'Scorer weight must be a finite positive number',
193193
);
194194

195195
expect(() => builder.addShellCommandScorer('s', { command: 'echo 1', weight: -1 })).toThrow(
196-
'Scorer weight must be positive',
196+
'Scorer weight must be a finite positive number',
197+
);
198+
199+
expect(() => builder.addShellCommandScorer('s', { command: 'echo 1', weight: NaN })).toThrow(
200+
'Scorer weight must be a finite positive number',
201+
);
202+
203+
expect(() => builder.addShellCommandScorer('s', { command: 'echo 1', weight: Infinity })).toThrow(
204+
'Scorer weight must be a finite positive number',
197205
);
198206
});
199207
});

0 commit comments

Comments
 (0)