|
| 1 | +// npx vitest run src/__tests__/tool-repetition-limits.test.ts |
| 2 | + |
| 3 | +import { normalizeToolRepetitionSoftLimit } from "../provider-settings.js" |
| 4 | + |
| 5 | +describe("normalizeToolRepetitionSoftLimit", () => { |
| 6 | + it("keeps a soft limit that is already below the hard limit", () => { |
| 7 | + expect(normalizeToolRepetitionSoftLimit(2, 5)).toBe(2) |
| 8 | + }) |
| 9 | + |
| 10 | + it("clamps a soft limit equal to the hard limit down to hardLimit - 1", () => { |
| 11 | + expect(normalizeToolRepetitionSoftLimit(5, 5)).toBe(4) |
| 12 | + }) |
| 13 | + |
| 14 | + it("clamps a soft limit above the hard limit down to hardLimit - 1", () => { |
| 15 | + expect(normalizeToolRepetitionSoftLimit(8, 3)).toBe(2) |
| 16 | + }) |
| 17 | + |
| 18 | + it("allows soft limit 0 regardless of hard limit", () => { |
| 19 | + expect(normalizeToolRepetitionSoftLimit(0, 5)).toBe(0) |
| 20 | + }) |
| 21 | + |
| 22 | + it("clamps soft to 0 when the hard limit is 1", () => { |
| 23 | + expect(normalizeToolRepetitionSoftLimit(3, 1)).toBe(0) |
| 24 | + }) |
| 25 | + |
| 26 | + it("disables the soft tier when the hard limit is 0", () => { |
| 27 | + expect(normalizeToolRepetitionSoftLimit(9, 0)).toBe(0) |
| 28 | + expect(normalizeToolRepetitionSoftLimit(2, 0)).toBe(0) |
| 29 | + expect(normalizeToolRepetitionSoftLimit(2, -1)).toBe(0) |
| 30 | + }) |
| 31 | + |
| 32 | + it("disables the soft tier when the hard limit is effectively unreachable", () => { |
| 33 | + expect(normalizeToolRepetitionSoftLimit(2, Number.MAX_SAFE_INTEGER)).toBe(0) |
| 34 | + expect(normalizeToolRepetitionSoftLimit(2, Number.POSITIVE_INFINITY)).toBe(0) |
| 35 | + }) |
| 36 | + |
| 37 | + it("clamps negative soft values to 0", () => { |
| 38 | + expect(normalizeToolRepetitionSoftLimit(-3, 5)).toBe(0) |
| 39 | + expect(normalizeToolRepetitionSoftLimit(-3, 0)).toBe(0) |
| 40 | + }) |
| 41 | + |
| 42 | + it("never returns a negative value for a fractional hard limit", () => { |
| 43 | + expect(normalizeToolRepetitionSoftLimit(3, 0.5)).toBe(0) |
| 44 | + expect(normalizeToolRepetitionSoftLimit(0, 0.5)).toBe(0) |
| 45 | + }) |
| 46 | + |
| 47 | + it("always stays strictly below an enabled hard limit", () => { |
| 48 | + for (let hard = 1; hard <= 20; hard++) { |
| 49 | + for (let requested = 0; requested <= 30; requested++) { |
| 50 | + const result = normalizeToolRepetitionSoftLimit(requested, hard) |
| 51 | + expect(result).toBeGreaterThanOrEqual(0) |
| 52 | + expect(result).toBeLessThan(hard) |
| 53 | + } |
| 54 | + } |
| 55 | + }) |
| 56 | +}) |
0 commit comments